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