ab8500.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
  6. * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson
  7. * Daniel Willerud <daniel.willerud@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. * 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. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1637. },
  1638. };
  1639. static int __init ab8500_regulator_init(void)
  1640. {
  1641. int ret;
  1642. ret = platform_driver_register(&ab8500_regulator_driver);
  1643. if (ret != 0)
  1644. pr_err("Failed to register ab8500 regulator: %d\n", ret);
  1645. return ret;
  1646. }
  1647. subsys_initcall(ab8500_regulator_init);
  1648. static void __exit ab8500_regulator_exit(void)
  1649. {
  1650. platform_driver_unregister(&ab8500_regulator_driver);
  1651. }
  1652. module_exit(ab8500_regulator_exit);
  1653. MODULE_LICENSE("GPL v2");
  1654. MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
  1655. MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
  1656. MODULE_AUTHOR("Daniel Willerud <daniel.willerud@stericsson.com>");
  1657. MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC");
  1658. MODULE_ALIAS("platform:ab8500-regulator");