adc128d818.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * Driver for TI ADC128D818 System Monitor with Temperature Sensor
  3. *
  4. * Copyright (c) 2014 Guenter Roeck
  5. *
  6. * Derived from lm80.c
  7. * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
  8. * and Philip Edelbrock <phil@netroedge.com>
  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. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/i2c.h>
  24. #include <linux/hwmon.h>
  25. #include <linux/hwmon-sysfs.h>
  26. #include <linux/err.h>
  27. #include <linux/regulator/consumer.h>
  28. #include <linux/mutex.h>
  29. #include <linux/bitops.h>
  30. #include <linux/of.h>
  31. /* Addresses to scan
  32. * The chip also supports addresses 0x35..0x37. Don't scan those addresses
  33. * since they are also used by some EEPROMs, which may result in false
  34. * positives.
  35. */
  36. static const unsigned short normal_i2c[] = {
  37. 0x1d, 0x1e, 0x1f, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
  38. /* registers */
  39. #define ADC128_REG_IN_MAX(nr) (0x2a + (nr) * 2)
  40. #define ADC128_REG_IN_MIN(nr) (0x2b + (nr) * 2)
  41. #define ADC128_REG_IN(nr) (0x20 + (nr))
  42. #define ADC128_REG_TEMP 0x27
  43. #define ADC128_REG_TEMP_MAX 0x38
  44. #define ADC128_REG_TEMP_HYST 0x39
  45. #define ADC128_REG_CONFIG 0x00
  46. #define ADC128_REG_ALARM 0x01
  47. #define ADC128_REG_MASK 0x03
  48. #define ADC128_REG_CONV_RATE 0x07
  49. #define ADC128_REG_ONESHOT 0x09
  50. #define ADC128_REG_SHUTDOWN 0x0a
  51. #define ADC128_REG_CONFIG_ADV 0x0b
  52. #define ADC128_REG_BUSY_STATUS 0x0c
  53. #define ADC128_REG_MAN_ID 0x3e
  54. #define ADC128_REG_DEV_ID 0x3f
  55. /* No. of voltage entries in adc128_attrs */
  56. #define ADC128_ATTR_NUM_VOLT (8 * 4)
  57. /* Voltage inputs visible per operation mode */
  58. static const u8 num_inputs[] = { 7, 8, 4, 6 };
  59. struct adc128_data {
  60. struct i2c_client *client;
  61. struct regulator *regulator;
  62. int vref; /* Reference voltage in mV */
  63. struct mutex update_lock;
  64. u8 mode; /* Operation mode */
  65. bool valid; /* true if following fields are valid */
  66. unsigned long last_updated; /* In jiffies */
  67. u16 in[3][8]; /* Register value, normalized to 12 bit
  68. * 0: input voltage
  69. * 1: min limit
  70. * 2: max limit
  71. */
  72. s16 temp[3]; /* Register value, normalized to 9 bit
  73. * 0: sensor 1: limit 2: hyst
  74. */
  75. u8 alarms; /* alarm register value */
  76. };
  77. static struct adc128_data *adc128_update_device(struct device *dev)
  78. {
  79. struct adc128_data *data = dev_get_drvdata(dev);
  80. struct i2c_client *client = data->client;
  81. struct adc128_data *ret = data;
  82. int i, rv;
  83. mutex_lock(&data->update_lock);
  84. if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
  85. for (i = 0; i < num_inputs[data->mode]; i++) {
  86. rv = i2c_smbus_read_word_swapped(client,
  87. ADC128_REG_IN(i));
  88. if (rv < 0)
  89. goto abort;
  90. data->in[0][i] = rv >> 4;
  91. rv = i2c_smbus_read_byte_data(client,
  92. ADC128_REG_IN_MIN(i));
  93. if (rv < 0)
  94. goto abort;
  95. data->in[1][i] = rv << 4;
  96. rv = i2c_smbus_read_byte_data(client,
  97. ADC128_REG_IN_MAX(i));
  98. if (rv < 0)
  99. goto abort;
  100. data->in[2][i] = rv << 4;
  101. }
  102. if (data->mode != 1) {
  103. rv = i2c_smbus_read_word_swapped(client,
  104. ADC128_REG_TEMP);
  105. if (rv < 0)
  106. goto abort;
  107. data->temp[0] = rv >> 7;
  108. rv = i2c_smbus_read_byte_data(client,
  109. ADC128_REG_TEMP_MAX);
  110. if (rv < 0)
  111. goto abort;
  112. data->temp[1] = rv << 1;
  113. rv = i2c_smbus_read_byte_data(client,
  114. ADC128_REG_TEMP_HYST);
  115. if (rv < 0)
  116. goto abort;
  117. data->temp[2] = rv << 1;
  118. }
  119. rv = i2c_smbus_read_byte_data(client, ADC128_REG_ALARM);
  120. if (rv < 0)
  121. goto abort;
  122. data->alarms |= rv;
  123. data->last_updated = jiffies;
  124. data->valid = true;
  125. }
  126. goto done;
  127. abort:
  128. ret = ERR_PTR(rv);
  129. data->valid = false;
  130. done:
  131. mutex_unlock(&data->update_lock);
  132. return ret;
  133. }
  134. static ssize_t adc128_show_in(struct device *dev, struct device_attribute *attr,
  135. char *buf)
  136. {
  137. struct adc128_data *data = adc128_update_device(dev);
  138. int index = to_sensor_dev_attr_2(attr)->index;
  139. int nr = to_sensor_dev_attr_2(attr)->nr;
  140. int val;
  141. if (IS_ERR(data))
  142. return PTR_ERR(data);
  143. val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095);
  144. return sprintf(buf, "%d\n", val);
  145. }
  146. static ssize_t adc128_set_in(struct device *dev, struct device_attribute *attr,
  147. const char *buf, size_t count)
  148. {
  149. struct adc128_data *data = dev_get_drvdata(dev);
  150. int index = to_sensor_dev_attr_2(attr)->index;
  151. int nr = to_sensor_dev_attr_2(attr)->nr;
  152. u8 reg, regval;
  153. long val;
  154. int err;
  155. err = kstrtol(buf, 10, &val);
  156. if (err < 0)
  157. return err;
  158. mutex_lock(&data->update_lock);
  159. /* 10 mV LSB on limit registers */
  160. regval = clamp_val(DIV_ROUND_CLOSEST(val, 10), 0, 255);
  161. data->in[index][nr] = regval << 4;
  162. reg = index == 1 ? ADC128_REG_IN_MIN(nr) : ADC128_REG_IN_MAX(nr);
  163. i2c_smbus_write_byte_data(data->client, reg, regval);
  164. mutex_unlock(&data->update_lock);
  165. return count;
  166. }
  167. static ssize_t adc128_show_temp(struct device *dev,
  168. struct device_attribute *attr, char *buf)
  169. {
  170. struct adc128_data *data = adc128_update_device(dev);
  171. int index = to_sensor_dev_attr(attr)->index;
  172. int temp;
  173. if (IS_ERR(data))
  174. return PTR_ERR(data);
  175. temp = sign_extend32(data->temp[index], 8);
  176. return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */
  177. }
  178. static ssize_t adc128_set_temp(struct device *dev,
  179. struct device_attribute *attr,
  180. const char *buf, size_t count)
  181. {
  182. struct adc128_data *data = dev_get_drvdata(dev);
  183. int index = to_sensor_dev_attr(attr)->index;
  184. long val;
  185. int err;
  186. s8 regval;
  187. err = kstrtol(buf, 10, &val);
  188. if (err < 0)
  189. return err;
  190. mutex_lock(&data->update_lock);
  191. regval = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
  192. data->temp[index] = regval << 1;
  193. i2c_smbus_write_byte_data(data->client,
  194. index == 1 ? ADC128_REG_TEMP_MAX
  195. : ADC128_REG_TEMP_HYST,
  196. regval);
  197. mutex_unlock(&data->update_lock);
  198. return count;
  199. }
  200. static ssize_t adc128_show_alarm(struct device *dev,
  201. struct device_attribute *attr, char *buf)
  202. {
  203. struct adc128_data *data = adc128_update_device(dev);
  204. int mask = 1 << to_sensor_dev_attr(attr)->index;
  205. u8 alarms;
  206. if (IS_ERR(data))
  207. return PTR_ERR(data);
  208. /*
  209. * Clear an alarm after reporting it to user space. If it is still
  210. * active, the next update sequence will set the alarm bit again.
  211. */
  212. alarms = data->alarms;
  213. data->alarms &= ~mask;
  214. return sprintf(buf, "%u\n", !!(alarms & mask));
  215. }
  216. static umode_t adc128_is_visible(struct kobject *kobj,
  217. struct attribute *attr, int index)
  218. {
  219. struct device *dev = container_of(kobj, struct device, kobj);
  220. struct adc128_data *data = dev_get_drvdata(dev);
  221. if (index < ADC128_ATTR_NUM_VOLT) {
  222. /* Voltage, visible according to num_inputs[] */
  223. if (index >= num_inputs[data->mode] * 4)
  224. return 0;
  225. } else {
  226. /* Temperature, visible if not in mode 1 */
  227. if (data->mode == 1)
  228. return 0;
  229. }
  230. return attr->mode;
  231. }
  232. static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO,
  233. adc128_show_in, NULL, 0, 0);
  234. static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO,
  235. adc128_show_in, adc128_set_in, 0, 1);
  236. static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO,
  237. adc128_show_in, adc128_set_in, 0, 2);
  238. static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO,
  239. adc128_show_in, NULL, 1, 0);
  240. static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO,
  241. adc128_show_in, adc128_set_in, 1, 1);
  242. static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO,
  243. adc128_show_in, adc128_set_in, 1, 2);
  244. static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO,
  245. adc128_show_in, NULL, 2, 0);
  246. static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO,
  247. adc128_show_in, adc128_set_in, 2, 1);
  248. static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO,
  249. adc128_show_in, adc128_set_in, 2, 2);
  250. static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO,
  251. adc128_show_in, NULL, 3, 0);
  252. static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO,
  253. adc128_show_in, adc128_set_in, 3, 1);
  254. static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO,
  255. adc128_show_in, adc128_set_in, 3, 2);
  256. static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO,
  257. adc128_show_in, NULL, 4, 0);
  258. static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO,
  259. adc128_show_in, adc128_set_in, 4, 1);
  260. static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO,
  261. adc128_show_in, adc128_set_in, 4, 2);
  262. static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO,
  263. adc128_show_in, NULL, 5, 0);
  264. static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO,
  265. adc128_show_in, adc128_set_in, 5, 1);
  266. static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO,
  267. adc128_show_in, adc128_set_in, 5, 2);
  268. static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO,
  269. adc128_show_in, NULL, 6, 0);
  270. static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO,
  271. adc128_show_in, adc128_set_in, 6, 1);
  272. static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO,
  273. adc128_show_in, adc128_set_in, 6, 2);
  274. static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO,
  275. adc128_show_in, NULL, 7, 0);
  276. static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO,
  277. adc128_show_in, adc128_set_in, 7, 1);
  278. static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO,
  279. adc128_show_in, adc128_set_in, 7, 2);
  280. static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, adc128_show_temp, NULL, 0);
  281. static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
  282. adc128_show_temp, adc128_set_temp, 1);
  283. static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
  284. adc128_show_temp, adc128_set_temp, 2);
  285. static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, adc128_show_alarm, NULL, 0);
  286. static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, adc128_show_alarm, NULL, 1);
  287. static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, adc128_show_alarm, NULL, 2);
  288. static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, adc128_show_alarm, NULL, 3);
  289. static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, adc128_show_alarm, NULL, 4);
  290. static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, adc128_show_alarm, NULL, 5);
  291. static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, adc128_show_alarm, NULL, 6);
  292. static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, adc128_show_alarm, NULL, 7);
  293. static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, adc128_show_alarm, NULL, 7);
  294. static struct attribute *adc128_attrs[] = {
  295. &sensor_dev_attr_in0_alarm.dev_attr.attr,
  296. &sensor_dev_attr_in0_input.dev_attr.attr,
  297. &sensor_dev_attr_in0_max.dev_attr.attr,
  298. &sensor_dev_attr_in0_min.dev_attr.attr,
  299. &sensor_dev_attr_in1_alarm.dev_attr.attr,
  300. &sensor_dev_attr_in1_input.dev_attr.attr,
  301. &sensor_dev_attr_in1_max.dev_attr.attr,
  302. &sensor_dev_attr_in1_min.dev_attr.attr,
  303. &sensor_dev_attr_in2_alarm.dev_attr.attr,
  304. &sensor_dev_attr_in2_input.dev_attr.attr,
  305. &sensor_dev_attr_in2_max.dev_attr.attr,
  306. &sensor_dev_attr_in2_min.dev_attr.attr,
  307. &sensor_dev_attr_in3_alarm.dev_attr.attr,
  308. &sensor_dev_attr_in3_input.dev_attr.attr,
  309. &sensor_dev_attr_in3_max.dev_attr.attr,
  310. &sensor_dev_attr_in3_min.dev_attr.attr,
  311. &sensor_dev_attr_in4_alarm.dev_attr.attr,
  312. &sensor_dev_attr_in4_input.dev_attr.attr,
  313. &sensor_dev_attr_in4_max.dev_attr.attr,
  314. &sensor_dev_attr_in4_min.dev_attr.attr,
  315. &sensor_dev_attr_in5_alarm.dev_attr.attr,
  316. &sensor_dev_attr_in5_input.dev_attr.attr,
  317. &sensor_dev_attr_in5_max.dev_attr.attr,
  318. &sensor_dev_attr_in5_min.dev_attr.attr,
  319. &sensor_dev_attr_in6_alarm.dev_attr.attr,
  320. &sensor_dev_attr_in6_input.dev_attr.attr,
  321. &sensor_dev_attr_in6_max.dev_attr.attr,
  322. &sensor_dev_attr_in6_min.dev_attr.attr,
  323. &sensor_dev_attr_in7_alarm.dev_attr.attr,
  324. &sensor_dev_attr_in7_input.dev_attr.attr,
  325. &sensor_dev_attr_in7_max.dev_attr.attr,
  326. &sensor_dev_attr_in7_min.dev_attr.attr,
  327. &sensor_dev_attr_temp1_input.dev_attr.attr,
  328. &sensor_dev_attr_temp1_max.dev_attr.attr,
  329. &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
  330. &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
  331. NULL
  332. };
  333. static const struct attribute_group adc128_group = {
  334. .attrs = adc128_attrs,
  335. .is_visible = adc128_is_visible,
  336. };
  337. __ATTRIBUTE_GROUPS(adc128);
  338. static int adc128_detect(struct i2c_client *client, struct i2c_board_info *info)
  339. {
  340. int man_id, dev_id;
  341. if (!i2c_check_functionality(client->adapter,
  342. I2C_FUNC_SMBUS_BYTE_DATA |
  343. I2C_FUNC_SMBUS_WORD_DATA))
  344. return -ENODEV;
  345. man_id = i2c_smbus_read_byte_data(client, ADC128_REG_MAN_ID);
  346. dev_id = i2c_smbus_read_byte_data(client, ADC128_REG_DEV_ID);
  347. if (man_id != 0x01 || dev_id != 0x09)
  348. return -ENODEV;
  349. /* Check unused bits for confirmation */
  350. if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG) & 0xf4)
  351. return -ENODEV;
  352. if (i2c_smbus_read_byte_data(client, ADC128_REG_CONV_RATE) & 0xfe)
  353. return -ENODEV;
  354. if (i2c_smbus_read_byte_data(client, ADC128_REG_ONESHOT) & 0xfe)
  355. return -ENODEV;
  356. if (i2c_smbus_read_byte_data(client, ADC128_REG_SHUTDOWN) & 0xfe)
  357. return -ENODEV;
  358. if (i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV) & 0xf8)
  359. return -ENODEV;
  360. if (i2c_smbus_read_byte_data(client, ADC128_REG_BUSY_STATUS) & 0xfc)
  361. return -ENODEV;
  362. strlcpy(info->type, "adc128d818", I2C_NAME_SIZE);
  363. return 0;
  364. }
  365. static int adc128_init_client(struct adc128_data *data)
  366. {
  367. struct i2c_client *client = data->client;
  368. int err;
  369. /*
  370. * Reset chip to defaults.
  371. * This makes most other initializations unnecessary.
  372. */
  373. err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x80);
  374. if (err)
  375. return err;
  376. /* Set operation mode, if non-default */
  377. if (data->mode != 0) {
  378. err = i2c_smbus_write_byte_data(client,
  379. ADC128_REG_CONFIG_ADV,
  380. data->mode << 1);
  381. if (err)
  382. return err;
  383. }
  384. /* Start monitoring */
  385. err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG, 0x01);
  386. if (err)
  387. return err;
  388. /* If external vref is selected, configure the chip to use it */
  389. if (data->regulator) {
  390. err = i2c_smbus_write_byte_data(client,
  391. ADC128_REG_CONFIG_ADV, 0x01);
  392. if (err)
  393. return err;
  394. }
  395. return 0;
  396. }
  397. static int adc128_probe(struct i2c_client *client,
  398. const struct i2c_device_id *id)
  399. {
  400. struct device *dev = &client->dev;
  401. struct regulator *regulator;
  402. struct device *hwmon_dev;
  403. struct adc128_data *data;
  404. int err, vref;
  405. data = devm_kzalloc(dev, sizeof(struct adc128_data), GFP_KERNEL);
  406. if (!data)
  407. return -ENOMEM;
  408. /* vref is optional. If specified, is used as chip reference voltage */
  409. regulator = devm_regulator_get_optional(dev, "vref");
  410. if (!IS_ERR(regulator)) {
  411. data->regulator = regulator;
  412. err = regulator_enable(regulator);
  413. if (err < 0)
  414. return err;
  415. vref = regulator_get_voltage(regulator);
  416. if (vref < 0) {
  417. err = vref;
  418. goto error;
  419. }
  420. data->vref = DIV_ROUND_CLOSEST(vref, 1000);
  421. } else {
  422. data->vref = 2560; /* 2.56V, in mV */
  423. }
  424. /* Operation mode is optional. If unspecified, keep current mode */
  425. if (of_property_read_u8(dev->of_node, "ti,mode", &data->mode) == 0) {
  426. if (data->mode > 3) {
  427. dev_err(dev, "invalid operation mode %d\n",
  428. data->mode);
  429. err = -EINVAL;
  430. goto error;
  431. }
  432. } else {
  433. err = i2c_smbus_read_byte_data(client, ADC128_REG_CONFIG_ADV);
  434. if (err < 0)
  435. goto error;
  436. data->mode = (err >> 1) & ADC128_REG_MASK;
  437. }
  438. data->client = client;
  439. i2c_set_clientdata(client, data);
  440. mutex_init(&data->update_lock);
  441. /* Initialize the chip */
  442. err = adc128_init_client(data);
  443. if (err < 0)
  444. goto error;
  445. hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
  446. data, adc128_groups);
  447. if (IS_ERR(hwmon_dev)) {
  448. err = PTR_ERR(hwmon_dev);
  449. goto error;
  450. }
  451. return 0;
  452. error:
  453. if (data->regulator)
  454. regulator_disable(data->regulator);
  455. return err;
  456. }
  457. static int adc128_remove(struct i2c_client *client)
  458. {
  459. struct adc128_data *data = i2c_get_clientdata(client);
  460. if (data->regulator)
  461. regulator_disable(data->regulator);
  462. return 0;
  463. }
  464. static const struct i2c_device_id adc128_id[] = {
  465. { "adc128d818", 0 },
  466. { }
  467. };
  468. MODULE_DEVICE_TABLE(i2c, adc128_id);
  469. static const struct of_device_id adc128_of_match[] = {
  470. { .compatible = "ti,adc128d818" },
  471. { },
  472. };
  473. MODULE_DEVICE_TABLE(of, adc128_of_match);
  474. static struct i2c_driver adc128_driver = {
  475. .class = I2C_CLASS_HWMON,
  476. .driver = {
  477. .name = "adc128d818",
  478. .of_match_table = of_match_ptr(adc128_of_match),
  479. },
  480. .probe = adc128_probe,
  481. .remove = adc128_remove,
  482. .id_table = adc128_id,
  483. .detect = adc128_detect,
  484. .address_list = normal_i2c,
  485. };
  486. module_i2c_driver(adc128_driver);
  487. MODULE_AUTHOR("Guenter Roeck");
  488. MODULE_DESCRIPTION("Driver for ADC128D818");
  489. MODULE_LICENSE("GPL");