jc42.c 16 KB

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