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