lm63.c 18 KB

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