bd71837-regulator.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 ROHM Semiconductors
  3. // bd71837-regulator.c ROHM BD71837MWV regulator driver
  4. #include <linux/kernel.h>
  5. #include <linux/module.h>
  6. #include <linux/init.h>
  7. #include <linux/err.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/regulator/driver.h>
  11. #include <linux/regulator/machine.h>
  12. #include <linux/delay.h>
  13. #include <linux/slab.h>
  14. #include <linux/gpio.h>
  15. #include <linux/mfd/bd71837.h>
  16. #include <linux/regulator/of_regulator.h>
  17. struct bd71837_pmic {
  18. struct regulator_desc descs[BD71837_REGULATOR_CNT];
  19. struct bd71837 *mfd;
  20. struct platform_device *pdev;
  21. struct regulator_dev *rdev[BD71837_REGULATOR_CNT];
  22. };
  23. /*
  24. * BUCK1/2/3/4
  25. * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
  26. * 00: 10.00mV/usec 10mV 1uS
  27. * 01: 5.00mV/usec 10mV 2uS
  28. * 10: 2.50mV/usec 10mV 4uS
  29. * 11: 1.25mV/usec 10mV 8uS
  30. */
  31. static int bd71837_buck1234_set_ramp_delay(struct regulator_dev *rdev,
  32. int ramp_delay)
  33. {
  34. struct bd71837_pmic *pmic = rdev_get_drvdata(rdev);
  35. struct bd71837 *mfd = pmic->mfd;
  36. int id = rdev->desc->id;
  37. unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
  38. dev_dbg(&(pmic->pdev->dev), "Buck[%d] Set Ramp = %d\n", id + 1,
  39. ramp_delay);
  40. switch (ramp_delay) {
  41. case 1 ... 1250:
  42. ramp_value = BUCK_RAMPRATE_1P25MV;
  43. break;
  44. case 1251 ... 2500:
  45. ramp_value = BUCK_RAMPRATE_2P50MV;
  46. break;
  47. case 2501 ... 5000:
  48. ramp_value = BUCK_RAMPRATE_5P00MV;
  49. break;
  50. case 5001 ... 10000:
  51. ramp_value = BUCK_RAMPRATE_10P00MV;
  52. break;
  53. default:
  54. ramp_value = BUCK_RAMPRATE_10P00MV;
  55. dev_err(&pmic->pdev->dev,
  56. "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
  57. rdev->desc->name, ramp_delay);
  58. }
  59. return regmap_update_bits(mfd->regmap, BD71837_REG_BUCK1_CTRL + id,
  60. BUCK_RAMPRATE_MASK, ramp_value << 6);
  61. }
  62. /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
  63. * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
  64. * is changed. Hence we return -EBUSY for these if voltage is changed
  65. * when BUCK/LDO is enabled.
  66. */
  67. static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev,
  68. unsigned int sel)
  69. {
  70. int ret;
  71. ret = regulator_is_enabled_regmap(rdev);
  72. if (!ret)
  73. ret = regulator_set_voltage_sel_regmap(rdev, sel);
  74. else if (ret == 1)
  75. ret = -EBUSY;
  76. return ret;
  77. }
  78. static struct regulator_ops bd71837_ldo_regulator_ops = {
  79. .enable = regulator_enable_regmap,
  80. .disable = regulator_disable_regmap,
  81. .is_enabled = regulator_is_enabled_regmap,
  82. .list_voltage = regulator_list_voltage_linear_range,
  83. .set_voltage_sel = bd71837_set_voltage_sel_restricted,
  84. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  85. };
  86. static struct regulator_ops bd71837_ldo_regulator_nolinear_ops = {
  87. .enable = regulator_enable_regmap,
  88. .disable = regulator_disable_regmap,
  89. .is_enabled = regulator_is_enabled_regmap,
  90. .list_voltage = regulator_list_voltage_table,
  91. .set_voltage_sel = bd71837_set_voltage_sel_restricted,
  92. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  93. };
  94. static struct regulator_ops bd71837_buck_regulator_ops = {
  95. .enable = regulator_enable_regmap,
  96. .disable = regulator_disable_regmap,
  97. .is_enabled = regulator_is_enabled_regmap,
  98. .list_voltage = regulator_list_voltage_linear_range,
  99. .set_voltage_sel = bd71837_set_voltage_sel_restricted,
  100. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  101. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  102. };
  103. static struct regulator_ops bd71837_buck_regulator_nolinear_ops = {
  104. .enable = regulator_enable_regmap,
  105. .disable = regulator_disable_regmap,
  106. .is_enabled = regulator_is_enabled_regmap,
  107. .list_voltage = regulator_list_voltage_table,
  108. .set_voltage_sel = bd71837_set_voltage_sel_restricted,
  109. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  110. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  111. };
  112. static struct regulator_ops bd71837_buck1234_regulator_ops = {
  113. .enable = regulator_enable_regmap,
  114. .disable = regulator_disable_regmap,
  115. .is_enabled = regulator_is_enabled_regmap,
  116. .list_voltage = regulator_list_voltage_linear_range,
  117. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  118. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  119. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  120. .set_ramp_delay = bd71837_buck1234_set_ramp_delay,
  121. };
  122. /*
  123. * BUCK1/2/3/4
  124. * 0.70 to 1.30V (10mV step)
  125. */
  126. static const struct regulator_linear_range bd71837_buck1234_voltage_ranges[] = {
  127. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
  128. REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
  129. };
  130. /*
  131. * BUCK5
  132. * 0.9V to 1.35V ()
  133. */
  134. static const struct regulator_linear_range bd71837_buck5_voltage_ranges[] = {
  135. REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
  136. REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
  137. REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
  138. };
  139. /*
  140. * BUCK6
  141. * 3.0V to 3.3V (step 100mV)
  142. */
  143. static const struct regulator_linear_range bd71837_buck6_voltage_ranges[] = {
  144. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  145. };
  146. /*
  147. * BUCK7
  148. * 000 = 1.605V
  149. * 001 = 1.695V
  150. * 010 = 1.755V
  151. * 011 = 1.8V (Initial)
  152. * 100 = 1.845V
  153. * 101 = 1.905V
  154. * 110 = 1.95V
  155. * 111 = 1.995V
  156. */
  157. static const unsigned int buck_7_volts[] = {
  158. 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
  159. };
  160. /*
  161. * BUCK8
  162. * 0.8V to 1.40V (step 10mV)
  163. */
  164. static const struct regulator_linear_range bd71837_buck8_voltage_ranges[] = {
  165. REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
  166. REGULATOR_LINEAR_RANGE(1400000, 0x3D, 0x3F, 0),
  167. };
  168. /*
  169. * LDO1
  170. * 3.0 to 3.3V (100mV step)
  171. */
  172. static const struct regulator_linear_range bd71837_ldo1_voltage_ranges[] = {
  173. REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
  174. };
  175. /*
  176. * LDO2
  177. * 0.8 or 0.9V
  178. */
  179. const unsigned int ldo_2_volts[] = {
  180. 900000, 800000
  181. };
  182. /*
  183. * LDO3
  184. * 1.8 to 3.3V (100mV step)
  185. */
  186. static const struct regulator_linear_range bd71837_ldo3_voltage_ranges[] = {
  187. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  188. };
  189. /*
  190. * LDO4
  191. * 0.9 to 1.8V (100mV step)
  192. */
  193. static const struct regulator_linear_range bd71837_ldo4_voltage_ranges[] = {
  194. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  195. REGULATOR_LINEAR_RANGE(1800000, 0x0A, 0x0F, 0),
  196. };
  197. /*
  198. * LDO5
  199. * 1.8 to 3.3V (100mV step)
  200. */
  201. static const struct regulator_linear_range bd71837_ldo5_voltage_ranges[] = {
  202. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  203. };
  204. /*
  205. * LDO6
  206. * 0.9 to 1.8V (100mV step)
  207. */
  208. static const struct regulator_linear_range bd71837_ldo6_voltage_ranges[] = {
  209. REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
  210. REGULATOR_LINEAR_RANGE(1800000, 0x0A, 0x0F, 0),
  211. };
  212. /*
  213. * LDO7
  214. * 1.8 to 3.3V (100mV step)
  215. */
  216. static const struct regulator_linear_range bd71837_ldo7_voltage_ranges[] = {
  217. REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
  218. };
  219. static const struct regulator_desc bd71837_regulators[] = {
  220. {
  221. .name = "buck1",
  222. .of_match = of_match_ptr("BUCK1"),
  223. .regulators_node = of_match_ptr("regulators"),
  224. .id = BD71837_BUCK1,
  225. .ops = &bd71837_buck1234_regulator_ops,
  226. .type = REGULATOR_VOLTAGE,
  227. .n_voltages = BD71837_BUCK1_VOLTAGE_NUM,
  228. .linear_ranges = bd71837_buck1234_voltage_ranges,
  229. .n_linear_ranges = ARRAY_SIZE(bd71837_buck1234_voltage_ranges),
  230. .vsel_reg = BD71837_REG_BUCK1_VOLT_RUN,
  231. .vsel_mask = BUCK1_RUN_MASK,
  232. .enable_reg = BD71837_REG_BUCK1_CTRL,
  233. .enable_mask = BD71837_BUCK_EN,
  234. .owner = THIS_MODULE,
  235. },
  236. {
  237. .name = "buck2",
  238. .of_match = of_match_ptr("BUCK2"),
  239. .regulators_node = of_match_ptr("regulators"),
  240. .id = BD71837_BUCK2,
  241. .ops = &bd71837_buck1234_regulator_ops,
  242. .type = REGULATOR_VOLTAGE,
  243. .n_voltages = BD71837_BUCK2_VOLTAGE_NUM,
  244. .linear_ranges = bd71837_buck1234_voltage_ranges,
  245. .n_linear_ranges = ARRAY_SIZE(bd71837_buck1234_voltage_ranges),
  246. .vsel_reg = BD71837_REG_BUCK2_VOLT_RUN,
  247. .vsel_mask = BUCK2_RUN_MASK,
  248. .enable_reg = BD71837_REG_BUCK2_CTRL,
  249. .enable_mask = BD71837_BUCK_EN,
  250. .owner = THIS_MODULE,
  251. },
  252. {
  253. .name = "buck3",
  254. .of_match = of_match_ptr("BUCK3"),
  255. .regulators_node = of_match_ptr("regulators"),
  256. .id = BD71837_BUCK3,
  257. .ops = &bd71837_buck1234_regulator_ops,
  258. .type = REGULATOR_VOLTAGE,
  259. .n_voltages = BD71837_BUCK3_VOLTAGE_NUM,
  260. .linear_ranges = bd71837_buck1234_voltage_ranges,
  261. .n_linear_ranges = ARRAY_SIZE(bd71837_buck1234_voltage_ranges),
  262. .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
  263. .vsel_mask = BUCK3_RUN_MASK,
  264. .enable_reg = BD71837_REG_BUCK3_CTRL,
  265. .enable_mask = BD71837_BUCK_EN,
  266. .owner = THIS_MODULE,
  267. },
  268. {
  269. .name = "buck4",
  270. .of_match = of_match_ptr("BUCK4"),
  271. .regulators_node = of_match_ptr("regulators"),
  272. .id = BD71837_BUCK4,
  273. .ops = &bd71837_buck1234_regulator_ops,
  274. .type = REGULATOR_VOLTAGE,
  275. .n_voltages = BD71837_BUCK4_VOLTAGE_NUM,
  276. .linear_ranges = bd71837_buck1234_voltage_ranges,
  277. .n_linear_ranges = ARRAY_SIZE(bd71837_buck1234_voltage_ranges),
  278. .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
  279. .vsel_mask = BUCK4_RUN_MASK,
  280. .enable_reg = BD71837_REG_BUCK4_CTRL,
  281. .enable_mask = BD71837_BUCK_EN,
  282. .owner = THIS_MODULE,
  283. },
  284. {
  285. .name = "buck5",
  286. .of_match = of_match_ptr("BUCK5"),
  287. .regulators_node = of_match_ptr("regulators"),
  288. .id = BD71837_BUCK5,
  289. .ops = &bd71837_buck_regulator_ops,
  290. .type = REGULATOR_VOLTAGE,
  291. .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
  292. .linear_ranges = bd71837_buck5_voltage_ranges,
  293. .n_linear_ranges = ARRAY_SIZE(bd71837_buck5_voltage_ranges),
  294. .vsel_reg = BD71837_REG_BUCK5_VOLT,
  295. .vsel_mask = BUCK5_MASK,
  296. .enable_reg = BD71837_REG_BUCK5_CTRL,
  297. .enable_mask = BD71837_BUCK_EN,
  298. .owner = THIS_MODULE,
  299. },
  300. {
  301. .name = "buck6",
  302. .of_match = of_match_ptr("BUCK6"),
  303. .regulators_node = of_match_ptr("regulators"),
  304. .id = BD71837_BUCK6,
  305. .ops = &bd71837_buck_regulator_ops,
  306. .type = REGULATOR_VOLTAGE,
  307. .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
  308. .linear_ranges = bd71837_buck6_voltage_ranges,
  309. .n_linear_ranges = ARRAY_SIZE(bd71837_buck6_voltage_ranges),
  310. .vsel_reg = BD71837_REG_BUCK6_VOLT,
  311. .vsel_mask = BUCK6_MASK,
  312. .enable_reg = BD71837_REG_BUCK6_CTRL,
  313. .enable_mask = BD71837_BUCK_EN,
  314. .owner = THIS_MODULE,
  315. },
  316. {
  317. .name = "buck7",
  318. .of_match = of_match_ptr("BUCK7"),
  319. .regulators_node = of_match_ptr("regulators"),
  320. .id = BD71837_BUCK7,
  321. .ops = &bd71837_buck_regulator_nolinear_ops,
  322. .type = REGULATOR_VOLTAGE,
  323. .volt_table = &buck_7_volts[0],
  324. .n_voltages = ARRAY_SIZE(buck_7_volts),
  325. .vsel_reg = BD71837_REG_BUCK7_VOLT,
  326. .vsel_mask = BUCK7_MASK,
  327. .enable_reg = BD71837_REG_BUCK7_CTRL,
  328. .enable_mask = BD71837_BUCK_EN,
  329. .owner = THIS_MODULE,
  330. },
  331. {
  332. .name = "buck8",
  333. .of_match = of_match_ptr("BUCK8"),
  334. .regulators_node = of_match_ptr("regulators"),
  335. .id = BD71837_BUCK8,
  336. .ops = &bd71837_buck_regulator_ops,
  337. .type = REGULATOR_VOLTAGE,
  338. .n_voltages = BD71837_BUCK8_VOLTAGE_NUM,
  339. .linear_ranges = bd71837_buck8_voltage_ranges,
  340. .n_linear_ranges = ARRAY_SIZE(bd71837_buck8_voltage_ranges),
  341. .vsel_reg = BD71837_REG_BUCK8_VOLT,
  342. .vsel_mask = BUCK8_MASK,
  343. .enable_reg = BD71837_REG_BUCK8_CTRL,
  344. .enable_mask = BD71837_BUCK_EN,
  345. .owner = THIS_MODULE,
  346. },
  347. {
  348. .name = "ldo1",
  349. .of_match = of_match_ptr("LDO1"),
  350. .regulators_node = of_match_ptr("regulators"),
  351. .id = BD71837_LDO1,
  352. .ops = &bd71837_ldo_regulator_ops,
  353. .type = REGULATOR_VOLTAGE,
  354. .n_voltages = BD71837_LDO1_VOLTAGE_NUM,
  355. .linear_ranges = bd71837_ldo1_voltage_ranges,
  356. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo1_voltage_ranges),
  357. .vsel_reg = BD71837_REG_LDO1_VOLT,
  358. .vsel_mask = LDO1_MASK,
  359. .enable_reg = BD71837_REG_LDO1_VOLT,
  360. .enable_mask = BD71837_LDO_EN,
  361. .owner = THIS_MODULE,
  362. },
  363. {
  364. .name = "ldo2",
  365. .of_match = of_match_ptr("LDO2"),
  366. .regulators_node = of_match_ptr("regulators"),
  367. .id = BD71837_LDO2,
  368. .ops = &bd71837_ldo_regulator_nolinear_ops,
  369. .type = REGULATOR_VOLTAGE,
  370. .volt_table = &ldo_2_volts[0],
  371. .vsel_reg = BD71837_REG_LDO2_VOLT,
  372. .vsel_mask = LDO2_MASK,
  373. .n_voltages = ARRAY_SIZE(ldo_2_volts),
  374. .n_voltages = BD71837_LDO2_VOLTAGE_NUM,
  375. .enable_reg = BD71837_REG_LDO2_VOLT,
  376. .enable_mask = BD71837_LDO_EN,
  377. .owner = THIS_MODULE,
  378. },
  379. {
  380. .name = "ldo3",
  381. .of_match = of_match_ptr("LDO3"),
  382. .regulators_node = of_match_ptr("regulators"),
  383. .id = BD71837_LDO3,
  384. .ops = &bd71837_ldo_regulator_ops,
  385. .type = REGULATOR_VOLTAGE,
  386. .n_voltages = BD71837_LDO3_VOLTAGE_NUM,
  387. .linear_ranges = bd71837_ldo3_voltage_ranges,
  388. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo3_voltage_ranges),
  389. .vsel_reg = BD71837_REG_LDO3_VOLT,
  390. .vsel_mask = LDO3_MASK,
  391. .enable_reg = BD71837_REG_LDO3_VOLT,
  392. .enable_mask = BD71837_LDO_EN,
  393. .owner = THIS_MODULE,
  394. },
  395. {
  396. .name = "ldo4",
  397. .of_match = of_match_ptr("LDO4"),
  398. .regulators_node = of_match_ptr("regulators"),
  399. .id = BD71837_LDO4,
  400. .ops = &bd71837_ldo_regulator_ops,
  401. .type = REGULATOR_VOLTAGE,
  402. .n_voltages = BD71837_LDO4_VOLTAGE_NUM,
  403. .linear_ranges = bd71837_ldo4_voltage_ranges,
  404. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo4_voltage_ranges),
  405. .vsel_reg = BD71837_REG_LDO4_VOLT,
  406. .vsel_mask = LDO4_MASK,
  407. .enable_reg = BD71837_REG_LDO4_VOLT,
  408. .enable_mask = BD71837_LDO_EN,
  409. .owner = THIS_MODULE,
  410. },
  411. {
  412. .name = "ldo5",
  413. .of_match = of_match_ptr("LDO5"),
  414. .regulators_node = of_match_ptr("regulators"),
  415. .id = BD71837_LDO5,
  416. .ops = &bd71837_ldo_regulator_ops,
  417. .type = REGULATOR_VOLTAGE,
  418. .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
  419. .linear_ranges = bd71837_ldo5_voltage_ranges,
  420. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_voltage_ranges),
  421. /* LDO5 is supplied by buck6 */
  422. .supply_name = "buck6",
  423. .vsel_reg = BD71837_REG_LDO5_VOLT,
  424. .vsel_mask = LDO5_MASK,
  425. .enable_reg = BD71837_REG_LDO5_VOLT,
  426. .enable_mask = BD71837_LDO_EN,
  427. .owner = THIS_MODULE,
  428. },
  429. {
  430. .name = "ldo6",
  431. .of_match = of_match_ptr("LDO6"),
  432. .regulators_node = of_match_ptr("regulators"),
  433. .id = BD71837_LDO6,
  434. .ops = &bd71837_ldo_regulator_ops,
  435. .type = REGULATOR_VOLTAGE,
  436. .n_voltages = BD71837_LDO6_VOLTAGE_NUM,
  437. .linear_ranges = bd71837_ldo6_voltage_ranges,
  438. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo6_voltage_ranges),
  439. /* LDO6 is supplied by buck7 */
  440. .supply_name = "buck7",
  441. .vsel_reg = BD71837_REG_LDO6_VOLT,
  442. .vsel_mask = LDO6_MASK,
  443. .enable_reg = BD71837_REG_LDO6_VOLT,
  444. .enable_mask = BD71837_LDO_EN,
  445. .owner = THIS_MODULE,
  446. },
  447. {
  448. .name = "ldo7",
  449. .of_match = of_match_ptr("LDO7"),
  450. .regulators_node = of_match_ptr("regulators"),
  451. .id = BD71837_LDO7,
  452. .ops = &bd71837_ldo_regulator_ops,
  453. .type = REGULATOR_VOLTAGE,
  454. .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
  455. .linear_ranges = bd71837_ldo7_voltage_ranges,
  456. .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_voltage_ranges),
  457. .vsel_reg = BD71837_REG_LDO7_VOLT,
  458. .vsel_mask = LDO7_MASK,
  459. .enable_reg = BD71837_REG_LDO7_VOLT,
  460. .enable_mask = BD71837_LDO_EN,
  461. .owner = THIS_MODULE,
  462. },
  463. };
  464. struct reg_init {
  465. unsigned int reg;
  466. unsigned int mask;
  467. };
  468. static int bd71837_probe(struct platform_device *pdev)
  469. {
  470. struct bd71837_pmic *pmic;
  471. struct bd71837_board *pdata;
  472. struct regulator_config config = { 0 };
  473. struct reg_init pmic_regulator_inits[] = {
  474. {
  475. .reg = BD71837_REG_BUCK1_CTRL,
  476. .mask = BD71837_BUCK_SEL,
  477. }, {
  478. .reg = BD71837_REG_BUCK2_CTRL,
  479. .mask = BD71837_BUCK_SEL,
  480. }, {
  481. .reg = BD71837_REG_BUCK3_CTRL,
  482. .mask = BD71837_BUCK_SEL,
  483. }, {
  484. .reg = BD71837_REG_BUCK4_CTRL,
  485. .mask = BD71837_BUCK_SEL,
  486. }, {
  487. .reg = BD71837_REG_BUCK5_CTRL,
  488. .mask = BD71837_BUCK_SEL,
  489. }, {
  490. .reg = BD71837_REG_BUCK6_CTRL,
  491. .mask = BD71837_BUCK_SEL,
  492. }, {
  493. .reg = BD71837_REG_BUCK7_CTRL,
  494. .mask = BD71837_BUCK_SEL,
  495. }, {
  496. .reg = BD71837_REG_BUCK8_CTRL,
  497. .mask = BD71837_BUCK_SEL,
  498. }, {
  499. .reg = BD71837_REG_LDO1_VOLT,
  500. .mask = BD71837_LDO_SEL,
  501. }, {
  502. .reg = BD71837_REG_LDO2_VOLT,
  503. .mask = BD71837_LDO_SEL,
  504. }, {
  505. .reg = BD71837_REG_LDO3_VOLT,
  506. .mask = BD71837_LDO_SEL,
  507. }, {
  508. .reg = BD71837_REG_LDO4_VOLT,
  509. .mask = BD71837_LDO_SEL,
  510. }, {
  511. .reg = BD71837_REG_LDO5_VOLT,
  512. .mask = BD71837_LDO_SEL,
  513. }, {
  514. .reg = BD71837_REG_LDO6_VOLT,
  515. .mask = BD71837_LDO_SEL,
  516. }, {
  517. .reg = BD71837_REG_LDO7_VOLT,
  518. .mask = BD71837_LDO_SEL,
  519. }
  520. };
  521. int i, err;
  522. pmic = devm_kzalloc(&pdev->dev, sizeof(struct bd71837_pmic),
  523. GFP_KERNEL);
  524. if (!pmic)
  525. return -ENOMEM;
  526. memcpy(pmic->descs, bd71837_regulators, sizeof(pmic->descs));
  527. pmic->pdev = pdev;
  528. pmic->mfd = dev_get_drvdata(pdev->dev.parent);
  529. if (!pmic->mfd) {
  530. dev_err(&pdev->dev, "No MFD driver data\n");
  531. err = -EINVAL;
  532. goto err;
  533. }
  534. platform_set_drvdata(pdev, pmic);
  535. pdata = dev_get_platdata(pmic->mfd->dev);
  536. /* Register LOCK release */
  537. err = regmap_update_bits(pmic->mfd->regmap, BD71837_REG_REGLOCK,
  538. (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
  539. if (err) {
  540. dev_err(&pmic->pdev->dev, "Failed to unlock PMIC (%d)\n", err);
  541. goto err;
  542. } else {
  543. dev_dbg(&pmic->pdev->dev, "%s: Unlocked lock register 0x%x\n",
  544. __func__, BD71837_REG_REGLOCK);
  545. }
  546. for (i = 0; i < ARRAY_SIZE(pmic_regulator_inits); i++) {
  547. struct regulator_desc *desc;
  548. struct regulator_dev *rdev;
  549. desc = &pmic->descs[i];
  550. if (pdata)
  551. config.init_data = pdata->init_data[i];
  552. config.dev = pdev->dev.parent;
  553. config.driver_data = pmic;
  554. config.regmap = pmic->mfd->regmap;
  555. rdev = devm_regulator_register(&pdev->dev, desc, &config);
  556. if (IS_ERR(rdev)) {
  557. dev_err(pmic->mfd->dev,
  558. "failed to register %s regulator\n",
  559. desc->name);
  560. err = PTR_ERR(rdev);
  561. goto err;
  562. }
  563. /* Regulator register gets the regulator constraints and
  564. * applies them (set_machine_constraints). This should have
  565. * turned the control register(s) to correct values and we
  566. * can now switch the control from PMIC state machine to the
  567. * register interface
  568. */
  569. err = regmap_update_bits(pmic->mfd->regmap,
  570. pmic_regulator_inits[i].reg,
  571. pmic_regulator_inits[i].mask,
  572. 0xFFFFFFFF);
  573. if (err) {
  574. dev_err(&pmic->pdev->dev,
  575. "Failed to write BUCK/LDO SEL bit for (%s)\n",
  576. desc->name);
  577. goto err;
  578. }
  579. pmic->rdev[i] = rdev;
  580. }
  581. return 0;
  582. err:
  583. return err;
  584. }
  585. static struct platform_driver bd71837_regulator = {
  586. .driver = {
  587. .name = "bd71837-pmic",
  588. .owner = THIS_MODULE,
  589. },
  590. .probe = bd71837_probe,
  591. };
  592. module_platform_driver(bd71837_regulator);
  593. MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
  594. MODULE_DESCRIPTION("BD71837 voltage regulator driver");
  595. MODULE_LICENSE("GPL");