ab8500.c 25 KB

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