jc42.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /*
  2. * jc42.c - driver for Jedec JC42.4 compliant temperature sensors
  3. *
  4. * Copyright (c) 2010 Ericsson AB.
  5. *
  6. * Derived from lm77.c by Andras BALI <drewie@freemail.hu>.
  7. *
  8. * JC42.4 compliant temperature sensors are typically used on memory modules.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/slab.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/i2c.h>
  29. #include <linux/hwmon.h>
  30. #include <linux/hwmon-sysfs.h>
  31. #include <linux/err.h>
  32. #include <linux/mutex.h>
  33. /* Addresses to scan */
  34. static const unsigned short normal_i2c[] = {
  35. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, I2C_CLIENT_END };
  36. /* JC42 registers. All registers are 16 bit. */
  37. #define JC42_REG_CAP 0x00
  38. #define JC42_REG_CONFIG 0x01
  39. #define JC42_REG_TEMP_UPPER 0x02
  40. #define JC42_REG_TEMP_LOWER 0x03
  41. #define JC42_REG_TEMP_CRITICAL 0x04
  42. #define JC42_REG_TEMP 0x05
  43. #define JC42_REG_MANID 0x06
  44. #define JC42_REG_DEVICEID 0x07
  45. /* Status bits in temperature register */
  46. #define JC42_ALARM_CRIT_BIT 15
  47. #define JC42_ALARM_MAX_BIT 14
  48. #define JC42_ALARM_MIN_BIT 13
  49. /* Configuration register defines */
  50. #define JC42_CFG_CRIT_ONLY (1 << 2)
  51. #define JC42_CFG_TCRIT_LOCK (1 << 6)
  52. #define JC42_CFG_EVENT_LOCK (1 << 7)
  53. #define JC42_CFG_SHUTDOWN (1 << 8)
  54. #define JC42_CFG_HYST_SHIFT 9
  55. #define JC42_CFG_HYST_MASK 0x03
  56. /* Capabilities */
  57. #define JC42_CAP_RANGE (1 << 2)
  58. /* Manufacturer IDs */
  59. #define ADT_MANID 0x11d4 /* Analog Devices */
  60. #define MAX_MANID 0x004d /* Maxim */
  61. #define IDT_MANID 0x00b3 /* IDT */
  62. #define MCP_MANID 0x0054 /* Microchip */
  63. #define NXP_MANID 0x1131 /* NXP Semiconductors */
  64. #define ONS_MANID 0x1b09 /* ON Semiconductor */
  65. #define STM_MANID 0x104a /* ST Microelectronics */
  66. /* Supported chips */
  67. /* Analog Devices */
  68. #define ADT7408_DEVID 0x0801
  69. #define ADT7408_DEVID_MASK 0xffff
  70. /* IDT */
  71. #define TS3000B3_DEVID 0x2903 /* Also matches TSE2002B3 */
  72. #define TS3000B3_DEVID_MASK 0xffff
  73. /* Maxim */
  74. #define MAX6604_DEVID 0x3e00
  75. #define MAX6604_DEVID_MASK 0xffff
  76. /* Microchip */
  77. #define MCP98242_DEVID 0x2000
  78. #define MCP98242_DEVID_MASK 0xfffc
  79. #define MCP98243_DEVID 0x2100
  80. #define MCP98243_DEVID_MASK 0xfffc
  81. #define MCP9843_DEVID 0x0000 /* Also matches mcp9805 */
  82. #define MCP9843_DEVID_MASK 0xfffe
  83. /* NXP */
  84. #define SE97_DEVID 0xa200
  85. #define SE97_DEVID_MASK 0xfffc
  86. #define SE98_DEVID 0xa100
  87. #define SE98_DEVID_MASK 0xfffc
  88. /* ON Semiconductor */
  89. #define CAT6095_DEVID 0x0800 /* Also matches CAT34TS02 */
  90. #define CAT6095_DEVID_MASK 0xffe0
  91. /* ST Microelectronics */
  92. #define STTS424_DEVID 0x0101
  93. #define STTS424_DEVID_MASK 0xffff
  94. #define STTS424E_DEVID 0x0000
  95. #define STTS424E_DEVID_MASK 0xfffe
  96. static u16 jc42_hysteresis[] = { 0, 1500, 3000, 6000 };
  97. struct jc42_chips {
  98. u16 manid;
  99. u16 devid;
  100. u16 devid_mask;
  101. };
  102. static struct jc42_chips jc42_chips[] = {
  103. { ADT_MANID, ADT7408_DEVID, ADT7408_DEVID_MASK },
  104. { IDT_MANID, TS3000B3_DEVID, TS3000B3_DEVID_MASK },
  105. { MAX_MANID, MAX6604_DEVID, MAX6604_DEVID_MASK },
  106. { MCP_MANID, MCP98242_DEVID, MCP98242_DEVID_MASK },
  107. { MCP_MANID, MCP98243_DEVID, MCP98243_DEVID_MASK },
  108. { MCP_MANID, MCP9843_DEVID, MCP9843_DEVID_MASK },
  109. { NXP_MANID, SE97_DEVID, SE97_DEVID_MASK },
  110. { ONS_MANID, CAT6095_DEVID, CAT6095_DEVID_MASK },
  111. { NXP_MANID, SE98_DEVID, SE98_DEVID_MASK },
  112. { STM_MANID, STTS424_DEVID, STTS424_DEVID_MASK },
  113. { STM_MANID, STTS424E_DEVID, STTS424E_DEVID_MASK },
  114. };
  115. /* Each client has this additional data */
  116. struct jc42_data {
  117. struct device *hwmon_dev;
  118. struct mutex update_lock; /* protect register access */
  119. bool extended; /* true if extended range supported */
  120. bool valid;
  121. unsigned long last_updated; /* In jiffies */
  122. u16 orig_config; /* original configuration */
  123. u16 config; /* current configuration */
  124. u16 temp_input; /* Temperatures */
  125. u16 temp_crit;
  126. u16 temp_min;
  127. u16 temp_max;
  128. };
  129. static int jc42_probe(struct i2c_client *client,
  130. const struct i2c_device_id *id);
  131. static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info);
  132. static int jc42_remove(struct i2c_client *client);
  133. static int jc42_read_value(struct i2c_client *client, u8 reg);
  134. static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value);
  135. static struct jc42_data *jc42_update_device(struct device *dev);
  136. static const struct i2c_device_id jc42_id[] = {
  137. { "adt7408", 0 },
  138. { "cat94ts02", 0 },
  139. { "cat6095", 0 },
  140. { "jc42", 0 },
  141. { "max6604", 0 },
  142. { "mcp9805", 0 },
  143. { "mcp98242", 0 },
  144. { "mcp98243", 0 },
  145. { "mcp9843", 0 },
  146. { "se97", 0 },
  147. { "se97b", 0 },
  148. { "se98", 0 },
  149. { "stts424", 0 },
  150. { "tse2002b3", 0 },
  151. { "ts3000b3", 0 },
  152. { }
  153. };
  154. MODULE_DEVICE_TABLE(i2c, jc42_id);
  155. #ifdef CONFIG_PM
  156. static int jc42_suspend(struct device *dev)
  157. {
  158. struct i2c_client *client = to_i2c_client(dev);
  159. struct jc42_data *data = i2c_get_clientdata(client);
  160. data->config |= JC42_CFG_SHUTDOWN;
  161. jc42_write_value(client, JC42_REG_CONFIG, data->config);
  162. return 0;
  163. }
  164. static int jc42_resume(struct device *dev)
  165. {
  166. struct i2c_client *client = to_i2c_client(dev);
  167. struct jc42_data *data = i2c_get_clientdata(client);
  168. data->config &= ~JC42_CFG_SHUTDOWN;
  169. jc42_write_value(client, JC42_REG_CONFIG, data->config);
  170. return 0;
  171. }
  172. static const struct dev_pm_ops jc42_dev_pm_ops = {
  173. .suspend = jc42_suspend,
  174. .resume = jc42_resume,
  175. };
  176. #define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
  177. #else
  178. #define JC42_DEV_PM_OPS NULL
  179. #endif /* CONFIG_PM */
  180. /* This is the driver that will be inserted */
  181. static struct i2c_driver jc42_driver = {
  182. .class = I2C_CLASS_SPD,
  183. .driver = {
  184. .name = "jc42",
  185. .pm = JC42_DEV_PM_OPS,
  186. },
  187. .probe = jc42_probe,
  188. .remove = jc42_remove,
  189. .id_table = jc42_id,
  190. .detect = jc42_detect,
  191. .address_list = normal_i2c,
  192. };
  193. #define JC42_TEMP_MIN_EXTENDED (-40000)
  194. #define JC42_TEMP_MIN 0
  195. #define JC42_TEMP_MAX 125000
  196. static u16 jc42_temp_to_reg(int temp, bool extended)
  197. {
  198. int ntemp = SENSORS_LIMIT(temp,
  199. extended ? JC42_TEMP_MIN_EXTENDED :
  200. JC42_TEMP_MIN, JC42_TEMP_MAX);
  201. /* convert from 0.001 to 0.0625 resolution */
  202. return (ntemp * 2 / 125) & 0x1fff;
  203. }
  204. static int jc42_temp_from_reg(s16 reg)
  205. {
  206. reg &= 0x1fff;
  207. /* sign extend register */
  208. if (reg & 0x1000)
  209. reg |= 0xf000;
  210. /* convert from 0.0625 to 0.001 resolution */
  211. return reg * 125 / 2;
  212. }
  213. /* sysfs stuff */
  214. /* read routines for temperature limits */
  215. #define show(value) \
  216. static ssize_t show_##value(struct device *dev, \
  217. struct device_attribute *attr, \
  218. char *buf) \
  219. { \
  220. struct jc42_data *data = jc42_update_device(dev); \
  221. if (IS_ERR(data)) \
  222. return PTR_ERR(data); \
  223. return sprintf(buf, "%d\n", jc42_temp_from_reg(data->value)); \
  224. }
  225. show(temp_input);
  226. show(temp_crit);
  227. show(temp_min);
  228. show(temp_max);
  229. /* read routines for hysteresis values */
  230. static ssize_t show_temp_crit_hyst(struct device *dev,
  231. struct device_attribute *attr, char *buf)
  232. {
  233. struct jc42_data *data = jc42_update_device(dev);
  234. int temp, hyst;
  235. if (IS_ERR(data))
  236. return PTR_ERR(data);
  237. temp = jc42_temp_from_reg(data->temp_crit);
  238. hyst = jc42_hysteresis[(data->config >> JC42_CFG_HYST_SHIFT)
  239. & JC42_CFG_HYST_MASK];
  240. return sprintf(buf, "%d\n", temp - hyst);
  241. }
  242. static ssize_t show_temp_max_hyst(struct device *dev,
  243. struct device_attribute *attr, char *buf)
  244. {
  245. struct jc42_data *data = jc42_update_device(dev);
  246. int temp, hyst;
  247. if (IS_ERR(data))
  248. return PTR_ERR(data);
  249. temp = jc42_temp_from_reg(data->temp_max);
  250. hyst = jc42_hysteresis[(data->config >> JC42_CFG_HYST_SHIFT)
  251. & JC42_CFG_HYST_MASK];
  252. return sprintf(buf, "%d\n", temp - hyst);
  253. }
  254. /* write routines */
  255. #define set(value, reg) \
  256. static ssize_t set_##value(struct device *dev, \
  257. struct device_attribute *attr, \
  258. const char *buf, size_t count) \
  259. { \
  260. struct i2c_client *client = to_i2c_client(dev); \
  261. struct jc42_data *data = i2c_get_clientdata(client); \
  262. int err, ret = count; \
  263. long val; \
  264. if (strict_strtol(buf, 10, &val) < 0) \
  265. return -EINVAL; \
  266. mutex_lock(&data->update_lock); \
  267. data->value = jc42_temp_to_reg(val, data->extended); \
  268. err = jc42_write_value(client, reg, data->value); \
  269. if (err < 0) \
  270. ret = err; \
  271. mutex_unlock(&data->update_lock); \
  272. return ret; \
  273. }
  274. set(temp_min, JC42_REG_TEMP_LOWER);
  275. set(temp_max, JC42_REG_TEMP_UPPER);
  276. set(temp_crit, JC42_REG_TEMP_CRITICAL);
  277. /* JC42.4 compliant chips only support four hysteresis values.
  278. * Pick best choice and go from there. */
  279. static ssize_t set_temp_crit_hyst(struct device *dev,
  280. struct device_attribute *attr,
  281. const char *buf, size_t count)
  282. {
  283. struct i2c_client *client = to_i2c_client(dev);
  284. struct jc42_data *data = i2c_get_clientdata(client);
  285. unsigned long val;
  286. int diff, hyst;
  287. int err;
  288. int ret = count;
  289. if (strict_strtoul(buf, 10, &val) < 0)
  290. return -EINVAL;
  291. diff = jc42_temp_from_reg(data->temp_crit) - val;
  292. hyst = 0;
  293. if (diff > 0) {
  294. if (diff < 2250)
  295. hyst = 1; /* 1.5 degrees C */
  296. else if (diff < 4500)
  297. hyst = 2; /* 3.0 degrees C */
  298. else
  299. hyst = 3; /* 6.0 degrees C */
  300. }
  301. mutex_lock(&data->update_lock);
  302. data->config = (data->config
  303. & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))
  304. | (hyst << JC42_CFG_HYST_SHIFT);
  305. err = jc42_write_value(client, JC42_REG_CONFIG, data->config);
  306. if (err < 0)
  307. ret = err;
  308. mutex_unlock(&data->update_lock);
  309. return ret;
  310. }
  311. static ssize_t show_alarm(struct device *dev,
  312. struct device_attribute *attr, char *buf)
  313. {
  314. u16 bit = to_sensor_dev_attr(attr)->index;
  315. struct jc42_data *data = jc42_update_device(dev);
  316. u16 val;
  317. if (IS_ERR(data))
  318. return PTR_ERR(data);
  319. val = data->temp_input;
  320. if (bit != JC42_ALARM_CRIT_BIT && (data->config & JC42_CFG_CRIT_ONLY))
  321. val = 0;
  322. return sprintf(buf, "%u\n", (val >> bit) & 1);
  323. }
  324. static DEVICE_ATTR(temp1_input, S_IRUGO,
  325. show_temp_input, NULL);
  326. static DEVICE_ATTR(temp1_crit, S_IRUGO,
  327. show_temp_crit, set_temp_crit);
  328. static DEVICE_ATTR(temp1_min, S_IRUGO,
  329. show_temp_min, set_temp_min);
  330. static DEVICE_ATTR(temp1_max, S_IRUGO,
  331. show_temp_max, set_temp_max);
  332. static DEVICE_ATTR(temp1_crit_hyst, S_IRUGO,
  333. show_temp_crit_hyst, set_temp_crit_hyst);
  334. static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
  335. show_temp_max_hyst, NULL);
  336. static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
  337. JC42_ALARM_CRIT_BIT);
  338. static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
  339. JC42_ALARM_MIN_BIT);
  340. static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
  341. JC42_ALARM_MAX_BIT);
  342. static struct attribute *jc42_attributes[] = {
  343. &dev_attr_temp1_input.attr,
  344. &dev_attr_temp1_crit.attr,
  345. &dev_attr_temp1_min.attr,
  346. &dev_attr_temp1_max.attr,
  347. &dev_attr_temp1_crit_hyst.attr,
  348. &dev_attr_temp1_max_hyst.attr,
  349. &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
  350. &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
  351. &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  352. NULL
  353. };
  354. static mode_t jc42_attribute_mode(struct kobject *kobj,
  355. struct attribute *attr, int index)
  356. {
  357. struct device *dev = container_of(kobj, struct device, kobj);
  358. struct i2c_client *client = to_i2c_client(dev);
  359. struct jc42_data *data = i2c_get_clientdata(client);
  360. unsigned int config = data->config;
  361. bool readonly;
  362. if (attr == &dev_attr_temp1_crit.attr)
  363. readonly = config & JC42_CFG_TCRIT_LOCK;
  364. else if (attr == &dev_attr_temp1_min.attr ||
  365. attr == &dev_attr_temp1_max.attr)
  366. readonly = config & JC42_CFG_EVENT_LOCK;
  367. else if (attr == &dev_attr_temp1_crit_hyst.attr)
  368. readonly = config & (JC42_CFG_EVENT_LOCK | JC42_CFG_TCRIT_LOCK);
  369. else
  370. readonly = true;
  371. return S_IRUGO | (readonly ? 0 : S_IWUSR);
  372. }
  373. static const struct attribute_group jc42_group = {
  374. .attrs = jc42_attributes,
  375. .is_visible = jc42_attribute_mode,
  376. };
  377. /* Return 0 if detection is successful, -ENODEV otherwise */
  378. static int jc42_detect(struct i2c_client *new_client,
  379. struct i2c_board_info *info)
  380. {
  381. struct i2c_adapter *adapter = new_client->adapter;
  382. int i, config, cap, manid, devid;
  383. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
  384. I2C_FUNC_SMBUS_WORD_DATA))
  385. return -ENODEV;
  386. cap = jc42_read_value(new_client, JC42_REG_CAP);
  387. config = jc42_read_value(new_client, JC42_REG_CONFIG);
  388. manid = jc42_read_value(new_client, JC42_REG_MANID);
  389. devid = jc42_read_value(new_client, JC42_REG_DEVICEID);
  390. if (cap < 0 || config < 0 || manid < 0 || devid < 0)
  391. return -ENODEV;
  392. if ((cap & 0xff00) || (config & 0xf800))
  393. return -ENODEV;
  394. for (i = 0; i < ARRAY_SIZE(jc42_chips); i++) {
  395. struct jc42_chips *chip = &jc42_chips[i];
  396. if (manid == chip->manid &&
  397. (devid & chip->devid_mask) == chip->devid) {
  398. strlcpy(info->type, "jc42", I2C_NAME_SIZE);
  399. return 0;
  400. }
  401. }
  402. return -ENODEV;
  403. }
  404. static int jc42_probe(struct i2c_client *new_client,
  405. const struct i2c_device_id *id)
  406. {
  407. struct jc42_data *data;
  408. int config, cap, err;
  409. data = kzalloc(sizeof(struct jc42_data), GFP_KERNEL);
  410. if (!data) {
  411. err = -ENOMEM;
  412. goto exit;
  413. }
  414. i2c_set_clientdata(new_client, data);
  415. mutex_init(&data->update_lock);
  416. cap = jc42_read_value(new_client, JC42_REG_CAP);
  417. if (cap < 0) {
  418. err = -EINVAL;
  419. goto exit_free;
  420. }
  421. data->extended = !!(cap & JC42_CAP_RANGE);
  422. config = jc42_read_value(new_client, JC42_REG_CONFIG);
  423. if (config < 0) {
  424. err = -EINVAL;
  425. goto exit_free;
  426. }
  427. data->orig_config = config;
  428. if (config & JC42_CFG_SHUTDOWN) {
  429. config &= ~JC42_CFG_SHUTDOWN;
  430. jc42_write_value(new_client, JC42_REG_CONFIG, config);
  431. }
  432. data->config = config;
  433. /* Register sysfs hooks */
  434. err = sysfs_create_group(&new_client->dev.kobj, &jc42_group);
  435. if (err)
  436. goto exit_free;
  437. data->hwmon_dev = hwmon_device_register(&new_client->dev);
  438. if (IS_ERR(data->hwmon_dev)) {
  439. err = PTR_ERR(data->hwmon_dev);
  440. goto exit_remove;
  441. }
  442. return 0;
  443. exit_remove:
  444. sysfs_remove_group(&new_client->dev.kobj, &jc42_group);
  445. exit_free:
  446. kfree(data);
  447. exit:
  448. return err;
  449. }
  450. static int jc42_remove(struct i2c_client *client)
  451. {
  452. struct jc42_data *data = i2c_get_clientdata(client);
  453. hwmon_device_unregister(data->hwmon_dev);
  454. sysfs_remove_group(&client->dev.kobj, &jc42_group);
  455. if (data->config != data->orig_config)
  456. jc42_write_value(client, JC42_REG_CONFIG, data->orig_config);
  457. kfree(data);
  458. return 0;
  459. }
  460. /* All registers are word-sized. */
  461. static int jc42_read_value(struct i2c_client *client, u8 reg)
  462. {
  463. int ret = i2c_smbus_read_word_data(client, reg);
  464. if (ret < 0)
  465. return ret;
  466. return swab16(ret);
  467. }
  468. static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value)
  469. {
  470. return i2c_smbus_write_word_data(client, reg, swab16(value));
  471. }
  472. static struct jc42_data *jc42_update_device(struct device *dev)
  473. {
  474. struct i2c_client *client = to_i2c_client(dev);
  475. struct jc42_data *data = i2c_get_clientdata(client);
  476. struct jc42_data *ret = data;
  477. int val;
  478. mutex_lock(&data->update_lock);
  479. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  480. val = jc42_read_value(client, JC42_REG_TEMP);
  481. if (val < 0) {
  482. ret = ERR_PTR(val);
  483. goto abort;
  484. }
  485. data->temp_input = val;
  486. val = jc42_read_value(client, JC42_REG_TEMP_CRITICAL);
  487. if (val < 0) {
  488. ret = ERR_PTR(val);
  489. goto abort;
  490. }
  491. data->temp_crit = val;
  492. val = jc42_read_value(client, JC42_REG_TEMP_LOWER);
  493. if (val < 0) {
  494. ret = ERR_PTR(val);
  495. goto abort;
  496. }
  497. data->temp_min = val;
  498. val = jc42_read_value(client, JC42_REG_TEMP_UPPER);
  499. if (val < 0) {
  500. ret = ERR_PTR(val);
  501. goto abort;
  502. }
  503. data->temp_max = val;
  504. data->last_updated = jiffies;
  505. data->valid = true;
  506. }
  507. abort:
  508. mutex_unlock(&data->update_lock);
  509. return ret;
  510. }
  511. static int __init sensors_jc42_init(void)
  512. {
  513. return i2c_add_driver(&jc42_driver);
  514. }
  515. static void __exit sensors_jc42_exit(void)
  516. {
  517. i2c_del_driver(&jc42_driver);
  518. }
  519. MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
  520. MODULE_DESCRIPTION("JC42 driver");
  521. MODULE_LICENSE("GPL");
  522. module_init(sensors_jc42_init);
  523. module_exit(sensors_jc42_exit);