jc42.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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/bitops.h>
  25. #include <linux/module.h>
  26. #include <linux/init.h>
  27. #include <linux/slab.h>
  28. #include <linux/jiffies.h>
  29. #include <linux/i2c.h>
  30. #include <linux/hwmon.h>
  31. #include <linux/err.h>
  32. #include <linux/mutex.h>
  33. #include <linux/of.h>
  34. /* Addresses to scan */
  35. static const unsigned short normal_i2c[] = {
  36. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, I2C_CLIENT_END };
  37. /* JC42 registers. All registers are 16 bit. */
  38. #define JC42_REG_CAP 0x00
  39. #define JC42_REG_CONFIG 0x01
  40. #define JC42_REG_TEMP_UPPER 0x02
  41. #define JC42_REG_TEMP_LOWER 0x03
  42. #define JC42_REG_TEMP_CRITICAL 0x04
  43. #define JC42_REG_TEMP 0x05
  44. #define JC42_REG_MANID 0x06
  45. #define JC42_REG_DEVICEID 0x07
  46. #define JC42_REG_SMBUS 0x22 /* NXP and Atmel, possibly others? */
  47. /* Status bits in temperature register */
  48. #define JC42_ALARM_CRIT_BIT 15
  49. #define JC42_ALARM_MAX_BIT 14
  50. #define JC42_ALARM_MIN_BIT 13
  51. /* Configuration register defines */
  52. #define JC42_CFG_CRIT_ONLY (1 << 2)
  53. #define JC42_CFG_TCRIT_LOCK (1 << 6)
  54. #define JC42_CFG_EVENT_LOCK (1 << 7)
  55. #define JC42_CFG_SHUTDOWN (1 << 8)
  56. #define JC42_CFG_HYST_SHIFT 9
  57. #define JC42_CFG_HYST_MASK (0x03 << 9)
  58. /* Capabilities */
  59. #define JC42_CAP_RANGE (1 << 2)
  60. /* Manufacturer IDs */
  61. #define ADT_MANID 0x11d4 /* Analog Devices */
  62. #define ATMEL_MANID 0x001f /* Atmel */
  63. #define ATMEL_MANID2 0x1114 /* Atmel */
  64. #define MAX_MANID 0x004d /* Maxim */
  65. #define IDT_MANID 0x00b3 /* IDT */
  66. #define MCP_MANID 0x0054 /* Microchip */
  67. #define NXP_MANID 0x1131 /* NXP Semiconductors */
  68. #define ONS_MANID 0x1b09 /* ON Semiconductor */
  69. #define STM_MANID 0x104a /* ST Microelectronics */
  70. #define GT_MANID 0x1c68 /* Giantec */
  71. #define GT_MANID2 0x132d /* Giantec, 2nd mfg ID */
  72. /* SMBUS register */
  73. #define SMBUS_STMOUT BIT(7) /* SMBus time-out, active low */
  74. /* Supported chips */
  75. /* Analog Devices */
  76. #define ADT7408_DEVID 0x0801
  77. #define ADT7408_DEVID_MASK 0xffff
  78. /* Atmel */
  79. #define AT30TS00_DEVID 0x8201
  80. #define AT30TS00_DEVID_MASK 0xffff
  81. #define AT30TSE004_DEVID 0x2200
  82. #define AT30TSE004_DEVID_MASK 0xffff
  83. /* Giantec */
  84. #define GT30TS00_DEVID 0x2200
  85. #define GT30TS00_DEVID_MASK 0xff00
  86. #define GT34TS02_DEVID 0x3300
  87. #define GT34TS02_DEVID_MASK 0xff00
  88. /* IDT */
  89. #define TSE2004_DEVID 0x2200
  90. #define TSE2004_DEVID_MASK 0xff00
  91. #define TS3000_DEVID 0x2900 /* Also matches TSE2002 */
  92. #define TS3000_DEVID_MASK 0xff00
  93. #define TS3001_DEVID 0x3000
  94. #define TS3001_DEVID_MASK 0xff00
  95. /* Maxim */
  96. #define MAX6604_DEVID 0x3e00
  97. #define MAX6604_DEVID_MASK 0xffff
  98. /* Microchip */
  99. #define MCP9804_DEVID 0x0200
  100. #define MCP9804_DEVID_MASK 0xfffc
  101. #define MCP9808_DEVID 0x0400
  102. #define MCP9808_DEVID_MASK 0xfffc
  103. #define MCP98242_DEVID 0x2000
  104. #define MCP98242_DEVID_MASK 0xfffc
  105. #define MCP98243_DEVID 0x2100
  106. #define MCP98243_DEVID_MASK 0xfffc
  107. #define MCP98244_DEVID 0x2200
  108. #define MCP98244_DEVID_MASK 0xfffc
  109. #define MCP9843_DEVID 0x0000 /* Also matches mcp9805 */
  110. #define MCP9843_DEVID_MASK 0xfffe
  111. /* NXP */
  112. #define SE97_DEVID 0xa200
  113. #define SE97_DEVID_MASK 0xfffc
  114. #define SE98_DEVID 0xa100
  115. #define SE98_DEVID_MASK 0xfffc
  116. /* ON Semiconductor */
  117. #define CAT6095_DEVID 0x0800 /* Also matches CAT34TS02 */
  118. #define CAT6095_DEVID_MASK 0xffe0
  119. #define CAT34TS02C_DEVID 0x0a00
  120. #define CAT34TS02C_DEVID_MASK 0xfff0
  121. #define CAT34TS04_DEVID 0x2200
  122. #define CAT34TS04_DEVID_MASK 0xfff0
  123. /* ST Microelectronics */
  124. #define STTS424_DEVID 0x0101
  125. #define STTS424_DEVID_MASK 0xffff
  126. #define STTS424E_DEVID 0x0000
  127. #define STTS424E_DEVID_MASK 0xfffe
  128. #define STTS2002_DEVID 0x0300
  129. #define STTS2002_DEVID_MASK 0xffff
  130. #define STTS2004_DEVID 0x2201
  131. #define STTS2004_DEVID_MASK 0xffff
  132. #define STTS3000_DEVID 0x0200
  133. #define STTS3000_DEVID_MASK 0xffff
  134. static u16 jc42_hysteresis[] = { 0, 1500, 3000, 6000 };
  135. struct jc42_chips {
  136. u16 manid;
  137. u16 devid;
  138. u16 devid_mask;
  139. };
  140. static struct jc42_chips jc42_chips[] = {
  141. { ADT_MANID, ADT7408_DEVID, ADT7408_DEVID_MASK },
  142. { ATMEL_MANID, AT30TS00_DEVID, AT30TS00_DEVID_MASK },
  143. { ATMEL_MANID2, AT30TSE004_DEVID, AT30TSE004_DEVID_MASK },
  144. { GT_MANID, GT30TS00_DEVID, GT30TS00_DEVID_MASK },
  145. { GT_MANID2, GT34TS02_DEVID, GT34TS02_DEVID_MASK },
  146. { IDT_MANID, TSE2004_DEVID, TSE2004_DEVID_MASK },
  147. { IDT_MANID, TS3000_DEVID, TS3000_DEVID_MASK },
  148. { IDT_MANID, TS3001_DEVID, TS3001_DEVID_MASK },
  149. { MAX_MANID, MAX6604_DEVID, MAX6604_DEVID_MASK },
  150. { MCP_MANID, MCP9804_DEVID, MCP9804_DEVID_MASK },
  151. { MCP_MANID, MCP9808_DEVID, MCP9808_DEVID_MASK },
  152. { MCP_MANID, MCP98242_DEVID, MCP98242_DEVID_MASK },
  153. { MCP_MANID, MCP98243_DEVID, MCP98243_DEVID_MASK },
  154. { MCP_MANID, MCP98244_DEVID, MCP98244_DEVID_MASK },
  155. { MCP_MANID, MCP9843_DEVID, MCP9843_DEVID_MASK },
  156. { NXP_MANID, SE97_DEVID, SE97_DEVID_MASK },
  157. { ONS_MANID, CAT6095_DEVID, CAT6095_DEVID_MASK },
  158. { ONS_MANID, CAT34TS02C_DEVID, CAT34TS02C_DEVID_MASK },
  159. { ONS_MANID, CAT34TS04_DEVID, CAT34TS04_DEVID_MASK },
  160. { NXP_MANID, SE98_DEVID, SE98_DEVID_MASK },
  161. { STM_MANID, STTS424_DEVID, STTS424_DEVID_MASK },
  162. { STM_MANID, STTS424E_DEVID, STTS424E_DEVID_MASK },
  163. { STM_MANID, STTS2002_DEVID, STTS2002_DEVID_MASK },
  164. { STM_MANID, STTS2004_DEVID, STTS2004_DEVID_MASK },
  165. { STM_MANID, STTS3000_DEVID, STTS3000_DEVID_MASK },
  166. };
  167. enum temp_index {
  168. t_input = 0,
  169. t_crit,
  170. t_min,
  171. t_max,
  172. t_num_temp
  173. };
  174. static const u8 temp_regs[t_num_temp] = {
  175. [t_input] = JC42_REG_TEMP,
  176. [t_crit] = JC42_REG_TEMP_CRITICAL,
  177. [t_min] = JC42_REG_TEMP_LOWER,
  178. [t_max] = JC42_REG_TEMP_UPPER,
  179. };
  180. /* Each client has this additional data */
  181. struct jc42_data {
  182. struct i2c_client *client;
  183. struct mutex update_lock; /* protect register access */
  184. bool extended; /* true if extended range supported */
  185. bool valid;
  186. unsigned long last_updated; /* In jiffies */
  187. u16 orig_config; /* original configuration */
  188. u16 config; /* current configuration */
  189. u16 temp[t_num_temp];/* Temperatures */
  190. };
  191. #define JC42_TEMP_MIN_EXTENDED (-40000)
  192. #define JC42_TEMP_MIN 0
  193. #define JC42_TEMP_MAX 125000
  194. static u16 jc42_temp_to_reg(long temp, bool extended)
  195. {
  196. int ntemp = clamp_val(temp,
  197. extended ? JC42_TEMP_MIN_EXTENDED :
  198. JC42_TEMP_MIN, JC42_TEMP_MAX);
  199. /* convert from 0.001 to 0.0625 resolution */
  200. return (ntemp * 2 / 125) & 0x1fff;
  201. }
  202. static int jc42_temp_from_reg(s16 reg)
  203. {
  204. reg = sign_extend32(reg, 12);
  205. /* convert from 0.0625 to 0.001 resolution */
  206. return reg * 125 / 2;
  207. }
  208. static struct jc42_data *jc42_update_device(struct device *dev)
  209. {
  210. struct jc42_data *data = dev_get_drvdata(dev);
  211. struct i2c_client *client = data->client;
  212. struct jc42_data *ret = data;
  213. int i, val;
  214. mutex_lock(&data->update_lock);
  215. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  216. for (i = 0; i < t_num_temp; i++) {
  217. val = i2c_smbus_read_word_swapped(client, temp_regs[i]);
  218. if (val < 0) {
  219. ret = ERR_PTR(val);
  220. goto abort;
  221. }
  222. data->temp[i] = val;
  223. }
  224. data->last_updated = jiffies;
  225. data->valid = true;
  226. }
  227. abort:
  228. mutex_unlock(&data->update_lock);
  229. return ret;
  230. }
  231. static int jc42_read(struct device *dev, enum hwmon_sensor_types type,
  232. u32 attr, int channel, long *val)
  233. {
  234. struct jc42_data *data = jc42_update_device(dev);
  235. int temp, hyst;
  236. if (IS_ERR(data))
  237. return PTR_ERR(data);
  238. switch (attr) {
  239. case hwmon_temp_input:
  240. *val = jc42_temp_from_reg(data->temp[t_input]);
  241. return 0;
  242. case hwmon_temp_min:
  243. *val = jc42_temp_from_reg(data->temp[t_min]);
  244. return 0;
  245. case hwmon_temp_max:
  246. *val = jc42_temp_from_reg(data->temp[t_max]);
  247. return 0;
  248. case hwmon_temp_crit:
  249. *val = jc42_temp_from_reg(data->temp[t_crit]);
  250. return 0;
  251. case hwmon_temp_max_hyst:
  252. temp = jc42_temp_from_reg(data->temp[t_max]);
  253. hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
  254. >> JC42_CFG_HYST_SHIFT];
  255. *val = temp - hyst;
  256. return 0;
  257. case hwmon_temp_crit_hyst:
  258. temp = jc42_temp_from_reg(data->temp[t_crit]);
  259. hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
  260. >> JC42_CFG_HYST_SHIFT];
  261. *val = temp - hyst;
  262. return 0;
  263. case hwmon_temp_min_alarm:
  264. *val = (data->temp[t_input] >> JC42_ALARM_MIN_BIT) & 1;
  265. return 0;
  266. case hwmon_temp_max_alarm:
  267. *val = (data->temp[t_input] >> JC42_ALARM_MAX_BIT) & 1;
  268. return 0;
  269. case hwmon_temp_crit_alarm:
  270. *val = (data->temp[t_input] >> JC42_ALARM_CRIT_BIT) & 1;
  271. return 0;
  272. default:
  273. return -EOPNOTSUPP;
  274. }
  275. }
  276. static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
  277. u32 attr, int channel, long val)
  278. {
  279. struct jc42_data *data = dev_get_drvdata(dev);
  280. struct i2c_client *client = data->client;
  281. int diff, hyst;
  282. int ret;
  283. mutex_lock(&data->update_lock);
  284. switch (attr) {
  285. case hwmon_temp_min:
  286. data->temp[t_min] = jc42_temp_to_reg(val, data->extended);
  287. ret = i2c_smbus_write_word_swapped(client, temp_regs[t_min],
  288. data->temp[t_min]);
  289. break;
  290. case hwmon_temp_max:
  291. data->temp[t_max] = jc42_temp_to_reg(val, data->extended);
  292. ret = i2c_smbus_write_word_swapped(client, temp_regs[t_max],
  293. data->temp[t_max]);
  294. break;
  295. case hwmon_temp_crit:
  296. data->temp[t_crit] = jc42_temp_to_reg(val, data->extended);
  297. ret = i2c_smbus_write_word_swapped(client, temp_regs[t_crit],
  298. data->temp[t_crit]);
  299. break;
  300. case hwmon_temp_crit_hyst:
  301. /*
  302. * JC42.4 compliant chips only support four hysteresis values.
  303. * Pick best choice and go from there.
  304. */
  305. val = clamp_val(val, (data->extended ? JC42_TEMP_MIN_EXTENDED
  306. : JC42_TEMP_MIN) - 6000,
  307. JC42_TEMP_MAX);
  308. diff = jc42_temp_from_reg(data->temp[t_crit]) - val;
  309. hyst = 0;
  310. if (diff > 0) {
  311. if (diff < 2250)
  312. hyst = 1; /* 1.5 degrees C */
  313. else if (diff < 4500)
  314. hyst = 2; /* 3.0 degrees C */
  315. else
  316. hyst = 3; /* 6.0 degrees C */
  317. }
  318. data->config = (data->config & ~JC42_CFG_HYST_MASK) |
  319. (hyst << JC42_CFG_HYST_SHIFT);
  320. ret = i2c_smbus_write_word_swapped(data->client,
  321. JC42_REG_CONFIG,
  322. data->config);
  323. break;
  324. default:
  325. ret = -EOPNOTSUPP;
  326. break;
  327. }
  328. mutex_unlock(&data->update_lock);
  329. return ret;
  330. }
  331. static umode_t jc42_is_visible(const void *_data, enum hwmon_sensor_types type,
  332. u32 attr, int channel)
  333. {
  334. const struct jc42_data *data = _data;
  335. unsigned int config = data->config;
  336. umode_t mode = S_IRUGO;
  337. switch (attr) {
  338. case hwmon_temp_min:
  339. case hwmon_temp_max:
  340. if (!(config & JC42_CFG_EVENT_LOCK))
  341. mode |= S_IWUSR;
  342. break;
  343. case hwmon_temp_crit:
  344. if (!(config & JC42_CFG_TCRIT_LOCK))
  345. mode |= S_IWUSR;
  346. break;
  347. case hwmon_temp_crit_hyst:
  348. if (!(config & (JC42_CFG_EVENT_LOCK | JC42_CFG_TCRIT_LOCK)))
  349. mode |= S_IWUSR;
  350. break;
  351. case hwmon_temp_input:
  352. case hwmon_temp_max_hyst:
  353. case hwmon_temp_min_alarm:
  354. case hwmon_temp_max_alarm:
  355. case hwmon_temp_crit_alarm:
  356. break;
  357. default:
  358. mode = 0;
  359. break;
  360. }
  361. return mode;
  362. }
  363. /* Return 0 if detection is successful, -ENODEV otherwise */
  364. static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info)
  365. {
  366. struct i2c_adapter *adapter = client->adapter;
  367. int i, config, cap, manid, devid;
  368. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
  369. I2C_FUNC_SMBUS_WORD_DATA))
  370. return -ENODEV;
  371. cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
  372. config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
  373. manid = i2c_smbus_read_word_swapped(client, JC42_REG_MANID);
  374. devid = i2c_smbus_read_word_swapped(client, JC42_REG_DEVICEID);
  375. if (cap < 0 || config < 0 || manid < 0 || devid < 0)
  376. return -ENODEV;
  377. if ((cap & 0xff00) || (config & 0xf800))
  378. return -ENODEV;
  379. for (i = 0; i < ARRAY_SIZE(jc42_chips); i++) {
  380. struct jc42_chips *chip = &jc42_chips[i];
  381. if (manid == chip->manid &&
  382. (devid & chip->devid_mask) == chip->devid) {
  383. strlcpy(info->type, "jc42", I2C_NAME_SIZE);
  384. return 0;
  385. }
  386. }
  387. return -ENODEV;
  388. }
  389. static const u32 jc42_temp_config[] = {
  390. HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | HWMON_T_CRIT |
  391. HWMON_T_MAX_HYST | HWMON_T_CRIT_HYST |
  392. HWMON_T_MIN_ALARM | HWMON_T_MAX_ALARM | HWMON_T_CRIT_ALARM,
  393. 0
  394. };
  395. static const struct hwmon_channel_info jc42_temp = {
  396. .type = hwmon_temp,
  397. .config = jc42_temp_config,
  398. };
  399. static const struct hwmon_channel_info *jc42_info[] = {
  400. &jc42_temp,
  401. NULL
  402. };
  403. static const struct hwmon_ops jc42_hwmon_ops = {
  404. .is_visible = jc42_is_visible,
  405. .read = jc42_read,
  406. .write = jc42_write,
  407. };
  408. static const struct hwmon_chip_info jc42_chip_info = {
  409. .ops = &jc42_hwmon_ops,
  410. .info = jc42_info,
  411. };
  412. static int jc42_probe(struct i2c_client *client, const struct i2c_device_id *id)
  413. {
  414. struct device *dev = &client->dev;
  415. struct device *hwmon_dev;
  416. struct jc42_data *data;
  417. int config, cap;
  418. data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL);
  419. if (!data)
  420. return -ENOMEM;
  421. data->client = client;
  422. i2c_set_clientdata(client, data);
  423. mutex_init(&data->update_lock);
  424. cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
  425. if (cap < 0)
  426. return cap;
  427. data->extended = !!(cap & JC42_CAP_RANGE);
  428. if (device_property_read_bool(dev, "smbus-timeout-disable")) {
  429. int smbus;
  430. /*
  431. * Not all chips support this register, but from a
  432. * quick read of various datasheets no chip appears
  433. * incompatible with the below attempt to disable
  434. * the timeout. And the whole thing is opt-in...
  435. */
  436. smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS);
  437. if (smbus < 0)
  438. return smbus;
  439. i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS,
  440. smbus | SMBUS_STMOUT);
  441. }
  442. config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
  443. if (config < 0)
  444. return config;
  445. data->orig_config = config;
  446. if (config & JC42_CFG_SHUTDOWN) {
  447. config &= ~JC42_CFG_SHUTDOWN;
  448. i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
  449. }
  450. data->config = config;
  451. hwmon_dev = devm_hwmon_device_register_with_info(dev, "jc42",
  452. data, &jc42_chip_info,
  453. NULL);
  454. return PTR_ERR_OR_ZERO(hwmon_dev);
  455. }
  456. static int jc42_remove(struct i2c_client *client)
  457. {
  458. struct jc42_data *data = i2c_get_clientdata(client);
  459. /* Restore original configuration except hysteresis */
  460. if ((data->config & ~JC42_CFG_HYST_MASK) !=
  461. (data->orig_config & ~JC42_CFG_HYST_MASK)) {
  462. int config;
  463. config = (data->orig_config & ~JC42_CFG_HYST_MASK)
  464. | (data->config & JC42_CFG_HYST_MASK);
  465. i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
  466. }
  467. return 0;
  468. }
  469. #ifdef CONFIG_PM
  470. static int jc42_suspend(struct device *dev)
  471. {
  472. struct jc42_data *data = dev_get_drvdata(dev);
  473. data->config |= JC42_CFG_SHUTDOWN;
  474. i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
  475. data->config);
  476. return 0;
  477. }
  478. static int jc42_resume(struct device *dev)
  479. {
  480. struct jc42_data *data = dev_get_drvdata(dev);
  481. data->config &= ~JC42_CFG_SHUTDOWN;
  482. i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
  483. data->config);
  484. return 0;
  485. }
  486. static const struct dev_pm_ops jc42_dev_pm_ops = {
  487. .suspend = jc42_suspend,
  488. .resume = jc42_resume,
  489. };
  490. #define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
  491. #else
  492. #define JC42_DEV_PM_OPS NULL
  493. #endif /* CONFIG_PM */
  494. static const struct i2c_device_id jc42_id[] = {
  495. { "jc42", 0 },
  496. { }
  497. };
  498. MODULE_DEVICE_TABLE(i2c, jc42_id);
  499. #ifdef CONFIG_OF
  500. static const struct of_device_id jc42_of_ids[] = {
  501. { .compatible = "jedec,jc-42.4-temp", },
  502. { }
  503. };
  504. MODULE_DEVICE_TABLE(of, jc42_of_ids);
  505. #endif
  506. static struct i2c_driver jc42_driver = {
  507. .class = I2C_CLASS_SPD | I2C_CLASS_HWMON,
  508. .driver = {
  509. .name = "jc42",
  510. .pm = JC42_DEV_PM_OPS,
  511. .of_match_table = of_match_ptr(jc42_of_ids),
  512. },
  513. .probe = jc42_probe,
  514. .remove = jc42_remove,
  515. .id_table = jc42_id,
  516. .detect = jc42_detect,
  517. .address_list = normal_i2c,
  518. };
  519. module_i2c_driver(jc42_driver);
  520. MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
  521. MODULE_DESCRIPTION("JC42 driver");
  522. MODULE_LICENSE("GPL");