wm831x-ldo.c 17 KB

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