adm1025.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. * adm1025.c
  3. *
  4. * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com>
  5. * Copyright (C) 2003-2004 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/i2c-sensor.h>
  53. #include <linux/i2c-vid.h>
  54. /*
  55. * Addresses to scan
  56. * ADM1025 and ADM1025A have three possible addresses: 0x2c, 0x2d and 0x2e.
  57. * NE1619 has two possible addresses: 0x2c and 0x2d.
  58. */
  59. static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
  60. static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
  61. /*
  62. * Insmod parameters
  63. */
  64. SENSORS_INSMOD_2(adm1025, ne1619);
  65. /*
  66. * The ADM1025 registers
  67. */
  68. #define ADM1025_REG_MAN_ID 0x3E
  69. #define ADM1025_REG_CHIP_ID 0x3F
  70. #define ADM1025_REG_CONFIG 0x40
  71. #define ADM1025_REG_STATUS1 0x41
  72. #define ADM1025_REG_STATUS2 0x42
  73. #define ADM1025_REG_IN(nr) (0x20 + (nr))
  74. #define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2)
  75. #define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2)
  76. #define ADM1025_REG_TEMP(nr) (0x26 + (nr))
  77. #define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2)
  78. #define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2)
  79. #define ADM1025_REG_VID 0x47
  80. #define ADM1025_REG_VID4 0x49
  81. /*
  82. * Conversions and various macros
  83. * The ADM1025 uses signed 8-bit values for temperatures.
  84. */
  85. static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
  86. #define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
  87. #define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
  88. (val) * 192 >= (scale) * 255 ? 255 : \
  89. ((val) * 192 + (scale)/2) / (scale))
  90. #define TEMP_FROM_REG(reg) ((reg) * 1000)
  91. #define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
  92. (val) >= 126500 ? 127 : \
  93. (((val) < 0 ? (val)-500 : (val)+500) / 1000))
  94. /*
  95. * Functions declaration
  96. */
  97. static int adm1025_attach_adapter(struct i2c_adapter *adapter);
  98. static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind);
  99. static void adm1025_init_client(struct i2c_client *client);
  100. static int adm1025_detach_client(struct i2c_client *client);
  101. static struct adm1025_data *adm1025_update_device(struct device *dev);
  102. /*
  103. * Driver data (common to all clients)
  104. */
  105. static struct i2c_driver adm1025_driver = {
  106. .owner = THIS_MODULE,
  107. .name = "adm1025",
  108. .id = I2C_DRIVERID_ADM1025,
  109. .flags = I2C_DF_NOTIFY,
  110. .attach_adapter = adm1025_attach_adapter,
  111. .detach_client = adm1025_detach_client,
  112. };
  113. /*
  114. * Client data (each client gets its own)
  115. */
  116. struct adm1025_data {
  117. struct i2c_client client;
  118. struct semaphore update_lock;
  119. char valid; /* zero until following fields are valid */
  120. unsigned long last_updated; /* in jiffies */
  121. u8 in[6]; /* register value */
  122. u8 in_max[6]; /* register value */
  123. u8 in_min[6]; /* register value */
  124. s8 temp[2]; /* register value */
  125. s8 temp_min[2]; /* register value */
  126. s8 temp_max[2]; /* register value */
  127. u16 alarms; /* register values, combined */
  128. u8 vid; /* register values, combined */
  129. u8 vrm;
  130. };
  131. /*
  132. * Sysfs stuff
  133. */
  134. #define show_in(offset) \
  135. static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \
  136. { \
  137. struct adm1025_data *data = adm1025_update_device(dev); \
  138. return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
  139. in_scale[offset])); \
  140. } \
  141. static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
  142. { \
  143. struct adm1025_data *data = adm1025_update_device(dev); \
  144. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
  145. in_scale[offset])); \
  146. } \
  147. static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
  148. { \
  149. struct adm1025_data *data = adm1025_update_device(dev); \
  150. return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
  151. in_scale[offset])); \
  152. } \
  153. static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
  154. show_in(0);
  155. show_in(1);
  156. show_in(2);
  157. show_in(3);
  158. show_in(4);
  159. show_in(5);
  160. #define show_temp(offset) \
  161. static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \
  162. { \
  163. struct adm1025_data *data = adm1025_update_device(dev); \
  164. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
  165. } \
  166. static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
  167. { \
  168. struct adm1025_data *data = adm1025_update_device(dev); \
  169. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
  170. } \
  171. static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
  172. { \
  173. struct adm1025_data *data = adm1025_update_device(dev); \
  174. return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
  175. }\
  176. static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL);
  177. show_temp(1);
  178. show_temp(2);
  179. #define set_in(offset) \
  180. static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
  181. size_t count) \
  182. { \
  183. struct i2c_client *client = to_i2c_client(dev); \
  184. struct adm1025_data *data = i2c_get_clientdata(client); \
  185. long val = simple_strtol(buf, NULL, 10); \
  186. \
  187. down(&data->update_lock); \
  188. data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
  189. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
  190. data->in_min[offset]); \
  191. up(&data->update_lock); \
  192. return count; \
  193. } \
  194. static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
  195. size_t count) \
  196. { \
  197. struct i2c_client *client = to_i2c_client(dev); \
  198. struct adm1025_data *data = i2c_get_clientdata(client); \
  199. long val = simple_strtol(buf, NULL, 10); \
  200. \
  201. down(&data->update_lock); \
  202. data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
  203. i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
  204. data->in_max[offset]); \
  205. up(&data->update_lock); \
  206. return count; \
  207. } \
  208. static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
  209. show_in##offset##_min, set_in##offset##_min); \
  210. static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
  211. show_in##offset##_max, set_in##offset##_max);
  212. set_in(0);
  213. set_in(1);
  214. set_in(2);
  215. set_in(3);
  216. set_in(4);
  217. set_in(5);
  218. #define set_temp(offset) \
  219. static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
  220. size_t count) \
  221. { \
  222. struct i2c_client *client = to_i2c_client(dev); \
  223. struct adm1025_data *data = i2c_get_clientdata(client); \
  224. long val = simple_strtol(buf, NULL, 10); \
  225. \
  226. down(&data->update_lock); \
  227. data->temp_min[offset-1] = TEMP_TO_REG(val); \
  228. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
  229. data->temp_min[offset-1]); \
  230. up(&data->update_lock); \
  231. return count; \
  232. } \
  233. static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
  234. size_t count) \
  235. { \
  236. struct i2c_client *client = to_i2c_client(dev); \
  237. struct adm1025_data *data = i2c_get_clientdata(client); \
  238. long val = simple_strtol(buf, NULL, 10); \
  239. \
  240. down(&data->update_lock); \
  241. data->temp_max[offset-1] = TEMP_TO_REG(val); \
  242. i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
  243. data->temp_max[offset-1]); \
  244. up(&data->update_lock); \
  245. return count; \
  246. } \
  247. static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
  248. show_temp##offset##_min, set_temp##offset##_min); \
  249. static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
  250. show_temp##offset##_max, set_temp##offset##_max);
  251. set_temp(1);
  252. set_temp(2);
  253. static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
  254. {
  255. struct adm1025_data *data = adm1025_update_device(dev);
  256. return sprintf(buf, "%u\n", data->alarms);
  257. }
  258. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  259. static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
  260. {
  261. struct adm1025_data *data = adm1025_update_device(dev);
  262. return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
  263. }
  264. /* in1_ref is deprecated in favour of cpu0_vid, remove after 2005-11-11 */
  265. static DEVICE_ATTR(in1_ref, S_IRUGO, show_vid, NULL);
  266. static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
  267. static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
  268. {
  269. struct adm1025_data *data = adm1025_update_device(dev);
  270. return sprintf(buf, "%u\n", data->vrm);
  271. }
  272. static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  273. {
  274. struct i2c_client *client = to_i2c_client(dev);
  275. struct adm1025_data *data = i2c_get_clientdata(client);
  276. data->vrm = simple_strtoul(buf, NULL, 10);
  277. return count;
  278. }
  279. static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
  280. /*
  281. * Real code
  282. */
  283. static int adm1025_attach_adapter(struct i2c_adapter *adapter)
  284. {
  285. if (!(adapter->class & I2C_CLASS_HWMON))
  286. return 0;
  287. return i2c_detect(adapter, &addr_data, adm1025_detect);
  288. }
  289. /*
  290. * The following function does more than just detection. If detection
  291. * succeeds, it also registers the new chip.
  292. */
  293. static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
  294. {
  295. struct i2c_client *new_client;
  296. struct adm1025_data *data;
  297. int err = 0;
  298. const char *name = "";
  299. u8 config;
  300. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  301. goto exit;
  302. if (!(data = kmalloc(sizeof(struct adm1025_data), GFP_KERNEL))) {
  303. err = -ENOMEM;
  304. goto exit;
  305. }
  306. memset(data, 0, sizeof(struct adm1025_data));
  307. /* The common I2C client data is placed right before the
  308. ADM1025-specific data. */
  309. new_client = &data->client;
  310. i2c_set_clientdata(new_client, data);
  311. new_client->addr = address;
  312. new_client->adapter = adapter;
  313. new_client->driver = &adm1025_driver;
  314. new_client->flags = 0;
  315. /*
  316. * Now we do the remaining detection. A negative kind means that
  317. * the driver was loaded with no force parameter (default), so we
  318. * must both detect and identify the chip. A zero kind means that
  319. * the driver was loaded with the force parameter, the detection
  320. * step shall be skipped. A positive kind means that the driver
  321. * was loaded with the force parameter and a given kind of chip is
  322. * requested, so both the detection and the identification steps
  323. * are skipped.
  324. */
  325. config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG);
  326. if (kind < 0) { /* detection */
  327. if ((config & 0x80) != 0x00
  328. || (i2c_smbus_read_byte_data(new_client,
  329. ADM1025_REG_STATUS1) & 0xC0) != 0x00
  330. || (i2c_smbus_read_byte_data(new_client,
  331. ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
  332. dev_dbg(&adapter->dev,
  333. "ADM1025 detection failed at 0x%02x.\n",
  334. address);
  335. goto exit_free;
  336. }
  337. }
  338. if (kind <= 0) { /* identification */
  339. u8 man_id, chip_id;
  340. man_id = i2c_smbus_read_byte_data(new_client,
  341. ADM1025_REG_MAN_ID);
  342. chip_id = i2c_smbus_read_byte_data(new_client,
  343. ADM1025_REG_CHIP_ID);
  344. if (man_id == 0x41) { /* Analog Devices */
  345. if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
  346. kind = adm1025;
  347. }
  348. } else
  349. if (man_id == 0xA1) { /* Philips */
  350. if (address != 0x2E
  351. && (chip_id & 0xF0) == 0x20) { /* NE1619 */
  352. kind = ne1619;
  353. }
  354. }
  355. if (kind <= 0) { /* identification failed */
  356. dev_info(&adapter->dev,
  357. "Unsupported chip (man_id=0x%02X, "
  358. "chip_id=0x%02X).\n", man_id, chip_id);
  359. goto exit_free;
  360. }
  361. }
  362. if (kind == adm1025) {
  363. name = "adm1025";
  364. } else if (kind == ne1619) {
  365. name = "ne1619";
  366. }
  367. /* We can fill in the remaining client fields */
  368. strlcpy(new_client->name, name, I2C_NAME_SIZE);
  369. data->valid = 0;
  370. init_MUTEX(&data->update_lock);
  371. /* Tell the I2C layer a new client has arrived */
  372. if ((err = i2c_attach_client(new_client)))
  373. goto exit_free;
  374. /* Initialize the ADM1025 chip */
  375. adm1025_init_client(new_client);
  376. /* Register sysfs hooks */
  377. device_create_file(&new_client->dev, &dev_attr_in0_input);
  378. device_create_file(&new_client->dev, &dev_attr_in1_input);
  379. device_create_file(&new_client->dev, &dev_attr_in2_input);
  380. device_create_file(&new_client->dev, &dev_attr_in3_input);
  381. device_create_file(&new_client->dev, &dev_attr_in5_input);
  382. device_create_file(&new_client->dev, &dev_attr_in0_min);
  383. device_create_file(&new_client->dev, &dev_attr_in1_min);
  384. device_create_file(&new_client->dev, &dev_attr_in2_min);
  385. device_create_file(&new_client->dev, &dev_attr_in3_min);
  386. device_create_file(&new_client->dev, &dev_attr_in5_min);
  387. device_create_file(&new_client->dev, &dev_attr_in0_max);
  388. device_create_file(&new_client->dev, &dev_attr_in1_max);
  389. device_create_file(&new_client->dev, &dev_attr_in2_max);
  390. device_create_file(&new_client->dev, &dev_attr_in3_max);
  391. device_create_file(&new_client->dev, &dev_attr_in5_max);
  392. device_create_file(&new_client->dev, &dev_attr_temp1_input);
  393. device_create_file(&new_client->dev, &dev_attr_temp2_input);
  394. device_create_file(&new_client->dev, &dev_attr_temp1_min);
  395. device_create_file(&new_client->dev, &dev_attr_temp2_min);
  396. device_create_file(&new_client->dev, &dev_attr_temp1_max);
  397. device_create_file(&new_client->dev, &dev_attr_temp2_max);
  398. device_create_file(&new_client->dev, &dev_attr_alarms);
  399. /* in1_ref is deprecated, remove after 2005-11-11 */
  400. device_create_file(&new_client->dev, &dev_attr_in1_ref);
  401. device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
  402. device_create_file(&new_client->dev, &dev_attr_vrm);
  403. /* Pin 11 is either in4 (+12V) or VID4 */
  404. if (!(config & 0x20)) {
  405. device_create_file(&new_client->dev, &dev_attr_in4_input);
  406. device_create_file(&new_client->dev, &dev_attr_in4_min);
  407. device_create_file(&new_client->dev, &dev_attr_in4_max);
  408. }
  409. return 0;
  410. exit_free:
  411. kfree(data);
  412. exit:
  413. return err;
  414. }
  415. static void adm1025_init_client(struct i2c_client *client)
  416. {
  417. u8 reg;
  418. struct adm1025_data *data = i2c_get_clientdata(client);
  419. int i;
  420. data->vrm = i2c_which_vrm();
  421. /*
  422. * Set high limits
  423. * Usually we avoid setting limits on driver init, but it happens
  424. * that the ADM1025 comes with stupid default limits (all registers
  425. * set to 0). In case the chip has not gone through any limit
  426. * setting yet, we better set the high limits to the max so that
  427. * no alarm triggers.
  428. */
  429. for (i=0; i<6; i++) {
  430. reg = i2c_smbus_read_byte_data(client,
  431. ADM1025_REG_IN_MAX(i));
  432. if (reg == 0)
  433. i2c_smbus_write_byte_data(client,
  434. ADM1025_REG_IN_MAX(i),
  435. 0xFF);
  436. }
  437. for (i=0; i<2; i++) {
  438. reg = i2c_smbus_read_byte_data(client,
  439. ADM1025_REG_TEMP_HIGH(i));
  440. if (reg == 0)
  441. i2c_smbus_write_byte_data(client,
  442. ADM1025_REG_TEMP_HIGH(i),
  443. 0x7F);
  444. }
  445. /*
  446. * Start the conversions
  447. */
  448. reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
  449. if (!(reg & 0x01))
  450. i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
  451. (reg&0x7E)|0x01);
  452. }
  453. static int adm1025_detach_client(struct i2c_client *client)
  454. {
  455. int err;
  456. if ((err = i2c_detach_client(client))) {
  457. dev_err(&client->dev, "Client deregistration failed, "
  458. "client not detached.\n");
  459. return err;
  460. }
  461. kfree(i2c_get_clientdata(client));
  462. return 0;
  463. }
  464. static struct adm1025_data *adm1025_update_device(struct device *dev)
  465. {
  466. struct i2c_client *client = to_i2c_client(dev);
  467. struct adm1025_data *data = i2c_get_clientdata(client);
  468. down(&data->update_lock);
  469. if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
  470. int i;
  471. dev_dbg(&client->dev, "Updating data.\n");
  472. for (i=0; i<6; i++) {
  473. data->in[i] = i2c_smbus_read_byte_data(client,
  474. ADM1025_REG_IN(i));
  475. data->in_min[i] = i2c_smbus_read_byte_data(client,
  476. ADM1025_REG_IN_MIN(i));
  477. data->in_max[i] = i2c_smbus_read_byte_data(client,
  478. ADM1025_REG_IN_MAX(i));
  479. }
  480. for (i=0; i<2; i++) {
  481. data->temp[i] = i2c_smbus_read_byte_data(client,
  482. ADM1025_REG_TEMP(i));
  483. data->temp_min[i] = i2c_smbus_read_byte_data(client,
  484. ADM1025_REG_TEMP_LOW(i));
  485. data->temp_max[i] = i2c_smbus_read_byte_data(client,
  486. ADM1025_REG_TEMP_HIGH(i));
  487. }
  488. data->alarms = i2c_smbus_read_byte_data(client,
  489. ADM1025_REG_STATUS1)
  490. | (i2c_smbus_read_byte_data(client,
  491. ADM1025_REG_STATUS2) << 8);
  492. data->vid = (i2c_smbus_read_byte_data(client,
  493. ADM1025_REG_VID) & 0x0f)
  494. | ((i2c_smbus_read_byte_data(client,
  495. ADM1025_REG_VID4) & 0x01) << 4);
  496. data->last_updated = jiffies;
  497. data->valid = 1;
  498. }
  499. up(&data->update_lock);
  500. return data;
  501. }
  502. static int __init sensors_adm1025_init(void)
  503. {
  504. return i2c_add_driver(&adm1025_driver);
  505. }
  506. static void __exit sensors_adm1025_exit(void)
  507. {
  508. i2c_del_driver(&adm1025_driver);
  509. }
  510. MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
  511. MODULE_DESCRIPTION("ADM1025 driver");
  512. MODULE_LICENSE("GPL");
  513. module_init(sensors_adm1025_init);
  514. module_exit(sensors_adm1025_exit);