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