mt6358-regulator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2019 MediaTek Inc.
  4. #include <linux/mfd/mt6358/registers.h>
  5. #include <linux/mfd/mt6397/core.h>
  6. #include <linux/module.h>
  7. #include <linux/of.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/regmap.h>
  10. #include <linux/regulator/driver.h>
  11. #include <linux/regulator/machine.h>
  12. #include <linux/regulator/mt6358-regulator.h>
  13. #include <linux/regulator/of_regulator.h>
  14. #define MT6358_BUCK_MODE_AUTO 0
  15. #define MT6358_BUCK_MODE_FORCE_PWM 1
  16. /*
  17. * MT6358 regulators' information
  18. *
  19. * @desc: standard fields of regulator description.
  20. * @qi: Mask for query enable signal status of regulators
  21. */
  22. struct mt6358_regulator_info {
  23. struct regulator_desc desc;
  24. u32 status_reg;
  25. u32 qi;
  26. const u32 *index_table;
  27. unsigned int n_table;
  28. u32 vsel_shift;
  29. u32 da_vsel_reg;
  30. u32 da_vsel_mask;
  31. u32 da_vsel_shift;
  32. u32 modeset_reg;
  33. u32 modeset_mask;
  34. u32 modeset_shift;
  35. };
  36. #define MT6358_BUCK(match, vreg, min, max, step, \
  37. volt_ranges, vosel_mask, _da_vsel_reg, _da_vsel_mask, \
  38. _da_vsel_shift, _modeset_reg, _modeset_shift) \
  39. [MT6358_ID_##vreg] = { \
  40. .desc = { \
  41. .name = #vreg, \
  42. .of_match = of_match_ptr(match), \
  43. .ops = &mt6358_volt_range_ops, \
  44. .type = REGULATOR_VOLTAGE, \
  45. .id = MT6358_ID_##vreg, \
  46. .owner = THIS_MODULE, \
  47. .n_voltages = ((max) - (min)) / (step) + 1, \
  48. .linear_ranges = volt_ranges, \
  49. .n_linear_ranges = ARRAY_SIZE(volt_ranges), \
  50. .vsel_reg = MT6358_BUCK_##vreg##_ELR0, \
  51. .vsel_mask = vosel_mask, \
  52. .enable_reg = MT6358_BUCK_##vreg##_CON0, \
  53. .enable_mask = BIT(0), \
  54. .of_map_mode = mt6358_map_mode, \
  55. }, \
  56. .status_reg = MT6358_BUCK_##vreg##_DBG1, \
  57. .qi = BIT(0), \
  58. .da_vsel_reg = _da_vsel_reg, \
  59. .da_vsel_mask = _da_vsel_mask, \
  60. .da_vsel_shift = _da_vsel_shift, \
  61. .modeset_reg = _modeset_reg, \
  62. .modeset_mask = BIT(_modeset_shift), \
  63. .modeset_shift = _modeset_shift \
  64. }
  65. #define MT6358_LDO(match, vreg, ldo_volt_table, \
  66. ldo_index_table, enreg, enbit, vosel, \
  67. vosel_mask, vosel_shift) \
  68. [MT6358_ID_##vreg] = { \
  69. .desc = { \
  70. .name = #vreg, \
  71. .of_match = of_match_ptr(match), \
  72. .ops = &mt6358_volt_table_ops, \
  73. .type = REGULATOR_VOLTAGE, \
  74. .id = MT6358_ID_##vreg, \
  75. .owner = THIS_MODULE, \
  76. .n_voltages = ARRAY_SIZE(ldo_volt_table), \
  77. .volt_table = ldo_volt_table, \
  78. .vsel_reg = vosel, \
  79. .vsel_mask = vosel_mask, \
  80. .enable_reg = enreg, \
  81. .enable_mask = BIT(enbit), \
  82. }, \
  83. .status_reg = MT6358_LDO_##vreg##_CON1, \
  84. .qi = BIT(15), \
  85. .index_table = ldo_index_table, \
  86. .n_table = ARRAY_SIZE(ldo_index_table), \
  87. .vsel_shift = vosel_shift, \
  88. }
  89. #define MT6358_LDO1(match, vreg, min, max, step, \
  90. volt_ranges, _da_vsel_reg, _da_vsel_mask, \
  91. _da_vsel_shift, vosel, vosel_mask) \
  92. [MT6358_ID_##vreg] = { \
  93. .desc = { \
  94. .name = #vreg, \
  95. .of_match = of_match_ptr(match), \
  96. .ops = &mt6358_volt_range_ops, \
  97. .type = REGULATOR_VOLTAGE, \
  98. .id = MT6358_ID_##vreg, \
  99. .owner = THIS_MODULE, \
  100. .n_voltages = ((max) - (min)) / (step) + 1, \
  101. .linear_ranges = volt_ranges, \
  102. .n_linear_ranges = ARRAY_SIZE(volt_ranges), \
  103. .vsel_reg = vosel, \
  104. .vsel_mask = vosel_mask, \
  105. .enable_reg = MT6358_LDO_##vreg##_CON0, \
  106. .enable_mask = BIT(0), \
  107. }, \
  108. .da_vsel_reg = _da_vsel_reg, \
  109. .da_vsel_mask = _da_vsel_mask, \
  110. .da_vsel_shift = _da_vsel_shift, \
  111. .status_reg = MT6358_LDO_##vreg##_DBG1, \
  112. .qi = BIT(0), \
  113. }
  114. #define MT6358_REG_FIXED(match, vreg, \
  115. enreg, enbit, volt) \
  116. [MT6358_ID_##vreg] = { \
  117. .desc = { \
  118. .name = #vreg, \
  119. .of_match = of_match_ptr(match), \
  120. .ops = &mt6358_volt_fixed_ops, \
  121. .type = REGULATOR_VOLTAGE, \
  122. .id = MT6358_ID_##vreg, \
  123. .owner = THIS_MODULE, \
  124. .n_voltages = 1, \
  125. .enable_reg = enreg, \
  126. .enable_mask = BIT(enbit), \
  127. .min_uV = volt, \
  128. }, \
  129. .status_reg = MT6358_LDO_##vreg##_CON1, \
  130. .qi = BIT(15), \
  131. }
  132. static const struct regulator_linear_range buck_volt_range1[] = {
  133. REGULATOR_LINEAR_RANGE(500000, 0, 0x7f, 6250),
  134. };
  135. static const struct regulator_linear_range buck_volt_range2[] = {
  136. REGULATOR_LINEAR_RANGE(500000, 0, 0x7f, 12500),
  137. };
  138. static const struct regulator_linear_range buck_volt_range3[] = {
  139. REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000),
  140. };
  141. static const struct regulator_linear_range buck_volt_range4[] = {
  142. REGULATOR_LINEAR_RANGE(1000000, 0, 0x7f, 12500),
  143. };
  144. static const u32 vdram2_voltages[] = {
  145. 600000, 1800000,
  146. };
  147. static const u32 vsim_voltages[] = {
  148. 1700000, 1800000, 2700000, 3000000, 3100000,
  149. };
  150. static const u32 vibr_voltages[] = {
  151. 1200000, 1300000, 1500000, 1800000,
  152. 2000000, 2800000, 3000000, 3300000,
  153. };
  154. static const u32 vusb_voltages[] = {
  155. 3000000, 3100000,
  156. };
  157. static const u32 vcamd_voltages[] = {
  158. 900000, 1000000, 1100000, 1200000,
  159. 1300000, 1500000, 1800000,
  160. };
  161. static const u32 vefuse_voltages[] = {
  162. 1700000, 1800000, 1900000,
  163. };
  164. static const u32 vmch_vemc_voltages[] = {
  165. 2900000, 3000000, 3300000,
  166. };
  167. static const u32 vcama_voltages[] = {
  168. 1800000, 2500000, 2700000,
  169. 2800000, 2900000, 3000000,
  170. };
  171. static const u32 vcn33_bt_wifi_voltages[] = {
  172. 3300000, 3400000, 3500000,
  173. };
  174. static const u32 vmc_voltages[] = {
  175. 1800000, 2900000, 3000000, 3300000,
  176. };
  177. static const u32 vldo28_voltages[] = {
  178. 2800000, 3000000,
  179. };
  180. static const u32 vdram2_idx[] = {
  181. 0, 12,
  182. };
  183. static const u32 vsim_idx[] = {
  184. 3, 4, 8, 11, 12,
  185. };
  186. static const u32 vibr_idx[] = {
  187. 0, 1, 2, 4, 5, 9, 11, 13,
  188. };
  189. static const u32 vusb_idx[] = {
  190. 3, 4,
  191. };
  192. static const u32 vcamd_idx[] = {
  193. 3, 4, 5, 6, 7, 9, 12,
  194. };
  195. static const u32 vefuse_idx[] = {
  196. 11, 12, 13,
  197. };
  198. static const u32 vmch_vemc_idx[] = {
  199. 2, 3, 5,
  200. };
  201. static const u32 vcama_idx[] = {
  202. 0, 7, 9, 10, 11, 12,
  203. };
  204. static const u32 vcn33_bt_wifi_idx[] = {
  205. 1, 2, 3,
  206. };
  207. static const u32 vmc_idx[] = {
  208. 4, 10, 11, 13,
  209. };
  210. static const u32 vldo28_idx[] = {
  211. 1, 3,
  212. };
  213. static unsigned int mt6358_map_mode(unsigned int mode)
  214. {
  215. return mode == MT6358_BUCK_MODE_AUTO ?
  216. REGULATOR_MODE_NORMAL : REGULATOR_MODE_FAST;
  217. }
  218. static int mt6358_set_voltage_sel(struct regulator_dev *rdev,
  219. unsigned int selector)
  220. {
  221. int idx, ret;
  222. const u32 *pvol;
  223. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  224. pvol = info->index_table;
  225. idx = pvol[selector];
  226. ret = regmap_update_bits(rdev->regmap, info->desc.vsel_reg,
  227. info->desc.vsel_mask,
  228. idx << info->vsel_shift);
  229. return ret;
  230. }
  231. static int mt6358_get_voltage_sel(struct regulator_dev *rdev)
  232. {
  233. int idx, ret;
  234. u32 selector;
  235. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  236. const u32 *pvol;
  237. ret = regmap_read(rdev->regmap, info->desc.vsel_reg, &selector);
  238. if (ret != 0) {
  239. dev_info(&rdev->dev,
  240. "Failed to get mt6358 %s vsel reg: %d\n",
  241. info->desc.name, ret);
  242. return ret;
  243. }
  244. selector = (selector & info->desc.vsel_mask) >> info->vsel_shift;
  245. pvol = info->index_table;
  246. for (idx = 0; idx < info->desc.n_voltages; idx++) {
  247. if (pvol[idx] == selector)
  248. return idx;
  249. }
  250. return -EINVAL;
  251. }
  252. static int mt6358_get_buck_voltage_sel(struct regulator_dev *rdev)
  253. {
  254. int ret, regval;
  255. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  256. ret = regmap_read(rdev->regmap, info->da_vsel_reg, &regval);
  257. if (ret != 0) {
  258. dev_err(&rdev->dev,
  259. "Failed to get mt6358 Buck %s vsel reg: %d\n",
  260. info->desc.name, ret);
  261. return ret;
  262. }
  263. ret = (regval >> info->da_vsel_shift) & info->da_vsel_mask;
  264. return ret;
  265. }
  266. static int mt6358_get_status(struct regulator_dev *rdev)
  267. {
  268. int ret;
  269. u32 regval;
  270. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  271. ret = regmap_read(rdev->regmap, info->status_reg, &regval);
  272. if (ret != 0) {
  273. dev_info(&rdev->dev, "Failed to get enable reg: %d\n", ret);
  274. return ret;
  275. }
  276. return (regval & info->qi) ? REGULATOR_STATUS_ON : REGULATOR_STATUS_OFF;
  277. }
  278. static int mt6358_regulator_set_mode(struct regulator_dev *rdev,
  279. unsigned int mode)
  280. {
  281. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  282. int val;
  283. switch (mode) {
  284. case REGULATOR_MODE_FAST:
  285. val = MT6358_BUCK_MODE_FORCE_PWM;
  286. break;
  287. case REGULATOR_MODE_NORMAL:
  288. val = MT6358_BUCK_MODE_AUTO;
  289. break;
  290. default:
  291. return -EINVAL;
  292. }
  293. dev_dbg(&rdev->dev, "mt6358 buck set_mode %#x, %#x, %#x, %#x\n",
  294. info->modeset_reg, info->modeset_mask,
  295. info->modeset_shift, val);
  296. val <<= info->modeset_shift;
  297. return regmap_update_bits(rdev->regmap, info->modeset_reg,
  298. info->modeset_mask, val);
  299. }
  300. static unsigned int mt6358_regulator_get_mode(struct regulator_dev *rdev)
  301. {
  302. struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
  303. int ret, regval;
  304. ret = regmap_read(rdev->regmap, info->modeset_reg, &regval);
  305. if (ret != 0) {
  306. dev_err(&rdev->dev,
  307. "Failed to get mt6358 buck mode: %d\n", ret);
  308. return ret;
  309. }
  310. switch ((regval & info->modeset_mask) >> info->modeset_shift) {
  311. case MT6358_BUCK_MODE_AUTO:
  312. return REGULATOR_MODE_NORMAL;
  313. case MT6358_BUCK_MODE_FORCE_PWM:
  314. return REGULATOR_MODE_FAST;
  315. default:
  316. return -EINVAL;
  317. }
  318. }
  319. static const struct regulator_ops mt6358_volt_range_ops = {
  320. .list_voltage = regulator_list_voltage_linear_range,
  321. .map_voltage = regulator_map_voltage_linear_range,
  322. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  323. .get_voltage_sel = mt6358_get_buck_voltage_sel,
  324. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  325. .enable = regulator_enable_regmap,
  326. .disable = regulator_disable_regmap,
  327. .is_enabled = regulator_is_enabled_regmap,
  328. .get_status = mt6358_get_status,
  329. .set_mode = mt6358_regulator_set_mode,
  330. .get_mode = mt6358_regulator_get_mode,
  331. };
  332. static const struct regulator_ops mt6358_volt_table_ops = {
  333. .list_voltage = regulator_list_voltage_table,
  334. .map_voltage = regulator_map_voltage_iterate,
  335. .set_voltage_sel = mt6358_set_voltage_sel,
  336. .get_voltage_sel = mt6358_get_voltage_sel,
  337. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  338. .enable = regulator_enable_regmap,
  339. .disable = regulator_disable_regmap,
  340. .is_enabled = regulator_is_enabled_regmap,
  341. .get_status = mt6358_get_status,
  342. };
  343. static const struct regulator_ops mt6358_volt_fixed_ops = {
  344. .list_voltage = regulator_list_voltage_linear,
  345. .enable = regulator_enable_regmap,
  346. .disable = regulator_disable_regmap,
  347. .is_enabled = regulator_is_enabled_regmap,
  348. .get_status = mt6358_get_status,
  349. };
  350. /* The array is indexed by id(MT6358_ID_XXX) */
  351. static struct mt6358_regulator_info mt6358_regulators[] = {
  352. MT6358_BUCK("buck_vdram1", VDRAM1, 500000, 2087500, 12500,
  353. buck_volt_range2, 0x7f, MT6358_BUCK_VDRAM1_DBG0, 0x7f,
  354. 0, MT6358_VDRAM1_ANA_CON0, 8),
  355. MT6358_BUCK("buck_vcore", VCORE, 500000, 1293750, 6250,
  356. buck_volt_range1, 0x7f, MT6358_BUCK_VCORE_DBG0, 0x7f,
  357. 0, MT6358_VCORE_VGPU_ANA_CON0, 1),
  358. MT6358_BUCK("buck_vpa", VPA, 500000, 3650000, 50000,
  359. buck_volt_range3, 0x3f, MT6358_BUCK_VPA_DBG0, 0x3f, 0,
  360. MT6358_VPA_ANA_CON0, 3),
  361. MT6358_BUCK("buck_vproc11", VPROC11, 500000, 1293750, 6250,
  362. buck_volt_range1, 0x7f, MT6358_BUCK_VPROC11_DBG0, 0x7f,
  363. 0, MT6358_VPROC_ANA_CON0, 1),
  364. MT6358_BUCK("buck_vproc12", VPROC12, 500000, 1293750, 6250,
  365. buck_volt_range1, 0x7f, MT6358_BUCK_VPROC12_DBG0, 0x7f,
  366. 0, MT6358_VPROC_ANA_CON0, 2),
  367. MT6358_BUCK("buck_vgpu", VGPU, 500000, 1293750, 6250,
  368. buck_volt_range1, 0x7f, MT6358_BUCK_VGPU_ELR0, 0x7f, 0,
  369. MT6358_VCORE_VGPU_ANA_CON0, 2),
  370. MT6358_BUCK("buck_vs2", VS2, 500000, 2087500, 12500,
  371. buck_volt_range2, 0x7f, MT6358_BUCK_VS2_DBG0, 0x7f, 0,
  372. MT6358_VS2_ANA_CON0, 8),
  373. MT6358_BUCK("buck_vmodem", VMODEM, 500000, 1293750, 6250,
  374. buck_volt_range1, 0x7f, MT6358_BUCK_VMODEM_DBG0, 0x7f,
  375. 0, MT6358_VMODEM_ANA_CON0, 8),
  376. MT6358_BUCK("buck_vs1", VS1, 1000000, 2587500, 12500,
  377. buck_volt_range4, 0x7f, MT6358_BUCK_VS1_DBG0, 0x7f, 0,
  378. MT6358_VS1_ANA_CON0, 8),
  379. MT6358_REG_FIXED("ldo_vrf12", VRF12,
  380. MT6358_LDO_VRF12_CON0, 0, 1200000),
  381. MT6358_REG_FIXED("ldo_vio18", VIO18,
  382. MT6358_LDO_VIO18_CON0, 0, 1800000),
  383. MT6358_REG_FIXED("ldo_vcamio", VCAMIO,
  384. MT6358_LDO_VCAMIO_CON0, 0, 1800000),
  385. MT6358_REG_FIXED("ldo_vcn18", VCN18, MT6358_LDO_VCN18_CON0, 0, 1800000),
  386. MT6358_REG_FIXED("ldo_vfe28", VFE28, MT6358_LDO_VFE28_CON0, 0, 2800000),
  387. MT6358_REG_FIXED("ldo_vcn28", VCN28, MT6358_LDO_VCN28_CON0, 0, 2800000),
  388. MT6358_REG_FIXED("ldo_vxo22", VXO22, MT6358_LDO_VXO22_CON0, 0, 2200000),
  389. MT6358_REG_FIXED("ldo_vaux18", VAUX18,
  390. MT6358_LDO_VAUX18_CON0, 0, 1800000),
  391. MT6358_REG_FIXED("ldo_vbif28", VBIF28,
  392. MT6358_LDO_VBIF28_CON0, 0, 2800000),
  393. MT6358_REG_FIXED("ldo_vio28", VIO28, MT6358_LDO_VIO28_CON0, 0, 2800000),
  394. MT6358_REG_FIXED("ldo_va12", VA12, MT6358_LDO_VA12_CON0, 0, 1200000),
  395. MT6358_REG_FIXED("ldo_vrf18", VRF18, MT6358_LDO_VRF18_CON0, 0, 1800000),
  396. MT6358_REG_FIXED("ldo_vaud28", VAUD28,
  397. MT6358_LDO_VAUD28_CON0, 0, 2800000),
  398. MT6358_LDO("ldo_vdram2", VDRAM2, vdram2_voltages, vdram2_idx,
  399. MT6358_LDO_VDRAM2_CON0, 0, MT6358_LDO_VDRAM2_ELR0, 0xf, 0),
  400. MT6358_LDO("ldo_vsim1", VSIM1, vsim_voltages, vsim_idx,
  401. MT6358_LDO_VSIM1_CON0, 0, MT6358_VSIM1_ANA_CON0, 0xf00, 8),
  402. MT6358_LDO("ldo_vibr", VIBR, vibr_voltages, vibr_idx,
  403. MT6358_LDO_VIBR_CON0, 0, MT6358_VIBR_ANA_CON0, 0xf00, 8),
  404. MT6358_LDO("ldo_vusb", VUSB, vusb_voltages, vusb_idx,
  405. MT6358_LDO_VUSB_CON0_0, 0, MT6358_VUSB_ANA_CON0, 0x700, 8),
  406. MT6358_LDO("ldo_vcamd", VCAMD, vcamd_voltages, vcamd_idx,
  407. MT6358_LDO_VCAMD_CON0, 0, MT6358_VCAMD_ANA_CON0, 0xf00, 8),
  408. MT6358_LDO("ldo_vefuse", VEFUSE, vefuse_voltages, vefuse_idx,
  409. MT6358_LDO_VEFUSE_CON0, 0, MT6358_VEFUSE_ANA_CON0, 0xf00, 8),
  410. MT6358_LDO("ldo_vmch", VMCH, vmch_vemc_voltages, vmch_vemc_idx,
  411. MT6358_LDO_VMCH_CON0, 0, MT6358_VMCH_ANA_CON0, 0x700, 8),
  412. MT6358_LDO("ldo_vcama1", VCAMA1, vcama_voltages, vcama_idx,
  413. MT6358_LDO_VCAMA1_CON0, 0, MT6358_VCAMA1_ANA_CON0, 0xf00, 8),
  414. MT6358_LDO("ldo_vemc", VEMC, vmch_vemc_voltages, vmch_vemc_idx,
  415. MT6358_LDO_VEMC_CON0, 0, MT6358_VEMC_ANA_CON0, 0x700, 8),
  416. MT6358_LDO("ldo_vcn33_bt", VCN33_BT, vcn33_bt_wifi_voltages,
  417. vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_0,
  418. 0, MT6358_VCN33_ANA_CON0, 0x300, 8),
  419. MT6358_LDO("ldo_vcn33_wifi", VCN33_WIFI, vcn33_bt_wifi_voltages,
  420. vcn33_bt_wifi_idx, MT6358_LDO_VCN33_CON0_1,
  421. 0, MT6358_VCN33_ANA_CON0, 0x300, 8),
  422. MT6358_LDO("ldo_vcama2", VCAMA2, vcama_voltages, vcama_idx,
  423. MT6358_LDO_VCAMA2_CON0, 0, MT6358_VCAMA2_ANA_CON0, 0xf00, 8),
  424. MT6358_LDO("ldo_vmc", VMC, vmc_voltages, vmc_idx,
  425. MT6358_LDO_VMC_CON0, 0, MT6358_VMC_ANA_CON0, 0xf00, 8),
  426. MT6358_LDO("ldo_vldo28", VLDO28, vldo28_voltages, vldo28_idx,
  427. MT6358_LDO_VLDO28_CON0_0, 0,
  428. MT6358_VLDO28_ANA_CON0, 0x300, 8),
  429. MT6358_LDO("ldo_vsim2", VSIM2, vsim_voltages, vsim_idx,
  430. MT6358_LDO_VSIM2_CON0, 0, MT6358_VSIM2_ANA_CON0, 0xf00, 8),
  431. MT6358_LDO1("ldo_vsram_proc11", VSRAM_PROC11, 500000, 1293750, 6250,
  432. buck_volt_range1, MT6358_LDO_VSRAM_PROC11_DBG0, 0x7f, 8,
  433. MT6358_LDO_VSRAM_CON0, 0x7f),
  434. MT6358_LDO1("ldo_vsram_others", VSRAM_OTHERS, 500000, 1293750, 6250,
  435. buck_volt_range1, MT6358_LDO_VSRAM_OTHERS_DBG0, 0x7f, 8,
  436. MT6358_LDO_VSRAM_CON2, 0x7f),
  437. MT6358_LDO1("ldo_vsram_gpu", VSRAM_GPU, 500000, 1293750, 6250,
  438. buck_volt_range1, MT6358_LDO_VSRAM_GPU_DBG0, 0x7f, 8,
  439. MT6358_LDO_VSRAM_CON3, 0x7f),
  440. MT6358_LDO1("ldo_vsram_proc12", VSRAM_PROC12, 500000, 1293750, 6250,
  441. buck_volt_range1, MT6358_LDO_VSRAM_PROC12_DBG0, 0x7f, 8,
  442. MT6358_LDO_VSRAM_CON1, 0x7f),
  443. };
  444. static int mt6358_regulator_probe(struct platform_device *pdev)
  445. {
  446. struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
  447. struct regulator_config config = {};
  448. struct regulator_dev *rdev;
  449. int i;
  450. for (i = 0; i < MT6358_MAX_REGULATOR; i++) {
  451. config.dev = &pdev->dev;
  452. config.driver_data = &mt6358_regulators[i];
  453. config.regmap = mt6397->regmap;
  454. rdev = devm_regulator_register(&pdev->dev,
  455. &mt6358_regulators[i].desc,
  456. &config);
  457. if (IS_ERR(rdev)) {
  458. dev_err(&pdev->dev, "failed to register %s\n",
  459. mt6358_regulators[i].desc.name);
  460. return PTR_ERR(rdev);
  461. }
  462. }
  463. return 0;
  464. }
  465. static const struct platform_device_id mt6358_platform_ids[] = {
  466. {"mt6358-regulator", 0},
  467. { /* sentinel */ },
  468. };
  469. MODULE_DEVICE_TABLE(platform, mt6358_platform_ids);
  470. static struct platform_driver mt6358_regulator_driver = {
  471. .driver = {
  472. .name = "mt6358-regulator",
  473. },
  474. .probe = mt6358_regulator_probe,
  475. .id_table = mt6358_platform_ids,
  476. };
  477. module_platform_driver(mt6358_regulator_driver);
  478. MODULE_AUTHOR("Hsin-Hsiung Wang <hsin-hsiung.wang@mediatek.com>");
  479. MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6358 PMIC");
  480. MODULE_LICENSE("GPL");