wm831x-ldo.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // wm831x-ldo.c -- LDO driver for the WM831x series
  4. //
  5. // Copyright 2009 Wolfson Microelectronics PLC.
  6. //
  7. // Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  8. #include <linux/module.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/init.h>
  11. #include <linux/bitops.h>
  12. #include <linux/err.h>
  13. #include <linux/i2c.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regulator/driver.h>
  16. #include <linux/slab.h>
  17. #include <linux/mfd/wm831x/core.h>
  18. #include <linux/mfd/wm831x/regulator.h>
  19. #include <linux/mfd/wm831x/pdata.h>
  20. #define WM831X_LDO_MAX_NAME 9
  21. #define WM831X_LDO_CONTROL 0
  22. #define WM831X_LDO_ON_CONTROL 1
  23. #define WM831X_LDO_SLEEP_CONTROL 2
  24. #define WM831X_ALIVE_LDO_ON_CONTROL 0
  25. #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1
  26. struct wm831x_ldo {
  27. char name[WM831X_LDO_MAX_NAME];
  28. char supply_name[WM831X_LDO_MAX_NAME];
  29. struct regulator_desc desc;
  30. int base;
  31. struct wm831x *wm831x;
  32. struct regulator_dev *regulator;
  33. };
  34. /*
  35. * Shared
  36. */
  37. static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data)
  38. {
  39. struct wm831x_ldo *ldo = data;
  40. regulator_lock(ldo->regulator);
  41. regulator_notifier_call_chain(ldo->regulator,
  42. REGULATOR_EVENT_UNDER_VOLTAGE,
  43. NULL);
  44. regulator_unlock(ldo->regulator);
  45. return IRQ_HANDLED;
  46. }
  47. /*
  48. * General purpose LDOs
  49. */
  50. static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = {
  51. REGULATOR_LINEAR_RANGE(900000, 0, 14, 50000),
  52. REGULATOR_LINEAR_RANGE(1700000, 15, 31, 100000),
  53. };
  54. static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev,
  55. int uV)
  56. {
  57. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  58. struct wm831x *wm831x = ldo->wm831x;
  59. int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
  60. sel = regulator_map_voltage_linear_range(rdev, uV, uV);
  61. if (sel < 0)
  62. return sel;
  63. return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel);
  64. }
  65. static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev)
  66. {
  67. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  68. struct wm831x *wm831x = ldo->wm831x;
  69. int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
  70. int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  71. int ret;
  72. ret = wm831x_reg_read(wm831x, on_reg);
  73. if (ret < 0)
  74. return ret;
  75. if (!(ret & WM831X_LDO1_ON_MODE))
  76. return REGULATOR_MODE_NORMAL;
  77. ret = wm831x_reg_read(wm831x, ctrl_reg);
  78. if (ret < 0)
  79. return ret;
  80. if (ret & WM831X_LDO1_LP_MODE)
  81. return REGULATOR_MODE_STANDBY;
  82. else
  83. return REGULATOR_MODE_IDLE;
  84. }
  85. static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
  86. unsigned int mode)
  87. {
  88. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  89. struct wm831x *wm831x = ldo->wm831x;
  90. int ctrl_reg = ldo->base + WM831X_LDO_CONTROL;
  91. int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  92. int ret;
  93. switch (mode) {
  94. case REGULATOR_MODE_NORMAL:
  95. ret = wm831x_set_bits(wm831x, on_reg,
  96. WM831X_LDO1_ON_MODE, 0);
  97. if (ret < 0)
  98. return ret;
  99. break;
  100. case REGULATOR_MODE_IDLE:
  101. ret = wm831x_set_bits(wm831x, ctrl_reg,
  102. WM831X_LDO1_LP_MODE, 0);
  103. if (ret < 0)
  104. return ret;
  105. ret = wm831x_set_bits(wm831x, on_reg,
  106. WM831X_LDO1_ON_MODE,
  107. WM831X_LDO1_ON_MODE);
  108. if (ret < 0)
  109. return ret;
  110. break;
  111. case REGULATOR_MODE_STANDBY:
  112. ret = wm831x_set_bits(wm831x, ctrl_reg,
  113. WM831X_LDO1_LP_MODE,
  114. WM831X_LDO1_LP_MODE);
  115. if (ret < 0)
  116. return ret;
  117. ret = wm831x_set_bits(wm831x, on_reg,
  118. WM831X_LDO1_ON_MODE,
  119. WM831X_LDO1_ON_MODE);
  120. if (ret < 0)
  121. return ret;
  122. break;
  123. default:
  124. return -EINVAL;
  125. }
  126. return 0;
  127. }
  128. static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev)
  129. {
  130. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  131. struct wm831x *wm831x = ldo->wm831x;
  132. int mask = 1 << rdev_get_id(rdev);
  133. int ret;
  134. /* Is the regulator on? */
  135. ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
  136. if (ret < 0)
  137. return ret;
  138. if (!(ret & mask))
  139. return REGULATOR_STATUS_OFF;
  140. /* Is it reporting under voltage? */
  141. ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
  142. if (ret < 0)
  143. return ret;
  144. if (ret & mask)
  145. return REGULATOR_STATUS_ERROR;
  146. ret = wm831x_gp_ldo_get_mode(rdev);
  147. if (ret < 0)
  148. return ret;
  149. else
  150. return regulator_mode_to_status(ret);
  151. }
  152. static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev,
  153. int input_uV,
  154. int output_uV, int load_uA)
  155. {
  156. if (load_uA < 20000)
  157. return REGULATOR_MODE_STANDBY;
  158. if (load_uA < 50000)
  159. return REGULATOR_MODE_IDLE;
  160. return REGULATOR_MODE_NORMAL;
  161. }
  162. static const struct regulator_ops wm831x_gp_ldo_ops = {
  163. .list_voltage = regulator_list_voltage_linear_range,
  164. .map_voltage = regulator_map_voltage_linear_range,
  165. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  166. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  167. .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage,
  168. .get_mode = wm831x_gp_ldo_get_mode,
  169. .set_mode = wm831x_gp_ldo_set_mode,
  170. .get_status = wm831x_gp_ldo_get_status,
  171. .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode,
  172. .get_bypass = regulator_get_bypass_regmap,
  173. .set_bypass = regulator_set_bypass_regmap,
  174. .is_enabled = regulator_is_enabled_regmap,
  175. .enable = regulator_enable_regmap,
  176. .disable = regulator_disable_regmap,
  177. };
  178. static int wm831x_gp_ldo_probe(struct platform_device *pdev)
  179. {
  180. struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
  181. struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
  182. struct regulator_config config = { };
  183. int id;
  184. struct wm831x_ldo *ldo;
  185. struct resource *res;
  186. int ret, irq;
  187. if (pdata && pdata->wm831x_num)
  188. id = (pdata->wm831x_num * 10) + 1;
  189. else
  190. id = 0;
  191. id = pdev->id - id;
  192. dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
  193. ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
  194. if (!ldo)
  195. return -ENOMEM;
  196. ldo->wm831x = wm831x;
  197. res = platform_get_resource(pdev, IORESOURCE_REG, 0);
  198. if (res == NULL) {
  199. dev_err(&pdev->dev, "No REG resource\n");
  200. ret = -EINVAL;
  201. goto err;
  202. }
  203. ldo->base = res->start;
  204. snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
  205. ldo->desc.name = ldo->name;
  206. snprintf(ldo->supply_name, sizeof(ldo->supply_name),
  207. "LDO%dVDD", id + 1);
  208. ldo->desc.supply_name = ldo->supply_name;
  209. ldo->desc.id = id;
  210. ldo->desc.type = REGULATOR_VOLTAGE;
  211. ldo->desc.n_voltages = 32;
  212. ldo->desc.ops = &wm831x_gp_ldo_ops;
  213. ldo->desc.owner = THIS_MODULE;
  214. ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  215. ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK;
  216. ldo->desc.enable_reg = WM831X_LDO_ENABLE;
  217. ldo->desc.enable_mask = 1 << id;
  218. ldo->desc.bypass_reg = ldo->base;
  219. ldo->desc.bypass_mask = WM831X_LDO1_SWI;
  220. ldo->desc.linear_ranges = wm831x_gp_ldo_ranges;
  221. ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges);
  222. config.dev = pdev->dev.parent;
  223. if (pdata)
  224. config.init_data = pdata->ldo[id];
  225. config.driver_data = ldo;
  226. config.regmap = wm831x->regmap;
  227. ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
  228. &config);
  229. if (IS_ERR(ldo->regulator)) {
  230. ret = PTR_ERR(ldo->regulator);
  231. dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
  232. id + 1, ret);
  233. goto err;
  234. }
  235. irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
  236. ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
  237. wm831x_ldo_uv_irq,
  238. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  239. ldo->name,
  240. ldo);
  241. if (ret != 0) {
  242. dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
  243. irq, ret);
  244. goto err;
  245. }
  246. platform_set_drvdata(pdev, ldo);
  247. return 0;
  248. err:
  249. return ret;
  250. }
  251. static struct platform_driver wm831x_gp_ldo_driver = {
  252. .probe = wm831x_gp_ldo_probe,
  253. .driver = {
  254. .name = "wm831x-ldo",
  255. },
  256. };
  257. /*
  258. * Analogue LDOs
  259. */
  260. static const struct regulator_linear_range wm831x_aldo_ranges[] = {
  261. REGULATOR_LINEAR_RANGE(1000000, 0, 12, 50000),
  262. REGULATOR_LINEAR_RANGE(1700000, 13, 31, 100000),
  263. };
  264. static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev,
  265. int uV)
  266. {
  267. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  268. struct wm831x *wm831x = ldo->wm831x;
  269. int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL;
  270. sel = regulator_map_voltage_linear_range(rdev, uV, uV);
  271. if (sel < 0)
  272. return sel;
  273. return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel);
  274. }
  275. static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev)
  276. {
  277. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  278. struct wm831x *wm831x = ldo->wm831x;
  279. int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  280. int ret;
  281. ret = wm831x_reg_read(wm831x, on_reg);
  282. if (ret < 0)
  283. return 0;
  284. if (ret & WM831X_LDO7_ON_MODE)
  285. return REGULATOR_MODE_IDLE;
  286. else
  287. return REGULATOR_MODE_NORMAL;
  288. }
  289. static int wm831x_aldo_set_mode(struct regulator_dev *rdev,
  290. unsigned int mode)
  291. {
  292. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  293. struct wm831x *wm831x = ldo->wm831x;
  294. int on_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  295. int ret;
  296. switch (mode) {
  297. case REGULATOR_MODE_NORMAL:
  298. ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0);
  299. if (ret < 0)
  300. return ret;
  301. break;
  302. case REGULATOR_MODE_IDLE:
  303. ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE,
  304. WM831X_LDO7_ON_MODE);
  305. if (ret < 0)
  306. return ret;
  307. break;
  308. default:
  309. return -EINVAL;
  310. }
  311. return 0;
  312. }
  313. static int wm831x_aldo_get_status(struct regulator_dev *rdev)
  314. {
  315. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  316. struct wm831x *wm831x = ldo->wm831x;
  317. int mask = 1 << rdev_get_id(rdev);
  318. int ret;
  319. /* Is the regulator on? */
  320. ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
  321. if (ret < 0)
  322. return ret;
  323. if (!(ret & mask))
  324. return REGULATOR_STATUS_OFF;
  325. /* Is it reporting under voltage? */
  326. ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS);
  327. if (ret < 0)
  328. return ret;
  329. if (ret & mask)
  330. return REGULATOR_STATUS_ERROR;
  331. ret = wm831x_aldo_get_mode(rdev);
  332. if (ret < 0)
  333. return ret;
  334. else
  335. return regulator_mode_to_status(ret);
  336. }
  337. static const struct regulator_ops wm831x_aldo_ops = {
  338. .list_voltage = regulator_list_voltage_linear_range,
  339. .map_voltage = regulator_map_voltage_linear_range,
  340. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  341. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  342. .set_suspend_voltage = wm831x_aldo_set_suspend_voltage,
  343. .get_mode = wm831x_aldo_get_mode,
  344. .set_mode = wm831x_aldo_set_mode,
  345. .get_status = wm831x_aldo_get_status,
  346. .set_bypass = regulator_set_bypass_regmap,
  347. .get_bypass = regulator_get_bypass_regmap,
  348. .is_enabled = regulator_is_enabled_regmap,
  349. .enable = regulator_enable_regmap,
  350. .disable = regulator_disable_regmap,
  351. };
  352. static int wm831x_aldo_probe(struct platform_device *pdev)
  353. {
  354. struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
  355. struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
  356. struct regulator_config config = { };
  357. int id;
  358. struct wm831x_ldo *ldo;
  359. struct resource *res;
  360. int ret, irq;
  361. if (pdata && pdata->wm831x_num)
  362. id = (pdata->wm831x_num * 10) + 1;
  363. else
  364. id = 0;
  365. id = pdev->id - id;
  366. dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
  367. ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
  368. if (!ldo)
  369. return -ENOMEM;
  370. ldo->wm831x = wm831x;
  371. res = platform_get_resource(pdev, IORESOURCE_REG, 0);
  372. if (res == NULL) {
  373. dev_err(&pdev->dev, "No REG resource\n");
  374. ret = -EINVAL;
  375. goto err;
  376. }
  377. ldo->base = res->start;
  378. snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
  379. ldo->desc.name = ldo->name;
  380. snprintf(ldo->supply_name, sizeof(ldo->supply_name),
  381. "LDO%dVDD", id + 1);
  382. ldo->desc.supply_name = ldo->supply_name;
  383. ldo->desc.id = id;
  384. ldo->desc.type = REGULATOR_VOLTAGE;
  385. ldo->desc.n_voltages = 32;
  386. ldo->desc.linear_ranges = wm831x_aldo_ranges;
  387. ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges);
  388. ldo->desc.ops = &wm831x_aldo_ops;
  389. ldo->desc.owner = THIS_MODULE;
  390. ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL;
  391. ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK;
  392. ldo->desc.enable_reg = WM831X_LDO_ENABLE;
  393. ldo->desc.enable_mask = 1 << id;
  394. ldo->desc.bypass_reg = ldo->base;
  395. ldo->desc.bypass_mask = WM831X_LDO7_SWI;
  396. config.dev = pdev->dev.parent;
  397. if (pdata)
  398. config.init_data = pdata->ldo[id];
  399. config.driver_data = ldo;
  400. config.regmap = wm831x->regmap;
  401. ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
  402. &config);
  403. if (IS_ERR(ldo->regulator)) {
  404. ret = PTR_ERR(ldo->regulator);
  405. dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
  406. id + 1, ret);
  407. goto err;
  408. }
  409. irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV"));
  410. ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
  411. wm831x_ldo_uv_irq,
  412. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  413. ldo->name, ldo);
  414. if (ret != 0) {
  415. dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n",
  416. irq, ret);
  417. goto err;
  418. }
  419. platform_set_drvdata(pdev, ldo);
  420. return 0;
  421. err:
  422. return ret;
  423. }
  424. static struct platform_driver wm831x_aldo_driver = {
  425. .probe = wm831x_aldo_probe,
  426. .driver = {
  427. .name = "wm831x-aldo",
  428. },
  429. };
  430. /*
  431. * Alive LDO
  432. */
  433. #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf
  434. static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev,
  435. int uV)
  436. {
  437. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  438. struct wm831x *wm831x = ldo->wm831x;
  439. int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL;
  440. sel = regulator_map_voltage_linear(rdev, uV, uV);
  441. if (sel < 0)
  442. return sel;
  443. return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel);
  444. }
  445. static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev)
  446. {
  447. struct wm831x_ldo *ldo = rdev_get_drvdata(rdev);
  448. struct wm831x *wm831x = ldo->wm831x;
  449. int mask = 1 << rdev_get_id(rdev);
  450. int ret;
  451. /* Is the regulator on? */
  452. ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS);
  453. if (ret < 0)
  454. return ret;
  455. if (ret & mask)
  456. return REGULATOR_STATUS_ON;
  457. else
  458. return REGULATOR_STATUS_OFF;
  459. }
  460. static const struct regulator_ops wm831x_alive_ldo_ops = {
  461. .list_voltage = regulator_list_voltage_linear,
  462. .map_voltage = regulator_map_voltage_linear,
  463. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  464. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  465. .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage,
  466. .get_status = wm831x_alive_ldo_get_status,
  467. .is_enabled = regulator_is_enabled_regmap,
  468. .enable = regulator_enable_regmap,
  469. .disable = regulator_disable_regmap,
  470. };
  471. static int wm831x_alive_ldo_probe(struct platform_device *pdev)
  472. {
  473. struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
  474. struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev);
  475. struct regulator_config config = { };
  476. int id;
  477. struct wm831x_ldo *ldo;
  478. struct resource *res;
  479. int ret;
  480. if (pdata && pdata->wm831x_num)
  481. id = (pdata->wm831x_num * 10) + 1;
  482. else
  483. id = 0;
  484. id = pdev->id - id;
  485. dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1);
  486. ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL);
  487. if (!ldo)
  488. return -ENOMEM;
  489. ldo->wm831x = wm831x;
  490. res = platform_get_resource(pdev, IORESOURCE_REG, 0);
  491. if (res == NULL) {
  492. dev_err(&pdev->dev, "No REG resource\n");
  493. ret = -EINVAL;
  494. goto err;
  495. }
  496. ldo->base = res->start;
  497. snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1);
  498. ldo->desc.name = ldo->name;
  499. snprintf(ldo->supply_name, sizeof(ldo->supply_name),
  500. "LDO%dVDD", id + 1);
  501. ldo->desc.supply_name = ldo->supply_name;
  502. ldo->desc.id = id;
  503. ldo->desc.type = REGULATOR_VOLTAGE;
  504. ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1;
  505. ldo->desc.ops = &wm831x_alive_ldo_ops;
  506. ldo->desc.owner = THIS_MODULE;
  507. ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL;
  508. ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK;
  509. ldo->desc.enable_reg = WM831X_LDO_ENABLE;
  510. ldo->desc.enable_mask = 1 << id;
  511. ldo->desc.min_uV = 800000;
  512. ldo->desc.uV_step = 50000;
  513. ldo->desc.enable_time = 1000;
  514. config.dev = pdev->dev.parent;
  515. if (pdata)
  516. config.init_data = pdata->ldo[id];
  517. config.driver_data = ldo;
  518. config.regmap = wm831x->regmap;
  519. ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc,
  520. &config);
  521. if (IS_ERR(ldo->regulator)) {
  522. ret = PTR_ERR(ldo->regulator);
  523. dev_err(wm831x->dev, "Failed to register LDO%d: %d\n",
  524. id + 1, ret);
  525. goto err;
  526. }
  527. platform_set_drvdata(pdev, ldo);
  528. return 0;
  529. err:
  530. return ret;
  531. }
  532. static struct platform_driver wm831x_alive_ldo_driver = {
  533. .probe = wm831x_alive_ldo_probe,
  534. .driver = {
  535. .name = "wm831x-alive-ldo",
  536. },
  537. };
  538. static struct platform_driver * const drivers[] = {
  539. &wm831x_gp_ldo_driver,
  540. &wm831x_aldo_driver,
  541. &wm831x_alive_ldo_driver,
  542. };
  543. static int __init wm831x_ldo_init(void)
  544. {
  545. return platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  546. }
  547. subsys_initcall(wm831x_ldo_init);
  548. static void __exit wm831x_ldo_exit(void)
  549. {
  550. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  551. }
  552. module_exit(wm831x_ldo_exit);
  553. /* Module information */
  554. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  555. MODULE_DESCRIPTION("WM831x LDO driver");
  556. MODULE_LICENSE("GPL");
  557. MODULE_ALIAS("platform:wm831x-ldo");
  558. MODULE_ALIAS("platform:wm831x-aldo");
  559. MODULE_ALIAS("platform:wm831x-aliveldo");