tps6586x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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 + 1)
  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. /* ARM needs us to explicitly flag the IRQ as valid
  254. * and will set them noprobe when we do so. */
  255. #ifdef CONFIG_ARM
  256. set_irq_flags(virq, IRQF_VALID);
  257. #else
  258. irq_set_noprobe(virq);
  259. #endif
  260. return 0;
  261. }
  262. static const struct irq_domain_ops tps6586x_domain_ops = {
  263. .map = tps6586x_irq_map,
  264. .xlate = irq_domain_xlate_twocell,
  265. };
  266. static irqreturn_t tps6586x_irq(int irq, void *data)
  267. {
  268. struct tps6586x *tps6586x = data;
  269. u32 acks;
  270. int ret = 0;
  271. ret = tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1,
  272. sizeof(acks), (uint8_t *)&acks);
  273. if (ret < 0) {
  274. dev_err(tps6586x->dev, "failed to read interrupt status\n");
  275. return IRQ_NONE;
  276. }
  277. acks = le32_to_cpu(acks);
  278. while (acks) {
  279. int i = __ffs(acks);
  280. if (tps6586x->irq_en & (1 << i))
  281. handle_nested_irq(
  282. irq_find_mapping(tps6586x->irq_domain, i));
  283. acks &= ~(1 << i);
  284. }
  285. return IRQ_HANDLED;
  286. }
  287. static int tps6586x_irq_init(struct tps6586x *tps6586x, int irq,
  288. int irq_base)
  289. {
  290. int i, ret;
  291. u8 tmp[4];
  292. int new_irq_base;
  293. int irq_num = ARRAY_SIZE(tps6586x_irqs);
  294. tps6586x->irq = irq;
  295. mutex_init(&tps6586x->irq_lock);
  296. for (i = 0; i < 5; i++) {
  297. tps6586x->mask_reg[i] = 0xff;
  298. tps6586x_write(tps6586x->dev, TPS6586X_INT_MASK1 + i, 0xff);
  299. }
  300. tps6586x_reads(tps6586x->dev, TPS6586X_INT_ACK1, sizeof(tmp), tmp);
  301. if (irq_base > 0) {
  302. new_irq_base = irq_alloc_descs(irq_base, 0, irq_num, -1);
  303. if (new_irq_base < 0) {
  304. dev_err(tps6586x->dev,
  305. "Failed to alloc IRQs: %d\n", new_irq_base);
  306. return new_irq_base;
  307. }
  308. } else {
  309. new_irq_base = 0;
  310. }
  311. tps6586x->irq_domain = irq_domain_add_simple(tps6586x->dev->of_node,
  312. irq_num, new_irq_base, &tps6586x_domain_ops,
  313. tps6586x);
  314. if (!tps6586x->irq_domain) {
  315. dev_err(tps6586x->dev, "Failed to create IRQ domain\n");
  316. return -ENOMEM;
  317. }
  318. ret = request_threaded_irq(irq, NULL, tps6586x_irq, IRQF_ONESHOT,
  319. "tps6586x", tps6586x);
  320. if (!ret)
  321. device_init_wakeup(tps6586x->dev, 1);
  322. return ret;
  323. }
  324. static int tps6586x_add_subdevs(struct tps6586x *tps6586x,
  325. struct tps6586x_platform_data *pdata)
  326. {
  327. struct tps6586x_subdev_info *subdev;
  328. struct platform_device *pdev;
  329. int i, ret = 0;
  330. for (i = 0; i < pdata->num_subdevs; i++) {
  331. subdev = &pdata->subdevs[i];
  332. pdev = platform_device_alloc(subdev->name, subdev->id);
  333. if (!pdev) {
  334. ret = -ENOMEM;
  335. goto failed;
  336. }
  337. pdev->dev.parent = tps6586x->dev;
  338. pdev->dev.platform_data = subdev->platform_data;
  339. pdev->dev.of_node = subdev->of_node;
  340. ret = platform_device_add(pdev);
  341. if (ret) {
  342. platform_device_put(pdev);
  343. goto failed;
  344. }
  345. }
  346. return 0;
  347. failed:
  348. tps6586x_remove_subdevs(tps6586x);
  349. return ret;
  350. }
  351. #ifdef CONFIG_OF
  352. static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client)
  353. {
  354. struct device_node *np = client->dev.of_node;
  355. struct tps6586x_platform_data *pdata;
  356. pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
  357. if (!pdata) {
  358. dev_err(&client->dev, "Memory allocation failed\n");
  359. return NULL;
  360. }
  361. pdata->num_subdevs = 0;
  362. pdata->subdevs = NULL;
  363. pdata->gpio_base = -1;
  364. pdata->irq_base = -1;
  365. pdata->pm_off = of_property_read_bool(np, "ti,system-power-controller");
  366. return pdata;
  367. }
  368. static const struct of_device_id tps6586x_of_match[] = {
  369. { .compatible = "ti,tps6586x", },
  370. { },
  371. };
  372. #else
  373. static struct tps6586x_platform_data *tps6586x_parse_dt(struct i2c_client *client)
  374. {
  375. return NULL;
  376. }
  377. #endif
  378. static bool is_volatile_reg(struct device *dev, unsigned int reg)
  379. {
  380. /* Cache all interrupt mask register */
  381. if ((reg >= TPS6586X_INT_MASK1) && (reg <= TPS6586X_INT_MASK5))
  382. return false;
  383. return true;
  384. }
  385. static const struct regmap_config tps6586x_regmap_config = {
  386. .reg_bits = 8,
  387. .val_bits = 8,
  388. .max_register = TPS6586X_MAX_REGISTER - 1,
  389. .volatile_reg = is_volatile_reg,
  390. .cache_type = REGCACHE_RBTREE,
  391. };
  392. static struct device *tps6586x_dev;
  393. static void tps6586x_power_off(void)
  394. {
  395. if (tps6586x_clr_bits(tps6586x_dev, TPS6586X_SUPPLYENE, EXITSLREQ_BIT))
  396. return;
  397. tps6586x_set_bits(tps6586x_dev, TPS6586X_SUPPLYENE, SLEEP_MODE_BIT);
  398. }
  399. static void tps6586x_print_version(struct i2c_client *client, int version)
  400. {
  401. const char *name;
  402. switch (version) {
  403. case TPS658621A:
  404. name = "TPS658621A";
  405. break;
  406. case TPS658621CD:
  407. name = "TPS658621C/D";
  408. break;
  409. case TPS658623:
  410. name = "TPS658623";
  411. break;
  412. case TPS658640:
  413. case TPS658640v2:
  414. name = "TPS658640";
  415. break;
  416. case TPS658643:
  417. name = "TPS658643";
  418. break;
  419. default:
  420. name = "TPS6586X";
  421. break;
  422. }
  423. dev_info(&client->dev, "Found %s, VERSIONCRC is %02x\n", name, version);
  424. }
  425. static int tps6586x_i2c_probe(struct i2c_client *client,
  426. const struct i2c_device_id *id)
  427. {
  428. struct tps6586x_platform_data *pdata = dev_get_platdata(&client->dev);
  429. struct tps6586x *tps6586x;
  430. int ret;
  431. int version;
  432. if (!pdata && client->dev.of_node)
  433. pdata = tps6586x_parse_dt(client);
  434. if (!pdata) {
  435. dev_err(&client->dev, "tps6586x requires platform data\n");
  436. return -ENOTSUPP;
  437. }
  438. version = i2c_smbus_read_byte_data(client, TPS6586X_VERSIONCRC);
  439. if (version < 0) {
  440. dev_err(&client->dev, "Chip ID read failed: %d\n", version);
  441. return -EIO;
  442. }
  443. tps6586x = devm_kzalloc(&client->dev, sizeof(*tps6586x), GFP_KERNEL);
  444. if (!tps6586x)
  445. return -ENOMEM;
  446. tps6586x->version = version;
  447. tps6586x_print_version(client, tps6586x->version);
  448. tps6586x->client = client;
  449. tps6586x->dev = &client->dev;
  450. i2c_set_clientdata(client, tps6586x);
  451. tps6586x->regmap = devm_regmap_init_i2c(client,
  452. &tps6586x_regmap_config);
  453. if (IS_ERR(tps6586x->regmap)) {
  454. ret = PTR_ERR(tps6586x->regmap);
  455. dev_err(&client->dev, "regmap init failed: %d\n", ret);
  456. return ret;
  457. }
  458. if (client->irq) {
  459. ret = tps6586x_irq_init(tps6586x, client->irq,
  460. pdata->irq_base);
  461. if (ret) {
  462. dev_err(&client->dev, "IRQ init failed: %d\n", ret);
  463. return ret;
  464. }
  465. }
  466. ret = mfd_add_devices(tps6586x->dev, -1,
  467. tps6586x_cell, ARRAY_SIZE(tps6586x_cell),
  468. NULL, 0, tps6586x->irq_domain);
  469. if (ret < 0) {
  470. dev_err(&client->dev, "mfd_add_devices failed: %d\n", ret);
  471. goto err_mfd_add;
  472. }
  473. ret = tps6586x_add_subdevs(tps6586x, pdata);
  474. if (ret) {
  475. dev_err(&client->dev, "add devices failed: %d\n", ret);
  476. goto err_add_devs;
  477. }
  478. if (pdata->pm_off && !pm_power_off) {
  479. tps6586x_dev = &client->dev;
  480. pm_power_off = tps6586x_power_off;
  481. }
  482. return 0;
  483. err_add_devs:
  484. mfd_remove_devices(tps6586x->dev);
  485. err_mfd_add:
  486. if (client->irq)
  487. free_irq(client->irq, tps6586x);
  488. return ret;
  489. }
  490. static int tps6586x_i2c_remove(struct i2c_client *client)
  491. {
  492. struct tps6586x *tps6586x = i2c_get_clientdata(client);
  493. tps6586x_remove_subdevs(tps6586x);
  494. mfd_remove_devices(tps6586x->dev);
  495. if (client->irq)
  496. free_irq(client->irq, tps6586x);
  497. return 0;
  498. }
  499. static const struct i2c_device_id tps6586x_id_table[] = {
  500. { "tps6586x", 0 },
  501. { },
  502. };
  503. MODULE_DEVICE_TABLE(i2c, tps6586x_id_table);
  504. static struct i2c_driver tps6586x_driver = {
  505. .driver = {
  506. .name = "tps6586x",
  507. .owner = THIS_MODULE,
  508. .of_match_table = of_match_ptr(tps6586x_of_match),
  509. },
  510. .probe = tps6586x_i2c_probe,
  511. .remove = tps6586x_i2c_remove,
  512. .id_table = tps6586x_id_table,
  513. };
  514. static int __init tps6586x_init(void)
  515. {
  516. return i2c_add_driver(&tps6586x_driver);
  517. }
  518. subsys_initcall(tps6586x_init);
  519. static void __exit tps6586x_exit(void)
  520. {
  521. i2c_del_driver(&tps6586x_driver);
  522. }
  523. module_exit(tps6586x_exit);
  524. MODULE_DESCRIPTION("TPS6586X core driver");
  525. MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>");
  526. MODULE_LICENSE("GPL");