da9062-regulator.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. /*
  2. * Regulator device driver for DA9061 and DA9062.
  3. * Copyright (C) 2015-2017 Dialog Semiconductor
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/err.h>
  19. #include <linux/slab.h>
  20. #include <linux/of.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regmap.h>
  23. #include <linux/regulator/driver.h>
  24. #include <linux/regulator/machine.h>
  25. #include <linux/regulator/of_regulator.h>
  26. #include <linux/mfd/da9062/core.h>
  27. #include <linux/mfd/da9062/registers.h>
  28. /* Regulator IDs */
  29. enum {
  30. DA9061_ID_BUCK1,
  31. DA9061_ID_BUCK2,
  32. DA9061_ID_BUCK3,
  33. DA9061_ID_LDO1,
  34. DA9061_ID_LDO2,
  35. DA9061_ID_LDO3,
  36. DA9061_ID_LDO4,
  37. DA9061_MAX_REGULATORS,
  38. };
  39. enum {
  40. DA9062_ID_BUCK1,
  41. DA9062_ID_BUCK2,
  42. DA9062_ID_BUCK3,
  43. DA9062_ID_BUCK4,
  44. DA9062_ID_LDO1,
  45. DA9062_ID_LDO2,
  46. DA9062_ID_LDO3,
  47. DA9062_ID_LDO4,
  48. DA9062_MAX_REGULATORS,
  49. };
  50. /* Regulator capabilities and registers description */
  51. struct da9062_regulator_info {
  52. struct regulator_desc desc;
  53. /* Current limiting */
  54. unsigned int n_current_limits;
  55. const int *current_limits;
  56. /* Main register fields */
  57. struct reg_field mode;
  58. struct reg_field suspend;
  59. struct reg_field sleep;
  60. struct reg_field suspend_sleep;
  61. unsigned int suspend_vsel_reg;
  62. struct reg_field ilimit;
  63. /* Event detection bit */
  64. struct reg_field oc_event;
  65. };
  66. /* Single regulator settings */
  67. struct da9062_regulator {
  68. struct regulator_desc desc;
  69. struct regulator_dev *rdev;
  70. struct da9062 *hw;
  71. const struct da9062_regulator_info *info;
  72. struct regmap_field *mode;
  73. struct regmap_field *suspend;
  74. struct regmap_field *sleep;
  75. struct regmap_field *suspend_sleep;
  76. struct regmap_field *ilimit;
  77. };
  78. /* Encapsulates all information for the regulators driver */
  79. struct da9062_regulators {
  80. int irq_ldo_lim;
  81. unsigned n_regulators;
  82. /* Array size to be defined during init. Keep at end. */
  83. struct da9062_regulator regulator[0];
  84. };
  85. /* BUCK modes */
  86. enum {
  87. BUCK_MODE_MANUAL, /* 0 */
  88. BUCK_MODE_SLEEP, /* 1 */
  89. BUCK_MODE_SYNC, /* 2 */
  90. BUCK_MODE_AUTO /* 3 */
  91. };
  92. /* Regulator operations */
  93. /* Current limits array (in uA)
  94. * - DA9061_ID_[BUCK1|BUCK3]
  95. * - DA9062_ID_[BUCK1|BUCK2|BUCK4]
  96. * Entry indexes corresponds to register values.
  97. */
  98. static const int da9062_buck_a_limits[] = {
  99. 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
  100. 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
  101. };
  102. /* Current limits array (in uA)
  103. * - DA9061_ID_BUCK2
  104. * - DA9062_ID_BUCK3
  105. * Entry indexes corresponds to register values.
  106. */
  107. static const int da9062_buck_b_limits[] = {
  108. 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
  109. 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
  110. };
  111. static int da9062_set_current_limit(struct regulator_dev *rdev,
  112. int min_ua, int max_ua)
  113. {
  114. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  115. const struct da9062_regulator_info *rinfo = regl->info;
  116. int n, tval;
  117. for (n = 0; n < rinfo->n_current_limits; n++) {
  118. tval = rinfo->current_limits[n];
  119. if (tval >= min_ua && tval <= max_ua)
  120. return regmap_field_write(regl->ilimit, n);
  121. }
  122. return -EINVAL;
  123. }
  124. static int da9062_get_current_limit(struct regulator_dev *rdev)
  125. {
  126. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  127. const struct da9062_regulator_info *rinfo = regl->info;
  128. unsigned int sel;
  129. int ret;
  130. ret = regmap_field_read(regl->ilimit, &sel);
  131. if (ret < 0)
  132. return ret;
  133. if (sel >= rinfo->n_current_limits)
  134. sel = rinfo->n_current_limits - 1;
  135. return rinfo->current_limits[sel];
  136. }
  137. static int da9062_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
  138. {
  139. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  140. unsigned val;
  141. switch (mode) {
  142. case REGULATOR_MODE_FAST:
  143. val = BUCK_MODE_SYNC;
  144. break;
  145. case REGULATOR_MODE_NORMAL:
  146. val = BUCK_MODE_AUTO;
  147. break;
  148. case REGULATOR_MODE_STANDBY:
  149. val = BUCK_MODE_SLEEP;
  150. break;
  151. default:
  152. return -EINVAL;
  153. }
  154. return regmap_field_write(regl->mode, val);
  155. }
  156. /*
  157. * Bucks use single mode register field for normal operation
  158. * and suspend state.
  159. * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
  160. */
  161. static unsigned da9062_buck_get_mode(struct regulator_dev *rdev)
  162. {
  163. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  164. struct regmap_field *field;
  165. unsigned int val, mode = 0;
  166. int ret;
  167. ret = regmap_field_read(regl->mode, &val);
  168. if (ret < 0)
  169. return ret;
  170. switch (val) {
  171. default:
  172. case BUCK_MODE_MANUAL:
  173. mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
  174. /* Sleep flag bit decides the mode */
  175. break;
  176. case BUCK_MODE_SLEEP:
  177. return REGULATOR_MODE_STANDBY;
  178. case BUCK_MODE_SYNC:
  179. return REGULATOR_MODE_FAST;
  180. case BUCK_MODE_AUTO:
  181. return REGULATOR_MODE_NORMAL;
  182. }
  183. /* Detect current regulator state */
  184. ret = regmap_field_read(regl->suspend, &val);
  185. if (ret < 0)
  186. return 0;
  187. /* Read regulator mode from proper register, depending on state */
  188. if (val)
  189. field = regl->suspend_sleep;
  190. else
  191. field = regl->sleep;
  192. ret = regmap_field_read(field, &val);
  193. if (ret < 0)
  194. return 0;
  195. if (val)
  196. mode &= REGULATOR_MODE_STANDBY;
  197. else
  198. mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
  199. return mode;
  200. }
  201. /*
  202. * LDOs use sleep flags - one for normal and one for suspend state.
  203. * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
  204. */
  205. static int da9062_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
  206. {
  207. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  208. unsigned val;
  209. switch (mode) {
  210. case REGULATOR_MODE_NORMAL:
  211. val = 0;
  212. break;
  213. case REGULATOR_MODE_STANDBY:
  214. val = 1;
  215. break;
  216. default:
  217. return -EINVAL;
  218. }
  219. return regmap_field_write(regl->sleep, val);
  220. }
  221. static unsigned da9062_ldo_get_mode(struct regulator_dev *rdev)
  222. {
  223. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  224. struct regmap_field *field;
  225. int ret, val;
  226. /* Detect current regulator state */
  227. ret = regmap_field_read(regl->suspend, &val);
  228. if (ret < 0)
  229. return 0;
  230. /* Read regulator mode from proper register, depending on state */
  231. if (val)
  232. field = regl->suspend_sleep;
  233. else
  234. field = regl->sleep;
  235. ret = regmap_field_read(field, &val);
  236. if (ret < 0)
  237. return 0;
  238. if (val)
  239. return REGULATOR_MODE_STANDBY;
  240. else
  241. return REGULATOR_MODE_NORMAL;
  242. }
  243. static int da9062_buck_get_status(struct regulator_dev *rdev)
  244. {
  245. int ret = regulator_is_enabled_regmap(rdev);
  246. if (ret == 0) {
  247. ret = REGULATOR_STATUS_OFF;
  248. } else if (ret > 0) {
  249. ret = da9062_buck_get_mode(rdev);
  250. if (ret > 0)
  251. ret = regulator_mode_to_status(ret);
  252. else if (ret == 0)
  253. ret = -EIO;
  254. }
  255. return ret;
  256. }
  257. static int da9062_ldo_get_status(struct regulator_dev *rdev)
  258. {
  259. int ret = regulator_is_enabled_regmap(rdev);
  260. if (ret == 0) {
  261. ret = REGULATOR_STATUS_OFF;
  262. } else if (ret > 0) {
  263. ret = da9062_ldo_get_mode(rdev);
  264. if (ret > 0)
  265. ret = regulator_mode_to_status(ret);
  266. else if (ret == 0)
  267. ret = -EIO;
  268. }
  269. return ret;
  270. }
  271. static int da9062_set_suspend_voltage(struct regulator_dev *rdev, int uv)
  272. {
  273. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  274. const struct da9062_regulator_info *rinfo = regl->info;
  275. int ret, sel;
  276. sel = regulator_map_voltage_linear(rdev, uv, uv);
  277. if (sel < 0)
  278. return sel;
  279. sel <<= ffs(rdev->desc->vsel_mask) - 1;
  280. ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg,
  281. rdev->desc->vsel_mask, sel);
  282. return ret;
  283. }
  284. static int da9062_suspend_enable(struct regulator_dev *rdev)
  285. {
  286. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  287. return regmap_field_write(regl->suspend, 1);
  288. }
  289. static int da9062_suspend_disable(struct regulator_dev *rdev)
  290. {
  291. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  292. return regmap_field_write(regl->suspend, 0);
  293. }
  294. static int da9062_buck_set_suspend_mode(struct regulator_dev *rdev,
  295. unsigned mode)
  296. {
  297. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  298. int val;
  299. switch (mode) {
  300. case REGULATOR_MODE_FAST:
  301. val = BUCK_MODE_SYNC;
  302. break;
  303. case REGULATOR_MODE_NORMAL:
  304. val = BUCK_MODE_AUTO;
  305. break;
  306. case REGULATOR_MODE_STANDBY:
  307. val = BUCK_MODE_SLEEP;
  308. break;
  309. default:
  310. return -EINVAL;
  311. }
  312. return regmap_field_write(regl->mode, val);
  313. }
  314. static int da9062_ldo_set_suspend_mode(struct regulator_dev *rdev,
  315. unsigned mode)
  316. {
  317. struct da9062_regulator *regl = rdev_get_drvdata(rdev);
  318. unsigned val;
  319. switch (mode) {
  320. case REGULATOR_MODE_NORMAL:
  321. val = 0;
  322. break;
  323. case REGULATOR_MODE_STANDBY:
  324. val = 1;
  325. break;
  326. default:
  327. return -EINVAL;
  328. }
  329. return regmap_field_write(regl->suspend_sleep, val);
  330. }
  331. static const struct regulator_ops da9062_buck_ops = {
  332. .enable = regulator_enable_regmap,
  333. .disable = regulator_disable_regmap,
  334. .is_enabled = regulator_is_enabled_regmap,
  335. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  336. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  337. .list_voltage = regulator_list_voltage_linear,
  338. .set_current_limit = da9062_set_current_limit,
  339. .get_current_limit = da9062_get_current_limit,
  340. .set_mode = da9062_buck_set_mode,
  341. .get_mode = da9062_buck_get_mode,
  342. .get_status = da9062_buck_get_status,
  343. .set_suspend_voltage = da9062_set_suspend_voltage,
  344. .set_suspend_enable = da9062_suspend_enable,
  345. .set_suspend_disable = da9062_suspend_disable,
  346. .set_suspend_mode = da9062_buck_set_suspend_mode,
  347. };
  348. static const struct regulator_ops da9062_ldo_ops = {
  349. .enable = regulator_enable_regmap,
  350. .disable = regulator_disable_regmap,
  351. .is_enabled = regulator_is_enabled_regmap,
  352. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  353. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  354. .list_voltage = regulator_list_voltage_linear,
  355. .set_mode = da9062_ldo_set_mode,
  356. .get_mode = da9062_ldo_get_mode,
  357. .get_status = da9062_ldo_get_status,
  358. .set_suspend_voltage = da9062_set_suspend_voltage,
  359. .set_suspend_enable = da9062_suspend_enable,
  360. .set_suspend_disable = da9062_suspend_disable,
  361. .set_suspend_mode = da9062_ldo_set_suspend_mode,
  362. };
  363. /* DA9061 Regulator information */
  364. static const struct da9062_regulator_info local_da9061_regulator_info[] = {
  365. {
  366. .desc.id = DA9061_ID_BUCK1,
  367. .desc.name = "DA9061 BUCK1",
  368. .desc.of_match = of_match_ptr("buck1"),
  369. .desc.regulators_node = of_match_ptr("regulators"),
  370. .desc.ops = &da9062_buck_ops,
  371. .desc.min_uV = (300) * 1000,
  372. .desc.uV_step = (10) * 1000,
  373. .desc.n_voltages = ((1570) - (300))/(10) + 1,
  374. .current_limits = da9062_buck_a_limits,
  375. .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
  376. .desc.enable_reg = DA9062AA_BUCK1_CONT,
  377. .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
  378. .desc.vsel_reg = DA9062AA_VBUCK1_A,
  379. .desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
  380. .desc.linear_min_sel = 0,
  381. .sleep = REG_FIELD(DA9062AA_VBUCK1_A,
  382. __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
  383. sizeof(unsigned int) * 8 -
  384. __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
  385. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK1_B,
  386. __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
  387. sizeof(unsigned int) * 8 -
  388. __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
  389. .suspend_vsel_reg = DA9062AA_VBUCK1_B,
  390. .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
  391. __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
  392. sizeof(unsigned int) * 8 -
  393. __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
  394. .suspend = REG_FIELD(DA9062AA_DVC_1,
  395. __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
  396. sizeof(unsigned int) * 8 -
  397. __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
  398. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
  399. __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
  400. sizeof(unsigned int) * 8 -
  401. __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
  402. },
  403. {
  404. .desc.id = DA9061_ID_BUCK2,
  405. .desc.name = "DA9061 BUCK2",
  406. .desc.of_match = of_match_ptr("buck2"),
  407. .desc.regulators_node = of_match_ptr("regulators"),
  408. .desc.ops = &da9062_buck_ops,
  409. .desc.min_uV = (800) * 1000,
  410. .desc.uV_step = (20) * 1000,
  411. .desc.n_voltages = ((3340) - (800))/(20) + 1,
  412. .current_limits = da9062_buck_b_limits,
  413. .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
  414. .desc.enable_reg = DA9062AA_BUCK3_CONT,
  415. .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
  416. .desc.vsel_reg = DA9062AA_VBUCK3_A,
  417. .desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
  418. .desc.linear_min_sel = 0,
  419. .sleep = REG_FIELD(DA9062AA_VBUCK3_A,
  420. __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
  421. sizeof(unsigned int) * 8 -
  422. __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
  423. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK3_B,
  424. __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
  425. sizeof(unsigned int) * 8 -
  426. __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
  427. .suspend_vsel_reg = DA9062AA_VBUCK3_B,
  428. .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
  429. __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
  430. sizeof(unsigned int) * 8 -
  431. __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
  432. .suspend = REG_FIELD(DA9062AA_DVC_1,
  433. __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
  434. sizeof(unsigned int) * 8 -
  435. __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
  436. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
  437. __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
  438. sizeof(unsigned int) * 8 -
  439. __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
  440. },
  441. {
  442. .desc.id = DA9061_ID_BUCK3,
  443. .desc.name = "DA9061 BUCK3",
  444. .desc.of_match = of_match_ptr("buck3"),
  445. .desc.regulators_node = of_match_ptr("regulators"),
  446. .desc.ops = &da9062_buck_ops,
  447. .desc.min_uV = (530) * 1000,
  448. .desc.uV_step = (10) * 1000,
  449. .desc.n_voltages = ((1800) - (530))/(10) + 1,
  450. .current_limits = da9062_buck_a_limits,
  451. .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
  452. .desc.enable_reg = DA9062AA_BUCK4_CONT,
  453. .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
  454. .desc.vsel_reg = DA9062AA_VBUCK4_A,
  455. .desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
  456. .desc.linear_min_sel = 0,
  457. .sleep = REG_FIELD(DA9062AA_VBUCK4_A,
  458. __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
  459. sizeof(unsigned int) * 8 -
  460. __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
  461. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK4_B,
  462. __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
  463. sizeof(unsigned int) * 8 -
  464. __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
  465. .suspend_vsel_reg = DA9062AA_VBUCK4_B,
  466. .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
  467. __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
  468. sizeof(unsigned int) * 8 -
  469. __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
  470. .suspend = REG_FIELD(DA9062AA_DVC_1,
  471. __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
  472. sizeof(unsigned int) * 8 -
  473. __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
  474. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
  475. __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
  476. sizeof(unsigned int) * 8 -
  477. __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
  478. },
  479. {
  480. .desc.id = DA9061_ID_LDO1,
  481. .desc.name = "DA9061 LDO1",
  482. .desc.of_match = of_match_ptr("ldo1"),
  483. .desc.regulators_node = of_match_ptr("regulators"),
  484. .desc.ops = &da9062_ldo_ops,
  485. .desc.min_uV = (900) * 1000,
  486. .desc.uV_step = (50) * 1000,
  487. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  488. .desc.enable_reg = DA9062AA_LDO1_CONT,
  489. .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
  490. .desc.vsel_reg = DA9062AA_VLDO1_A,
  491. .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
  492. .desc.linear_min_sel = 0,
  493. .sleep = REG_FIELD(DA9062AA_VLDO1_A,
  494. __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
  495. sizeof(unsigned int) * 8 -
  496. __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
  497. .suspend_sleep = REG_FIELD(DA9062AA_VLDO1_B,
  498. __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
  499. sizeof(unsigned int) * 8 -
  500. __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
  501. .suspend_vsel_reg = DA9062AA_VLDO1_B,
  502. .suspend = REG_FIELD(DA9062AA_DVC_1,
  503. __builtin_ffs((int)DA9062AA_VLDO1_SEL_MASK) - 1,
  504. sizeof(unsigned int) * 8 -
  505. __builtin_clz((DA9062AA_VLDO1_SEL_MASK)) - 1),
  506. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  507. __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
  508. sizeof(unsigned int) * 8 -
  509. __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
  510. },
  511. {
  512. .desc.id = DA9061_ID_LDO2,
  513. .desc.name = "DA9061 LDO2",
  514. .desc.of_match = of_match_ptr("ldo2"),
  515. .desc.regulators_node = of_match_ptr("regulators"),
  516. .desc.ops = &da9062_ldo_ops,
  517. .desc.min_uV = (900) * 1000,
  518. .desc.uV_step = (50) * 1000,
  519. .desc.n_voltages = ((3600) - (600))/(50) + 1,
  520. .desc.enable_reg = DA9062AA_LDO2_CONT,
  521. .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
  522. .desc.vsel_reg = DA9062AA_VLDO2_A,
  523. .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
  524. .desc.linear_min_sel = 0,
  525. .sleep = REG_FIELD(DA9062AA_VLDO2_A,
  526. __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
  527. sizeof(unsigned int) * 8 -
  528. __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
  529. .suspend_sleep = REG_FIELD(DA9062AA_VLDO2_B,
  530. __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
  531. sizeof(unsigned int) * 8 -
  532. __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
  533. .suspend_vsel_reg = DA9062AA_VLDO2_B,
  534. .suspend = REG_FIELD(DA9062AA_DVC_1,
  535. __builtin_ffs((int)DA9062AA_VLDO2_SEL_MASK) - 1,
  536. sizeof(unsigned int) * 8 -
  537. __builtin_clz((DA9062AA_VLDO2_SEL_MASK)) - 1),
  538. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  539. __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
  540. sizeof(unsigned int) * 8 -
  541. __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
  542. },
  543. {
  544. .desc.id = DA9061_ID_LDO3,
  545. .desc.name = "DA9061 LDO3",
  546. .desc.of_match = of_match_ptr("ldo3"),
  547. .desc.regulators_node = of_match_ptr("regulators"),
  548. .desc.ops = &da9062_ldo_ops,
  549. .desc.min_uV = (900) * 1000,
  550. .desc.uV_step = (50) * 1000,
  551. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  552. .desc.enable_reg = DA9062AA_LDO3_CONT,
  553. .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
  554. .desc.vsel_reg = DA9062AA_VLDO3_A,
  555. .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
  556. .desc.linear_min_sel = 0,
  557. .sleep = REG_FIELD(DA9062AA_VLDO3_A,
  558. __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
  559. sizeof(unsigned int) * 8 -
  560. __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
  561. .suspend_sleep = REG_FIELD(DA9062AA_VLDO3_B,
  562. __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
  563. sizeof(unsigned int) * 8 -
  564. __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
  565. .suspend_vsel_reg = DA9062AA_VLDO3_B,
  566. .suspend = REG_FIELD(DA9062AA_DVC_1,
  567. __builtin_ffs((int)DA9062AA_VLDO3_SEL_MASK) - 1,
  568. sizeof(unsigned int) * 8 -
  569. __builtin_clz((DA9062AA_VLDO3_SEL_MASK)) - 1),
  570. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  571. __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
  572. sizeof(unsigned int) * 8 -
  573. __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
  574. },
  575. {
  576. .desc.id = DA9061_ID_LDO4,
  577. .desc.name = "DA9061 LDO4",
  578. .desc.of_match = of_match_ptr("ldo4"),
  579. .desc.regulators_node = of_match_ptr("regulators"),
  580. .desc.ops = &da9062_ldo_ops,
  581. .desc.min_uV = (900) * 1000,
  582. .desc.uV_step = (50) * 1000,
  583. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  584. .desc.enable_reg = DA9062AA_LDO4_CONT,
  585. .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
  586. .desc.vsel_reg = DA9062AA_VLDO4_A,
  587. .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
  588. .desc.linear_min_sel = 0,
  589. .sleep = REG_FIELD(DA9062AA_VLDO4_A,
  590. __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
  591. sizeof(unsigned int) * 8 -
  592. __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
  593. .suspend_sleep = REG_FIELD(DA9062AA_VLDO4_B,
  594. __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
  595. sizeof(unsigned int) * 8 -
  596. __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
  597. .suspend_vsel_reg = DA9062AA_VLDO4_B,
  598. .suspend = REG_FIELD(DA9062AA_DVC_1,
  599. __builtin_ffs((int)DA9062AA_VLDO4_SEL_MASK) - 1,
  600. sizeof(unsigned int) * 8 -
  601. __builtin_clz((DA9062AA_VLDO4_SEL_MASK)) - 1),
  602. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  603. __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
  604. sizeof(unsigned int) * 8 -
  605. __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
  606. },
  607. };
  608. /* DA9062 Regulator information */
  609. static const struct da9062_regulator_info local_da9062_regulator_info[] = {
  610. {
  611. .desc.id = DA9062_ID_BUCK1,
  612. .desc.name = "DA9062 BUCK1",
  613. .desc.of_match = of_match_ptr("buck1"),
  614. .desc.regulators_node = of_match_ptr("regulators"),
  615. .desc.ops = &da9062_buck_ops,
  616. .desc.min_uV = (300) * 1000,
  617. .desc.uV_step = (10) * 1000,
  618. .desc.n_voltages = ((1570) - (300))/(10) + 1,
  619. .current_limits = da9062_buck_a_limits,
  620. .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
  621. .desc.enable_reg = DA9062AA_BUCK1_CONT,
  622. .desc.enable_mask = DA9062AA_BUCK1_EN_MASK,
  623. .desc.vsel_reg = DA9062AA_VBUCK1_A,
  624. .desc.vsel_mask = DA9062AA_VBUCK1_A_MASK,
  625. .desc.linear_min_sel = 0,
  626. .sleep = REG_FIELD(DA9062AA_VBUCK1_A,
  627. __builtin_ffs((int)DA9062AA_BUCK1_SL_A_MASK) - 1,
  628. sizeof(unsigned int) * 8 -
  629. __builtin_clz((DA9062AA_BUCK1_SL_A_MASK)) - 1),
  630. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK1_B,
  631. __builtin_ffs((int)DA9062AA_BUCK1_SL_B_MASK) - 1,
  632. sizeof(unsigned int) * 8 -
  633. __builtin_clz((DA9062AA_BUCK1_SL_B_MASK)) - 1),
  634. .suspend_vsel_reg = DA9062AA_VBUCK1_B,
  635. .mode = REG_FIELD(DA9062AA_BUCK1_CFG,
  636. __builtin_ffs((int)DA9062AA_BUCK1_MODE_MASK) - 1,
  637. sizeof(unsigned int) * 8 -
  638. __builtin_clz((DA9062AA_BUCK1_MODE_MASK)) - 1),
  639. .suspend = REG_FIELD(DA9062AA_DVC_1,
  640. __builtin_ffs((int)DA9062AA_VBUCK1_SEL_MASK) - 1,
  641. sizeof(unsigned int) * 8 -
  642. __builtin_clz((DA9062AA_VBUCK1_SEL_MASK)) - 1),
  643. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
  644. __builtin_ffs((int)DA9062AA_BUCK1_ILIM_MASK) - 1,
  645. sizeof(unsigned int) * 8 -
  646. __builtin_clz((DA9062AA_BUCK1_ILIM_MASK)) - 1),
  647. },
  648. {
  649. .desc.id = DA9062_ID_BUCK2,
  650. .desc.name = "DA9062 BUCK2",
  651. .desc.of_match = of_match_ptr("buck2"),
  652. .desc.regulators_node = of_match_ptr("regulators"),
  653. .desc.ops = &da9062_buck_ops,
  654. .desc.min_uV = (300) * 1000,
  655. .desc.uV_step = (10) * 1000,
  656. .desc.n_voltages = ((1570) - (300))/(10) + 1,
  657. .current_limits = da9062_buck_a_limits,
  658. .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
  659. .desc.enable_reg = DA9062AA_BUCK2_CONT,
  660. .desc.enable_mask = DA9062AA_BUCK2_EN_MASK,
  661. .desc.vsel_reg = DA9062AA_VBUCK2_A,
  662. .desc.vsel_mask = DA9062AA_VBUCK2_A_MASK,
  663. .desc.linear_min_sel = 0,
  664. .sleep = REG_FIELD(DA9062AA_VBUCK2_A,
  665. __builtin_ffs((int)DA9062AA_BUCK2_SL_A_MASK) - 1,
  666. sizeof(unsigned int) * 8 -
  667. __builtin_clz((DA9062AA_BUCK2_SL_A_MASK)) - 1),
  668. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK2_B,
  669. __builtin_ffs((int)DA9062AA_BUCK2_SL_B_MASK) - 1,
  670. sizeof(unsigned int) * 8 -
  671. __builtin_clz((DA9062AA_BUCK2_SL_B_MASK)) - 1),
  672. .suspend_vsel_reg = DA9062AA_VBUCK2_B,
  673. .mode = REG_FIELD(DA9062AA_BUCK2_CFG,
  674. __builtin_ffs((int)DA9062AA_BUCK2_MODE_MASK) - 1,
  675. sizeof(unsigned int) * 8 -
  676. __builtin_clz((DA9062AA_BUCK2_MODE_MASK)) - 1),
  677. .suspend = REG_FIELD(DA9062AA_DVC_1,
  678. __builtin_ffs((int)DA9062AA_VBUCK2_SEL_MASK) - 1,
  679. sizeof(unsigned int) * 8 -
  680. __builtin_clz((DA9062AA_VBUCK2_SEL_MASK)) - 1),
  681. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_C,
  682. __builtin_ffs((int)DA9062AA_BUCK2_ILIM_MASK) - 1,
  683. sizeof(unsigned int) * 8 -
  684. __builtin_clz((DA9062AA_BUCK2_ILIM_MASK)) - 1),
  685. },
  686. {
  687. .desc.id = DA9062_ID_BUCK3,
  688. .desc.name = "DA9062 BUCK3",
  689. .desc.of_match = of_match_ptr("buck3"),
  690. .desc.regulators_node = of_match_ptr("regulators"),
  691. .desc.ops = &da9062_buck_ops,
  692. .desc.min_uV = (800) * 1000,
  693. .desc.uV_step = (20) * 1000,
  694. .desc.n_voltages = ((3340) - (800))/(20) + 1,
  695. .current_limits = da9062_buck_b_limits,
  696. .n_current_limits = ARRAY_SIZE(da9062_buck_b_limits),
  697. .desc.enable_reg = DA9062AA_BUCK3_CONT,
  698. .desc.enable_mask = DA9062AA_BUCK3_EN_MASK,
  699. .desc.vsel_reg = DA9062AA_VBUCK3_A,
  700. .desc.vsel_mask = DA9062AA_VBUCK3_A_MASK,
  701. .desc.linear_min_sel = 0,
  702. .sleep = REG_FIELD(DA9062AA_VBUCK3_A,
  703. __builtin_ffs((int)DA9062AA_BUCK3_SL_A_MASK) - 1,
  704. sizeof(unsigned int) * 8 -
  705. __builtin_clz((DA9062AA_BUCK3_SL_A_MASK)) - 1),
  706. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK3_B,
  707. __builtin_ffs((int)DA9062AA_BUCK3_SL_B_MASK) - 1,
  708. sizeof(unsigned int) * 8 -
  709. __builtin_clz((DA9062AA_BUCK3_SL_B_MASK)) - 1),
  710. .suspend_vsel_reg = DA9062AA_VBUCK3_B,
  711. .mode = REG_FIELD(DA9062AA_BUCK3_CFG,
  712. __builtin_ffs((int)DA9062AA_BUCK3_MODE_MASK) - 1,
  713. sizeof(unsigned int) * 8 -
  714. __builtin_clz((DA9062AA_BUCK3_MODE_MASK)) - 1),
  715. .suspend = REG_FIELD(DA9062AA_DVC_1,
  716. __builtin_ffs((int)DA9062AA_VBUCK3_SEL_MASK) - 1,
  717. sizeof(unsigned int) * 8 -
  718. __builtin_clz((DA9062AA_VBUCK3_SEL_MASK)) - 1),
  719. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_A,
  720. __builtin_ffs((int)DA9062AA_BUCK3_ILIM_MASK) - 1,
  721. sizeof(unsigned int) * 8 -
  722. __builtin_clz((DA9062AA_BUCK3_ILIM_MASK)) - 1),
  723. },
  724. {
  725. .desc.id = DA9062_ID_BUCK4,
  726. .desc.name = "DA9062 BUCK4",
  727. .desc.of_match = of_match_ptr("buck4"),
  728. .desc.regulators_node = of_match_ptr("regulators"),
  729. .desc.ops = &da9062_buck_ops,
  730. .desc.min_uV = (530) * 1000,
  731. .desc.uV_step = (10) * 1000,
  732. .desc.n_voltages = ((1800) - (530))/(10) + 1,
  733. .current_limits = da9062_buck_a_limits,
  734. .n_current_limits = ARRAY_SIZE(da9062_buck_a_limits),
  735. .desc.enable_reg = DA9062AA_BUCK4_CONT,
  736. .desc.enable_mask = DA9062AA_BUCK4_EN_MASK,
  737. .desc.vsel_reg = DA9062AA_VBUCK4_A,
  738. .desc.vsel_mask = DA9062AA_VBUCK4_A_MASK,
  739. .desc.linear_min_sel = 0,
  740. .sleep = REG_FIELD(DA9062AA_VBUCK4_A,
  741. __builtin_ffs((int)DA9062AA_BUCK4_SL_A_MASK) - 1,
  742. sizeof(unsigned int) * 8 -
  743. __builtin_clz((DA9062AA_BUCK4_SL_A_MASK)) - 1),
  744. .suspend_sleep = REG_FIELD(DA9062AA_VBUCK4_B,
  745. __builtin_ffs((int)DA9062AA_BUCK4_SL_B_MASK) - 1,
  746. sizeof(unsigned int) * 8 -
  747. __builtin_clz((DA9062AA_BUCK4_SL_B_MASK)) - 1),
  748. .suspend_vsel_reg = DA9062AA_VBUCK4_B,
  749. .mode = REG_FIELD(DA9062AA_BUCK4_CFG,
  750. __builtin_ffs((int)DA9062AA_BUCK4_MODE_MASK) - 1,
  751. sizeof(unsigned int) * 8 -
  752. __builtin_clz((DA9062AA_BUCK4_MODE_MASK)) - 1),
  753. .suspend = REG_FIELD(DA9062AA_DVC_1,
  754. __builtin_ffs((int)DA9062AA_VBUCK4_SEL_MASK) - 1,
  755. sizeof(unsigned int) * 8 -
  756. __builtin_clz((DA9062AA_VBUCK4_SEL_MASK)) - 1),
  757. .ilimit = REG_FIELD(DA9062AA_BUCK_ILIM_B,
  758. __builtin_ffs((int)DA9062AA_BUCK4_ILIM_MASK) - 1,
  759. sizeof(unsigned int) * 8 -
  760. __builtin_clz((DA9062AA_BUCK4_ILIM_MASK)) - 1),
  761. },
  762. {
  763. .desc.id = DA9062_ID_LDO1,
  764. .desc.name = "DA9062 LDO1",
  765. .desc.of_match = of_match_ptr("ldo1"),
  766. .desc.regulators_node = of_match_ptr("regulators"),
  767. .desc.ops = &da9062_ldo_ops,
  768. .desc.min_uV = (900) * 1000,
  769. .desc.uV_step = (50) * 1000,
  770. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  771. .desc.enable_reg = DA9062AA_LDO1_CONT,
  772. .desc.enable_mask = DA9062AA_LDO1_EN_MASK,
  773. .desc.vsel_reg = DA9062AA_VLDO1_A,
  774. .desc.vsel_mask = DA9062AA_VLDO1_A_MASK,
  775. .desc.linear_min_sel = 0,
  776. .sleep = REG_FIELD(DA9062AA_VLDO1_A,
  777. __builtin_ffs((int)DA9062AA_LDO1_SL_A_MASK) - 1,
  778. sizeof(unsigned int) * 8 -
  779. __builtin_clz((DA9062AA_LDO1_SL_A_MASK)) - 1),
  780. .suspend_sleep = REG_FIELD(DA9062AA_VLDO1_B,
  781. __builtin_ffs((int)DA9062AA_LDO1_SL_B_MASK) - 1,
  782. sizeof(unsigned int) * 8 -
  783. __builtin_clz((DA9062AA_LDO1_SL_B_MASK)) - 1),
  784. .suspend_vsel_reg = DA9062AA_VLDO1_B,
  785. .suspend = REG_FIELD(DA9062AA_DVC_1,
  786. __builtin_ffs((int)DA9062AA_VLDO1_SEL_MASK) - 1,
  787. sizeof(unsigned int) * 8 -
  788. __builtin_clz((DA9062AA_VLDO1_SEL_MASK)) - 1),
  789. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  790. __builtin_ffs((int)DA9062AA_LDO1_ILIM_MASK) - 1,
  791. sizeof(unsigned int) * 8 -
  792. __builtin_clz((DA9062AA_LDO1_ILIM_MASK)) - 1),
  793. },
  794. {
  795. .desc.id = DA9062_ID_LDO2,
  796. .desc.name = "DA9062 LDO2",
  797. .desc.of_match = of_match_ptr("ldo2"),
  798. .desc.regulators_node = of_match_ptr("regulators"),
  799. .desc.ops = &da9062_ldo_ops,
  800. .desc.min_uV = (900) * 1000,
  801. .desc.uV_step = (50) * 1000,
  802. .desc.n_voltages = ((3600) - (600))/(50) + 1,
  803. .desc.enable_reg = DA9062AA_LDO2_CONT,
  804. .desc.enable_mask = DA9062AA_LDO2_EN_MASK,
  805. .desc.vsel_reg = DA9062AA_VLDO2_A,
  806. .desc.vsel_mask = DA9062AA_VLDO2_A_MASK,
  807. .desc.linear_min_sel = 0,
  808. .sleep = REG_FIELD(DA9062AA_VLDO2_A,
  809. __builtin_ffs((int)DA9062AA_LDO2_SL_A_MASK) - 1,
  810. sizeof(unsigned int) * 8 -
  811. __builtin_clz((DA9062AA_LDO2_SL_A_MASK)) - 1),
  812. .suspend_sleep = REG_FIELD(DA9062AA_VLDO2_B,
  813. __builtin_ffs((int)DA9062AA_LDO2_SL_B_MASK) - 1,
  814. sizeof(unsigned int) * 8 -
  815. __builtin_clz((DA9062AA_LDO2_SL_B_MASK)) - 1),
  816. .suspend_vsel_reg = DA9062AA_VLDO2_B,
  817. .suspend = REG_FIELD(DA9062AA_DVC_1,
  818. __builtin_ffs((int)DA9062AA_VLDO2_SEL_MASK) - 1,
  819. sizeof(unsigned int) * 8 -
  820. __builtin_clz((DA9062AA_VLDO2_SEL_MASK)) - 1),
  821. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  822. __builtin_ffs((int)DA9062AA_LDO2_ILIM_MASK) - 1,
  823. sizeof(unsigned int) * 8 -
  824. __builtin_clz((DA9062AA_LDO2_ILIM_MASK)) - 1),
  825. },
  826. {
  827. .desc.id = DA9062_ID_LDO3,
  828. .desc.name = "DA9062 LDO3",
  829. .desc.of_match = of_match_ptr("ldo3"),
  830. .desc.regulators_node = of_match_ptr("regulators"),
  831. .desc.ops = &da9062_ldo_ops,
  832. .desc.min_uV = (900) * 1000,
  833. .desc.uV_step = (50) * 1000,
  834. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  835. .desc.enable_reg = DA9062AA_LDO3_CONT,
  836. .desc.enable_mask = DA9062AA_LDO3_EN_MASK,
  837. .desc.vsel_reg = DA9062AA_VLDO3_A,
  838. .desc.vsel_mask = DA9062AA_VLDO3_A_MASK,
  839. .desc.linear_min_sel = 0,
  840. .sleep = REG_FIELD(DA9062AA_VLDO3_A,
  841. __builtin_ffs((int)DA9062AA_LDO3_SL_A_MASK) - 1,
  842. sizeof(unsigned int) * 8 -
  843. __builtin_clz((DA9062AA_LDO3_SL_A_MASK)) - 1),
  844. .suspend_sleep = REG_FIELD(DA9062AA_VLDO3_B,
  845. __builtin_ffs((int)DA9062AA_LDO3_SL_B_MASK) - 1,
  846. sizeof(unsigned int) * 8 -
  847. __builtin_clz((DA9062AA_LDO3_SL_B_MASK)) - 1),
  848. .suspend_vsel_reg = DA9062AA_VLDO3_B,
  849. .suspend = REG_FIELD(DA9062AA_DVC_1,
  850. __builtin_ffs((int)DA9062AA_VLDO3_SEL_MASK) - 1,
  851. sizeof(unsigned int) * 8 -
  852. __builtin_clz((DA9062AA_VLDO3_SEL_MASK)) - 1),
  853. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  854. __builtin_ffs((int)DA9062AA_LDO3_ILIM_MASK) - 1,
  855. sizeof(unsigned int) * 8 -
  856. __builtin_clz((DA9062AA_LDO3_ILIM_MASK)) - 1),
  857. },
  858. {
  859. .desc.id = DA9062_ID_LDO4,
  860. .desc.name = "DA9062 LDO4",
  861. .desc.of_match = of_match_ptr("ldo4"),
  862. .desc.regulators_node = of_match_ptr("regulators"),
  863. .desc.ops = &da9062_ldo_ops,
  864. .desc.min_uV = (900) * 1000,
  865. .desc.uV_step = (50) * 1000,
  866. .desc.n_voltages = ((3600) - (900))/(50) + 1,
  867. .desc.enable_reg = DA9062AA_LDO4_CONT,
  868. .desc.enable_mask = DA9062AA_LDO4_EN_MASK,
  869. .desc.vsel_reg = DA9062AA_VLDO4_A,
  870. .desc.vsel_mask = DA9062AA_VLDO4_A_MASK,
  871. .desc.linear_min_sel = 0,
  872. .sleep = REG_FIELD(DA9062AA_VLDO4_A,
  873. __builtin_ffs((int)DA9062AA_LDO4_SL_A_MASK) - 1,
  874. sizeof(unsigned int) * 8 -
  875. __builtin_clz((DA9062AA_LDO4_SL_A_MASK)) - 1),
  876. .suspend_sleep = REG_FIELD(DA9062AA_VLDO4_B,
  877. __builtin_ffs((int)DA9062AA_LDO4_SL_B_MASK) - 1,
  878. sizeof(unsigned int) * 8 -
  879. __builtin_clz((DA9062AA_LDO4_SL_B_MASK)) - 1),
  880. .suspend_vsel_reg = DA9062AA_VLDO4_B,
  881. .suspend = REG_FIELD(DA9062AA_DVC_1,
  882. __builtin_ffs((int)DA9062AA_VLDO4_SEL_MASK) - 1,
  883. sizeof(unsigned int) * 8 -
  884. __builtin_clz((DA9062AA_VLDO4_SEL_MASK)) - 1),
  885. .oc_event = REG_FIELD(DA9062AA_STATUS_D,
  886. __builtin_ffs((int)DA9062AA_LDO4_ILIM_MASK) - 1,
  887. sizeof(unsigned int) * 8 -
  888. __builtin_clz((DA9062AA_LDO4_ILIM_MASK)) - 1),
  889. },
  890. };
  891. /* Regulator interrupt handlers */
  892. static irqreturn_t da9062_ldo_lim_event(int irq, void *data)
  893. {
  894. struct da9062_regulators *regulators = data;
  895. struct da9062 *hw = regulators->regulator[0].hw;
  896. struct da9062_regulator *regl;
  897. int handled = IRQ_NONE;
  898. int bits, i, ret;
  899. ret = regmap_read(hw->regmap, DA9062AA_STATUS_D, &bits);
  900. if (ret < 0) {
  901. dev_err(hw->dev,
  902. "Failed to read LDO overcurrent indicator\n");
  903. goto ldo_lim_error;
  904. }
  905. for (i = regulators->n_regulators - 1; i >= 0; i--) {
  906. regl = &regulators->regulator[i];
  907. if (regl->info->oc_event.reg != DA9062AA_STATUS_D)
  908. continue;
  909. if (BIT(regl->info->oc_event.lsb) & bits) {
  910. regulator_notifier_call_chain(regl->rdev,
  911. REGULATOR_EVENT_OVER_CURRENT, NULL);
  912. handled = IRQ_HANDLED;
  913. }
  914. }
  915. ldo_lim_error:
  916. return handled;
  917. }
  918. static int da9062_regulator_probe(struct platform_device *pdev)
  919. {
  920. struct da9062 *chip = dev_get_drvdata(pdev->dev.parent);
  921. struct da9062_regulators *regulators;
  922. struct da9062_regulator *regl;
  923. struct regulator_config config = { };
  924. const struct da9062_regulator_info *rinfo;
  925. int irq, n, ret;
  926. size_t size;
  927. int max_regulators;
  928. switch (chip->chip_type) {
  929. case COMPAT_TYPE_DA9061:
  930. max_regulators = DA9061_MAX_REGULATORS;
  931. rinfo = local_da9061_regulator_info;
  932. break;
  933. case COMPAT_TYPE_DA9062:
  934. max_regulators = DA9062_MAX_REGULATORS;
  935. rinfo = local_da9062_regulator_info;
  936. break;
  937. default:
  938. dev_err(chip->dev, "Unrecognised chip type\n");
  939. return -ENODEV;
  940. }
  941. /* Allocate memory required by usable regulators */
  942. size = sizeof(struct da9062_regulators) +
  943. max_regulators * sizeof(struct da9062_regulator);
  944. regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
  945. if (!regulators)
  946. return -ENOMEM;
  947. regulators->n_regulators = max_regulators;
  948. platform_set_drvdata(pdev, regulators);
  949. n = 0;
  950. while (n < regulators->n_regulators) {
  951. /* Initialise regulator structure */
  952. regl = &regulators->regulator[n];
  953. regl->hw = chip;
  954. regl->info = &rinfo[n];
  955. regl->desc = regl->info->desc;
  956. regl->desc.type = REGULATOR_VOLTAGE;
  957. regl->desc.owner = THIS_MODULE;
  958. if (regl->info->mode.reg)
  959. regl->mode = devm_regmap_field_alloc(
  960. &pdev->dev,
  961. chip->regmap,
  962. regl->info->mode);
  963. if (regl->info->suspend.reg)
  964. regl->suspend = devm_regmap_field_alloc(
  965. &pdev->dev,
  966. chip->regmap,
  967. regl->info->suspend);
  968. if (regl->info->sleep.reg)
  969. regl->sleep = devm_regmap_field_alloc(
  970. &pdev->dev,
  971. chip->regmap,
  972. regl->info->sleep);
  973. if (regl->info->suspend_sleep.reg)
  974. regl->suspend_sleep = devm_regmap_field_alloc(
  975. &pdev->dev,
  976. chip->regmap,
  977. regl->info->suspend_sleep);
  978. if (regl->info->ilimit.reg)
  979. regl->ilimit = devm_regmap_field_alloc(
  980. &pdev->dev,
  981. chip->regmap,
  982. regl->info->ilimit);
  983. /* Register regulator */
  984. memset(&config, 0, sizeof(config));
  985. config.dev = chip->dev;
  986. config.driver_data = regl;
  987. config.regmap = chip->regmap;
  988. regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc,
  989. &config);
  990. if (IS_ERR(regl->rdev)) {
  991. dev_err(&pdev->dev,
  992. "Failed to register %s regulator\n",
  993. regl->desc.name);
  994. return PTR_ERR(regl->rdev);
  995. }
  996. n++;
  997. }
  998. /* LDOs overcurrent event support */
  999. irq = platform_get_irq_byname(pdev, "LDO_LIM");
  1000. if (irq < 0) {
  1001. dev_err(&pdev->dev, "Failed to get IRQ.\n");
  1002. return irq;
  1003. }
  1004. regulators->irq_ldo_lim = irq;
  1005. ret = devm_request_threaded_irq(&pdev->dev, irq,
  1006. NULL, da9062_ldo_lim_event,
  1007. IRQF_TRIGGER_LOW | IRQF_ONESHOT,
  1008. "LDO_LIM", regulators);
  1009. if (ret) {
  1010. dev_warn(&pdev->dev,
  1011. "Failed to request LDO_LIM IRQ.\n");
  1012. regulators->irq_ldo_lim = -ENXIO;
  1013. }
  1014. return 0;
  1015. }
  1016. static struct platform_driver da9062_regulator_driver = {
  1017. .driver = {
  1018. .name = "da9062-regulators",
  1019. },
  1020. .probe = da9062_regulator_probe,
  1021. };
  1022. static int __init da9062_regulator_init(void)
  1023. {
  1024. return platform_driver_register(&da9062_regulator_driver);
  1025. }
  1026. subsys_initcall(da9062_regulator_init);
  1027. static void __exit da9062_regulator_cleanup(void)
  1028. {
  1029. platform_driver_unregister(&da9062_regulator_driver);
  1030. }
  1031. module_exit(da9062_regulator_cleanup);
  1032. /* Module information */
  1033. MODULE_AUTHOR("S Twiss <stwiss.opensource@diasemi.com>");
  1034. MODULE_DESCRIPTION("REGULATOR device driver for Dialog DA9062 and DA9061");
  1035. MODULE_LICENSE("GPL");
  1036. MODULE_ALIAS("platform:da9062-regulators");