23 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/i2c.h>
36 static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e,
I2C_CLIENT_END };
41 static unsigned short adm1022_temp3[16];
42 static unsigned int adm1022_temp3_num;
45 "to enable 3rd temperature (ADM1022 only)");
50 #define THMC50_REG_CONF 0x40
51 #define THMC50_REG_COMPANY_ID 0x3E
52 #define THMC50_REG_DIE_CODE 0x3F
53 #define THMC50_REG_ANALOG_OUT 0x19
58 #define THMC50_REG_INTR 0x41
60 static const u8 THMC50_REG_TEMP[] = { 0x27, 0x26, 0x20 };
61 static const u8 THMC50_REG_TEMP_MIN[] = { 0x3A, 0x38, 0x2C };
62 static const u8 THMC50_REG_TEMP_MAX[] = { 0x39, 0x37, 0x2B };
63 static const u8 THMC50_REG_TEMP_CRITICAL[] = { 0x13, 0x14, 0x14 };
64 static const u8 THMC50_REG_TEMP_DEFAULT[] = { 0x17, 0x18, 0x18 };
66 #define THMC50_REG_CONF_nFANOFF 0x20
67 #define THMC50_REG_CONF_PROGRAMMED 0x08
108 .probe = thmc50_probe,
109 .remove = thmc50_remove,
110 .id_table = thmc50_id,
111 .detect = thmc50_detect,
112 .address_list = normal_i2c,
132 err = kstrtoul(buf, 10, &tmp);
137 data->
analog_out = SENSORS_LIMIT(tmp, 0, 255);
164 struct thmc50_data *data = thmc50_update_device(dev);
172 struct thmc50_data *data = thmc50_update_device(dev);
177 const char *buf,
size_t count)
181 struct thmc50_data *data = i2c_get_clientdata(client);
185 err = kstrtol(buf, 10, &val);
190 data->
temp_min[
nr] = SENSORS_LIMIT(val / 1000, -128, 127);
201 struct thmc50_data *data = thmc50_update_device(dev);
206 const char *buf,
size_t count)
210 struct thmc50_data *data = i2c_get_clientdata(client);
214 err = kstrtol(buf, 10, &val);
219 data->
temp_max[
nr] = SENSORS_LIMIT(val / 1000, -128, 127);
231 struct thmc50_data *data = thmc50_update_device(dev);
239 struct thmc50_data *data = thmc50_update_device(dev);
244 #define temp_reg(offset) \
245 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \
247 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
248 show_temp_min, set_temp_min, offset - 1); \
249 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
250 show_temp_max, set_temp_max, offset - 1); \
251 static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO, \
252 show_temp_critical, NULL, offset - 1);
268 static struct attribute *thmc50_attributes[] = {
269 &sensor_dev_attr_temp1_max.dev_attr.attr,
270 &sensor_dev_attr_temp1_min.dev_attr.attr,
271 &sensor_dev_attr_temp1_input.dev_attr.attr,
272 &sensor_dev_attr_temp1_crit.dev_attr.attr,
273 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
274 &sensor_dev_attr_temp2_max.dev_attr.attr,
275 &sensor_dev_attr_temp2_min.dev_attr.attr,
276 &sensor_dev_attr_temp2_input.dev_attr.attr,
277 &sensor_dev_attr_temp2_crit.dev_attr.attr,
278 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
279 &sensor_dev_attr_temp2_fault.dev_attr.attr,
280 &sensor_dev_attr_pwm1.dev_attr.attr,
281 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
286 .attrs = thmc50_attributes,
290 static struct attribute *temp3_attributes[] = {
291 &sensor_dev_attr_temp3_max.dev_attr.attr,
292 &sensor_dev_attr_temp3_min.dev_attr.attr,
293 &sensor_dev_attr_temp3_input.dev_attr.attr,
294 &sensor_dev_attr_temp3_crit.dev_attr.attr,
295 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
296 &sensor_dev_attr_temp3_fault.dev_attr.attr,
301 .attrs = temp3_attributes,
305 static int thmc50_detect(
struct i2c_client *client,
312 const char *type_name;
316 "smbus byte data not supported!\n");
320 pr_debug(
"thmc50: Probing for THMC50 at 0x%2X on bus %d\n",
326 if (revision < 0xc0 || (config & 0x10))
329 if (company == 0x41) {
330 int id = i2c_adapter_id(client->
adapter);
333 type_name =
"adm1022";
334 for (i = 0; i + 1 < adm1022_temp3_num; i += 2)
335 if (adm1022_temp3[i] ==
id &&
336 adm1022_temp3[i + 1] == client->
addr) {
344 }
else if (company == 0x49) {
345 type_name =
"thmc50";
347 pr_debug(
"thmc50: Detection of THMC50/ADM1022 failed\n");
351 pr_debug(
"thmc50: Detected %s (version %x, revision %x)\n",
352 type_name, (revision >> 4) - 0
xc, revision & 0xf);
359 static int thmc50_probe(
struct i2c_client *client,
370 i2c_set_clientdata(client, data);
371 data->
type =
id->driver_data;
374 thmc50_init_client(client);
385 goto exit_remove_sysfs_thmc50;
392 goto exit_remove_sysfs;
400 exit_remove_sysfs_thmc50:
405 static int thmc50_remove(
struct i2c_client *client)
407 struct thmc50_data *data = i2c_get_clientdata(client);
417 static void thmc50_init_client(
struct i2c_client *client)
419 struct thmc50_data *data = i2c_get_clientdata(client);
440 struct thmc50_data *data = i2c_get_clientdata(client);
454 for (i = 0; i < temps; i++) {
458 THMC50_REG_TEMP_MAX[i]);
460 THMC50_REG_TEMP_MIN[i]);
463 prog ? THMC50_REG_TEMP_CRITICAL[i]
464 : THMC50_REG_TEMP_DEFAULT[i]);