Lines Matching full:th
91 static void write_both_fan_speed(struct thermostat *th, int speed);
92 static void write_fan_speed(struct thermostat *th, int speed, int fan);
95 write_reg(struct thermostat* th, int reg, u8 data) in write_reg() argument
102 rc = i2c_master_send(th->clt, (const char *)tmp, 2); in write_reg()
111 read_reg(struct thermostat* th, int reg) in read_reg() argument
117 rc = i2c_master_send(th->clt, ®_addr, 1); in read_reg()
122 rc = i2c_master_recv(th->clt, (char *)&data, 1); in read_reg()
128 static int read_fan_speed(struct thermostat *th, u8 addr) in read_fan_speed() argument
134 tmp[1] = read_reg(th, addr); in read_fan_speed()
135 tmp[0] = read_reg(th, addr + 1); in read_fan_speed()
142 static void write_both_fan_speed(struct thermostat *th, int speed) in write_both_fan_speed() argument
144 write_fan_speed(th, speed, 0); in write_both_fan_speed()
145 if (th->type == ADT7460) in write_both_fan_speed()
146 write_fan_speed(th, speed, 1); in write_both_fan_speed()
149 static void write_fan_speed(struct thermostat *th, int speed, int fan) in write_fan_speed() argument
158 if (th->type == ADT7467 && fan == 1) in write_fan_speed()
161 if (th->last_speed[fan] != speed) { in write_fan_speed()
174 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
176 write_reg(th, MANUAL_MODE[fan], in write_fan_speed()
177 manual | MANUAL_MASK | th->pwm_inv[fan]); in write_fan_speed()
178 write_reg(th, FAN_SPD_SET[fan], speed); in write_fan_speed()
181 if(th->type == ADT7460) { in write_fan_speed()
182 manual = read_reg(th, in write_fan_speed()
185 manual |= th->pwm_inv[fan]; in write_fan_speed()
186 write_reg(th, in write_fan_speed()
189 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
191 manual |= th->pwm_inv[fan]; in write_fan_speed()
192 write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK)); in write_fan_speed()
196 th->last_speed[fan] = speed; in write_fan_speed()
199 static void read_sensors(struct thermostat *th) in read_sensors() argument
204 th->temps[i] = read_reg(th, TEMP_REG[i]); in read_sensors()
208 static void display_stats(struct thermostat *th) in display_stats() argument
210 if (th->temps[0] != th->cached_temp[0] in display_stats()
211 || th->temps[1] != th->cached_temp[1] in display_stats()
212 || th->temps[2] != th->cached_temp[2]) { in display_stats()
217 th->temps[0], th->temps[1], th->temps[2], in display_stats()
218 th->limits[0], th->limits[1], th->limits[2], in display_stats()
219 read_fan_speed(th, FAN_SPEED[0])); in display_stats()
221 th->cached_temp[0] = th->temps[0]; in display_stats()
222 th->cached_temp[1] = th->temps[1]; in display_stats()
223 th->cached_temp[2] = th->temps[2]; in display_stats()
227 static void update_fans_speed (struct thermostat *th) in update_fans_speed() argument
235 int fan_number = (th->type == ADT7460 && i == 2); in update_fans_speed()
236 int var = th->temps[i] - th->limits[i]; in update_fans_speed()
244 if (abs(var - th->last_var[fan_number]) < 2) in update_fans_speed()
260 write_both_fan_speed(th, new_speed); in update_fans_speed()
261 th->last_var[fan_number] = var; in update_fans_speed()
266 if (th->last_speed[fan_number] != 0) in update_fans_speed()
270 write_both_fan_speed(th, 0); in update_fans_speed()
284 struct thermostat* th = arg; in monitor_task() local
293 read_sensors(th); in monitor_task()
295 read_sensors(th); in monitor_task()
299 update_fans_speed(th); in monitor_task()
302 display_stats(th); in monitor_task()
310 static void set_limit(struct thermostat *th, int i) in set_limit() argument
313 th->limits[i] = default_limits_chip[i] + limit_adjust; in set_limit()
314 write_reg(th, LIMIT_REG[i], th->limits[i]); in set_limit()
317 th->limits[i] = default_limits_local[i] + limit_adjust; in set_limit()
323 struct thermostat *th = dev_get_drvdata(dev); \
342 struct thermostat *th = dev_get_drvdata(dev); \
344 th->last_speed[data], \
345 read_fan_speed(th, FAN_SPEED[data]) \
352 struct thermostat *th = dev_get_drvdata(dev); \
359 set_limit(th, i); \
375 BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(th, TEMP_REG[1])))
376 BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(th, TEMP_REG[2])))
377 BUILD_SHOW_FUNC_INT(sensor1_limit, th->limits[1])
378 BUILD_SHOW_FUNC_INT(sensor2_limit, th->limits[2])
389 BUILD_STORE_FUNC_DEG(limit_adjust, th)
415 static void thermostat_create_files(struct thermostat *th) in thermostat_create_files() argument
417 struct device_node *np = th->clt->dev.of_node; in thermostat_create_files()
425 th->pdev = of_platform_device_create(np, "temperatures", NULL); in thermostat_create_files()
426 if (!th->pdev) in thermostat_create_files()
428 dev = &th->pdev->dev; in thermostat_create_files()
429 dev_set_drvdata(dev, th); in thermostat_create_files()
439 if(th->type == ADT7460) in thermostat_create_files()
446 static void thermostat_remove_files(struct thermostat *th) in thermostat_remove_files() argument
450 if (!th->pdev) in thermostat_remove_files()
452 dev = &th->pdev->dev; in thermostat_remove_files()
462 if (th->type == ADT7460) in thermostat_remove_files()
464 of_device_unregister(th->pdev); in thermostat_remove_files()
472 struct thermostat* th; in probe_thermostat() local
500 th = kzalloc(sizeof(struct thermostat), GFP_KERNEL); in probe_thermostat()
501 if (!th) in probe_thermostat()
504 i2c_set_clientdata(client, th); in probe_thermostat()
505 th->clt = client; in probe_thermostat()
506 th->type = id->driver_data; in probe_thermostat()
508 rc = read_reg(th, CONFIG_REG); in probe_thermostat()
511 kfree(th); in probe_thermostat()
519 if (th->type == ADT7460) { in probe_thermostat()
522 write_reg(th, CONFIG_REG, 1); in probe_thermostat()
527 th->initial_limits[i] = read_reg(th, LIMIT_REG[i]); in probe_thermostat()
528 set_limit(th, i); in probe_thermostat()
533 th->initial_limits[0], th->initial_limits[1], in probe_thermostat()
534 th->initial_limits[2], th->limits[0], th->limits[1], in probe_thermostat()
535 th->limits[2]); in probe_thermostat()
538 th->pwm_inv[0] = read_reg(th, MANUAL_MODE[0]) & INVERT_MASK; in probe_thermostat()
539 th->pwm_inv[1] = read_reg(th, MANUAL_MODE[1]) & INVERT_MASK; in probe_thermostat()
542 th->last_speed[0] = -2; in probe_thermostat()
543 th->last_speed[1] = -2; in probe_thermostat()
544 th->last_var[0] = -80; in probe_thermostat()
545 th->last_var[1] = -80; in probe_thermostat()
549 write_both_fan_speed(th, 0); in probe_thermostat()
552 write_both_fan_speed(th, -1); in probe_thermostat()
555 th->thread = kthread_run(monitor_task, th, "kfand"); in probe_thermostat()
556 if (th->thread == ERR_PTR(-ENOMEM)) { in probe_thermostat()
558 th->thread = NULL; in probe_thermostat()
562 thermostat_create_files(th); in probe_thermostat()
569 struct thermostat *th = i2c_get_clientdata(client); in remove_thermostat() local
572 thermostat_remove_files(th); in remove_thermostat()
574 if (th->thread != NULL) in remove_thermostat()
575 kthread_stop(th->thread); in remove_thermostat()
579 th->limits[0], th->limits[1], th->limits[2], in remove_thermostat()
580 th->initial_limits[0], th->initial_limits[1], in remove_thermostat()
581 th->initial_limits[2]); in remove_thermostat()
584 write_reg(th, LIMIT_REG[i], th->initial_limits[i]); in remove_thermostat()
586 write_both_fan_speed(th, -1); in remove_thermostat()
588 kfree(th); in remove_thermostat()