ab3100.c 18 KB

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