18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci// 38c2ecf20Sopenharmony_ci// Copyright (c) 2017 MediaTek Inc. 48c2ecf20Sopenharmony_ci// Author: Chenglin Xu <chenglin.xu@mediatek.com> 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/module.h> 78c2ecf20Sopenharmony_ci#include <linux/of.h> 88c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 98c2ecf20Sopenharmony_ci#include <linux/regmap.h> 108c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h> 118c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h> 128c2ecf20Sopenharmony_ci#include <linux/regulator/mt6380-regulator.h> 138c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* PMIC Registers */ 168c2ecf20Sopenharmony_ci#define MT6380_ALDO_CON_0 0x0000 178c2ecf20Sopenharmony_ci#define MT6380_BTLDO_CON_0 0x0004 188c2ecf20Sopenharmony_ci#define MT6380_COMP_CON_0 0x0008 198c2ecf20Sopenharmony_ci#define MT6380_CPUBUCK_CON_0 0x000C 208c2ecf20Sopenharmony_ci#define MT6380_CPUBUCK_CON_1 0x0010 218c2ecf20Sopenharmony_ci#define MT6380_CPUBUCK_CON_2 0x0014 228c2ecf20Sopenharmony_ci#define MT6380_DDRLDO_CON_0 0x0018 238c2ecf20Sopenharmony_ci#define MT6380_MLDO_CON_0 0x001C 248c2ecf20Sopenharmony_ci#define MT6380_PALDO_CON_0 0x0020 258c2ecf20Sopenharmony_ci#define MT6380_PHYLDO_CON_0 0x0024 268c2ecf20Sopenharmony_ci#define MT6380_SIDO_CON_0 0x0028 278c2ecf20Sopenharmony_ci#define MT6380_SIDO_CON_1 0x002C 288c2ecf20Sopenharmony_ci#define MT6380_SIDO_CON_2 0x0030 298c2ecf20Sopenharmony_ci#define MT6380_SLDO_CON_0 0x0034 308c2ecf20Sopenharmony_ci#define MT6380_TLDO_CON_0 0x0038 318c2ecf20Sopenharmony_ci#define MT6380_STARTUP_CON_0 0x003C 328c2ecf20Sopenharmony_ci#define MT6380_STARTUP_CON_1 0x0040 338c2ecf20Sopenharmony_ci#define MT6380_SMPS_TOP_CON_0 0x0044 348c2ecf20Sopenharmony_ci#define MT6380_SMPS_TOP_CON_1 0x0048 358c2ecf20Sopenharmony_ci#define MT6380_ANA_CTRL_0 0x0050 368c2ecf20Sopenharmony_ci#define MT6380_ANA_CTRL_1 0x0054 378c2ecf20Sopenharmony_ci#define MT6380_ANA_CTRL_2 0x0058 388c2ecf20Sopenharmony_ci#define MT6380_ANA_CTRL_3 0x005C 398c2ecf20Sopenharmony_ci#define MT6380_ANA_CTRL_4 0x0060 408c2ecf20Sopenharmony_ci#define MT6380_SPK_CON9 0x0064 418c2ecf20Sopenharmony_ci#define MT6380_SPK_CON11 0x0068 428c2ecf20Sopenharmony_ci#define MT6380_SPK_CON12 0x006A 438c2ecf20Sopenharmony_ci#define MT6380_CLK_CTRL 0x0070 448c2ecf20Sopenharmony_ci#define MT6380_PINMUX_CTRL 0x0074 458c2ecf20Sopenharmony_ci#define MT6380_IO_CTRL 0x0078 468c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_0 0x007C 478c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_1 0x0080 488c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_2 0x0084 498c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_3 0x0088 508c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_4 0x008C 518c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_5 0x0090 528c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_6 0x0094 538c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_7 0x0098 548c2ecf20Sopenharmony_ci#define MT6380_SLP_MODE_CTRL_8 0x009C 558c2ecf20Sopenharmony_ci#define MT6380_FCAL_CTRL_0 0x00A0 568c2ecf20Sopenharmony_ci#define MT6380_FCAL_CTRL_1 0x00A4 578c2ecf20Sopenharmony_ci#define MT6380_LDO_CTRL_0 0x00A8 588c2ecf20Sopenharmony_ci#define MT6380_LDO_CTRL_1 0x00AC 598c2ecf20Sopenharmony_ci#define MT6380_LDO_CTRL_2 0x00B0 608c2ecf20Sopenharmony_ci#define MT6380_LDO_CTRL_3 0x00B4 618c2ecf20Sopenharmony_ci#define MT6380_LDO_CTRL_4 0x00B8 628c2ecf20Sopenharmony_ci#define MT6380_DEBUG_CTRL_0 0x00BC 638c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_0 0x0200 648c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_1 0x0201 658c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_2 0x0202 668c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_3 0x0203 678c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_4 0x0204 688c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_5 0x0205 698c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_6 0x0206 708c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_7 0x0207 718c2ecf20Sopenharmony_ci#define MT6380_EFU_CTRL_8 0x0208 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define MT6380_REGULATOR_MODE_AUTO 0 748c2ecf20Sopenharmony_ci#define MT6380_REGULATOR_MODE_FORCE_PWM 1 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* 778c2ecf20Sopenharmony_ci * mt6380 regulators' information 788c2ecf20Sopenharmony_ci * 798c2ecf20Sopenharmony_ci * @desc: standard fields of regulator description 808c2ecf20Sopenharmony_ci * @vselon_reg: Register sections for hardware control mode of bucks 818c2ecf20Sopenharmony_ci * @modeset_reg: Register for controlling the buck/LDO control mode 828c2ecf20Sopenharmony_ci * @modeset_mask: Mask for controlling the buck/LDO control mode 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_cistruct mt6380_regulator_info { 858c2ecf20Sopenharmony_ci struct regulator_desc desc; 868c2ecf20Sopenharmony_ci u32 vselon_reg; 878c2ecf20Sopenharmony_ci u32 modeset_reg; 888c2ecf20Sopenharmony_ci u32 modeset_mask; 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define MT6380_BUCK(match, vreg, min, max, step, volt_ranges, enreg, \ 928c2ecf20Sopenharmony_ci vosel, vosel_mask, enbit, voselon, _modeset_reg, \ 938c2ecf20Sopenharmony_ci _modeset_mask) \ 948c2ecf20Sopenharmony_ci[MT6380_ID_##vreg] = { \ 958c2ecf20Sopenharmony_ci .desc = { \ 968c2ecf20Sopenharmony_ci .name = #vreg, \ 978c2ecf20Sopenharmony_ci .of_match = of_match_ptr(match), \ 988c2ecf20Sopenharmony_ci .ops = &mt6380_volt_range_ops, \ 998c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 1008c2ecf20Sopenharmony_ci .id = MT6380_ID_##vreg, \ 1018c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 1028c2ecf20Sopenharmony_ci .n_voltages = ((max) - (min)) / (step) + 1, \ 1038c2ecf20Sopenharmony_ci .linear_ranges = volt_ranges, \ 1048c2ecf20Sopenharmony_ci .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ 1058c2ecf20Sopenharmony_ci .vsel_reg = vosel, \ 1068c2ecf20Sopenharmony_ci .vsel_mask = vosel_mask, \ 1078c2ecf20Sopenharmony_ci .enable_reg = enreg, \ 1088c2ecf20Sopenharmony_ci .enable_mask = BIT(enbit), \ 1098c2ecf20Sopenharmony_ci }, \ 1108c2ecf20Sopenharmony_ci .vselon_reg = voselon, \ 1118c2ecf20Sopenharmony_ci .modeset_reg = _modeset_reg, \ 1128c2ecf20Sopenharmony_ci .modeset_mask = _modeset_mask, \ 1138c2ecf20Sopenharmony_ci} 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#define MT6380_LDO(match, vreg, ldo_volt_table, enreg, enbit, vosel, \ 1168c2ecf20Sopenharmony_ci vosel_mask, _modeset_reg, _modeset_mask) \ 1178c2ecf20Sopenharmony_ci[MT6380_ID_##vreg] = { \ 1188c2ecf20Sopenharmony_ci .desc = { \ 1198c2ecf20Sopenharmony_ci .name = #vreg, \ 1208c2ecf20Sopenharmony_ci .of_match = of_match_ptr(match), \ 1218c2ecf20Sopenharmony_ci .ops = &mt6380_volt_table_ops, \ 1228c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 1238c2ecf20Sopenharmony_ci .id = MT6380_ID_##vreg, \ 1248c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 1258c2ecf20Sopenharmony_ci .n_voltages = ARRAY_SIZE(ldo_volt_table), \ 1268c2ecf20Sopenharmony_ci .volt_table = ldo_volt_table, \ 1278c2ecf20Sopenharmony_ci .vsel_reg = vosel, \ 1288c2ecf20Sopenharmony_ci .vsel_mask = vosel_mask, \ 1298c2ecf20Sopenharmony_ci .enable_reg = enreg, \ 1308c2ecf20Sopenharmony_ci .enable_mask = BIT(enbit), \ 1318c2ecf20Sopenharmony_ci }, \ 1328c2ecf20Sopenharmony_ci .modeset_reg = _modeset_reg, \ 1338c2ecf20Sopenharmony_ci .modeset_mask = _modeset_mask, \ 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#define MT6380_REG_FIXED(match, vreg, enreg, enbit, volt, \ 1378c2ecf20Sopenharmony_ci _modeset_reg, _modeset_mask) \ 1388c2ecf20Sopenharmony_ci[MT6380_ID_##vreg] = { \ 1398c2ecf20Sopenharmony_ci .desc = { \ 1408c2ecf20Sopenharmony_ci .name = #vreg, \ 1418c2ecf20Sopenharmony_ci .of_match = of_match_ptr(match), \ 1428c2ecf20Sopenharmony_ci .ops = &mt6380_volt_fixed_ops, \ 1438c2ecf20Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 1448c2ecf20Sopenharmony_ci .id = MT6380_ID_##vreg, \ 1458c2ecf20Sopenharmony_ci .owner = THIS_MODULE, \ 1468c2ecf20Sopenharmony_ci .n_voltages = 1, \ 1478c2ecf20Sopenharmony_ci .enable_reg = enreg, \ 1488c2ecf20Sopenharmony_ci .enable_mask = BIT(enbit), \ 1498c2ecf20Sopenharmony_ci .min_uV = volt, \ 1508c2ecf20Sopenharmony_ci }, \ 1518c2ecf20Sopenharmony_ci .modeset_reg = _modeset_reg, \ 1528c2ecf20Sopenharmony_ci .modeset_mask = _modeset_mask, \ 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic const struct linear_range buck_volt_range1[] = { 1568c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(600000, 0, 0xfe, 6250), 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistatic const struct linear_range buck_volt_range2[] = { 1608c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(600000, 0, 0xfe, 6250), 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_cistatic const struct linear_range buck_volt_range3[] = { 1648c2ecf20Sopenharmony_ci REGULATOR_LINEAR_RANGE(1200000, 0, 0x3c, 25000), 1658c2ecf20Sopenharmony_ci}; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistatic const unsigned int ldo_volt_table1[] = { 1688c2ecf20Sopenharmony_ci 1400000, 1350000, 1300000, 1250000, 1200000, 1150000, 1100000, 1050000, 1698c2ecf20Sopenharmony_ci}; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic const unsigned int ldo_volt_table2[] = { 1728c2ecf20Sopenharmony_ci 2200000, 3300000, 1738c2ecf20Sopenharmony_ci}; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_cistatic const unsigned int ldo_volt_table3[] = { 1768c2ecf20Sopenharmony_ci 1240000, 1390000, 1540000, 1840000, 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistatic const unsigned int ldo_volt_table4[] = { 1808c2ecf20Sopenharmony_ci 2200000, 3300000, 1818c2ecf20Sopenharmony_ci}; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_cistatic int mt6380_regulator_set_mode(struct regulator_dev *rdev, 1848c2ecf20Sopenharmony_ci unsigned int mode) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci int ret, val = 0; 1878c2ecf20Sopenharmony_ci struct mt6380_regulator_info *info = rdev_get_drvdata(rdev); 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci switch (mode) { 1908c2ecf20Sopenharmony_ci case REGULATOR_MODE_NORMAL: 1918c2ecf20Sopenharmony_ci val = MT6380_REGULATOR_MODE_AUTO; 1928c2ecf20Sopenharmony_ci break; 1938c2ecf20Sopenharmony_ci case REGULATOR_MODE_FAST: 1948c2ecf20Sopenharmony_ci val = MT6380_REGULATOR_MODE_FORCE_PWM; 1958c2ecf20Sopenharmony_ci break; 1968c2ecf20Sopenharmony_ci default: 1978c2ecf20Sopenharmony_ci return -EINVAL; 1988c2ecf20Sopenharmony_ci } 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci val <<= ffs(info->modeset_mask) - 1; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci ret = regmap_update_bits(rdev->regmap, info->modeset_reg, 2038c2ecf20Sopenharmony_ci info->modeset_mask, val); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci return ret; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic unsigned int mt6380_regulator_get_mode(struct regulator_dev *rdev) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci unsigned int val; 2118c2ecf20Sopenharmony_ci unsigned int mode; 2128c2ecf20Sopenharmony_ci int ret; 2138c2ecf20Sopenharmony_ci struct mt6380_regulator_info *info = rdev_get_drvdata(rdev); 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci ret = regmap_read(rdev->regmap, info->modeset_reg, &val); 2168c2ecf20Sopenharmony_ci if (ret < 0) 2178c2ecf20Sopenharmony_ci return ret; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci val &= info->modeset_mask; 2208c2ecf20Sopenharmony_ci val >>= ffs(info->modeset_mask) - 1; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci switch (val) { 2238c2ecf20Sopenharmony_ci case MT6380_REGULATOR_MODE_AUTO: 2248c2ecf20Sopenharmony_ci mode = REGULATOR_MODE_NORMAL; 2258c2ecf20Sopenharmony_ci break; 2268c2ecf20Sopenharmony_ci case MT6380_REGULATOR_MODE_FORCE_PWM: 2278c2ecf20Sopenharmony_ci mode = REGULATOR_MODE_FAST; 2288c2ecf20Sopenharmony_ci break; 2298c2ecf20Sopenharmony_ci default: 2308c2ecf20Sopenharmony_ci return -EINVAL; 2318c2ecf20Sopenharmony_ci } 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci return mode; 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic const struct regulator_ops mt6380_volt_range_ops = { 2378c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear_range, 2388c2ecf20Sopenharmony_ci .map_voltage = regulator_map_voltage_linear_range, 2398c2ecf20Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 2408c2ecf20Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 2418c2ecf20Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 2428c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 2438c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 2448c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 2458c2ecf20Sopenharmony_ci .set_mode = mt6380_regulator_set_mode, 2468c2ecf20Sopenharmony_ci .get_mode = mt6380_regulator_get_mode, 2478c2ecf20Sopenharmony_ci}; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_cistatic const struct regulator_ops mt6380_volt_table_ops = { 2508c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_table, 2518c2ecf20Sopenharmony_ci .map_voltage = regulator_map_voltage_iterate, 2528c2ecf20Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 2538c2ecf20Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 2548c2ecf20Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 2558c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 2568c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 2578c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 2588c2ecf20Sopenharmony_ci .set_mode = mt6380_regulator_set_mode, 2598c2ecf20Sopenharmony_ci .get_mode = mt6380_regulator_get_mode, 2608c2ecf20Sopenharmony_ci}; 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_cistatic const struct regulator_ops mt6380_volt_fixed_ops = { 2638c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 2648c2ecf20Sopenharmony_ci .enable = regulator_enable_regmap, 2658c2ecf20Sopenharmony_ci .disable = regulator_disable_regmap, 2668c2ecf20Sopenharmony_ci .is_enabled = regulator_is_enabled_regmap, 2678c2ecf20Sopenharmony_ci .set_mode = mt6380_regulator_set_mode, 2688c2ecf20Sopenharmony_ci .get_mode = mt6380_regulator_get_mode, 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci/* The array is indexed by id(MT6380_ID_XXX) */ 2728c2ecf20Sopenharmony_cistatic struct mt6380_regulator_info mt6380_regulators[] = { 2738c2ecf20Sopenharmony_ci MT6380_BUCK("buck-vcore1", VCPU, 600000, 1393750, 6250, 2748c2ecf20Sopenharmony_ci buck_volt_range1, MT6380_ANA_CTRL_3, MT6380_ANA_CTRL_1, 2758c2ecf20Sopenharmony_ci 0xfe, 3, MT6380_ANA_CTRL_1, 2768c2ecf20Sopenharmony_ci MT6380_CPUBUCK_CON_0, 0x8000000), 2778c2ecf20Sopenharmony_ci MT6380_BUCK("buck-vcore", VCORE, 600000, 1393750, 6250, 2788c2ecf20Sopenharmony_ci buck_volt_range2, MT6380_ANA_CTRL_3, MT6380_ANA_CTRL_2, 2798c2ecf20Sopenharmony_ci 0xfe, 2, MT6380_ANA_CTRL_2, MT6380_SIDO_CON_0, 0x1000000), 2808c2ecf20Sopenharmony_ci MT6380_BUCK("buck-vrf", VRF, 1200000, 1575000, 25000, 2818c2ecf20Sopenharmony_ci buck_volt_range3, MT6380_ANA_CTRL_3, MT6380_SIDO_CON_0, 2828c2ecf20Sopenharmony_ci 0x78, 1, MT6380_SIDO_CON_0, MT6380_SIDO_CON_0, 0x8000), 2838c2ecf20Sopenharmony_ci MT6380_LDO("ldo-vm", VMLDO, ldo_volt_table1, MT6380_LDO_CTRL_0, 2848c2ecf20Sopenharmony_ci 1, MT6380_MLDO_CON_0, 0xE000, MT6380_ANA_CTRL_1, 0x4000000), 2858c2ecf20Sopenharmony_ci MT6380_LDO("ldo-va", VALDO, ldo_volt_table2, MT6380_LDO_CTRL_0, 2868c2ecf20Sopenharmony_ci 2, MT6380_ALDO_CON_0, 0x400, MT6380_ALDO_CON_0, 0x20), 2878c2ecf20Sopenharmony_ci MT6380_REG_FIXED("ldo-vphy", VPHYLDO, MT6380_LDO_CTRL_0, 7, 1800000, 2888c2ecf20Sopenharmony_ci MT6380_PHYLDO_CON_0, 0x80), 2898c2ecf20Sopenharmony_ci MT6380_LDO("ldo-vddr", VDDRLDO, ldo_volt_table3, MT6380_LDO_CTRL_0, 2908c2ecf20Sopenharmony_ci 8, MT6380_DDRLDO_CON_0, 0x3000, MT6380_DDRLDO_CON_0, 0x80), 2918c2ecf20Sopenharmony_ci MT6380_LDO("ldo-vt", VTLDO, ldo_volt_table4, MT6380_LDO_CTRL_0, 3, 2928c2ecf20Sopenharmony_ci MT6380_TLDO_CON_0, 0x400, MT6380_TLDO_CON_0, 0x20), 2938c2ecf20Sopenharmony_ci}; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_cistatic int mt6380_regulator_probe(struct platform_device *pdev) 2968c2ecf20Sopenharmony_ci{ 2978c2ecf20Sopenharmony_ci struct regmap *regmap = dev_get_regmap(pdev->dev.parent, NULL); 2988c2ecf20Sopenharmony_ci struct regulator_config config = {}; 2998c2ecf20Sopenharmony_ci struct regulator_dev *rdev; 3008c2ecf20Sopenharmony_ci int i; 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci for (i = 0; i < MT6380_MAX_REGULATOR; i++) { 3038c2ecf20Sopenharmony_ci config.dev = &pdev->dev; 3048c2ecf20Sopenharmony_ci config.driver_data = &mt6380_regulators[i]; 3058c2ecf20Sopenharmony_ci config.regmap = regmap; 3068c2ecf20Sopenharmony_ci rdev = devm_regulator_register(&pdev->dev, 3078c2ecf20Sopenharmony_ci &mt6380_regulators[i].desc, 3088c2ecf20Sopenharmony_ci &config); 3098c2ecf20Sopenharmony_ci if (IS_ERR(rdev)) { 3108c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "failed to register %s\n", 3118c2ecf20Sopenharmony_ci mt6380_regulators[i].desc.name); 3128c2ecf20Sopenharmony_ci return PTR_ERR(rdev); 3138c2ecf20Sopenharmony_ci } 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci return 0; 3168c2ecf20Sopenharmony_ci} 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_cistatic const struct platform_device_id mt6380_platform_ids[] = { 3198c2ecf20Sopenharmony_ci {"mt6380-regulator", 0}, 3208c2ecf20Sopenharmony_ci { /* sentinel */ }, 3218c2ecf20Sopenharmony_ci}; 3228c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(platform, mt6380_platform_ids); 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_cistatic const struct of_device_id mt6380_of_match[] = { 3258c2ecf20Sopenharmony_ci { .compatible = "mediatek,mt6380-regulator", }, 3268c2ecf20Sopenharmony_ci { /* sentinel */ }, 3278c2ecf20Sopenharmony_ci}; 3288c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, mt6380_of_match); 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_cistatic struct platform_driver mt6380_regulator_driver = { 3318c2ecf20Sopenharmony_ci .driver = { 3328c2ecf20Sopenharmony_ci .name = "mt6380-regulator", 3338c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(mt6380_of_match), 3348c2ecf20Sopenharmony_ci }, 3358c2ecf20Sopenharmony_ci .probe = mt6380_regulator_probe, 3368c2ecf20Sopenharmony_ci .id_table = mt6380_platform_ids, 3378c2ecf20Sopenharmony_ci}; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_cimodule_platform_driver(mt6380_regulator_driver); 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ciMODULE_AUTHOR("Chenglin Xu <chenglin.xu@mediatek.com>"); 3428c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Regulator Driver for MediaTek MT6380 PMIC"); 3438c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 344