ab8500.c 24 KB

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