ab8500.c 23 KB

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