bd71828-regulator.c 22 KB

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