ab3100.c 17 KB

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