lm63.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * lm63.c - driver for the National Semiconductor LM63 temperature sensor
  3. * with integrated fan control
  4. * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
  5. * Based on the lm90 driver.
  6. *
  7. * The LM63 is a sensor chip made by National Semiconductor. It measures
  8. * two temperatures (its own and one external one) and the speed of one
  9. * fan, those speed it can additionally control. Complete datasheet can be
  10. * obtained from National's website at:
  11. * http://www.national.com/pf/LM/LM63.html
  12. *
  13. * The LM63 is basically an LM86 with fan speed monitoring and control
  14. * capabilities added. It misses some of the LM86 features though:
  15. * - No low limit for local temperature.
  16. * - No critical limit for local temperature.
  17. * - Critical limit for remote temperature can be changed only once. We
  18. * will consider that the critical limit is read-only.
  19. *
  20. * The datasheet isn't very clear about what the tachometer reading is.
  21. * I had a explanation from National Semiconductor though. The two lower
  22. * bits of the read value have to be masked out. The value is still 16 bit
  23. * in width.
  24. *
  25. * This program is free software; you can redistribute it and/or modify
  26. * it under the terms of the GNU General Public License as published by
  27. * the Free Software Foundation; either version 2 of the License, or
  28. * (at your option) any later version.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU General Public License
  36. * along with this program; if not, write to the Free Software
  37. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  38. */
  39. #include <linux/config.h>
  40. #include <linux/module.h>
  41. #include <linux/init.h>
  42. #include <linux/slab.h>
  43. #include <linux/jiffies.h>
  44. #include <linux/i2c.h>
  45. #include <linux/i2c-sensor.h>
  46. /*
  47. * Addresses to scan
  48. * Address is fully defined internally and cannot be changed.
  49. */
  50. static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
  51. static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
  52. /*
  53. * Insmod parameters
  54. */
  55. SENSORS_INSMOD_1(lm63);
  56. /*
  57. * The LM63 registers
  58. */
  59. #define LM63_REG_CONFIG1 0x03
  60. #define LM63_REG_CONFIG2 0xBF
  61. #define LM63_REG_CONFIG_FAN 0x4A
  62. #define LM63_REG_TACH_COUNT_MSB 0x47
  63. #define LM63_REG_TACH_COUNT_LSB 0x46
  64. #define LM63_REG_TACH_LIMIT_MSB 0x49
  65. #define LM63_REG_TACH_LIMIT_LSB 0x48
  66. #define LM63_REG_PWM_VALUE 0x4C
  67. #define LM63_REG_PWM_FREQ 0x4D
  68. #define LM63_REG_LOCAL_TEMP 0x00
  69. #define LM63_REG_LOCAL_HIGH 0x05
  70. #define LM63_REG_REMOTE_TEMP_MSB 0x01
  71. #define LM63_REG_REMOTE_TEMP_LSB 0x10
  72. #define LM63_REG_REMOTE_OFFSET_MSB 0x11
  73. #define LM63_REG_REMOTE_OFFSET_LSB 0x12
  74. #define LM63_REG_REMOTE_HIGH_MSB 0x07
  75. #define LM63_REG_REMOTE_HIGH_LSB 0x13
  76. #define LM63_REG_REMOTE_LOW_MSB 0x08
  77. #define LM63_REG_REMOTE_LOW_LSB 0x14
  78. #define LM63_REG_REMOTE_TCRIT 0x19
  79. #define LM63_REG_REMOTE_TCRIT_HYST 0x21
  80. #define LM63_REG_ALERT_STATUS 0x02
  81. #define LM63_REG_ALERT_MASK 0x16
  82. #define LM63_REG_MAN_ID 0xFE
  83. #define LM63_REG_CHIP_ID 0xFF
  84. /*
  85. * Conversions and various macros
  86. * For tachometer counts, the LM63 uses 16-bit values.
  87. * For local temperature and high limit, remote critical limit and hysteresis
  88. * value, it uses signed 8-bit values with LSB = 1 degree Celcius.
  89. * For remote temperature, low and high limits, it uses signed 11-bit values
  90. * with LSB = 0.125 degree Celcius, left-justified in 16-bit registers.
  91. */
  92. #define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
  93. 5400000 / (reg))
  94. #define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \
  95. (5400000 / (val)) & 0xFFFC)
  96. #define TEMP8_FROM_REG(reg) ((reg) * 1000)
  97. #define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \
  98. (val) >= 127000 ? 127 : \
  99. (val) < 0 ? ((val) - 500) / 1000 : \
  100. ((val) + 500) / 1000)
  101. #define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
  102. #define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
  103. (val) >= 127875 ? 0x7FE0 : \
  104. (val) < 0 ? ((val) - 62) / 125 * 32 : \
  105. ((val) + 62) / 125 * 32)
  106. #define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
  107. (val) >= 127000 ? 127 : \
  108. ((val) + 500) / 1000)
  109. /*
  110. * Functions declaration
  111. */
  112. static int lm63_attach_adapter(struct i2c_adapter *adapter);
  113. static int lm63_detach_client(struct i2c_client *client);
  114. static struct lm63_data *lm63_update_device(struct device *dev);
  115. static int lm63_detect(struct i2c_adapter *adapter, int address, int kind);
  116. static void lm63_init_client(struct i2c_client *client);
  117. /*
  118. * Driver data (common to all clients)
  119. */
  120. static struct i2c_driver lm63_driver = {
  121. .owner = THIS_MODULE,
  122. .name = "lm63",
  123. .flags = I2C_DF_NOTIFY,
  124. .attach_adapter = lm63_attach_adapter,
  125. .detach_client = lm63_detach_client,
  126. };
  127. /*
  128. * Client data (each client gets its own)
  129. */
  130. struct lm63_data {
  131. struct i2c_client client;
  132. struct semaphore update_lock;
  133. char valid; /* zero until following fields are valid */
  134. unsigned long last_updated; /* in jiffies */
  135. /* registers values */
  136. u8 config, config_fan;
  137. u16 fan1_input;
  138. u16 fan1_low;
  139. u8 pwm1_freq;
  140. u8 pwm1_value;
  141. s8 temp1_input;
  142. s8 temp1_high;
  143. s16 temp2_input;
  144. s16 temp2_high;
  145. s16 temp2_low;
  146. s8 temp2_crit;
  147. u8 temp2_crit_hyst;
  148. u8 alarms;
  149. };
  150. /*
  151. * Sysfs callback functions and files
  152. */
  153. #define show_fan(value) \
  154. static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
  155. { \
  156. struct lm63_data *data = lm63_update_device(dev); \
  157. return sprintf(buf, "%d\n", FAN_FROM_REG(data->value)); \
  158. }
  159. show_fan(fan1_input);
  160. show_fan(fan1_low);
  161. static ssize_t set_fan1_low(struct device *dev, struct device_attribute *attr, const char *buf,
  162. size_t count)
  163. {
  164. struct i2c_client *client = to_i2c_client(dev);
  165. struct lm63_data *data = i2c_get_clientdata(client);
  166. unsigned long val = simple_strtoul(buf, NULL, 10);
  167. down(&data->update_lock);
  168. data->fan1_low = FAN_TO_REG(val);
  169. i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
  170. data->fan1_low & 0xFF);
  171. i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
  172. data->fan1_low >> 8);
  173. up(&data->update_lock);
  174. return count;
  175. }
  176. static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
  177. {
  178. struct lm63_data *data = lm63_update_device(dev);
  179. return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ?
  180. 255 : (data->pwm1_value * 255 + data->pwm1_freq) /
  181. (2 * data->pwm1_freq));
  182. }
  183. static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  184. {
  185. struct i2c_client *client = to_i2c_client(dev);
  186. struct lm63_data *data = i2c_get_clientdata(client);
  187. unsigned long val;
  188. if (!(data->config_fan & 0x20)) /* register is read-only */
  189. return -EPERM;
  190. val = simple_strtoul(buf, NULL, 10);
  191. down(&data->update_lock);
  192. data->pwm1_value = val <= 0 ? 0 :
  193. val >= 255 ? 2 * data->pwm1_freq :
  194. (val * data->pwm1_freq * 2 + 127) / 255;
  195. i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value);
  196. up(&data->update_lock);
  197. return count;
  198. }
  199. static ssize_t show_pwm1_enable(struct device *dev, struct device_attribute *attr, char *buf)
  200. {
  201. struct lm63_data *data = lm63_update_device(dev);
  202. return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2);
  203. }
  204. #define show_temp8(value) \
  205. static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
  206. { \
  207. struct lm63_data *data = lm63_update_device(dev); \
  208. return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->value)); \
  209. }
  210. #define show_temp11(value) \
  211. static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
  212. { \
  213. struct lm63_data *data = lm63_update_device(dev); \
  214. return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->value)); \
  215. }
  216. show_temp8(temp1_input);
  217. show_temp8(temp1_high);
  218. show_temp11(temp2_input);
  219. show_temp11(temp2_high);
  220. show_temp11(temp2_low);
  221. show_temp8(temp2_crit);
  222. #define set_temp8(value, reg) \
  223. static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, \
  224. size_t count) \
  225. { \
  226. struct i2c_client *client = to_i2c_client(dev); \
  227. struct lm63_data *data = i2c_get_clientdata(client); \
  228. long val = simple_strtol(buf, NULL, 10); \
  229. \
  230. down(&data->update_lock); \
  231. data->value = TEMP8_TO_REG(val); \
  232. i2c_smbus_write_byte_data(client, reg, data->value); \
  233. up(&data->update_lock); \
  234. return count; \
  235. }
  236. #define set_temp11(value, reg_msb, reg_lsb) \
  237. static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, \
  238. size_t count) \
  239. { \
  240. struct i2c_client *client = to_i2c_client(dev); \
  241. struct lm63_data *data = i2c_get_clientdata(client); \
  242. long val = simple_strtol(buf, NULL, 10); \
  243. \
  244. down(&data->update_lock); \
  245. data->value = TEMP11_TO_REG(val); \
  246. i2c_smbus_write_byte_data(client, reg_msb, data->value >> 8); \
  247. i2c_smbus_write_byte_data(client, reg_lsb, data->value & 0xff); \
  248. up(&data->update_lock); \
  249. return count; \
  250. }
  251. set_temp8(temp1_high, LM63_REG_LOCAL_HIGH);
  252. set_temp11(temp2_high, LM63_REG_REMOTE_HIGH_MSB, LM63_REG_REMOTE_HIGH_LSB);
  253. set_temp11(temp2_low, LM63_REG_REMOTE_LOW_MSB, LM63_REG_REMOTE_LOW_LSB);
  254. /* Hysteresis register holds a relative value, while we want to present
  255. an absolute to user-space */
  256. static ssize_t show_temp2_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf)
  257. {
  258. struct lm63_data *data = lm63_update_device(dev);
  259. return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp2_crit)
  260. - TEMP8_FROM_REG(data->temp2_crit_hyst));
  261. }
  262. /* And now the other way around, user-space provides an absolute
  263. hysteresis value and we have to store a relative one */
  264. static ssize_t set_temp2_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf,
  265. size_t count)
  266. {
  267. struct i2c_client *client = to_i2c_client(dev);
  268. struct lm63_data *data = i2c_get_clientdata(client);
  269. long val = simple_strtol(buf, NULL, 10);
  270. long hyst;
  271. down(&data->update_lock);
  272. hyst = TEMP8_FROM_REG(data->temp2_crit) - val;
  273. i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
  274. HYST_TO_REG(hyst));
  275. up(&data->update_lock);
  276. return count;
  277. }
  278. static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
  279. {
  280. struct lm63_data *data = lm63_update_device(dev);
  281. return sprintf(buf, "%u\n", data->alarms);
  282. }
  283. static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan1_input, NULL);
  284. static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan1_low,
  285. set_fan1_low);
  286. static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1);
  287. static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL);
  288. static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1_input, NULL);
  289. static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp1_high,
  290. set_temp1_high);
  291. static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp2_input, NULL);
  292. static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp2_low,
  293. set_temp2_low);
  294. static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp2_high,
  295. set_temp2_high);
  296. static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp2_crit, NULL);
  297. static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
  298. set_temp2_crit_hyst);
  299. static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
  300. /*
  301. * Real code
  302. */
  303. static int lm63_attach_adapter(struct i2c_adapter *adapter)
  304. {
  305. if (!(adapter->class & I2C_CLASS_HWMON))
  306. return 0;
  307. return i2c_detect(adapter, &addr_data, lm63_detect);
  308. }
  309. /*
  310. * The following function does more than just detection. If detection
  311. * succeeds, it also registers the new chip.
  312. */
  313. static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
  314. {
  315. struct i2c_client *new_client;
  316. struct lm63_data *data;
  317. int err = 0;
  318. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
  319. goto exit;
  320. if (!(data = kmalloc(sizeof(struct lm63_data), GFP_KERNEL))) {
  321. err = -ENOMEM;
  322. goto exit;
  323. }
  324. memset(data, 0, sizeof(struct lm63_data));
  325. /* The common I2C client data is placed right before the
  326. LM63-specific data. */
  327. new_client = &data->client;
  328. i2c_set_clientdata(new_client, data);
  329. new_client->addr = address;
  330. new_client->adapter = adapter;
  331. new_client->driver = &lm63_driver;
  332. new_client->flags = 0;
  333. /* Default to an LM63 if forced */
  334. if (kind == 0)
  335. kind = lm63;
  336. if (kind < 0) { /* must identify */
  337. u8 man_id, chip_id, reg_config1, reg_config2;
  338. u8 reg_alert_status, reg_alert_mask;
  339. man_id = i2c_smbus_read_byte_data(new_client,
  340. LM63_REG_MAN_ID);
  341. chip_id = i2c_smbus_read_byte_data(new_client,
  342. LM63_REG_CHIP_ID);
  343. reg_config1 = i2c_smbus_read_byte_data(new_client,
  344. LM63_REG_CONFIG1);
  345. reg_config2 = i2c_smbus_read_byte_data(new_client,
  346. LM63_REG_CONFIG2);
  347. reg_alert_status = i2c_smbus_read_byte_data(new_client,
  348. LM63_REG_ALERT_STATUS);
  349. reg_alert_mask = i2c_smbus_read_byte_data(new_client,
  350. LM63_REG_ALERT_MASK);
  351. if (man_id == 0x01 /* National Semiconductor */
  352. && chip_id == 0x41 /* LM63 */
  353. && (reg_config1 & 0x18) == 0x00
  354. && (reg_config2 & 0xF8) == 0x00
  355. && (reg_alert_status & 0x20) == 0x00
  356. && (reg_alert_mask & 0xA4) == 0xA4) {
  357. kind = lm63;
  358. } else { /* failed */
  359. dev_dbg(&adapter->dev, "Unsupported chip "
  360. "(man_id=0x%02X, chip_id=0x%02X).\n",
  361. man_id, chip_id);
  362. goto exit_free;
  363. }
  364. }
  365. strlcpy(new_client->name, "lm63", I2C_NAME_SIZE);
  366. data->valid = 0;
  367. init_MUTEX(&data->update_lock);
  368. /* Tell the I2C layer a new client has arrived */
  369. if ((err = i2c_attach_client(new_client)))
  370. goto exit_free;
  371. /* Initialize the LM63 chip */
  372. lm63_init_client(new_client);
  373. /* Register sysfs hooks */
  374. if (data->config & 0x04) { /* tachometer enabled */
  375. device_create_file(&new_client->dev, &dev_attr_fan1_input);
  376. device_create_file(&new_client->dev, &dev_attr_fan1_min);
  377. }
  378. device_create_file(&new_client->dev, &dev_attr_pwm1);
  379. device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
  380. device_create_file(&new_client->dev, &dev_attr_temp1_input);
  381. device_create_file(&new_client->dev, &dev_attr_temp2_input);
  382. device_create_file(&new_client->dev, &dev_attr_temp2_min);
  383. device_create_file(&new_client->dev, &dev_attr_temp1_max);
  384. device_create_file(&new_client->dev, &dev_attr_temp2_max);
  385. device_create_file(&new_client->dev, &dev_attr_temp2_crit);
  386. device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
  387. device_create_file(&new_client->dev, &dev_attr_alarms);
  388. return 0;
  389. exit_free:
  390. kfree(data);
  391. exit:
  392. return err;
  393. }
  394. /* Idealy we shouldn't have to initialize anything, since the BIOS
  395. should have taken care of everything */
  396. static void lm63_init_client(struct i2c_client *client)
  397. {
  398. struct lm63_data *data = i2c_get_clientdata(client);
  399. data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
  400. data->config_fan = i2c_smbus_read_byte_data(client,
  401. LM63_REG_CONFIG_FAN);
  402. /* Start converting if needed */
  403. if (data->config & 0x40) { /* standby */
  404. dev_dbg(&client->dev, "Switching to operational mode");
  405. data->config &= 0xA7;
  406. i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
  407. data->config);
  408. }
  409. /* We may need pwm1_freq before ever updating the client data */
  410. data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ);
  411. if (data->pwm1_freq == 0)
  412. data->pwm1_freq = 1;
  413. /* Show some debug info about the LM63 configuration */
  414. dev_dbg(&client->dev, "Alert/tach pin configured for %s\n",
  415. (data->config & 0x04) ? "tachometer input" :
  416. "alert output");
  417. dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n",
  418. (data->config_fan & 0x08) ? "1.4" : "360",
  419. ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq);
  420. dev_dbg(&client->dev, "PWM output active %s, %s mode\n",
  421. (data->config_fan & 0x10) ? "low" : "high",
  422. (data->config_fan & 0x20) ? "manual" : "auto");
  423. }
  424. static int lm63_detach_client(struct i2c_client *client)
  425. {
  426. int err;
  427. if ((err = i2c_detach_client(client))) {
  428. dev_err(&client->dev, "Client deregistration failed, "
  429. "client not detached\n");
  430. return err;
  431. }
  432. kfree(i2c_get_clientdata(client));
  433. return 0;
  434. }
  435. static struct lm63_data *lm63_update_device(struct device *dev)
  436. {
  437. struct i2c_client *client = to_i2c_client(dev);
  438. struct lm63_data *data = i2c_get_clientdata(client);
  439. down(&data->update_lock);
  440. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  441. if (data->config & 0x04) { /* tachometer enabled */
  442. /* order matters for fan1_input */
  443. data->fan1_input = i2c_smbus_read_byte_data(client,
  444. LM63_REG_TACH_COUNT_LSB) & 0xFC;
  445. data->fan1_input |= i2c_smbus_read_byte_data(client,
  446. LM63_REG_TACH_COUNT_MSB) << 8;
  447. data->fan1_low = (i2c_smbus_read_byte_data(client,
  448. LM63_REG_TACH_LIMIT_LSB) & 0xFC)
  449. | (i2c_smbus_read_byte_data(client,
  450. LM63_REG_TACH_LIMIT_MSB) << 8);
  451. }
  452. data->pwm1_freq = i2c_smbus_read_byte_data(client,
  453. LM63_REG_PWM_FREQ);
  454. if (data->pwm1_freq == 0)
  455. data->pwm1_freq = 1;
  456. data->pwm1_value = i2c_smbus_read_byte_data(client,
  457. LM63_REG_PWM_VALUE);
  458. data->temp1_input = i2c_smbus_read_byte_data(client,
  459. LM63_REG_LOCAL_TEMP);
  460. data->temp1_high = i2c_smbus_read_byte_data(client,
  461. LM63_REG_LOCAL_HIGH);
  462. /* order matters for temp2_input */
  463. data->temp2_input = i2c_smbus_read_byte_data(client,
  464. LM63_REG_REMOTE_TEMP_MSB) << 8;
  465. data->temp2_input |= i2c_smbus_read_byte_data(client,
  466. LM63_REG_REMOTE_TEMP_LSB);
  467. data->temp2_high = (i2c_smbus_read_byte_data(client,
  468. LM63_REG_REMOTE_HIGH_MSB) << 8)
  469. | i2c_smbus_read_byte_data(client,
  470. LM63_REG_REMOTE_HIGH_LSB);
  471. data->temp2_low = (i2c_smbus_read_byte_data(client,
  472. LM63_REG_REMOTE_LOW_MSB) << 8)
  473. | i2c_smbus_read_byte_data(client,
  474. LM63_REG_REMOTE_LOW_LSB);
  475. data->temp2_crit = i2c_smbus_read_byte_data(client,
  476. LM63_REG_REMOTE_TCRIT);
  477. data->temp2_crit_hyst = i2c_smbus_read_byte_data(client,
  478. LM63_REG_REMOTE_TCRIT_HYST);
  479. data->alarms = i2c_smbus_read_byte_data(client,
  480. LM63_REG_ALERT_STATUS) & 0x7F;
  481. data->last_updated = jiffies;
  482. data->valid = 1;
  483. }
  484. up(&data->update_lock);
  485. return data;
  486. }
  487. static int __init sensors_lm63_init(void)
  488. {
  489. return i2c_add_driver(&lm63_driver);
  490. }
  491. static void __exit sensors_lm63_exit(void)
  492. {
  493. i2c_del_driver(&lm63_driver);
  494. }
  495. MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
  496. MODULE_DESCRIPTION("LM63 driver");
  497. MODULE_LICENSE("GPL");
  498. module_init(sensors_lm63_init);
  499. module_exit(sensors_lm63_exit);