ab8500.c 21 KB

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