ab8500.c 21 KB

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