adm1025.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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.onsemi.com/PowerSolutions/product.do?id=ADM1025
  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. enum chips { adm1025, ne1619 };
  64. /*
  65. * The ADM1025 registers
  66. */
  67. #define ADM1025_REG_MAN_ID 0x3E
  68. #define ADM1025_REG_CHIP_ID 0x3F
  69. #define ADM1025_REG_CONFIG 0x40
  70. #define ADM1025_REG_STATUS1 0x41
  71. #define ADM1025_REG_STATUS2 0x42
  72. #define ADM1025_REG_IN(nr) (0x20 + (nr))
  73. #define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2)
  74. #define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2)
  75. #define ADM1025_REG_TEMP(nr) (0x26 + (nr))
  76. #define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2)
  77. #define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2)
  78. #define ADM1025_REG_VID 0x47
  79. #define ADM1025_REG_VID4 0x49
  80. /*
  81. * Conversions and various macros
  82. * The ADM1025 uses signed 8-bit values for temperatures.
  83. */
  84. static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
  85. #define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
  86. #define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
  87. (val) * 192 >= (scale) * 255 ? 255 : \
  88. ((val) * 192 + (scale) / 2) / (scale))
  89. #define TEMP_FROM_REG(reg) ((reg) * 1000)
  90. #define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
  91. (val) >= 126500 ? 127 : \
  92. (((val) < 0 ? (val) - 500 : \
  93. (val) + 500) / 1000))
  94. /*
  95. * Functions declaration
  96. */
  97. static int adm1025_probe(struct i2c_client *client,
  98. const struct i2c_device_id *id);
  99. static int adm1025_detect(struct i2c_client *client,
  100. struct i2c_board_info *info);
  101. static void adm1025_init_client(struct i2c_client *client);
  102. static int adm1025_remove(struct i2c_client *client);
  103. static struct adm1025_data *adm1025_update_device(struct device *dev);
  104. /*
  105. * Driver data (common to all clients)
  106. */
  107. static const struct i2c_device_id adm1025_id[] = {
  108. { "adm1025", adm1025 },
  109. { "ne1619", ne1619 },
  110. { }
  111. };
  112. MODULE_DEVICE_TABLE(i2c, adm1025_id);
  113. static struct i2c_driver adm1025_driver = {
  114. .class = I2C_CLASS_HWMON,
  115. .driver = {
  116. .name = "adm1025",
  117. },
  118. .probe = adm1025_probe,
  119. .remove = adm1025_remove,
  120. .id_table = adm1025_id,
  121. .detect = adm1025_detect,
  122. .address_list = normal_i2c,
  123. };
  124. /*
  125. * Client data (each client gets its own)
  126. */
  127. struct adm1025_data {
  128. struct device *hwmon_dev;
  129. struct mutex update_lock;
  130. char valid; /* zero until following fields are valid */
  131. unsigned long last_updated; /* in jiffies */
  132. u8 in[6]; /* register value */
  133. u8 in_max[6]; /* register value */
  134. u8 in_min[6]; /* register value */
  135. s8 temp[2]; /* register value */
  136. s8 temp_min[2]; /* register value */
  137. s8 temp_max[2]; /* register value */
  138. u16 alarms; /* register values, combined */
  139. u8 vid; /* register values, combined */
  140. u8 vrm;
  141. };
  142. /*
  143. * Sysfs stuff
  144. */
  145. static ssize_t
  146. show_in(struct device *dev, struct device_attribute *attr, char *buf)
  147. {
  148. int index = to_sensor_dev_attr(attr)->index;
  149. struct adm1025_data *data = adm1025_update_device(dev);
  150. return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
  151. in_scale[index]));
  152. }
  153. static ssize_t
  154. show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
  155. {
  156. int index = to_sensor_dev_attr(attr)->index;
  157. struct adm1025_data *data = adm1025_update_device(dev);
  158. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
  159. in_scale[index]));
  160. }
  161. static ssize_t
  162. show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
  163. {
  164. int index = to_sensor_dev_attr(attr)->index;
  165. struct adm1025_data *data = adm1025_update_device(dev);
  166. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
  167. in_scale[index]));
  168. }
  169. static ssize_t
  170. show_temp(struct device *dev, struct device_attribute *attr, char *buf)
  171. {
  172. int index = to_sensor_dev_attr(attr)->index;
  173. struct adm1025_data *data = adm1025_update_device(dev);
  174. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
  175. }
  176. static ssize_t
  177. show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
  178. {
  179. int index = to_sensor_dev_attr(attr)->index;
  180. struct adm1025_data *data = adm1025_update_device(dev);
  181. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
  182. }
  183. static ssize_t
  184. show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
  185. {
  186. int index = to_sensor_dev_attr(attr)->index;
  187. struct adm1025_data *data = adm1025_update_device(dev);
  188. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
  189. }
  190. static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
  191. const char *buf, size_t count)
  192. {
  193. int index = to_sensor_dev_attr(attr)->index;
  194. struct i2c_client *client = to_i2c_client(dev);
  195. struct adm1025_data *data = i2c_get_clientdata(client);
  196. long val;
  197. int err;
  198. err = kstrtol(buf, 10, &val);
  199. if (err)
  200. return err;
  201. mutex_lock(&data->update_lock);
  202. data->in_min[index] = IN_TO_REG(val, in_scale[index]);
  203. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
  204. data->in_min[index]);
  205. mutex_unlock(&data->update_lock);
  206. return count;
  207. }
  208. static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
  209. const char *buf, size_t count)
  210. {
  211. int index = to_sensor_dev_attr(attr)->index;
  212. struct i2c_client *client = to_i2c_client(dev);
  213. struct adm1025_data *data = i2c_get_clientdata(client);
  214. long val;
  215. int err;
  216. err = kstrtol(buf, 10, &val);
  217. if (err)
  218. return err;
  219. mutex_lock(&data->update_lock);
  220. data->in_max[index] = IN_TO_REG(val, in_scale[index]);
  221. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
  222. data->in_max[index]);
  223. mutex_unlock(&data->update_lock);
  224. return count;
  225. }
  226. #define set_in(offset) \
  227. static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
  228. show_in, NULL, offset); \
  229. static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
  230. show_in_min, set_in_min, offset); \
  231. static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
  232. show_in_max, set_in_max, offset)
  233. set_in(0);
  234. set_in(1);
  235. set_in(2);
  236. set_in(3);
  237. set_in(4);
  238. set_in(5);
  239. static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
  240. const char *buf, size_t count)
  241. {
  242. int index = to_sensor_dev_attr(attr)->index;
  243. struct i2c_client *client = to_i2c_client(dev);
  244. struct adm1025_data *data = i2c_get_clientdata(client);
  245. long val;
  246. int err;
  247. err = kstrtol(buf, 10, &val);
  248. if (err)
  249. return err;
  250. mutex_lock(&data->update_lock);
  251. data->temp_min[index] = TEMP_TO_REG(val);
  252. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
  253. data->temp_min[index]);
  254. mutex_unlock(&data->update_lock);
  255. return count;
  256. }
  257. static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
  258. const char *buf, size_t count)
  259. {
  260. int index = to_sensor_dev_attr(attr)->index;
  261. struct i2c_client *client = to_i2c_client(dev);
  262. struct adm1025_data *data = i2c_get_clientdata(client);
  263. long val;
  264. int err;
  265. err = kstrtol(buf, 10, &val);
  266. if (err)
  267. return err;
  268. mutex_lock(&data->update_lock);
  269. data->temp_max[index] = TEMP_TO_REG(val);
  270. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
  271. data->temp_max[index]);
  272. mutex_unlock(&data->update_lock);
  273. return count;
  274. }
  275. #define set_temp(offset) \
  276. static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
  277. show_temp, NULL, offset - 1); \
  278. static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
  279. show_temp_min, set_temp_min, offset - 1); \
  280. static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
  281. show_temp_max, set_temp_max, offset - 1)
  282. set_temp(1);
  283. set_temp(2);
  284. static ssize_t
  285. show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
  286. {
  287. struct adm1025_data *data = adm1025_update_device(dev);
  288. return sprintf(buf, "%u\n", data->alarms);
  289. }
  290. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  291. static ssize_t
  292. show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
  293. {
  294. int bitnr = to_sensor_dev_attr(attr)->index;
  295. struct adm1025_data *data = adm1025_update_device(dev);
  296. return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
  297. }
  298. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
  299. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
  300. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
  301. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
  302. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
  303. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
  304. static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
  305. static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
  306. static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
  307. static ssize_t
  308. show_vid(struct device *dev, struct device_attribute *attr, char *buf)
  309. {
  310. struct adm1025_data *data = adm1025_update_device(dev);
  311. return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
  312. }
  313. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
  314. static ssize_t
  315. show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
  316. {
  317. struct adm1025_data *data = dev_get_drvdata(dev);
  318. return sprintf(buf, "%u\n", data->vrm);
  319. }
  320. static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
  321. const char *buf, size_t count)
  322. {
  323. struct adm1025_data *data = dev_get_drvdata(dev);
  324. unsigned long val;
  325. int err;
  326. err = kstrtoul(buf, 10, &val);
  327. if (err)
  328. return err;
  329. data->vrm = val;
  330. return count;
  331. }
  332. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
  333. /*
  334. * Real code
  335. */
  336. static struct attribute *adm1025_attributes[] = {
  337. &sensor_dev_attr_in0_input.dev_attr.attr,
  338. &sensor_dev_attr_in1_input.dev_attr.attr,
  339. &sensor_dev_attr_in2_input.dev_attr.attr,
  340. &sensor_dev_attr_in3_input.dev_attr.attr,
  341. &sensor_dev_attr_in5_input.dev_attr.attr,
  342. &sensor_dev_attr_in0_min.dev_attr.attr,
  343. &sensor_dev_attr_in1_min.dev_attr.attr,
  344. &sensor_dev_attr_in2_min.dev_attr.attr,
  345. &sensor_dev_attr_in3_min.dev_attr.attr,
  346. &sensor_dev_attr_in5_min.dev_attr.attr,
  347. &sensor_dev_attr_in0_max.dev_attr.attr,
  348. &sensor_dev_attr_in1_max.dev_attr.attr,
  349. &sensor_dev_attr_in2_max.dev_attr.attr,
  350. &sensor_dev_attr_in3_max.dev_attr.attr,
  351. &sensor_dev_attr_in5_max.dev_attr.attr,
  352. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  353. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  354. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  355. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  356. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  357. &sensor_dev_attr_temp1_input.dev_attr.attr,
  358. &sensor_dev_attr_temp2_input.dev_attr.attr,
  359. &sensor_dev_attr_temp1_min.dev_attr.attr,
  360. &sensor_dev_attr_temp2_min.dev_attr.attr,
  361. &sensor_dev_attr_temp1_max.dev_attr.attr,
  362. &sensor_dev_attr_temp2_max.dev_attr.attr,
  363. &sensor_dev_attr_temp1_alarm.dev_attr.attr,
  364. &sensor_dev_attr_temp2_alarm.dev_attr.attr,
  365. &sensor_dev_attr_temp1_fault.dev_attr.attr,
  366. &dev_attr_alarms.attr,
  367. &dev_attr_cpu0_vid.attr,
  368. &dev_attr_vrm.attr,
  369. NULL
  370. };
  371. static const struct attribute_group adm1025_group = {
  372. .attrs = adm1025_attributes,
  373. };
  374. static struct attribute *adm1025_attributes_in4[] = {
  375. &sensor_dev_attr_in4_input.dev_attr.attr,
  376. &sensor_dev_attr_in4_min.dev_attr.attr,
  377. &sensor_dev_attr_in4_max.dev_attr.attr,
  378. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  379. NULL
  380. };
  381. static const struct attribute_group adm1025_group_in4 = {
  382. .attrs = adm1025_attributes_in4,
  383. };
  384. /* Return 0 if detection is successful, -ENODEV otherwise */
  385. static int adm1025_detect(struct i2c_client *client,
  386. struct i2c_board_info *info)
  387. {
  388. struct i2c_adapter *adapter = client->adapter;
  389. const char *name;
  390. u8 man_id, chip_id;
  391. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  392. return -ENODEV;
  393. /* Check for unused bits */
  394. if ((i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG) & 0x80)
  395. || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS1) & 0xC0)
  396. || (i2c_smbus_read_byte_data(client, ADM1025_REG_STATUS2) & 0xBC)) {
  397. dev_dbg(&adapter->dev, "ADM1025 detection failed at 0x%02x\n",
  398. client->addr);
  399. return -ENODEV;
  400. }
  401. /* Identification */
  402. chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
  403. if ((chip_id & 0xF0) != 0x20)
  404. return -ENODEV;
  405. man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
  406. if (man_id == 0x41)
  407. name = "adm1025";
  408. else if (man_id == 0xA1 && client->addr != 0x2E)
  409. name = "ne1619";
  410. else
  411. return -ENODEV;
  412. strlcpy(info->type, name, I2C_NAME_SIZE);
  413. return 0;
  414. }
  415. static int adm1025_probe(struct i2c_client *client,
  416. const struct i2c_device_id *id)
  417. {
  418. struct adm1025_data *data;
  419. int err;
  420. u8 config;
  421. data = kzalloc(sizeof(struct adm1025_data), GFP_KERNEL);
  422. if (!data) {
  423. err = -ENOMEM;
  424. goto exit;
  425. }
  426. i2c_set_clientdata(client, data);
  427. mutex_init(&data->update_lock);
  428. /* Initialize the ADM1025 chip */
  429. adm1025_init_client(client);
  430. /* Register sysfs hooks */
  431. err = sysfs_create_group(&client->dev.kobj, &adm1025_group);
  432. if (err)
  433. goto exit_free;
  434. /* Pin 11 is either in4 (+12V) or VID4 */
  435. config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
  436. if (!(config & 0x20)) {
  437. err = sysfs_create_group(&client->dev.kobj, &adm1025_group_in4);
  438. if (err)
  439. goto exit_remove;
  440. }
  441. data->hwmon_dev = hwmon_device_register(&client->dev);
  442. if (IS_ERR(data->hwmon_dev)) {
  443. err = PTR_ERR(data->hwmon_dev);
  444. goto exit_remove;
  445. }
  446. return 0;
  447. exit_remove:
  448. sysfs_remove_group(&client->dev.kobj, &adm1025_group);
  449. sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
  450. exit_free:
  451. kfree(data);
  452. exit:
  453. return err;
  454. }
  455. static void adm1025_init_client(struct i2c_client *client)
  456. {
  457. u8 reg;
  458. struct adm1025_data *data = i2c_get_clientdata(client);
  459. int i;
  460. data->vrm = vid_which_vrm();
  461. /*
  462. * Set high limits
  463. * Usually we avoid setting limits on driver init, but it happens
  464. * that the ADM1025 comes with stupid default limits (all registers
  465. * set to 0). In case the chip has not gone through any limit
  466. * setting yet, we better set the high limits to the max so that
  467. * no alarm triggers.
  468. */
  469. for (i = 0; i < 6; i++) {
  470. reg = i2c_smbus_read_byte_data(client,
  471. ADM1025_REG_IN_MAX(i));
  472. if (reg == 0)
  473. i2c_smbus_write_byte_data(client,
  474. ADM1025_REG_IN_MAX(i),
  475. 0xFF);
  476. }
  477. for (i = 0; i < 2; i++) {
  478. reg = i2c_smbus_read_byte_data(client,
  479. ADM1025_REG_TEMP_HIGH(i));
  480. if (reg == 0)
  481. i2c_smbus_write_byte_data(client,
  482. ADM1025_REG_TEMP_HIGH(i),
  483. 0x7F);
  484. }
  485. /*
  486. * Start the conversions
  487. */
  488. reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
  489. if (!(reg & 0x01))
  490. i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
  491. (reg&0x7E)|0x01);
  492. }
  493. static int adm1025_remove(struct i2c_client *client)
  494. {
  495. struct adm1025_data *data = i2c_get_clientdata(client);
  496. hwmon_device_unregister(data->hwmon_dev);
  497. sysfs_remove_group(&client->dev.kobj, &adm1025_group);
  498. sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
  499. kfree(data);
  500. return 0;
  501. }
  502. static struct adm1025_data *adm1025_update_device(struct device *dev)
  503. {
  504. struct i2c_client *client = to_i2c_client(dev);
  505. struct adm1025_data *data = i2c_get_clientdata(client);
  506. mutex_lock(&data->update_lock);
  507. if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
  508. int i;
  509. dev_dbg(&client->dev, "Updating data.\n");
  510. for (i = 0; i < 6; i++) {
  511. data->in[i] = i2c_smbus_read_byte_data(client,
  512. ADM1025_REG_IN(i));
  513. data->in_min[i] = i2c_smbus_read_byte_data(client,
  514. ADM1025_REG_IN_MIN(i));
  515. data->in_max[i] = i2c_smbus_read_byte_data(client,
  516. ADM1025_REG_IN_MAX(i));
  517. }
  518. for (i = 0; i < 2; i++) {
  519. data->temp[i] = i2c_smbus_read_byte_data(client,
  520. ADM1025_REG_TEMP(i));
  521. data->temp_min[i] = i2c_smbus_read_byte_data(client,
  522. ADM1025_REG_TEMP_LOW(i));
  523. data->temp_max[i] = i2c_smbus_read_byte_data(client,
  524. ADM1025_REG_TEMP_HIGH(i));
  525. }
  526. data->alarms = i2c_smbus_read_byte_data(client,
  527. ADM1025_REG_STATUS1)
  528. | (i2c_smbus_read_byte_data(client,
  529. ADM1025_REG_STATUS2) << 8);
  530. data->vid = (i2c_smbus_read_byte_data(client,
  531. ADM1025_REG_VID) & 0x0f)
  532. | ((i2c_smbus_read_byte_data(client,
  533. ADM1025_REG_VID4) & 0x01) << 4);
  534. data->last_updated = jiffies;
  535. data->valid = 1;
  536. }
  537. mutex_unlock(&data->update_lock);
  538. return data;
  539. }
  540. module_i2c_driver(adm1025_driver);
  541. MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
  542. MODULE_DESCRIPTION("ADM1025 driver");
  543. MODULE_LICENSE("GPL");