ab3100.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * drivers/regulator/ab3100.c
  4. *
  5. * Copyright (C) 2008-2009 ST-Ericsson AB
  6. * Low-level control of the AB3100 IC Low Dropout (LDO)
  7. * regulators, external regulator and buck converter
  8. * Author: Mattias Wallin <mattias.wallin@stericsson.com>
  9. * Author: Linus Walleij <linus.walleij@stericsson.com>
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/err.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/mfd/ab3100.h>
  18. #include <linux/mfd/abx500.h>
  19. #include <linux/of.h>
  20. #include <linux/regulator/of_regulator.h>
  21. /* LDO registers and some handy masking definitions for AB3100 */
  22. #define AB3100_LDO_A 0x40
  23. #define AB3100_LDO_C 0x41
  24. #define AB3100_LDO_D 0x42
  25. #define AB3100_LDO_E 0x43
  26. #define AB3100_LDO_E_SLEEP 0x44
  27. #define AB3100_LDO_F 0x45
  28. #define AB3100_LDO_G 0x46
  29. #define AB3100_LDO_H 0x47
  30. #define AB3100_LDO_H_SLEEP_MODE 0
  31. #define AB3100_LDO_H_SLEEP_EN 2
  32. #define AB3100_LDO_ON 4
  33. #define AB3100_LDO_H_VSEL_AC 5
  34. #define AB3100_LDO_K 0x48
  35. #define AB3100_LDO_EXT 0x49
  36. #define AB3100_BUCK 0x4A
  37. #define AB3100_BUCK_SLEEP 0x4B
  38. #define AB3100_REG_ON_MASK 0x10
  39. /**
  40. * struct ab3100_regulator
  41. * A struct passed around the individual regulator functions
  42. * @platform_device: platform device holding this regulator
  43. * @dev: handle to the device
  44. * @plfdata: AB3100 platform data passed in at probe time
  45. * @regreg: regulator register number in the AB3100
  46. */
  47. struct ab3100_regulator {
  48. struct device *dev;
  49. struct ab3100_platform_data *plfdata;
  50. u8 regreg;
  51. };
  52. /* The order in which registers are initialized */
  53. static const u8 ab3100_reg_init_order[AB3100_NUM_REGULATORS+2] = {
  54. AB3100_LDO_A,
  55. AB3100_LDO_C,
  56. AB3100_LDO_E,
  57. AB3100_LDO_E_SLEEP,
  58. AB3100_LDO_F,
  59. AB3100_LDO_G,
  60. AB3100_LDO_H,
  61. AB3100_LDO_K,
  62. AB3100_LDO_EXT,
  63. AB3100_BUCK,
  64. AB3100_BUCK_SLEEP,
  65. AB3100_LDO_D,
  66. };
  67. /* Preset (hardware defined) voltages for these regulators */
  68. #define LDO_A_VOLTAGE 2750000
  69. #define LDO_C_VOLTAGE 2650000
  70. #define LDO_D_VOLTAGE 2650000
  71. static const unsigned int ldo_e_buck_typ_voltages[] = {
  72. 1800000,
  73. 1400000,
  74. 1300000,
  75. 1200000,
  76. 1100000,
  77. 1050000,
  78. 900000,
  79. };
  80. static const unsigned int ldo_f_typ_voltages[] = {
  81. 1800000,
  82. 1400000,
  83. 1300000,
  84. 1200000,
  85. 1100000,
  86. 1050000,
  87. 2500000,
  88. 2650000,
  89. };
  90. static const unsigned int ldo_g_typ_voltages[] = {
  91. 2850000,
  92. 2750000,
  93. 1800000,
  94. 1500000,
  95. };
  96. static const unsigned int ldo_h_typ_voltages[] = {
  97. 2750000,
  98. 1800000,
  99. 1500000,
  100. 1200000,
  101. };
  102. static const unsigned int ldo_k_typ_voltages[] = {
  103. 2750000,
  104. 1800000,
  105. };
  106. /* The regulator devices */
  107. static struct ab3100_regulator
  108. ab3100_regulators[AB3100_NUM_REGULATORS] = {
  109. {
  110. .regreg = AB3100_LDO_A,
  111. },
  112. {
  113. .regreg = AB3100_LDO_C,
  114. },
  115. {
  116. .regreg = AB3100_LDO_D,
  117. },
  118. {
  119. .regreg = AB3100_LDO_E,
  120. },
  121. {
  122. .regreg = AB3100_LDO_F,
  123. },
  124. {
  125. .regreg = AB3100_LDO_G,
  126. },
  127. {
  128. .regreg = AB3100_LDO_H,
  129. },
  130. {
  131. .regreg = AB3100_LDO_K,
  132. },
  133. {
  134. .regreg = AB3100_LDO_EXT,
  135. /* No voltages for the external regulator */
  136. },
  137. {
  138. .regreg = AB3100_BUCK,
  139. },
  140. };
  141. /*
  142. * General functions for enable, disable and is_enabled used for
  143. * LDO: A,C,E,F,G,H,K,EXT and BUCK
  144. */
  145. static int ab3100_enable_regulator(struct regulator_dev *reg)
  146. {
  147. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  148. int err;
  149. u8 regval;
  150. err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
  151. &regval);
  152. if (err) {
  153. dev_warn(&reg->dev, "failed to get regid %d value\n",
  154. abreg->regreg);
  155. return err;
  156. }
  157. /* The regulator is already on, no reason to go further */
  158. if (regval & AB3100_REG_ON_MASK)
  159. return 0;
  160. regval |= AB3100_REG_ON_MASK;
  161. err = abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
  162. regval);
  163. if (err) {
  164. dev_warn(&reg->dev, "failed to set regid %d value\n",
  165. abreg->regreg);
  166. return err;
  167. }
  168. return 0;
  169. }
  170. static int ab3100_disable_regulator(struct regulator_dev *reg)
  171. {
  172. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  173. int err;
  174. u8 regval;
  175. /*
  176. * LDO D is a special regulator. When it is disabled, the entire
  177. * system is shut down. So this is handled specially.
  178. */
  179. pr_info("Called ab3100_disable_regulator\n");
  180. if (abreg->regreg == AB3100_LDO_D) {
  181. dev_info(&reg->dev, "disabling LDO D - shut down system\n");
  182. /* Setting LDO D to 0x00 cuts the power to the SoC */
  183. return abx500_set_register_interruptible(abreg->dev, 0,
  184. AB3100_LDO_D, 0x00U);
  185. }
  186. /*
  187. * All other regulators are handled here
  188. */
  189. err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
  190. &regval);
  191. if (err) {
  192. dev_err(&reg->dev, "unable to get register 0x%x\n",
  193. abreg->regreg);
  194. return err;
  195. }
  196. regval &= ~AB3100_REG_ON_MASK;
  197. return abx500_set_register_interruptible(abreg->dev, 0, abreg->regreg,
  198. regval);
  199. }
  200. static int ab3100_is_enabled_regulator(struct regulator_dev *reg)
  201. {
  202. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  203. u8 regval;
  204. int err;
  205. err = abx500_get_register_interruptible(abreg->dev, 0, abreg->regreg,
  206. &regval);
  207. if (err) {
  208. dev_err(&reg->dev, "unable to get register 0x%x\n",
  209. abreg->regreg);
  210. return err;
  211. }
  212. return regval & AB3100_REG_ON_MASK;
  213. }
  214. static int ab3100_get_voltage_regulator(struct regulator_dev *reg)
  215. {
  216. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  217. u8 regval;
  218. int err;
  219. /*
  220. * For variable types, read out setting and index into
  221. * supplied voltage list.
  222. */
  223. err = abx500_get_register_interruptible(abreg->dev, 0,
  224. abreg->regreg, &regval);
  225. if (err) {
  226. dev_warn(&reg->dev,
  227. "failed to get regulator value in register %02x\n",
  228. abreg->regreg);
  229. return err;
  230. }
  231. /* The 3 highest bits index voltages */
  232. regval &= 0xE0;
  233. regval >>= 5;
  234. if (regval >= reg->desc->n_voltages) {
  235. dev_err(&reg->dev,
  236. "regulator register %02x contains an illegal voltage setting\n",
  237. abreg->regreg);
  238. return -EINVAL;
  239. }
  240. return reg->desc->volt_table[regval];
  241. }
  242. static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg,
  243. unsigned selector)
  244. {
  245. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  246. u8 regval;
  247. int err;
  248. err = abx500_get_register_interruptible(abreg->dev, 0,
  249. abreg->regreg, &regval);
  250. if (err) {
  251. dev_warn(&reg->dev,
  252. "failed to get regulator register %02x\n",
  253. abreg->regreg);
  254. return err;
  255. }
  256. /* The highest three bits control the variable regulators */
  257. regval &= ~0xE0;
  258. regval |= (selector << 5);
  259. err = abx500_set_register_interruptible(abreg->dev, 0,
  260. abreg->regreg, regval);
  261. if (err)
  262. dev_warn(&reg->dev, "failed to set regulator register %02x\n",
  263. abreg->regreg);
  264. return err;
  265. }
  266. static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg,
  267. int uV)
  268. {
  269. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  270. u8 regval;
  271. int err;
  272. int bestindex;
  273. u8 targetreg;
  274. if (abreg->regreg == AB3100_LDO_E)
  275. targetreg = AB3100_LDO_E_SLEEP;
  276. else if (abreg->regreg == AB3100_BUCK)
  277. targetreg = AB3100_BUCK_SLEEP;
  278. else
  279. return -EINVAL;
  280. /* LDO E and BUCK have special suspend voltages you can set */
  281. bestindex = regulator_map_voltage_iterate(reg, uV, uV);
  282. err = abx500_get_register_interruptible(abreg->dev, 0,
  283. targetreg, &regval);
  284. if (err) {
  285. dev_warn(&reg->dev,
  286. "failed to get regulator register %02x\n",
  287. targetreg);
  288. return err;
  289. }
  290. /* The highest three bits control the variable regulators */
  291. regval &= ~0xE0;
  292. regval |= (bestindex << 5);
  293. err = abx500_set_register_interruptible(abreg->dev, 0,
  294. targetreg, regval);
  295. if (err)
  296. dev_warn(&reg->dev, "failed to set regulator register %02x\n",
  297. abreg->regreg);
  298. return err;
  299. }
  300. /*
  301. * The external regulator can just define a fixed voltage.
  302. */
  303. static int ab3100_get_voltage_regulator_external(struct regulator_dev *reg)
  304. {
  305. struct ab3100_regulator *abreg = rdev_get_drvdata(reg);
  306. if (abreg->plfdata)
  307. return abreg->plfdata->external_voltage;
  308. else
  309. /* TODO: encode external voltage into device tree */
  310. return 0;
  311. }
  312. static const struct regulator_ops regulator_ops_fixed = {
  313. .enable = ab3100_enable_regulator,
  314. .disable = ab3100_disable_regulator,
  315. .is_enabled = ab3100_is_enabled_regulator,
  316. };
  317. static const struct regulator_ops regulator_ops_variable = {
  318. .enable = ab3100_enable_regulator,
  319. .disable = ab3100_disable_regulator,
  320. .is_enabled = ab3100_is_enabled_regulator,
  321. .get_voltage = ab3100_get_voltage_regulator,
  322. .set_voltage_sel = ab3100_set_voltage_regulator_sel,
  323. .list_voltage = regulator_list_voltage_table,
  324. };
  325. static const struct regulator_ops regulator_ops_variable_sleepable = {
  326. .enable = ab3100_enable_regulator,
  327. .disable = ab3100_disable_regulator,
  328. .is_enabled = ab3100_is_enabled_regulator,
  329. .get_voltage = ab3100_get_voltage_regulator,
  330. .set_voltage_sel = ab3100_set_voltage_regulator_sel,
  331. .set_suspend_voltage = ab3100_set_suspend_voltage_regulator,
  332. .list_voltage = regulator_list_voltage_table,
  333. };
  334. /*
  335. * LDO EXT is an external regulator so it is really
  336. * not possible to set any voltage locally here, AB3100
  337. * is an on/off switch plain an simple. The external
  338. * voltage is defined in the board set-up if any.
  339. */
  340. static const struct regulator_ops regulator_ops_external = {
  341. .enable = ab3100_enable_regulator,
  342. .disable = ab3100_disable_regulator,
  343. .is_enabled = ab3100_is_enabled_regulator,
  344. .get_voltage = ab3100_get_voltage_regulator_external,
  345. };
  346. static const struct regulator_desc
  347. ab3100_regulator_desc[AB3100_NUM_REGULATORS] = {
  348. {
  349. .name = "LDO_A",
  350. .id = AB3100_LDO_A,
  351. .ops = &regulator_ops_fixed,
  352. .n_voltages = 1,
  353. .type = REGULATOR_VOLTAGE,
  354. .owner = THIS_MODULE,
  355. .fixed_uV = LDO_A_VOLTAGE,
  356. .enable_time = 200,
  357. },
  358. {
  359. .name = "LDO_C",
  360. .id = AB3100_LDO_C,
  361. .ops = &regulator_ops_fixed,
  362. .n_voltages = 1,
  363. .type = REGULATOR_VOLTAGE,
  364. .owner = THIS_MODULE,
  365. .fixed_uV = LDO_C_VOLTAGE,
  366. .enable_time = 200,
  367. },
  368. {
  369. .name = "LDO_D",
  370. .id = AB3100_LDO_D,
  371. .ops = &regulator_ops_fixed,
  372. .n_voltages = 1,
  373. .type = REGULATOR_VOLTAGE,
  374. .owner = THIS_MODULE,
  375. .fixed_uV = LDO_D_VOLTAGE,
  376. .enable_time = 200,
  377. },
  378. {
  379. .name = "LDO_E",
  380. .id = AB3100_LDO_E,
  381. .ops = &regulator_ops_variable_sleepable,
  382. .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
  383. .volt_table = ldo_e_buck_typ_voltages,
  384. .type = REGULATOR_VOLTAGE,
  385. .owner = THIS_MODULE,
  386. .enable_time = 200,
  387. },
  388. {
  389. .name = "LDO_F",
  390. .id = AB3100_LDO_F,
  391. .ops = &regulator_ops_variable,
  392. .n_voltages = ARRAY_SIZE(ldo_f_typ_voltages),
  393. .volt_table = ldo_f_typ_voltages,
  394. .type = REGULATOR_VOLTAGE,
  395. .owner = THIS_MODULE,
  396. .enable_time = 600,
  397. },
  398. {
  399. .name = "LDO_G",
  400. .id = AB3100_LDO_G,
  401. .ops = &regulator_ops_variable,
  402. .n_voltages = ARRAY_SIZE(ldo_g_typ_voltages),
  403. .volt_table = ldo_g_typ_voltages,
  404. .type = REGULATOR_VOLTAGE,
  405. .owner = THIS_MODULE,
  406. .enable_time = 400,
  407. },
  408. {
  409. .name = "LDO_H",
  410. .id = AB3100_LDO_H,
  411. .ops = &regulator_ops_variable,
  412. .n_voltages = ARRAY_SIZE(ldo_h_typ_voltages),
  413. .volt_table = ldo_h_typ_voltages,
  414. .type = REGULATOR_VOLTAGE,
  415. .owner = THIS_MODULE,
  416. .enable_time = 200,
  417. },
  418. {
  419. .name = "LDO_K",
  420. .id = AB3100_LDO_K,
  421. .ops = &regulator_ops_variable,
  422. .n_voltages = ARRAY_SIZE(ldo_k_typ_voltages),
  423. .volt_table = ldo_k_typ_voltages,
  424. .type = REGULATOR_VOLTAGE,
  425. .owner = THIS_MODULE,
  426. .enable_time = 200,
  427. },
  428. {
  429. .name = "LDO_EXT",
  430. .id = AB3100_LDO_EXT,
  431. .ops = &regulator_ops_external,
  432. .type = REGULATOR_VOLTAGE,
  433. .owner = THIS_MODULE,
  434. },
  435. {
  436. .name = "BUCK",
  437. .id = AB3100_BUCK,
  438. .ops = &regulator_ops_variable_sleepable,
  439. .n_voltages = ARRAY_SIZE(ldo_e_buck_typ_voltages),
  440. .volt_table = ldo_e_buck_typ_voltages,
  441. .type = REGULATOR_VOLTAGE,
  442. .owner = THIS_MODULE,
  443. .enable_time = 1000,
  444. },
  445. };
  446. static int ab3100_regulator_register(struct platform_device *pdev,
  447. struct ab3100_platform_data *plfdata,
  448. struct regulator_init_data *init_data,
  449. struct device_node *np,
  450. unsigned long id)
  451. {
  452. const struct regulator_desc *desc;
  453. struct ab3100_regulator *reg;
  454. struct regulator_dev *rdev;
  455. struct regulator_config config = { };
  456. int err, i;
  457. for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
  458. desc = &ab3100_regulator_desc[i];
  459. if (desc->id == id)
  460. break;
  461. }
  462. if (desc->id != id)
  463. return -ENODEV;
  464. /* Same index used for this array */
  465. reg = &ab3100_regulators[i];
  466. /*
  467. * Initialize per-regulator struct.
  468. * Inherit platform data, this comes down from the
  469. * i2c boarddata, from the machine. So if you want to
  470. * see what it looks like for a certain machine, go
  471. * into the machine I2C setup.
  472. */
  473. reg->dev = &pdev->dev;
  474. if (plfdata) {
  475. reg->plfdata = plfdata;
  476. config.init_data = &plfdata->reg_constraints[i];
  477. } else if (np) {
  478. config.of_node = np;
  479. config.init_data = init_data;
  480. }
  481. config.dev = &pdev->dev;
  482. config.driver_data = reg;
  483. rdev = devm_regulator_register(&pdev->dev, desc, &config);
  484. if (IS_ERR(rdev)) {
  485. err = PTR_ERR(rdev);
  486. dev_err(&pdev->dev,
  487. "%s: failed to register regulator %s err %d\n",
  488. __func__, desc->name,
  489. err);
  490. return err;
  491. }
  492. return 0;
  493. }
  494. static struct of_regulator_match ab3100_regulator_matches[] = {
  495. { .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, },
  496. { .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, },
  497. { .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, },
  498. { .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, },
  499. { .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F },
  500. { .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G },
  501. { .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H },
  502. { .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K },
  503. { .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT },
  504. { .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK },
  505. };
  506. /*
  507. * Initial settings of ab3100 registers.
  508. * Common for below LDO regulator settings are that
  509. * bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0).
  510. * Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode.
  511. */
  512. /* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */
  513. #define LDO_A_SETTING 0x16
  514. /* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */
  515. #define LDO_C_SETTING 0x10
  516. /* LDO_D 0x10: 2.65V, ON, sleep mode not used */
  517. #define LDO_D_SETTING 0x10
  518. /* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */
  519. #define LDO_E_SETTING 0x10
  520. /* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */
  521. #define LDO_E_SLEEP_SETTING 0x00
  522. /* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */
  523. #define LDO_F_SETTING 0xD0
  524. /* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */
  525. #define LDO_G_SETTING 0x00
  526. /* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */
  527. #define LDO_H_SETTING 0x18
  528. /* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */
  529. #define LDO_K_SETTING 0x00
  530. /* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */
  531. #define LDO_EXT_SETTING 0x00
  532. /* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */
  533. #define BUCK_SETTING 0x7D
  534. /* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */
  535. #define BUCK_SLEEP_SETTING 0xAC
  536. static const u8 ab3100_reg_initvals[] = {
  537. LDO_A_SETTING,
  538. LDO_C_SETTING,
  539. LDO_E_SETTING,
  540. LDO_E_SLEEP_SETTING,
  541. LDO_F_SETTING,
  542. LDO_G_SETTING,
  543. LDO_H_SETTING,
  544. LDO_K_SETTING,
  545. LDO_EXT_SETTING,
  546. BUCK_SETTING,
  547. BUCK_SLEEP_SETTING,
  548. LDO_D_SETTING,
  549. };
  550. static int
  551. ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
  552. {
  553. int err, i;
  554. /*
  555. * Set up the regulator registers, as was previously done with
  556. * platform data.
  557. */
  558. /* Set up regulators */
  559. for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
  560. err = abx500_set_register_interruptible(&pdev->dev, 0,
  561. ab3100_reg_init_order[i],
  562. ab3100_reg_initvals[i]);
  563. if (err) {
  564. dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
  565. err);
  566. return err;
  567. }
  568. }
  569. for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) {
  570. err = ab3100_regulator_register(
  571. pdev, NULL, ab3100_regulator_matches[i].init_data,
  572. ab3100_regulator_matches[i].of_node,
  573. (unsigned long)ab3100_regulator_matches[i].driver_data);
  574. if (err)
  575. return err;
  576. }
  577. return 0;
  578. }
  579. static int ab3100_regulators_probe(struct platform_device *pdev)
  580. {
  581. struct ab3100_platform_data *plfdata = dev_get_platdata(&pdev->dev);
  582. struct device_node *np = pdev->dev.of_node;
  583. int err = 0;
  584. u8 data;
  585. int i;
  586. /* Check chip state */
  587. err = abx500_get_register_interruptible(&pdev->dev, 0,
  588. AB3100_LDO_D, &data);
  589. if (err) {
  590. dev_err(&pdev->dev, "could not read initial status of LDO_D\n");
  591. return err;
  592. }
  593. if (data & 0x10)
  594. dev_notice(&pdev->dev,
  595. "chip is already in active mode (Warm start)\n");
  596. else
  597. dev_notice(&pdev->dev,
  598. "chip is in inactive mode (Cold start)\n");
  599. if (np) {
  600. err = of_regulator_match(&pdev->dev, np,
  601. ab3100_regulator_matches,
  602. ARRAY_SIZE(ab3100_regulator_matches));
  603. if (err < 0) {
  604. dev_err(&pdev->dev,
  605. "Error parsing regulator init data: %d\n", err);
  606. return err;
  607. }
  608. return ab3100_regulator_of_probe(pdev, np);
  609. }
  610. /* Set up regulators */
  611. for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) {
  612. err = abx500_set_register_interruptible(&pdev->dev, 0,
  613. ab3100_reg_init_order[i],
  614. plfdata->reg_initvals[i]);
  615. if (err) {
  616. dev_err(&pdev->dev, "regulator initialization failed with error %d\n",
  617. err);
  618. return err;
  619. }
  620. }
  621. /* Register the regulators */
  622. for (i = 0; i < AB3100_NUM_REGULATORS; i++) {
  623. const struct regulator_desc *desc = &ab3100_regulator_desc[i];
  624. err = ab3100_regulator_register(pdev, plfdata, NULL, NULL,
  625. desc->id);
  626. if (err)
  627. return err;
  628. }
  629. return 0;
  630. }
  631. static struct platform_driver ab3100_regulators_driver = {
  632. .driver = {
  633. .name = "ab3100-regulators",
  634. },
  635. .probe = ab3100_regulators_probe,
  636. };
  637. static __init int ab3100_regulators_init(void)
  638. {
  639. return platform_driver_register(&ab3100_regulators_driver);
  640. }
  641. static __exit void ab3100_regulators_exit(void)
  642. {
  643. platform_driver_unregister(&ab3100_regulators_driver);
  644. }
  645. subsys_initcall(ab3100_regulators_init);
  646. module_exit(ab3100_regulators_exit);
  647. MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
  648. MODULE_DESCRIPTION("AB3100 Regulator driver");
  649. MODULE_LICENSE("GPL");
  650. MODULE_ALIAS("platform:ab3100-regulators");