Lines Matching full:th

90 static void write_both_fan_speed(struct thermostat *th, int speed);
91 static void write_fan_speed(struct thermostat *th, int speed, int fan);
94 write_reg(struct thermostat* th, int reg, u8 data) in write_reg() argument
101 rc = i2c_master_send(th->clt, (const char *)tmp, 2); in write_reg()
110 read_reg(struct thermostat* th, int reg) in read_reg() argument
116 rc = i2c_master_send(th->clt, &reg_addr, 1); in read_reg()
121 rc = i2c_master_recv(th->clt, (char *)&data, 1); in read_reg()
127 static int read_fan_speed(struct thermostat *th, u8 addr) in read_fan_speed() argument
133 tmp[1] = read_reg(th, addr); in read_fan_speed()
134 tmp[0] = read_reg(th, addr + 1); in read_fan_speed()
141 static void write_both_fan_speed(struct thermostat *th, int speed) in write_both_fan_speed() argument
143 write_fan_speed(th, speed, 0); in write_both_fan_speed()
144 if (th->type == ADT7460) in write_both_fan_speed()
145 write_fan_speed(th, speed, 1); in write_both_fan_speed()
148 static void write_fan_speed(struct thermostat *th, int speed, int fan) in write_fan_speed() argument
157 if (th->type == ADT7467 && fan == 1) in write_fan_speed()
160 if (th->last_speed[fan] != speed) { in write_fan_speed()
173 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
175 write_reg(th, MANUAL_MODE[fan], in write_fan_speed()
176 manual | MANUAL_MASK | th->pwm_inv[fan]); in write_fan_speed()
177 write_reg(th, FAN_SPD_SET[fan], speed); in write_fan_speed()
180 if(th->type == ADT7460) { in write_fan_speed()
181 manual = read_reg(th, in write_fan_speed()
184 manual |= th->pwm_inv[fan]; in write_fan_speed()
185 write_reg(th, in write_fan_speed()
188 manual = read_reg(th, MANUAL_MODE[fan]); in write_fan_speed()
190 manual |= th->pwm_inv[fan]; in write_fan_speed()
191 write_reg(th, MANUAL_MODE[fan], manual&(~AUTO_MASK)); in write_fan_speed()
195 th->last_speed[fan] = speed; in write_fan_speed()
198 static void read_sensors(struct thermostat *th) in read_sensors() argument
203 th->temps[i] = read_reg(th, TEMP_REG[i]); in read_sensors()
207 static void display_stats(struct thermostat *th) in display_stats() argument
209 if (th->temps[0] != th->cached_temp[0] in display_stats()
210 || th->temps[1] != th->cached_temp[1] in display_stats()
211 || th->temps[2] != th->cached_temp[2]) { in display_stats()
216 th->temps[0], th->temps[1], th->temps[2], in display_stats()
217 th->limits[0], th->limits[1], th->limits[2], in display_stats()
218 read_fan_speed(th, FAN_SPEED[0])); in display_stats()
220 th->cached_temp[0] = th->temps[0]; in display_stats()
221 th->cached_temp[1] = th->temps[1]; in display_stats()
222 th->cached_temp[2] = th->temps[2]; in display_stats()
226 static void update_fans_speed (struct thermostat *th) in update_fans_speed() argument
234 int fan_number = (th->type == ADT7460 && i == 2); in update_fans_speed()
235 int var = th->temps[i] - th->limits[i]; in update_fans_speed()
243 if (abs(var - th->last_var[fan_number]) < 2) in update_fans_speed()
259 write_both_fan_speed(th, new_speed); in update_fans_speed()
260 th->last_var[fan_number] = var; in update_fans_speed()
265 if (th->last_speed[fan_number] != 0) in update_fans_speed()
269 write_both_fan_speed(th, 0); in update_fans_speed()
283 struct thermostat* th = arg; in monitor_task() local
292 read_sensors(th); in monitor_task()
294 read_sensors(th); in monitor_task()
298 update_fans_speed(th); in monitor_task()
301 display_stats(th); in monitor_task()
309 static void set_limit(struct thermostat *th, int i) in set_limit() argument
312 th->limits[i] = default_limits_chip[i] + limit_adjust; in set_limit()
313 write_reg(th, LIMIT_REG[i], th->limits[i]); in set_limit()
316 th->limits[i] = default_limits_local[i] + limit_adjust; in set_limit()
322 struct thermostat *th = dev_get_drvdata(dev); \
341 struct thermostat *th = dev_get_drvdata(dev); \
343 th->last_speed[data], \
344 read_fan_speed(th, FAN_SPEED[data]) \
351 struct thermostat *th = dev_get_drvdata(dev); \
358 set_limit(th, i); \
374 BUILD_SHOW_FUNC_INT(sensor1_temperature, (read_reg(th, TEMP_REG[1])))
375 BUILD_SHOW_FUNC_INT(sensor2_temperature, (read_reg(th, TEMP_REG[2])))
376 BUILD_SHOW_FUNC_INT(sensor1_limit, th->limits[1])
377 BUILD_SHOW_FUNC_INT(sensor2_limit, th->limits[2])
388 BUILD_STORE_FUNC_DEG(limit_adjust, th)
414 static void thermostat_create_files(struct thermostat *th) in thermostat_create_files() argument
416 struct device_node *np = th->clt->dev.of_node; in thermostat_create_files()
424 th->pdev = of_platform_device_create(np, "temperatures", NULL); in thermostat_create_files()
425 if (!th->pdev) in thermostat_create_files()
427 dev = &th->pdev->dev; in thermostat_create_files()
428 dev_set_drvdata(dev, th); in thermostat_create_files()
438 if(th->type == ADT7460) in thermostat_create_files()
445 static void thermostat_remove_files(struct thermostat *th) in thermostat_remove_files() argument
449 if (!th->pdev) in thermostat_remove_files()
451 dev = &th->pdev->dev; in thermostat_remove_files()
461 if (th->type == ADT7460) in thermostat_remove_files()
463 of_device_unregister(th->pdev); in thermostat_remove_files()
471 struct thermostat* th; in probe_thermostat() local
499 th = kzalloc(sizeof(struct thermostat), GFP_KERNEL); in probe_thermostat()
500 if (!th) in probe_thermostat()
503 i2c_set_clientdata(client, th); in probe_thermostat()
504 th->clt = client; in probe_thermostat()
505 th->type = id->driver_data; in probe_thermostat()
507 rc = read_reg(th, CONFIG_REG); in probe_thermostat()
510 kfree(th); in probe_thermostat()
518 if (th->type == ADT7460) { in probe_thermostat()
521 write_reg(th, CONFIG_REG, 1); in probe_thermostat()
526 th->initial_limits[i] = read_reg(th, LIMIT_REG[i]); in probe_thermostat()
527 set_limit(th, i); in probe_thermostat()
532 th->initial_limits[0], th->initial_limits[1], in probe_thermostat()
533 th->initial_limits[2], th->limits[0], th->limits[1], in probe_thermostat()
534 th->limits[2]); in probe_thermostat()
537 th->pwm_inv[0] = read_reg(th, MANUAL_MODE[0]) & INVERT_MASK; in probe_thermostat()
538 th->pwm_inv[1] = read_reg(th, MANUAL_MODE[1]) & INVERT_MASK; in probe_thermostat()
541 th->last_speed[0] = -2; in probe_thermostat()
542 th->last_speed[1] = -2; in probe_thermostat()
543 th->last_var[0] = -80; in probe_thermostat()
544 th->last_var[1] = -80; in probe_thermostat()
548 write_both_fan_speed(th, 0); in probe_thermostat()
551 write_both_fan_speed(th, -1); in probe_thermostat()
554 th->thread = kthread_run(monitor_task, th, "kfand"); in probe_thermostat()
555 if (th->thread == ERR_PTR(-ENOMEM)) { in probe_thermostat()
557 th->thread = NULL; in probe_thermostat()
561 thermostat_create_files(th); in probe_thermostat()
568 struct thermostat *th = i2c_get_clientdata(client); in remove_thermostat() local
571 thermostat_remove_files(th); in remove_thermostat()
573 if (th->thread != NULL) in remove_thermostat()
574 kthread_stop(th->thread); in remove_thermostat()
578 th->limits[0], th->limits[1], th->limits[2], in remove_thermostat()
579 th->initial_limits[0], th->initial_limits[1], in remove_thermostat()
580 th->initial_limits[2]); in remove_thermostat()
583 write_reg(th, LIMIT_REG[i], th->initial_limits[i]); in remove_thermostat()
585 write_both_fan_speed(th, -1); in remove_thermostat()
587 kfree(th); in remove_thermostat()