ab8500.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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_enable_time(struct regulator_dev *rdev)
  212. {
  213. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  214. return info->delay;
  215. }
  216. static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  217. unsigned int old_sel,
  218. unsigned int new_sel)
  219. {
  220. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  221. return info->delay;
  222. }
  223. static struct regulator_ops ab8500_regulator_ops = {
  224. .enable = ab8500_regulator_enable,
  225. .disable = ab8500_regulator_disable,
  226. .is_enabled = ab8500_regulator_is_enabled,
  227. .get_voltage_sel = ab8500_regulator_get_voltage_sel,
  228. .set_voltage_sel = ab8500_regulator_set_voltage_sel,
  229. .list_voltage = regulator_list_voltage_table,
  230. .enable_time = ab8500_regulator_enable_time,
  231. .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel,
  232. };
  233. static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
  234. {
  235. return rdev->desc->min_uV;
  236. }
  237. static struct regulator_ops ab8500_regulator_fixed_ops = {
  238. .enable = ab8500_regulator_enable,
  239. .disable = ab8500_regulator_disable,
  240. .is_enabled = ab8500_regulator_is_enabled,
  241. .get_voltage = ab8500_fixed_get_voltage,
  242. .list_voltage = regulator_list_voltage_linear,
  243. .enable_time = ab8500_regulator_enable_time,
  244. };
  245. static struct ab8500_regulator_info
  246. ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
  247. /*
  248. * Variable Voltage Regulators
  249. * name, min mV, max mV,
  250. * update bank, reg, mask, enable val
  251. * volt bank, reg, mask
  252. */
  253. [AB8500_LDO_AUX1] = {
  254. .desc = {
  255. .name = "LDO-AUX1",
  256. .ops = &ab8500_regulator_ops,
  257. .type = REGULATOR_VOLTAGE,
  258. .id = AB8500_LDO_AUX1,
  259. .owner = THIS_MODULE,
  260. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  261. .volt_table = ldo_vauxn_voltages,
  262. },
  263. .update_bank = 0x04,
  264. .update_reg = 0x09,
  265. .update_mask = 0x03,
  266. .update_val_enable = 0x01,
  267. .voltage_bank = 0x04,
  268. .voltage_reg = 0x1f,
  269. .voltage_mask = 0x0f,
  270. },
  271. [AB8500_LDO_AUX2] = {
  272. .desc = {
  273. .name = "LDO-AUX2",
  274. .ops = &ab8500_regulator_ops,
  275. .type = REGULATOR_VOLTAGE,
  276. .id = AB8500_LDO_AUX2,
  277. .owner = THIS_MODULE,
  278. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  279. .volt_table = ldo_vauxn_voltages,
  280. },
  281. .update_bank = 0x04,
  282. .update_reg = 0x09,
  283. .update_mask = 0x0c,
  284. .update_val_enable = 0x04,
  285. .voltage_bank = 0x04,
  286. .voltage_reg = 0x20,
  287. .voltage_mask = 0x0f,
  288. },
  289. [AB8500_LDO_AUX3] = {
  290. .desc = {
  291. .name = "LDO-AUX3",
  292. .ops = &ab8500_regulator_ops,
  293. .type = REGULATOR_VOLTAGE,
  294. .id = AB8500_LDO_AUX3,
  295. .owner = THIS_MODULE,
  296. .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
  297. .volt_table = ldo_vaux3_voltages,
  298. },
  299. .update_bank = 0x04,
  300. .update_reg = 0x0a,
  301. .update_mask = 0x03,
  302. .update_val_enable = 0x01,
  303. .voltage_bank = 0x04,
  304. .voltage_reg = 0x21,
  305. .voltage_mask = 0x07,
  306. },
  307. [AB8500_LDO_INTCORE] = {
  308. .desc = {
  309. .name = "LDO-INTCORE",
  310. .ops = &ab8500_regulator_ops,
  311. .type = REGULATOR_VOLTAGE,
  312. .id = AB8500_LDO_INTCORE,
  313. .owner = THIS_MODULE,
  314. .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
  315. .volt_table = ldo_vintcore_voltages,
  316. },
  317. .update_bank = 0x03,
  318. .update_reg = 0x80,
  319. .update_mask = 0x44,
  320. .update_val_enable = 0x04,
  321. .voltage_bank = 0x03,
  322. .voltage_reg = 0x80,
  323. .voltage_mask = 0x38,
  324. },
  325. /*
  326. * Fixed Voltage Regulators
  327. * name, fixed mV,
  328. * update bank, reg, mask, enable val
  329. */
  330. [AB8500_LDO_TVOUT] = {
  331. .desc = {
  332. .name = "LDO-TVOUT",
  333. .ops = &ab8500_regulator_fixed_ops,
  334. .type = REGULATOR_VOLTAGE,
  335. .id = AB8500_LDO_TVOUT,
  336. .owner = THIS_MODULE,
  337. .n_voltages = 1,
  338. .min_uV = 2000000,
  339. },
  340. .delay = 10000,
  341. .update_bank = 0x03,
  342. .update_reg = 0x80,
  343. .update_mask = 0x82,
  344. .update_val_enable = 0x02,
  345. },
  346. [AB8500_LDO_USB] = {
  347. .desc = {
  348. .name = "LDO-USB",
  349. .ops = &ab8500_regulator_fixed_ops,
  350. .type = REGULATOR_VOLTAGE,
  351. .id = AB8500_LDO_USB,
  352. .owner = THIS_MODULE,
  353. .n_voltages = 1,
  354. .min_uV = 3300000,
  355. },
  356. .update_bank = 0x03,
  357. .update_reg = 0x82,
  358. .update_mask = 0x03,
  359. .update_val_enable = 0x01,
  360. },
  361. [AB8500_LDO_AUDIO] = {
  362. .desc = {
  363. .name = "LDO-AUDIO",
  364. .ops = &ab8500_regulator_fixed_ops,
  365. .type = REGULATOR_VOLTAGE,
  366. .id = AB8500_LDO_AUDIO,
  367. .owner = THIS_MODULE,
  368. .n_voltages = 1,
  369. .min_uV = 2000000,
  370. },
  371. .update_bank = 0x03,
  372. .update_reg = 0x83,
  373. .update_mask = 0x02,
  374. .update_val_enable = 0x02,
  375. },
  376. [AB8500_LDO_ANAMIC1] = {
  377. .desc = {
  378. .name = "LDO-ANAMIC1",
  379. .ops = &ab8500_regulator_fixed_ops,
  380. .type = REGULATOR_VOLTAGE,
  381. .id = AB8500_LDO_ANAMIC1,
  382. .owner = THIS_MODULE,
  383. .n_voltages = 1,
  384. .min_uV = 2050000,
  385. },
  386. .update_bank = 0x03,
  387. .update_reg = 0x83,
  388. .update_mask = 0x08,
  389. .update_val_enable = 0x08,
  390. },
  391. [AB8500_LDO_ANAMIC2] = {
  392. .desc = {
  393. .name = "LDO-ANAMIC2",
  394. .ops = &ab8500_regulator_fixed_ops,
  395. .type = REGULATOR_VOLTAGE,
  396. .id = AB8500_LDO_ANAMIC2,
  397. .owner = THIS_MODULE,
  398. .n_voltages = 1,
  399. .min_uV = 2050000,
  400. },
  401. .update_bank = 0x03,
  402. .update_reg = 0x83,
  403. .update_mask = 0x10,
  404. .update_val_enable = 0x10,
  405. },
  406. [AB8500_LDO_DMIC] = {
  407. .desc = {
  408. .name = "LDO-DMIC",
  409. .ops = &ab8500_regulator_fixed_ops,
  410. .type = REGULATOR_VOLTAGE,
  411. .id = AB8500_LDO_DMIC,
  412. .owner = THIS_MODULE,
  413. .n_voltages = 1,
  414. .min_uV = 1800000,
  415. },
  416. .update_bank = 0x03,
  417. .update_reg = 0x83,
  418. .update_mask = 0x04,
  419. .update_val_enable = 0x04,
  420. },
  421. [AB8500_LDO_ANA] = {
  422. .desc = {
  423. .name = "LDO-ANA",
  424. .ops = &ab8500_regulator_fixed_ops,
  425. .type = REGULATOR_VOLTAGE,
  426. .id = AB8500_LDO_ANA,
  427. .owner = THIS_MODULE,
  428. .n_voltages = 1,
  429. .min_uV = 1200000,
  430. },
  431. .update_bank = 0x04,
  432. .update_reg = 0x06,
  433. .update_mask = 0x0c,
  434. .update_val_enable = 0x04,
  435. },
  436. };
  437. struct ab8500_reg_init {
  438. u8 bank;
  439. u8 addr;
  440. u8 mask;
  441. };
  442. #define REG_INIT(_id, _bank, _addr, _mask) \
  443. [_id] = { \
  444. .bank = _bank, \
  445. .addr = _addr, \
  446. .mask = _mask, \
  447. }
  448. static struct ab8500_reg_init ab8500_reg_init[] = {
  449. /*
  450. * 0x30, VanaRequestCtrl
  451. * 0x0C, VpllRequestCtrl
  452. * 0xc0, VextSupply1RequestCtrl
  453. */
  454. REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc),
  455. /*
  456. * 0x03, VextSupply2RequestCtrl
  457. * 0x0c, VextSupply3RequestCtrl
  458. * 0x30, Vaux1RequestCtrl
  459. * 0xc0, Vaux2RequestCtrl
  460. */
  461. REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
  462. /*
  463. * 0x03, Vaux3RequestCtrl
  464. * 0x04, SwHPReq
  465. */
  466. REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
  467. /*
  468. * 0x08, VanaSysClkReq1HPValid
  469. * 0x20, Vaux1SysClkReq1HPValid
  470. * 0x40, Vaux2SysClkReq1HPValid
  471. * 0x80, Vaux3SysClkReq1HPValid
  472. */
  473. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
  474. /*
  475. * 0x10, VextSupply1SysClkReq1HPValid
  476. * 0x20, VextSupply2SysClkReq1HPValid
  477. * 0x40, VextSupply3SysClkReq1HPValid
  478. */
  479. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
  480. /*
  481. * 0x08, VanaHwHPReq1Valid
  482. * 0x20, Vaux1HwHPReq1Valid
  483. * 0x40, Vaux2HwHPReq1Valid
  484. * 0x80, Vaux3HwHPReq1Valid
  485. */
  486. REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
  487. /*
  488. * 0x01, VextSupply1HwHPReq1Valid
  489. * 0x02, VextSupply2HwHPReq1Valid
  490. * 0x04, VextSupply3HwHPReq1Valid
  491. */
  492. REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
  493. /*
  494. * 0x08, VanaHwHPReq2Valid
  495. * 0x20, Vaux1HwHPReq2Valid
  496. * 0x40, Vaux2HwHPReq2Valid
  497. * 0x80, Vaux3HwHPReq2Valid
  498. */
  499. REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
  500. /*
  501. * 0x01, VextSupply1HwHPReq2Valid
  502. * 0x02, VextSupply2HwHPReq2Valid
  503. * 0x04, VextSupply3HwHPReq2Valid
  504. */
  505. REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
  506. /*
  507. * 0x20, VanaSwHPReqValid
  508. * 0x80, Vaux1SwHPReqValid
  509. */
  510. REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
  511. /*
  512. * 0x01, Vaux2SwHPReqValid
  513. * 0x02, Vaux3SwHPReqValid
  514. * 0x04, VextSupply1SwHPReqValid
  515. * 0x08, VextSupply2SwHPReqValid
  516. * 0x10, VextSupply3SwHPReqValid
  517. */
  518. REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
  519. /*
  520. * 0x02, SysClkReq2Valid1
  521. * ...
  522. * 0x80, SysClkReq8Valid1
  523. */
  524. REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
  525. /*
  526. * 0x02, SysClkReq2Valid2
  527. * ...
  528. * 0x80, SysClkReq8Valid2
  529. */
  530. REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
  531. /*
  532. * 0x02, VTVoutEna
  533. * 0x04, Vintcore12Ena
  534. * 0x38, Vintcore12Sel
  535. * 0x40, Vintcore12LP
  536. * 0x80, VTVoutLP
  537. */
  538. REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
  539. /*
  540. * 0x02, VaudioEna
  541. * 0x04, VdmicEna
  542. * 0x08, Vamic1Ena
  543. * 0x10, Vamic2Ena
  544. */
  545. REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
  546. /*
  547. * 0x01, Vamic1_dzout
  548. * 0x02, Vamic2_dzout
  549. */
  550. REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
  551. /*
  552. * 0x0c, VanaRegu
  553. * 0x03, VpllRegu
  554. */
  555. REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
  556. /*
  557. * 0x01, VrefDDREna
  558. * 0x02, VrefDDRSleepMode
  559. */
  560. REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
  561. /*
  562. * 0x03, VextSupply1Regu
  563. * 0x0c, VextSupply2Regu
  564. * 0x30, VextSupply3Regu
  565. * 0x40, ExtSupply2Bypass
  566. * 0x80, ExtSupply3Bypass
  567. */
  568. REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
  569. /*
  570. * 0x03, Vaux1Regu
  571. * 0x0c, Vaux2Regu
  572. */
  573. REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
  574. /*
  575. * 0x03, Vaux3Regu
  576. */
  577. REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
  578. /*
  579. * 0x3f, Vsmps1Sel1
  580. */
  581. REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f),
  582. /*
  583. * 0x0f, Vaux1Sel
  584. */
  585. REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
  586. /*
  587. * 0x0f, Vaux2Sel
  588. */
  589. REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
  590. /*
  591. * 0x07, Vaux3Sel
  592. */
  593. REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
  594. /*
  595. * 0x01, VextSupply12LP
  596. */
  597. REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
  598. /*
  599. * 0x04, Vaux1Disch
  600. * 0x08, Vaux2Disch
  601. * 0x10, Vaux3Disch
  602. * 0x20, Vintcore12Disch
  603. * 0x40, VTVoutDisch
  604. * 0x80, VaudioDisch
  605. */
  606. REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
  607. /*
  608. * 0x02, VanaDisch
  609. * 0x04, VdmicPullDownEna
  610. * 0x10, VdmicDisch
  611. */
  612. REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
  613. };
  614. static __devinit int
  615. ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
  616. {
  617. int err;
  618. if (value & ~ab8500_reg_init[id].mask) {
  619. dev_err(&pdev->dev,
  620. "Configuration error: value outside mask.\n");
  621. return -EINVAL;
  622. }
  623. err = abx500_mask_and_set_register_interruptible(
  624. &pdev->dev,
  625. ab8500_reg_init[id].bank,
  626. ab8500_reg_init[id].addr,
  627. ab8500_reg_init[id].mask,
  628. value);
  629. if (err < 0) {
  630. dev_err(&pdev->dev,
  631. "Failed to initialize 0x%02x, 0x%02x.\n",
  632. ab8500_reg_init[id].bank,
  633. ab8500_reg_init[id].addr);
  634. return err;
  635. }
  636. dev_vdbg(&pdev->dev,
  637. "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
  638. ab8500_reg_init[id].bank,
  639. ab8500_reg_init[id].addr,
  640. ab8500_reg_init[id].mask,
  641. value);
  642. return 0;
  643. }
  644. static __devinit int ab8500_regulator_register(struct platform_device *pdev,
  645. struct regulator_init_data *init_data,
  646. int id,
  647. struct device_node *np)
  648. {
  649. struct ab8500_regulator_info *info = NULL;
  650. struct regulator_config config = { };
  651. int err;
  652. /* assign per-regulator data */
  653. info = &ab8500_regulator_info[id];
  654. info->dev = &pdev->dev;
  655. config.dev = &pdev->dev;
  656. config.init_data = init_data;
  657. config.driver_data = info;
  658. config.of_node = np;
  659. /* fix for hardware before ab8500v2.0 */
  660. if (abx500_get_chip_id(info->dev) < 0x20) {
  661. if (info->desc.id == AB8500_LDO_AUX3) {
  662. info->desc.n_voltages =
  663. ARRAY_SIZE(ldo_vauxn_voltages);
  664. info->desc.volt_table = ldo_vauxn_voltages;
  665. info->voltage_mask = 0xf;
  666. }
  667. }
  668. /* register regulator with framework */
  669. info->regulator = regulator_register(&info->desc, &config);
  670. if (IS_ERR(info->regulator)) {
  671. err = PTR_ERR(info->regulator);
  672. dev_err(&pdev->dev, "failed to register regulator %s\n",
  673. info->desc.name);
  674. /* when we fail, un-register all earlier regulators */
  675. while (--id >= 0) {
  676. info = &ab8500_regulator_info[id];
  677. regulator_unregister(info->regulator);
  678. }
  679. return err;
  680. }
  681. return 0;
  682. }
  683. static struct of_regulator_match ab8500_regulator_matches[] = {
  684. { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
  685. { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
  686. { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
  687. { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
  688. { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
  689. { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, },
  690. { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
  691. { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
  692. { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
  693. { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
  694. { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
  695. };
  696. static __devinit int
  697. ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np)
  698. {
  699. int err, i;
  700. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  701. err = ab8500_regulator_register(
  702. pdev, ab8500_regulator_matches[i].init_data,
  703. i, ab8500_regulator_matches[i].of_node);
  704. if (err)
  705. return err;
  706. }
  707. return 0;
  708. }
  709. static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
  710. {
  711. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  712. struct ab8500_platform_data *pdata;
  713. struct device_node *np = pdev->dev.of_node;
  714. int i, err;
  715. if (np) {
  716. err = of_regulator_match(&pdev->dev, np,
  717. ab8500_regulator_matches,
  718. ARRAY_SIZE(ab8500_regulator_matches));
  719. if (err < 0) {
  720. dev_err(&pdev->dev,
  721. "Error parsing regulator init data: %d\n", err);
  722. return err;
  723. }
  724. err = ab8500_regulator_of_probe(pdev, np);
  725. return err;
  726. }
  727. if (!ab8500) {
  728. dev_err(&pdev->dev, "null mfd parent\n");
  729. return -EINVAL;
  730. }
  731. pdata = dev_get_platdata(ab8500->dev);
  732. if (!pdata) {
  733. dev_err(&pdev->dev, "null pdata\n");
  734. return -EINVAL;
  735. }
  736. /* make sure the platform data has the correct size */
  737. if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
  738. dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
  739. return -EINVAL;
  740. }
  741. /* initialize registers */
  742. for (i = 0; i < pdata->num_regulator_reg_init; i++) {
  743. int id, value;
  744. id = pdata->regulator_reg_init[i].id;
  745. value = pdata->regulator_reg_init[i].value;
  746. /* check for configuration errors */
  747. if (id >= AB8500_NUM_REGULATOR_REGISTERS) {
  748. dev_err(&pdev->dev,
  749. "Configuration error: id outside range.\n");
  750. return -EINVAL;
  751. }
  752. err = ab8500_regulator_init_registers(pdev, id, value);
  753. if (err < 0)
  754. return err;
  755. }
  756. /* register all regulators */
  757. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  758. err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
  759. if (err < 0)
  760. return err;
  761. }
  762. return 0;
  763. }
  764. static __devexit int ab8500_regulator_remove(struct platform_device *pdev)
  765. {
  766. int i;
  767. for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
  768. struct ab8500_regulator_info *info = NULL;
  769. info = &ab8500_regulator_info[i];
  770. dev_vdbg(rdev_get_dev(info->regulator),
  771. "%s-remove\n", info->desc.name);
  772. regulator_unregister(info->regulator);
  773. }
  774. return 0;
  775. }
  776. static struct platform_driver ab8500_regulator_driver = {
  777. .probe = ab8500_regulator_probe,
  778. .remove = __devexit_p(ab8500_regulator_remove),
  779. .driver = {
  780. .name = "ab8500-regulator",
  781. .owner = THIS_MODULE,
  782. },
  783. };
  784. static int __init ab8500_regulator_init(void)
  785. {
  786. int ret;
  787. ret = platform_driver_register(&ab8500_regulator_driver);
  788. if (ret != 0)
  789. pr_err("Failed to register ab8500 regulator: %d\n", ret);
  790. return ret;
  791. }
  792. subsys_initcall(ab8500_regulator_init);
  793. static void __exit ab8500_regulator_exit(void)
  794. {
  795. platform_driver_unregister(&ab8500_regulator_driver);
  796. }
  797. module_exit(ab8500_regulator_exit);
  798. MODULE_LICENSE("GPL v2");
  799. MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
  800. MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
  801. MODULE_ALIAS("platform:ab8500-regulator");