da9055-regulator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. * Regulator driver for DA9055 PMIC
  3. *
  4. * Copyright(c) 2012 Dialog Semiconductor Ltd.
  5. *
  6. * Author: David Dajun Chen <[email protected]>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/err.h>
  17. #include <linux/gpio.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/regulator/driver.h>
  20. #include <linux/regulator/machine.h>
  21. #include <linux/of.h>
  22. #include <linux/regulator/of_regulator.h>
  23. #include <linux/mfd/da9055/core.h>
  24. #include <linux/mfd/da9055/reg.h>
  25. #include <linux/mfd/da9055/pdata.h>
  26. #define DA9055_MIN_UA 0
  27. #define DA9055_MAX_UA 3
  28. #define DA9055_LDO_MODE_SYNC 0
  29. #define DA9055_LDO_MODE_SLEEP 1
  30. #define DA9055_BUCK_MODE_SLEEP 1
  31. #define DA9055_BUCK_MODE_SYNC 2
  32. #define DA9055_BUCK_MODE_AUTO 3
  33. /* DA9055 REGULATOR IDs */
  34. #define DA9055_ID_BUCK1 0
  35. #define DA9055_ID_BUCK2 1
  36. #define DA9055_ID_LDO1 2
  37. #define DA9055_ID_LDO2 3
  38. #define DA9055_ID_LDO3 4
  39. #define DA9055_ID_LDO4 5
  40. #define DA9055_ID_LDO5 6
  41. #define DA9055_ID_LDO6 7
  42. /* DA9055 BUCK current limit */
  43. static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 };
  44. struct da9055_conf_reg {
  45. int reg;
  46. int sel_mask;
  47. int en_mask;
  48. };
  49. struct da9055_volt_reg {
  50. int reg_a;
  51. int reg_b;
  52. int sl_shift;
  53. int v_mask;
  54. };
  55. struct da9055_mode_reg {
  56. int reg;
  57. int mask;
  58. int shift;
  59. };
  60. struct da9055_regulator_info {
  61. struct regulator_desc reg_desc;
  62. struct da9055_conf_reg conf;
  63. struct da9055_volt_reg volt;
  64. struct da9055_mode_reg mode;
  65. };
  66. struct da9055_regulator {
  67. struct da9055 *da9055;
  68. struct da9055_regulator_info *info;
  69. struct regulator_dev *rdev;
  70. enum gpio_select reg_rselect;
  71. };
  72. static unsigned int da9055_buck_get_mode(struct regulator_dev *rdev)
  73. {
  74. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  75. struct da9055_regulator_info *info = regulator->info;
  76. int ret, mode = 0;
  77. ret = da9055_reg_read(regulator->da9055, info->mode.reg);
  78. if (ret < 0)
  79. return ret;
  80. switch ((ret & info->mode.mask) >> info->mode.shift) {
  81. case DA9055_BUCK_MODE_SYNC:
  82. mode = REGULATOR_MODE_FAST;
  83. break;
  84. case DA9055_BUCK_MODE_AUTO:
  85. mode = REGULATOR_MODE_NORMAL;
  86. break;
  87. case DA9055_BUCK_MODE_SLEEP:
  88. mode = REGULATOR_MODE_STANDBY;
  89. break;
  90. }
  91. return mode;
  92. }
  93. static int da9055_buck_set_mode(struct regulator_dev *rdev,
  94. unsigned int mode)
  95. {
  96. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  97. struct da9055_regulator_info *info = regulator->info;
  98. int val = 0;
  99. switch (mode) {
  100. case REGULATOR_MODE_FAST:
  101. val = DA9055_BUCK_MODE_SYNC << info->mode.shift;
  102. break;
  103. case REGULATOR_MODE_NORMAL:
  104. val = DA9055_BUCK_MODE_AUTO << info->mode.shift;
  105. break;
  106. case REGULATOR_MODE_STANDBY:
  107. val = DA9055_BUCK_MODE_SLEEP << info->mode.shift;
  108. break;
  109. }
  110. return da9055_reg_update(regulator->da9055, info->mode.reg,
  111. info->mode.mask, val);
  112. }
  113. static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
  114. {
  115. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  116. struct da9055_regulator_info *info = regulator->info;
  117. int ret;
  118. ret = da9055_reg_read(regulator->da9055, info->volt.reg_b);
  119. if (ret < 0)
  120. return ret;
  121. if (ret >> info->volt.sl_shift)
  122. return REGULATOR_MODE_STANDBY;
  123. else
  124. return REGULATOR_MODE_NORMAL;
  125. }
  126. static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
  127. {
  128. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  129. struct da9055_regulator_info *info = regulator->info;
  130. struct da9055_volt_reg volt = info->volt;
  131. int val = 0;
  132. switch (mode) {
  133. case REGULATOR_MODE_NORMAL:
  134. case REGULATOR_MODE_FAST:
  135. val = DA9055_LDO_MODE_SYNC;
  136. break;
  137. case REGULATOR_MODE_STANDBY:
  138. val = DA9055_LDO_MODE_SLEEP;
  139. break;
  140. }
  141. return da9055_reg_update(regulator->da9055, volt.reg_b,
  142. 1 << volt.sl_shift,
  143. val << volt.sl_shift);
  144. }
  145. static int da9055_buck_get_current_limit(struct regulator_dev *rdev)
  146. {
  147. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  148. struct da9055_regulator_info *info = regulator->info;
  149. int ret;
  150. ret = da9055_reg_read(regulator->da9055, DA9055_REG_BUCK_LIM);
  151. if (ret < 0)
  152. return ret;
  153. ret &= info->mode.mask;
  154. return da9055_current_limits[ret >> info->mode.shift];
  155. }
  156. static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
  157. int max_uA)
  158. {
  159. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  160. struct da9055_regulator_info *info = regulator->info;
  161. int i;
  162. for (i = ARRAY_SIZE(da9055_current_limits) - 1; i >= 0; i--) {
  163. if ((min_uA <= da9055_current_limits[i]) &&
  164. (da9055_current_limits[i] <= max_uA))
  165. return da9055_reg_update(regulator->da9055,
  166. DA9055_REG_BUCK_LIM,
  167. info->mode.mask,
  168. i << info->mode.shift);
  169. }
  170. return -EINVAL;
  171. }
  172. static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
  173. {
  174. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  175. struct da9055_regulator_info *info = regulator->info;
  176. struct da9055_volt_reg volt = info->volt;
  177. int ret, sel;
  178. /*
  179. * There are two voltage register set A & B for voltage ramping but
  180. * either one of then can be active therefore we first determine
  181. * the active register set.
  182. */
  183. ret = da9055_reg_read(regulator->da9055, info->conf.reg);
  184. if (ret < 0)
  185. return ret;
  186. ret &= info->conf.sel_mask;
  187. /* Get the voltage for the active register set A/B */
  188. if (ret == DA9055_REGUALTOR_SET_A)
  189. ret = da9055_reg_read(regulator->da9055, volt.reg_a);
  190. else
  191. ret = da9055_reg_read(regulator->da9055, volt.reg_b);
  192. if (ret < 0)
  193. return ret;
  194. sel = (ret & volt.v_mask);
  195. return sel;
  196. }
  197. static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
  198. unsigned int selector)
  199. {
  200. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  201. struct da9055_regulator_info *info = regulator->info;
  202. int ret;
  203. /*
  204. * Regulator register set A/B is not selected through GPIO therefore
  205. * we use default register set A for voltage ramping.
  206. */
  207. if (regulator->reg_rselect == NO_GPIO) {
  208. /* Select register set A */
  209. ret = da9055_reg_update(regulator->da9055, info->conf.reg,
  210. info->conf.sel_mask, DA9055_SEL_REG_A);
  211. if (ret < 0)
  212. return ret;
  213. /* Set the voltage */
  214. return da9055_reg_update(regulator->da9055, info->volt.reg_a,
  215. info->volt.v_mask, selector);
  216. }
  217. /*
  218. * Here regulator register set A/B is selected through GPIO.
  219. * Therefore we first determine the selected register set A/B and
  220. * then set the desired voltage for that register set A/B.
  221. */
  222. ret = da9055_reg_read(regulator->da9055, info->conf.reg);
  223. if (ret < 0)
  224. return ret;
  225. ret &= info->conf.sel_mask;
  226. /* Set the voltage */
  227. if (ret == DA9055_REGUALTOR_SET_A)
  228. return da9055_reg_update(regulator->da9055, info->volt.reg_a,
  229. info->volt.v_mask, selector);
  230. else
  231. return da9055_reg_update(regulator->da9055, info->volt.reg_b,
  232. info->volt.v_mask, selector);
  233. }
  234. static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
  235. int uV)
  236. {
  237. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  238. struct da9055_regulator_info *info = regulator->info;
  239. int ret;
  240. /* Select register set B for suspend voltage ramping. */
  241. if (regulator->reg_rselect == NO_GPIO) {
  242. ret = da9055_reg_update(regulator->da9055, info->conf.reg,
  243. info->conf.sel_mask, DA9055_SEL_REG_B);
  244. if (ret < 0)
  245. return ret;
  246. }
  247. ret = regulator_map_voltage_linear(rdev, uV, uV);
  248. if (ret < 0)
  249. return ret;
  250. return da9055_reg_update(regulator->da9055, info->volt.reg_b,
  251. info->volt.v_mask, ret);
  252. }
  253. static int da9055_suspend_enable(struct regulator_dev *rdev)
  254. {
  255. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  256. struct da9055_regulator_info *info = regulator->info;
  257. /* Select register set B for voltage ramping. */
  258. if (regulator->reg_rselect == NO_GPIO)
  259. return da9055_reg_update(regulator->da9055, info->conf.reg,
  260. info->conf.sel_mask, DA9055_SEL_REG_B);
  261. else
  262. return 0;
  263. }
  264. static int da9055_suspend_disable(struct regulator_dev *rdev)
  265. {
  266. struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
  267. struct da9055_regulator_info *info = regulator->info;
  268. /* Diselect register set B. */
  269. if (regulator->reg_rselect == NO_GPIO)
  270. return da9055_reg_update(regulator->da9055, info->conf.reg,
  271. info->conf.sel_mask, DA9055_SEL_REG_A);
  272. else
  273. return 0;
  274. }
  275. static const struct regulator_ops da9055_buck_ops = {
  276. .get_mode = da9055_buck_get_mode,
  277. .set_mode = da9055_buck_set_mode,
  278. .get_current_limit = da9055_buck_get_current_limit,
  279. .set_current_limit = da9055_buck_set_current_limit,
  280. .get_voltage_sel = da9055_regulator_get_voltage_sel,
  281. .set_voltage_sel = da9055_regulator_set_voltage_sel,
  282. .list_voltage = regulator_list_voltage_linear,
  283. .map_voltage = regulator_map_voltage_linear,
  284. .is_enabled = regulator_is_enabled_regmap,
  285. .enable = regulator_enable_regmap,
  286. .disable = regulator_disable_regmap,
  287. .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
  288. .set_suspend_enable = da9055_suspend_enable,
  289. .set_suspend_disable = da9055_suspend_disable,
  290. .set_suspend_mode = da9055_buck_set_mode,
  291. };
  292. static const struct regulator_ops da9055_ldo_ops = {
  293. .get_mode = da9055_ldo_get_mode,
  294. .set_mode = da9055_ldo_set_mode,
  295. .get_voltage_sel = da9055_regulator_get_voltage_sel,
  296. .set_voltage_sel = da9055_regulator_set_voltage_sel,
  297. .list_voltage = regulator_list_voltage_linear,
  298. .map_voltage = regulator_map_voltage_linear,
  299. .is_enabled = regulator_is_enabled_regmap,
  300. .enable = regulator_enable_regmap,
  301. .disable = regulator_disable_regmap,
  302. .set_suspend_voltage = da9055_regulator_set_suspend_voltage,
  303. .set_suspend_enable = da9055_suspend_enable,
  304. .set_suspend_disable = da9055_suspend_disable,
  305. .set_suspend_mode = da9055_ldo_set_mode,
  306. };
  307. #define DA9055_LDO(_id, step, min, max, vbits, voffset) \
  308. {\
  309. .reg_desc = {\
  310. .name = #_id,\
  311. .ops = &da9055_ldo_ops,\
  312. .type = REGULATOR_VOLTAGE,\
  313. .id = DA9055_ID_##_id,\
  314. .n_voltages = (max - min) / step + 1 + (voffset), \
  315. .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
  316. .enable_mask = 1, \
  317. .min_uV = (min) * 1000,\
  318. .uV_step = (step) * 1000,\
  319. .linear_min_sel = (voffset),\
  320. .owner = THIS_MODULE,\
  321. },\
  322. .conf = {\
  323. .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
  324. .sel_mask = (1 << 4),\
  325. .en_mask = 1,\
  326. },\
  327. .volt = {\
  328. .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
  329. .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
  330. .sl_shift = 7,\
  331. .v_mask = (1 << (vbits)) - 1,\
  332. },\
  333. }
  334. #define DA9055_BUCK(_id, step, min, max, vbits, voffset, mbits, sbits) \
  335. {\
  336. .reg_desc = {\
  337. .name = #_id,\
  338. .ops = &da9055_buck_ops,\
  339. .type = REGULATOR_VOLTAGE,\
  340. .id = DA9055_ID_##_id,\
  341. .n_voltages = (max - min) / step + 1 + (voffset), \
  342. .enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
  343. .enable_mask = 1,\
  344. .min_uV = (min) * 1000,\
  345. .uV_step = (step) * 1000,\
  346. .linear_min_sel = (voffset),\
  347. .owner = THIS_MODULE,\
  348. },\
  349. .conf = {\
  350. .reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
  351. .sel_mask = (1 << 4),\
  352. .en_mask = 1,\
  353. },\
  354. .volt = {\
  355. .reg_a = DA9055_REG_VBCORE_A + DA9055_ID_##_id, \
  356. .reg_b = DA9055_REG_VBCORE_B + DA9055_ID_##_id, \
  357. .sl_shift = 7,\
  358. .v_mask = (1 << (vbits)) - 1,\
  359. },\
  360. .mode = {\
  361. .reg = DA9055_REG_BCORE_MODE,\
  362. .mask = (mbits),\
  363. .shift = (sbits),\
  364. },\
  365. }
  366. static struct da9055_regulator_info da9055_regulator_info[] = {
  367. DA9055_BUCK(BUCK1, 25, 725, 2075, 6, 9, 0xc, 2),
  368. DA9055_BUCK(BUCK2, 25, 925, 2500, 6, 0, 3, 0),
  369. DA9055_LDO(LDO1, 50, 900, 3300, 6, 2),
  370. DA9055_LDO(LDO2, 50, 900, 3300, 6, 3),
  371. DA9055_LDO(LDO3, 50, 900, 3300, 6, 2),
  372. DA9055_LDO(LDO4, 50, 900, 3300, 6, 2),
  373. DA9055_LDO(LDO5, 50, 900, 2750, 6, 2),
  374. DA9055_LDO(LDO6, 20, 900, 3300, 7, 0),
  375. };
  376. /*
  377. * Configures regulator to be controlled either through GPIO 1 or 2.
  378. * GPIO can control regulator state and/or select the regulator register
  379. * set A/B for voltage ramping.
  380. */
  381. static int da9055_gpio_init(struct da9055_regulator *regulator,
  382. struct regulator_config *config,
  383. struct da9055_pdata *pdata, int id)
  384. {
  385. struct da9055_regulator_info *info = regulator->info;
  386. int ret = 0;
  387. if (!pdata)
  388. return 0;
  389. if (pdata->gpio_ren && pdata->gpio_ren[id]) {
  390. char name[18];
  391. int gpio_mux = pdata->gpio_ren[id];
  392. config->ena_gpio = pdata->ena_gpio[id];
  393. config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
  394. config->ena_gpio_invert = 1;
  395. /*
  396. * GPI pin is muxed with regulator to control the
  397. * regulator state.
  398. */
  399. sprintf(name, "DA9055 GPI %d", gpio_mux);
  400. ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
  401. name);
  402. if (ret < 0)
  403. goto err;
  404. /*
  405. * Let the regulator know that its state is controlled
  406. * through GPI.
  407. */
  408. ret = da9055_reg_update(regulator->da9055, info->conf.reg,
  409. DA9055_E_GPI_MASK,
  410. pdata->reg_ren[id]
  411. << DA9055_E_GPI_SHIFT);
  412. if (ret < 0)
  413. goto err;
  414. }
  415. if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
  416. char name[18];
  417. int gpio_mux = pdata->gpio_rsel[id];
  418. regulator->reg_rselect = pdata->reg_rsel[id];
  419. /*
  420. * GPI pin is muxed with regulator to select the
  421. * regulator register set A/B for voltage ramping.
  422. */
  423. sprintf(name, "DA9055 GPI %d", gpio_mux);
  424. ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
  425. name);
  426. if (ret < 0)
  427. goto err;
  428. /*
  429. * Let the regulator know that its register set A/B
  430. * will be selected through GPI for voltage ramping.
  431. */
  432. ret = da9055_reg_update(regulator->da9055, info->conf.reg,
  433. DA9055_V_GPI_MASK,
  434. pdata->reg_rsel[id]
  435. << DA9055_V_GPI_SHIFT);
  436. }
  437. err:
  438. return ret;
  439. }
  440. static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data)
  441. {
  442. struct da9055_regulator *regulator = data;
  443. regulator_notifier_call_chain(regulator->rdev,
  444. REGULATOR_EVENT_OVER_CURRENT, NULL);
  445. return IRQ_HANDLED;
  446. }
  447. static inline struct da9055_regulator_info *find_regulator_info(int id)
  448. {
  449. struct da9055_regulator_info *info;
  450. int i;
  451. for (i = 0; i < ARRAY_SIZE(da9055_regulator_info); i++) {
  452. info = &da9055_regulator_info[i];
  453. if (info->reg_desc.id == id)
  454. return info;
  455. }
  456. return NULL;
  457. }
  458. #ifdef CONFIG_OF
  459. static struct of_regulator_match da9055_reg_matches[] = {
  460. { .name = "BUCK1", },
  461. { .name = "BUCK2", },
  462. { .name = "LDO1", },
  463. { .name = "LDO2", },
  464. { .name = "LDO3", },
  465. { .name = "LDO4", },
  466. { .name = "LDO5", },
  467. { .name = "LDO6", },
  468. };
  469. static int da9055_regulator_dt_init(struct platform_device *pdev,
  470. struct da9055_regulator *regulator,
  471. struct regulator_config *config,
  472. int regid)
  473. {
  474. struct device_node *nproot, *np;
  475. int ret;
  476. nproot = of_node_get(pdev->dev.parent->of_node);
  477. if (!nproot)
  478. return -ENODEV;
  479. np = of_get_child_by_name(nproot, "regulators");
  480. if (!np)
  481. return -ENODEV;
  482. ret = of_regulator_match(&pdev->dev, np, &da9055_reg_matches[regid], 1);
  483. of_node_put(nproot);
  484. if (ret < 0) {
  485. dev_err(&pdev->dev, "Error matching regulator: %d\n", ret);
  486. return ret;
  487. }
  488. config->init_data = da9055_reg_matches[regid].init_data;
  489. config->of_node = da9055_reg_matches[regid].of_node;
  490. if (!config->of_node)
  491. return -ENODEV;
  492. return 0;
  493. }
  494. #else
  495. static inline int da9055_regulator_dt_init(struct platform_device *pdev,
  496. struct da9055_regulator *regulator,
  497. struct regulator_config *config,
  498. int regid)
  499. {
  500. return -ENODEV;
  501. }
  502. #endif /* CONFIG_OF */
  503. static int da9055_regulator_probe(struct platform_device *pdev)
  504. {
  505. struct regulator_config config = { };
  506. struct da9055_regulator *regulator;
  507. struct da9055 *da9055 = dev_get_drvdata(pdev->dev.parent);
  508. struct da9055_pdata *pdata = dev_get_platdata(da9055->dev);
  509. int ret, irq;
  510. regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9055_regulator),
  511. GFP_KERNEL);
  512. if (!regulator)
  513. return -ENOMEM;
  514. regulator->info = find_regulator_info(pdev->id);
  515. if (regulator->info == NULL) {
  516. dev_err(&pdev->dev, "invalid regulator ID specified\n");
  517. return -EINVAL;
  518. }
  519. regulator->da9055 = da9055;
  520. config.dev = &pdev->dev;
  521. config.driver_data = regulator;
  522. config.regmap = da9055->regmap;
  523. if (pdata && pdata->regulators) {
  524. config.init_data = pdata->regulators[pdev->id];
  525. } else {
  526. ret = da9055_regulator_dt_init(pdev, regulator, &config,
  527. pdev->id);
  528. if (ret < 0)
  529. return ret;
  530. }
  531. ret = da9055_gpio_init(regulator, &config, pdata, pdev->id);
  532. if (ret < 0)
  533. return ret;
  534. regulator->rdev = devm_regulator_register(&pdev->dev,
  535. &regulator->info->reg_desc,
  536. &config);
  537. if (IS_ERR(regulator->rdev)) {
  538. dev_err(&pdev->dev, "Failed to register regulator %s\n",
  539. regulator->info->reg_desc.name);
  540. return PTR_ERR(regulator->rdev);
  541. }
  542. /* Only LDO 5 and 6 has got the over current interrupt */
  543. if (pdev->id == DA9055_ID_LDO5 || pdev->id == DA9055_ID_LDO6) {
  544. irq = platform_get_irq_byname(pdev, "REGULATOR");
  545. if (irq < 0)
  546. return irq;
  547. ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
  548. da9055_ldo5_6_oc_irq,
  549. IRQF_TRIGGER_HIGH |
  550. IRQF_ONESHOT |
  551. IRQF_PROBE_SHARED,
  552. pdev->name, regulator);
  553. if (ret != 0) {
  554. if (ret != -EBUSY) {
  555. dev_err(&pdev->dev,
  556. "Failed to request Regulator IRQ %d: %d\n",
  557. irq, ret);
  558. return ret;
  559. }
  560. }
  561. }
  562. platform_set_drvdata(pdev, regulator);
  563. return 0;
  564. }
  565. static struct platform_driver da9055_regulator_driver = {
  566. .probe = da9055_regulator_probe,
  567. .driver = {
  568. .name = "da9055-regulator",
  569. },
  570. };
  571. static int __init da9055_regulator_init(void)
  572. {
  573. return platform_driver_register(&da9055_regulator_driver);
  574. }
  575. subsys_initcall(da9055_regulator_init);
  576. static void __exit da9055_regulator_exit(void)
  577. {
  578. platform_driver_unregister(&da9055_regulator_driver);
  579. }
  580. module_exit(da9055_regulator_exit);
  581. MODULE_AUTHOR("David Dajun Chen <[email protected]>");
  582. MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9055 PMIC");
  583. MODULE_LICENSE("GPL");
  584. MODULE_ALIAS("platform:da9055-regulator");