Lines Matching refs:th

92 static void write_both_fan_speed(struct thermostat *th, int speed);
93 static void write_fan_speed(struct thermostat *th, int speed, int fan);
96 write_reg(struct thermostat* th, int reg, u8 data) in write_reg() argument
103 rc = i2c_master_send(th->clt, (const char *)tmp, 2); in write_reg()
112 read_reg(struct thermostat* th, int reg) in read_reg() argument
118 rc = i2c_master_send(th->clt, &reg_addr, 1); in read_reg()
123 rc = i2c_master_recv(th->clt, (char *)&data, 1); in read_reg()
129 static int read_fan_speed(struct thermostat *th, u8 addr) in read_fan_speed() argument
135 tmp[1] = read_reg(th, addr); in read_fan_speed()
136 tmp[0] = read_reg(th, addr + 1); in read_fan_speed()
143 static void write_both_fan_speed(struct thermostat *th, int speed) in write_both_fan_speed() argument
145 write_fan_speed(th, speed, 0); in write_both_fan_speed()
146 if (th->type == ADT7460) in write_both_fan_speed()
147 write_fan_speed(th, speed, 1); in write_both_fan_speed()
150 static void write_fan_speed(struct thermostat *th, int speed, int fan) in write_fan_speed() argument
159 if (th->type == ADT7467 && fan == 1) in write_fan_speed()
162 if (th->last_speed[fan] != speed) { in write_fan_speed()
175 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
177 write_reg(th, MANUAL_MODE[fan], in write_fan_speed()
178 manual | MANUAL_MASK | th->pwm_inv[fan]); in write_fan_speed()
179 write_reg(th, FAN_SPD_SET[fan], speed); in write_fan_speed()
182 if(th->type == ADT7460) { in write_fan_speed()
183 manual = read_reg(th, in write_fan_speed()
186 manual |= th->pwm_inv[fan]; in write_fan_speed()
187 write_reg(th, in write_fan_speed()
190 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
192 manual |= th->pwm_inv[fan]; in write_fan_speed()
193 write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK)); in write_fan_speed()
197 th->last_speed[fan] = speed; in write_fan_speed()
200 static void read_sensors(struct thermostat *th) in read_sensors() argument
205 th->temps[i] = read_reg(th, TEMP_REG[i]); in read_sensors()
209 static void display_stats(struct thermostat *th) in display_stats() argument
211 if (th->temps[0] != th->cached_temp[0] in display_stats()
212 || th->temps[1] != th->cached_temp[1] in display_stats()
213 || th->temps[2] != th->cached_temp[2]) { in display_stats()
218 th->temps[0], th->temps[1], th->temps[2], in display_stats()
219 th->limits[0], th->limits[1], th->limits[2], in display_stats()
220 read_fan_speed(th, FAN_SPEED[0])); in display_stats()
222 th->cached_temp[0] = th->temps[0]; in display_stats()
223 th->cached_temp[1] = th->temps[1]; in display_stats()
224 th->cached_temp[2] = th->temps[2]; in display_stats()
228 static void update_fans_speed (struct thermostat *th) in update_fans_speed() argument
236 int fan_number = (th->type == ADT7460 && i == 2); in update_fans_speed()
237 int var = th->temps[i] - th->limits[i]; in update_fans_speed()
245 if (abs(var - th->last_var[fan_number]) < 2) in update_fans_speed()
261 write_both_fan_speed(th, new_speed); in update_fans_speed()
262 th->last_var[fan_number] = var; in update_fans_speed()
267 if (th->last_speed[fan_number] != 0) in update_fans_speed()
271 write_both_fan_speed(th, 0); in update_fans_speed()
285 struct thermostat* th = arg; in monitor_task() local
294 read_sensors(th); in monitor_task()
296 read_sensors(th); in monitor_task()
300 update_fans_speed(th); in monitor_task()
303 display_stats(th); in monitor_task()
311 static void set_limit(struct thermostat *th, int i) in set_limit() argument
314 th->limits[i] = default_limits_chip[i] + limit_adjust; in set_limit()
315 write_reg(th, LIMIT_REG[i], th->limits[i]); in set_limit()
318 th->limits[i] = default_limits_local[i] + limit_adjust; in set_limit()
324 struct thermostat *th = dev_get_drvdata(dev); \
343 struct thermostat *th = dev_get_drvdata(dev); \
345 th->last_speed[data], \
346 read_fan_speed(th, FAN_SPEED[data]) \
353 struct thermostat *th = dev_get_drvdata(dev); \
360 set_limit(th, i); \
376 BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(th, TEMP_REG[1])))
377 BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(th, TEMP_REG[2])))
378 BUILD_SHOW_FUNC_INT(sensor1_limit, th->limits[1])
379 BUILD_SHOW_FUNC_INT(sensor2_limit, th->limits[2])
390 BUILD_STORE_FUNC_DEG(limit_adjust, th)
416 static void thermostat_create_files(struct thermostat *th) in thermostat_create_files() argument
418 struct device_node *np = th->clt->dev.of_node; in thermostat_create_files()
426 th->pdev = of_platform_device_create(np, "temperatures", NULL); in thermostat_create_files()
427 if (!th->pdev) in thermostat_create_files()
429 dev = &th->pdev->dev; in thermostat_create_files()
430 dev_set_drvdata(dev, th); in thermostat_create_files()
440 if(th->type == ADT7460) in thermostat_create_files()
447 static void thermostat_remove_files(struct thermostat *th) in thermostat_remove_files() argument
451 if (!th->pdev) in thermostat_remove_files()
453 dev = &th->pdev->dev; in thermostat_remove_files()
463 if (th->type == ADT7460) in thermostat_remove_files()
465 of_device_unregister(th->pdev); in thermostat_remove_files()
473 struct thermostat* th; in probe_thermostat() local
501 th = kzalloc(sizeof(struct thermostat), GFP_KERNEL); in probe_thermostat()
502 if (!th) in probe_thermostat()
505 i2c_set_clientdata(client, th); in probe_thermostat()
506 th->clt = client; in probe_thermostat()
507 th->type = id->driver_data; in probe_thermostat()
509 rc = read_reg(th, CONFIG_REG); in probe_thermostat()
512 kfree(th); in probe_thermostat()
520 if (th->type == ADT7460) { in probe_thermostat()
523 write_reg(th, CONFIG_REG, 1); in probe_thermostat()
528 th->initial_limits[i] = read_reg(th, LIMIT_REG[i]); in probe_thermostat()
529 set_limit(th, i); in probe_thermostat()
534 th->initial_limits[0], th->initial_limits[1], in probe_thermostat()
535 th->initial_limits[2], th->limits[0], th->limits[1], in probe_thermostat()
536 th->limits[2]); in probe_thermostat()
539 th->pwm_inv[0] = read_reg(th, MANUAL_MODE[0]) & INVERT_MASK; in probe_thermostat()
540 th->pwm_inv[1] = read_reg(th, MANUAL_MODE[1]) & INVERT_MASK; in probe_thermostat()
543 th->last_speed[0] = -2; in probe_thermostat()
544 th->last_speed[1] = -2; in probe_thermostat()
545 th->last_var[0] = -80; in probe_thermostat()
546 th->last_var[1] = -80; in probe_thermostat()
550 write_both_fan_speed(th, 0); in probe_thermostat()
553 write_both_fan_speed(th, -1); in probe_thermostat()
556 th->thread = kthread_run(monitor_task, th, "kfand"); in probe_thermostat()
557 if (th->thread == ERR_PTR(-ENOMEM)) { in probe_thermostat()
559 th->thread = NULL; in probe_thermostat()
563 thermostat_create_files(th); in probe_thermostat()
570 struct thermostat *th = i2c_get_clientdata(client); in remove_thermostat() local
573 thermostat_remove_files(th); in remove_thermostat()
575 if (th->thread != NULL) in remove_thermostat()
576 kthread_stop(th->thread); in remove_thermostat()
580 th->limits[0], th->limits[1], th->limits[2], in remove_thermostat()
581 th->initial_limits[0], th->initial_limits[1], in remove_thermostat()
582 th->initial_limits[2]); in remove_thermostat()
585 write_reg(th, LIMIT_REG[i], th->initial_limits[i]); in remove_thermostat()
587 write_both_fan_speed(th, -1); in remove_thermostat()
589 kfree(th); in remove_thermostat()