tps6586x.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. * Core driver for TI TPS6586x PMIC family
  3. *
  4. * Copyright (c) 2010 CompuLab Ltd.
  5. * Mike Rapoport <mike@compulab.co.il>
  6. *
  7. * Based on da903x.c.
  8. * Copyright (C) 2008 Compulab, Ltd.
  9. * Mike Rapoport <mike@compulab.co.il>
  10. * Copyright (C) 2006-2008 Marvell International Ltd.
  11. * Eric Miao <eric.miao@marvell.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/irqdomain.h>
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/mutex.h>
  23. #include <linux/slab.h>
  24. #include <linux/err.h>
  25. #include <linux/i2c.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/regmap.h>
  28. #include <linux/of.h>
  29. #include <linux/mfd/core.h>
  30. #include <linux/mfd/tps6586x.h>
  31. #define TPS6586X_SUPPLYENE 0x14
  32. #define EXITSLREQ_BIT BIT(1)
  33. #define SLEEP_MODE_BIT BIT(3)
  34. /* interrupt control registers */
  35. #define TPS6586X_INT_ACK1 0xb5
  36. #define TPS6586X_INT_ACK2 0xb6
  37. #define TPS6586X_INT_ACK3 0xb7
  38. #define TPS6586X_INT_ACK4 0xb8
  39. /* interrupt mask registers */
  40. #define TPS6586X_INT_MASK1 0xb0
  41. #define TPS6586X_INT_MASK2 0xb1
  42. #define TPS6586X_INT_MASK3 0xb2
  43. #define TPS6586X_INT_MASK4 0xb3
  44. #define TPS6586X_INT_MASK5 0xb4
  45. /* device id */
  46. #define TPS6586X_VERSIONCRC 0xcd
  47. /* Maximum register */
  48. #define TPS6586X_MAX_REGISTER TPS6586X_VERSIONCRC
  49. struct tps6586x_irq_data {
  50. u8 mask_reg;
  51. u8 mask_mask;
  52. };
  53. #define TPS6586X_IRQ(_reg, _mask) \
  54. { \
  55. .mask_reg = (_reg) - TPS6586X_INT_MASK1, \
  56. .mask_mask = (_mask), \
  57. }
  58. static const struct tps6586x_irq_data tps6586x_irqs[] = {
  59. [TPS6586X_INT_PLDO_0] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 0),
  60. [TPS6586X_INT_PLDO_1] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 1),
  61. [TPS6586X_INT_PLDO_2] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 2),
  62. [TPS6586X_INT_PLDO_3] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 3),
  63. [TPS6586X_INT_PLDO_4] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 4),
  64. [TPS6586X_INT_PLDO_5] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 5),
  65. [TPS6586X_INT_PLDO_6] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 6),
  66. [TPS6586X_INT_PLDO_7] = TPS6586X_IRQ(TPS6586X_INT_MASK1, 1 << 7),
  67. [TPS6586X_INT_COMP_DET] = TPS6586X_IRQ(TPS6586X_INT_MASK4, 1 << 0),
  68. [TPS6586X_INT_ADC] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 1),
  69. [TPS6586X_INT_PLDO_8] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 2),
  70. [TPS6586X_INT_PLDO_9] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 3),
  71. [TPS6586X_INT_PSM_0] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 4),
  72. [TPS6586X_INT_PSM_1] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 5),
  73. [TPS6586X_INT_PSM_2] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 6),
  74. [TPS6586X_INT_PSM_3] = TPS6586X_IRQ(TPS6586X_INT_MASK2, 1 << 7),
  75. [TPS6586X_INT_RTC_ALM1] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 1 << 4),
  76. [TPS6586X_INT_ACUSB_OVP] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 0x03),
  77. [TPS6586X_INT_USB_DET] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 1 << 2),
  78. [TPS6586X_INT_AC_DET] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 1 << 3),
  79. [TPS6586X_INT_BAT_DET] = TPS6586X_IRQ(TPS6586X_INT_MASK3, 1 << 0),
  80. [TPS6586X_INT_CHG_STAT] = TPS6586X_IRQ(TPS6586X_INT_MASK4, 0xfc),
  81. [TPS6586X_INT_CHG_TEMP] = TPS6586X_IRQ(TPS6586X_INT_MASK3, 0x06),
  82. [TPS6586X_INT_PP] = TPS6586X_IRQ(TPS6586X_INT_MASK3, 0xf0),
  83. [TPS6586X_INT_RESUME] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 1 << 5),
  84. [TPS6586X_INT_LOW_SYS] = TPS6586X_IRQ(TPS6586X_INT_MASK5, 1 << 6),
  85. [TPS6586X_INT_RTC_ALM2] = TPS6586X_IRQ(TPS6586X_INT_MASK4, 1 << 1),
  86. };
  87. static struct resource tps6586x_rtc_resources[] = {
  88. {
  89. .start = TPS6586X_INT_RTC_ALM1,
  90. .end = TPS6586X_INT_RTC_ALM1,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. };
  94. static const struct mfd_cell tps6586x_cell[] = {
  95. {
  96. .name = "tps6586x-gpio",
  97. },
  98. {
  99. .name = "tps6586x-regulator",
  100. },
  101. {
  102. .name = "tps6586x-rtc",
  103. .num_resources = ARRAY_SIZE(tps6586x_rtc_resources),
  104. .resources = &tps6586x_rtc_resources[0],
  105. },
  106. {
  107. .name = "tps6586x-onkey",
  108. },
  109. };
  110. struct tps6586x {
  111. struct device *dev;
  112. struct i2c_client *client;
  113. struct regmap *regmap;
  114. int version;
  115. int irq;
  116. struct irq_chip irq_chip;
  117. struct mutex irq_lock;
  118. int irq_base;
  119. u32 irq_en;
  120. u8 mask_reg[5];
  121. struct irq_domain *irq_domain;
  122. };
  123. static inline struct tps6586x *dev_to_tps6586x(struct device *dev)
  124. {
  125. return i2c_get_clientdata(to_i2c_client(dev));
  126. }
  127. int tps6586x_write(struct device *dev, int reg, uint8_t val)
  128. {
  129. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  130. return regmap_write(tps6586x->regmap, reg, val);
  131. }
  132. EXPORT_SYMBOL_GPL(tps6586x_write);
  133. int tps6586x_writes(struct device *dev, int reg, int len, uint8_t *val)
  134. {
  135. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  136. return regmap_bulk_write(tps6586x->regmap, reg, val, len);
  137. }
  138. EXPORT_SYMBOL_GPL(tps6586x_writes);
  139. int tps6586x_read(struct device *dev, int reg, uint8_t *val)
  140. {
  141. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  142. unsigned int rval;
  143. int ret;
  144. ret = regmap_read(tps6586x->regmap, reg, &rval);
  145. if (!ret)
  146. *val = rval;
  147. return ret;
  148. }
  149. EXPORT_SYMBOL_GPL(tps6586x_read);
  150. int tps6586x_reads(struct device *dev, int reg, int len, uint8_t *val)
  151. {
  152. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  153. return regmap_bulk_read(tps6586x->regmap, reg, val, len);
  154. }
  155. EXPORT_SYMBOL_GPL(tps6586x_reads);
  156. int tps6586x_set_bits(struct device *dev, int reg, uint8_t bit_mask)
  157. {
  158. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  159. return regmap_update_bits(tps6586x->regmap, reg, bit_mask, bit_mask);
  160. }
  161. EXPORT_SYMBOL_GPL(tps6586x_set_bits);
  162. int tps6586x_clr_bits(struct device *dev, int reg, uint8_t bit_mask)
  163. {
  164. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  165. return regmap_update_bits(tps6586x->regmap, reg, bit_mask, 0);
  166. }
  167. EXPORT_SYMBOL_GPL(tps6586x_clr_bits);
  168. int tps6586x_update(struct device *dev, int reg, uint8_t val, uint8_t mask)
  169. {
  170. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  171. return regmap_update_bits(tps6586x->regmap, reg, mask, val);
  172. }
  173. EXPORT_SYMBOL_GPL(tps6586x_update);
  174. int tps6586x_irq_get_virq(struct device *dev, int irq)
  175. {
  176. struct tps6586x *tps6586x = dev_to_tps6586x(dev);
  177. return irq_create_mapping(tps6586x->irq_domain, irq);
  178. }
  179. EXPORT_SYMBOL_GPL(tps6586x_irq_get_virq);
  180. int tps6586x_get_version(struct device *dev)
  181. {
  182. struct tps6586x *tps6586x = dev_get_drvdata(dev);
  183. return tps6586x->version;
  184. }
  185. EXPORT_SYMBOL_GPL(tps6586x_get_version);
  186. static int __remove_subdev(struct device *dev, void *unused)
  187. {
  188. platform_device_unregister(to_platform_device(dev));
  189. return 0;
  190. }
  191. static int tps6586x_remove_subdevs(struct tps6586x *tps6586x)
  192. {
  193. return device_for_each_child(tps6586x->dev, NULL, __remove_subdev);
  194. }
  195. static void tps6586x_irq_lock(struct irq_data *data)
  196. {
  197. struct tps6586x *tps6586x = irq_data_get_irq_chip_data(data);
  198. mutex_lock(&tps6586x->irq_lock);
  199. }
  200. static void tps6586x_irq_enable(struct irq_data *irq_data)
  201. {
  202. struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data);
  203. unsigned int __irq = irq_data->hwirq;
  204. const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq];
  205. tps6586x->mask_reg[data->mask_reg] &= ~data->mask_mask;
  206. tps6586x->irq_en |= (1 << __irq);
  207. }
  208. static void tps6586x_irq_disable(struct irq_data *irq_data)
  209. {
  210. struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data);
  211. unsigned int __irq = irq_data->hwirq;
  212. const struct tps6586x_irq_data *data = &tps6586x_irqs[__irq];
  213. tps6586x->mask_reg[data->mask_reg] |= data->mask_mask;
  214. tps6586x->irq_en &= ~(1 << __irq);
  215. }
  216. static void tps6586x_irq_sync_unlock(struct irq_data *data)
  217. {
  218. struct tps6586x *tps6586x = irq_data_get_irq_chip_data(data);
  219. int i;
  220. for (i = 0; i < ARRAY_SIZE(tps6586x->mask_reg); i++) {
  221. int ret;
  222. ret = tps6586x_write(tps6586x->dev,
  223. TPS6586X_INT_MASK1 + i,
  224. tps6586x->mask_reg[i]);
  225. WARN_ON(ret);
  226. }
  227. mutex_unlock(&tps6586x->irq_lock);
  228. }
  229. #ifdef CONFIG_PM_SLEEP
  230. static int tps6586x_irq_set_wake(struct irq_data *irq_data, unsigned int on)
  231. {
  232. struct tps6586x *tps6586x = irq_data_get_irq_chip_data(irq_data);
  233. return irq_set_irq_wake(tps6586x->irq, on);
  234. }
  235. #else
  236. #define tps6586x_irq_set_wake NULL
  237. #endif
  238. static struct irq_chip tps6586x_irq_chip = {
  239. .name = "tps6586x",
  240. .irq_bus_lock = tps6586x_irq_lock,
  241. .irq_bus_sync_unlock = tps6586x_irq_sync_unlock,
  242. .irq_disable = tps6586x_irq_disable,
  243. .irq_enable = tps6586x_irq_enable,
  244. .irq_set_wake = tps6586x_irq_set_wake,
  245. };
  246. static int tps6586x_irq_map(struct irq_domain *h, unsigned int virq,
  247. irq_hw_number_t hw)
  248. {
  249. struct tps6586x *tps6586x = h->host_data;
  250. irq_set_chip_data(virq, tps6586x);
  251. irq_set_chip_and_handler(virq, &tps6586x_irq_chip, handle_simple_irq);
  252. irq_set_nested_thread(virq, 1);
  253. irq_set_noprobe(virq);
  254. return 0;
  255. }
  256. static const struct irq_domain_ops tps6586x_domain_ops = {
  257. .map = tps6586x_irq_map,
  258. .xlate = irq_domain_xlate_twocell,
  259. };
  260. static irqreturn_t tps6586x_irq(int irq, void *data)
  261. {
  262. struct tps6586x *tps6586x = data;
  263. u32 acks;
  264. int ret = 0;
  265. ret = tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1,
  266. sizeof(acks), (uint8_t *)&acks);
  267. if (ret < 0) {
  268. dev_err(tps6586x->dev, "failed to read interrupt status\n");
  269. return IRQ_NONE;
  270. }
  271. acks = le32_to_cpu(acks);
  272. while (acks) {
  273. int i = __ffs(acks);
  274. if (tps6586x->irq_en & (1 << i))
  275. handle_nested_irq(
  276. irq_find_mapping(tps6586x->irq_domain, i));
  277. acks &= ~(1 << i);
  278. }
  279. return IRQ_HANDLED;
  280. }
  281. static int tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
  282. int irq_base)
  283. {
  284. int i, ret;
  285. u8 tmp[4];
  286. int new_irq_base;
  287. int irq_num = ARRAY_SIZE(tps6586x_irqs);
  288. tps6586x->irq = irq;
  289. mutex_init(&tps6586x->irq_lock);
  290. for (i = 0; i < 5; i++) {
  291. tps6586x->mask_reg[i] = 0xff;
  292. tps6586x_write(tps6586x->dev, TPS6586X_INT_MASK1 + i, 0xff);
  293. }
  294. tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1, sizeof(tmp), tmp);
  295. if (irq_base > 0) {
  296. new_irq_base = irq_alloc_descs(irq_base, 0, irq_num, -1);
  297. if (new_irq_base < 0) {
  298. dev_err(tps6586x->dev,
  299. "Failed to alloc IRQs: %d\n", new_irq_base);
  300. return new_irq_base;
  301. }
  302. } else {
  303. new_irq_base = 0;
  304. }
  305. tps6586x->irq_domain = irq_domain_add_simple(tps6586x->dev->of_node,
  306. irq_num, new_irq_base, &tps6586x_domain_ops,
  307. tps6586x);
  308. if (!tps6586x->irq_domain) {
  309. dev_err(tps6586x->dev, "Failed to create IRQ domain\n");
  310. return -ENOMEM;
  311. }
  312. ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
  313. "tps6586x", tps6586x);
  314. if (!ret)
  315. device_init_wakeup(tps6586x->dev, 1);
  316. return ret;
  317. }
  318. static int tps6586x_add_subdevs(struct tps6586x *tps6586x,
  319. struct tps6586x_platform_data *pdata)
  320. {
  321. struct tps6586x_subdev_info *subdev;
  322. struct platform_device *pdev;
  323. int i, ret = 0;
  324. for (i = 0; i < pdata->num_subdevs; i++) {
  325. subdev = &pdata->subdevs[i];
  326. pdev = platform_device_alloc(subdev->name, subdev->id);
  327. if (!pdev) {
  328. ret = -ENOMEM;
  329. goto failed;
  330. }
  331. pdev->dev.parent = tps6586x->dev;
  332. pdev->dev.platform_data = subdev->platform_data;
  333. pdev->dev.of_node = subdev->of_node;
  334. ret = platform_device_add(pdev);
  335. if (ret) {
  336. platform_device_put(pdev);
  337. goto failed;
  338. }
  339. }
  340. return 0;
  341. failed:
  342. tps6586x_remove_subdevs(tps6586x);
  343. return ret;
  344. }
  345. #ifdef CONFIG_OF
  346. static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client)
  347. {
  348. struct device_node *np = client->dev.of_node;
  349. struct tps6586x_platform_data *pdata;
  350. pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
  351. if (!pdata) {
  352. dev_err(&client->dev, "Memory allocation failed\n");
  353. return NULL;
  354. }
  355. pdata->num_subdevs = 0;
  356. pdata->subdevs = NULL;
  357. pdata->gpio_base = -1;
  358. pdata->irq_base = -1;
  359. pdata->pm_off = of_property_read_bool(np, "ti,system-power-controller");
  360. return pdata;
  361. }
  362. static const struct of_device_id tps6586x_of_match[] = {
  363. { .compatible = "ti,tps6586x", },
  364. { },
  365. };
  366. #else
  367. static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client)
  368. {
  369. return NULL;
  370. }
  371. #endif
  372. static bool is_volatile_reg(struct device *dev, unsigned int reg)
  373. {
  374. /* Cache all interrupt mask register */
  375. if ((reg >= TPS6586X_INT_MASK1) && (reg <= TPS6586X_INT_MASK5))
  376. return false;
  377. return true;
  378. }
  379. static const struct regmap_config tps6586x_regmap_config = {
  380. .reg_bits = 8,
  381. .val_bits = 8,
  382. .max_register = TPS6586X_MAX_REGISTER,
  383. .volatile_reg = is_volatile_reg,
  384. .cache_type = REGCACHE_RBTREE,
  385. };
  386. static struct device *tps6586x_dev;
  387. static void tps6586x_power_off(void)
  388. {
  389. if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
  390. return;
  391. tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
  392. }
  393. static void tps6586x_print_version(struct i2c_client *client, int version)
  394. {
  395. const char *name;
  396. switch (version) {
  397. case TPS658621A:
  398. name = "TPS658621A";
  399. break;
  400. case TPS658621CD:
  401. name = "TPS658621C/D";
  402. break;
  403. case TPS658623:
  404. name = "TPS658623";
  405. break;
  406. case TPS658640:
  407. case TPS658640v2:
  408. name = "TPS658640";
  409. break;
  410. case TPS658643:
  411. name = "TPS658643";
  412. break;
  413. default:
  414. name = "TPS6586X";
  415. break;
  416. }
  417. dev_info(&client->dev, "Found %s, VERSIONCRC is %02x\n", name, version);
  418. }
  419. static int tps6586x_i2c_probe(struct i2c_client *client,
  420. const struct i2c_device_id *id)
  421. {
  422. struct tps6586x_platform_data *pdata = dev_get_platdata(&client->dev);
  423. struct tps6586x *tps6586x;
  424. int ret;
  425. int version;
  426. if (!pdata && client->dev.of_node)
  427. pdata = tps6586x_parse_dt(client);
  428. if (!pdata) {
  429. dev_err(&client->dev, "tps6586x requires platform data\n");
  430. return -ENOTSUPP;
  431. }
  432. version = i2c_smbus_read_byte_data(client, TPS6586X_VERSIONCRC);
  433. if (version < 0) {
  434. dev_err(&client->dev, "Chip ID read failed: %d\n", version);
  435. return -EIO;
  436. }
  437. tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL);
  438. if (!tps6586x)
  439. return -ENOMEM;
  440. tps6586x->version = version;
  441. tps6586x_print_version(client, tps6586x->version);
  442. tps6586x->client = client;
  443. tps6586x->dev = &client->dev;
  444. i2c_set_clientdata(client, tps6586x);
  445. tps6586x->regmap = devm_regmap_init_i2c(client,
  446. &tps6586x_regmap_config);
  447. if (IS_ERR(tps6586x->regmap)) {
  448. ret = PTR_ERR(tps6586x->regmap);
  449. dev_err(&client->dev, "regmap init failed: %d\n", ret);
  450. return ret;
  451. }
  452. if (client->irq) {
  453. ret = tps6586x_irq_init(tps6586x, client->irq,
  454. pdata->irq_base);
  455. if (ret) {
  456. dev_err(&client->dev, "IRQ init failed: %d\n", ret);
  457. return ret;
  458. }
  459. }
  460. ret = mfd_add_devices(tps6586x->dev, -1,
  461. tps6586x_cell, ARRAY_SIZE(tps6586x_cell),
  462. NULL, 0, tps6586x->irq_domain);
  463. if (ret < 0) {
  464. dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret);
  465. goto err_mfd_add;
  466. }
  467. ret = tps6586x_add_subdevs(tps6586x, pdata);
  468. if (ret) {
  469. dev_err(&client->dev, "add devices failed: %d\n", ret);
  470. goto err_add_devs;
  471. }
  472. if (pdata->pm_off && !pm_power_off) {
  473. tps6586x_dev = &client->dev;
  474. pm_power_off = tps6586x_power_off;
  475. }
  476. return 0;
  477. err_add_devs:
  478. mfd_remove_devices(tps6586x->dev);
  479. err_mfd_add:
  480. if (client->irq)
  481. free_irq(client->irq, tps6586x);
  482. return ret;
  483. }
  484. static int tps6586x_i2c_remove(struct i2c_client *client)
  485. {
  486. struct tps6586x *tps6586x = i2c_get_clientdata(client);
  487. tps6586x_remove_subdevs(tps6586x);
  488. mfd_remove_devices(tps6586x->dev);
  489. if (client->irq)
  490. free_irq(client->irq, tps6586x);
  491. return 0;
  492. }
  493. static const struct i2c_device_id tps6586x_id_table[] = {
  494. { "tps6586x", 0 },
  495. { },
  496. };
  497. MODULE_DEVICE_TABLE(i2c, tps6586x_id_table);
  498. static struct i2c_driver tps6586x_driver = {
  499. .driver = {
  500. .name = "tps6586x",
  501. .of_match_table = of_match_ptr(tps6586x_of_match),
  502. },
  503. .probe = tps6586x_i2c_probe,
  504. .remove = tps6586x_i2c_remove,
  505. .id_table = tps6586x_id_table,
  506. };
  507. static int __init tps6586x_init(void)
  508. {
  509. return i2c_add_driver(&tps6586x_driver);
  510. }
  511. subsys_initcall(tps6586x_init);
  512. static void __exit tps6586x_exit(void)
  513. {
  514. i2c_del_driver(&tps6586x_driver);
  515. }
  516. module_exit(tps6586x_exit);
  517. MODULE_DESCRIPTION("TPS6586X core driver");
  518. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  519. MODULE_LICENSE("GPL");