s2mps11.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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/err.h>
  7. #include <linux/gpio/consumer.h>
  8. #include <linux/slab.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/regmap.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regulator/driver.h>
  14. #include <linux/regulator/machine.h>
  15. #include <linux/regulator/of_regulator.h>
  16. #include <linux/mfd/samsung/core.h>
  17. #include <linux/mfd/samsung/s2mps11.h>
  18. #include <linux/mfd/samsung/s2mps13.h>
  19. #include <linux/mfd/samsung/s2mps14.h>
  20. #include <linux/mfd/samsung/s2mps15.h>
  21. #include <linux/mfd/samsung/s2mpu02.h>
  22. /* The highest number of possible regulators for supported devices. */
  23. #define S2MPS_REGULATOR_MAX S2MPS13_REGULATOR_MAX
  24. struct s2mps11_info {
  25. int ramp_delay2;
  26. int ramp_delay34;
  27. int ramp_delay5;
  28. int ramp_delay16;
  29. int ramp_delay7810;
  30. int ramp_delay9;
  31. enum sec_device_type dev_type;
  32. /*
  33. * One bit for each S2MPS11/S2MPS13/S2MPS14/S2MPU02 regulator whether
  34. * the suspend mode was enabled.
  35. */
  36. DECLARE_BITMAP(suspend_state, S2MPS_REGULATOR_MAX);
  37. /*
  38. * Array (size: number of regulators) with GPIO-s for external
  39. * sleep control.
  40. */
  41. struct gpio_desc **ext_control_gpiod;
  42. };
  43. static int get_ramp_delay(int ramp_delay)
  44. {
  45. unsigned char cnt = 0;
  46. ramp_delay /= 6250;
  47. while (true) {
  48. ramp_delay = ramp_delay >> 1;
  49. if (ramp_delay == 0)
  50. break;
  51. cnt++;
  52. }
  53. if (cnt > 3)
  54. cnt = 3;
  55. return cnt;
  56. }
  57. static int s2mps11_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
  58. unsigned int old_selector,
  59. unsigned int new_selector)
  60. {
  61. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  62. int rdev_id = rdev_get_id(rdev);
  63. unsigned int ramp_delay = 0;
  64. int old_volt, new_volt;
  65. switch (rdev_id) {
  66. case S2MPS11_BUCK2:
  67. ramp_delay = s2mps11->ramp_delay2;
  68. break;
  69. case S2MPS11_BUCK3:
  70. case S2MPS11_BUCK4:
  71. ramp_delay = s2mps11->ramp_delay34;
  72. break;
  73. case S2MPS11_BUCK5:
  74. ramp_delay = s2mps11->ramp_delay5;
  75. break;
  76. case S2MPS11_BUCK6:
  77. case S2MPS11_BUCK1:
  78. ramp_delay = s2mps11->ramp_delay16;
  79. break;
  80. case S2MPS11_BUCK7:
  81. case S2MPS11_BUCK8:
  82. case S2MPS11_BUCK10:
  83. ramp_delay = s2mps11->ramp_delay7810;
  84. break;
  85. case S2MPS11_BUCK9:
  86. ramp_delay = s2mps11->ramp_delay9;
  87. }
  88. if (ramp_delay == 0)
  89. ramp_delay = rdev->desc->ramp_delay;
  90. old_volt = rdev->desc->min_uV + (rdev->desc->uV_step * old_selector);
  91. new_volt = rdev->desc->min_uV + (rdev->desc->uV_step * new_selector);
  92. return DIV_ROUND_UP(abs(new_volt - old_volt), ramp_delay);
  93. }
  94. static int s2mps11_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
  95. {
  96. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  97. unsigned int ramp_val, ramp_shift, ramp_reg = S2MPS11_REG_RAMP_BUCK;
  98. unsigned int ramp_enable = 1, enable_shift = 0;
  99. int rdev_id = rdev_get_id(rdev);
  100. int ret;
  101. switch (rdev_id) {
  102. case S2MPS11_BUCK1:
  103. if (ramp_delay > s2mps11->ramp_delay16)
  104. s2mps11->ramp_delay16 = ramp_delay;
  105. else
  106. ramp_delay = s2mps11->ramp_delay16;
  107. ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
  108. break;
  109. case S2MPS11_BUCK2:
  110. enable_shift = S2MPS11_BUCK2_RAMP_EN_SHIFT;
  111. if (!ramp_delay) {
  112. ramp_enable = 0;
  113. break;
  114. }
  115. s2mps11->ramp_delay2 = ramp_delay;
  116. ramp_shift = S2MPS11_BUCK2_RAMP_SHIFT;
  117. ramp_reg = S2MPS11_REG_RAMP;
  118. break;
  119. case S2MPS11_BUCK3:
  120. enable_shift = S2MPS11_BUCK3_RAMP_EN_SHIFT;
  121. if (!ramp_delay) {
  122. ramp_enable = 0;
  123. break;
  124. }
  125. if (ramp_delay > s2mps11->ramp_delay34)
  126. s2mps11->ramp_delay34 = ramp_delay;
  127. else
  128. ramp_delay = s2mps11->ramp_delay34;
  129. ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
  130. ramp_reg = S2MPS11_REG_RAMP;
  131. break;
  132. case S2MPS11_BUCK4:
  133. enable_shift = S2MPS11_BUCK4_RAMP_EN_SHIFT;
  134. if (!ramp_delay) {
  135. ramp_enable = 0;
  136. break;
  137. }
  138. if (ramp_delay > s2mps11->ramp_delay34)
  139. s2mps11->ramp_delay34 = ramp_delay;
  140. else
  141. ramp_delay = s2mps11->ramp_delay34;
  142. ramp_shift = S2MPS11_BUCK34_RAMP_SHIFT;
  143. ramp_reg = S2MPS11_REG_RAMP;
  144. break;
  145. case S2MPS11_BUCK5:
  146. s2mps11->ramp_delay5 = ramp_delay;
  147. ramp_shift = S2MPS11_BUCK5_RAMP_SHIFT;
  148. break;
  149. case S2MPS11_BUCK6:
  150. enable_shift = S2MPS11_BUCK6_RAMP_EN_SHIFT;
  151. if (!ramp_delay) {
  152. ramp_enable = 0;
  153. break;
  154. }
  155. if (ramp_delay > s2mps11->ramp_delay16)
  156. s2mps11->ramp_delay16 = ramp_delay;
  157. else
  158. ramp_delay = s2mps11->ramp_delay16;
  159. ramp_shift = S2MPS11_BUCK16_RAMP_SHIFT;
  160. break;
  161. case S2MPS11_BUCK7:
  162. case S2MPS11_BUCK8:
  163. case S2MPS11_BUCK10:
  164. if (ramp_delay > s2mps11->ramp_delay7810)
  165. s2mps11->ramp_delay7810 = ramp_delay;
  166. else
  167. ramp_delay = s2mps11->ramp_delay7810;
  168. ramp_shift = S2MPS11_BUCK7810_RAMP_SHIFT;
  169. break;
  170. case S2MPS11_BUCK9:
  171. s2mps11->ramp_delay9 = ramp_delay;
  172. ramp_shift = S2MPS11_BUCK9_RAMP_SHIFT;
  173. break;
  174. default:
  175. return 0;
  176. }
  177. if (!ramp_enable)
  178. goto ramp_disable;
  179. /* Ramp delay can be enabled/disabled only for buck[2346] */
  180. if ((rdev_id >= S2MPS11_BUCK2 && rdev_id <= S2MPS11_BUCK4) ||
  181. rdev_id == S2MPS11_BUCK6) {
  182. ret = regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
  183. 1 << enable_shift, 1 << enable_shift);
  184. if (ret) {
  185. dev_err(&rdev->dev, "failed to enable ramp rate\n");
  186. return ret;
  187. }
  188. }
  189. ramp_val = get_ramp_delay(ramp_delay);
  190. return regmap_update_bits(rdev->regmap, ramp_reg, 0x3 << ramp_shift,
  191. ramp_val << ramp_shift);
  192. ramp_disable:
  193. return regmap_update_bits(rdev->regmap, S2MPS11_REG_RAMP,
  194. 1 << enable_shift, 0);
  195. }
  196. static int s2mps11_regulator_enable(struct regulator_dev *rdev)
  197. {
  198. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  199. int rdev_id = rdev_get_id(rdev);
  200. unsigned int val;
  201. switch (s2mps11->dev_type) {
  202. case S2MPS11X:
  203. if (test_bit(rdev_id, s2mps11->suspend_state))
  204. val = S2MPS14_ENABLE_SUSPEND;
  205. else
  206. val = rdev->desc->enable_mask;
  207. break;
  208. case S2MPS13X:
  209. case S2MPS14X:
  210. if (test_bit(rdev_id, s2mps11->suspend_state))
  211. val = S2MPS14_ENABLE_SUSPEND;
  212. else if (s2mps11->ext_control_gpiod[rdev_id])
  213. val = S2MPS14_ENABLE_EXT_CONTROL;
  214. else
  215. val = rdev->desc->enable_mask;
  216. break;
  217. case S2MPU02:
  218. if (test_bit(rdev_id, s2mps11->suspend_state))
  219. val = S2MPU02_ENABLE_SUSPEND;
  220. else
  221. val = rdev->desc->enable_mask;
  222. break;
  223. default:
  224. return -EINVAL;
  225. }
  226. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  227. rdev->desc->enable_mask, val);
  228. }
  229. static int s2mps11_regulator_set_suspend_disable(struct regulator_dev *rdev)
  230. {
  231. int ret;
  232. unsigned int val, state;
  233. struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
  234. int rdev_id = rdev_get_id(rdev);
  235. /* Below LDO should be always on or does not support suspend mode. */
  236. switch (s2mps11->dev_type) {
  237. case S2MPS11X:
  238. switch (rdev_id) {
  239. case S2MPS11_LDO2:
  240. case S2MPS11_LDO36:
  241. case S2MPS11_LDO37:
  242. case S2MPS11_LDO38:
  243. return 0;
  244. default:
  245. state = S2MPS14_ENABLE_SUSPEND;
  246. break;
  247. }
  248. break;
  249. case S2MPS13X:
  250. case S2MPS14X:
  251. switch (rdev_id) {
  252. case S2MPS14_LDO3:
  253. return 0;
  254. default:
  255. state = S2MPS14_ENABLE_SUSPEND;
  256. break;
  257. }
  258. break;
  259. case S2MPU02:
  260. switch (rdev_id) {
  261. case S2MPU02_LDO13:
  262. case S2MPU02_LDO14:
  263. case S2MPU02_LDO15:
  264. case S2MPU02_LDO17:
  265. case S2MPU02_BUCK7:
  266. state = S2MPU02_DISABLE_SUSPEND;
  267. break;
  268. default:
  269. state = S2MPU02_ENABLE_SUSPEND;
  270. break;
  271. }
  272. break;
  273. default:
  274. return -EINVAL;
  275. }
  276. ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
  277. if (ret < 0)
  278. return ret;
  279. set_bit(rdev_id, s2mps11->suspend_state);
  280. /*
  281. * Don't enable suspend mode if regulator is already disabled because
  282. * this would effectively for a short time turn on the regulator after
  283. * resuming.
  284. * However we still want to toggle the suspend_state bit for regulator
  285. * in case if it got enabled before suspending the system.
  286. */
  287. if (!(val & rdev->desc->enable_mask))
  288. return 0;
  289. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  290. rdev->desc->enable_mask, state);
  291. }
  292. static const struct regulator_ops s2mps11_ldo_ops = {
  293. .list_voltage = regulator_list_voltage_linear,
  294. .map_voltage = regulator_map_voltage_linear,
  295. .is_enabled = regulator_is_enabled_regmap,
  296. .enable = s2mps11_regulator_enable,
  297. .disable = regulator_disable_regmap,
  298. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  299. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  300. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  301. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  302. };
  303. static const struct regulator_ops s2mps11_buck_ops = {
  304. .list_voltage = regulator_list_voltage_linear,
  305. .map_voltage = regulator_map_voltage_linear,
  306. .is_enabled = regulator_is_enabled_regmap,
  307. .enable = s2mps11_regulator_enable,
  308. .disable = regulator_disable_regmap,
  309. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  310. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  311. .set_voltage_time_sel = s2mps11_regulator_set_voltage_time_sel,
  312. .set_ramp_delay = s2mps11_set_ramp_delay,
  313. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  314. };
  315. #define regulator_desc_s2mps11_ldo(num, step) { \
  316. .name = "LDO"#num, \
  317. .id = S2MPS11_LDO##num, \
  318. .ops = &s2mps11_ldo_ops, \
  319. .type = REGULATOR_VOLTAGE, \
  320. .owner = THIS_MODULE, \
  321. .ramp_delay = RAMP_DELAY_12_MVUS, \
  322. .min_uV = MIN_800_MV, \
  323. .uV_step = step, \
  324. .n_voltages = S2MPS11_LDO_N_VOLTAGES, \
  325. .vsel_reg = S2MPS11_REG_L1CTRL + num - 1, \
  326. .vsel_mask = S2MPS11_LDO_VSEL_MASK, \
  327. .enable_reg = S2MPS11_REG_L1CTRL + num - 1, \
  328. .enable_mask = S2MPS11_ENABLE_MASK \
  329. }
  330. #define regulator_desc_s2mps11_buck1_4(num) { \
  331. .name = "BUCK"#num, \
  332. .id = S2MPS11_BUCK##num, \
  333. .ops = &s2mps11_buck_ops, \
  334. .type = REGULATOR_VOLTAGE, \
  335. .owner = THIS_MODULE, \
  336. .min_uV = MIN_650_MV, \
  337. .uV_step = STEP_6_25_MV, \
  338. .linear_min_sel = 8, \
  339. .n_voltages = S2MPS11_BUCK12346_N_VOLTAGES, \
  340. .ramp_delay = S2MPS11_RAMP_DELAY, \
  341. .vsel_reg = S2MPS11_REG_B1CTRL2 + (num - 1) * 2, \
  342. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  343. .enable_reg = S2MPS11_REG_B1CTRL1 + (num - 1) * 2, \
  344. .enable_mask = S2MPS11_ENABLE_MASK \
  345. }
  346. #define regulator_desc_s2mps11_buck5 { \
  347. .name = "BUCK5", \
  348. .id = S2MPS11_BUCK5, \
  349. .ops = &s2mps11_buck_ops, \
  350. .type = REGULATOR_VOLTAGE, \
  351. .owner = THIS_MODULE, \
  352. .min_uV = MIN_650_MV, \
  353. .uV_step = STEP_6_25_MV, \
  354. .linear_min_sel = 8, \
  355. .n_voltages = S2MPS11_BUCK5_N_VOLTAGES, \
  356. .ramp_delay = S2MPS11_RAMP_DELAY, \
  357. .vsel_reg = S2MPS11_REG_B5CTRL2, \
  358. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  359. .enable_reg = S2MPS11_REG_B5CTRL1, \
  360. .enable_mask = S2MPS11_ENABLE_MASK \
  361. }
  362. #define regulator_desc_s2mps11_buck67810(num, min, step, min_sel, voltages) { \
  363. .name = "BUCK"#num, \
  364. .id = S2MPS11_BUCK##num, \
  365. .ops = &s2mps11_buck_ops, \
  366. .type = REGULATOR_VOLTAGE, \
  367. .owner = THIS_MODULE, \
  368. .min_uV = min, \
  369. .uV_step = step, \
  370. .linear_min_sel = min_sel, \
  371. .n_voltages = voltages, \
  372. .ramp_delay = S2MPS11_RAMP_DELAY, \
  373. .vsel_reg = S2MPS11_REG_B6CTRL2 + (num - 6) * 2, \
  374. .vsel_mask = S2MPS11_BUCK_VSEL_MASK, \
  375. .enable_reg = S2MPS11_REG_B6CTRL1 + (num - 6) * 2, \
  376. .enable_mask = S2MPS11_ENABLE_MASK \
  377. }
  378. #define regulator_desc_s2mps11_buck9 { \
  379. .name = "BUCK9", \
  380. .id = S2MPS11_BUCK9, \
  381. .ops = &s2mps11_buck_ops, \
  382. .type = REGULATOR_VOLTAGE, \
  383. .owner = THIS_MODULE, \
  384. .min_uV = MIN_3000_MV, \
  385. .uV_step = STEP_25_MV, \
  386. .n_voltages = S2MPS11_BUCK9_N_VOLTAGES, \
  387. .ramp_delay = S2MPS11_RAMP_DELAY, \
  388. .vsel_reg = S2MPS11_REG_B9CTRL2, \
  389. .vsel_mask = S2MPS11_BUCK9_VSEL_MASK, \
  390. .enable_reg = S2MPS11_REG_B9CTRL1, \
  391. .enable_mask = S2MPS11_ENABLE_MASK \
  392. }
  393. static const struct regulator_desc s2mps11_regulators[] = {
  394. regulator_desc_s2mps11_ldo(1, STEP_25_MV),
  395. regulator_desc_s2mps11_ldo(2, STEP_50_MV),
  396. regulator_desc_s2mps11_ldo(3, STEP_50_MV),
  397. regulator_desc_s2mps11_ldo(4, STEP_50_MV),
  398. regulator_desc_s2mps11_ldo(5, STEP_50_MV),
  399. regulator_desc_s2mps11_ldo(6, STEP_25_MV),
  400. regulator_desc_s2mps11_ldo(7, STEP_50_MV),
  401. regulator_desc_s2mps11_ldo(8, STEP_50_MV),
  402. regulator_desc_s2mps11_ldo(9, STEP_50_MV),
  403. regulator_desc_s2mps11_ldo(10, STEP_50_MV),
  404. regulator_desc_s2mps11_ldo(11, STEP_25_MV),
  405. regulator_desc_s2mps11_ldo(12, STEP_50_MV),
  406. regulator_desc_s2mps11_ldo(13, STEP_50_MV),
  407. regulator_desc_s2mps11_ldo(14, STEP_50_MV),
  408. regulator_desc_s2mps11_ldo(15, STEP_50_MV),
  409. regulator_desc_s2mps11_ldo(16, STEP_50_MV),
  410. regulator_desc_s2mps11_ldo(17, STEP_50_MV),
  411. regulator_desc_s2mps11_ldo(18, STEP_50_MV),
  412. regulator_desc_s2mps11_ldo(19, STEP_50_MV),
  413. regulator_desc_s2mps11_ldo(20, STEP_50_MV),
  414. regulator_desc_s2mps11_ldo(21, STEP_50_MV),
  415. regulator_desc_s2mps11_ldo(22, STEP_25_MV),
  416. regulator_desc_s2mps11_ldo(23, STEP_25_MV),
  417. regulator_desc_s2mps11_ldo(24, STEP_50_MV),
  418. regulator_desc_s2mps11_ldo(25, STEP_50_MV),
  419. regulator_desc_s2mps11_ldo(26, STEP_50_MV),
  420. regulator_desc_s2mps11_ldo(27, STEP_25_MV),
  421. regulator_desc_s2mps11_ldo(28, STEP_50_MV),
  422. regulator_desc_s2mps11_ldo(29, STEP_50_MV),
  423. regulator_desc_s2mps11_ldo(30, STEP_50_MV),
  424. regulator_desc_s2mps11_ldo(31, STEP_50_MV),
  425. regulator_desc_s2mps11_ldo(32, STEP_50_MV),
  426. regulator_desc_s2mps11_ldo(33, STEP_50_MV),
  427. regulator_desc_s2mps11_ldo(34, STEP_50_MV),
  428. regulator_desc_s2mps11_ldo(35, STEP_25_MV),
  429. regulator_desc_s2mps11_ldo(36, STEP_50_MV),
  430. regulator_desc_s2mps11_ldo(37, STEP_50_MV),
  431. regulator_desc_s2mps11_ldo(38, STEP_50_MV),
  432. regulator_desc_s2mps11_buck1_4(1),
  433. regulator_desc_s2mps11_buck1_4(2),
  434. regulator_desc_s2mps11_buck1_4(3),
  435. regulator_desc_s2mps11_buck1_4(4),
  436. regulator_desc_s2mps11_buck5,
  437. regulator_desc_s2mps11_buck67810(6, MIN_650_MV, STEP_6_25_MV, 8,
  438. S2MPS11_BUCK12346_N_VOLTAGES),
  439. regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV, 0,
  440. S2MPS11_BUCK7810_N_VOLTAGES),
  441. regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV, 0,
  442. S2MPS11_BUCK7810_N_VOLTAGES),
  443. regulator_desc_s2mps11_buck9,
  444. regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV, 0,
  445. S2MPS11_BUCK7810_N_VOLTAGES),
  446. };
  447. static const struct regulator_ops s2mps14_reg_ops;
  448. #define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
  449. .name = "LDO"#num, \
  450. .id = S2MPS13_LDO##num, \
  451. .ops = &s2mps14_reg_ops, \
  452. .type = REGULATOR_VOLTAGE, \
  453. .owner = THIS_MODULE, \
  454. .min_uV = min, \
  455. .uV_step = step, \
  456. .linear_min_sel = min_sel, \
  457. .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
  458. .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
  459. .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
  460. .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
  461. .enable_mask = S2MPS14_ENABLE_MASK \
  462. }
  463. #define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
  464. .name = "BUCK"#num, \
  465. .id = S2MPS13_BUCK##num, \
  466. .ops = &s2mps14_reg_ops, \
  467. .type = REGULATOR_VOLTAGE, \
  468. .owner = THIS_MODULE, \
  469. .min_uV = min, \
  470. .uV_step = step, \
  471. .linear_min_sel = min_sel, \
  472. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  473. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  474. .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
  475. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  476. .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
  477. .enable_mask = S2MPS14_ENABLE_MASK \
  478. }
  479. #define regulator_desc_s2mps13_buck7(num, min, step, min_sel) { \
  480. .name = "BUCK"#num, \
  481. .id = S2MPS13_BUCK##num, \
  482. .ops = &s2mps14_reg_ops, \
  483. .type = REGULATOR_VOLTAGE, \
  484. .owner = THIS_MODULE, \
  485. .min_uV = min, \
  486. .uV_step = step, \
  487. .linear_min_sel = min_sel, \
  488. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  489. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  490. .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
  491. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  492. .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
  493. .enable_mask = S2MPS14_ENABLE_MASK \
  494. }
  495. #define regulator_desc_s2mps13_buck8_10(num, min, step, min_sel) { \
  496. .name = "BUCK"#num, \
  497. .id = S2MPS13_BUCK##num, \
  498. .ops = &s2mps14_reg_ops, \
  499. .type = REGULATOR_VOLTAGE, \
  500. .owner = THIS_MODULE, \
  501. .min_uV = min, \
  502. .uV_step = step, \
  503. .linear_min_sel = min_sel, \
  504. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  505. .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
  506. .vsel_reg = S2MPS13_REG_B1OUT + (num) * 2 - 1, \
  507. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  508. .enable_reg = S2MPS13_REG_B1CTRL + (num) * 2 - 1, \
  509. .enable_mask = S2MPS14_ENABLE_MASK \
  510. }
  511. static const struct regulator_desc s2mps13_regulators[] = {
  512. regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
  513. regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
  514. regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
  515. regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
  516. regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
  517. regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
  518. regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
  519. regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
  520. regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
  521. regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
  522. regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
  523. regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
  524. regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
  525. regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
  526. regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
  527. regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
  528. regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
  529. regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
  530. regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
  531. regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
  532. regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
  533. regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
  534. regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
  535. regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
  536. regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
  537. regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
  538. regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
  539. regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
  540. regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
  541. regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
  542. regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
  543. regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
  544. regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
  545. regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
  546. regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
  547. regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
  548. regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
  549. regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
  550. regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
  551. regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
  552. regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
  553. regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
  554. regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
  555. regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
  556. regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
  557. regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
  558. regulator_desc_s2mps13_buck7(7, MIN_500_MV, STEP_6_25_MV, 0x10),
  559. regulator_desc_s2mps13_buck8_10(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
  560. regulator_desc_s2mps13_buck8_10(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
  561. regulator_desc_s2mps13_buck8_10(10, MIN_500_MV, STEP_6_25_MV, 0x10),
  562. };
  563. static const struct regulator_ops s2mps14_reg_ops = {
  564. .list_voltage = regulator_list_voltage_linear,
  565. .map_voltage = regulator_map_voltage_linear,
  566. .is_enabled = regulator_is_enabled_regmap,
  567. .enable = s2mps11_regulator_enable,
  568. .disable = regulator_disable_regmap,
  569. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  570. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  571. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  572. .set_suspend_disable = s2mps11_regulator_set_suspend_disable,
  573. };
  574. #define regulator_desc_s2mps14_ldo(num, min, step) { \
  575. .name = "LDO"#num, \
  576. .id = S2MPS14_LDO##num, \
  577. .ops = &s2mps14_reg_ops, \
  578. .type = REGULATOR_VOLTAGE, \
  579. .owner = THIS_MODULE, \
  580. .min_uV = min, \
  581. .uV_step = step, \
  582. .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
  583. .vsel_reg = S2MPS14_REG_L1CTRL + num - 1, \
  584. .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
  585. .enable_reg = S2MPS14_REG_L1CTRL + num - 1, \
  586. .enable_mask = S2MPS14_ENABLE_MASK \
  587. }
  588. #define regulator_desc_s2mps14_buck(num, min, step, min_sel) { \
  589. .name = "BUCK"#num, \
  590. .id = S2MPS14_BUCK##num, \
  591. .ops = &s2mps14_reg_ops, \
  592. .type = REGULATOR_VOLTAGE, \
  593. .owner = THIS_MODULE, \
  594. .min_uV = min, \
  595. .uV_step = step, \
  596. .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
  597. .linear_min_sel = min_sel, \
  598. .ramp_delay = S2MPS14_BUCK_RAMP_DELAY, \
  599. .vsel_reg = S2MPS14_REG_B1CTRL2 + (num - 1) * 2, \
  600. .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
  601. .enable_reg = S2MPS14_REG_B1CTRL1 + (num - 1) * 2, \
  602. .enable_mask = S2MPS14_ENABLE_MASK \
  603. }
  604. static const struct regulator_desc s2mps14_regulators[] = {
  605. regulator_desc_s2mps14_ldo(1, MIN_800_MV, STEP_12_5_MV),
  606. regulator_desc_s2mps14_ldo(2, MIN_800_MV, STEP_12_5_MV),
  607. regulator_desc_s2mps14_ldo(3, MIN_800_MV, STEP_25_MV),
  608. regulator_desc_s2mps14_ldo(4, MIN_800_MV, STEP_25_MV),
  609. regulator_desc_s2mps14_ldo(5, MIN_800_MV, STEP_12_5_MV),
  610. regulator_desc_s2mps14_ldo(6, MIN_800_MV, STEP_12_5_MV),
  611. regulator_desc_s2mps14_ldo(7, MIN_800_MV, STEP_25_MV),
  612. regulator_desc_s2mps14_ldo(8, MIN_1800_MV, STEP_25_MV),
  613. regulator_desc_s2mps14_ldo(9, MIN_800_MV, STEP_12_5_MV),
  614. regulator_desc_s2mps14_ldo(10, MIN_800_MV, STEP_12_5_MV),
  615. regulator_desc_s2mps14_ldo(11, MIN_800_MV, STEP_25_MV),
  616. regulator_desc_s2mps14_ldo(12, MIN_1800_MV, STEP_25_MV),
  617. regulator_desc_s2mps14_ldo(13, MIN_1800_MV, STEP_25_MV),
  618. regulator_desc_s2mps14_ldo(14, MIN_1800_MV, STEP_25_MV),
  619. regulator_desc_s2mps14_ldo(15, MIN_1800_MV, STEP_25_MV),
  620. regulator_desc_s2mps14_ldo(16, MIN_1800_MV, STEP_25_MV),
  621. regulator_desc_s2mps14_ldo(17, MIN_1800_MV, STEP_25_MV),
  622. regulator_desc_s2mps14_ldo(18, MIN_1800_MV, STEP_25_MV),
  623. regulator_desc_s2mps14_ldo(19, MIN_800_MV, STEP_25_MV),
  624. regulator_desc_s2mps14_ldo(20, MIN_800_MV, STEP_25_MV),
  625. regulator_desc_s2mps14_ldo(21, MIN_800_MV, STEP_25_MV),
  626. regulator_desc_s2mps14_ldo(22, MIN_800_MV, STEP_12_5_MV),
  627. regulator_desc_s2mps14_ldo(23, MIN_800_MV, STEP_25_MV),
  628. regulator_desc_s2mps14_ldo(24, MIN_1800_MV, STEP_25_MV),
  629. regulator_desc_s2mps14_ldo(25, MIN_1800_MV, STEP_25_MV),
  630. regulator_desc_s2mps14_buck(1, MIN_600_MV, STEP_6_25_MV,
  631. S2MPS14_BUCK1235_START_SEL),
  632. regulator_desc_s2mps14_buck(2, MIN_600_MV, STEP_6_25_MV,
  633. S2MPS14_BUCK1235_START_SEL),
  634. regulator_desc_s2mps14_buck(3, MIN_600_MV, STEP_6_25_MV,
  635. S2MPS14_BUCK1235_START_SEL),
  636. regulator_desc_s2mps14_buck(4, MIN_1400_MV, STEP_12_5_MV,
  637. S2MPS14_BUCK4_START_SEL),
  638. regulator_desc_s2mps14_buck(5, MIN_600_MV, STEP_6_25_MV,
  639. S2MPS14_BUCK1235_START_SEL),
  640. };
  641. static const struct regulator_ops s2mps15_reg_ldo_ops = {
  642. .list_voltage = regulator_list_voltage_linear_range,
  643. .map_voltage = regulator_map_voltage_linear_range,
  644. .is_enabled = regulator_is_enabled_regmap,
  645. .enable = regulator_enable_regmap,
  646. .disable = regulator_disable_regmap,
  647. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  648. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  649. };
  650. static const struct regulator_ops s2mps15_reg_buck_ops = {
  651. .list_voltage = regulator_list_voltage_linear_range,
  652. .map_voltage = regulator_map_voltage_linear_range,
  653. .is_enabled = regulator_is_enabled_regmap,
  654. .enable = regulator_enable_regmap,
  655. .disable = regulator_disable_regmap,
  656. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  657. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  658. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  659. };
  660. #define regulator_desc_s2mps15_ldo(num, range) { \
  661. .name = "LDO"#num, \
  662. .id = S2MPS15_LDO##num, \
  663. .ops = &s2mps15_reg_ldo_ops, \
  664. .type = REGULATOR_VOLTAGE, \
  665. .owner = THIS_MODULE, \
  666. .linear_ranges = range, \
  667. .n_linear_ranges = ARRAY_SIZE(range), \
  668. .n_voltages = S2MPS15_LDO_N_VOLTAGES, \
  669. .vsel_reg = S2MPS15_REG_L1CTRL + num - 1, \
  670. .vsel_mask = S2MPS15_LDO_VSEL_MASK, \
  671. .enable_reg = S2MPS15_REG_L1CTRL + num - 1, \
  672. .enable_mask = S2MPS15_ENABLE_MASK \
  673. }
  674. #define regulator_desc_s2mps15_buck(num, range) { \
  675. .name = "BUCK"#num, \
  676. .id = S2MPS15_BUCK##num, \
  677. .ops = &s2mps15_reg_buck_ops, \
  678. .type = REGULATOR_VOLTAGE, \
  679. .owner = THIS_MODULE, \
  680. .linear_ranges = range, \
  681. .n_linear_ranges = ARRAY_SIZE(range), \
  682. .ramp_delay = 12500, \
  683. .n_voltages = S2MPS15_BUCK_N_VOLTAGES, \
  684. .vsel_reg = S2MPS15_REG_B1CTRL2 + ((num - 1) * 2), \
  685. .vsel_mask = S2MPS15_BUCK_VSEL_MASK, \
  686. .enable_reg = S2MPS15_REG_B1CTRL1 + ((num - 1) * 2), \
  687. .enable_mask = S2MPS15_ENABLE_MASK \
  688. }
  689. /* voltage range for s2mps15 LDO 3, 5, 15, 16, 18, 20, 23 and 27 */
  690. static const struct regulator_linear_range s2mps15_ldo_voltage_ranges1[] = {
  691. REGULATOR_LINEAR_RANGE(1000000, 0xc, 0x38, 25000),
  692. };
  693. /* voltage range for s2mps15 LDO 2, 6, 14, 17, 19, 21, 24 and 25 */
  694. static const struct regulator_linear_range s2mps15_ldo_voltage_ranges2[] = {
  695. REGULATOR_LINEAR_RANGE(1800000, 0x0, 0x3f, 25000),
  696. };
  697. /* voltage range for s2mps15 LDO 4, 11, 12, 13, 22 and 26 */
  698. static const struct regulator_linear_range s2mps15_ldo_voltage_ranges3[] = {
  699. REGULATOR_LINEAR_RANGE(700000, 0x0, 0x34, 12500),
  700. };
  701. /* voltage range for s2mps15 LDO 7, 8, 9 and 10 */
  702. static const struct regulator_linear_range s2mps15_ldo_voltage_ranges4[] = {
  703. REGULATOR_LINEAR_RANGE(700000, 0x10, 0x20, 25000),
  704. };
  705. /* voltage range for s2mps15 LDO 1 */
  706. static const struct regulator_linear_range s2mps15_ldo_voltage_ranges5[] = {
  707. REGULATOR_LINEAR_RANGE(500000, 0x0, 0x20, 12500),
  708. };
  709. /* voltage range for s2mps15 BUCK 1, 2, 3, 4, 5, 6 and 7 */
  710. static const struct regulator_linear_range s2mps15_buck_voltage_ranges1[] = {
  711. REGULATOR_LINEAR_RANGE(500000, 0x20, 0xc0, 6250),
  712. };
  713. /* voltage range for s2mps15 BUCK 8, 9 and 10 */
  714. static const struct regulator_linear_range s2mps15_buck_voltage_ranges2[] = {
  715. REGULATOR_LINEAR_RANGE(1000000, 0x20, 0x78, 12500),
  716. };
  717. static const struct regulator_desc s2mps15_regulators[] = {
  718. regulator_desc_s2mps15_ldo(1, s2mps15_ldo_voltage_ranges5),
  719. regulator_desc_s2mps15_ldo(2, s2mps15_ldo_voltage_ranges2),
  720. regulator_desc_s2mps15_ldo(3, s2mps15_ldo_voltage_ranges1),
  721. regulator_desc_s2mps15_ldo(4, s2mps15_ldo_voltage_ranges3),
  722. regulator_desc_s2mps15_ldo(5, s2mps15_ldo_voltage_ranges1),
  723. regulator_desc_s2mps15_ldo(6, s2mps15_ldo_voltage_ranges2),
  724. regulator_desc_s2mps15_ldo(7, s2mps15_ldo_voltage_ranges4),
  725. regulator_desc_s2mps15_ldo(8, s2mps15_ldo_voltage_ranges4),
  726. regulator_desc_s2mps15_ldo(9, s2mps15_ldo_voltage_ranges4),
  727. regulator_desc_s2mps15_ldo(10, s2mps15_ldo_voltage_ranges4),
  728. regulator_desc_s2mps15_ldo(11, s2mps15_ldo_voltage_ranges3),
  729. regulator_desc_s2mps15_ldo(12, s2mps15_ldo_voltage_ranges3),
  730. regulator_desc_s2mps15_ldo(13, s2mps15_ldo_voltage_ranges3),
  731. regulator_desc_s2mps15_ldo(14, s2mps15_ldo_voltage_ranges2),
  732. regulator_desc_s2mps15_ldo(15, s2mps15_ldo_voltage_ranges1),
  733. regulator_desc_s2mps15_ldo(16, s2mps15_ldo_voltage_ranges1),
  734. regulator_desc_s2mps15_ldo(17, s2mps15_ldo_voltage_ranges2),
  735. regulator_desc_s2mps15_ldo(18, s2mps15_ldo_voltage_ranges1),
  736. regulator_desc_s2mps15_ldo(19, s2mps15_ldo_voltage_ranges2),
  737. regulator_desc_s2mps15_ldo(20, s2mps15_ldo_voltage_ranges1),
  738. regulator_desc_s2mps15_ldo(21, s2mps15_ldo_voltage_ranges2),
  739. regulator_desc_s2mps15_ldo(22, s2mps15_ldo_voltage_ranges3),
  740. regulator_desc_s2mps15_ldo(23, s2mps15_ldo_voltage_ranges1),
  741. regulator_desc_s2mps15_ldo(24, s2mps15_ldo_voltage_ranges2),
  742. regulator_desc_s2mps15_ldo(25, s2mps15_ldo_voltage_ranges2),
  743. regulator_desc_s2mps15_ldo(26, s2mps15_ldo_voltage_ranges3),
  744. regulator_desc_s2mps15_ldo(27, s2mps15_ldo_voltage_ranges1),
  745. regulator_desc_s2mps15_buck(1, s2mps15_buck_voltage_ranges1),
  746. regulator_desc_s2mps15_buck(2, s2mps15_buck_voltage_ranges1),
  747. regulator_desc_s2mps15_buck(3, s2mps15_buck_voltage_ranges1),
  748. regulator_desc_s2mps15_buck(4, s2mps15_buck_voltage_ranges1),
  749. regulator_desc_s2mps15_buck(5, s2mps15_buck_voltage_ranges1),
  750. regulator_desc_s2mps15_buck(6, s2mps15_buck_voltage_ranges1),
  751. regulator_desc_s2mps15_buck(7, s2mps15_buck_voltage_ranges1),
  752. regulator_desc_s2mps15_buck(8, s2mps15_buck_voltage_ranges2),
  753. regulator_desc_s2mps15_buck(9, s2mps15_buck_voltage_ranges2),
  754. regulator_desc_s2mps15_buck(10, s2mps15_buck_voltage_ranges2),
  755. };
  756. static int s2mps14_pmic_enable_ext_control(struct s2mps11_info *s2mps11,
  757. struct regulator_dev *rdev)
  758. {
  759. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  760. rdev->desc->enable_mask, S2MPS14_ENABLE_EXT_CONTROL);
  761. }
  762. static void s2mps14_pmic_dt_parse_ext_control_gpio(struct platform_device *pdev,
  763. struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
  764. {
  765. struct gpio_desc **gpio = s2mps11->ext_control_gpiod;
  766. unsigned int i;
  767. unsigned int valid_regulators[3] = { S2MPS14_LDO10, S2MPS14_LDO11,
  768. S2MPS14_LDO12 };
  769. for (i = 0; i < ARRAY_SIZE(valid_regulators); i++) {
  770. unsigned int reg = valid_regulators[i];
  771. if (!rdata[reg].init_data || !rdata[reg].of_node)
  772. continue;
  773. gpio[reg] = devm_gpiod_get_from_of_node(&pdev->dev,
  774. rdata[reg].of_node,
  775. "samsung,ext-control-gpios",
  776. 0,
  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 sec_platform_data *pdata = NULL;
  1037. struct of_regulator_match *rdata = NULL;
  1038. struct regulator_config config = { };
  1039. struct s2mps11_info *s2mps11;
  1040. unsigned int rdev_num = 0;
  1041. int i, ret = 0;
  1042. const struct regulator_desc *regulators;
  1043. s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
  1044. GFP_KERNEL);
  1045. if (!s2mps11)
  1046. return -ENOMEM;
  1047. s2mps11->dev_type = platform_get_device_id(pdev)->driver_data;
  1048. switch (s2mps11->dev_type) {
  1049. case S2MPS11X:
  1050. rdev_num = ARRAY_SIZE(s2mps11_regulators);
  1051. regulators = s2mps11_regulators;
  1052. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps11_regulators));
  1053. break;
  1054. case S2MPS13X:
  1055. rdev_num = ARRAY_SIZE(s2mps13_regulators);
  1056. regulators = s2mps13_regulators;
  1057. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps13_regulators));
  1058. break;
  1059. case S2MPS14X:
  1060. rdev_num = ARRAY_SIZE(s2mps14_regulators);
  1061. regulators = s2mps14_regulators;
  1062. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps14_regulators));
  1063. break;
  1064. case S2MPS15X:
  1065. rdev_num = ARRAY_SIZE(s2mps15_regulators);
  1066. regulators = s2mps15_regulators;
  1067. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mps15_regulators));
  1068. break;
  1069. case S2MPU02:
  1070. rdev_num = ARRAY_SIZE(s2mpu02_regulators);
  1071. regulators = s2mpu02_regulators;
  1072. BUILD_BUG_ON(S2MPS_REGULATOR_MAX < ARRAY_SIZE(s2mpu02_regulators));
  1073. break;
  1074. default:
  1075. dev_err(&pdev->dev, "Invalid device type: %u\n",
  1076. s2mps11->dev_type);
  1077. return -EINVAL;
  1078. }
  1079. s2mps11->ext_control_gpiod = devm_kcalloc(&pdev->dev, rdev_num,
  1080. sizeof(*s2mps11->ext_control_gpiod), GFP_KERNEL);
  1081. if (!s2mps11->ext_control_gpiod)
  1082. return -ENOMEM;
  1083. if (!iodev->dev->of_node) {
  1084. if (iodev->pdata) {
  1085. pdata = iodev->pdata;
  1086. goto common_reg;
  1087. } else {
  1088. dev_err(pdev->dev.parent,
  1089. "Platform data or DT node not supplied\n");
  1090. return -ENODEV;
  1091. }
  1092. }
  1093. rdata = kcalloc(rdev_num, sizeof(*rdata), GFP_KERNEL);
  1094. if (!rdata)
  1095. return -ENOMEM;
  1096. for (i = 0; i < rdev_num; i++)
  1097. rdata[i].name = regulators[i].name;
  1098. ret = s2mps11_pmic_dt_parse(pdev, rdata, s2mps11, rdev_num);
  1099. if (ret)
  1100. goto out;
  1101. common_reg:
  1102. platform_set_drvdata(pdev, s2mps11);
  1103. config.dev = &pdev->dev;
  1104. config.regmap = iodev->regmap_pmic;
  1105. config.driver_data = s2mps11;
  1106. for (i = 0; i < rdev_num; i++) {
  1107. struct regulator_dev *regulator;
  1108. if (pdata) {
  1109. config.init_data = pdata->regulators[i].initdata;
  1110. config.of_node = pdata->regulators[i].reg_node;
  1111. } else {
  1112. config.init_data = rdata[i].init_data;
  1113. config.of_node = rdata[i].of_node;
  1114. }
  1115. config.ena_gpiod = s2mps11->ext_control_gpiod[i];
  1116. /*
  1117. * Hand the GPIO descriptor management over to the regulator
  1118. * core, remove it from devres management.
  1119. */
  1120. if (config.ena_gpiod)
  1121. devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod);
  1122. regulator = devm_regulator_register(&pdev->dev,
  1123. &regulators[i], &config);
  1124. if (IS_ERR(regulator)) {
  1125. ret = PTR_ERR(regulator);
  1126. dev_err(&pdev->dev, "regulator init failed for %d\n",
  1127. i);
  1128. goto out;
  1129. }
  1130. if (config.ena_gpiod) {
  1131. ret = s2mps14_pmic_enable_ext_control(s2mps11,
  1132. regulator);
  1133. if (ret < 0) {
  1134. dev_err(&pdev->dev,
  1135. "failed to enable GPIO control over %s: %d\n",
  1136. regulator->desc->name, ret);
  1137. goto out;
  1138. }
  1139. }
  1140. }
  1141. out:
  1142. kfree(rdata);
  1143. return ret;
  1144. }
  1145. static const struct platform_device_id s2mps11_pmic_id[] = {
  1146. { "s2mps11-regulator", S2MPS11X},
  1147. { "s2mps13-regulator", S2MPS13X},
  1148. { "s2mps14-regulator", S2MPS14X},
  1149. { "s2mps15-regulator", S2MPS15X},
  1150. { "s2mpu02-regulator", S2MPU02},
  1151. { },
  1152. };
  1153. MODULE_DEVICE_TABLE(platform, s2mps11_pmic_id);
  1154. static struct platform_driver s2mps11_pmic_driver = {
  1155. .driver = {
  1156. .name = "s2mps11-pmic",
  1157. },
  1158. .probe = s2mps11_pmic_probe,
  1159. .id_table = s2mps11_pmic_id,
  1160. };
  1161. module_platform_driver(s2mps11_pmic_driver);
  1162. /* Module information */
  1163. MODULE_AUTHOR("Sangbeom Kim <sbkim73@samsung.com>");
  1164. MODULE_DESCRIPTION("SAMSUNG S2MPS11/S2MPS14/S2MPS15/S2MPU02 Regulator Driver");
  1165. MODULE_LICENSE("GPL");