Lines Matching +full:fan +full:-
1 // SPDX-License-Identifier: GPL-2.0+
3 * GPD Pocket fan controller driver
9 #include <linux/devm-helpers.h>
33 "Millicelsius values above which the fan speed increases");
38 "Hysteresis in millicelsius before lowering the fan speed");
43 "minimum fan speed to allow when system is powered by AC");
55 static void gpd_pocket_fan_set_speed(struct gpd_pocket_fan_data *fan, int speed) in gpd_pocket_fan_set_speed() argument
57 if (speed == fan->last_speed) in gpd_pocket_fan_set_speed()
60 gpiod_direction_output(fan->gpio0, !!(speed & 1)); in gpd_pocket_fan_set_speed()
61 gpiod_direction_output(fan->gpio1, !!(speed & 2)); in gpd_pocket_fan_set_speed()
63 fan->last_speed = speed; in gpd_pocket_fan_set_speed()
76 struct gpd_pocket_fan_data *fan = in gpd_pocket_fan_worker() local
80 if (thermal_zone_get_temp(fan->dts0, &t0) || in gpd_pocket_fan_worker()
81 thermal_zone_get_temp(fan->dts1, &t1)) { in gpd_pocket_fan_worker()
82 dev_warn(fan->dev, "Error getting temperature\n"); in gpd_pocket_fan_worker()
89 speed = fan->last_speed; in gpd_pocket_fan_worker()
102 if (temp <= (temp_limits[i] - hysteresis)) in gpd_pocket_fan_worker()
108 if (fan->last_speed <= 0 && speed) in gpd_pocket_fan_worker()
112 gpd_pocket_fan_set_speed(fan, speed); in gpd_pocket_fan_worker()
115 queue_delayed_work(system_wq, &fan->work, in gpd_pocket_fan_worker()
119 static void gpd_pocket_fan_force_update(struct gpd_pocket_fan_data *fan) in gpd_pocket_fan_force_update() argument
121 fan->last_speed = -1; in gpd_pocket_fan_force_update()
122 mod_delayed_work(system_wq, &fan->work, 0); in gpd_pocket_fan_force_update()
127 struct gpd_pocket_fan_data *fan; in gpd_pocket_fan_probe() local
132 dev_err(&pdev->dev, "Invalid temp-limit %d (must be between 20000 and 90000)\n", in gpd_pocket_fan_probe()
141 dev_err(&pdev->dev, "Invalid hysteresis %d (must be between 1000 and 10000)\n", in gpd_pocket_fan_probe()
146 dev_err(&pdev->dev, "Invalid speed_on_ac %d (must be between 0 and 3)\n", in gpd_pocket_fan_probe()
151 fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); in gpd_pocket_fan_probe()
152 if (!fan) in gpd_pocket_fan_probe()
153 return -ENOMEM; in gpd_pocket_fan_probe()
155 fan->dev = &pdev->dev; in gpd_pocket_fan_probe()
156 ret = devm_delayed_work_autocancel(&pdev->dev, &fan->work, in gpd_pocket_fan_probe()
162 fan->dts0 = thermal_zone_get_zone_by_name("soc_dts0"); in gpd_pocket_fan_probe()
163 if (IS_ERR(fan->dts0)) in gpd_pocket_fan_probe()
164 return -EPROBE_DEFER; in gpd_pocket_fan_probe()
166 fan->dts1 = thermal_zone_get_zone_by_name("soc_dts1"); in gpd_pocket_fan_probe()
167 if (IS_ERR(fan->dts1)) in gpd_pocket_fan_probe()
168 return -EPROBE_DEFER; in gpd_pocket_fan_probe()
170 fan->gpio0 = devm_gpiod_get_index(fan->dev, NULL, 0, GPIOD_ASIS); in gpd_pocket_fan_probe()
171 if (IS_ERR(fan->gpio0)) in gpd_pocket_fan_probe()
172 return PTR_ERR(fan->gpio0); in gpd_pocket_fan_probe()
174 fan->gpio1 = devm_gpiod_get_index(fan->dev, NULL, 1, GPIOD_ASIS); in gpd_pocket_fan_probe()
175 if (IS_ERR(fan->gpio1)) in gpd_pocket_fan_probe()
176 return PTR_ERR(fan->gpio1); in gpd_pocket_fan_probe()
178 gpd_pocket_fan_force_update(fan); in gpd_pocket_fan_probe()
180 platform_set_drvdata(pdev, fan); in gpd_pocket_fan_probe()
187 struct gpd_pocket_fan_data *fan = dev_get_drvdata(dev); in gpd_pocket_fan_suspend() local
189 cancel_delayed_work_sync(&fan->work); in gpd_pocket_fan_suspend()
190 gpd_pocket_fan_set_speed(fan, gpd_pocket_fan_min_speed()); in gpd_pocket_fan_suspend()
196 struct gpd_pocket_fan_data *fan = dev_get_drvdata(dev); in gpd_pocket_fan_resume() local
198 gpd_pocket_fan_force_update(fan); in gpd_pocket_fan_resume()
223 MODULE_DESCRIPTION("GPD pocket fan driver");