s2mps11.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Copyright (c) 2012-2014 Samsung Electronics Co., Ltd
  4. // http://www.samsung.com
  5. #include <linux/bug.h>
  6. #include <linux/cleanup.h>
  7. #include <linux/err.h>
  8. #include <linux/gpio/consumer.h>
  9. #include <linux/slab.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/regmap.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regulator/driver.h>
  15. #include <linux/regulator/machine.h>
  16. #include <linux/regulator/of_regulator.h>
  17. #include <linux/mfd/samsung/core.h>
  18. #include <linux/mfd/samsung/s2mps11.h>
  19. #include <linux/mfd/samsung/s2mps13.h>
  20. #include <linux/mfd/samsung/s2mps14.h>
  21. #include <linux/mfd/samsung/s2mps15.h>
  22. #include <linux/mfd/samsung/s2mpu02.h>
  23. /* The highest number of possible regulators for supported devices. */
  24. #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
  25. struct s2mps11_info {
  26. int ramp_delay2;
  27. int ramp_delay34;
  28. int ramp_delay5;
  29. int ramp_delay16;
  30. int ramp_delay7810;
  31. int ramp_delay9;
  32. enum sec_device_type dev_type;
  33. /*
  34. * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
  35. * the suspend mode was enabled.
  36. */
  37. DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
  38. /*
  39. * Array (size: number of regulators) with GPIO-s for external
  40. * sleep control.
  41. */
  42. struct gpio_desc **ext_control_gpiod;
  43. };
  44. static int get_ramp_delay(int ramp_delay)
  45. {
  46. unsigned char cnt = 0;
  47. ramp_delay /= 6250;
  48. while (true) {
  49. ramp_delay = ramp_delay >> 1;
  50. if (ramp_delay == 0)
  51. break;
  52. cnt++;
  53. }
  54. if (cnt > 3)
  55. cnt = 3;
  56. return cnt;
  57. }
  58. static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  59. unsigned int old_selector,
  60. unsigned int new_selector)
  61. {
  62. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  63. int rdev_id = rdev_get_id(rdev);
  64. unsigned int ramp_delay = 0;
  65. int old_volt, new_volt;
  66. switch (rdev_id) {
  67. case S2MPS11_BUCK2:
  68. ramp_delay = s2mps11->ramp_delay2;
  69. break;
  70. case S2MPS11_BUCK3:
  71. case S2MPS11_BUCK4:
  72. ramp_delay = s2mps11->ramp_delay34;
  73. break;
  74. case S2MPS11_BUCK5:
  75. ramp_delay = s2mps11->ramp_delay5;
  76. break;
  77. case S2MPS11_BUCK6:
  78. case S2MPS11_BUCK1:
  79. ramp_delay = s2mps11->ramp_delay16;
  80. break;
  81. case S2MPS11_BUCK7:
  82. case S2MPS11_BUCK8:
  83. case S2MPS11_BUCK10:
  84. ramp_delay = s2mps11->ramp_delay7810;
  85. break;
  86. case S2MPS11_BUCK9:
  87. ramp_delay = s2mps11->ramp_delay9;
  88. }
  89. if (ramp_delay == 0)
  90. ramp_delay = rdev->desc->ramp_delay;
  91. old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
  92. new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
  93. return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
  94. }
  95. static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
  96. {
  97. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  98. unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
  99. unsigned int ramp_enable = 1, enable_shift = 0;
  100. int rdev_id = rdev_get_id(rdev);
  101. int ret;
  102. switch (rdev_id) {
  103. case S2MPS11_BUCK1:
  104. if (ramp_delay > s2mps11->ramp_delay16)
  105. s2mps11->ramp_delay16 = ramp_delay;
  106. else
  107. ramp_delay = s2mps11->ramp_delay16;
  108. ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
  109. break;
  110. case S2MPS11_BUCK2:
  111. enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
  112. if (!ramp_delay) {
  113. ramp_enable = 0;
  114. break;
  115. }
  116. s2mps11->ramp_delay2 = ramp_delay;
  117. ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
  118. ramp_reg = S2MPS11_REG_RAMP;
  119. break;
  120. case S2MPS11_BUCK3:
  121. enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
  122. if (!ramp_delay) {
  123. ramp_enable = 0;
  124. break;
  125. }
  126. if (ramp_delay > s2mps11->ramp_delay34)
  127. s2mps11->ramp_delay34 = ramp_delay;
  128. else
  129. ramp_delay = s2mps11->ramp_delay34;
  130. ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
  131. ramp_reg = S2MPS11_REG_RAMP;
  132. break;
  133. case S2MPS11_BUCK4:
  134. enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
  135. if (!ramp_delay) {
  136. ramp_enable = 0;
  137. break;
  138. }
  139. if (ramp_delay > s2mps11->ramp_delay34)
  140. s2mps11->ramp_delay34 = ramp_delay;
  141. else
  142. ramp_delay = s2mps11->ramp_delay34;
  143. ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
  144. ramp_reg = S2MPS11_REG_RAMP;
  145. break;
  146. case S2MPS11_BUCK5:
  147. s2mps11->ramp_delay5 = ramp_delay;
  148. ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
  149. break;
  150. case S2MPS11_BUCK6:
  151. enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
  152. if (!ramp_delay) {
  153. ramp_enable = 0;
  154. break;
  155. }
  156. if (ramp_delay > s2mps11->ramp_delay16)
  157. s2mps11->ramp_delay16 = ramp_delay;
  158. else
  159. ramp_delay = s2mps11->ramp_delay16;
  160. ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
  161. break;
  162. case S2MPS11_BUCK7:
  163. case S2MPS11_BUCK8:
  164. case S2MPS11_BUCK10:
  165. if (ramp_delay > s2mps11->ramp_delay7810)
  166. s2mps11->ramp_delay7810 = ramp_delay;
  167. else
  168. ramp_delay = s2mps11->ramp_delay7810;
  169. ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
  170. break;
  171. case S2MPS11_BUCK9:
  172. s2mps11->ramp_delay9 = ramp_delay;
  173. ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
  174. break;
  175. default:
  176. return 0;
  177. }
  178. if (!ramp_enable)
  179. goto ramp_disable;
  180. /* Ramp delay can be enabled/disabled only for buck[2346] */
  181. if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
  182. rdev_id == S2MPS11_BUCK6) {
  183. ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
  184. 1 << enable_shift, 1 << enable_shift);
  185. if (ret) {
  186. dev_err(&rdev->dev, "failed to enable ramp rate\n");
  187. return ret;
  188. }
  189. }
  190. ramp_val = get_ramp_delay(ramp_delay);
  191. return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
  192. ramp_val << ramp_shift);
  193. ramp_disable:
  194. return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
  195. 1 << enable_shift, 0);
  196. }
  197. static int s2mps11_regulator_enable(struct regulator_dev *rdev)
  198. {
  199. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  200. int rdev_id = rdev_get_id(rdev);
  201. unsigned int val;
  202. switch (s2mps11->dev_type) {
  203. case S2MPS11X:
  204. if (test_bit(rdev_id, s2mps11->suspend_state))
  205. val = S2MPS14_ENABLE_SUSPEND;
  206. else
  207. val = rdev->desc->enable_mask;
  208. break;
  209. case S2MPS13X:
  210. case S2MPS14X:
  211. if (test_bit(rdev_id, s2mps11->suspend_state))
  212. val = S2MPS14_ENABLE_SUSPEND;
  213. else if (s2mps11->ext_control_gpiod[rdev_id])
  214. val = S2MPS14_ENABLE_EXT_CONTROL;
  215. else
  216. val = rdev->desc->enable_mask;
  217. break;
  218. case S2MPU02:
  219. if (test_bit(rdev_id, s2mps11->suspend_state))
  220. val = S2MPU02_ENABLE_SUSPEND;
  221. else
  222. val = rdev->desc->enable_mask;
  223. break;
  224. default:
  225. return -EINVAL;
  226. }
  227. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  228. rdev->desc->enable_mask, val);
  229. }
  230. static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
  231. {
  232. int ret;
  233. unsigned int val, state;
  234. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  235. int rdev_id = rdev_get_id(rdev);
  236. /* Below LDO should be always on or does not support suspend mode. */
  237. switch (s2mps11->dev_type) {
  238. case S2MPS11X:
  239. switch (rdev_id) {
  240. case S2MPS11_LDO2:
  241. case S2MPS11_LDO36:
  242. case S2MPS11_LDO37:
  243. case S2MPS11_LDO38:
  244. return 0;
  245. default:
  246. state = S2MPS14_ENABLE_SUSPEND;
  247. break;
  248. }
  249. break;
  250. case S2MPS13X:
  251. case S2MPS14X:
  252. switch (rdev_id) {
  253. case S2MPS14_LDO3:
  254. return 0;
  255. default:
  256. state = S2MPS14_ENABLE_SUSPEND;
  257. break;
  258. }
  259. break;
  260. case S2MPU02:
  261. switch (rdev_id) {
  262. case S2MPU02_LDO13:
  263. case S2MPU02_LDO14:
  264. case S2MPU02_LDO15:
  265. case S2MPU02_LDO17:
  266. case S2MPU02_BUCK7:
  267. state = S2MPU02_DISABLE_SUSPEND;
  268. break;
  269. default:
  270. state = S2MPU02_ENABLE_SUSPEND;
  271. break;
  272. }
  273. break;
  274. default:
  275. return -EINVAL;
  276. }
  277. ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
  278. if (ret < 0)
  279. return ret;
  280. set_bit(rdev_id, s2mps11->suspend_state);
  281. /*
  282. * Don't enable suspend mode if regulator is already disabled because
  283. * this would effectively for a short time turn on the regulator after
  284. * resuming.
  285. * However we still want to toggle the suspend_state bit for regulator
  286. * in case if it got enabled before suspending the system.
  287. */
  288. if (!(val & rdev->desc->enable_mask))
  289. return 0;
  290. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  291. rdev->desc->enable_mask, state);
  292. }
  293. static const struct regulator_ops s2mps11_ldo_ops = {
  294. .list_voltage = regulator_list_voltage_linear,
  295. .map_voltage = regulator_map_voltage_linear,
  296. .is_enabled = regulator_is_enabled_regmap,
  297. .enable = s2mps11_regulator_enable,
  298. .disable = regulator_disable_regmap,
  299. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  300. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  301. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  302. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  303. };
  304. static const struct regulator_ops s2mps11_buck_ops = {
  305. .list_voltage = regulator_list_voltage_linear,
  306. .map_voltage = regulator_map_voltage_linear,
  307. .is_enabled = regulator_is_enabled_regmap,
  308. .enable = s2mps11_regulator_enable,
  309. .disable = regulator_disable_regmap,
  310. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  311. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  312. .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
  313. .set_ramp_delay = s2mps11_set_ramp_delay,
  314. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  315. };
  316. #define regulator_desc_s2mps11_ldo(num, step) { \
  317. .name = "LDO"#num, \
  318. .id = S2MPS11_LDO##num, \
  319. .ops = &s2mps11_ldo_ops, \
  320. .type = REGULATOR_VOLTAGE, \
  321. .owner = THIS_MODULE, \
  322. .ramp_delay = RAMP_DELAY_12_MVUS, \
  323. .min_uV = MIN_800_MV, \
  324. .uV_step = step, \
  325. .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
  326. .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
  327. .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
  328. .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
  329. .enable_mask = S2MPS11_ENABLE_MASK \
  330. }
  331. #define regulator_desc_s2mps11_buck1_4(num) { \
  332. .name = "BUCK"#num, \
  333. .id = S2MPS11_BUCK##num, \
  334. .ops = &s2mps11_buck_ops, \
  335. .type = REGULATOR_VOLTAGE, \
  336. .owner = THIS_MODULE, \
  337. .min_uV = MIN_650_MV, \
  338. .uV_step = STEP_6_25_MV, \
  339. .linear_min_sel = 8, \
  340. .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \
  341. .ramp_delay = S2MPS11_RAMP_DELAY, \
  342. .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
  343. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  344. .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
  345. .enable_mask = S2MPS11_ENABLE_MASK \
  346. }
  347. #define regulator_desc_s2mps11_buck5 { \
  348. .name = "BUCK5", \
  349. .id = S2MPS11_BUCK5, \
  350. .ops = &s2mps11_buck_ops, \
  351. .type = REGULATOR_VOLTAGE, \
  352. .owner = THIS_MODULE, \
  353. .min_uV = MIN_650_MV, \
  354. .uV_step = STEP_6_25_MV, \
  355. .linear_min_sel = 8, \
  356. .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \
  357. .ramp_delay = S2MPS11_RAMP_DELAY, \
  358. .vsel_reg = S2MPS11_REG_B5CTRL2, \
  359. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  360. .enable_reg = S2MPS11_REG_B5CTRL1, \
  361. .enable_mask = S2MPS11_ENABLE_MASK \
  362. }
  363. #define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \
  364. .name = "BUCK"#num, \
  365. .id = S2MPS11_BUCK##num, \
  366. .ops = &s2mps11_buck_ops, \
  367. .type = REGULATOR_VOLTAGE, \
  368. .owner = THIS_MODULE, \
  369. .min_uV = min, \
  370. .uV_step = step, \
  371. .linear_min_sel = min_sel, \
  372. .n_voltages = voltages, \
  373. .ramp_delay = S2MPS11_RAMP_DELAY, \
  374. .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
  375. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  376. .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
  377. .enable_mask = S2MPS11_ENABLE_MASK \
  378. }
  379. #define regulator_desc_s2mps11_buck9 { \
  380. .name = "BUCK9", \
  381. .id = S2MPS11_BUCK9, \
  382. .ops = &s2mps11_buck_ops, \
  383. .type = REGULATOR_VOLTAGE, \
  384. .owner = THIS_MODULE, \
  385. .min_uV = MIN_3000_MV, \
  386. .uV_step = STEP_25_MV, \
  387. .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
  388. .ramp_delay = S2MPS11_RAMP_DELAY, \
  389. .vsel_reg = S2MPS11_REG_B9CTRL2, \
  390. .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
  391. .enable_reg = S2MPS11_REG_B9CTRL1, \
  392. .enable_mask = S2MPS11_ENABLE_MASK \
  393. }
  394. static const struct regulator_desc s2mps11_regulators[] = {
  395. regulator_desc_s2mps11_ldo(1, STEP_25_MV),
  396. regulator_desc_s2mps11_ldo(2, STEP_50_MV),
  397. regulator_desc_s2mps11_ldo(3, STEP_50_MV),
  398. regulator_desc_s2mps11_ldo(4, STEP_50_MV),
  399. regulator_desc_s2mps11_ldo(5, STEP_50_MV),
  400. regulator_desc_s2mps11_ldo(6, STEP_25_MV),
  401. regulator_desc_s2mps11_ldo(7, STEP_50_MV),
  402. regulator_desc_s2mps11_ldo(8, STEP_50_MV),
  403. regulator_desc_s2mps11_ldo(9, STEP_50_MV),
  404. regulator_desc_s2mps11_ldo(10, STEP_50_MV),
  405. regulator_desc_s2mps11_ldo(11, STEP_25_MV),
  406. regulator_desc_s2mps11_ldo(12, STEP_50_MV),
  407. regulator_desc_s2mps11_ldo(13, STEP_50_MV),
  408. regulator_desc_s2mps11_ldo(14, STEP_50_MV),
  409. regulator_desc_s2mps11_ldo(15, STEP_50_MV),
  410. regulator_desc_s2mps11_ldo(16, STEP_50_MV),
  411. regulator_desc_s2mps11_ldo(17, STEP_50_MV),
  412. regulator_desc_s2mps11_ldo(18, STEP_50_MV),
  413. regulator_desc_s2mps11_ldo(19, STEP_50_MV),
  414. regulator_desc_s2mps11_ldo(20, STEP_50_MV),
  415. regulator_desc_s2mps11_ldo(21, STEP_50_MV),
  416. regulator_desc_s2mps11_ldo(22, STEP_25_MV),
  417. regulator_desc_s2mps11_ldo(23, STEP_25_MV),
  418. regulator_desc_s2mps11_ldo(24, STEP_50_MV),
  419. regulator_desc_s2mps11_ldo(25, STEP_50_MV),
  420. regulator_desc_s2mps11_ldo(26, STEP_50_MV),
  421. regulator_desc_s2mps11_ldo(27, STEP_25_MV),
  422. regulator_desc_s2mps11_ldo(28, STEP_50_MV),
  423. regulator_desc_s2mps11_ldo(29, STEP_50_MV),
  424. regulator_desc_s2mps11_ldo(30, STEP_50_MV),
  425. regulator_desc_s2mps11_ldo(31, STEP_50_MV),
  426. regulator_desc_s2mps11_ldo(32, STEP_50_MV),
  427. regulator_desc_s2mps11_ldo(33, STEP_50_MV),
  428. regulator_desc_s2mps11_ldo(34, STEP_50_MV),
  429. regulator_desc_s2mps11_ldo(35, STEP_25_MV),
  430. regulator_desc_s2mps11_ldo(36, STEP_50_MV),
  431. regulator_desc_s2mps11_ldo(37, STEP_50_MV),
  432. regulator_desc_s2mps11_ldo(38, STEP_50_MV),
  433. regulator_desc_s2mps11_buck1_4(1),
  434. regulator_desc_s2mps11_buck1_4(2),
  435. regulator_desc_s2mps11_buck1_4(3),
  436. regulator_desc_s2mps11_buck1_4(4),
  437. regulator_desc_s2mps11_buck5,
  438. regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
  439. S2MPS11_BUCK12346_N_VOLTAGES),
  440. regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
  441. S2MPS11_BUCK7810_N_VOLTAGES),
  442. regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
  443. S2MPS11_BUCK7810_N_VOLTAGES),
  444. regulator_desc_s2mps11_buck9,
  445. regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
  446. S2MPS11_BUCK7810_N_VOLTAGES),
  447. };
  448. static const struct regulator_ops s2mps14_reg_ops;
  449. #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
  450. .name = "LDO"#num, \
  451. .id = S2MPS13_LDO##num, \
  452. .ops = &s2mps14_reg_ops, \
  453. .type = REGULATOR_VOLTAGE, \
  454. .owner = THIS_MODULE, \
  455. .min_uV = min, \
  456. .uV_step = step, \
  457. .linear_min_sel = min_sel, \
  458. .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
  459. .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
  460. .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
  461. .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
  462. .enable_mask = S2MPS14_ENABLE_MASK \
  463. }
  464. #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
  465. .name = "BUCK"#num, \
  466. .id = S2MPS13_BUCK##num, \
  467. .ops = &s2mps14_reg_ops, \
  468. .type = REGULATOR_VOLTAGE, \
  469. .owner = THIS_MODULE, \
  470. .min_uV = min, \
  471. .uV_step = step, \
  472. .linear_min_sel = min_sel, \
  473. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  474. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  475. .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
  476. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  477. .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
  478. .enable_mask = S2MPS14_ENABLE_MASK \
  479. }
  480. #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
  481. .name = "BUCK"#num, \
  482. .id = S2MPS13_BUCK##num, \
  483. .ops = &s2mps14_reg_ops, \
  484. .type = REGULATOR_VOLTAGE, \
  485. .owner = THIS_MODULE, \
  486. .min_uV = min, \
  487. .uV_step = step, \
  488. .linear_min_sel = min_sel, \
  489. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  490. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  491. .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
  492. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  493. .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
  494. .enable_mask = S2MPS14_ENABLE_MASK \
  495. }
  496. #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
  497. .name = "BUCK"#num, \
  498. .id = S2MPS13_BUCK##num, \
  499. .ops = &s2mps14_reg_ops, \
  500. .type = REGULATOR_VOLTAGE, \
  501. .owner = THIS_MODULE, \
  502. .min_uV = min, \
  503. .uV_step = step, \
  504. .linear_min_sel = min_sel, \
  505. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  506. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  507. .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
  508. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  509. .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
  510. .enable_mask = S2MPS14_ENABLE_MASK \
  511. }
  512. static const struct regulator_desc s2mps13_regulators[] = {
  513. regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
  514. regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
  515. regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
  516. regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
  517. regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
  518. regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
  519. regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
  520. regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
  521. regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
  522. regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
  523. regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
  524. regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
  525. regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
  526. regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
  527. regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
  528. regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
  529. regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
  530. regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
  531. regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
  532. regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
  533. regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
  534. regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
  535. regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
  536. regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
  537. regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
  538. regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
  539. regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
  540. regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
  541. regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
  542. regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
  543. regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
  544. regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
  545. regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
  546. regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
  547. regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
  548. regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
  549. regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
  550. regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
  551. regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
  552. regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
  553. regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
  554. regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
  555. regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
  556. regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
  557. regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
  558. regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
  559. regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
  560. regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
  561. regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
  562. regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
  563. };
  564. static const struct regulator_ops s2mps14_reg_ops = {
  565. .list_voltage = regulator_list_voltage_linear,
  566. .map_voltage = regulator_map_voltage_linear,
  567. .is_enabled = regulator_is_enabled_regmap,
  568. .enable = s2mps11_regulator_enable,
  569. .disable = regulator_disable_regmap,
  570. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  571. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  572. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  573. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  574. };
  575. #define regulator_desc_s2mps14_ldo(num, min, step) { \
  576. .name = "LDO"#num, \
  577. .id = S2MPS14_LDO##num, \
  578. .ops = &s2mps14_reg_ops, \
  579. .type = REGULATOR_VOLTAGE, \
  580. .owner = THIS_MODULE, \
  581. .min_uV = min, \
  582. .uV_step = step, \
  583. .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
  584. .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
  585. .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
  586. .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
  587. .enable_mask = S2MPS14_ENABLE_MASK \
  588. }
  589. #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
  590. .name = "BUCK"#num, \
  591. .id = S2MPS14_BUCK##num, \
  592. .ops = &s2mps14_reg_ops, \
  593. .type = REGULATOR_VOLTAGE, \
  594. .owner = THIS_MODULE, \
  595. .min_uV = min, \
  596. .uV_step = step, \
  597. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  598. .linear_min_sel = min_sel, \
  599. .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
  600. .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
  601. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  602. .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
  603. .enable_mask = S2MPS14_ENABLE_MASK \
  604. }
  605. static const struct regulator_desc s2mps14_regulators[] = {
  606. regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
  607. regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
  608. regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
  609. regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
  610. regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
  611. regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
  612. regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
  613. regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
  614. regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
  615. regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
  616. regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
  617. regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
  618. regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
  619. regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
  620. regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
  621. regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
  622. regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
  623. regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
  624. regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
  625. regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
  626. regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
  627. regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
  628. regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
  629. regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
  630. regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
  631. regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
  632. S2MPS14_BUCK1235_START_SEL),
  633. regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
  634. S2MPS14_BUCK1235_START_SEL),
  635. regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
  636. S2MPS14_BUCK1235_START_SEL),
  637. regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
  638. S2MPS14_BUCK4_START_SEL),
  639. regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
  640. S2MPS14_BUCK1235_START_SEL),
  641. };
  642. static const struct regulator_ops s2mps15_reg_ldo_ops = {
  643. .list_voltage = regulator_list_voltage_linear_range,
  644. .map_voltage = regulator_map_voltage_linear_range,
  645. .is_enabled = regulator_is_enabled_regmap,
  646. .enable = regulator_enable_regmap,
  647. .disable = regulator_disable_regmap,
  648. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  649. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  650. };
  651. static const struct regulator_ops s2mps15_reg_buck_ops = {
  652. .list_voltage = regulator_list_voltage_linear_range,
  653. .map_voltage = regulator_map_voltage_linear_range,
  654. .is_enabled = regulator_is_enabled_regmap,
  655. .enable = regulator_enable_regmap,
  656. .disable = regulator_disable_regmap,
  657. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  658. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  659. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  660. };
  661. #define regulator_desc_s2mps15_ldo(num, range) { \
  662. .name = "LDO"#num, \
  663. .id = S2MPS15_LDO##num, \
  664. .ops = &s2mps15_reg_ldo_ops, \
  665. .type = REGULATOR_VOLTAGE, \
  666. .owner = THIS_MODULE, \
  667. .linear_ranges = range, \
  668. .n_linear_ranges = ARRAY_SIZE(range), \
  669. .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
  670. .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
  671. .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
  672. .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
  673. .enable_mask = S2MPS15_ENABLE_MASK \
  674. }
  675. #define regulator_desc_s2mps15_buck(num, range) { \
  676. .name = "BUCK"#num, \
  677. .id = S2MPS15_BUCK##num, \
  678. .ops = &s2mps15_reg_buck_ops, \
  679. .type = REGULATOR_VOLTAGE, \
  680. .owner = THIS_MODULE, \
  681. .linear_ranges = range, \
  682. .n_linear_ranges = ARRAY_SIZE(range), \
  683. .ramp_delay = 12500, \
  684. .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
  685. .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
  686. .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
  687. .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
  688. .enable_mask = S2MPS15_ENABLE_MASK \
  689. }
  690. /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
  691. static const struct linear_range s2mps15_ldo_voltage_ranges1[] = {
  692. REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
  693. };
  694. /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
  695. static const struct linear_range s2mps15_ldo_voltage_ranges2[] = {
  696. REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
  697. };
  698. /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
  699. static const struct linear_range s2mps15_ldo_voltage_ranges3[] = {
  700. REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
  701. };
  702. /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
  703. static const struct linear_range s2mps15_ldo_voltage_ranges4[] = {
  704. REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
  705. };
  706. /* voltage range for s2mps15 LDO 1 */
  707. static const struct linear_range s2mps15_ldo_voltage_ranges5[] = {
  708. REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
  709. };
  710. /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
  711. static const struct linear_range s2mps15_buck_voltage_ranges1[] = {
  712. REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
  713. };
  714. /* voltage range for s2mps15 BUCK 8, 9 and 10 */
  715. static const struct linear_range s2mps15_buck_voltage_ranges2[] = {
  716. REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
  717. };
  718. static const struct regulator_desc s2mps15_regulators[] = {
  719. regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
  720. regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
  721. regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
  722. regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
  723. regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
  724. regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
  725. regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
  726. regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
  727. regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
  728. regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
  729. regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
  730. regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
  731. regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
  732. regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
  733. regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
  734. regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
  735. regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
  736. regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
  737. regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
  738. regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
  739. regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
  740. regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
  741. regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
  742. regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
  743. regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
  744. regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
  745. regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
  746. regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
  747. regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
  748. regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
  749. regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
  750. regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
  751. regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
  752. regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
  753. regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
  754. regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
  755. regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
  756. };
  757. static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
  758. struct regulator_dev *rdev)
  759. {
  760. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  761. rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
  762. }
  763. static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
  764. struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
  765. {
  766. struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
  767. unsigned int i;
  768. unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
  769. S2MPS14_LDO12 };
  770. for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
  771. unsigned int reg = valid_regulators[i];
  772. if (!rdata[reg].init_data || !rdata[reg].of_node)
  773. continue;
  774. gpio[reg] = devm_fwnode_gpiod_get(&pdev->dev,
  775. of_fwnode_handle(rdata[reg].of_node),
  776. "samsung,ext-control",
  777. GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE,
  778. "s2mps11-regulator");
  779. if (PTR_ERR(gpio[reg]) == -ENOENT)
  780. gpio[reg] = NULL;
  781. else if (IS_ERR(gpio[reg])) {
  782. dev_err(&pdev->dev, "Failed to get control GPIO for %d/%s\n",
  783. reg, rdata[reg].name);
  784. gpio[reg] = NULL;
  785. continue;
  786. }
  787. if (gpio[reg])
  788. dev_dbg(&pdev->dev, "Using GPIO for ext-control over %d/%s\n",
  789. reg, rdata[reg].name);
  790. }
  791. }
  792. static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
  793. struct of_regulator_match *rdata, struct s2mps11_info *s2mps11,
  794. unsigned int rdev_num)
  795. {
  796. struct device_node *reg_np;
  797. reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
  798. if (!reg_np) {
  799. dev_err(&pdev->dev, "could not find regulators sub-node\n");
  800. return -EINVAL;
  801. }
  802. of_regulator_match(&pdev->dev, reg_np, rdata, rdev_num);
  803. if (s2mps11->dev_type == S2MPS14X)
  804. s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);
  805. of_node_put(reg_np);
  806. return 0;
  807. }
  808. static int s2mpu02_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
  809. {
  810. unsigned int ramp_val, ramp_shift, ramp_reg;
  811. int rdev_id = rdev_get_id(rdev);
  812. switch (rdev_id) {
  813. case S2MPU02_BUCK1:
  814. ramp_shift = S2MPU02_BUCK1_RAMP_SHIFT;
  815. break;
  816. case S2MPU02_BUCK2:
  817. ramp_shift = S2MPU02_BUCK2_RAMP_SHIFT;
  818. break;
  819. case S2MPU02_BUCK3:
  820. ramp_shift = S2MPU02_BUCK3_RAMP_SHIFT;
  821. break;
  822. case S2MPU02_BUCK4:
  823. ramp_shift = S2MPU02_BUCK4_RAMP_SHIFT;
  824. break;
  825. default:
  826. return 0;
  827. }
  828. ramp_reg = S2MPU02_REG_RAMP1;
  829. ramp_val = get_ramp_delay(ramp_delay);
  830. return regmap_update_bits(rdev->regmap, ramp_reg,
  831. S2MPU02_BUCK1234_RAMP_MASK << ramp_shift,
  832. ramp_val << ramp_shift);
  833. }
  834. static const struct regulator_ops s2mpu02_ldo_ops = {
  835. .list_voltage = regulator_list_voltage_linear,
  836. .map_voltage = regulator_map_voltage_linear,
  837. .is_enabled = regulator_is_enabled_regmap,
  838. .enable = s2mps11_regulator_enable,
  839. .disable = regulator_disable_regmap,
  840. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  841. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  842. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  843. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  844. };
  845. static const struct regulator_ops s2mpu02_buck_ops = {
  846. .list_voltage = regulator_list_voltage_linear,
  847. .map_voltage = regulator_map_voltage_linear,
  848. .is_enabled = regulator_is_enabled_regmap,
  849. .enable = s2mps11_regulator_enable,
  850. .disable = regulator_disable_regmap,
  851. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  852. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  853. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  854. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  855. .set_ramp_delay = s2mpu02_set_ramp_delay,
  856. };
  857. #define regulator_desc_s2mpu02_ldo1(num) { \
  858. .name = "LDO"#num, \
  859. .id = S2MPU02_LDO##num, \
  860. .ops = &s2mpu02_ldo_ops, \
  861. .type = REGULATOR_VOLTAGE, \
  862. .owner = THIS_MODULE, \
  863. .min_uV = S2MPU02_LDO_MIN_900MV, \
  864. .uV_step = S2MPU02_LDO_STEP_12_5MV, \
  865. .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
  866. .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
  867. .vsel_reg = S2MPU02_REG_L1CTRL, \
  868. .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
  869. .enable_reg = S2MPU02_REG_L1CTRL, \
  870. .enable_mask = S2MPU02_ENABLE_MASK \
  871. }
  872. #define regulator_desc_s2mpu02_ldo2(num) { \
  873. .name = "LDO"#num, \
  874. .id = S2MPU02_LDO##num, \
  875. .ops = &s2mpu02_ldo_ops, \
  876. .type = REGULATOR_VOLTAGE, \
  877. .owner = THIS_MODULE, \
  878. .min_uV = S2MPU02_LDO_MIN_1050MV, \
  879. .uV_step = S2MPU02_LDO_STEP_25MV, \
  880. .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
  881. .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
  882. .vsel_reg = S2MPU02_REG_L2CTRL1, \
  883. .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
  884. .enable_reg = S2MPU02_REG_L2CTRL1, \
  885. .enable_mask = S2MPU02_ENABLE_MASK \
  886. }
  887. #define regulator_desc_s2mpu02_ldo3(num) { \
  888. .name = "LDO"#num, \
  889. .id = S2MPU02_LDO##num, \
  890. .ops = &s2mpu02_ldo_ops, \
  891. .type = REGULATOR_VOLTAGE, \
  892. .owner = THIS_MODULE, \
  893. .min_uV = S2MPU02_LDO_MIN_900MV, \
  894. .uV_step = S2MPU02_LDO_STEP_12_5MV, \
  895. .linear_min_sel = S2MPU02_LDO_GROUP1_START_SEL, \
  896. .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
  897. .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
  898. .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
  899. .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
  900. .enable_mask = S2MPU02_ENABLE_MASK \
  901. }
  902. #define regulator_desc_s2mpu02_ldo4(num) { \
  903. .name = "LDO"#num, \
  904. .id = S2MPU02_LDO##num, \
  905. .ops = &s2mpu02_ldo_ops, \
  906. .type = REGULATOR_VOLTAGE, \
  907. .owner = THIS_MODULE, \
  908. .min_uV = S2MPU02_LDO_MIN_1050MV, \
  909. .uV_step = S2MPU02_LDO_STEP_25MV, \
  910. .linear_min_sel = S2MPU02_LDO_GROUP2_START_SEL, \
  911. .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
  912. .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
  913. .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
  914. .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
  915. .enable_mask = S2MPU02_ENABLE_MASK \
  916. }
  917. #define regulator_desc_s2mpu02_ldo5(num) { \
  918. .name = "LDO"#num, \
  919. .id = S2MPU02_LDO##num, \
  920. .ops = &s2mpu02_ldo_ops, \
  921. .type = REGULATOR_VOLTAGE, \
  922. .owner = THIS_MODULE, \
  923. .min_uV = S2MPU02_LDO_MIN_1600MV, \
  924. .uV_step = S2MPU02_LDO_STEP_50MV, \
  925. .linear_min_sel = S2MPU02_LDO_GROUP3_START_SEL, \
  926. .n_voltages = S2MPU02_LDO_N_VOLTAGES, \
  927. .vsel_reg = S2MPU02_REG_L3CTRL + num - 3, \
  928. .vsel_mask = S2MPU02_LDO_VSEL_MASK, \
  929. .enable_reg = S2MPU02_REG_L3CTRL + num - 3, \
  930. .enable_mask = S2MPU02_ENABLE_MASK \
  931. }
  932. #define regulator_desc_s2mpu02_buck1234(num) { \
  933. .name = "BUCK"#num, \
  934. .id = S2MPU02_BUCK##num, \
  935. .ops = &s2mpu02_buck_ops, \
  936. .type = REGULATOR_VOLTAGE, \
  937. .owner = THIS_MODULE, \
  938. .min_uV = S2MPU02_BUCK1234_MIN_600MV, \
  939. .uV_step = S2MPU02_BUCK1234_STEP_6_25MV, \
  940. .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
  941. .linear_min_sel = S2MPU02_BUCK1234_START_SEL, \
  942. .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
  943. .vsel_reg = S2MPU02_REG_B1CTRL2 + (num - 1) * 2, \
  944. .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
  945. .enable_reg = S2MPU02_REG_B1CTRL1 + (num - 1) * 2, \
  946. .enable_mask = S2MPU02_ENABLE_MASK \
  947. }
  948. #define regulator_desc_s2mpu02_buck5(num) { \
  949. .name = "BUCK"#num, \
  950. .id = S2MPU02_BUCK##num, \
  951. .ops = &s2mpu02_ldo_ops, \
  952. .type = REGULATOR_VOLTAGE, \
  953. .owner = THIS_MODULE, \
  954. .min_uV = S2MPU02_BUCK5_MIN_1081_25MV, \
  955. .uV_step = S2MPU02_BUCK5_STEP_6_25MV, \
  956. .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
  957. .linear_min_sel = S2MPU02_BUCK5_START_SEL, \
  958. .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
  959. .vsel_reg = S2MPU02_REG_B5CTRL2, \
  960. .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
  961. .enable_reg = S2MPU02_REG_B5CTRL1, \
  962. .enable_mask = S2MPU02_ENABLE_MASK \
  963. }
  964. #define regulator_desc_s2mpu02_buck6(num) { \
  965. .name = "BUCK"#num, \
  966. .id = S2MPU02_BUCK##num, \
  967. .ops = &s2mpu02_ldo_ops, \
  968. .type = REGULATOR_VOLTAGE, \
  969. .owner = THIS_MODULE, \
  970. .min_uV = S2MPU02_BUCK6_MIN_1700MV, \
  971. .uV_step = S2MPU02_BUCK6_STEP_2_50MV, \
  972. .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
  973. .linear_min_sel = S2MPU02_BUCK6_START_SEL, \
  974. .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
  975. .vsel_reg = S2MPU02_REG_B6CTRL2, \
  976. .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
  977. .enable_reg = S2MPU02_REG_B6CTRL1, \
  978. .enable_mask = S2MPU02_ENABLE_MASK \
  979. }
  980. #define regulator_desc_s2mpu02_buck7(num) { \
  981. .name = "BUCK"#num, \
  982. .id = S2MPU02_BUCK##num, \
  983. .ops = &s2mpu02_ldo_ops, \
  984. .type = REGULATOR_VOLTAGE, \
  985. .owner = THIS_MODULE, \
  986. .min_uV = S2MPU02_BUCK7_MIN_900MV, \
  987. .uV_step = S2MPU02_BUCK7_STEP_6_25MV, \
  988. .n_voltages = S2MPU02_BUCK_N_VOLTAGES, \
  989. .linear_min_sel = S2MPU02_BUCK7_START_SEL, \
  990. .ramp_delay = S2MPU02_BUCK_RAMP_DELAY, \
  991. .vsel_reg = S2MPU02_REG_B7CTRL2, \
  992. .vsel_mask = S2MPU02_BUCK_VSEL_MASK, \
  993. .enable_reg = S2MPU02_REG_B7CTRL1, \
  994. .enable_mask = S2MPU02_ENABLE_MASK \
  995. }
  996. static const struct regulator_desc s2mpu02_regulators[] = {
  997. regulator_desc_s2mpu02_ldo1(1),
  998. regulator_desc_s2mpu02_ldo2(2),
  999. regulator_desc_s2mpu02_ldo4(3),
  1000. regulator_desc_s2mpu02_ldo5(4),
  1001. regulator_desc_s2mpu02_ldo4(5),
  1002. regulator_desc_s2mpu02_ldo3(6),
  1003. regulator_desc_s2mpu02_ldo3(7),
  1004. regulator_desc_s2mpu02_ldo4(8),
  1005. regulator_desc_s2mpu02_ldo5(9),
  1006. regulator_desc_s2mpu02_ldo3(10),
  1007. regulator_desc_s2mpu02_ldo4(11),
  1008. regulator_desc_s2mpu02_ldo5(12),
  1009. regulator_desc_s2mpu02_ldo5(13),
  1010. regulator_desc_s2mpu02_ldo5(14),
  1011. regulator_desc_s2mpu02_ldo5(15),
  1012. regulator_desc_s2mpu02_ldo5(16),
  1013. regulator_desc_s2mpu02_ldo4(17),
  1014. regulator_desc_s2mpu02_ldo5(18),
  1015. regulator_desc_s2mpu02_ldo3(19),
  1016. regulator_desc_s2mpu02_ldo4(20),
  1017. regulator_desc_s2mpu02_ldo5(21),
  1018. regulator_desc_s2mpu02_ldo5(22),
  1019. regulator_desc_s2mpu02_ldo5(23),
  1020. regulator_desc_s2mpu02_ldo4(24),
  1021. regulator_desc_s2mpu02_ldo5(25),
  1022. regulator_desc_s2mpu02_ldo4(26),
  1023. regulator_desc_s2mpu02_ldo5(27),
  1024. regulator_desc_s2mpu02_ldo5(28),
  1025. regulator_desc_s2mpu02_buck1234(1),
  1026. regulator_desc_s2mpu02_buck1234(2),
  1027. regulator_desc_s2mpu02_buck1234(3),
  1028. regulator_desc_s2mpu02_buck1234(4),
  1029. regulator_desc_s2mpu02_buck5(5),
  1030. regulator_desc_s2mpu02_buck6(6),
  1031. regulator_desc_s2mpu02_buck7(7),
  1032. };
  1033. static int s2mps11_pmic_probe(struct platform_device *pdev)
  1034. {
  1035. struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
  1036. struct regulator_config config = { };
  1037. struct s2mps11_info *s2mps11;
  1038. unsigned int rdev_num = 0;
  1039. int i, ret = 0;
  1040. const struct regulator_desc *regulators;
  1041. s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
  1042. GFP_KERNEL);
  1043. if (!s2mps11)
  1044. return -ENOMEM;
  1045. s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
  1046. switch (s2mps11->dev_type) {
  1047. case S2MPS11X:
  1048. rdev_num = ARRAY_SIZE(s2mps11_regulators);
  1049. regulators = s2mps11_regulators;
  1050. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
  1051. break;
  1052. case S2MPS13X:
  1053. rdev_num = ARRAY_SIZE(s2mps13_regulators);
  1054. regulators = s2mps13_regulators;
  1055. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
  1056. break;
  1057. case S2MPS14X:
  1058. rdev_num = ARRAY_SIZE(s2mps14_regulators);
  1059. regulators = s2mps14_regulators;
  1060. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
  1061. break;
  1062. case S2MPS15X:
  1063. rdev_num = ARRAY_SIZE(s2mps15_regulators);
  1064. regulators = s2mps15_regulators;
  1065. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
  1066. break;
  1067. case S2MPU02:
  1068. rdev_num = ARRAY_SIZE(s2mpu02_regulators);
  1069. regulators = s2mpu02_regulators;
  1070. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
  1071. break;
  1072. default:
  1073. dev_err(&pdev->dev, "Invalid device type: %u\n",
  1074. s2mps11->dev_type);
  1075. return -EINVAL;
  1076. }
  1077. s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
  1078. sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
  1079. if (!s2mps11->ext_control_gpiod)
  1080. return -ENOMEM;
  1081. struct of_regulator_match *rdata __free(kfree) =
  1082. kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
  1083. if (!rdata)
  1084. return -ENOMEM;
  1085. for (i = 0; i < rdev_num; i++)
  1086. rdata[i].name = regulators[i].name;
  1087. ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
  1088. if (ret)
  1089. return ret;
  1090. platform_set_drvdata(pdev, s2mps11);
  1091. config.dev = &pdev->dev;
  1092. config.regmap = iodev->regmap_pmic;
  1093. config.driver_data = s2mps11;
  1094. for (i = 0; i < rdev_num; i++) {
  1095. struct regulator_dev *regulator;
  1096. config.init_data = rdata[i].init_data;
  1097. config.of_node = rdata[i].of_node;
  1098. config.ena_gpiod = s2mps11->ext_control_gpiod[i];
  1099. /*
  1100. * Hand the GPIO descriptor management over to the regulator
  1101. * core, remove it from devres management.
  1102. */
  1103. if (config.ena_gpiod)
  1104. devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
  1105. regulator = devm_regulator_register(&pdev->dev,
  1106. &regulators[i], &config);
  1107. if (IS_ERR(regulator)) {
  1108. dev_err(&pdev->dev, "regulator init failed for %d\n",
  1109. i);
  1110. return PTR_ERR(regulator);
  1111. }
  1112. if (config.ena_gpiod) {
  1113. ret = s2mps14_pmic_enable_ext_control(s2mps11,
  1114. regulator);
  1115. if (ret < 0) {
  1116. dev_err(&pdev->dev,
  1117. "failed to enable GPIO control over %s: %d\n",
  1118. regulator->desc->name, ret);
  1119. return ret;
  1120. }
  1121. }
  1122. }
  1123. return 0;
  1124. }
  1125. static const struct platform_device_id s2mps11_pmic_id[] = {
  1126. { "s2mps11-regulator", S2MPS11X},
  1127. { "s2mps13-regulator", S2MPS13X},
  1128. { "s2mps14-regulator", S2MPS14X},
  1129. { "s2mps15-regulator", S2MPS15X},
  1130. { "s2mpu02-regulator", S2MPU02},
  1131. { },
  1132. };
  1133. MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
  1134. static struct platform_driver s2mps11_pmic_driver = {
  1135. .driver = {
  1136. .name = "s2mps11-pmic",
  1137. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  1138. },
  1139. .probe = s2mps11_pmic_probe,
  1140. .id_table = s2mps11_pmic_id,
  1141. };
  1142. module_platform_driver(s2mps11_pmic_driver);
  1143. /* Module information */
  1144. MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
  1145. MODULE_DESCRIPTION("Samsung S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
  1146. MODULE_LICENSE("GPL");