drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c- Extension
.c- Size
- 3257 bytes
- Lines
- 117
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
priv.hsubdev/gpio.hsubdev/timer.h
Detected Declarations
struct nvkm_fantogfunction nvkm_fantog_updatefunction nvkm_fantog_alarmfunction nvkm_fantog_getfunction nvkm_fantog_setfunction nvkm_fantog_create
Annotated Snippet
struct nvkm_fantog {
struct nvkm_fan base;
struct nvkm_alarm alarm;
spinlock_t lock;
u32 period_us;
u32 percent;
struct dcb_gpio_func func;
};
static void
nvkm_fantog_update(struct nvkm_fantog *fan, int percent)
{
struct nvkm_therm *therm = fan->base.parent;
struct nvkm_device *device = therm->subdev.device;
struct nvkm_timer *tmr = device->timer;
struct nvkm_gpio *gpio = device->gpio;
unsigned long flags;
int duty;
spin_lock_irqsave(&fan->lock, flags);
if (percent < 0)
percent = fan->percent;
fan->percent = percent;
duty = !nvkm_gpio_get(gpio, 0, DCB_GPIO_FAN, 0xff);
nvkm_gpio_set(gpio, 0, DCB_GPIO_FAN, 0xff, duty);
if (percent != (duty * 100)) {
u64 next_change = (percent * fan->period_us) / 100;
if (!duty)
next_change = fan->period_us - next_change;
nvkm_timer_alarm(tmr, next_change * 1000, &fan->alarm);
}
spin_unlock_irqrestore(&fan->lock, flags);
}
static void
nvkm_fantog_alarm(struct nvkm_alarm *alarm)
{
struct nvkm_fantog *fan =
container_of(alarm, struct nvkm_fantog, alarm);
nvkm_fantog_update(fan, -1);
}
static int
nvkm_fantog_get(struct nvkm_therm *therm)
{
struct nvkm_fantog *fan = (void *)therm->fan;
return fan->percent;
}
static int
nvkm_fantog_set(struct nvkm_therm *therm, int percent)
{
struct nvkm_fantog *fan = (void *)therm->fan;
if (therm->func->pwm_ctrl)
therm->func->pwm_ctrl(therm, fan->func.line, false);
nvkm_fantog_update(fan, percent);
return 0;
}
int
nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
{
struct nvkm_fantog *fan;
int ret;
if (therm->func->pwm_ctrl) {
ret = therm->func->pwm_ctrl(therm, func->line, false);
if (ret)
return ret;
}
fan = kzalloc_obj(*fan);
if (!fan)
return -ENOMEM;
therm->fan = &fan->base;
fan->base.type = "toggle";
fan->base.get = nvkm_fantog_get;
fan->base.set = nvkm_fantog_set;
nvkm_alarm_init(&fan->alarm, nvkm_fantog_alarm);
fan->period_us = 100000; /* 10Hz */
fan->percent = 100;
fan->func = *func;
spin_lock_init(&fan->lock);
return 0;
}
Annotation
- Immediate include surface: `priv.h`, `subdev/gpio.h`, `subdev/timer.h`.
- Detected declarations: `struct nvkm_fantog`, `function nvkm_fantog_update`, `function nvkm_fantog_alarm`, `function nvkm_fantog_get`, `function nvkm_fantog_set`, `function nvkm_fantog_create`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.