bd71828-regulator.c 24 KB

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