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