ab8500.c 26 KB

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