adm1025.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * adm1025.c
  3. *
  4. * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com>
  5. * Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
  6. *
  7. * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6
  8. * voltages (including its own power source) and up to two temperatures
  9. * (its own plus up to one external one). Voltages are scaled internally
  10. * (which is not the common way) with ratios such that the nominal value
  11. * of each voltage correspond to a register value of 192 (which means a
  12. * resolution of about 0.5% of the nominal value). Temperature values are
  13. * reported with a 1 deg resolution and a 3 deg accuracy. Complete
  14. * datasheet can be obtained from Analog's website at:
  15. * http://www.analog.com/Analog_Root/productPage/productHome/0,2121,ADM1025,00.html
  16. *
  17. * This driver also supports the ADM1025A, which differs from the ADM1025
  18. * only in that it has "open-drain VID inputs while the ADM1025 has
  19. * on-chip 100k pull-ups on the VID inputs". It doesn't make any
  20. * difference for us.
  21. *
  22. * This driver also supports the NE1619, a sensor chip made by Philips.
  23. * That chip is similar to the ADM1025A, with a few differences. The only
  24. * difference that matters to us is that the NE1619 has only two possible
  25. * addresses while the ADM1025A has a third one. Complete datasheet can be
  26. * obtained from Philips's website at:
  27. * http://www.semiconductors.philips.com/pip/NE1619DS.html
  28. *
  29. * Since the ADM1025 was the first chipset supported by this driver, most
  30. * comments will refer to this chipset, but are actually general and
  31. * concern all supported chipsets, unless mentioned otherwise.
  32. *
  33. * This program is free software; you can redistribute it and/or modify
  34. * it under the terms of the GNU General Public License as published by
  35. * the Free Software Foundation; either version 2 of the License, or
  36. * (at your option) any later version.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU General Public License
  44. * along with this program; if not, write to the Free Software
  45. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46. */
  47. #include <linux/module.h>
  48. #include <linux/init.h>
  49. #include <linux/slab.h>
  50. #include <linux/jiffies.h>
  51. #include <linux/i2c.h>
  52. #include <linux/hwmon.h>
  53. #include <linux/hwmon-sysfs.h>
  54. #include <linux/hwmon-vid.h>
  55. #include <linux/err.h>
  56. #include <linux/mutex.h>
  57. /*
  58. * Addresses to scan
  59. * ADM1025 and ADM1025A have three possible addresses: 0x2c, 0x2d and 0x2e.
  60. * NE1619 has two possible addresses: 0x2c and 0x2d.
  61. */
  62. static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
  63. /*
  64. * Insmod parameters
  65. */
  66. I2C_CLIENT_INSMOD_2(adm1025, ne1619);
  67. /*
  68. * The ADM1025 registers
  69. */
  70. #define ADM1025_REG_MAN_ID 0x3E
  71. #define ADM1025_REG_CHIP_ID 0x3F
  72. #define ADM1025_REG_CONFIG 0x40
  73. #define ADM1025_REG_STATUS1 0x41
  74. #define ADM1025_REG_STATUS2 0x42
  75. #define ADM1025_REG_IN(nr) (0x20 + (nr))
  76. #define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2)
  77. #define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2)
  78. #define ADM1025_REG_TEMP(nr) (0x26 + (nr))
  79. #define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2)
  80. #define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2)
  81. #define ADM1025_REG_VID 0x47
  82. #define ADM1025_REG_VID4 0x49
  83. /*
  84. * Conversions and various macros
  85. * The ADM1025 uses signed 8-bit values for temperatures.
  86. */
  87. static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
  88. #define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
  89. #define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
  90. (val) * 192 >= (scale) * 255 ? 255 : \
  91. ((val) * 192 + (scale)/2) / (scale))
  92. #define TEMP_FROM_REG(reg) ((reg) * 1000)
  93. #define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
  94. (val) >= 126500 ? 127 : \
  95. (((val) < 0 ? (val)-500 : (val)+500) / 1000))
  96. /*
  97. * Functions declaration
  98. */
  99. static int adm1025_probe(struct i2c_client *client,
  100. const struct i2c_device_id *id);
  101. static int adm1025_detect(struct i2c_client *client, int kind,
  102. struct i2c_board_info *info);
  103. static void adm1025_init_client(struct i2c_client *client);
  104. static int adm1025_remove(struct i2c_client *client);
  105. static struct adm1025_data *adm1025_update_device(struct device *dev);
  106. /*
  107. * Driver data (common to all clients)
  108. */
  109. static const struct i2c_device_id adm1025_id[] = {
  110. { "adm1025", adm1025 },
  111. { "ne1619", ne1619 },
  112. { }
  113. };
  114. MODULE_DEVICE_TABLE(i2c, adm1025_id);
  115. static struct i2c_driver adm1025_driver = {
  116. .class = I2C_CLASS_HWMON,
  117. .driver = {
  118. .name = "adm1025",
  119. },
  120. .probe = adm1025_probe,
  121. .remove = adm1025_remove,
  122. .id_table = adm1025_id,
  123. .detect = adm1025_detect,
  124. .address_data = &addr_data,
  125. };
  126. /*
  127. * Client data (each client gets its own)
  128. */
  129. struct adm1025_data {
  130. struct device *hwmon_dev;
  131. struct mutex update_lock;
  132. char valid; /* zero until following fields are valid */
  133. unsigned long last_updated; /* in jiffies */
  134. u8 in[6]; /* register value */
  135. u8 in_max[6]; /* register value */
  136. u8 in_min[6]; /* register value */
  137. s8 temp[2]; /* register value */
  138. s8 temp_min[2]; /* register value */
  139. s8 temp_max[2]; /* register value */
  140. u16 alarms; /* register values, combined */
  141. u8 vid; /* register values, combined */
  142. u8 vrm;
  143. };
  144. /*
  145. * Sysfs stuff
  146. */
  147. static ssize_t
  148. show_in(struct device *dev, struct device_attribute *attr, char *buf)
  149. {
  150. int index = to_sensor_dev_attr(attr)->index;
  151. struct adm1025_data *data = adm1025_update_device(dev);
  152. return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
  153. in_scale[index]));
  154. }
  155. static ssize_t
  156. show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
  157. {
  158. int index = to_sensor_dev_attr(attr)->index;
  159. struct adm1025_data *data = adm1025_update_device(dev);
  160. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
  161. in_scale[index]));
  162. }
  163. static ssize_t
  164. show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
  165. {
  166. int index = to_sensor_dev_attr(attr)->index;
  167. struct adm1025_data *data = adm1025_update_device(dev);
  168. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
  169. in_scale[index]));
  170. }
  171. static ssize_t
  172. show_temp(struct device *dev, struct device_attribute *attr, char *buf)
  173. {
  174. int index = to_sensor_dev_attr(attr)->index;
  175. struct adm1025_data *data = adm1025_update_device(dev);
  176. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
  177. }
  178. static ssize_t
  179. show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
  180. {
  181. int index = to_sensor_dev_attr(attr)->index;
  182. struct adm1025_data *data = adm1025_update_device(dev);
  183. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
  184. }
  185. static ssize_t
  186. show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
  187. {
  188. int index = to_sensor_dev_attr(attr)->index;
  189. struct adm1025_data *data = adm1025_update_device(dev);
  190. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
  191. }
  192. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  193. const char *buf, size_t count)
  194. {
  195. int index = to_sensor_dev_attr(attr)->index;
  196. struct i2c_client *client = to_i2c_client(dev);
  197. struct adm1025_data *data = i2c_get_clientdata(client);
  198. long val = simple_strtol(buf, NULL, 10);
  199. mutex_lock(&data->update_lock);
  200. data->in_min[index] = IN_TO_REG(val, in_scale[index]);
  201. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
  202. data->in_min[index]);
  203. mutex_unlock(&data->update_lock);
  204. return count;
  205. }
  206. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  207. const char *buf, size_t count)
  208. {
  209. int index = to_sensor_dev_attr(attr)->index;
  210. struct i2c_client *client = to_i2c_client(dev);
  211. struct adm1025_data *data = i2c_get_clientdata(client);
  212. long val = simple_strtol(buf, NULL, 10);
  213. mutex_lock(&data->update_lock);
  214. data->in_max[index] = IN_TO_REG(val, in_scale[index]);
  215. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
  216. data->in_max[index]);
  217. mutex_unlock(&data->update_lock);
  218. return count;
  219. }
  220. #define set_in(offset) \
  221. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  222. show_in, NULL, offset); \
  223. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
  224. show_in_min, set_in_min, offset); \
  225. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
  226. show_in_max, set_in_max, offset)
  227. set_in(0);
  228. set_in(1);
  229. set_in(2);
  230. set_in(3);
  231. set_in(4);
  232. set_in(5);
  233. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  234. const char *buf, size_t count)
  235. {
  236. int index = to_sensor_dev_attr(attr)->index;
  237. struct i2c_client *client = to_i2c_client(dev);
  238. struct adm1025_data *data = i2c_get_clientdata(client);
  239. long val = simple_strtol(buf, NULL, 10);
  240. mutex_lock(&data->update_lock);
  241. data->temp_min[index] = TEMP_TO_REG(val);
  242. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
  243. data->temp_min[index]);
  244. mutex_unlock(&data->update_lock);
  245. return count;
  246. }
  247. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  248. const char *buf, size_t count)
  249. {
  250. int index = to_sensor_dev_attr(attr)->index;
  251. struct i2c_client *client = to_i2c_client(dev);
  252. struct adm1025_data *data = i2c_get_clientdata(client);
  253. long val = simple_strtol(buf, NULL, 10);
  254. mutex_lock(&data->update_lock);
  255. data->temp_max[index] = TEMP_TO_REG(val);
  256. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
  257. data->temp_max[index]);
  258. mutex_unlock(&data->update_lock);
  259. return count;
  260. }
  261. #define set_temp(offset) \
  262. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  263. show_temp, NULL, offset - 1); \
  264. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
  265. show_temp_min, set_temp_min, offset - 1); \
  266. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
  267. show_temp_max, set_temp_max, offset - 1)
  268. set_temp(1);
  269. set_temp(2);
  270. static ssize_t
  271. show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
  272. {
  273. struct adm1025_data *data = adm1025_update_device(dev);
  274. return sprintf(buf, "%u\n", data->alarms);
  275. }
  276. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  277. static ssize_t
  278. show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
  279. {
  280. int bitnr = to_sensor_dev_attr(attr)->index;
  281. struct adm1025_data *data = adm1025_update_device(dev);
  282. return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  283. }
  284. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  285. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  286. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  287. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  288. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
  289. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
  290. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
  291. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
  292. static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
  293. static ssize_t
  294. show_vid(struct device *dev, struct device_attribute *attr, char *buf)
  295. {
  296. struct adm1025_data *data = adm1025_update_device(dev);
  297. return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
  298. }
  299. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
  300. static ssize_t
  301. show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
  302. {
  303. struct adm1025_data *data = dev_get_drvdata(dev);
  304. return sprintf(buf, "%u\n", data->vrm);
  305. }
  306. static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
  307. const char *buf, size_t count)
  308. {
  309. struct adm1025_data *data = dev_get_drvdata(dev);
  310. data->vrm = simple_strtoul(buf, NULL, 10);
  311. return count;
  312. }
  313. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
  314. /*
  315. * Real code
  316. */
  317. static struct attribute *adm1025_attributes[] = {
  318. &sensor_dev_attr_in0_input.dev_attr.attr,
  319. &sensor_dev_attr_in1_input.dev_attr.attr,
  320. &sensor_dev_attr_in2_input.dev_attr.attr,
  321. &sensor_dev_attr_in3_input.dev_attr.attr,
  322. &sensor_dev_attr_in5_input.dev_attr.attr,
  323. &sensor_dev_attr_in0_min.dev_attr.attr,
  324. &sensor_dev_attr_in1_min.dev_attr.attr,
  325. &sensor_dev_attr_in2_min.dev_attr.attr,
  326. &sensor_dev_attr_in3_min.dev_attr.attr,
  327. &sensor_dev_attr_in5_min.dev_attr.attr,
  328. &sensor_dev_attr_in0_max.dev_attr.attr,
  329. &sensor_dev_attr_in1_max.dev_attr.attr,
  330. &sensor_dev_attr_in2_max.dev_attr.attr,
  331. &sensor_dev_attr_in3_max.dev_attr.attr,
  332. &sensor_dev_attr_in5_max.dev_attr.attr,
  333. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  334. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  335. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  336. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  337. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  338. &sensor_dev_attr_temp1_input.dev_attr.attr,
  339. &sensor_dev_attr_temp2_input.dev_attr.attr,
  340. &sensor_dev_attr_temp1_min.dev_attr.attr,
  341. &sensor_dev_attr_temp2_min.dev_attr.attr,
  342. &sensor_dev_attr_temp1_max.dev_attr.attr,
  343. &sensor_dev_attr_temp2_max.dev_attr.attr,
  344. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  345. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  346. &sensor_dev_attr_temp1_fault.dev_attr.attr,
  347. &dev_attr_alarms.attr,
  348. &dev_attr_cpu0_vid.attr,
  349. &dev_attr_vrm.attr,
  350. NULL
  351. };
  352. static const struct attribute_group adm1025_group = {
  353. .attrs = adm1025_attributes,
  354. };
  355. static struct attribute *adm1025_attributes_in4[] = {
  356. &sensor_dev_attr_in4_input.dev_attr.attr,
  357. &sensor_dev_attr_in4_min.dev_attr.attr,
  358. &sensor_dev_attr_in4_max.dev_attr.attr,
  359. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  360. NULL
  361. };
  362. static const struct attribute_group adm1025_group_in4 = {
  363. .attrs = adm1025_attributes_in4,
  364. };
  365. /* Return 0 if detection is successful, -ENODEV otherwise */
  366. static int adm1025_detect(struct i2c_client *client, int kind,
  367. struct i2c_board_info *info)
  368. {
  369. struct i2c_adapter *adapter = client->adapter;
  370. const char *name;
  371. u8 man_id, chip_id;
  372. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  373. return -ENODEV;
  374. /* Check for unused bits */
  375. if ((i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG) & 0x80)
  376. || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS1) & 0xC0)
  377. || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS2) & 0xBC)) {
  378. dev_dbg(&adapter->dev, "ADM1025 detection failed at 0x%02x\n",
  379. client->addr);
  380. return -ENODEV;
  381. }
  382. /* Identification */
  383. chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
  384. if ((chip_id & 0xF0) != 0x20)
  385. return -ENODEV;
  386. man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
  387. if (man_id == 0x41)
  388. name = "adm1025";
  389. else if (man_id == 0xA1 && client->addr != 0x2E)
  390. name = "ne1619";
  391. else
  392. return -ENODEV;
  393. strlcpy(info->type, name, I2C_NAME_SIZE);
  394. return 0;
  395. }
  396. static int adm1025_probe(struct i2c_client *client,
  397. const struct i2c_device_id *id)
  398. {
  399. struct adm1025_data *data;
  400. int err;
  401. u8 config;
  402. data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL);
  403. if (!data) {
  404. err = -ENOMEM;
  405. goto exit;
  406. }
  407. i2c_set_clientdata(client, data);
  408. mutex_init(&data->update_lock);
  409. /* Initialize the ADM1025 chip */
  410. adm1025_init_client(client);
  411. /* Register sysfs hooks */
  412. if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
  413. goto exit_free;
  414. /* Pin 11 is either in4 (+12V) or VID4 */
  415. config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
  416. if (!(config & 0x20)) {
  417. if ((err = sysfs_create_group(&client->dev.kobj,
  418. &adm1025_group_in4)))
  419. goto exit_remove;
  420. }
  421. data->hwmon_dev = hwmon_device_register(&client->dev);
  422. if (IS_ERR(data->hwmon_dev)) {
  423. err = PTR_ERR(data->hwmon_dev);
  424. goto exit_remove;
  425. }
  426. return 0;
  427. exit_remove:
  428. sysfs_remove_group(&client->dev.kobj, &adm1025_group);
  429. sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
  430. exit_free:
  431. kfree(data);
  432. exit:
  433. return err;
  434. }
  435. static void adm1025_init_client(struct i2c_client *client)
  436. {
  437. u8 reg;
  438. struct adm1025_data *data = i2c_get_clientdata(client);
  439. int i;
  440. data->vrm = vid_which_vrm();
  441. /*
  442. * Set high limits
  443. * Usually we avoid setting limits on driver init, but it happens
  444. * that the ADM1025 comes with stupid default limits (all registers
  445. * set to 0). In case the chip has not gone through any limit
  446. * setting yet, we better set the high limits to the max so that
  447. * no alarm triggers.
  448. */
  449. for (i=0; i<6; i++) {
  450. reg = i2c_smbus_read_byte_data(client,
  451. ADM1025_REG_IN_MAX(i));
  452. if (reg == 0)
  453. i2c_smbus_write_byte_data(client,
  454. ADM1025_REG_IN_MAX(i),
  455. 0xFF);
  456. }
  457. for (i=0; i<2; i++) {
  458. reg = i2c_smbus_read_byte_data(client,
  459. ADM1025_REG_TEMP_HIGH(i));
  460. if (reg == 0)
  461. i2c_smbus_write_byte_data(client,
  462. ADM1025_REG_TEMP_HIGH(i),
  463. 0x7F);
  464. }
  465. /*
  466. * Start the conversions
  467. */
  468. reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
  469. if (!(reg & 0x01))
  470. i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
  471. (reg&0x7E)|0x01);
  472. }
  473. static int adm1025_remove(struct i2c_client *client)
  474. {
  475. struct adm1025_data *data = i2c_get_clientdata(client);
  476. hwmon_device_unregister(data->hwmon_dev);
  477. sysfs_remove_group(&client->dev.kobj, &adm1025_group);
  478. sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
  479. kfree(data);
  480. return 0;
  481. }
  482. static struct adm1025_data *adm1025_update_device(struct device *dev)
  483. {
  484. struct i2c_client *client = to_i2c_client(dev);
  485. struct adm1025_data *data = i2c_get_clientdata(client);
  486. mutex_lock(&data->update_lock);
  487. if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
  488. int i;
  489. dev_dbg(&client->dev, "Updating data.\n");
  490. for (i=0; i<6; i++) {
  491. data->in[i] = i2c_smbus_read_byte_data(client,
  492. ADM1025_REG_IN(i));
  493. data->in_min[i] = i2c_smbus_read_byte_data(client,
  494. ADM1025_REG_IN_MIN(i));
  495. data->in_max[i] = i2c_smbus_read_byte_data(client,
  496. ADM1025_REG_IN_MAX(i));
  497. }
  498. for (i=0; i<2; i++) {
  499. data->temp[i] = i2c_smbus_read_byte_data(client,
  500. ADM1025_REG_TEMP(i));
  501. data->temp_min[i] = i2c_smbus_read_byte_data(client,
  502. ADM1025_REG_TEMP_LOW(i));
  503. data->temp_max[i] = i2c_smbus_read_byte_data(client,
  504. ADM1025_REG_TEMP_HIGH(i));
  505. }
  506. data->alarms = i2c_smbus_read_byte_data(client,
  507. ADM1025_REG_STATUS1)
  508. | (i2c_smbus_read_byte_data(client,
  509. ADM1025_REG_STATUS2) << 8);
  510. data->vid = (i2c_smbus_read_byte_data(client,
  511. ADM1025_REG_VID) & 0x0f)
  512. | ((i2c_smbus_read_byte_data(client,
  513. ADM1025_REG_VID4) & 0x01) << 4);
  514. data->last_updated = jiffies;
  515. data->valid = 1;
  516. }
  517. mutex_unlock(&data->update_lock);
  518. return data;
  519. }
  520. static int __init sensors_adm1025_init(void)
  521. {
  522. return i2c_add_driver(&adm1025_driver);
  523. }
  524. static void __exit sensors_adm1025_exit(void)
  525. {
  526. i2c_del_driver(&adm1025_driver);
  527. }
  528. MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
  529. MODULE_DESCRIPTION("ADM1025 driver");
  530. MODULE_LICENSE("GPL");
  531. module_init(sensors_adm1025_init);
  532. module_exit(sensors_adm1025_exit);