ab8500.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License Terms: GNU General Public License v2
  5. *
  6. * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
  7. * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
  8. *
  9. * AB8500 peripheral regulators
  10. *
  11. * AB8500 supports the following regulators:
  12. * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
  13. */
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/err.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/mfd/abx500.h>
  20. #include <linux/mfd/abx500/ab8500.h>
  21. #include <linux/of.h>
  22. #include <linux/regulator/of_regulator.h>
  23. #include <linux/regulator/driver.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/regulator/ab8500.h>
  26. #include <linux/slab.h>
  27. /**
  28. * struct ab8500_regulator_info - ab8500 regulator information
  29. * @dev: device pointer
  30. * @desc: regulator description
  31. * @regulator_dev: regulator device
  32. * @update_bank: bank to control on/off
  33. * @update_reg: register to control on/off
  34. * @update_mask: mask to enable/disable regulator
  35. * @update_val_enable: bits to enable the regulator in normal (high power) mode
  36. * @voltage_bank: bank to control regulator voltage
  37. * @voltage_reg: register to control regulator voltage
  38. * @voltage_mask: mask to control regulator voltage
  39. * @delay: startup/set voltage delay in us
  40. */
  41. struct ab8500_regulator_info {
  42. struct device *dev;
  43. struct regulator_desc desc;
  44. struct regulator_dev *regulator;
  45. u8 update_bank;
  46. u8 update_reg;
  47. u8 update_mask;
  48. u8 update_val_enable;
  49. u8 voltage_bank;
  50. u8 voltage_reg;
  51. u8 voltage_mask;
  52. unsigned int delay;
  53. };
  54. /* voltage tables for the vauxn/vintcore supplies */
  55. static const unsigned int ldo_vauxn_voltages[] = {
  56. 1100000,
  57. 1200000,
  58. 1300000,
  59. 1400000,
  60. 1500000,
  61. 1800000,
  62. 1850000,
  63. 1900000,
  64. 2500000,
  65. 2650000,
  66. 2700000,
  67. 2750000,
  68. 2800000,
  69. 2900000,
  70. 3000000,
  71. 3300000,
  72. };
  73. static const unsigned int ldo_vaux3_voltages[] = {
  74. 1200000,
  75. 1500000,
  76. 1800000,
  77. 2100000,
  78. 2500000,
  79. 2750000,
  80. 2790000,
  81. 2910000,
  82. };
  83. static const unsigned int ldo_vintcore_voltages[] = {
  84. 1200000,
  85. 1225000,
  86. 1250000,
  87. 1275000,
  88. 1300000,
  89. 1325000,
  90. 1350000,
  91. };
  92. static int ab8500_regulator_enable(struct regulator_dev *rdev)
  93. {
  94. int ret;
  95. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  96. if (info == NULL) {
  97. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  98. return -EINVAL;
  99. }
  100. ret = abx500_mask_and_set_register_interruptible(info->dev,
  101. info->update_bank, info->update_reg,
  102. info->update_mask, info->update_val_enable);
  103. if (ret < 0)
  104. dev_err(rdev_get_dev(rdev),
  105. "couldn't set enable bits for regulator\n");
  106. dev_vdbg(rdev_get_dev(rdev),
  107. "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
  108. info->desc.name, info->update_bank, info->update_reg,
  109. info->update_mask, info->update_val_enable);
  110. return ret;
  111. }
  112. static int ab8500_regulator_disable(struct regulator_dev *rdev)
  113. {
  114. int ret;
  115. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  116. if (info == NULL) {
  117. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  118. return -EINVAL;
  119. }
  120. ret = abx500_mask_and_set_register_interruptible(info->dev,
  121. info->update_bank, info->update_reg,
  122. info->update_mask, 0x0);
  123. if (ret < 0)
  124. dev_err(rdev_get_dev(rdev),
  125. "couldn't set disable bits for regulator\n");
  126. dev_vdbg(rdev_get_dev(rdev),
  127. "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
  128. info->desc.name, info->update_bank, info->update_reg,
  129. info->update_mask, 0x0);
  130. return ret;
  131. }
  132. static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
  133. {
  134. int ret;
  135. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  136. u8 regval;
  137. if (info == NULL) {
  138. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  139. return -EINVAL;
  140. }
  141. ret = abx500_get_register_interruptible(info->dev,
  142. info->update_bank, info->update_reg, &regval);
  143. if (ret < 0) {
  144. dev_err(rdev_get_dev(rdev),
  145. "couldn't read 0x%x register\n", info->update_reg);
  146. return ret;
  147. }
  148. dev_vdbg(rdev_get_dev(rdev),
  149. "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  150. " 0x%x\n",
  151. info->desc.name, info->update_bank, info->update_reg,
  152. info->update_mask, regval);
  153. if (regval & info->update_mask)
  154. return true;
  155. else
  156. return false;
  157. }
  158. static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
  159. {
  160. int ret, val;
  161. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  162. u8 regval;
  163. if (info == NULL) {
  164. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  165. return -EINVAL;
  166. }
  167. ret = abx500_get_register_interruptible(info->dev,
  168. info->voltage_bank, info->voltage_reg, &regval);
  169. if (ret < 0) {
  170. dev_err(rdev_get_dev(rdev),
  171. "couldn't read voltage reg for regulator\n");
  172. return ret;
  173. }
  174. dev_vdbg(rdev_get_dev(rdev),
  175. "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  176. " 0x%x\n",
  177. info->desc.name, info->voltage_bank, info->voltage_reg,
  178. info->voltage_mask, regval);
  179. /* vintcore has a different layout */
  180. val = regval & info->voltage_mask;
  181. if (info->desc.id == AB8500_LDO_INTCORE)
  182. return val >> 0x3;
  183. else
  184. return val;
  185. }
  186. static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
  187. unsigned selector)
  188. {
  189. int ret;
  190. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  191. u8 regval;
  192. if (info == NULL) {
  193. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  194. return -EINVAL;
  195. }
  196. /* set the registers for the request */
  197. regval = (u8)selector;
  198. ret = abx500_mask_and_set_register_interruptible(info->dev,
  199. info->voltage_bank, info->voltage_reg,
  200. info->voltage_mask, regval);
  201. if (ret < 0)
  202. dev_err(rdev_get_dev(rdev),
  203. "couldn't set voltage reg for regulator\n");
  204. dev_vdbg(rdev_get_dev(rdev),
  205. "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  206. " 0x%x\n",
  207. info->desc.name, info->voltage_bank, info->voltage_reg,
  208. info->voltage_mask, regval);
  209. return ret;
  210. }
  211. static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  212. unsigned int old_sel,
  213. unsigned int new_sel)
  214. {
  215. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  216. return info->delay;
  217. }
  218. static struct regulator_ops ab8500_regulator_ops = {
  219. .enable = ab8500_regulator_enable,
  220. .disable = ab8500_regulator_disable,
  221. .is_enabled = ab8500_regulator_is_enabled,
  222. .get_voltage_sel = ab8500_regulator_get_voltage_sel,
  223. .set_voltage_sel = ab8500_regulator_set_voltage_sel,
  224. .list_voltage = regulator_list_voltage_table,
  225. .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
  226. };
  227. static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
  228. {
  229. return rdev->desc->min_uV;
  230. }
  231. static struct regulator_ops ab8500_regulator_fixed_ops = {
  232. .enable = ab8500_regulator_enable,
  233. .disable = ab8500_regulator_disable,
  234. .is_enabled = ab8500_regulator_is_enabled,
  235. .get_voltage = ab8500_fixed_get_voltage,
  236. .list_voltage = regulator_list_voltage_linear,
  237. };
  238. static struct ab8500_regulator_info
  239. ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
  240. /*
  241. * Variable Voltage Regulators
  242. * name, min mV, max mV,
  243. * update bank, reg, mask, enable val
  244. * volt bank, reg, mask
  245. */
  246. [AB8500_LDO_AUX1] = {
  247. .desc = {
  248. .name = "LDO-AUX1",
  249. .ops = &ab8500_regulator_ops,
  250. .type = REGULATOR_VOLTAGE,
  251. .id = AB8500_LDO_AUX1,
  252. .owner = THIS_MODULE,
  253. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  254. .volt_table = ldo_vauxn_voltages,
  255. },
  256. .update_bank = 0x04,
  257. .update_reg = 0x09,
  258. .update_mask = 0x03,
  259. .update_val_enable = 0x01,
  260. .voltage_bank = 0x04,
  261. .voltage_reg = 0x1f,
  262. .voltage_mask = 0x0f,
  263. },
  264. [AB8500_LDO_AUX2] = {
  265. .desc = {
  266. .name = "LDO-AUX2",
  267. .ops = &ab8500_regulator_ops,
  268. .type = REGULATOR_VOLTAGE,
  269. .id = AB8500_LDO_AUX2,
  270. .owner = THIS_MODULE,
  271. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  272. .volt_table = ldo_vauxn_voltages,
  273. },
  274. .update_bank = 0x04,
  275. .update_reg = 0x09,
  276. .update_mask = 0x0c,
  277. .update_val_enable = 0x04,
  278. .voltage_bank = 0x04,
  279. .voltage_reg = 0x20,
  280. .voltage_mask = 0x0f,
  281. },
  282. [AB8500_LDO_AUX3] = {
  283. .desc = {
  284. .name = "LDO-AUX3",
  285. .ops = &ab8500_regulator_ops,
  286. .type = REGULATOR_VOLTAGE,
  287. .id = AB8500_LDO_AUX3,
  288. .owner = THIS_MODULE,
  289. .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
  290. .volt_table = ldo_vaux3_voltages,
  291. },
  292. .update_bank = 0x04,
  293. .update_reg = 0x0a,
  294. .update_mask = 0x03,
  295. .update_val_enable = 0x01,
  296. .voltage_bank = 0x04,
  297. .voltage_reg = 0x21,
  298. .voltage_mask = 0x07,
  299. },
  300. [AB8500_LDO_INTCORE] = {
  301. .desc = {
  302. .name = "LDO-INTCORE",
  303. .ops = &ab8500_regulator_ops,
  304. .type = REGULATOR_VOLTAGE,
  305. .id = AB8500_LDO_INTCORE,
  306. .owner = THIS_MODULE,
  307. .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
  308. .volt_table = ldo_vintcore_voltages,
  309. },
  310. .update_bank = 0x03,
  311. .update_reg = 0x80,
  312. .update_mask = 0x44,
  313. .update_val_enable = 0x04,
  314. .voltage_bank = 0x03,
  315. .voltage_reg = 0x80,
  316. .voltage_mask = 0x38,
  317. },
  318. /*
  319. * Fixed Voltage Regulators
  320. * name, fixed mV,
  321. * update bank, reg, mask, enable val
  322. */
  323. [AB8500_LDO_TVOUT] = {
  324. .desc = {
  325. .name = "LDO-TVOUT",
  326. .ops = &ab8500_regulator_fixed_ops,
  327. .type = REGULATOR_VOLTAGE,
  328. .id = AB8500_LDO_TVOUT,
  329. .owner = THIS_MODULE,
  330. .n_voltages = 1,
  331. .min_uV = 2000000,
  332. .enable_time = 10000,
  333. },
  334. .delay = 10000,
  335. .update_bank = 0x03,
  336. .update_reg = 0x80,
  337. .update_mask = 0x82,
  338. .update_val_enable = 0x02,
  339. },
  340. [AB8500_LDO_USB] = {
  341. .desc = {
  342. .name = "LDO-USB",
  343. .ops = &ab8500_regulator_fixed_ops,
  344. .type = REGULATOR_VOLTAGE,
  345. .id = AB8500_LDO_USB,
  346. .owner = THIS_MODULE,
  347. .n_voltages = 1,
  348. .min_uV = 3300000,
  349. },
  350. .update_bank = 0x03,
  351. .update_reg = 0x82,
  352. .update_mask = 0x03,
  353. .update_val_enable = 0x01,
  354. },
  355. [AB8500_LDO_AUDIO] = {
  356. .desc = {
  357. .name = "LDO-AUDIO",
  358. .ops = &ab8500_regulator_fixed_ops,
  359. .type = REGULATOR_VOLTAGE,
  360. .id = AB8500_LDO_AUDIO,
  361. .owner = THIS_MODULE,
  362. .n_voltages = 1,
  363. .min_uV = 2000000,
  364. },
  365. .update_bank = 0x03,
  366. .update_reg = 0x83,
  367. .update_mask = 0x02,
  368. .update_val_enable = 0x02,
  369. },
  370. [AB8500_LDO_ANAMIC1] = {
  371. .desc = {
  372. .name = "LDO-ANAMIC1",
  373. .ops = &ab8500_regulator_fixed_ops,
  374. .type = REGULATOR_VOLTAGE,
  375. .id = AB8500_LDO_ANAMIC1,
  376. .owner = THIS_MODULE,
  377. .n_voltages = 1,
  378. .min_uV = 2050000,
  379. },
  380. .update_bank = 0x03,
  381. .update_reg = 0x83,
  382. .update_mask = 0x08,
  383. .update_val_enable = 0x08,
  384. },
  385. [AB8500_LDO_ANAMIC2] = {
  386. .desc = {
  387. .name = "LDO-ANAMIC2",
  388. .ops = &ab8500_regulator_fixed_ops,
  389. .type = REGULATOR_VOLTAGE,
  390. .id = AB8500_LDO_ANAMIC2,
  391. .owner = THIS_MODULE,
  392. .n_voltages = 1,
  393. .min_uV = 2050000,
  394. },
  395. .update_bank = 0x03,
  396. .update_reg = 0x83,
  397. .update_mask = 0x10,
  398. .update_val_enable = 0x10,
  399. },
  400. [AB8500_LDO_DMIC] = {
  401. .desc = {
  402. .name = "LDO-DMIC",
  403. .ops = &ab8500_regulator_fixed_ops,
  404. .type = REGULATOR_VOLTAGE,
  405. .id = AB8500_LDO_DMIC,
  406. .owner = THIS_MODULE,
  407. .n_voltages = 1,
  408. .min_uV = 1800000,
  409. },
  410. .update_bank = 0x03,
  411. .update_reg = 0x83,
  412. .update_mask = 0x04,
  413. .update_val_enable = 0x04,
  414. },
  415. [AB8500_LDO_ANA] = {
  416. .desc = {
  417. .name = "LDO-ANA",
  418. .ops = &ab8500_regulator_fixed_ops,
  419. .type = REGULATOR_VOLTAGE,
  420. .id = AB8500_LDO_ANA,
  421. .owner = THIS_MODULE,
  422. .n_voltages = 1,
  423. .min_uV = 1200000,
  424. },
  425. .update_bank = 0x04,
  426. .update_reg = 0x06,
  427. .update_mask = 0x0c,
  428. .update_val_enable = 0x04,
  429. },
  430. };
  431. struct ab8500_reg_init {
  432. u8 bank;
  433. u8 addr;
  434. u8 mask;
  435. };
  436. #define REG_INIT(_id, _bank, _addr, _mask) \
  437. [_id] = { \
  438. .bank = _bank, \
  439. .addr = _addr, \
  440. .mask = _mask, \
  441. }
  442. static struct ab8500_reg_init ab8500_reg_init[] = {
  443. /*
  444. * 0x30, VanaRequestCtrl
  445. * 0x0C, VpllRequestCtrl
  446. * 0xc0, VextSupply1RequestCtrl
  447. */
  448. REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
  449. /*
  450. * 0x03, VextSupply2RequestCtrl
  451. * 0x0c, VextSupply3RequestCtrl
  452. * 0x30, Vaux1RequestCtrl
  453. * 0xc0, Vaux2RequestCtrl
  454. */
  455. REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
  456. /*
  457. * 0x03, Vaux3RequestCtrl
  458. * 0x04, SwHPReq
  459. */
  460. REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
  461. /*
  462. * 0x08, VanaSysClkReq1HPValid
  463. * 0x20, Vaux1SysClkReq1HPValid
  464. * 0x40, Vaux2SysClkReq1HPValid
  465. * 0x80, Vaux3SysClkReq1HPValid
  466. */
  467. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
  468. /*
  469. * 0x10, VextSupply1SysClkReq1HPValid
  470. * 0x20, VextSupply2SysClkReq1HPValid
  471. * 0x40, VextSupply3SysClkReq1HPValid
  472. */
  473. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
  474. /*
  475. * 0x08, VanaHwHPReq1Valid
  476. * 0x20, Vaux1HwHPReq1Valid
  477. * 0x40, Vaux2HwHPReq1Valid
  478. * 0x80, Vaux3HwHPReq1Valid
  479. */
  480. REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
  481. /*
  482. * 0x01, VextSupply1HwHPReq1Valid
  483. * 0x02, VextSupply2HwHPReq1Valid
  484. * 0x04, VextSupply3HwHPReq1Valid
  485. */
  486. REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
  487. /*
  488. * 0x08, VanaHwHPReq2Valid
  489. * 0x20, Vaux1HwHPReq2Valid
  490. * 0x40, Vaux2HwHPReq2Valid
  491. * 0x80, Vaux3HwHPReq2Valid
  492. */
  493. REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
  494. /*
  495. * 0x01, VextSupply1HwHPReq2Valid
  496. * 0x02, VextSupply2HwHPReq2Valid
  497. * 0x04, VextSupply3HwHPReq2Valid
  498. */
  499. REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
  500. /*
  501. * 0x20, VanaSwHPReqValid
  502. * 0x80, Vaux1SwHPReqValid
  503. */
  504. REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
  505. /*
  506. * 0x01, Vaux2SwHPReqValid
  507. * 0x02, Vaux3SwHPReqValid
  508. * 0x04, VextSupply1SwHPReqValid
  509. * 0x08, VextSupply2SwHPReqValid
  510. * 0x10, VextSupply3SwHPReqValid
  511. */
  512. REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
  513. /*
  514. * 0x02, SysClkReq2Valid1
  515. * ...
  516. * 0x80, SysClkReq8Valid1
  517. */
  518. REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
  519. /*
  520. * 0x02, SysClkReq2Valid2
  521. * ...
  522. * 0x80, SysClkReq8Valid2
  523. */
  524. REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
  525. /*
  526. * 0x02, VTVoutEna
  527. * 0x04, Vintcore12Ena
  528. * 0x38, Vintcore12Sel
  529. * 0x40, Vintcore12LP
  530. * 0x80, VTVoutLP
  531. */
  532. REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
  533. /*
  534. * 0x02, VaudioEna
  535. * 0x04, VdmicEna
  536. * 0x08, Vamic1Ena
  537. * 0x10, Vamic2Ena
  538. */
  539. REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
  540. /*
  541. * 0x01, Vamic1_dzout
  542. * 0x02, Vamic2_dzout
  543. */
  544. REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
  545. /*
  546. * 0x0c, VanaRegu
  547. * 0x03, VpllRegu
  548. */
  549. REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
  550. /*
  551. * 0x01, VrefDDREna
  552. * 0x02, VrefDDRSleepMode
  553. */
  554. REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
  555. /*
  556. * 0x03, VextSupply1Regu
  557. * 0x0c, VextSupply2Regu
  558. * 0x30, VextSupply3Regu
  559. * 0x40, ExtSupply2Bypass
  560. * 0x80, ExtSupply3Bypass
  561. */
  562. REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
  563. /*
  564. * 0x03, Vaux1Regu
  565. * 0x0c, Vaux2Regu
  566. */
  567. REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
  568. /*
  569. * 0x03, Vaux3Regu
  570. */
  571. REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
  572. /*
  573. * 0x3f, Vsmps1Sel1
  574. */
  575. REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
  576. /*
  577. * 0x0f, Vaux1Sel
  578. */
  579. REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
  580. /*
  581. * 0x0f, Vaux2Sel
  582. */
  583. REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
  584. /*
  585. * 0x07, Vaux3Sel
  586. */
  587. REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
  588. /*
  589. * 0x01, VextSupply12LP
  590. */
  591. REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
  592. /*
  593. * 0x04, Vaux1Disch
  594. * 0x08, Vaux2Disch
  595. * 0x10, Vaux3Disch
  596. * 0x20, Vintcore12Disch
  597. * 0x40, VTVoutDisch
  598. * 0x80, VaudioDisch
  599. */
  600. REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
  601. /*
  602. * 0x02, VanaDisch
  603. * 0x04, VdmicPullDownEna
  604. * 0x10, VdmicDisch
  605. */
  606. REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
  607. };
  608. static __devinit int
  609. ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
  610. {
  611. int err;
  612. if (value & ~ab8500_reg_init[id].mask) {
  613. dev_err(&pdev->dev,
  614. "Configuration error: value outside mask.\n");
  615. return -EINVAL;
  616. }
  617. err = abx500_mask_and_set_register_interruptible(
  618. &pdev->dev,
  619. ab8500_reg_init[id].bank,
  620. ab8500_reg_init[id].addr,
  621. ab8500_reg_init[id].mask,
  622. value);
  623. if (err < 0) {
  624. dev_err(&pdev->dev,
  625. "Failed to initialize 0x%02x, 0x%02x.\n",
  626. ab8500_reg_init[id].bank,
  627. ab8500_reg_init[id].addr);
  628. return err;
  629. }
  630. dev_vdbg(&pdev->dev,
  631. "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
  632. ab8500_reg_init[id].bank,
  633. ab8500_reg_init[id].addr,
  634. ab8500_reg_init[id].mask,
  635. value);
  636. return 0;
  637. }
  638. static __devinit int ab8500_regulator_register(struct platform_device *pdev,
  639. struct regulator_init_data *init_data,
  640. int id,
  641. struct device_node *np)
  642. {
  643. struct ab8500_regulator_info *info = NULL;
  644. struct regulator_config config = { };
  645. int err;
  646. /* assign per-regulator data */
  647. info = &ab8500_regulator_info[id];
  648. info->dev = &pdev->dev;
  649. config.dev = &pdev->dev;
  650. config.init_data = init_data;
  651. config.driver_data = info;
  652. config.of_node = np;
  653. /* fix for hardware before ab8500v2.0 */
  654. if (abx500_get_chip_id(info->dev) < 0x20) {
  655. if (info->desc.id == AB8500_LDO_AUX3) {
  656. info->desc.n_voltages =
  657. ARRAY_SIZE(ldo_vauxn_voltages);
  658. info->desc.volt_table = ldo_vauxn_voltages;
  659. info->voltage_mask = 0xf;
  660. }
  661. }
  662. /* register regulator with framework */
  663. info->regulator = regulator_register(&info->desc, &config);
  664. if (IS_ERR(info->regulator)) {
  665. err = PTR_ERR(info->regulator);
  666. dev_err(&pdev->dev, "failed to register regulator %s\n",
  667. info->desc.name);
  668. /* when we fail, un-register all earlier regulators */
  669. while (--id >= 0) {
  670. info = &ab8500_regulator_info[id];
  671. regulator_unregister(info->regulator);
  672. }
  673. return err;
  674. }
  675. return 0;
  676. }
  677. static struct of_regulator_match ab8500_regulator_matches[] = {
  678. { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
  679. { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
  680. { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
  681. { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
  682. { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
  683. { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
  684. { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
  685. { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
  686. { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
  687. { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
  688. { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
  689. };
  690. static __devinit int
  691. ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
  692. {
  693. int err, i;
  694. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  695. err = ab8500_regulator_register(
  696. pdev, ab8500_regulator_matches[i].init_data,
  697. i, ab8500_regulator_matches[i].of_node);
  698. if (err)
  699. return err;
  700. }
  701. return 0;
  702. }
  703. static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
  704. {
  705. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  706. struct ab8500_platform_data *pdata;
  707. struct device_node *np = pdev->dev.of_node;
  708. int i, err;
  709. if (np) {
  710. err = of_regulator_match(&pdev->dev, np,
  711. ab8500_regulator_matches,
  712. ARRAY_SIZE(ab8500_regulator_matches));
  713. if (err < 0) {
  714. dev_err(&pdev->dev,
  715. "Error parsing regulator init data: %d\n", err);
  716. return err;
  717. }
  718. err = ab8500_regulator_of_probe(pdev, np);
  719. return err;
  720. }
  721. if (!ab8500) {
  722. dev_err(&pdev->dev, "null mfd parent\n");
  723. return -EINVAL;
  724. }
  725. pdata = dev_get_platdata(ab8500->dev);
  726. if (!pdata) {
  727. dev_err(&pdev->dev, "null pdata\n");
  728. return -EINVAL;
  729. }
  730. /* make sure the platform data has the correct size */
  731. if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
  732. dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
  733. return -EINVAL;
  734. }
  735. /* initialize registers */
  736. for (i = 0; i < pdata->num_regulator_reg_init; i++) {
  737. int id, value;
  738. id = pdata->regulator_reg_init[i].id;
  739. value = pdata->regulator_reg_init[i].value;
  740. /* check for configuration errors */
  741. if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
  742. dev_err(&pdev->dev,
  743. "Configuration error: id outside range.\n");
  744. return -EINVAL;
  745. }
  746. err = ab8500_regulator_init_registers(pdev, id, value);
  747. if (err < 0)
  748. return err;
  749. }
  750. /* register all regulators */
  751. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  752. err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
  753. if (err < 0)
  754. return err;
  755. }
  756. return 0;
  757. }
  758. static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
  759. {
  760. int i;
  761. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  762. struct ab8500_regulator_info *info = NULL;
  763. info = &ab8500_regulator_info[i];
  764. dev_vdbg(rdev_get_dev(info->regulator),
  765. "%s-remove\n", info->desc.name);
  766. regulator_unregister(info->regulator);
  767. }
  768. return 0;
  769. }
  770. static struct platform_driver ab8500_regulator_driver = {
  771. .probe = ab8500_regulator_probe,
  772. .remove = __devexit_p(ab8500_regulator_remove),
  773. .driver = {
  774. .name = "ab8500-regulator",
  775. .owner = THIS_MODULE,
  776. },
  777. };
  778. static int __init ab8500_regulator_init(void)
  779. {
  780. int ret;
  781. ret = platform_driver_register(&ab8500_regulator_driver);
  782. if (ret != 0)
  783. pr_err("Failed to register ab8500 regulator: %d\n", ret);
  784. return ret;
  785. }
  786. subsys_initcall(ab8500_regulator_init);
  787. static void __exit ab8500_regulator_exit(void)
  788. {
  789. platform_driver_unregister(&ab8500_regulator_driver);
  790. }
  791. module_exit(ab8500_regulator_exit);
  792. MODULE_LICENSE("GPL v2");
  793. MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
  794. MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
  795. MODULE_ALIAS("platform:ab8500-regulator");