bd718x7-regulator.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 ROHM Semiconductors
  3. // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
  4. #include <linux/delay.h>
  5. #include <linux/err.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/kernel.h>
  8. #include <linux/mfd/rohm-bd718x7.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/regulator/driver.h>
  13. #include <linux/regulator/machine.h>
  14. #include <linux/regulator/of_regulator.h>
  15. #include <linux/slab.h>
  16. /* Typical regulator startup times as per data sheet in uS */
  17. #define BD71847_BUCK1_STARTUP_TIME 144
  18. #define BD71847_BUCK2_STARTUP_TIME 162
  19. #define BD71847_BUCK3_STARTUP_TIME 162
  20. #define BD71847_BUCK4_STARTUP_TIME 240
  21. #define BD71847_BUCK5_STARTUP_TIME 270
  22. #define BD71847_BUCK6_STARTUP_TIME 200
  23. #define BD71847_LDO1_STARTUP_TIME 440
  24. #define BD71847_LDO2_STARTUP_TIME 370
  25. #define BD71847_LDO3_STARTUP_TIME 310
  26. #define BD71847_LDO4_STARTUP_TIME 400
  27. #define BD71847_LDO5_STARTUP_TIME 530
  28. #define BD71847_LDO6_STARTUP_TIME 400
  29. #define BD71837_BUCK1_STARTUP_TIME 160
  30. #define BD71837_BUCK2_STARTUP_TIME 180
  31. #define BD71837_BUCK3_STARTUP_TIME 180
  32. #define BD71837_BUCK4_STARTUP_TIME 180
  33. #define BD71837_BUCK5_STARTUP_TIME 160
  34. #define BD71837_BUCK6_STARTUP_TIME 240
  35. #define BD71837_BUCK7_STARTUP_TIME 220
  36. #define BD71837_BUCK8_STARTUP_TIME 200
  37. #define BD71837_LDO1_STARTUP_TIME 440
  38. #define BD71837_LDO2_STARTUP_TIME 370
  39. #define BD71837_LDO3_STARTUP_TIME 310
  40. #define BD71837_LDO4_STARTUP_TIME 400
  41. #define BD71837_LDO5_STARTUP_TIME 310
  42. #define BD71837_LDO6_STARTUP_TIME 400
  43. #define BD71837_LDO7_STARTUP_TIME 530
  44. /*
  45. * BUCK1/2/3/4
  46. * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
  47. * 00: 10.00mV/usec 10mV 1uS
  48. * 01: 5.00mV/usec 10mV 2uS
  49. * 10: 2.50mV/usec 10mV 4uS
  50. * 11: 1.25mV/usec 10mV 8uS
  51. */
  52. static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
  53. int ramp_delay)
  54. {
  55. int id = rdev_get_id(rdev);
  56. unsigned int ramp_value;
  57. dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
  58. ramp_delay);
  59. switch (ramp_delay) {
  60. case 1 ... 1250:
  61. ramp_value = BUCK_RAMPRATE_1P25MV;
  62. break;
  63. case 1251 ... 2500:
  64. ramp_value = BUCK_RAMPRATE_2P50MV;
  65. break;
  66. case 2501 ... 5000:
  67. ramp_value = BUCK_RAMPRATE_5P00MV;
  68. break;
  69. case 5001 ... 10000:
  70. ramp_value = BUCK_RAMPRATE_10P00MV;
  71. break;
  72. default:
  73. ramp_value = BUCK_RAMPRATE_10P00MV;
  74. dev_err(&rdev->dev,
  75. "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
  76. rdev->desc->name, ramp_delay);
  77. }
  78. return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
  79. BUCK_RAMPRATE_MASK, ramp_value << 6);
  80. }
  81. /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
  82. * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
  83. * is changed. Hence we return -EBUSY for these if voltage is changed
  84. * when BUCK/LDO is enabled.
  85. */
  86. static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
  87. unsigned int sel)
  88. {
  89. if (regulator_is_enabled_regmap(rdev))
  90. return -EBUSY;
  91. return regulator_set_voltage_sel_regmap(rdev, sel);
  92. }
  93. static int bd718xx_set_voltage_sel_pickable_restricted(
  94. struct regulator_dev *rdev, unsigned int sel)
  95. {
  96. if (regulator_is_enabled_regmap(rdev))
  97. return -EBUSY;
  98. return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
  99. }
  100. static const struct regulator_ops bd718xx_pickable_range_ldo_ops = {
  101. .enable = regulator_enable_regmap,
  102. .disable = regulator_disable_regmap,
  103. .is_enabled = regulator_is_enabled_regmap,
  104. .list_voltage = regulator_list_voltage_pickable_linear_range,
  105. .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
  106. .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
  107. };
  108. static const struct regulator_ops bd718xx_pickable_range_buck_ops = {
  109. .enable = regulator_enable_regmap,
  110. .disable = regulator_disable_regmap,
  111. .is_enabled = regulator_is_enabled_regmap,
  112. .list_voltage = regulator_list_voltage_pickable_linear_range,
  113. .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
  114. .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
  115. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  116. };
  117. static const struct regulator_ops bd718xx_ldo_regulator_ops = {
  118. .enable = regulator_enable_regmap,
  119. .disable = regulator_disable_regmap,
  120. .is_enabled = regulator_is_enabled_regmap,
  121. .list_voltage = regulator_list_voltage_linear_range,
  122. .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
  123. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  124. };
  125. static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
  126. .enable = regulator_enable_regmap,
  127. .disable = regulator_disable_regmap,
  128. .is_enabled = regulator_is_enabled_regmap,
  129. .list_voltage = regulator_list_voltage_table,
  130. .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
  131. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  132. };
  133. static const struct regulator_ops bd718xx_buck_regulator_ops = {
  134. .enable = regulator_enable_regmap,
  135. .disable = regulator_disable_regmap,
  136. .is_enabled = regulator_is_enabled_regmap,
  137. .list_voltage = regulator_list_voltage_linear_range,
  138. .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
  139. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  140. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  141. };
  142. static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
  143. .enable = regulator_enable_regmap,
  144. .disable = regulator_disable_regmap,
  145. .is_enabled = regulator_is_enabled_regmap,
  146. .list_voltage = regulator_list_voltage_table,
  147. .map_voltage = regulator_map_voltage_ascend,
  148. .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
  149. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  150. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  151. };
  152. static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
  153. .enable = regulator_enable_regmap,
  154. .disable = regulator_disable_regmap,
  155. .is_enabled = regulator_is_enabled_regmap,
  156. .list_voltage = regulator_list_voltage_linear_range,
  157. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  158. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  159. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  160. .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
  161. };
  162. /*
  163. * BD71837 BUCK1/2/3/4
  164. * BD71847 BUCK1/2
  165. * 0.70 to 1.30V (10mV step)
  166. */
  167. static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
  168. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
  169. REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
  170. };
  171. /*
  172. * BD71837 BUCK5
  173. * 0.7V to 1.35V (range 0)
  174. * and
  175. * 0.675 to 1.325 (range 1)
  176. */
  177. static const struct regulator_linear_range bd71837_buck5_volts[] = {
  178. /* Ranges when VOLT_SEL bit is 0 */
  179. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  180. REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  181. REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  182. /* Ranges when VOLT_SEL bit is 1 */
  183. REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  184. REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  185. REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  186. };
  187. /*
  188. * Range selector for first 3 linear ranges is 0x0
  189. * and 0x1 for last 3 ranges.
  190. */
  191. static const unsigned int bd71837_buck5_volt_range_sel[] = {
  192. 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
  193. };
  194. /*
  195. * BD71847 BUCK3
  196. */
  197. static const struct regulator_linear_range bd71847_buck3_volts[] = {
  198. /* Ranges when VOLT_SEL bits are 00 */
  199. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  200. REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  201. REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  202. /* Ranges when VOLT_SEL bits are 01 */
  203. REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
  204. /* Ranges when VOLT_SEL bits are 11 */
  205. REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
  206. REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
  207. REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
  208. };
  209. static const unsigned int bd71847_buck3_volt_range_sel[] = {
  210. 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
  211. };
  212. static const struct regulator_linear_range bd71847_buck4_volts[] = {
  213. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  214. REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
  215. };
  216. static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
  217. /*
  218. * BUCK6
  219. * 3.0V to 3.3V (step 100mV)
  220. */
  221. static const struct regulator_linear_range bd71837_buck6_volts[] = {
  222. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  223. };
  224. /*
  225. * BD71837 BUCK7
  226. * BD71847 BUCK5
  227. * 000 = 1.605V
  228. * 001 = 1.695V
  229. * 010 = 1.755V
  230. * 011 = 1.8V (Initial)
  231. * 100 = 1.845V
  232. * 101 = 1.905V
  233. * 110 = 1.95V
  234. * 111 = 1.995V
  235. */
  236. static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
  237. 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
  238. };
  239. /*
  240. * BUCK8
  241. * 0.8V to 1.40V (step 10mV)
  242. */
  243. static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
  244. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
  245. };
  246. /*
  247. * LDO1
  248. * 3.0 to 3.3V (100mV step)
  249. */
  250. static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
  251. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  252. REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
  253. };
  254. static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
  255. /*
  256. * LDO2
  257. * 0.8 or 0.9V
  258. */
  259. static const unsigned int ldo_2_volts[] = {
  260. 900000, 800000
  261. };
  262. /*
  263. * LDO3
  264. * 1.8 to 3.3V (100mV step)
  265. */
  266. static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
  267. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  268. };
  269. /*
  270. * LDO4
  271. * 0.9 to 1.8V (100mV step)
  272. */
  273. static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
  274. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  275. };
  276. /*
  277. * LDO5 for BD71837
  278. * 1.8 to 3.3V (100mV step)
  279. */
  280. static const struct regulator_linear_range bd71837_ldo5_volts[] = {
  281. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  282. };
  283. /*
  284. * LDO5 for BD71837
  285. * 1.8 to 3.3V (100mV step)
  286. */
  287. static const struct regulator_linear_range bd71847_ldo5_volts[] = {
  288. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  289. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
  290. };
  291. static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
  292. /*
  293. * LDO6
  294. * 0.9 to 1.8V (100mV step)
  295. */
  296. static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
  297. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  298. };
  299. /*
  300. * LDO7
  301. * 1.8 to 3.3V (100mV step)
  302. */
  303. static const struct regulator_linear_range bd71837_ldo7_volts[] = {
  304. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  305. };
  306. struct reg_init {
  307. unsigned int reg;
  308. unsigned int mask;
  309. unsigned int val;
  310. };
  311. struct bd718xx_regulator_data {
  312. struct regulator_desc desc;
  313. const struct reg_init init;
  314. const struct reg_init *additional_inits;
  315. int additional_init_amnt;
  316. };
  317. /*
  318. * There is a HW quirk in BD71837. The shutdown sequence timings for
  319. * bucks/LDOs which are controlled via register interface are changed.
  320. * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
  321. * beginning of shut-down sequence. As bucks 6 and 7 are parent
  322. * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
  323. * monitoring to errorneously detect under voltage and force PMIC to
  324. * emergency state instead of poweroff. In order to avoid this we
  325. * disable voltage monitoring for LDO5 and LDO6
  326. */
  327. static const struct reg_init bd71837_ldo5_inits[] = {
  328. {
  329. .reg = BD718XX_REG_MVRFLTMASK2,
  330. .mask = BD718XX_LDO5_VRMON80,
  331. .val = BD718XX_LDO5_VRMON80,
  332. },
  333. };
  334. static const struct reg_init bd71837_ldo6_inits[] = {
  335. {
  336. .reg = BD718XX_REG_MVRFLTMASK2,
  337. .mask = BD718XX_LDO6_VRMON80,
  338. .val = BD718XX_LDO6_VRMON80,
  339. },
  340. };
  341. #define NUM_DVS_BUCKS 4
  342. struct of_dvs_setting {
  343. const char *prop;
  344. unsigned int reg;
  345. };
  346. static int set_dvs_levels(const struct of_dvs_setting *dvs,
  347. struct device_node *np,
  348. const struct regulator_desc *desc,
  349. struct regmap *regmap)
  350. {
  351. int ret, i;
  352. unsigned int uv;
  353. ret = of_property_read_u32(np, dvs->prop, &uv);
  354. if (ret) {
  355. if (ret != -EINVAL)
  356. return ret;
  357. return 0;
  358. }
  359. for (i = 0; i < desc->n_voltages; i++) {
  360. ret = regulator_desc_list_voltage_linear_range(desc, i);
  361. if (ret < 0)
  362. continue;
  363. if (ret == uv) {
  364. i <<= ffs(desc->vsel_mask) - 1;
  365. ret = regmap_update_bits(regmap, dvs->reg,
  366. DVS_BUCK_RUN_MASK, i);
  367. break;
  368. }
  369. }
  370. return ret;
  371. }
  372. static int buck4_set_hw_dvs_levels(struct device_node *np,
  373. const struct regulator_desc *desc,
  374. struct regulator_config *cfg)
  375. {
  376. int ret, i;
  377. const struct of_dvs_setting dvs[] = {
  378. {
  379. .prop = "rohm,dvs-run-voltage",
  380. .reg = BD71837_REG_BUCK4_VOLT_RUN,
  381. },
  382. };
  383. for (i = 0; i < ARRAY_SIZE(dvs); i++) {
  384. ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
  385. if (ret)
  386. break;
  387. }
  388. return ret;
  389. }
  390. static int buck3_set_hw_dvs_levels(struct device_node *np,
  391. const struct regulator_desc *desc,
  392. struct regulator_config *cfg)
  393. {
  394. int ret, i;
  395. const struct of_dvs_setting dvs[] = {
  396. {
  397. .prop = "rohm,dvs-run-voltage",
  398. .reg = BD71837_REG_BUCK3_VOLT_RUN,
  399. },
  400. };
  401. for (i = 0; i < ARRAY_SIZE(dvs); i++) {
  402. ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
  403. if (ret)
  404. break;
  405. }
  406. return ret;
  407. }
  408. static int buck2_set_hw_dvs_levels(struct device_node *np,
  409. const struct regulator_desc *desc,
  410. struct regulator_config *cfg)
  411. {
  412. int ret, i;
  413. const struct of_dvs_setting dvs[] = {
  414. {
  415. .prop = "rohm,dvs-run-voltage",
  416. .reg = BD718XX_REG_BUCK2_VOLT_RUN,
  417. },
  418. {
  419. .prop = "rohm,dvs-idle-voltage",
  420. .reg = BD718XX_REG_BUCK2_VOLT_IDLE,
  421. },
  422. };
  423. for (i = 0; i < ARRAY_SIZE(dvs); i++) {
  424. ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
  425. if (ret)
  426. break;
  427. }
  428. return ret;
  429. }
  430. static int buck1_set_hw_dvs_levels(struct device_node *np,
  431. const struct regulator_desc *desc,
  432. struct regulator_config *cfg)
  433. {
  434. int ret, i;
  435. const struct of_dvs_setting dvs[] = {
  436. {
  437. .prop = "rohm,dvs-run-voltage",
  438. .reg = BD718XX_REG_BUCK1_VOLT_RUN,
  439. },
  440. {
  441. .prop = "rohm,dvs-idle-voltage",
  442. .reg = BD718XX_REG_BUCK1_VOLT_IDLE,
  443. },
  444. {
  445. .prop = "rohm,dvs-suspend-voltage",
  446. .reg = BD718XX_REG_BUCK1_VOLT_SUSP,
  447. },
  448. };
  449. for (i = 0; i < ARRAY_SIZE(dvs); i++) {
  450. ret = set_dvs_levels(&dvs[i], np, desc, cfg->regmap);
  451. if (ret)
  452. break;
  453. }
  454. return ret;
  455. }
  456. static const struct bd718xx_regulator_data bd71847_regulators[] = {
  457. {
  458. .desc = {
  459. .name = "buck1",
  460. .of_match = of_match_ptr("BUCK1"),
  461. .regulators_node = of_match_ptr("regulators"),
  462. .id = BD718XX_BUCK1,
  463. .ops = &bd718xx_dvs_buck_regulator_ops,
  464. .type = REGULATOR_VOLTAGE,
  465. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  466. .linear_ranges = bd718xx_dvs_buck_volts,
  467. .n_linear_ranges =
  468. ARRAY_SIZE(bd718xx_dvs_buck_volts),
  469. .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  470. .vsel_mask = DVS_BUCK_RUN_MASK,
  471. .enable_reg = BD718XX_REG_BUCK1_CTRL,
  472. .enable_mask = BD718XX_BUCK_EN,
  473. .enable_time = BD71847_BUCK1_STARTUP_TIME,
  474. .owner = THIS_MODULE,
  475. .of_parse_cb = buck1_set_hw_dvs_levels,
  476. },
  477. .init = {
  478. .reg = BD718XX_REG_BUCK1_CTRL,
  479. .mask = BD718XX_BUCK_SEL,
  480. .val = BD718XX_BUCK_SEL,
  481. },
  482. },
  483. {
  484. .desc = {
  485. .name = "buck2",
  486. .of_match = of_match_ptr("BUCK2"),
  487. .regulators_node = of_match_ptr("regulators"),
  488. .id = BD718XX_BUCK2,
  489. .ops = &bd718xx_dvs_buck_regulator_ops,
  490. .type = REGULATOR_VOLTAGE,
  491. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  492. .linear_ranges = bd718xx_dvs_buck_volts,
  493. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  494. .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  495. .vsel_mask = DVS_BUCK_RUN_MASK,
  496. .enable_reg = BD718XX_REG_BUCK2_CTRL,
  497. .enable_mask = BD718XX_BUCK_EN,
  498. .enable_time = BD71847_BUCK2_STARTUP_TIME,
  499. .owner = THIS_MODULE,
  500. .of_parse_cb = buck2_set_hw_dvs_levels,
  501. },
  502. .init = {
  503. .reg = BD718XX_REG_BUCK2_CTRL,
  504. .mask = BD718XX_BUCK_SEL,
  505. .val = BD718XX_BUCK_SEL,
  506. },
  507. },
  508. {
  509. .desc = {
  510. .name = "buck3",
  511. .of_match = of_match_ptr("BUCK3"),
  512. .regulators_node = of_match_ptr("regulators"),
  513. .id = BD718XX_BUCK3,
  514. .ops = &bd718xx_pickable_range_buck_ops,
  515. .type = REGULATOR_VOLTAGE,
  516. .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
  517. .linear_ranges = bd71847_buck3_volts,
  518. .n_linear_ranges =
  519. ARRAY_SIZE(bd71847_buck3_volts),
  520. .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  521. .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
  522. .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  523. .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
  524. .linear_range_selectors = bd71847_buck3_volt_range_sel,
  525. .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  526. .enable_mask = BD718XX_BUCK_EN,
  527. .enable_time = BD71847_BUCK3_STARTUP_TIME,
  528. .owner = THIS_MODULE,
  529. },
  530. .init = {
  531. .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  532. .mask = BD718XX_BUCK_SEL,
  533. .val = BD718XX_BUCK_SEL,
  534. },
  535. },
  536. {
  537. .desc = {
  538. .name = "buck4",
  539. .of_match = of_match_ptr("BUCK4"),
  540. .regulators_node = of_match_ptr("regulators"),
  541. .id = BD718XX_BUCK4,
  542. .ops = &bd718xx_pickable_range_buck_ops,
  543. .type = REGULATOR_VOLTAGE,
  544. .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
  545. .linear_ranges = bd71847_buck4_volts,
  546. .n_linear_ranges =
  547. ARRAY_SIZE(bd71847_buck4_volts),
  548. .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  549. .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  550. .vsel_mask = BD71847_BUCK4_MASK,
  551. .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  552. .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
  553. .linear_range_selectors = bd71847_buck4_volt_range_sel,
  554. .enable_mask = BD718XX_BUCK_EN,
  555. .enable_time = BD71847_BUCK4_STARTUP_TIME,
  556. .owner = THIS_MODULE,
  557. },
  558. .init = {
  559. .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  560. .mask = BD718XX_BUCK_SEL,
  561. .val = BD718XX_BUCK_SEL,
  562. },
  563. },
  564. {
  565. .desc = {
  566. .name = "buck5",
  567. .of_match = of_match_ptr("BUCK5"),
  568. .regulators_node = of_match_ptr("regulators"),
  569. .id = BD718XX_BUCK5,
  570. .ops = &bd718xx_buck_regulator_nolinear_ops,
  571. .type = REGULATOR_VOLTAGE,
  572. .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  573. .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  574. .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  575. .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  576. .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  577. .enable_mask = BD718XX_BUCK_EN,
  578. .enable_time = BD71847_BUCK5_STARTUP_TIME,
  579. .owner = THIS_MODULE,
  580. },
  581. .init = {
  582. .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  583. .mask = BD718XX_BUCK_SEL,
  584. .val = BD718XX_BUCK_SEL,
  585. },
  586. },
  587. {
  588. .desc = {
  589. .name = "buck6",
  590. .of_match = of_match_ptr("BUCK6"),
  591. .regulators_node = of_match_ptr("regulators"),
  592. .id = BD718XX_BUCK6,
  593. .ops = &bd718xx_buck_regulator_ops,
  594. .type = REGULATOR_VOLTAGE,
  595. .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
  596. .linear_ranges = bd718xx_4th_nodvs_buck_volts,
  597. .n_linear_ranges =
  598. ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  599. .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  600. .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  601. .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  602. .enable_mask = BD718XX_BUCK_EN,
  603. .enable_time = BD71847_BUCK6_STARTUP_TIME,
  604. .owner = THIS_MODULE,
  605. },
  606. .init = {
  607. .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  608. .mask = BD718XX_BUCK_SEL,
  609. .val = BD718XX_BUCK_SEL,
  610. },
  611. },
  612. {
  613. .desc = {
  614. .name = "ldo1",
  615. .of_match = of_match_ptr("LDO1"),
  616. .regulators_node = of_match_ptr("regulators"),
  617. .id = BD718XX_LDO1,
  618. .ops = &bd718xx_pickable_range_ldo_ops,
  619. .type = REGULATOR_VOLTAGE,
  620. .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  621. .linear_ranges = bd718xx_ldo1_volts,
  622. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  623. .vsel_reg = BD718XX_REG_LDO1_VOLT,
  624. .vsel_mask = BD718XX_LDO1_MASK,
  625. .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  626. .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  627. .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
  628. .enable_reg = BD718XX_REG_LDO1_VOLT,
  629. .enable_mask = BD718XX_LDO_EN,
  630. .enable_time = BD71847_LDO1_STARTUP_TIME,
  631. .owner = THIS_MODULE,
  632. },
  633. .init = {
  634. .reg = BD718XX_REG_LDO1_VOLT,
  635. .mask = BD718XX_LDO_SEL,
  636. .val = BD718XX_LDO_SEL,
  637. },
  638. },
  639. {
  640. .desc = {
  641. .name = "ldo2",
  642. .of_match = of_match_ptr("LDO2"),
  643. .regulators_node = of_match_ptr("regulators"),
  644. .id = BD718XX_LDO2,
  645. .ops = &bd718xx_ldo_regulator_nolinear_ops,
  646. .type = REGULATOR_VOLTAGE,
  647. .volt_table = &ldo_2_volts[0],
  648. .vsel_reg = BD718XX_REG_LDO2_VOLT,
  649. .vsel_mask = BD718XX_LDO2_MASK,
  650. .n_voltages = ARRAY_SIZE(ldo_2_volts),
  651. .enable_reg = BD718XX_REG_LDO2_VOLT,
  652. .enable_mask = BD718XX_LDO_EN,
  653. .enable_time = BD71847_LDO2_STARTUP_TIME,
  654. .owner = THIS_MODULE,
  655. },
  656. .init = {
  657. .reg = BD718XX_REG_LDO2_VOLT,
  658. .mask = BD718XX_LDO_SEL,
  659. .val = BD718XX_LDO_SEL,
  660. },
  661. },
  662. {
  663. .desc = {
  664. .name = "ldo3",
  665. .of_match = of_match_ptr("LDO3"),
  666. .regulators_node = of_match_ptr("regulators"),
  667. .id = BD718XX_LDO3,
  668. .ops = &bd718xx_ldo_regulator_ops,
  669. .type = REGULATOR_VOLTAGE,
  670. .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  671. .linear_ranges = bd718xx_ldo3_volts,
  672. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  673. .vsel_reg = BD718XX_REG_LDO3_VOLT,
  674. .vsel_mask = BD718XX_LDO3_MASK,
  675. .enable_reg = BD718XX_REG_LDO3_VOLT,
  676. .enable_mask = BD718XX_LDO_EN,
  677. .enable_time = BD71847_LDO3_STARTUP_TIME,
  678. .owner = THIS_MODULE,
  679. },
  680. .init = {
  681. .reg = BD718XX_REG_LDO3_VOLT,
  682. .mask = BD718XX_LDO_SEL,
  683. .val = BD718XX_LDO_SEL,
  684. },
  685. },
  686. {
  687. .desc = {
  688. .name = "ldo4",
  689. .of_match = of_match_ptr("LDO4"),
  690. .regulators_node = of_match_ptr("regulators"),
  691. .id = BD718XX_LDO4,
  692. .ops = &bd718xx_ldo_regulator_ops,
  693. .type = REGULATOR_VOLTAGE,
  694. .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  695. .linear_ranges = bd718xx_ldo4_volts,
  696. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  697. .vsel_reg = BD718XX_REG_LDO4_VOLT,
  698. .vsel_mask = BD718XX_LDO4_MASK,
  699. .enable_reg = BD718XX_REG_LDO4_VOLT,
  700. .enable_mask = BD718XX_LDO_EN,
  701. .enable_time = BD71847_LDO4_STARTUP_TIME,
  702. .owner = THIS_MODULE,
  703. },
  704. .init = {
  705. .reg = BD718XX_REG_LDO4_VOLT,
  706. .mask = BD718XX_LDO_SEL,
  707. .val = BD718XX_LDO_SEL,
  708. },
  709. },
  710. {
  711. .desc = {
  712. .name = "ldo5",
  713. .of_match = of_match_ptr("LDO5"),
  714. .regulators_node = of_match_ptr("regulators"),
  715. .id = BD718XX_LDO5,
  716. .ops = &bd718xx_pickable_range_ldo_ops,
  717. .type = REGULATOR_VOLTAGE,
  718. .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
  719. .linear_ranges = bd71847_ldo5_volts,
  720. .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
  721. .vsel_reg = BD718XX_REG_LDO5_VOLT,
  722. .vsel_mask = BD71847_LDO5_MASK,
  723. .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
  724. .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
  725. .linear_range_selectors = bd71847_ldo5_volt_range_sel,
  726. .enable_reg = BD718XX_REG_LDO5_VOLT,
  727. .enable_mask = BD718XX_LDO_EN,
  728. .enable_time = BD71847_LDO5_STARTUP_TIME,
  729. .owner = THIS_MODULE,
  730. },
  731. .init = {
  732. .reg = BD718XX_REG_LDO5_VOLT,
  733. .mask = BD718XX_LDO_SEL,
  734. .val = BD718XX_LDO_SEL,
  735. },
  736. },
  737. {
  738. .desc = {
  739. .name = "ldo6",
  740. .of_match = of_match_ptr("LDO6"),
  741. .regulators_node = of_match_ptr("regulators"),
  742. .id = BD718XX_LDO6,
  743. .ops = &bd718xx_ldo_regulator_ops,
  744. .type = REGULATOR_VOLTAGE,
  745. .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  746. .linear_ranges = bd718xx_ldo6_volts,
  747. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  748. /* LDO6 is supplied by buck5 */
  749. .supply_name = "buck5",
  750. .vsel_reg = BD718XX_REG_LDO6_VOLT,
  751. .vsel_mask = BD718XX_LDO6_MASK,
  752. .enable_reg = BD718XX_REG_LDO6_VOLT,
  753. .enable_mask = BD718XX_LDO_EN,
  754. .enable_time = BD71847_LDO6_STARTUP_TIME,
  755. .owner = THIS_MODULE,
  756. },
  757. .init = {
  758. .reg = BD718XX_REG_LDO6_VOLT,
  759. .mask = BD718XX_LDO_SEL,
  760. .val = BD718XX_LDO_SEL,
  761. },
  762. },
  763. };
  764. static const struct bd718xx_regulator_data bd71837_regulators[] = {
  765. {
  766. .desc = {
  767. .name = "buck1",
  768. .of_match = of_match_ptr("BUCK1"),
  769. .regulators_node = of_match_ptr("regulators"),
  770. .id = BD718XX_BUCK1,
  771. .ops = &bd718xx_dvs_buck_regulator_ops,
  772. .type = REGULATOR_VOLTAGE,
  773. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  774. .linear_ranges = bd718xx_dvs_buck_volts,
  775. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  776. .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
  777. .vsel_mask = DVS_BUCK_RUN_MASK,
  778. .enable_reg = BD718XX_REG_BUCK1_CTRL,
  779. .enable_mask = BD718XX_BUCK_EN,
  780. .enable_time = BD71837_BUCK1_STARTUP_TIME,
  781. .owner = THIS_MODULE,
  782. .of_parse_cb = buck1_set_hw_dvs_levels,
  783. },
  784. .init = {
  785. .reg = BD718XX_REG_BUCK1_CTRL,
  786. .mask = BD718XX_BUCK_SEL,
  787. .val = BD718XX_BUCK_SEL,
  788. },
  789. },
  790. {
  791. .desc = {
  792. .name = "buck2",
  793. .of_match = of_match_ptr("BUCK2"),
  794. .regulators_node = of_match_ptr("regulators"),
  795. .id = BD718XX_BUCK2,
  796. .ops = &bd718xx_dvs_buck_regulator_ops,
  797. .type = REGULATOR_VOLTAGE,
  798. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  799. .linear_ranges = bd718xx_dvs_buck_volts,
  800. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  801. .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
  802. .vsel_mask = DVS_BUCK_RUN_MASK,
  803. .enable_reg = BD718XX_REG_BUCK2_CTRL,
  804. .enable_mask = BD718XX_BUCK_EN,
  805. .enable_time = BD71837_BUCK2_STARTUP_TIME,
  806. .owner = THIS_MODULE,
  807. .of_parse_cb = buck2_set_hw_dvs_levels,
  808. },
  809. .init = {
  810. .reg = BD718XX_REG_BUCK2_CTRL,
  811. .mask = BD718XX_BUCK_SEL,
  812. .val = BD718XX_BUCK_SEL,
  813. },
  814. },
  815. {
  816. .desc = {
  817. .name = "buck3",
  818. .of_match = of_match_ptr("BUCK3"),
  819. .regulators_node = of_match_ptr("regulators"),
  820. .id = BD718XX_BUCK3,
  821. .ops = &bd718xx_dvs_buck_regulator_ops,
  822. .type = REGULATOR_VOLTAGE,
  823. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  824. .linear_ranges = bd718xx_dvs_buck_volts,
  825. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  826. .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
  827. .vsel_mask = DVS_BUCK_RUN_MASK,
  828. .enable_reg = BD71837_REG_BUCK3_CTRL,
  829. .enable_mask = BD718XX_BUCK_EN,
  830. .enable_time = BD71837_BUCK3_STARTUP_TIME,
  831. .owner = THIS_MODULE,
  832. .of_parse_cb = buck3_set_hw_dvs_levels,
  833. },
  834. .init = {
  835. .reg = BD71837_REG_BUCK3_CTRL,
  836. .mask = BD718XX_BUCK_SEL,
  837. .val = BD718XX_BUCK_SEL,
  838. },
  839. },
  840. {
  841. .desc = {
  842. .name = "buck4",
  843. .of_match = of_match_ptr("BUCK4"),
  844. .regulators_node = of_match_ptr("regulators"),
  845. .id = BD718XX_BUCK4,
  846. .ops = &bd718xx_dvs_buck_regulator_ops,
  847. .type = REGULATOR_VOLTAGE,
  848. .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
  849. .linear_ranges = bd718xx_dvs_buck_volts,
  850. .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
  851. .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
  852. .vsel_mask = DVS_BUCK_RUN_MASK,
  853. .enable_reg = BD71837_REG_BUCK4_CTRL,
  854. .enable_mask = BD718XX_BUCK_EN,
  855. .enable_time = BD71837_BUCK4_STARTUP_TIME,
  856. .owner = THIS_MODULE,
  857. .of_parse_cb = buck4_set_hw_dvs_levels,
  858. },
  859. .init = {
  860. .reg = BD71837_REG_BUCK4_CTRL,
  861. .mask = BD718XX_BUCK_SEL,
  862. .val = BD718XX_BUCK_SEL,
  863. },
  864. },
  865. {
  866. .desc = {
  867. .name = "buck5",
  868. .of_match = of_match_ptr("BUCK5"),
  869. .regulators_node = of_match_ptr("regulators"),
  870. .id = BD718XX_BUCK5,
  871. .ops = &bd718xx_pickable_range_buck_ops,
  872. .type = REGULATOR_VOLTAGE,
  873. .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
  874. .linear_ranges = bd71837_buck5_volts,
  875. .n_linear_ranges =
  876. ARRAY_SIZE(bd71837_buck5_volts),
  877. .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  878. .vsel_mask = BD71837_BUCK5_MASK,
  879. .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
  880. .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
  881. .linear_range_selectors = bd71837_buck5_volt_range_sel,
  882. .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  883. .enable_mask = BD718XX_BUCK_EN,
  884. .enable_time = BD71837_BUCK5_STARTUP_TIME,
  885. .owner = THIS_MODULE,
  886. },
  887. .init = {
  888. .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
  889. .mask = BD718XX_BUCK_SEL,
  890. .val = BD718XX_BUCK_SEL,
  891. },
  892. },
  893. {
  894. .desc = {
  895. .name = "buck6",
  896. .of_match = of_match_ptr("BUCK6"),
  897. .regulators_node = of_match_ptr("regulators"),
  898. .id = BD718XX_BUCK6,
  899. .ops = &bd718xx_buck_regulator_ops,
  900. .type = REGULATOR_VOLTAGE,
  901. .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
  902. .linear_ranges = bd71837_buck6_volts,
  903. .n_linear_ranges =
  904. ARRAY_SIZE(bd71837_buck6_volts),
  905. .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
  906. .vsel_mask = BD71837_BUCK6_MASK,
  907. .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  908. .enable_mask = BD718XX_BUCK_EN,
  909. .enable_time = BD71837_BUCK6_STARTUP_TIME,
  910. .owner = THIS_MODULE,
  911. },
  912. .init = {
  913. .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
  914. .mask = BD718XX_BUCK_SEL,
  915. .val = BD718XX_BUCK_SEL,
  916. },
  917. },
  918. {
  919. .desc = {
  920. .name = "buck7",
  921. .of_match = of_match_ptr("BUCK7"),
  922. .regulators_node = of_match_ptr("regulators"),
  923. .id = BD718XX_BUCK7,
  924. .ops = &bd718xx_buck_regulator_nolinear_ops,
  925. .type = REGULATOR_VOLTAGE,
  926. .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
  927. .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
  928. .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
  929. .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
  930. .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  931. .enable_mask = BD718XX_BUCK_EN,
  932. .enable_time = BD71837_BUCK7_STARTUP_TIME,
  933. .owner = THIS_MODULE,
  934. },
  935. .init = {
  936. .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
  937. .mask = BD718XX_BUCK_SEL,
  938. .val = BD718XX_BUCK_SEL,
  939. },
  940. },
  941. {
  942. .desc = {
  943. .name = "buck8",
  944. .of_match = of_match_ptr("BUCK8"),
  945. .regulators_node = of_match_ptr("regulators"),
  946. .id = BD718XX_BUCK8,
  947. .ops = &bd718xx_buck_regulator_ops,
  948. .type = REGULATOR_VOLTAGE,
  949. .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
  950. .linear_ranges = bd718xx_4th_nodvs_buck_volts,
  951. .n_linear_ranges =
  952. ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
  953. .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
  954. .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
  955. .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  956. .enable_mask = BD718XX_BUCK_EN,
  957. .enable_time = BD71837_BUCK8_STARTUP_TIME,
  958. .owner = THIS_MODULE,
  959. },
  960. .init = {
  961. .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
  962. .mask = BD718XX_BUCK_SEL,
  963. .val = BD718XX_BUCK_SEL,
  964. },
  965. },
  966. {
  967. .desc = {
  968. .name = "ldo1",
  969. .of_match = of_match_ptr("LDO1"),
  970. .regulators_node = of_match_ptr("regulators"),
  971. .id = BD718XX_LDO1,
  972. .ops = &bd718xx_pickable_range_ldo_ops,
  973. .type = REGULATOR_VOLTAGE,
  974. .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
  975. .linear_ranges = bd718xx_ldo1_volts,
  976. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
  977. .vsel_reg = BD718XX_REG_LDO1_VOLT,
  978. .vsel_mask = BD718XX_LDO1_MASK,
  979. .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
  980. .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
  981. .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
  982. .enable_reg = BD718XX_REG_LDO1_VOLT,
  983. .enable_mask = BD718XX_LDO_EN,
  984. .enable_time = BD71837_LDO1_STARTUP_TIME,
  985. .owner = THIS_MODULE,
  986. },
  987. .init = {
  988. .reg = BD718XX_REG_LDO1_VOLT,
  989. .mask = BD718XX_LDO_SEL,
  990. .val = BD718XX_LDO_SEL,
  991. },
  992. },
  993. {
  994. .desc = {
  995. .name = "ldo2",
  996. .of_match = of_match_ptr("LDO2"),
  997. .regulators_node = of_match_ptr("regulators"),
  998. .id = BD718XX_LDO2,
  999. .ops = &bd718xx_ldo_regulator_nolinear_ops,
  1000. .type = REGULATOR_VOLTAGE,
  1001. .volt_table = &ldo_2_volts[0],
  1002. .vsel_reg = BD718XX_REG_LDO2_VOLT,
  1003. .vsel_mask = BD718XX_LDO2_MASK,
  1004. .n_voltages = ARRAY_SIZE(ldo_2_volts),
  1005. .enable_reg = BD718XX_REG_LDO2_VOLT,
  1006. .enable_mask = BD718XX_LDO_EN,
  1007. .enable_time = BD71837_LDO2_STARTUP_TIME,
  1008. .owner = THIS_MODULE,
  1009. },
  1010. .init = {
  1011. .reg = BD718XX_REG_LDO2_VOLT,
  1012. .mask = BD718XX_LDO_SEL,
  1013. .val = BD718XX_LDO_SEL,
  1014. },
  1015. },
  1016. {
  1017. .desc = {
  1018. .name = "ldo3",
  1019. .of_match = of_match_ptr("LDO3"),
  1020. .regulators_node = of_match_ptr("regulators"),
  1021. .id = BD718XX_LDO3,
  1022. .ops = &bd718xx_ldo_regulator_ops,
  1023. .type = REGULATOR_VOLTAGE,
  1024. .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
  1025. .linear_ranges = bd718xx_ldo3_volts,
  1026. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
  1027. .vsel_reg = BD718XX_REG_LDO3_VOLT,
  1028. .vsel_mask = BD718XX_LDO3_MASK,
  1029. .enable_reg = BD718XX_REG_LDO3_VOLT,
  1030. .enable_mask = BD718XX_LDO_EN,
  1031. .enable_time = BD71837_LDO3_STARTUP_TIME,
  1032. .owner = THIS_MODULE,
  1033. },
  1034. .init = {
  1035. .reg = BD718XX_REG_LDO3_VOLT,
  1036. .mask = BD718XX_LDO_SEL,
  1037. .val = BD718XX_LDO_SEL,
  1038. },
  1039. },
  1040. {
  1041. .desc = {
  1042. .name = "ldo4",
  1043. .of_match = of_match_ptr("LDO4"),
  1044. .regulators_node = of_match_ptr("regulators"),
  1045. .id = BD718XX_LDO4,
  1046. .ops = &bd718xx_ldo_regulator_ops,
  1047. .type = REGULATOR_VOLTAGE,
  1048. .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
  1049. .linear_ranges = bd718xx_ldo4_volts,
  1050. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
  1051. .vsel_reg = BD718XX_REG_LDO4_VOLT,
  1052. .vsel_mask = BD718XX_LDO4_MASK,
  1053. .enable_reg = BD718XX_REG_LDO4_VOLT,
  1054. .enable_mask = BD718XX_LDO_EN,
  1055. .enable_time = BD71837_LDO4_STARTUP_TIME,
  1056. .owner = THIS_MODULE,
  1057. },
  1058. .init = {
  1059. .reg = BD718XX_REG_LDO4_VOLT,
  1060. .mask = BD718XX_LDO_SEL,
  1061. .val = BD718XX_LDO_SEL,
  1062. },
  1063. },
  1064. {
  1065. .desc = {
  1066. .name = "ldo5",
  1067. .of_match = of_match_ptr("LDO5"),
  1068. .regulators_node = of_match_ptr("regulators"),
  1069. .id = BD718XX_LDO5,
  1070. .ops = &bd718xx_ldo_regulator_ops,
  1071. .type = REGULATOR_VOLTAGE,
  1072. .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
  1073. .linear_ranges = bd71837_ldo5_volts,
  1074. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
  1075. /* LDO5 is supplied by buck6 */
  1076. .supply_name = "buck6",
  1077. .vsel_reg = BD718XX_REG_LDO5_VOLT,
  1078. .vsel_mask = BD71837_LDO5_MASK,
  1079. .enable_reg = BD718XX_REG_LDO5_VOLT,
  1080. .enable_mask = BD718XX_LDO_EN,
  1081. .enable_time = BD71837_LDO5_STARTUP_TIME,
  1082. .owner = THIS_MODULE,
  1083. },
  1084. .init = {
  1085. .reg = BD718XX_REG_LDO5_VOLT,
  1086. .mask = BD718XX_LDO_SEL,
  1087. .val = BD718XX_LDO_SEL,
  1088. },
  1089. .additional_inits = bd71837_ldo5_inits,
  1090. .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
  1091. },
  1092. {
  1093. .desc = {
  1094. .name = "ldo6",
  1095. .of_match = of_match_ptr("LDO6"),
  1096. .regulators_node = of_match_ptr("regulators"),
  1097. .id = BD718XX_LDO6,
  1098. .ops = &bd718xx_ldo_regulator_ops,
  1099. .type = REGULATOR_VOLTAGE,
  1100. .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
  1101. .linear_ranges = bd718xx_ldo6_volts,
  1102. .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
  1103. /* LDO6 is supplied by buck7 */
  1104. .supply_name = "buck7",
  1105. .vsel_reg = BD718XX_REG_LDO6_VOLT,
  1106. .vsel_mask = BD718XX_LDO6_MASK,
  1107. .enable_reg = BD718XX_REG_LDO6_VOLT,
  1108. .enable_mask = BD718XX_LDO_EN,
  1109. .enable_time = BD71837_LDO6_STARTUP_TIME,
  1110. .owner = THIS_MODULE,
  1111. },
  1112. .init = {
  1113. .reg = BD718XX_REG_LDO6_VOLT,
  1114. .mask = BD718XX_LDO_SEL,
  1115. .val = BD718XX_LDO_SEL,
  1116. },
  1117. .additional_inits = bd71837_ldo6_inits,
  1118. .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
  1119. },
  1120. {
  1121. .desc = {
  1122. .name = "ldo7",
  1123. .of_match = of_match_ptr("LDO7"),
  1124. .regulators_node = of_match_ptr("regulators"),
  1125. .id = BD718XX_LDO7,
  1126. .ops = &bd718xx_ldo_regulator_ops,
  1127. .type = REGULATOR_VOLTAGE,
  1128. .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
  1129. .linear_ranges = bd71837_ldo7_volts,
  1130. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
  1131. .vsel_reg = BD71837_REG_LDO7_VOLT,
  1132. .vsel_mask = BD71837_LDO7_MASK,
  1133. .enable_reg = BD71837_REG_LDO7_VOLT,
  1134. .enable_mask = BD718XX_LDO_EN,
  1135. .enable_time = BD71837_LDO7_STARTUP_TIME,
  1136. .owner = THIS_MODULE,
  1137. },
  1138. .init = {
  1139. .reg = BD71837_REG_LDO7_VOLT,
  1140. .mask = BD718XX_LDO_SEL,
  1141. .val = BD718XX_LDO_SEL,
  1142. },
  1143. },
  1144. };
  1145. struct bd718xx_pmic_inits {
  1146. const struct bd718xx_regulator_data *r_datas;
  1147. unsigned int r_amount;
  1148. };
  1149. static int bd718xx_probe(struct platform_device *pdev)
  1150. {
  1151. struct bd718xx *mfd;
  1152. struct regulator_config config = { 0 };
  1153. struct bd718xx_pmic_inits pmic_regulators[ROHM_CHIP_TYPE_AMOUNT] = {
  1154. [ROHM_CHIP_TYPE_BD71837] = {
  1155. .r_datas = bd71837_regulators,
  1156. .r_amount = ARRAY_SIZE(bd71837_regulators),
  1157. },
  1158. [ROHM_CHIP_TYPE_BD71847] = {
  1159. .r_datas = bd71847_regulators,
  1160. .r_amount = ARRAY_SIZE(bd71847_regulators),
  1161. },
  1162. };
  1163. int i, j, err;
  1164. bool use_snvs;
  1165. mfd = dev_get_drvdata(pdev->dev.parent);
  1166. if (!mfd) {
  1167. dev_err(&pdev->dev, "No MFD driver data\n");
  1168. err = -EINVAL;
  1169. goto err;
  1170. }
  1171. if (mfd->chip.chip_type >= ROHM_CHIP_TYPE_AMOUNT ||
  1172. !pmic_regulators[mfd->chip.chip_type].r_datas) {
  1173. dev_err(&pdev->dev, "Unsupported chip type\n");
  1174. err = -EINVAL;
  1175. goto err;
  1176. }
  1177. /* Register LOCK release */
  1178. err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK,
  1179. (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
  1180. if (err) {
  1181. dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
  1182. goto err;
  1183. } else {
  1184. dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
  1185. BD718XX_REG_REGLOCK);
  1186. }
  1187. use_snvs = of_property_read_bool(pdev->dev.parent->of_node,
  1188. "rohm,reset-snvs-powered");
  1189. /*
  1190. * Change the next stage from poweroff to be READY instead of SNVS
  1191. * for all reset types because OTP loading at READY will clear SEL
  1192. * bit allowing HW defaults for power rails to be used
  1193. */
  1194. if (!use_snvs) {
  1195. err = regmap_update_bits(mfd->chip.regmap,
  1196. BD718XX_REG_TRANS_COND1,
  1197. BD718XX_ON_REQ_POWEROFF_MASK |
  1198. BD718XX_SWRESET_POWEROFF_MASK |
  1199. BD718XX_WDOG_POWEROFF_MASK |
  1200. BD718XX_KEY_L_POWEROFF_MASK,
  1201. BD718XX_POWOFF_TO_RDY);
  1202. if (err) {
  1203. dev_err(&pdev->dev, "Failed to change reset target\n");
  1204. goto err;
  1205. } else {
  1206. dev_dbg(&pdev->dev,
  1207. "Changed all resets from SVNS to READY\n");
  1208. }
  1209. }
  1210. for (i = 0; i < pmic_regulators[mfd->chip.chip_type].r_amount; i++) {
  1211. const struct regulator_desc *desc;
  1212. struct regulator_dev *rdev;
  1213. const struct bd718xx_regulator_data *r;
  1214. r = &pmic_regulators[mfd->chip.chip_type].r_datas[i];
  1215. desc = &r->desc;
  1216. config.dev = pdev->dev.parent;
  1217. config.regmap = mfd->chip.regmap;
  1218. rdev = devm_regulator_register(&pdev->dev, desc, &config);
  1219. if (IS_ERR(rdev)) {
  1220. dev_err(&pdev->dev,
  1221. "failed to register %s regulator\n",
  1222. desc->name);
  1223. err = PTR_ERR(rdev);
  1224. goto err;
  1225. }
  1226. /*
  1227. * Regulator register gets the regulator constraints and
  1228. * applies them (set_machine_constraints). This should have
  1229. * turned the control register(s) to correct values and we
  1230. * can now switch the control from PMIC state machine to the
  1231. * register interface
  1232. *
  1233. * At poweroff transition PMIC HW disables EN bit for
  1234. * regulators but leaves SEL bit untouched. So if state
  1235. * transition from POWEROFF is done to SNVS - then all power
  1236. * rails controlled by SW (having SEL bit set) stay disabled
  1237. * as EN is cleared. This will result boot failure if any
  1238. * crucial systems are powered by these rails. We don't
  1239. * enable SW control for crucial regulators if snvs state is
  1240. * used
  1241. */
  1242. if (!use_snvs || !rdev->constraints->always_on ||
  1243. !rdev->constraints->boot_on) {
  1244. err = regmap_update_bits(mfd->chip.regmap, r->init.reg,
  1245. r->init.mask, r->init.val);
  1246. if (err) {
  1247. dev_err(&pdev->dev,
  1248. "Failed to take control for (%s)\n",
  1249. desc->name);
  1250. goto err;
  1251. }
  1252. }
  1253. for (j = 0; j < r->additional_init_amnt; j++) {
  1254. err = regmap_update_bits(mfd->chip.regmap,
  1255. r->additional_inits[j].reg,
  1256. r->additional_inits[j].mask,
  1257. r->additional_inits[j].val);
  1258. if (err) {
  1259. dev_err(&pdev->dev,
  1260. "Buck (%s) initialization failed\n",
  1261. desc->name);
  1262. goto err;
  1263. }
  1264. }
  1265. }
  1266. err:
  1267. return err;
  1268. }
  1269. static struct platform_driver bd718xx_regulator = {
  1270. .driver = {
  1271. .name = "bd718xx-pmic",
  1272. },
  1273. .probe = bd718xx_probe,
  1274. };
  1275. module_platform_driver(bd718xx_regulator);
  1276. MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
  1277. MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
  1278. MODULE_LICENSE("GPL");