drivers/platform/x86/gpd-pocket-fan.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/gpd-pocket-fan.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/gpd-pocket-fan.c- Extension
.c- Size
- 5816 bytes
- Lines
- 225
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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.
- 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
linux/acpi.hlinux/devm-helpers.hlinux/gpio/consumer.hlinux/module.hlinux/moduleparam.hlinux/platform_device.hlinux/power_supply.hlinux/thermal.hlinux/workqueue.h
Detected Declarations
struct gpd_pocket_fan_datafunction gpd_pocket_fan_set_speedfunction gpd_pocket_fan_min_speedfunction gpd_pocket_fan_workerfunction gpd_pocket_fan_force_updatefunction gpd_pocket_fan_probefunction gpd_pocket_fan_suspendfunction gpd_pocket_fan_resume
Annotated Snippet
struct gpd_pocket_fan_data {
struct device *dev;
struct thermal_zone_device *dts0;
struct thermal_zone_device *dts1;
struct gpio_desc *gpio0;
struct gpio_desc *gpio1;
struct delayed_work work;
int last_speed;
};
static void gpd_pocket_fan_set_speed(struct gpd_pocket_fan_data *fan, int speed)
{
if (speed == fan->last_speed)
return;
gpiod_direction_output(fan->gpio0, !!(speed & 1));
gpiod_direction_output(fan->gpio1, !!(speed & 2));
fan->last_speed = speed;
}
static int gpd_pocket_fan_min_speed(void)
{
if (power_supply_is_system_supplied())
return speed_on_ac;
else
return 0;
}
static void gpd_pocket_fan_worker(struct work_struct *work)
{
struct gpd_pocket_fan_data *fan =
container_of(work, struct gpd_pocket_fan_data, work.work);
int t0, t1, temp, speed, min_speed, i;
if (thermal_zone_get_temp(fan->dts0, &t0) ||
thermal_zone_get_temp(fan->dts1, &t1)) {
dev_warn(fan->dev, "Error getting temperature\n");
speed = MAX_SPEED;
goto set_speed;
}
temp = max(t0, t1);
speed = fan->last_speed;
min_speed = gpd_pocket_fan_min_speed();
/* Determine minimum speed */
for (i = min_speed; i < ARRAY_SIZE(temp_limits); i++) {
if (temp < temp_limits[i])
break;
}
if (speed < i)
speed = i;
/* Use hysteresis before lowering speed again */
for (i = min_speed; i < ARRAY_SIZE(temp_limits); i++) {
if (temp <= (temp_limits[i] - hysteresis))
break;
}
if (speed > i)
speed = i;
if (fan->last_speed <= 0 && speed)
speed = MAX_SPEED; /* kick start motor */
set_speed:
gpd_pocket_fan_set_speed(fan, speed);
/* When mostly idle (low temp/speed), slow down the poll interval. */
queue_delayed_work(system_percpu_wq, &fan->work,
msecs_to_jiffies(4000 / (speed + 1)));
}
static void gpd_pocket_fan_force_update(struct gpd_pocket_fan_data *fan)
{
fan->last_speed = -1;
mod_delayed_work(system_percpu_wq, &fan->work, 0);
}
static int gpd_pocket_fan_probe(struct platform_device *pdev)
{
struct gpd_pocket_fan_data *fan;
int i, ret;
for (i = 0; i < ARRAY_SIZE(temp_limits); i++) {
if (temp_limits[i] < 20000 || temp_limits[i] > 90000) {
dev_err(&pdev->dev, "Invalid temp-limit %d (must be between 20000 and 90000)\n",
temp_limits[i]);
temp_limits[0] = TEMP_LIMIT0_DEFAULT;
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/devm-helpers.h`, `linux/gpio/consumer.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/thermal.h`.
- Detected declarations: `struct gpd_pocket_fan_data`, `function gpd_pocket_fan_set_speed`, `function gpd_pocket_fan_min_speed`, `function gpd_pocket_fan_worker`, `function gpd_pocket_fan_force_update`, `function gpd_pocket_fan_probe`, `function gpd_pocket_fan_suspend`, `function gpd_pocket_fan_resume`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
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.