ab8500.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * Authors: Sundar Iyer <[email protected]> for ST-Ericsson
  6. * Bengt Jonsson <[email protected]> for ST-Ericsson
  7. * Daniel Willerud <[email protected]> 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. * AB8505 supports the following regulators:
  15. * VAUX1/2/3/4/5/6, VINTCORE, VADC, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA
  16. */
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/err.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/mfd/abx500.h>
  23. #include <linux/mfd/abx500/ab8500.h>
  24. #include <linux/of.h>
  25. #include <linux/regulator/of_regulator.h>
  26. #include <linux/regulator/driver.h>
  27. #include <linux/regulator/machine.h>
  28. #include <linux/slab.h>
  29. /* AB8500 regulators */
  30. enum ab8500_regulator_id {
  31. AB8500_LDO_AUX1,
  32. AB8500_LDO_AUX2,
  33. AB8500_LDO_AUX3,
  34. AB8500_LDO_INTCORE,
  35. AB8500_LDO_TVOUT,
  36. AB8500_LDO_AUDIO,
  37. AB8500_LDO_ANAMIC1,
  38. AB8500_LDO_ANAMIC2,
  39. AB8500_LDO_DMIC,
  40. AB8500_LDO_ANA,
  41. AB8500_NUM_REGULATORS,
  42. };
  43. /* AB8505 regulators */
  44. enum ab8505_regulator_id {
  45. AB8505_LDO_AUX1,
  46. AB8505_LDO_AUX2,
  47. AB8505_LDO_AUX3,
  48. AB8505_LDO_AUX4,
  49. AB8505_LDO_AUX5,
  50. AB8505_LDO_AUX6,
  51. AB8505_LDO_INTCORE,
  52. AB8505_LDO_ADC,
  53. AB8505_LDO_AUDIO,
  54. AB8505_LDO_ANAMIC1,
  55. AB8505_LDO_ANAMIC2,
  56. AB8505_LDO_AUX8,
  57. AB8505_LDO_ANA,
  58. AB8505_NUM_REGULATORS,
  59. };
  60. /* AB8500 registers */
  61. enum ab8500_regulator_reg {
  62. AB8500_REGUREQUESTCTRL2,
  63. AB8500_REGUREQUESTCTRL3,
  64. AB8500_REGUREQUESTCTRL4,
  65. AB8500_REGUSYSCLKREQ1HPVALID1,
  66. AB8500_REGUSYSCLKREQ1HPVALID2,
  67. AB8500_REGUHWHPREQ1VALID1,
  68. AB8500_REGUHWHPREQ1VALID2,
  69. AB8500_REGUHWHPREQ2VALID1,
  70. AB8500_REGUHWHPREQ2VALID2,
  71. AB8500_REGUSWHPREQVALID1,
  72. AB8500_REGUSWHPREQVALID2,
  73. AB8500_REGUSYSCLKREQVALID1,
  74. AB8500_REGUSYSCLKREQVALID2,
  75. AB8500_REGUMISC1,
  76. AB8500_VAUDIOSUPPLY,
  77. AB8500_REGUCTRL1VAMIC,
  78. AB8500_VPLLVANAREGU,
  79. AB8500_VREFDDR,
  80. AB8500_EXTSUPPLYREGU,
  81. AB8500_VAUX12REGU,
  82. AB8500_VRF1VAUX3REGU,
  83. AB8500_VAUX1SEL,
  84. AB8500_VAUX2SEL,
  85. AB8500_VRF1VAUX3SEL,
  86. AB8500_REGUCTRL2SPARE,
  87. AB8500_REGUCTRLDISCH,
  88. AB8500_REGUCTRLDISCH2,
  89. AB8500_NUM_REGULATOR_REGISTERS,
  90. };
  91. /* AB8505 registers */
  92. enum ab8505_regulator_reg {
  93. AB8505_REGUREQUESTCTRL1,
  94. AB8505_REGUREQUESTCTRL2,
  95. AB8505_REGUREQUESTCTRL3,
  96. AB8505_REGUREQUESTCTRL4,
  97. AB8505_REGUSYSCLKREQ1HPVALID1,
  98. AB8505_REGUSYSCLKREQ1HPVALID2,
  99. AB8505_REGUHWHPREQ1VALID1,
  100. AB8505_REGUHWHPREQ1VALID2,
  101. AB8505_REGUHWHPREQ2VALID1,
  102. AB8505_REGUHWHPREQ2VALID2,
  103. AB8505_REGUSWHPREQVALID1,
  104. AB8505_REGUSWHPREQVALID2,
  105. AB8505_REGUSYSCLKREQVALID1,
  106. AB8505_REGUSYSCLKREQVALID2,
  107. AB8505_REGUVAUX4REQVALID,
  108. AB8505_REGUMISC1,
  109. AB8505_VAUDIOSUPPLY,
  110. AB8505_REGUCTRL1VAMIC,
  111. AB8505_VSMPSAREGU,
  112. AB8505_VSMPSBREGU,
  113. AB8505_VSAFEREGU, /* NOTE! PRCMU register */
  114. AB8505_VPLLVANAREGU,
  115. AB8505_EXTSUPPLYREGU,
  116. AB8505_VAUX12REGU,
  117. AB8505_VRF1VAUX3REGU,
  118. AB8505_VSMPSASEL1,
  119. AB8505_VSMPSASEL2,
  120. AB8505_VSMPSASEL3,
  121. AB8505_VSMPSBSEL1,
  122. AB8505_VSMPSBSEL2,
  123. AB8505_VSMPSBSEL3,
  124. AB8505_VSAFESEL1, /* NOTE! PRCMU register */
  125. AB8505_VSAFESEL2, /* NOTE! PRCMU register */
  126. AB8505_VSAFESEL3, /* NOTE! PRCMU register */
  127. AB8505_VAUX1SEL,
  128. AB8505_VAUX2SEL,
  129. AB8505_VRF1VAUX3SEL,
  130. AB8505_VAUX4REQCTRL,
  131. AB8505_VAUX4REGU,
  132. AB8505_VAUX4SEL,
  133. AB8505_REGUCTRLDISCH,
  134. AB8505_REGUCTRLDISCH2,
  135. AB8505_REGUCTRLDISCH3,
  136. AB8505_CTRLVAUX5,
  137. AB8505_CTRLVAUX6,
  138. AB8505_NUM_REGULATOR_REGISTERS,
  139. };
  140. /**
  141. * struct ab8500_shared_mode - is used when mode is shared between
  142. * two regulators.
  143. * @shared_regulator: pointer to the other sharing regulator
  144. * @lp_mode_req: low power mode requested by this regulator
  145. */
  146. struct ab8500_shared_mode {
  147. struct ab8500_regulator_info *shared_regulator;
  148. bool lp_mode_req;
  149. };
  150. /**
  151. * struct ab8500_regulator_info - ab8500 regulator information
  152. * @dev: device pointer
  153. * @desc: regulator description
  154. * @shared_mode: used when mode is shared between two regulators
  155. * @load_lp_uA: maximum load in idle (low power) mode
  156. * @update_bank: bank to control on/off
  157. * @update_reg: register to control on/off
  158. * @update_mask: mask to enable/disable and set mode of regulator
  159. * @update_val: bits holding the regulator current mode
  160. * @update_val_idle: bits to enable the regulator in idle (low power) mode
  161. * @update_val_normal: bits to enable the regulator in normal (high power) mode
  162. * @mode_bank: bank with location of mode register
  163. * @mode_reg: mode register
  164. * @mode_mask: mask for setting mode
  165. * @mode_val_idle: mode setting for low power
  166. * @mode_val_normal: mode setting for normal power
  167. * @voltage_bank: bank to control regulator voltage
  168. * @voltage_reg: register to control regulator voltage
  169. * @voltage_mask: mask to control regulator voltage
  170. * @expand_register:
  171. */
  172. struct ab8500_regulator_info {
  173. struct device *dev;
  174. struct regulator_desc desc;
  175. struct ab8500_shared_mode *shared_mode;
  176. int load_lp_uA;
  177. u8 update_bank;
  178. u8 update_reg;
  179. u8 update_mask;
  180. u8 update_val;
  181. u8 update_val_idle;
  182. u8 update_val_normal;
  183. u8 mode_bank;
  184. u8 mode_reg;
  185. u8 mode_mask;
  186. u8 mode_val_idle;
  187. u8 mode_val_normal;
  188. u8 voltage_bank;
  189. u8 voltage_reg;
  190. u8 voltage_mask;
  191. };
  192. /* voltage tables for the vauxn/vintcore supplies */
  193. static const unsigned int ldo_vauxn_voltages[] = {
  194. 1100000,
  195. 1200000,
  196. 1300000,
  197. 1400000,
  198. 1500000,
  199. 1800000,
  200. 1850000,
  201. 1900000,
  202. 2500000,
  203. 2650000,
  204. 2700000,
  205. 2750000,
  206. 2800000,
  207. 2900000,
  208. 3000000,
  209. 3300000,
  210. };
  211. static const unsigned int ldo_vaux3_voltages[] = {
  212. 1200000,
  213. 1500000,
  214. 1800000,
  215. 2100000,
  216. 2500000,
  217. 2750000,
  218. 2790000,
  219. 2910000,
  220. };
  221. static const unsigned int ldo_vaux56_voltages[] = {
  222. 1800000,
  223. 1050000,
  224. 1100000,
  225. 1200000,
  226. 1500000,
  227. 2200000,
  228. 2500000,
  229. 2790000,
  230. };
  231. static const unsigned int ldo_vintcore_voltages[] = {
  232. 1200000,
  233. 1225000,
  234. 1250000,
  235. 1275000,
  236. 1300000,
  237. 1325000,
  238. 1350000,
  239. };
  240. static const unsigned int fixed_1200000_voltage[] = {
  241. 1200000,
  242. };
  243. static const unsigned int fixed_1800000_voltage[] = {
  244. 1800000,
  245. };
  246. static const unsigned int fixed_2000000_voltage[] = {
  247. 2000000,
  248. };
  249. static const unsigned int fixed_2050000_voltage[] = {
  250. 2050000,
  251. };
  252. static const unsigned int ldo_vana_voltages[] = {
  253. 1050000,
  254. 1075000,
  255. 1100000,
  256. 1125000,
  257. 1150000,
  258. 1175000,
  259. 1200000,
  260. 1225000,
  261. };
  262. static const unsigned int ldo_vaudio_voltages[] = {
  263. 2000000,
  264. 2100000,
  265. 2200000,
  266. 2300000,
  267. 2400000,
  268. 2500000,
  269. 2600000,
  270. 2600000, /* Duplicated in Vaudio and IsoUicc Control register. */
  271. };
  272. static DEFINE_MUTEX(shared_mode_mutex);
  273. static struct ab8500_shared_mode ldo_anamic1_shared;
  274. static struct ab8500_shared_mode ldo_anamic2_shared;
  275. static int ab8500_regulator_enable(struct regulator_dev *rdev)
  276. {
  277. int ret;
  278. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  279. if (info == NULL) {
  280. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  281. return -EINVAL;
  282. }
  283. ret = abx500_mask_and_set_register_interruptible(info->dev,
  284. info->update_bank, info->update_reg,
  285. info->update_mask, info->update_val);
  286. if (ret < 0) {
  287. dev_err(rdev_get_dev(rdev),
  288. "couldn't set enable bits for regulator\n");
  289. return ret;
  290. }
  291. dev_vdbg(rdev_get_dev(rdev),
  292. "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
  293. info->desc.name, info->update_bank, info->update_reg,
  294. info->update_mask, info->update_val);
  295. return ret;
  296. }
  297. static int ab8500_regulator_disable(struct regulator_dev *rdev)
  298. {
  299. int ret;
  300. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  301. if (info == NULL) {
  302. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  303. return -EINVAL;
  304. }
  305. ret = abx500_mask_and_set_register_interruptible(info->dev,
  306. info->update_bank, info->update_reg,
  307. info->update_mask, 0x0);
  308. if (ret < 0) {
  309. dev_err(rdev_get_dev(rdev),
  310. "couldn't set disable bits for regulator\n");
  311. return ret;
  312. }
  313. dev_vdbg(rdev_get_dev(rdev),
  314. "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n",
  315. info->desc.name, info->update_bank, info->update_reg,
  316. info->update_mask, 0x0);
  317. return ret;
  318. }
  319. static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
  320. {
  321. int ret;
  322. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  323. u8 regval;
  324. if (info == NULL) {
  325. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  326. return -EINVAL;
  327. }
  328. ret = abx500_get_register_interruptible(info->dev,
  329. info->update_bank, info->update_reg, &regval);
  330. if (ret < 0) {
  331. dev_err(rdev_get_dev(rdev),
  332. "couldn't read 0x%x register\n", info->update_reg);
  333. return ret;
  334. }
  335. dev_vdbg(rdev_get_dev(rdev),
  336. "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  337. " 0x%x\n",
  338. info->desc.name, info->update_bank, info->update_reg,
  339. info->update_mask, regval);
  340. if (regval & info->update_mask)
  341. return 1;
  342. else
  343. return 0;
  344. }
  345. static unsigned int ab8500_regulator_get_optimum_mode(
  346. struct regulator_dev *rdev, int input_uV,
  347. int output_uV, int load_uA)
  348. {
  349. unsigned int mode;
  350. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  351. if (info == NULL) {
  352. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  353. return -EINVAL;
  354. }
  355. if (load_uA <= info->load_lp_uA)
  356. mode = REGULATOR_MODE_IDLE;
  357. else
  358. mode = REGULATOR_MODE_NORMAL;
  359. return mode;
  360. }
  361. static int ab8500_regulator_set_mode(struct regulator_dev *rdev,
  362. unsigned int mode)
  363. {
  364. int ret = 0;
  365. u8 bank, reg, mask, val;
  366. bool lp_mode_req = false;
  367. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  368. if (info == NULL) {
  369. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  370. return -EINVAL;
  371. }
  372. if (info->mode_mask) {
  373. bank = info->mode_bank;
  374. reg = info->mode_reg;
  375. mask = info->mode_mask;
  376. } else {
  377. bank = info->update_bank;
  378. reg = info->update_reg;
  379. mask = info->update_mask;
  380. }
  381. if (info->shared_mode)
  382. mutex_lock(&shared_mode_mutex);
  383. switch (mode) {
  384. case REGULATOR_MODE_NORMAL:
  385. if (info->shared_mode)
  386. lp_mode_req = false;
  387. if (info->mode_mask)
  388. val = info->mode_val_normal;
  389. else
  390. val = info->update_val_normal;
  391. break;
  392. case REGULATOR_MODE_IDLE:
  393. if (info->shared_mode) {
  394. struct ab8500_regulator_info *shared_regulator;
  395. shared_regulator = info->shared_mode->shared_regulator;
  396. if (!shared_regulator->shared_mode->lp_mode_req) {
  397. /* Other regulator prevent LP mode */
  398. info->shared_mode->lp_mode_req = true;
  399. goto out_unlock;
  400. }
  401. lp_mode_req = true;
  402. }
  403. if (info->mode_mask)
  404. val = info->mode_val_idle;
  405. else
  406. val = info->update_val_idle;
  407. break;
  408. default:
  409. ret = -EINVAL;
  410. goto out_unlock;
  411. }
  412. if (info->mode_mask || ab8500_regulator_is_enabled(rdev)) {
  413. ret = abx500_mask_and_set_register_interruptible(info->dev,
  414. bank, reg, mask, val);
  415. if (ret < 0) {
  416. dev_err(rdev_get_dev(rdev),
  417. "couldn't set regulator mode\n");
  418. goto out_unlock;
  419. }
  420. dev_vdbg(rdev_get_dev(rdev),
  421. "%s-set_mode (bank, reg, mask, value): "
  422. "0x%x, 0x%x, 0x%x, 0x%x\n",
  423. info->desc.name, bank, reg,
  424. mask, val);
  425. }
  426. if (!info->mode_mask)
  427. info->update_val = val;
  428. if (info->shared_mode)
  429. info->shared_mode->lp_mode_req = lp_mode_req;
  430. out_unlock:
  431. if (info->shared_mode)
  432. mutex_unlock(&shared_mode_mutex);
  433. return ret;
  434. }
  435. static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev)
  436. {
  437. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  438. int ret;
  439. u8 val;
  440. u8 val_normal;
  441. u8 val_idle;
  442. if (info == NULL) {
  443. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  444. return -EINVAL;
  445. }
  446. /* Need special handling for shared mode */
  447. if (info->shared_mode) {
  448. if (info->shared_mode->lp_mode_req)
  449. return REGULATOR_MODE_IDLE;
  450. else
  451. return REGULATOR_MODE_NORMAL;
  452. }
  453. if (info->mode_mask) {
  454. /* Dedicated register for handling mode */
  455. ret = abx500_get_register_interruptible(info->dev,
  456. info->mode_bank, info->mode_reg, &val);
  457. val = val & info->mode_mask;
  458. val_normal = info->mode_val_normal;
  459. val_idle = info->mode_val_idle;
  460. } else {
  461. /* Mode register same as enable register */
  462. val = info->update_val;
  463. val_normal = info->update_val_normal;
  464. val_idle = info->update_val_idle;
  465. }
  466. if (val == val_normal)
  467. ret = REGULATOR_MODE_NORMAL;
  468. else if (val == val_idle)
  469. ret = REGULATOR_MODE_IDLE;
  470. else
  471. ret = -EINVAL;
  472. return ret;
  473. }
  474. static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev)
  475. {
  476. int ret, voltage_shift;
  477. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  478. u8 regval;
  479. if (info == NULL) {
  480. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  481. return -EINVAL;
  482. }
  483. voltage_shift = ffs(info->voltage_mask) - 1;
  484. ret = abx500_get_register_interruptible(info->dev,
  485. info->voltage_bank, info->voltage_reg, &regval);
  486. if (ret < 0) {
  487. dev_err(rdev_get_dev(rdev),
  488. "couldn't read voltage reg for regulator\n");
  489. return ret;
  490. }
  491. dev_vdbg(rdev_get_dev(rdev),
  492. "%s-get_voltage (bank, reg, mask, shift, value): "
  493. "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  494. info->desc.name, info->voltage_bank,
  495. info->voltage_reg, info->voltage_mask,
  496. voltage_shift, regval);
  497. return (regval & info->voltage_mask) >> voltage_shift;
  498. }
  499. static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev,
  500. unsigned selector)
  501. {
  502. int ret, voltage_shift;
  503. struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
  504. u8 regval;
  505. if (info == NULL) {
  506. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  507. return -EINVAL;
  508. }
  509. voltage_shift = ffs(info->voltage_mask) - 1;
  510. /* set the registers for the request */
  511. regval = (u8)selector << voltage_shift;
  512. ret = abx500_mask_and_set_register_interruptible(info->dev,
  513. info->voltage_bank, info->voltage_reg,
  514. info->voltage_mask, regval);
  515. if (ret < 0)
  516. dev_err(rdev_get_dev(rdev),
  517. "couldn't set voltage reg for regulator\n");
  518. dev_vdbg(rdev_get_dev(rdev),
  519. "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x,"
  520. " 0x%x\n",
  521. info->desc.name, info->voltage_bank, info->voltage_reg,
  522. info->voltage_mask, regval);
  523. return ret;
  524. }
  525. static const struct regulator_ops ab8500_regulator_volt_mode_ops = {
  526. .enable = ab8500_regulator_enable,
  527. .disable = ab8500_regulator_disable,
  528. .is_enabled = ab8500_regulator_is_enabled,
  529. .get_optimum_mode = ab8500_regulator_get_optimum_mode,
  530. .set_mode = ab8500_regulator_set_mode,
  531. .get_mode = ab8500_regulator_get_mode,
  532. .get_voltage_sel = ab8500_regulator_get_voltage_sel,
  533. .set_voltage_sel = ab8500_regulator_set_voltage_sel,
  534. .list_voltage = regulator_list_voltage_table,
  535. };
  536. static const struct regulator_ops ab8500_regulator_volt_ops = {
  537. .enable = ab8500_regulator_enable,
  538. .disable = ab8500_regulator_disable,
  539. .is_enabled = ab8500_regulator_is_enabled,
  540. .get_voltage_sel = ab8500_regulator_get_voltage_sel,
  541. .set_voltage_sel = ab8500_regulator_set_voltage_sel,
  542. .list_voltage = regulator_list_voltage_table,
  543. };
  544. static const struct regulator_ops ab8500_regulator_mode_ops = {
  545. .enable = ab8500_regulator_enable,
  546. .disable = ab8500_regulator_disable,
  547. .is_enabled = ab8500_regulator_is_enabled,
  548. .get_optimum_mode = ab8500_regulator_get_optimum_mode,
  549. .set_mode = ab8500_regulator_set_mode,
  550. .get_mode = ab8500_regulator_get_mode,
  551. .list_voltage = regulator_list_voltage_table,
  552. };
  553. static const struct regulator_ops ab8500_regulator_ops = {
  554. .enable = ab8500_regulator_enable,
  555. .disable = ab8500_regulator_disable,
  556. .is_enabled = ab8500_regulator_is_enabled,
  557. .list_voltage = regulator_list_voltage_table,
  558. };
  559. static const struct regulator_ops ab8500_regulator_anamic_mode_ops = {
  560. .enable = ab8500_regulator_enable,
  561. .disable = ab8500_regulator_disable,
  562. .is_enabled = ab8500_regulator_is_enabled,
  563. .set_mode = ab8500_regulator_set_mode,
  564. .get_mode = ab8500_regulator_get_mode,
  565. .list_voltage = regulator_list_voltage_table,
  566. };
  567. /* AB8500 regulator information */
  568. static struct ab8500_regulator_info
  569. ab8500_regulator_info[AB8500_NUM_REGULATORS] = {
  570. /*
  571. * Variable Voltage Regulators
  572. * name, min mV, max mV,
  573. * update bank, reg, mask, enable val
  574. * volt bank, reg, mask
  575. */
  576. [AB8500_LDO_AUX1] = {
  577. .desc = {
  578. .name = "LDO-AUX1",
  579. .ops = &ab8500_regulator_volt_mode_ops,
  580. .type = REGULATOR_VOLTAGE,
  581. .id = AB8500_LDO_AUX1,
  582. .owner = THIS_MODULE,
  583. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  584. .volt_table = ldo_vauxn_voltages,
  585. .enable_time = 200,
  586. .supply_name = "vin",
  587. },
  588. .load_lp_uA = 5000,
  589. .update_bank = 0x04,
  590. .update_reg = 0x09,
  591. .update_mask = 0x03,
  592. .update_val = 0x01,
  593. .update_val_idle = 0x03,
  594. .update_val_normal = 0x01,
  595. .voltage_bank = 0x04,
  596. .voltage_reg = 0x1f,
  597. .voltage_mask = 0x0f,
  598. },
  599. [AB8500_LDO_AUX2] = {
  600. .desc = {
  601. .name = "LDO-AUX2",
  602. .ops = &ab8500_regulator_volt_mode_ops,
  603. .type = REGULATOR_VOLTAGE,
  604. .id = AB8500_LDO_AUX2,
  605. .owner = THIS_MODULE,
  606. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  607. .volt_table = ldo_vauxn_voltages,
  608. .enable_time = 200,
  609. .supply_name = "vin",
  610. },
  611. .load_lp_uA = 5000,
  612. .update_bank = 0x04,
  613. .update_reg = 0x09,
  614. .update_mask = 0x0c,
  615. .update_val = 0x04,
  616. .update_val_idle = 0x0c,
  617. .update_val_normal = 0x04,
  618. .voltage_bank = 0x04,
  619. .voltage_reg = 0x20,
  620. .voltage_mask = 0x0f,
  621. },
  622. [AB8500_LDO_AUX3] = {
  623. .desc = {
  624. .name = "LDO-AUX3",
  625. .ops = &ab8500_regulator_volt_mode_ops,
  626. .type = REGULATOR_VOLTAGE,
  627. .id = AB8500_LDO_AUX3,
  628. .owner = THIS_MODULE,
  629. .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
  630. .volt_table = ldo_vaux3_voltages,
  631. .enable_time = 450,
  632. .supply_name = "vin",
  633. },
  634. .load_lp_uA = 5000,
  635. .update_bank = 0x04,
  636. .update_reg = 0x0a,
  637. .update_mask = 0x03,
  638. .update_val = 0x01,
  639. .update_val_idle = 0x03,
  640. .update_val_normal = 0x01,
  641. .voltage_bank = 0x04,
  642. .voltage_reg = 0x21,
  643. .voltage_mask = 0x07,
  644. },
  645. [AB8500_LDO_INTCORE] = {
  646. .desc = {
  647. .name = "LDO-INTCORE",
  648. .ops = &ab8500_regulator_volt_mode_ops,
  649. .type = REGULATOR_VOLTAGE,
  650. .id = AB8500_LDO_INTCORE,
  651. .owner = THIS_MODULE,
  652. .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
  653. .volt_table = ldo_vintcore_voltages,
  654. .enable_time = 750,
  655. },
  656. .load_lp_uA = 5000,
  657. .update_bank = 0x03,
  658. .update_reg = 0x80,
  659. .update_mask = 0x44,
  660. .update_val = 0x44,
  661. .update_val_idle = 0x44,
  662. .update_val_normal = 0x04,
  663. .voltage_bank = 0x03,
  664. .voltage_reg = 0x80,
  665. .voltage_mask = 0x38,
  666. },
  667. /*
  668. * Fixed Voltage Regulators
  669. * name, fixed mV,
  670. * update bank, reg, mask, enable val
  671. */
  672. [AB8500_LDO_TVOUT] = {
  673. .desc = {
  674. .name = "LDO-TVOUT",
  675. .ops = &ab8500_regulator_mode_ops,
  676. .type = REGULATOR_VOLTAGE,
  677. .id = AB8500_LDO_TVOUT,
  678. .owner = THIS_MODULE,
  679. .n_voltages = 1,
  680. .volt_table = fixed_2000000_voltage,
  681. .enable_time = 500,
  682. },
  683. .load_lp_uA = 1000,
  684. .update_bank = 0x03,
  685. .update_reg = 0x80,
  686. .update_mask = 0x82,
  687. .update_val = 0x02,
  688. .update_val_idle = 0x82,
  689. .update_val_normal = 0x02,
  690. },
  691. [AB8500_LDO_AUDIO] = {
  692. .desc = {
  693. .name = "LDO-AUDIO",
  694. .ops = &ab8500_regulator_ops,
  695. .type = REGULATOR_VOLTAGE,
  696. .id = AB8500_LDO_AUDIO,
  697. .owner = THIS_MODULE,
  698. .n_voltages = 1,
  699. .enable_time = 140,
  700. .volt_table = fixed_2000000_voltage,
  701. },
  702. .update_bank = 0x03,
  703. .update_reg = 0x83,
  704. .update_mask = 0x02,
  705. .update_val = 0x02,
  706. },
  707. [AB8500_LDO_ANAMIC1] = {
  708. .desc = {
  709. .name = "LDO-ANAMIC1",
  710. .ops = &ab8500_regulator_ops,
  711. .type = REGULATOR_VOLTAGE,
  712. .id = AB8500_LDO_ANAMIC1,
  713. .owner = THIS_MODULE,
  714. .n_voltages = 1,
  715. .enable_time = 500,
  716. .volt_table = fixed_2050000_voltage,
  717. },
  718. .update_bank = 0x03,
  719. .update_reg = 0x83,
  720. .update_mask = 0x08,
  721. .update_val = 0x08,
  722. },
  723. [AB8500_LDO_ANAMIC2] = {
  724. .desc = {
  725. .name = "LDO-ANAMIC2",
  726. .ops = &ab8500_regulator_ops,
  727. .type = REGULATOR_VOLTAGE,
  728. .id = AB8500_LDO_ANAMIC2,
  729. .owner = THIS_MODULE,
  730. .n_voltages = 1,
  731. .enable_time = 500,
  732. .volt_table = fixed_2050000_voltage,
  733. },
  734. .update_bank = 0x03,
  735. .update_reg = 0x83,
  736. .update_mask = 0x10,
  737. .update_val = 0x10,
  738. },
  739. [AB8500_LDO_DMIC] = {
  740. .desc = {
  741. .name = "LDO-DMIC",
  742. .ops = &ab8500_regulator_ops,
  743. .type = REGULATOR_VOLTAGE,
  744. .id = AB8500_LDO_DMIC,
  745. .owner = THIS_MODULE,
  746. .n_voltages = 1,
  747. .enable_time = 420,
  748. .volt_table = fixed_1800000_voltage,
  749. },
  750. .update_bank = 0x03,
  751. .update_reg = 0x83,
  752. .update_mask = 0x04,
  753. .update_val = 0x04,
  754. },
  755. /*
  756. * Regulators with fixed voltage and normal/idle modes
  757. */
  758. [AB8500_LDO_ANA] = {
  759. .desc = {
  760. .name = "LDO-ANA",
  761. .ops = &ab8500_regulator_mode_ops,
  762. .type = REGULATOR_VOLTAGE,
  763. .id = AB8500_LDO_ANA,
  764. .owner = THIS_MODULE,
  765. .n_voltages = 1,
  766. .enable_time = 140,
  767. .volt_table = fixed_1200000_voltage,
  768. },
  769. .load_lp_uA = 1000,
  770. .update_bank = 0x04,
  771. .update_reg = 0x06,
  772. .update_mask = 0x0c,
  773. .update_val = 0x04,
  774. .update_val_idle = 0x0c,
  775. .update_val_normal = 0x04,
  776. },
  777. };
  778. /* AB8505 regulator information */
  779. static struct ab8500_regulator_info
  780. ab8505_regulator_info[AB8505_NUM_REGULATORS] = {
  781. /*
  782. * Variable Voltage Regulators
  783. * name, min mV, max mV,
  784. * update bank, reg, mask, enable val
  785. * volt bank, reg, mask
  786. */
  787. [AB8505_LDO_AUX1] = {
  788. .desc = {
  789. .name = "LDO-AUX1",
  790. .ops = &ab8500_regulator_volt_mode_ops,
  791. .type = REGULATOR_VOLTAGE,
  792. .id = AB8505_LDO_AUX1,
  793. .owner = THIS_MODULE,
  794. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  795. .volt_table = ldo_vauxn_voltages,
  796. },
  797. .load_lp_uA = 5000,
  798. .update_bank = 0x04,
  799. .update_reg = 0x09,
  800. .update_mask = 0x03,
  801. .update_val = 0x01,
  802. .update_val_idle = 0x03,
  803. .update_val_normal = 0x01,
  804. .voltage_bank = 0x04,
  805. .voltage_reg = 0x1f,
  806. .voltage_mask = 0x0f,
  807. },
  808. [AB8505_LDO_AUX2] = {
  809. .desc = {
  810. .name = "LDO-AUX2",
  811. .ops = &ab8500_regulator_volt_mode_ops,
  812. .type = REGULATOR_VOLTAGE,
  813. .id = AB8505_LDO_AUX2,
  814. .owner = THIS_MODULE,
  815. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  816. .volt_table = ldo_vauxn_voltages,
  817. },
  818. .load_lp_uA = 5000,
  819. .update_bank = 0x04,
  820. .update_reg = 0x09,
  821. .update_mask = 0x0c,
  822. .update_val = 0x04,
  823. .update_val_idle = 0x0c,
  824. .update_val_normal = 0x04,
  825. .voltage_bank = 0x04,
  826. .voltage_reg = 0x20,
  827. .voltage_mask = 0x0f,
  828. },
  829. [AB8505_LDO_AUX3] = {
  830. .desc = {
  831. .name = "LDO-AUX3",
  832. .ops = &ab8500_regulator_volt_mode_ops,
  833. .type = REGULATOR_VOLTAGE,
  834. .id = AB8505_LDO_AUX3,
  835. .owner = THIS_MODULE,
  836. .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages),
  837. .volt_table = ldo_vaux3_voltages,
  838. },
  839. .load_lp_uA = 5000,
  840. .update_bank = 0x04,
  841. .update_reg = 0x0a,
  842. .update_mask = 0x03,
  843. .update_val = 0x01,
  844. .update_val_idle = 0x03,
  845. .update_val_normal = 0x01,
  846. .voltage_bank = 0x04,
  847. .voltage_reg = 0x21,
  848. .voltage_mask = 0x07,
  849. },
  850. [AB8505_LDO_AUX4] = {
  851. .desc = {
  852. .name = "LDO-AUX4",
  853. .ops = &ab8500_regulator_volt_mode_ops,
  854. .type = REGULATOR_VOLTAGE,
  855. .id = AB8505_LDO_AUX4,
  856. .owner = THIS_MODULE,
  857. .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages),
  858. .volt_table = ldo_vauxn_voltages,
  859. },
  860. .load_lp_uA = 5000,
  861. /* values for Vaux4Regu register */
  862. .update_bank = 0x04,
  863. .update_reg = 0x2e,
  864. .update_mask = 0x03,
  865. .update_val = 0x01,
  866. .update_val_idle = 0x03,
  867. .update_val_normal = 0x01,
  868. /* values for Vaux4SEL register */
  869. .voltage_bank = 0x04,
  870. .voltage_reg = 0x2f,
  871. .voltage_mask = 0x0f,
  872. },
  873. [AB8505_LDO_AUX5] = {
  874. .desc = {
  875. .name = "LDO-AUX5",
  876. .ops = &ab8500_regulator_volt_mode_ops,
  877. .type = REGULATOR_VOLTAGE,
  878. .id = AB8505_LDO_AUX5,
  879. .owner = THIS_MODULE,
  880. .n_voltages = ARRAY_SIZE(ldo_vaux56_voltages),
  881. .volt_table = ldo_vaux56_voltages,
  882. },
  883. .load_lp_uA = 2000,
  884. /* values for CtrlVaux5 register */
  885. .update_bank = 0x01,
  886. .update_reg = 0x55,
  887. .update_mask = 0x18,
  888. .update_val = 0x10,
  889. .update_val_idle = 0x18,
  890. .update_val_normal = 0x10,
  891. .voltage_bank = 0x01,
  892. .voltage_reg = 0x55,
  893. .voltage_mask = 0x07,
  894. },
  895. [AB8505_LDO_AUX6] = {
  896. .desc = {
  897. .name = "LDO-AUX6",
  898. .ops = &ab8500_regulator_volt_mode_ops,
  899. .type = REGULATOR_VOLTAGE,
  900. .id = AB8505_LDO_AUX6,
  901. .owner = THIS_MODULE,
  902. .n_voltages = ARRAY_SIZE(ldo_vaux56_voltages),
  903. .volt_table = ldo_vaux56_voltages,
  904. },
  905. .load_lp_uA = 2000,
  906. /* values for CtrlVaux6 register */
  907. .update_bank = 0x01,
  908. .update_reg = 0x56,
  909. .update_mask = 0x18,
  910. .update_val = 0x10,
  911. .update_val_idle = 0x18,
  912. .update_val_normal = 0x10,
  913. .voltage_bank = 0x01,
  914. .voltage_reg = 0x56,
  915. .voltage_mask = 0x07,
  916. },
  917. [AB8505_LDO_INTCORE] = {
  918. .desc = {
  919. .name = "LDO-INTCORE",
  920. .ops = &ab8500_regulator_volt_mode_ops,
  921. .type = REGULATOR_VOLTAGE,
  922. .id = AB8505_LDO_INTCORE,
  923. .owner = THIS_MODULE,
  924. .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages),
  925. .volt_table = ldo_vintcore_voltages,
  926. },
  927. .load_lp_uA = 5000,
  928. .update_bank = 0x03,
  929. .update_reg = 0x80,
  930. .update_mask = 0x44,
  931. .update_val = 0x04,
  932. .update_val_idle = 0x44,
  933. .update_val_normal = 0x04,
  934. .voltage_bank = 0x03,
  935. .voltage_reg = 0x80,
  936. .voltage_mask = 0x38,
  937. },
  938. /*
  939. * Fixed Voltage Regulators
  940. * name, fixed mV,
  941. * update bank, reg, mask, enable val
  942. */
  943. [AB8505_LDO_ADC] = {
  944. .desc = {
  945. .name = "LDO-ADC",
  946. .ops = &ab8500_regulator_mode_ops,
  947. .type = REGULATOR_VOLTAGE,
  948. .id = AB8505_LDO_ADC,
  949. .owner = THIS_MODULE,
  950. .n_voltages = 1,
  951. .volt_table = fixed_2000000_voltage,
  952. .enable_time = 10000,
  953. },
  954. .load_lp_uA = 1000,
  955. .update_bank = 0x03,
  956. .update_reg = 0x80,
  957. .update_mask = 0x82,
  958. .update_val = 0x02,
  959. .update_val_idle = 0x82,
  960. .update_val_normal = 0x02,
  961. },
  962. [AB8505_LDO_AUDIO] = {
  963. .desc = {
  964. .name = "LDO-AUDIO",
  965. .ops = &ab8500_regulator_volt_ops,
  966. .type = REGULATOR_VOLTAGE,
  967. .id = AB8505_LDO_AUDIO,
  968. .owner = THIS_MODULE,
  969. .n_voltages = ARRAY_SIZE(ldo_vaudio_voltages),
  970. .volt_table = ldo_vaudio_voltages,
  971. },
  972. .update_bank = 0x03,
  973. .update_reg = 0x83,
  974. .update_mask = 0x02,
  975. .update_val = 0x02,
  976. .voltage_bank = 0x01,
  977. .voltage_reg = 0x57,
  978. .voltage_mask = 0x70,
  979. },
  980. [AB8505_LDO_ANAMIC1] = {
  981. .desc = {
  982. .name = "LDO-ANAMIC1",
  983. .ops = &ab8500_regulator_anamic_mode_ops,
  984. .type = REGULATOR_VOLTAGE,
  985. .id = AB8505_LDO_ANAMIC1,
  986. .owner = THIS_MODULE,
  987. .n_voltages = 1,
  988. .volt_table = fixed_2050000_voltage,
  989. },
  990. .shared_mode = &ldo_anamic1_shared,
  991. .update_bank = 0x03,
  992. .update_reg = 0x83,
  993. .update_mask = 0x08,
  994. .update_val = 0x08,
  995. .mode_bank = 0x01,
  996. .mode_reg = 0x54,
  997. .mode_mask = 0x04,
  998. .mode_val_idle = 0x04,
  999. .mode_val_normal = 0x00,
  1000. },
  1001. [AB8505_LDO_ANAMIC2] = {
  1002. .desc = {
  1003. .name = "LDO-ANAMIC2",
  1004. .ops = &ab8500_regulator_anamic_mode_ops,
  1005. .type = REGULATOR_VOLTAGE,
  1006. .id = AB8505_LDO_ANAMIC2,
  1007. .owner = THIS_MODULE,
  1008. .n_voltages = 1,
  1009. .volt_table = fixed_2050000_voltage,
  1010. },
  1011. .shared_mode = &ldo_anamic2_shared,
  1012. .update_bank = 0x03,
  1013. .update_reg = 0x83,
  1014. .update_mask = 0x10,
  1015. .update_val = 0x10,
  1016. .mode_bank = 0x01,
  1017. .mode_reg = 0x54,
  1018. .mode_mask = 0x04,
  1019. .mode_val_idle = 0x04,
  1020. .mode_val_normal = 0x00,
  1021. },
  1022. [AB8505_LDO_AUX8] = {
  1023. .desc = {
  1024. .name = "LDO-AUX8",
  1025. .ops = &ab8500_regulator_ops,
  1026. .type = REGULATOR_VOLTAGE,
  1027. .id = AB8505_LDO_AUX8,
  1028. .owner = THIS_MODULE,
  1029. .n_voltages = 1,
  1030. .volt_table = fixed_1800000_voltage,
  1031. },
  1032. .update_bank = 0x03,
  1033. .update_reg = 0x83,
  1034. .update_mask = 0x04,
  1035. .update_val = 0x04,
  1036. },
  1037. /*
  1038. * Regulators with fixed voltage and normal/idle modes
  1039. */
  1040. [AB8505_LDO_ANA] = {
  1041. .desc = {
  1042. .name = "LDO-ANA",
  1043. .ops = &ab8500_regulator_volt_mode_ops,
  1044. .type = REGULATOR_VOLTAGE,
  1045. .id = AB8505_LDO_ANA,
  1046. .owner = THIS_MODULE,
  1047. .n_voltages = ARRAY_SIZE(ldo_vana_voltages),
  1048. .volt_table = ldo_vana_voltages,
  1049. },
  1050. .load_lp_uA = 1000,
  1051. .update_bank = 0x04,
  1052. .update_reg = 0x06,
  1053. .update_mask = 0x0c,
  1054. .update_val = 0x04,
  1055. .update_val_idle = 0x0c,
  1056. .update_val_normal = 0x04,
  1057. .voltage_bank = 0x04,
  1058. .voltage_reg = 0x29,
  1059. .voltage_mask = 0x7,
  1060. },
  1061. };
  1062. static struct ab8500_shared_mode ldo_anamic1_shared = {
  1063. .shared_regulator = &ab8505_regulator_info[AB8505_LDO_ANAMIC2],
  1064. };
  1065. static struct ab8500_shared_mode ldo_anamic2_shared = {
  1066. .shared_regulator = &ab8505_regulator_info[AB8505_LDO_ANAMIC1],
  1067. };
  1068. struct ab8500_reg_init {
  1069. u8 bank;
  1070. u8 addr;
  1071. u8 mask;
  1072. };
  1073. #define REG_INIT(_id, _bank, _addr, _mask) \
  1074. [_id] = { \
  1075. .bank = _bank, \
  1076. .addr = _addr, \
  1077. .mask = _mask, \
  1078. }
  1079. /* AB8500 register init */
  1080. static struct ab8500_reg_init ab8500_reg_init[] = {
  1081. /*
  1082. * 0x30, VanaRequestCtrl
  1083. * 0xc0, VextSupply1RequestCtrl
  1084. */
  1085. REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xf0),
  1086. /*
  1087. * 0x03, VextSupply2RequestCtrl
  1088. * 0x0c, VextSupply3RequestCtrl
  1089. * 0x30, Vaux1RequestCtrl
  1090. * 0xc0, Vaux2RequestCtrl
  1091. */
  1092. REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff),
  1093. /*
  1094. * 0x03, Vaux3RequestCtrl
  1095. * 0x04, SwHPReq
  1096. */
  1097. REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
  1098. /*
  1099. * 0x08, VanaSysClkReq1HPValid
  1100. * 0x20, Vaux1SysClkReq1HPValid
  1101. * 0x40, Vaux2SysClkReq1HPValid
  1102. * 0x80, Vaux3SysClkReq1HPValid
  1103. */
  1104. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8),
  1105. /*
  1106. * 0x10, VextSupply1SysClkReq1HPValid
  1107. * 0x20, VextSupply2SysClkReq1HPValid
  1108. * 0x40, VextSupply3SysClkReq1HPValid
  1109. */
  1110. REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70),
  1111. /*
  1112. * 0x08, VanaHwHPReq1Valid
  1113. * 0x20, Vaux1HwHPReq1Valid
  1114. * 0x40, Vaux2HwHPReq1Valid
  1115. * 0x80, Vaux3HwHPReq1Valid
  1116. */
  1117. REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8),
  1118. /*
  1119. * 0x01, VextSupply1HwHPReq1Valid
  1120. * 0x02, VextSupply2HwHPReq1Valid
  1121. * 0x04, VextSupply3HwHPReq1Valid
  1122. */
  1123. REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07),
  1124. /*
  1125. * 0x08, VanaHwHPReq2Valid
  1126. * 0x20, Vaux1HwHPReq2Valid
  1127. * 0x40, Vaux2HwHPReq2Valid
  1128. * 0x80, Vaux3HwHPReq2Valid
  1129. */
  1130. REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8),
  1131. /*
  1132. * 0x01, VextSupply1HwHPReq2Valid
  1133. * 0x02, VextSupply2HwHPReq2Valid
  1134. * 0x04, VextSupply3HwHPReq2Valid
  1135. */
  1136. REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07),
  1137. /*
  1138. * 0x20, VanaSwHPReqValid
  1139. * 0x80, Vaux1SwHPReqValid
  1140. */
  1141. REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0),
  1142. /*
  1143. * 0x01, Vaux2SwHPReqValid
  1144. * 0x02, Vaux3SwHPReqValid
  1145. * 0x04, VextSupply1SwHPReqValid
  1146. * 0x08, VextSupply2SwHPReqValid
  1147. * 0x10, VextSupply3SwHPReqValid
  1148. */
  1149. REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f),
  1150. /*
  1151. * 0x02, SysClkReq2Valid1
  1152. * 0x04, SysClkReq3Valid1
  1153. * 0x08, SysClkReq4Valid1
  1154. * 0x10, SysClkReq5Valid1
  1155. * 0x20, SysClkReq6Valid1
  1156. * 0x40, SysClkReq7Valid1
  1157. * 0x80, SysClkReq8Valid1
  1158. */
  1159. REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe),
  1160. /*
  1161. * 0x02, SysClkReq2Valid2
  1162. * 0x04, SysClkReq3Valid2
  1163. * 0x08, SysClkReq4Valid2
  1164. * 0x10, SysClkReq5Valid2
  1165. * 0x20, SysClkReq6Valid2
  1166. * 0x40, SysClkReq7Valid2
  1167. * 0x80, SysClkReq8Valid2
  1168. */
  1169. REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe),
  1170. /*
  1171. * 0x02, VTVoutEna
  1172. * 0x04, Vintcore12Ena
  1173. * 0x38, Vintcore12Sel
  1174. * 0x40, Vintcore12LP
  1175. * 0x80, VTVoutLP
  1176. */
  1177. REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe),
  1178. /*
  1179. * 0x02, VaudioEna
  1180. * 0x04, VdmicEna
  1181. * 0x08, Vamic1Ena
  1182. * 0x10, Vamic2Ena
  1183. */
  1184. REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
  1185. /*
  1186. * 0x01, Vamic1_dzout
  1187. * 0x02, Vamic2_dzout
  1188. */
  1189. REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
  1190. /*
  1191. * 0x03, VpllRegu (NOTE! PRCMU register bits)
  1192. * 0x0c, VanaRegu
  1193. */
  1194. REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f),
  1195. /*
  1196. * 0x01, VrefDDREna
  1197. * 0x02, VrefDDRSleepMode
  1198. */
  1199. REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03),
  1200. /*
  1201. * 0x03, VextSupply1Regu
  1202. * 0x0c, VextSupply2Regu
  1203. * 0x30, VextSupply3Regu
  1204. * 0x40, ExtSupply2Bypass
  1205. * 0x80, ExtSupply3Bypass
  1206. */
  1207. REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
  1208. /*
  1209. * 0x03, Vaux1Regu
  1210. * 0x0c, Vaux2Regu
  1211. */
  1212. REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f),
  1213. /*
  1214. * 0x03, Vaux3Regu
  1215. */
  1216. REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03),
  1217. /*
  1218. * 0x0f, Vaux1Sel
  1219. */
  1220. REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f),
  1221. /*
  1222. * 0x0f, Vaux2Sel
  1223. */
  1224. REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f),
  1225. /*
  1226. * 0x07, Vaux3Sel
  1227. */
  1228. REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07),
  1229. /*
  1230. * 0x01, VextSupply12LP
  1231. */
  1232. REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01),
  1233. /*
  1234. * 0x04, Vaux1Disch
  1235. * 0x08, Vaux2Disch
  1236. * 0x10, Vaux3Disch
  1237. * 0x20, Vintcore12Disch
  1238. * 0x40, VTVoutDisch
  1239. * 0x80, VaudioDisch
  1240. */
  1241. REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
  1242. /*
  1243. * 0x02, VanaDisch
  1244. * 0x04, VdmicPullDownEna
  1245. * 0x10, VdmicDisch
  1246. */
  1247. REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
  1248. };
  1249. /* AB8505 register init */
  1250. static struct ab8500_reg_init ab8505_reg_init[] = {
  1251. /*
  1252. * 0x03, VarmRequestCtrl
  1253. * 0x0c, VsmpsCRequestCtrl
  1254. * 0x30, VsmpsARequestCtrl
  1255. * 0xc0, VsmpsBRequestCtrl
  1256. */
  1257. REG_INIT(AB8505_REGUREQUESTCTRL1, 0x03, 0x03, 0xff),
  1258. /*
  1259. * 0x03, VsafeRequestCtrl
  1260. * 0x0c, VpllRequestCtrl
  1261. * 0x30, VanaRequestCtrl
  1262. */
  1263. REG_INIT(AB8505_REGUREQUESTCTRL2, 0x03, 0x04, 0x3f),
  1264. /*
  1265. * 0x30, Vaux1RequestCtrl
  1266. * 0xc0, Vaux2RequestCtrl
  1267. */
  1268. REG_INIT(AB8505_REGUREQUESTCTRL3, 0x03, 0x05, 0xf0),
  1269. /*
  1270. * 0x03, Vaux3RequestCtrl
  1271. * 0x04, SwHPReq
  1272. */
  1273. REG_INIT(AB8505_REGUREQUESTCTRL4, 0x03, 0x06, 0x07),
  1274. /*
  1275. * 0x01, VsmpsASysClkReq1HPValid
  1276. * 0x02, VsmpsBSysClkReq1HPValid
  1277. * 0x04, VsafeSysClkReq1HPValid
  1278. * 0x08, VanaSysClkReq1HPValid
  1279. * 0x10, VpllSysClkReq1HPValid
  1280. * 0x20, Vaux1SysClkReq1HPValid
  1281. * 0x40, Vaux2SysClkReq1HPValid
  1282. * 0x80, Vaux3SysClkReq1HPValid
  1283. */
  1284. REG_INIT(AB8505_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff),
  1285. /*
  1286. * 0x01, VsmpsCSysClkReq1HPValid
  1287. * 0x02, VarmSysClkReq1HPValid
  1288. * 0x04, VbbSysClkReq1HPValid
  1289. * 0x08, VsmpsMSysClkReq1HPValid
  1290. */
  1291. REG_INIT(AB8505_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x0f),
  1292. /*
  1293. * 0x01, VsmpsAHwHPReq1Valid
  1294. * 0x02, VsmpsBHwHPReq1Valid
  1295. * 0x04, VsafeHwHPReq1Valid
  1296. * 0x08, VanaHwHPReq1Valid
  1297. * 0x10, VpllHwHPReq1Valid
  1298. * 0x20, Vaux1HwHPReq1Valid
  1299. * 0x40, Vaux2HwHPReq1Valid
  1300. * 0x80, Vaux3HwHPReq1Valid
  1301. */
  1302. REG_INIT(AB8505_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xff),
  1303. /*
  1304. * 0x08, VsmpsMHwHPReq1Valid
  1305. */
  1306. REG_INIT(AB8505_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x08),
  1307. /*
  1308. * 0x01, VsmpsAHwHPReq2Valid
  1309. * 0x02, VsmpsBHwHPReq2Valid
  1310. * 0x04, VsafeHwHPReq2Valid
  1311. * 0x08, VanaHwHPReq2Valid
  1312. * 0x10, VpllHwHPReq2Valid
  1313. * 0x20, Vaux1HwHPReq2Valid
  1314. * 0x40, Vaux2HwHPReq2Valid
  1315. * 0x80, Vaux3HwHPReq2Valid
  1316. */
  1317. REG_INIT(AB8505_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xff),
  1318. /*
  1319. * 0x08, VsmpsMHwHPReq2Valid
  1320. */
  1321. REG_INIT(AB8505_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x08),
  1322. /*
  1323. * 0x01, VsmpsCSwHPReqValid
  1324. * 0x02, VarmSwHPReqValid
  1325. * 0x04, VsmpsASwHPReqValid
  1326. * 0x08, VsmpsBSwHPReqValid
  1327. * 0x10, VsafeSwHPReqValid
  1328. * 0x20, VanaSwHPReqValid
  1329. * 0x40, VpllSwHPReqValid
  1330. * 0x80, Vaux1SwHPReqValid
  1331. */
  1332. REG_INIT(AB8505_REGUSWHPREQVALID1, 0x03, 0x0d, 0xff),
  1333. /*
  1334. * 0x01, Vaux2SwHPReqValid
  1335. * 0x02, Vaux3SwHPReqValid
  1336. * 0x20, VsmpsMSwHPReqValid
  1337. */
  1338. REG_INIT(AB8505_REGUSWHPREQVALID2, 0x03, 0x0e, 0x23),
  1339. /*
  1340. * 0x02, SysClkReq2Valid1
  1341. * 0x04, SysClkReq3Valid1
  1342. * 0x08, SysClkReq4Valid1
  1343. */
  1344. REG_INIT(AB8505_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0x0e),
  1345. /*
  1346. * 0x02, SysClkReq2Valid2
  1347. * 0x04, SysClkReq3Valid2
  1348. * 0x08, SysClkReq4Valid2
  1349. */
  1350. REG_INIT(AB8505_REGUSYSCLKREQVALID2, 0x03, 0x10, 0x0e),
  1351. /*
  1352. * 0x01, Vaux4SwHPReqValid
  1353. * 0x02, Vaux4HwHPReq2Valid
  1354. * 0x04, Vaux4HwHPReq1Valid
  1355. * 0x08, Vaux4SysClkReq1HPValid
  1356. */
  1357. REG_INIT(AB8505_REGUVAUX4REQVALID, 0x03, 0x11, 0x0f),
  1358. /*
  1359. * 0x02, VadcEna
  1360. * 0x04, VintCore12Ena
  1361. * 0x38, VintCore12Sel
  1362. * 0x40, VintCore12LP
  1363. * 0x80, VadcLP
  1364. */
  1365. REG_INIT(AB8505_REGUMISC1, 0x03, 0x80, 0xfe),
  1366. /*
  1367. * 0x02, VaudioEna
  1368. * 0x04, VdmicEna
  1369. * 0x08, Vamic1Ena
  1370. * 0x10, Vamic2Ena
  1371. */
  1372. REG_INIT(AB8505_VAUDIOSUPPLY, 0x03, 0x83, 0x1e),
  1373. /*
  1374. * 0x01, Vamic1_dzout
  1375. * 0x02, Vamic2_dzout
  1376. */
  1377. REG_INIT(AB8505_REGUCTRL1VAMIC, 0x03, 0x84, 0x03),
  1378. /*
  1379. * 0x03, VsmpsARegu
  1380. * 0x0c, VsmpsASelCtrl
  1381. * 0x10, VsmpsAAutoMode
  1382. * 0x20, VsmpsAPWMMode
  1383. */
  1384. REG_INIT(AB8505_VSMPSAREGU, 0x04, 0x03, 0x3f),
  1385. /*
  1386. * 0x03, VsmpsBRegu
  1387. * 0x0c, VsmpsBSelCtrl
  1388. * 0x10, VsmpsBAutoMode
  1389. * 0x20, VsmpsBPWMMode
  1390. */
  1391. REG_INIT(AB8505_VSMPSBREGU, 0x04, 0x04, 0x3f),
  1392. /*
  1393. * 0x03, VsafeRegu
  1394. * 0x0c, VsafeSelCtrl
  1395. * 0x10, VsafeAutoMode
  1396. * 0x20, VsafePWMMode
  1397. */
  1398. REG_INIT(AB8505_VSAFEREGU, 0x04, 0x05, 0x3f),
  1399. /*
  1400. * 0x03, VpllRegu (NOTE! PRCMU register bits)
  1401. * 0x0c, VanaRegu
  1402. */
  1403. REG_INIT(AB8505_VPLLVANAREGU, 0x04, 0x06, 0x0f),
  1404. /*
  1405. * 0x03, VextSupply1Regu
  1406. * 0x0c, VextSupply2Regu
  1407. * 0x30, VextSupply3Regu
  1408. * 0x40, ExtSupply2Bypass
  1409. * 0x80, ExtSupply3Bypass
  1410. */
  1411. REG_INIT(AB8505_EXTSUPPLYREGU, 0x04, 0x08, 0xff),
  1412. /*
  1413. * 0x03, Vaux1Regu
  1414. * 0x0c, Vaux2Regu
  1415. */
  1416. REG_INIT(AB8505_VAUX12REGU, 0x04, 0x09, 0x0f),
  1417. /*
  1418. * 0x0f, Vaux3Regu
  1419. */
  1420. REG_INIT(AB8505_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f),
  1421. /*
  1422. * 0x3f, VsmpsASel1
  1423. */
  1424. REG_INIT(AB8505_VSMPSASEL1, 0x04, 0x13, 0x3f),
  1425. /*
  1426. * 0x3f, VsmpsASel2
  1427. */
  1428. REG_INIT(AB8505_VSMPSASEL2, 0x04, 0x14, 0x3f),
  1429. /*
  1430. * 0x3f, VsmpsASel3
  1431. */
  1432. REG_INIT(AB8505_VSMPSASEL3, 0x04, 0x15, 0x3f),
  1433. /*
  1434. * 0x3f, VsmpsBSel1
  1435. */
  1436. REG_INIT(AB8505_VSMPSBSEL1, 0x04, 0x17, 0x3f),
  1437. /*
  1438. * 0x3f, VsmpsBSel2
  1439. */
  1440. REG_INIT(AB8505_VSMPSBSEL2, 0x04, 0x18, 0x3f),
  1441. /*
  1442. * 0x3f, VsmpsBSel3
  1443. */
  1444. REG_INIT(AB8505_VSMPSBSEL3, 0x04, 0x19, 0x3f),
  1445. /*
  1446. * 0x7f, VsafeSel1
  1447. */
  1448. REG_INIT(AB8505_VSAFESEL1, 0x04, 0x1b, 0x7f),
  1449. /*
  1450. * 0x3f, VsafeSel2
  1451. */
  1452. REG_INIT(AB8505_VSAFESEL2, 0x04, 0x1c, 0x7f),
  1453. /*
  1454. * 0x3f, VsafeSel3
  1455. */
  1456. REG_INIT(AB8505_VSAFESEL3, 0x04, 0x1d, 0x7f),
  1457. /*
  1458. * 0x0f, Vaux1Sel
  1459. */
  1460. REG_INIT(AB8505_VAUX1SEL, 0x04, 0x1f, 0x0f),
  1461. /*
  1462. * 0x0f, Vaux2Sel
  1463. */
  1464. REG_INIT(AB8505_VAUX2SEL, 0x04, 0x20, 0x0f),
  1465. /*
  1466. * 0x07, Vaux3Sel
  1467. * 0x30, VRF1Sel
  1468. */
  1469. REG_INIT(AB8505_VRF1VAUX3SEL, 0x04, 0x21, 0x37),
  1470. /*
  1471. * 0x03, Vaux4RequestCtrl
  1472. */
  1473. REG_INIT(AB8505_VAUX4REQCTRL, 0x04, 0x2d, 0x03),
  1474. /*
  1475. * 0x03, Vaux4Regu
  1476. */
  1477. REG_INIT(AB8505_VAUX4REGU, 0x04, 0x2e, 0x03),
  1478. /*
  1479. * 0x0f, Vaux4Sel
  1480. */
  1481. REG_INIT(AB8505_VAUX4SEL, 0x04, 0x2f, 0x0f),
  1482. /*
  1483. * 0x04, Vaux1Disch
  1484. * 0x08, Vaux2Disch
  1485. * 0x10, Vaux3Disch
  1486. * 0x20, Vintcore12Disch
  1487. * 0x40, VTVoutDisch
  1488. * 0x80, VaudioDisch
  1489. */
  1490. REG_INIT(AB8505_REGUCTRLDISCH, 0x04, 0x43, 0xfc),
  1491. /*
  1492. * 0x02, VanaDisch
  1493. * 0x04, VdmicPullDownEna
  1494. * 0x10, VdmicDisch
  1495. */
  1496. REG_INIT(AB8505_REGUCTRLDISCH2, 0x04, 0x44, 0x16),
  1497. /*
  1498. * 0x01, Vaux4Disch
  1499. */
  1500. REG_INIT(AB8505_REGUCTRLDISCH3, 0x04, 0x48, 0x01),
  1501. /*
  1502. * 0x07, Vaux5Sel
  1503. * 0x08, Vaux5LP
  1504. * 0x10, Vaux5Ena
  1505. * 0x20, Vaux5Disch
  1506. * 0x40, Vaux5DisSfst
  1507. * 0x80, Vaux5DisPulld
  1508. */
  1509. REG_INIT(AB8505_CTRLVAUX5, 0x01, 0x55, 0xff),
  1510. /*
  1511. * 0x07, Vaux6Sel
  1512. * 0x08, Vaux6LP
  1513. * 0x10, Vaux6Ena
  1514. * 0x80, Vaux6DisPulld
  1515. */
  1516. REG_INIT(AB8505_CTRLVAUX6, 0x01, 0x56, 0x9f),
  1517. };
  1518. static struct of_regulator_match ab8500_regulator_match[] = {
  1519. { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, },
  1520. { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, },
  1521. { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, },
  1522. { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, },
  1523. { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, },
  1524. { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, },
  1525. { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, },
  1526. { .name = "ab8500_ldo_anamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, },
  1527. { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, },
  1528. { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, },
  1529. };
  1530. static struct of_regulator_match ab8505_regulator_match[] = {
  1531. { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8505_LDO_AUX1, },
  1532. { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8505_LDO_AUX2, },
  1533. { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8505_LDO_AUX3, },
  1534. { .name = "ab8500_ldo_aux4", .driver_data = (void *) AB8505_LDO_AUX4, },
  1535. { .name = "ab8500_ldo_aux5", .driver_data = (void *) AB8505_LDO_AUX5, },
  1536. { .name = "ab8500_ldo_aux6", .driver_data = (void *) AB8505_LDO_AUX6, },
  1537. { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8505_LDO_INTCORE, },
  1538. { .name = "ab8500_ldo_adc", .driver_data = (void *) AB8505_LDO_ADC, },
  1539. { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8505_LDO_AUDIO, },
  1540. { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8505_LDO_ANAMIC1, },
  1541. { .name = "ab8500_ldo_anamic2", .driver_data = (void *) AB8505_LDO_ANAMIC2, },
  1542. { .name = "ab8500_ldo_aux8", .driver_data = (void *) AB8505_LDO_AUX8, },
  1543. { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8505_LDO_ANA, },
  1544. };
  1545. static struct {
  1546. struct ab8500_regulator_info *info;
  1547. int info_size;
  1548. struct ab8500_reg_init *init;
  1549. int init_size;
  1550. struct of_regulator_match *match;
  1551. int match_size;
  1552. } abx500_regulator;
  1553. static void abx500_get_regulator_info(struct ab8500 *ab8500)
  1554. {
  1555. if (is_ab8505(ab8500)) {
  1556. abx500_regulator.info = ab8505_regulator_info;
  1557. abx500_regulator.info_size = ARRAY_SIZE(ab8505_regulator_info);
  1558. abx500_regulator.init = ab8505_reg_init;
  1559. abx500_regulator.init_size = AB8505_NUM_REGULATOR_REGISTERS;
  1560. abx500_regulator.match = ab8505_regulator_match;
  1561. abx500_regulator.match_size = ARRAY_SIZE(ab8505_regulator_match);
  1562. } else {
  1563. abx500_regulator.info = ab8500_regulator_info;
  1564. abx500_regulator.info_size = ARRAY_SIZE(ab8500_regulator_info);
  1565. abx500_regulator.init = ab8500_reg_init;
  1566. abx500_regulator.init_size = AB8500_NUM_REGULATOR_REGISTERS;
  1567. abx500_regulator.match = ab8500_regulator_match;
  1568. abx500_regulator.match_size = ARRAY_SIZE(ab8500_regulator_match);
  1569. }
  1570. }
  1571. static int ab8500_regulator_register(struct platform_device *pdev,
  1572. struct regulator_init_data *init_data,
  1573. int id, struct device_node *np)
  1574. {
  1575. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  1576. struct ab8500_regulator_info *info = NULL;
  1577. struct regulator_config config = { };
  1578. struct regulator_dev *rdev;
  1579. /* assign per-regulator data */
  1580. info = &abx500_regulator.info[id];
  1581. info->dev = &pdev->dev;
  1582. config.dev = &pdev->dev;
  1583. config.init_data = init_data;
  1584. config.driver_data = info;
  1585. config.of_node = np;
  1586. /* fix for hardware before ab8500v2.0 */
  1587. if (is_ab8500_1p1_or_earlier(ab8500)) {
  1588. if (info->desc.id == AB8500_LDO_AUX3) {
  1589. info->desc.n_voltages =
  1590. ARRAY_SIZE(ldo_vauxn_voltages);
  1591. info->desc.volt_table = ldo_vauxn_voltages;
  1592. info->voltage_mask = 0xf;
  1593. }
  1594. }
  1595. /* register regulator with framework */
  1596. rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
  1597. if (IS_ERR(rdev)) {
  1598. dev_err(&pdev->dev, "failed to register regulator %s\n",
  1599. info->desc.name);
  1600. return PTR_ERR(rdev);
  1601. }
  1602. return 0;
  1603. }
  1604. static int ab8500_regulator_probe(struct platform_device *pdev)
  1605. {
  1606. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  1607. struct device_node *np = pdev->dev.of_node;
  1608. struct of_regulator_match *match;
  1609. int err, i;
  1610. if (!ab8500) {
  1611. dev_err(&pdev->dev, "null mfd parent\n");
  1612. return -EINVAL;
  1613. }
  1614. abx500_get_regulator_info(ab8500);
  1615. err = of_regulator_match(&pdev->dev, np,
  1616. abx500_regulator.match,
  1617. abx500_regulator.match_size);
  1618. if (err < 0) {
  1619. dev_err(&pdev->dev,
  1620. "Error parsing regulator init data: %d\n", err);
  1621. return err;
  1622. }
  1623. match = abx500_regulator.match;
  1624. for (i = 0; i < abx500_regulator.info_size; i++) {
  1625. err = ab8500_regulator_register(pdev, match[i].init_data, i,
  1626. match[i].of_node);
  1627. if (err)
  1628. return err;
  1629. }
  1630. return 0;
  1631. }
  1632. static struct platform_driver ab8500_regulator_driver = {
  1633. .probe = ab8500_regulator_probe,
  1634. .driver = {
  1635. .name = "ab8500-regulator",
  1636. },
  1637. };
  1638. static int __init ab8500_regulator_init(void)
  1639. {
  1640. int ret;
  1641. ret = platform_driver_register(&ab8500_regulator_driver);
  1642. if (ret != 0)
  1643. pr_err("Failed to register ab8500 regulator: %d\n", ret);
  1644. return ret;
  1645. }
  1646. subsys_initcall(ab8500_regulator_init);
  1647. static void __exit ab8500_regulator_exit(void)
  1648. {
  1649. platform_driver_unregister(&ab8500_regulator_driver);
  1650. }
  1651. module_exit(ab8500_regulator_exit);
  1652. MODULE_LICENSE("GPL v2");
  1653. MODULE_AUTHOR("Sundar Iyer <[email protected]>");
  1654. MODULE_AUTHOR("Bengt Jonsson <[email protected]>");
  1655. MODULE_AUTHOR("Daniel Willerud <[email protected]>");
  1656. MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
  1657. MODULE_ALIAS("platform:ab8500-regulator");