lm63.c 18 KB

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