28 #include <linux/module.h>
30 #include <linux/slab.h>
32 #include <linux/i2c.h>
42 static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
51 #define ADM1029_REG_MAN_ID 0x0D
52 #define ADM1029_REG_CHIP_ID 0x0E
53 #define ADM1029_REG_CONFIG 0x01
54 #define ADM1029_REG_NB_FAN_SUPPORT 0x02
56 #define ADM1029_REG_TEMP_DEVICES_INSTALLED 0x06
58 #define ADM1029_REG_LOCAL_TEMP 0xA0
59 #define ADM1029_REG_REMOTE1_TEMP 0xA1
60 #define ADM1029_REG_REMOTE2_TEMP 0xA2
62 #define ADM1029_REG_LOCAL_TEMP_HIGH 0x90
63 #define ADM1029_REG_REMOTE1_TEMP_HIGH 0x91
64 #define ADM1029_REG_REMOTE2_TEMP_HIGH 0x92
66 #define ADM1029_REG_LOCAL_TEMP_LOW 0x98
67 #define ADM1029_REG_REMOTE1_TEMP_LOW 0x99
68 #define ADM1029_REG_REMOTE2_TEMP_LOW 0x9A
70 #define ADM1029_REG_FAN1 0x70
71 #define ADM1029_REG_FAN2 0x71
73 #define ADM1029_REG_FAN1_MIN 0x78
74 #define ADM1029_REG_FAN2_MIN 0x79
76 #define ADM1029_REG_FAN1_CONFIG 0x68
77 #define ADM1029_REG_FAN2_CONFIG 0x69
79 #define TEMP_FROM_REG(val) ((val) * 1000)
81 #define DIV_FROM_REG(val) (1 << (((val) >> 6) - 1))
84 static const u8 ADM1029_REG_TEMP[] = {
96 static const u8 ADM1029_REG_FAN[] = {
103 static const u8 ADM1029_REG_FAN_DIV[] = {
135 .probe = adm1029_probe,
136 .remove = adm1029_remove,
137 .id_table = adm1029_id,
138 .detect = adm1029_detect,
139 .address_list = normal_i2c,
184 return sprintf(buf,
"%d\n", val);
205 int ret = kstrtol(buf, 10, &val);
213 ADM1029_REG_FAN_DIV[attr->
index]);
227 dev_err(&client->
dev,
"fan_div value %ld not "
228 "supported. Choose one of 1, 2 or 4!\n", val);
232 reg = (reg & 0x3F) | (val << 6);
236 ADM1029_REG_FAN_DIV[attr->
index], reg);
265 show_fan_div, set_fan_div, 0);
267 show_fan_div, set_fan_div, 1);
269 static struct attribute *adm1029_attributes[] = {
270 &sensor_dev_attr_temp1_input.dev_attr.attr,
271 &sensor_dev_attr_temp1_min.dev_attr.attr,
272 &sensor_dev_attr_temp1_max.dev_attr.attr,
273 &sensor_dev_attr_temp2_input.dev_attr.attr,
274 &sensor_dev_attr_temp2_min.dev_attr.attr,
275 &sensor_dev_attr_temp2_max.dev_attr.attr,
276 &sensor_dev_attr_temp3_input.dev_attr.attr,
277 &sensor_dev_attr_temp3_min.dev_attr.attr,
278 &sensor_dev_attr_temp3_max.dev_attr.attr,
279 &sensor_dev_attr_fan1_input.dev_attr.attr,
280 &sensor_dev_attr_fan2_input.dev_attr.attr,
281 &sensor_dev_attr_fan1_min.dev_attr.attr,
282 &sensor_dev_attr_fan2_min.dev_attr.attr,
283 &sensor_dev_attr_fan1_div.dev_attr.attr,
284 &sensor_dev_attr_fan2_div.dev_attr.attr,
289 .attrs = adm1029_attributes,
297 static int adm1029_detect(
struct i2c_client *client,
301 u8 man_id,
chip_id, temp_devices_installed, nb_fan_support;
320 if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01
321 || nb_fan_support != 0x03)
324 if ((chip_id & 0xF0) != 0x00) {
329 pr_info(
"adm1029: Unknown major revision %x, "
330 "please let us know\n", chip_id);
339 static int adm1029_probe(
struct i2c_client *client,
350 i2c_set_clientdata(client, data);
357 if (adm1029_init_client(client) == 0)
368 goto exit_remove_files;
378 static int adm1029_init_client(
struct i2c_client *client)
382 if ((config & 0x10) == 0) {
388 if ((config & 0x10) == 0) {
389 dev_err(&client->
dev,
"Initialization failed!\n");
395 static int adm1029_remove(
struct i2c_client *client)
422 dev_dbg(&client->
dev,
"Updating adm1029 data\n");
424 for (nr = 0; nr <
ARRAY_SIZE(ADM1029_REG_TEMP); nr++) {
427 ADM1029_REG_TEMP[nr]);
429 for (nr = 0; nr <
ARRAY_SIZE(ADM1029_REG_FAN); nr++) {
432 ADM1029_REG_FAN[nr]);
434 for (nr = 0; nr <
ARRAY_SIZE(ADM1029_REG_FAN_DIV); nr++) {
437 ADM1029_REG_FAN_DIV[nr]);