bd71828-regulator.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2019 ROHM Semiconductors
  3. // bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
  4. //
  5. #include <linux/delay.h>
  6. #include <linux/err.h>
  7. #include <linux/gpio.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mfd/rohm-bd71828.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #include <linux/regulator/driver.h>
  16. #include <linux/regulator/machine.h>
  17. #include <linux/regulator/of_regulator.h>
  18. struct reg_init {
  19. unsigned int reg;
  20. unsigned int mask;
  21. unsigned int val;
  22. };
  23. struct bd71828_regulator_data {
  24. struct regulator_desc desc;
  25. const struct rohm_dvs_config dvs;
  26. const struct reg_init *reg_inits;
  27. int reg_init_amnt;
  28. };
  29. static const struct reg_init buck1_inits[] = {
  30. /*
  31. * DVS Buck voltages can be changed by register values or via GPIO.
  32. * Use register accesses by default.
  33. */
  34. {
  35. .reg = BD71828_REG_PS_CTRL_1,
  36. .mask = BD71828_MASK_DVS_BUCK1_CTRL,
  37. .val = BD71828_DVS_BUCK1_CTRL_I2C,
  38. },
  39. };
  40. static const struct reg_init buck2_inits[] = {
  41. {
  42. .reg = BD71828_REG_PS_CTRL_1,
  43. .mask = BD71828_MASK_DVS_BUCK2_CTRL,
  44. .val = BD71828_DVS_BUCK2_CTRL_I2C,
  45. },
  46. };
  47. static const struct reg_init buck6_inits[] = {
  48. {
  49. .reg = BD71828_REG_PS_CTRL_1,
  50. .mask = BD71828_MASK_DVS_BUCK6_CTRL,
  51. .val = BD71828_DVS_BUCK6_CTRL_I2C,
  52. },
  53. };
  54. static const struct reg_init buck7_inits[] = {
  55. {
  56. .reg = BD71828_REG_PS_CTRL_1,
  57. .mask = BD71828_MASK_DVS_BUCK7_CTRL,
  58. .val = BD71828_DVS_BUCK7_CTRL_I2C,
  59. },
  60. };
  61. static const struct linear_range bd71828_buck1267_volts[] = {
  62. REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
  63. REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
  64. };
  65. static const struct linear_range bd71828_buck3_volts[] = {
  66. REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
  67. REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
  68. };
  69. static const struct linear_range bd71828_buck4_volts[] = {
  70. REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
  71. REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
  72. };
  73. static const struct linear_range bd71828_buck5_volts[] = {
  74. REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
  75. REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
  76. };
  77. static const struct linear_range bd71828_ldo_volts[] = {
  78. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
  79. REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
  80. };
  81. static const unsigned int bd71828_ramp_delay[] = { 2500, 5000, 10000, 20000 };
  82. static int buck_set_hw_dvs_levels(struct device_node *np,
  83. const struct regulator_desc *desc,
  84. struct regulator_config *cfg)
  85. {
  86. struct bd71828_regulator_data *data;
  87. data = container_of(desc, struct bd71828_regulator_data, desc);
  88. return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
  89. }
  90. static int ldo6_parse_dt(struct device_node *np,
  91. const struct regulator_desc *desc,
  92. struct regulator_config *cfg)
  93. {
  94. int ret, i;
  95. uint32_t uv = 0;
  96. unsigned int en;
  97. struct regmap *regmap = cfg->regmap;
  98. static const char * const props[] = { "rohm,dvs-run-voltage",
  99. "rohm,dvs-idle-voltage",
  100. "rohm,dvs-suspend-voltage",
  101. "rohm,dvs-lpsr-voltage" };
  102. unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
  103. BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
  104. for (i = 0; i < ARRAY_SIZE(props); i++) {
  105. ret = of_property_read_u32(np, props[i], &uv);
  106. if (ret) {
  107. if (ret != -EINVAL)
  108. return ret;
  109. continue;
  110. }
  111. if (uv)
  112. en = 0xffffffff;
  113. else
  114. en = 0;
  115. ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
  116. if (ret)
  117. return ret;
  118. }
  119. return 0;
  120. }
  121. static const struct regulator_ops bd71828_buck_ops = {
  122. .enable = regulator_enable_regmap,
  123. .disable = regulator_disable_regmap,
  124. .is_enabled = regulator_is_enabled_regmap,
  125. .list_voltage = regulator_list_voltage_linear_range,
  126. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  127. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  128. };
  129. static const struct regulator_ops bd71828_dvs_buck_ops = {
  130. .enable = regulator_enable_regmap,
  131. .disable = regulator_disable_regmap,
  132. .is_enabled = regulator_is_enabled_regmap,
  133. .list_voltage = regulator_list_voltage_linear_range,
  134. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  135. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  136. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  137. .set_ramp_delay = regulator_set_ramp_delay_regmap,
  138. };
  139. static const struct regulator_ops bd71828_ldo_ops = {
  140. .enable = regulator_enable_regmap,
  141. .disable = regulator_disable_regmap,
  142. .is_enabled = regulator_is_enabled_regmap,
  143. .list_voltage = regulator_list_voltage_linear_range,
  144. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  145. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  146. };
  147. static const struct regulator_ops bd71828_ldo6_ops = {
  148. .enable = regulator_enable_regmap,
  149. .disable = regulator_disable_regmap,
  150. .is_enabled = regulator_is_enabled_regmap,
  151. };
  152. static const struct bd71828_regulator_data bd71828_rdata[] = {
  153. {
  154. .desc = {
  155. .name = "buck1",
  156. .of_match = of_match_ptr("BUCK1"),
  157. .regulators_node = of_match_ptr("regulators"),
  158. .id = BD71828_BUCK1,
  159. .ops = &bd71828_dvs_buck_ops,
  160. .type = REGULATOR_VOLTAGE,
  161. .linear_ranges = bd71828_buck1267_volts,
  162. .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
  163. .n_voltages = BD71828_BUCK1267_VOLTS,
  164. .enable_reg = BD71828_REG_BUCK1_EN,
  165. .enable_mask = BD71828_MASK_RUN_EN,
  166. .vsel_reg = BD71828_REG_BUCK1_VOLT,
  167. .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
  168. .ramp_delay_table = bd71828_ramp_delay,
  169. .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
  170. .ramp_reg = BD71828_REG_BUCK1_MODE,
  171. .ramp_mask = BD71828_MASK_RAMP_DELAY,
  172. .owner = THIS_MODULE,
  173. .of_parse_cb = buck_set_hw_dvs_levels,
  174. },
  175. .dvs = {
  176. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  177. ROHM_DVS_LEVEL_SUSPEND |
  178. ROHM_DVS_LEVEL_LPSR,
  179. .run_reg = BD71828_REG_BUCK1_VOLT,
  180. .run_mask = BD71828_MASK_BUCK1267_VOLT,
  181. .idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
  182. .idle_mask = BD71828_MASK_BUCK1267_VOLT,
  183. .idle_on_mask = BD71828_MASK_IDLE_EN,
  184. .suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
  185. .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
  186. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  187. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  188. /*
  189. * LPSR voltage is same as SUSPEND voltage. Allow
  190. * setting it so that regulator can be set enabled at
  191. * LPSR state
  192. */
  193. .lpsr_reg = BD71828_REG_BUCK1_SUSP_VOLT,
  194. .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
  195. },
  196. .reg_inits = buck1_inits,
  197. .reg_init_amnt = ARRAY_SIZE(buck1_inits),
  198. },
  199. {
  200. .desc = {
  201. .name = "buck2",
  202. .of_match = of_match_ptr("BUCK2"),
  203. .regulators_node = of_match_ptr("regulators"),
  204. .id = BD71828_BUCK2,
  205. .ops = &bd71828_dvs_buck_ops,
  206. .type = REGULATOR_VOLTAGE,
  207. .linear_ranges = bd71828_buck1267_volts,
  208. .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
  209. .n_voltages = BD71828_BUCK1267_VOLTS,
  210. .enable_reg = BD71828_REG_BUCK2_EN,
  211. .enable_mask = BD71828_MASK_RUN_EN,
  212. .vsel_reg = BD71828_REG_BUCK2_VOLT,
  213. .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
  214. .ramp_delay_table = bd71828_ramp_delay,
  215. .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
  216. .ramp_reg = BD71828_REG_BUCK2_MODE,
  217. .ramp_mask = BD71828_MASK_RAMP_DELAY,
  218. .owner = THIS_MODULE,
  219. .of_parse_cb = buck_set_hw_dvs_levels,
  220. },
  221. .dvs = {
  222. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  223. ROHM_DVS_LEVEL_SUSPEND |
  224. ROHM_DVS_LEVEL_LPSR,
  225. .run_reg = BD71828_REG_BUCK2_VOLT,
  226. .run_mask = BD71828_MASK_BUCK1267_VOLT,
  227. .idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
  228. .idle_mask = BD71828_MASK_BUCK1267_VOLT,
  229. .idle_on_mask = BD71828_MASK_IDLE_EN,
  230. .suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
  231. .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
  232. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  233. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  234. .lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
  235. .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
  236. },
  237. .reg_inits = buck2_inits,
  238. .reg_init_amnt = ARRAY_SIZE(buck2_inits),
  239. },
  240. {
  241. .desc = {
  242. .name = "buck3",
  243. .of_match = of_match_ptr("BUCK3"),
  244. .regulators_node = of_match_ptr("regulators"),
  245. .id = BD71828_BUCK3,
  246. .ops = &bd71828_buck_ops,
  247. .type = REGULATOR_VOLTAGE,
  248. .linear_ranges = bd71828_buck3_volts,
  249. .n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
  250. .n_voltages = BD71828_BUCK3_VOLTS,
  251. .enable_reg = BD71828_REG_BUCK3_EN,
  252. .enable_mask = BD71828_MASK_RUN_EN,
  253. .vsel_reg = BD71828_REG_BUCK3_VOLT,
  254. .vsel_mask = BD71828_MASK_BUCK3_VOLT,
  255. .owner = THIS_MODULE,
  256. .of_parse_cb = buck_set_hw_dvs_levels,
  257. },
  258. .dvs = {
  259. /*
  260. * BUCK3 only supports single voltage for all states.
  261. * voltage can be individually enabled for each state
  262. * though => allow setting all states to support
  263. * enabling power rail on different states.
  264. */
  265. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  266. ROHM_DVS_LEVEL_SUSPEND |
  267. ROHM_DVS_LEVEL_LPSR,
  268. .run_reg = BD71828_REG_BUCK3_VOLT,
  269. .idle_reg = BD71828_REG_BUCK3_VOLT,
  270. .suspend_reg = BD71828_REG_BUCK3_VOLT,
  271. .lpsr_reg = BD71828_REG_BUCK3_VOLT,
  272. .run_mask = BD71828_MASK_BUCK3_VOLT,
  273. .idle_mask = BD71828_MASK_BUCK3_VOLT,
  274. .suspend_mask = BD71828_MASK_BUCK3_VOLT,
  275. .lpsr_mask = BD71828_MASK_BUCK3_VOLT,
  276. .idle_on_mask = BD71828_MASK_IDLE_EN,
  277. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  278. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  279. },
  280. },
  281. {
  282. .desc = {
  283. .name = "buck4",
  284. .of_match = of_match_ptr("BUCK4"),
  285. .regulators_node = of_match_ptr("regulators"),
  286. .id = BD71828_BUCK4,
  287. .ops = &bd71828_buck_ops,
  288. .type = REGULATOR_VOLTAGE,
  289. .linear_ranges = bd71828_buck4_volts,
  290. .n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
  291. .n_voltages = BD71828_BUCK4_VOLTS,
  292. .enable_reg = BD71828_REG_BUCK4_EN,
  293. .enable_mask = BD71828_MASK_RUN_EN,
  294. .vsel_reg = BD71828_REG_BUCK4_VOLT,
  295. .vsel_mask = BD71828_MASK_BUCK4_VOLT,
  296. .owner = THIS_MODULE,
  297. .of_parse_cb = buck_set_hw_dvs_levels,
  298. },
  299. .dvs = {
  300. /*
  301. * BUCK4 only supports single voltage for all states.
  302. * voltage can be individually enabled for each state
  303. * though => allow setting all states to support
  304. * enabling power rail on different states.
  305. */
  306. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  307. ROHM_DVS_LEVEL_SUSPEND |
  308. ROHM_DVS_LEVEL_LPSR,
  309. .run_reg = BD71828_REG_BUCK4_VOLT,
  310. .idle_reg = BD71828_REG_BUCK4_VOLT,
  311. .suspend_reg = BD71828_REG_BUCK4_VOLT,
  312. .lpsr_reg = BD71828_REG_BUCK4_VOLT,
  313. .run_mask = BD71828_MASK_BUCK4_VOLT,
  314. .idle_mask = BD71828_MASK_BUCK4_VOLT,
  315. .suspend_mask = BD71828_MASK_BUCK4_VOLT,
  316. .lpsr_mask = BD71828_MASK_BUCK4_VOLT,
  317. .idle_on_mask = BD71828_MASK_IDLE_EN,
  318. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  319. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  320. },
  321. },
  322. {
  323. .desc = {
  324. .name = "buck5",
  325. .of_match = of_match_ptr("BUCK5"),
  326. .regulators_node = of_match_ptr("regulators"),
  327. .id = BD71828_BUCK5,
  328. .ops = &bd71828_buck_ops,
  329. .type = REGULATOR_VOLTAGE,
  330. .linear_ranges = bd71828_buck5_volts,
  331. .n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
  332. .n_voltages = BD71828_BUCK5_VOLTS,
  333. .enable_reg = BD71828_REG_BUCK5_EN,
  334. .enable_mask = BD71828_MASK_RUN_EN,
  335. .vsel_reg = BD71828_REG_BUCK5_VOLT,
  336. .vsel_mask = BD71828_MASK_BUCK5_VOLT,
  337. .owner = THIS_MODULE,
  338. .of_parse_cb = buck_set_hw_dvs_levels,
  339. },
  340. .dvs = {
  341. /*
  342. * BUCK5 only supports single voltage for all states.
  343. * voltage can be individually enabled for each state
  344. * though => allow setting all states to support
  345. * enabling power rail on different states.
  346. */
  347. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  348. ROHM_DVS_LEVEL_SUSPEND |
  349. ROHM_DVS_LEVEL_LPSR,
  350. .run_reg = BD71828_REG_BUCK5_VOLT,
  351. .idle_reg = BD71828_REG_BUCK5_VOLT,
  352. .suspend_reg = BD71828_REG_BUCK5_VOLT,
  353. .lpsr_reg = BD71828_REG_BUCK5_VOLT,
  354. .run_mask = BD71828_MASK_BUCK5_VOLT,
  355. .idle_mask = BD71828_MASK_BUCK5_VOLT,
  356. .suspend_mask = BD71828_MASK_BUCK5_VOLT,
  357. .lpsr_mask = BD71828_MASK_BUCK5_VOLT,
  358. .idle_on_mask = BD71828_MASK_IDLE_EN,
  359. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  360. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  361. },
  362. },
  363. {
  364. .desc = {
  365. .name = "buck6",
  366. .of_match = of_match_ptr("BUCK6"),
  367. .regulators_node = of_match_ptr("regulators"),
  368. .id = BD71828_BUCK6,
  369. .ops = &bd71828_dvs_buck_ops,
  370. .type = REGULATOR_VOLTAGE,
  371. .linear_ranges = bd71828_buck1267_volts,
  372. .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
  373. .n_voltages = BD71828_BUCK1267_VOLTS,
  374. .enable_reg = BD71828_REG_BUCK6_EN,
  375. .enable_mask = BD71828_MASK_RUN_EN,
  376. .vsel_reg = BD71828_REG_BUCK6_VOLT,
  377. .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
  378. .ramp_delay_table = bd71828_ramp_delay,
  379. .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
  380. .ramp_reg = BD71828_REG_BUCK6_MODE,
  381. .ramp_mask = BD71828_MASK_RAMP_DELAY,
  382. .owner = THIS_MODULE,
  383. .of_parse_cb = buck_set_hw_dvs_levels,
  384. },
  385. .dvs = {
  386. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  387. ROHM_DVS_LEVEL_SUSPEND |
  388. ROHM_DVS_LEVEL_LPSR,
  389. .run_reg = BD71828_REG_BUCK6_VOLT,
  390. .run_mask = BD71828_MASK_BUCK1267_VOLT,
  391. .idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
  392. .idle_mask = BD71828_MASK_BUCK1267_VOLT,
  393. .idle_on_mask = BD71828_MASK_IDLE_EN,
  394. .suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
  395. .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
  396. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  397. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  398. .lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
  399. .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
  400. },
  401. .reg_inits = buck6_inits,
  402. .reg_init_amnt = ARRAY_SIZE(buck6_inits),
  403. },
  404. {
  405. .desc = {
  406. .name = "buck7",
  407. .of_match = of_match_ptr("BUCK7"),
  408. .regulators_node = of_match_ptr("regulators"),
  409. .id = BD71828_BUCK7,
  410. .ops = &bd71828_dvs_buck_ops,
  411. .type = REGULATOR_VOLTAGE,
  412. .linear_ranges = bd71828_buck1267_volts,
  413. .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
  414. .n_voltages = BD71828_BUCK1267_VOLTS,
  415. .enable_reg = BD71828_REG_BUCK7_EN,
  416. .enable_mask = BD71828_MASK_RUN_EN,
  417. .vsel_reg = BD71828_REG_BUCK7_VOLT,
  418. .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
  419. .ramp_delay_table = bd71828_ramp_delay,
  420. .n_ramp_values = ARRAY_SIZE(bd71828_ramp_delay),
  421. .ramp_reg = BD71828_REG_BUCK7_MODE,
  422. .ramp_mask = BD71828_MASK_RAMP_DELAY,
  423. .owner = THIS_MODULE,
  424. .of_parse_cb = buck_set_hw_dvs_levels,
  425. },
  426. .dvs = {
  427. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  428. ROHM_DVS_LEVEL_SUSPEND |
  429. ROHM_DVS_LEVEL_LPSR,
  430. .run_reg = BD71828_REG_BUCK7_VOLT,
  431. .run_mask = BD71828_MASK_BUCK1267_VOLT,
  432. .idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
  433. .idle_mask = BD71828_MASK_BUCK1267_VOLT,
  434. .idle_on_mask = BD71828_MASK_IDLE_EN,
  435. .suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
  436. .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
  437. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  438. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  439. .lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
  440. .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
  441. },
  442. .reg_inits = buck7_inits,
  443. .reg_init_amnt = ARRAY_SIZE(buck7_inits),
  444. },
  445. {
  446. .desc = {
  447. .name = "ldo1",
  448. .of_match = of_match_ptr("LDO1"),
  449. .regulators_node = of_match_ptr("regulators"),
  450. .id = BD71828_LDO1,
  451. .ops = &bd71828_ldo_ops,
  452. .type = REGULATOR_VOLTAGE,
  453. .linear_ranges = bd71828_ldo_volts,
  454. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  455. .n_voltages = BD71828_LDO_VOLTS,
  456. .enable_reg = BD71828_REG_LDO1_EN,
  457. .enable_mask = BD71828_MASK_RUN_EN,
  458. .vsel_reg = BD71828_REG_LDO1_VOLT,
  459. .vsel_mask = BD71828_MASK_LDO_VOLT,
  460. .owner = THIS_MODULE,
  461. .of_parse_cb = buck_set_hw_dvs_levels,
  462. },
  463. .dvs = {
  464. /*
  465. * LDO1 only supports single voltage for all states.
  466. * voltage can be individually enabled for each state
  467. * though => allow setting all states to support
  468. * enabling power rail on different states.
  469. */
  470. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  471. ROHM_DVS_LEVEL_SUSPEND |
  472. ROHM_DVS_LEVEL_LPSR,
  473. .run_reg = BD71828_REG_LDO1_VOLT,
  474. .idle_reg = BD71828_REG_LDO1_VOLT,
  475. .suspend_reg = BD71828_REG_LDO1_VOLT,
  476. .lpsr_reg = BD71828_REG_LDO1_VOLT,
  477. .run_mask = BD71828_MASK_LDO_VOLT,
  478. .idle_mask = BD71828_MASK_LDO_VOLT,
  479. .suspend_mask = BD71828_MASK_LDO_VOLT,
  480. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  481. .idle_on_mask = BD71828_MASK_IDLE_EN,
  482. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  483. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  484. },
  485. }, {
  486. .desc = {
  487. .name = "ldo2",
  488. .of_match = of_match_ptr("LDO2"),
  489. .regulators_node = of_match_ptr("regulators"),
  490. .id = BD71828_LDO2,
  491. .ops = &bd71828_ldo_ops,
  492. .type = REGULATOR_VOLTAGE,
  493. .linear_ranges = bd71828_ldo_volts,
  494. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  495. .n_voltages = BD71828_LDO_VOLTS,
  496. .enable_reg = BD71828_REG_LDO2_EN,
  497. .enable_mask = BD71828_MASK_RUN_EN,
  498. .vsel_reg = BD71828_REG_LDO2_VOLT,
  499. .vsel_mask = BD71828_MASK_LDO_VOLT,
  500. .owner = THIS_MODULE,
  501. .of_parse_cb = buck_set_hw_dvs_levels,
  502. },
  503. .dvs = {
  504. /*
  505. * LDO2 only supports single voltage for all states.
  506. * voltage can be individually enabled for each state
  507. * though => allow setting all states to support
  508. * enabling power rail on different states.
  509. */
  510. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  511. ROHM_DVS_LEVEL_SUSPEND |
  512. ROHM_DVS_LEVEL_LPSR,
  513. .run_reg = BD71828_REG_LDO2_VOLT,
  514. .idle_reg = BD71828_REG_LDO2_VOLT,
  515. .suspend_reg = BD71828_REG_LDO2_VOLT,
  516. .lpsr_reg = BD71828_REG_LDO2_VOLT,
  517. .run_mask = BD71828_MASK_LDO_VOLT,
  518. .idle_mask = BD71828_MASK_LDO_VOLT,
  519. .suspend_mask = BD71828_MASK_LDO_VOLT,
  520. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  521. .idle_on_mask = BD71828_MASK_IDLE_EN,
  522. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  523. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  524. },
  525. }, {
  526. .desc = {
  527. .name = "ldo3",
  528. .of_match = of_match_ptr("LDO3"),
  529. .regulators_node = of_match_ptr("regulators"),
  530. .id = BD71828_LDO3,
  531. .ops = &bd71828_ldo_ops,
  532. .type = REGULATOR_VOLTAGE,
  533. .linear_ranges = bd71828_ldo_volts,
  534. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  535. .n_voltages = BD71828_LDO_VOLTS,
  536. .enable_reg = BD71828_REG_LDO3_EN,
  537. .enable_mask = BD71828_MASK_RUN_EN,
  538. .vsel_reg = BD71828_REG_LDO3_VOLT,
  539. .vsel_mask = BD71828_MASK_LDO_VOLT,
  540. .owner = THIS_MODULE,
  541. .of_parse_cb = buck_set_hw_dvs_levels,
  542. },
  543. .dvs = {
  544. /*
  545. * LDO3 only supports single voltage for all states.
  546. * voltage can be individually enabled for each state
  547. * though => allow setting all states to support
  548. * enabling power rail on different states.
  549. */
  550. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  551. ROHM_DVS_LEVEL_SUSPEND |
  552. ROHM_DVS_LEVEL_LPSR,
  553. .run_reg = BD71828_REG_LDO3_VOLT,
  554. .idle_reg = BD71828_REG_LDO3_VOLT,
  555. .suspend_reg = BD71828_REG_LDO3_VOLT,
  556. .lpsr_reg = BD71828_REG_LDO3_VOLT,
  557. .run_mask = BD71828_MASK_LDO_VOLT,
  558. .idle_mask = BD71828_MASK_LDO_VOLT,
  559. .suspend_mask = BD71828_MASK_LDO_VOLT,
  560. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  561. .idle_on_mask = BD71828_MASK_IDLE_EN,
  562. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  563. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  564. },
  565. }, {
  566. .desc = {
  567. .name = "ldo4",
  568. .of_match = of_match_ptr("LDO4"),
  569. .regulators_node = of_match_ptr("regulators"),
  570. .id = BD71828_LDO4,
  571. .ops = &bd71828_ldo_ops,
  572. .type = REGULATOR_VOLTAGE,
  573. .linear_ranges = bd71828_ldo_volts,
  574. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  575. .n_voltages = BD71828_LDO_VOLTS,
  576. .enable_reg = BD71828_REG_LDO4_EN,
  577. .enable_mask = BD71828_MASK_RUN_EN,
  578. .vsel_reg = BD71828_REG_LDO4_VOLT,
  579. .vsel_mask = BD71828_MASK_LDO_VOLT,
  580. .owner = THIS_MODULE,
  581. .of_parse_cb = buck_set_hw_dvs_levels,
  582. },
  583. .dvs = {
  584. /*
  585. * LDO1 only supports single voltage for all states.
  586. * voltage can be individually enabled for each state
  587. * though => allow setting all states to support
  588. * enabling power rail on different states.
  589. */
  590. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  591. ROHM_DVS_LEVEL_SUSPEND |
  592. ROHM_DVS_LEVEL_LPSR,
  593. .run_reg = BD71828_REG_LDO4_VOLT,
  594. .idle_reg = BD71828_REG_LDO4_VOLT,
  595. .suspend_reg = BD71828_REG_LDO4_VOLT,
  596. .lpsr_reg = BD71828_REG_LDO4_VOLT,
  597. .run_mask = BD71828_MASK_LDO_VOLT,
  598. .idle_mask = BD71828_MASK_LDO_VOLT,
  599. .suspend_mask = BD71828_MASK_LDO_VOLT,
  600. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  601. .idle_on_mask = BD71828_MASK_IDLE_EN,
  602. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  603. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  604. },
  605. }, {
  606. .desc = {
  607. .name = "ldo5",
  608. .of_match = of_match_ptr("LDO5"),
  609. .regulators_node = of_match_ptr("regulators"),
  610. .id = BD71828_LDO5,
  611. .ops = &bd71828_ldo_ops,
  612. .type = REGULATOR_VOLTAGE,
  613. .linear_ranges = bd71828_ldo_volts,
  614. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  615. .n_voltages = BD71828_LDO_VOLTS,
  616. .enable_reg = BD71828_REG_LDO5_EN,
  617. .enable_mask = BD71828_MASK_RUN_EN,
  618. .vsel_reg = BD71828_REG_LDO5_VOLT,
  619. .vsel_mask = BD71828_MASK_LDO_VOLT,
  620. .of_parse_cb = buck_set_hw_dvs_levels,
  621. .owner = THIS_MODULE,
  622. },
  623. /*
  624. * LDO5 is special. It can choose vsel settings to be configured
  625. * from 2 different registers (by GPIO).
  626. *
  627. * This driver supports only configuration where
  628. * BD71828_REG_LDO5_VOLT_L is used.
  629. */
  630. .dvs = {
  631. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  632. ROHM_DVS_LEVEL_SUSPEND |
  633. ROHM_DVS_LEVEL_LPSR,
  634. .run_reg = BD71828_REG_LDO5_VOLT,
  635. .idle_reg = BD71828_REG_LDO5_VOLT,
  636. .suspend_reg = BD71828_REG_LDO5_VOLT,
  637. .lpsr_reg = BD71828_REG_LDO5_VOLT,
  638. .run_mask = BD71828_MASK_LDO_VOLT,
  639. .idle_mask = BD71828_MASK_LDO_VOLT,
  640. .suspend_mask = BD71828_MASK_LDO_VOLT,
  641. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  642. .idle_on_mask = BD71828_MASK_IDLE_EN,
  643. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  644. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  645. },
  646. }, {
  647. .desc = {
  648. .name = "ldo6",
  649. .of_match = of_match_ptr("LDO6"),
  650. .regulators_node = of_match_ptr("regulators"),
  651. .id = BD71828_LDO6,
  652. .ops = &bd71828_ldo6_ops,
  653. .type = REGULATOR_VOLTAGE,
  654. .fixed_uV = BD71828_LDO_6_VOLTAGE,
  655. .n_voltages = 1,
  656. .enable_reg = BD71828_REG_LDO6_EN,
  657. .enable_mask = BD71828_MASK_RUN_EN,
  658. .owner = THIS_MODULE,
  659. /*
  660. * LDO6 only supports enable/disable for all states.
  661. * Voltage for LDO6 is fixed.
  662. */
  663. .of_parse_cb = ldo6_parse_dt,
  664. },
  665. }, {
  666. .desc = {
  667. /* SNVS LDO in data-sheet */
  668. .name = "ldo7",
  669. .of_match = of_match_ptr("LDO7"),
  670. .regulators_node = of_match_ptr("regulators"),
  671. .id = BD71828_LDO_SNVS,
  672. .ops = &bd71828_ldo_ops,
  673. .type = REGULATOR_VOLTAGE,
  674. .linear_ranges = bd71828_ldo_volts,
  675. .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
  676. .n_voltages = BD71828_LDO_VOLTS,
  677. .enable_reg = BD71828_REG_LDO7_EN,
  678. .enable_mask = BD71828_MASK_RUN_EN,
  679. .vsel_reg = BD71828_REG_LDO7_VOLT,
  680. .vsel_mask = BD71828_MASK_LDO_VOLT,
  681. .owner = THIS_MODULE,
  682. .of_parse_cb = buck_set_hw_dvs_levels,
  683. },
  684. .dvs = {
  685. /*
  686. * LDO7 only supports single voltage for all states.
  687. * voltage can be individually enabled for each state
  688. * though => allow setting all states to support
  689. * enabling power rail on different states.
  690. */
  691. .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
  692. ROHM_DVS_LEVEL_SUSPEND |
  693. ROHM_DVS_LEVEL_LPSR,
  694. .run_reg = BD71828_REG_LDO7_VOLT,
  695. .idle_reg = BD71828_REG_LDO7_VOLT,
  696. .suspend_reg = BD71828_REG_LDO7_VOLT,
  697. .lpsr_reg = BD71828_REG_LDO7_VOLT,
  698. .run_mask = BD71828_MASK_LDO_VOLT,
  699. .idle_mask = BD71828_MASK_LDO_VOLT,
  700. .suspend_mask = BD71828_MASK_LDO_VOLT,
  701. .lpsr_mask = BD71828_MASK_LDO_VOLT,
  702. .idle_on_mask = BD71828_MASK_IDLE_EN,
  703. .suspend_on_mask = BD71828_MASK_SUSP_EN,
  704. .lpsr_on_mask = BD71828_MASK_LPSR_EN,
  705. },
  706. },
  707. };
  708. static int bd71828_probe(struct platform_device *pdev)
  709. {
  710. int i, j, ret;
  711. struct regulator_config config = {
  712. .dev = pdev->dev.parent,
  713. };
  714. config.regmap = dev_get_regmap(pdev->dev.parent, NULL);
  715. if (!config.regmap)
  716. return -ENODEV;
  717. for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
  718. struct regulator_dev *rdev;
  719. const struct bd71828_regulator_data *rd;
  720. rd = &bd71828_rdata[i];
  721. rdev = devm_regulator_register(&pdev->dev,
  722. &rd->desc, &config);
  723. if (IS_ERR(rdev)) {
  724. dev_err(&pdev->dev,
  725. "failed to register %s regulator\n",
  726. rd->desc.name);
  727. return PTR_ERR(rdev);
  728. }
  729. for (j = 0; j < rd->reg_init_amnt; j++) {
  730. ret = regmap_update_bits(config.regmap,
  731. rd->reg_inits[j].reg,
  732. rd->reg_inits[j].mask,
  733. rd->reg_inits[j].val);
  734. if (ret) {
  735. dev_err(&pdev->dev,
  736. "regulator %s init failed\n",
  737. rd->desc.name);
  738. return ret;
  739. }
  740. }
  741. }
  742. return 0;
  743. }
  744. static struct platform_driver bd71828_regulator = {
  745. .driver = {
  746. .name = "bd71828-pmic"
  747. },
  748. .probe = bd71828_probe,
  749. };
  750. module_platform_driver(bd71828_regulator);
  751. MODULE_AUTHOR("Matti Vaittinen <[email protected]>");
  752. MODULE_DESCRIPTION("BD71828 voltage regulator driver");
  753. MODULE_LICENSE("GPL");
  754. MODULE_ALIAS("platform:bd71828-pmic");