ab8500.c 21 KB

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