ab8500.c 26 KB

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