1dafc7cdeSFabien Parent // SPDX-License-Identifier: GPL-2.0 2dafc7cdeSFabien Parent // 3dafc7cdeSFabien Parent // Copyright (c) 2022 MediaTek Inc. 4dafc7cdeSFabien Parent // Copyright (c) 2022 BayLibre, SAS. 5dafc7cdeSFabien Parent // Author: Chen Zhong <chen.zhong@mediatek.com> 6dafc7cdeSFabien Parent // Author: Fabien Parent <fparent@baylibre.com> 7dafc7cdeSFabien Parent // Author: Alexandre Mergnat <amergnat@baylibre.com> 8dafc7cdeSFabien Parent // 9dafc7cdeSFabien Parent // Based on mt6397-regulator.c 10dafc7cdeSFabien Parent // 11dafc7cdeSFabien Parent 12dafc7cdeSFabien Parent #include <linux/module.h> 13dafc7cdeSFabien Parent #include <linux/of.h> 14dafc7cdeSFabien Parent #include <linux/platform_device.h> 15dafc7cdeSFabien Parent #include <linux/regmap.h> 16dafc7cdeSFabien Parent #include <linux/mfd/mt6397/core.h> 17dafc7cdeSFabien Parent #include <linux/mfd/mt6357/registers.h> 18dafc7cdeSFabien Parent #include <linux/regulator/driver.h> 19dafc7cdeSFabien Parent #include <linux/regulator/machine.h> 20dafc7cdeSFabien Parent #include <linux/regulator/mt6357-regulator.h> 21dafc7cdeSFabien Parent #include <linux/regulator/of_regulator.h> 22dafc7cdeSFabien Parent 23dafc7cdeSFabien Parent /* 24dafc7cdeSFabien Parent * MT6357 regulators' information 25dafc7cdeSFabien Parent * 26dafc7cdeSFabien Parent * @desc: standard fields of regulator description. 27dafc7cdeSFabien Parent * @da_vsel_reg: Monitor register for query buck's voltage. 28dafc7cdeSFabien Parent * @da_vsel_mask: Mask for query buck's voltage. 29dafc7cdeSFabien Parent */ 30dafc7cdeSFabien Parent struct mt6357_regulator_info { 31dafc7cdeSFabien Parent struct regulator_desc desc; 32dafc7cdeSFabien Parent u32 da_vsel_reg; 33dafc7cdeSFabien Parent u32 da_vsel_mask; 34dafc7cdeSFabien Parent }; 35dafc7cdeSFabien Parent 36dafc7cdeSFabien Parent #define MT6357_BUCK(match, vreg, min, max, step, \ 37dafc7cdeSFabien Parent volt_ranges, vosel_reg, vosel_mask, _da_vsel_mask) \ 38dafc7cdeSFabien Parent [MT6357_ID_##vreg] = { \ 39dafc7cdeSFabien Parent .desc = { \ 40dafc7cdeSFabien Parent .name = #vreg, \ 41dafc7cdeSFabien Parent .of_match = of_match_ptr(match), \ 42dafc7cdeSFabien Parent .regulators_node = "regulators", \ 43dafc7cdeSFabien Parent .ops = &mt6357_volt_range_ops, \ 44dafc7cdeSFabien Parent .type = REGULATOR_VOLTAGE, \ 45dafc7cdeSFabien Parent .id = MT6357_ID_##vreg, \ 46dafc7cdeSFabien Parent .owner = THIS_MODULE, \ 47dafc7cdeSFabien Parent .n_voltages = ((max) - (min)) / (step) + 1, \ 48dafc7cdeSFabien Parent .linear_ranges = volt_ranges, \ 49dafc7cdeSFabien Parent .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ 50dafc7cdeSFabien Parent .vsel_reg = vosel_reg, \ 51dafc7cdeSFabien Parent .vsel_mask = vosel_mask, \ 52dafc7cdeSFabien Parent .enable_reg = MT6357_BUCK_##vreg##_CON0, \ 53dafc7cdeSFabien Parent .enable_mask = BIT(0), \ 54dafc7cdeSFabien Parent }, \ 55dafc7cdeSFabien Parent .da_vsel_reg = MT6357_BUCK_##vreg##_DBG0, \ 56dafc7cdeSFabien Parent .da_vsel_mask = vosel_mask, \ 57dafc7cdeSFabien Parent } 58dafc7cdeSFabien Parent 59dafc7cdeSFabien Parent #define MT6357_LDO(match, vreg, ldo_volt_table, \ 60dafc7cdeSFabien Parent enreg, vosel, vosel_mask) \ 61dafc7cdeSFabien Parent [MT6357_ID_##vreg] = { \ 62dafc7cdeSFabien Parent .desc = { \ 63dafc7cdeSFabien Parent .name = #vreg, \ 64dafc7cdeSFabien Parent .of_match = of_match_ptr(match), \ 65dafc7cdeSFabien Parent .regulators_node = "regulators", \ 66dafc7cdeSFabien Parent .ops = &mt6357_volt_table_ops, \ 67dafc7cdeSFabien Parent .type = REGULATOR_VOLTAGE, \ 68dafc7cdeSFabien Parent .id = MT6357_ID_##vreg, \ 69dafc7cdeSFabien Parent .owner = THIS_MODULE, \ 70dafc7cdeSFabien Parent .n_voltages = ARRAY_SIZE(ldo_volt_table), \ 71dafc7cdeSFabien Parent .volt_table = ldo_volt_table, \ 72dafc7cdeSFabien Parent .vsel_reg = vosel, \ 73dafc7cdeSFabien Parent .vsel_mask = vosel_mask, \ 74dafc7cdeSFabien Parent .enable_reg = enreg, \ 75dafc7cdeSFabien Parent .enable_mask = BIT(0), \ 76dafc7cdeSFabien Parent }, \ 77dafc7cdeSFabien Parent } 78dafc7cdeSFabien Parent 79dafc7cdeSFabien Parent #define MT6357_LDO1(match, vreg, min, max, step, volt_ranges, \ 80dafc7cdeSFabien Parent enreg, vosel, vosel_mask) \ 81dafc7cdeSFabien Parent [MT6357_ID_##vreg] = { \ 82dafc7cdeSFabien Parent .desc = { \ 83dafc7cdeSFabien Parent .name = #vreg, \ 84dafc7cdeSFabien Parent .of_match = of_match_ptr(match), \ 85dafc7cdeSFabien Parent .regulators_node = "regulators", \ 86dafc7cdeSFabien Parent .ops = &mt6357_volt_range_ops, \ 87dafc7cdeSFabien Parent .type = REGULATOR_VOLTAGE, \ 88dafc7cdeSFabien Parent .id = MT6357_ID_##vreg, \ 89dafc7cdeSFabien Parent .owner = THIS_MODULE, \ 90dafc7cdeSFabien Parent .n_voltages = ((max) - (min)) / (step) + 1, \ 91dafc7cdeSFabien Parent .linear_ranges = volt_ranges, \ 92dafc7cdeSFabien Parent .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ 93dafc7cdeSFabien Parent .vsel_reg = vosel, \ 94dafc7cdeSFabien Parent .vsel_mask = vosel_mask, \ 95dafc7cdeSFabien Parent .enable_reg = enreg, \ 96dafc7cdeSFabien Parent .enable_mask = BIT(0), \ 97dafc7cdeSFabien Parent }, \ 98dafc7cdeSFabien Parent .da_vsel_reg = MT6357_LDO_##vreg##_DBG0, \ 99dafc7cdeSFabien Parent .da_vsel_mask = 0x7f00, \ 100dafc7cdeSFabien Parent } 101dafc7cdeSFabien Parent 102dafc7cdeSFabien Parent #define MT6357_REG_FIXED(match, vreg, volt) \ 103dafc7cdeSFabien Parent [MT6357_ID_##vreg] = { \ 104dafc7cdeSFabien Parent .desc = { \ 105dafc7cdeSFabien Parent .name = #vreg, \ 106dafc7cdeSFabien Parent .of_match = of_match_ptr(match), \ 107dafc7cdeSFabien Parent .regulators_node = "regulators", \ 108dafc7cdeSFabien Parent .ops = &mt6357_volt_fixed_ops, \ 109dafc7cdeSFabien Parent .type = REGULATOR_VOLTAGE, \ 110dafc7cdeSFabien Parent .id = MT6357_ID_##vreg, \ 111dafc7cdeSFabien Parent .owner = THIS_MODULE, \ 112dafc7cdeSFabien Parent .n_voltages = 1, \ 113dafc7cdeSFabien Parent .enable_reg = MT6357_LDO_##vreg##_CON0, \ 114dafc7cdeSFabien Parent .enable_mask = BIT(0), \ 115dafc7cdeSFabien Parent .min_uV = volt, \ 116dafc7cdeSFabien Parent }, \ 117dafc7cdeSFabien Parent } 118dafc7cdeSFabien Parent 119dafc7cdeSFabien Parent /** 120dafc7cdeSFabien Parent * mt6357_get_buck_voltage_sel - get_voltage_sel for regmap users 121dafc7cdeSFabien Parent * 122dafc7cdeSFabien Parent * @rdev: regulator to operate on 123dafc7cdeSFabien Parent * 124dafc7cdeSFabien Parent * Regulators that use regmap for their register I/O can set the 125dafc7cdeSFabien Parent * da_vsel_reg and da_vsel_mask fields in the info structure and 126dafc7cdeSFabien Parent * then use this as their get_voltage_vsel operation. 127dafc7cdeSFabien Parent */ 128dafc7cdeSFabien Parent static int mt6357_get_buck_voltage_sel(struct regulator_dev *rdev) 129dafc7cdeSFabien Parent { 130dafc7cdeSFabien Parent int ret, regval; 131dafc7cdeSFabien Parent struct mt6357_regulator_info *info = rdev_get_drvdata(rdev); 132dafc7cdeSFabien Parent 133dafc7cdeSFabien Parent ret = regmap_read(rdev->regmap, info->da_vsel_reg, ®val); 134dafc7cdeSFabien Parent if (ret != 0) { 135dafc7cdeSFabien Parent dev_err(&rdev->dev, 136dafc7cdeSFabien Parent "Failed to get mt6357 Buck %s vsel reg: %d\n", 137dafc7cdeSFabien Parent info->desc.name, ret); 138dafc7cdeSFabien Parent return ret; 139dafc7cdeSFabien Parent } 140dafc7cdeSFabien Parent 141dafc7cdeSFabien Parent regval &= info->da_vsel_mask; 142dafc7cdeSFabien Parent regval >>= ffs(info->da_vsel_mask) - 1; 143dafc7cdeSFabien Parent 144dafc7cdeSFabien Parent return regval; 145dafc7cdeSFabien Parent } 146dafc7cdeSFabien Parent 147dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_range_ops = { 148dafc7cdeSFabien Parent .list_voltage = regulator_list_voltage_linear_range, 149dafc7cdeSFabien Parent .map_voltage = regulator_map_voltage_linear_range, 150dafc7cdeSFabien Parent .set_voltage_sel = regulator_set_voltage_sel_regmap, 151dafc7cdeSFabien Parent .get_voltage_sel = mt6357_get_buck_voltage_sel, 152dafc7cdeSFabien Parent .set_voltage_time_sel = regulator_set_voltage_time_sel, 153dafc7cdeSFabien Parent .enable = regulator_enable_regmap, 154dafc7cdeSFabien Parent .disable = regulator_disable_regmap, 155dafc7cdeSFabien Parent .is_enabled = regulator_is_enabled_regmap, 156dafc7cdeSFabien Parent }; 157dafc7cdeSFabien Parent 158dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_table_ops = { 159dafc7cdeSFabien Parent .list_voltage = regulator_list_voltage_table, 160dafc7cdeSFabien Parent .map_voltage = regulator_map_voltage_iterate, 161dafc7cdeSFabien Parent .set_voltage_sel = regulator_set_voltage_sel_regmap, 162dafc7cdeSFabien Parent .get_voltage_sel = regulator_get_voltage_sel_regmap, 163dafc7cdeSFabien Parent .set_voltage_time_sel = regulator_set_voltage_time_sel, 164dafc7cdeSFabien Parent .enable = regulator_enable_regmap, 165dafc7cdeSFabien Parent .disable = regulator_disable_regmap, 166dafc7cdeSFabien Parent .is_enabled = regulator_is_enabled_regmap, 167dafc7cdeSFabien Parent }; 168dafc7cdeSFabien Parent 169dafc7cdeSFabien Parent static const struct regulator_ops mt6357_volt_fixed_ops = { 170dafc7cdeSFabien Parent .list_voltage = regulator_list_voltage_linear, 171dafc7cdeSFabien Parent .enable = regulator_enable_regmap, 172dafc7cdeSFabien Parent .disable = regulator_disable_regmap, 173dafc7cdeSFabien Parent .is_enabled = regulator_is_enabled_regmap, 174dafc7cdeSFabien Parent }; 175dafc7cdeSFabien Parent 176dafc7cdeSFabien Parent static const int vxo22_voltages[] = { 177dafc7cdeSFabien Parent 2200000, 178dafc7cdeSFabien Parent 0, 179dafc7cdeSFabien Parent 2400000, 180dafc7cdeSFabien Parent }; 181dafc7cdeSFabien Parent 182dafc7cdeSFabien Parent static const int vefuse_voltages[] = { 183dafc7cdeSFabien Parent 1200000, 184dafc7cdeSFabien Parent 1300000, 185dafc7cdeSFabien Parent 1500000, 186dafc7cdeSFabien Parent 0, 187dafc7cdeSFabien Parent 1800000, 188dafc7cdeSFabien Parent 0, 189dafc7cdeSFabien Parent 0, 190dafc7cdeSFabien Parent 0, 191dafc7cdeSFabien Parent 0, 192dafc7cdeSFabien Parent 2800000, 193dafc7cdeSFabien Parent 2900000, 194dafc7cdeSFabien Parent 3000000, 195dafc7cdeSFabien Parent 0, 196dafc7cdeSFabien Parent 3300000, 197dafc7cdeSFabien Parent }; 198dafc7cdeSFabien Parent 199dafc7cdeSFabien Parent static const int vcn33_voltages[] = { 200dafc7cdeSFabien Parent 0, 201dafc7cdeSFabien Parent 3300000, 202dafc7cdeSFabien Parent 3400000, 203dafc7cdeSFabien Parent 3500000, 204dafc7cdeSFabien Parent }; 205dafc7cdeSFabien Parent 206dafc7cdeSFabien Parent static const int vcama_voltages[] = { 207dafc7cdeSFabien Parent 0, 208dafc7cdeSFabien Parent 0, 209dafc7cdeSFabien Parent 0, 210dafc7cdeSFabien Parent 0, 211dafc7cdeSFabien Parent 0, 212dafc7cdeSFabien Parent 0, 213dafc7cdeSFabien Parent 0, 214dafc7cdeSFabien Parent 2500000, 215dafc7cdeSFabien Parent 0, 216dafc7cdeSFabien Parent 0, 217dafc7cdeSFabien Parent 2800000, 218dafc7cdeSFabien Parent }; 219dafc7cdeSFabien Parent 220dafc7cdeSFabien Parent static const int vcamd_voltages[] = { 221dafc7cdeSFabien Parent 0, 222dafc7cdeSFabien Parent 0, 223dafc7cdeSFabien Parent 0, 224dafc7cdeSFabien Parent 0, 225dafc7cdeSFabien Parent 1000000, 226dafc7cdeSFabien Parent 1100000, 227dafc7cdeSFabien Parent 1200000, 228dafc7cdeSFabien Parent 1300000, 229dafc7cdeSFabien Parent 0, 230dafc7cdeSFabien Parent 1500000, 231dafc7cdeSFabien Parent 0, 232dafc7cdeSFabien Parent 0, 233dafc7cdeSFabien Parent 1800000, 234dafc7cdeSFabien Parent }; 235dafc7cdeSFabien Parent 236dafc7cdeSFabien Parent static const int vldo28_voltages[] = { 237dafc7cdeSFabien Parent 0, 238dafc7cdeSFabien Parent 2800000, 239dafc7cdeSFabien Parent 0, 240dafc7cdeSFabien Parent 3000000, 241dafc7cdeSFabien Parent }; 242dafc7cdeSFabien Parent 243dafc7cdeSFabien Parent static const int vdram_voltages[] = { 244dafc7cdeSFabien Parent 0, 245dafc7cdeSFabien Parent 1100000, 246dafc7cdeSFabien Parent 1200000, 247dafc7cdeSFabien Parent }; 248dafc7cdeSFabien Parent 249dafc7cdeSFabien Parent static const int vsim_voltages[] = { 250dafc7cdeSFabien Parent 0, 251dafc7cdeSFabien Parent 0, 252dafc7cdeSFabien Parent 0, 253dafc7cdeSFabien Parent 1700000, 254dafc7cdeSFabien Parent 1800000, 255dafc7cdeSFabien Parent 0, 256dafc7cdeSFabien Parent 0, 257dafc7cdeSFabien Parent 0, 258dafc7cdeSFabien Parent 2700000, 259dafc7cdeSFabien Parent 0, 260dafc7cdeSFabien Parent 0, 261dafc7cdeSFabien Parent 3000000, 262dafc7cdeSFabien Parent 3100000, 263dafc7cdeSFabien Parent }; 264dafc7cdeSFabien Parent 265dafc7cdeSFabien Parent static const int vibr_voltages[] = { 266dafc7cdeSFabien Parent 1200000, 267dafc7cdeSFabien Parent 1300000, 268dafc7cdeSFabien Parent 1500000, 269dafc7cdeSFabien Parent 0, 270dafc7cdeSFabien Parent 1800000, 271dafc7cdeSFabien Parent 2000000, 272dafc7cdeSFabien Parent 0, 273dafc7cdeSFabien Parent 0, 274dafc7cdeSFabien Parent 0, 275dafc7cdeSFabien Parent 2800000, 276dafc7cdeSFabien Parent 0, 277dafc7cdeSFabien Parent 3000000, 278dafc7cdeSFabien Parent 0, 279dafc7cdeSFabien Parent 3300000, 280dafc7cdeSFabien Parent }; 281dafc7cdeSFabien Parent 282dafc7cdeSFabien Parent static const int vmc_voltages[] = { 283dafc7cdeSFabien Parent 0, 284dafc7cdeSFabien Parent 0, 285dafc7cdeSFabien Parent 0, 286dafc7cdeSFabien Parent 0, 287dafc7cdeSFabien Parent 1800000, 288dafc7cdeSFabien Parent 0, 289dafc7cdeSFabien Parent 0, 290dafc7cdeSFabien Parent 0, 291dafc7cdeSFabien Parent 0, 292dafc7cdeSFabien Parent 0, 293dafc7cdeSFabien Parent 2900000, 294dafc7cdeSFabien Parent 3000000, 295dafc7cdeSFabien Parent 0, 296dafc7cdeSFabien Parent 3300000, 297dafc7cdeSFabien Parent }; 298dafc7cdeSFabien Parent 299dafc7cdeSFabien Parent static const int vmch_voltages[] = { 300dafc7cdeSFabien Parent 0, 301dafc7cdeSFabien Parent 0, 302dafc7cdeSFabien Parent 2900000, 303dafc7cdeSFabien Parent 3000000, 304dafc7cdeSFabien Parent 0, 305dafc7cdeSFabien Parent 3300000, 306dafc7cdeSFabien Parent }; 307dafc7cdeSFabien Parent 308dafc7cdeSFabien Parent static const int vemc_voltages[] = { 309dafc7cdeSFabien Parent 0, 310dafc7cdeSFabien Parent 0, 311dafc7cdeSFabien Parent 2900000, 312dafc7cdeSFabien Parent 3000000, 313dafc7cdeSFabien Parent 0, 314dafc7cdeSFabien Parent 3300000, 315dafc7cdeSFabien Parent }; 316dafc7cdeSFabien Parent 317dafc7cdeSFabien Parent static const int vusb_voltages[] = { 318dafc7cdeSFabien Parent 0, 319dafc7cdeSFabien Parent 0, 320dafc7cdeSFabien Parent 0, 321dafc7cdeSFabien Parent 3000000, 322dafc7cdeSFabien Parent 3100000, 323dafc7cdeSFabien Parent }; 324dafc7cdeSFabien Parent 325dafc7cdeSFabien Parent static const struct linear_range buck_volt_range1[] = { 326dafc7cdeSFabien Parent REGULATOR_LINEAR_RANGE(518750, 0, 0x7f, 6250), 327dafc7cdeSFabien Parent }; 328dafc7cdeSFabien Parent 329dafc7cdeSFabien Parent static const struct linear_range buck_volt_range2[] = { 330dafc7cdeSFabien Parent REGULATOR_LINEAR_RANGE(500000, 0, 0x7f, 6250), 331dafc7cdeSFabien Parent }; 332dafc7cdeSFabien Parent 333dafc7cdeSFabien Parent static const struct linear_range buck_volt_range3[] = { 334dafc7cdeSFabien Parent REGULATOR_LINEAR_RANGE(500000, 0, 0x3f, 50000), 335dafc7cdeSFabien Parent }; 336dafc7cdeSFabien Parent 337dafc7cdeSFabien Parent static const struct linear_range buck_volt_range4[] = { 338dafc7cdeSFabien Parent REGULATOR_LINEAR_RANGE(1200000, 0, 0x7f, 12500), 339dafc7cdeSFabien Parent }; 340dafc7cdeSFabien Parent 341dafc7cdeSFabien Parent /* The array is indexed by id(MT6357_ID_XXX) */ 342dafc7cdeSFabien Parent static struct mt6357_regulator_info mt6357_regulators[] = { 343dafc7cdeSFabien Parent /* Bucks */ 344dafc7cdeSFabien Parent MT6357_BUCK("buck-vcore", VCORE, 518750, 1312500, 6250, 345dafc7cdeSFabien Parent buck_volt_range1, MT6357_BUCK_VCORE_ELR0, 0x7f, 0x7f), 346dafc7cdeSFabien Parent MT6357_BUCK("buck-vproc", VPROC, 518750, 1312500, 6250, 347dafc7cdeSFabien Parent buck_volt_range1, MT6357_BUCK_VPROC_ELR0, 0x7f, 0x7f), 348dafc7cdeSFabien Parent MT6357_BUCK("buck-vmodem", VMODEM, 500000, 1293750, 6250, 349dafc7cdeSFabien Parent buck_volt_range2, MT6357_BUCK_VMODEM_ELR0, 0x7f, 0x7f), 350dafc7cdeSFabien Parent MT6357_BUCK("buck-vpa", VPA, 500000, 3650000, 50000, 351dafc7cdeSFabien Parent buck_volt_range3, MT6357_BUCK_VPA_CON1, 0x3f, 0x3f), 352dafc7cdeSFabien Parent MT6357_BUCK("buck-vs1", VS1, 1200000, 2787500, 12500, 353dafc7cdeSFabien Parent buck_volt_range4, MT6357_BUCK_VS1_ELR0, 0x7f, 0x7f), 354dafc7cdeSFabien Parent 355dafc7cdeSFabien Parent /* LDOs */ 356dafc7cdeSFabien Parent MT6357_LDO("ldo-vcama", VCAMA, vcama_voltages, 357dafc7cdeSFabien Parent MT6357_LDO_VCAMA_CON0, MT6357_VCAMA_ANA_CON0, 0xf00), 358dafc7cdeSFabien Parent MT6357_LDO("ldo-vcamd", VCAMD, vcamd_voltages, 359dafc7cdeSFabien Parent MT6357_LDO_VCAMD_CON0, MT6357_VCAMD_ANA_CON0, 0xf00), 360dafc7cdeSFabien Parent MT6357_LDO("ldo-vcn33-bt", VCN33_BT, vcn33_voltages, 361dafc7cdeSFabien Parent MT6357_LDO_VCN33_CON0_0, MT6357_VCN33_ANA_CON0, 0x300), 362dafc7cdeSFabien Parent MT6357_LDO("ldo-vcn33-wifi", VCN33_WIFI, vcn33_voltages, 363dafc7cdeSFabien Parent MT6357_LDO_VCN33_CON0_1, MT6357_VCN33_ANA_CON0, 0x300), 364dafc7cdeSFabien Parent MT6357_LDO("ldo-vdram", VDRAM, vdram_voltages, 365dafc7cdeSFabien Parent MT6357_LDO_VDRAM_CON0, MT6357_VDRAM_ELR_2, 0x300), 366dafc7cdeSFabien Parent MT6357_LDO("ldo-vefuse", VEFUSE, vefuse_voltages, 367dafc7cdeSFabien Parent MT6357_LDO_VEFUSE_CON0, MT6357_VEFUSE_ANA_CON0, 0xf00), 368dafc7cdeSFabien Parent MT6357_LDO("ldo-vemc", VEMC, vemc_voltages, 369dafc7cdeSFabien Parent MT6357_LDO_VEMC_CON0, MT6357_VEMC_ANA_CON0, 0x700), 370dafc7cdeSFabien Parent MT6357_LDO("ldo-vibr", VIBR, vibr_voltages, 371dafc7cdeSFabien Parent MT6357_LDO_VIBR_CON0, MT6357_VIBR_ANA_CON0, 0xf00), 372dafc7cdeSFabien Parent MT6357_LDO("ldo-vldo28", VLDO28, vldo28_voltages, 373dafc7cdeSFabien Parent MT6357_LDO_VLDO28_CON0_0, MT6357_VLDO28_ANA_CON0, 0x300), 374dafc7cdeSFabien Parent MT6357_LDO("ldo-vmc", VMC, vmc_voltages, 375dafc7cdeSFabien Parent MT6357_LDO_VMC_CON0, MT6357_VMC_ANA_CON0, 0xf00), 376dafc7cdeSFabien Parent MT6357_LDO("ldo-vmch", VMCH, vmch_voltages, 377dafc7cdeSFabien Parent MT6357_LDO_VMCH_CON0, MT6357_VMCH_ANA_CON0, 0x700), 378dafc7cdeSFabien Parent MT6357_LDO("ldo-vsim1", VSIM1, vsim_voltages, 379dafc7cdeSFabien Parent MT6357_LDO_VSIM1_CON0, MT6357_VSIM1_ANA_CON0, 0xf00), 380dafc7cdeSFabien Parent MT6357_LDO("ldo-vsim2", VSIM2, vsim_voltages, 381dafc7cdeSFabien Parent MT6357_LDO_VSIM2_CON0, MT6357_VSIM2_ANA_CON0, 0xf00), 382dafc7cdeSFabien Parent MT6357_LDO("ldo-vusb33", VUSB33, vusb_voltages, 383dafc7cdeSFabien Parent MT6357_LDO_VUSB33_CON0_0, MT6357_VUSB33_ANA_CON0, 0x700), 384dafc7cdeSFabien Parent MT6357_LDO("ldo-vxo22", VXO22, vxo22_voltages, 385dafc7cdeSFabien Parent MT6357_LDO_VXO22_CON0, MT6357_VXO22_ANA_CON0, 0x300), 386dafc7cdeSFabien Parent 387dafc7cdeSFabien Parent MT6357_LDO1("ldo-vsram-proc", VSRAM_PROC, 518750, 1312500, 6250, 388dafc7cdeSFabien Parent buck_volt_range1, MT6357_LDO_VSRAM_PROC_CON0, 389dafc7cdeSFabien Parent MT6357_LDO_VSRAM_CON0, 0x7f00), 390dafc7cdeSFabien Parent MT6357_LDO1("ldo-vsram-others", VSRAM_OTHERS, 518750, 1312500, 6250, 391dafc7cdeSFabien Parent buck_volt_range1, MT6357_LDO_VSRAM_OTHERS_CON0, 392dafc7cdeSFabien Parent MT6357_LDO_VSRAM_CON1, 0x7f00), 393dafc7cdeSFabien Parent 394dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vaud28", VAUD28, 2800000), 395dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vaux18", VAUX18, 1800000), 396dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vcamio18", VCAMIO, 1800000), 397dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vcn18", VCN18, 1800000), 398dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vcn28", VCN28, 2800000), 399dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vfe28", VFE28, 2800000), 400dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vio18", VIO18, 1800000), 401dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vio28", VIO28, 2800000), 402dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vrf12", VRF12, 1200000), 403dafc7cdeSFabien Parent MT6357_REG_FIXED("ldo-vrf18", VRF18, 1800000), 404dafc7cdeSFabien Parent }; 405dafc7cdeSFabien Parent 406dafc7cdeSFabien Parent static int mt6357_regulator_probe(struct platform_device *pdev) 407dafc7cdeSFabien Parent { 408dafc7cdeSFabien Parent struct mt6397_chip *mt6357 = dev_get_drvdata(pdev->dev.parent); 409dafc7cdeSFabien Parent struct regulator_config config = {}; 410dafc7cdeSFabien Parent struct regulator_dev *rdev; 411dafc7cdeSFabien Parent int i; 412dafc7cdeSFabien Parent 413dafc7cdeSFabien Parent pdev->dev.of_node = pdev->dev.parent->of_node; 414dafc7cdeSFabien Parent 415dafc7cdeSFabien Parent for (i = 0; i < MT6357_MAX_REGULATOR; i++) { 416dafc7cdeSFabien Parent config.dev = &pdev->dev; 417dafc7cdeSFabien Parent config.driver_data = &mt6357_regulators[i]; 418dafc7cdeSFabien Parent config.regmap = mt6357->regmap; 419dafc7cdeSFabien Parent 420dafc7cdeSFabien Parent rdev = devm_regulator_register(&pdev->dev, 421dafc7cdeSFabien Parent &mt6357_regulators[i].desc, 422dafc7cdeSFabien Parent &config); 423dafc7cdeSFabien Parent if (IS_ERR(rdev)) { 424dafc7cdeSFabien Parent dev_err(&pdev->dev, "failed to register %s\n", 425dafc7cdeSFabien Parent mt6357_regulators[i].desc.name); 426dafc7cdeSFabien Parent return PTR_ERR(rdev); 427dafc7cdeSFabien Parent } 428dafc7cdeSFabien Parent } 429dafc7cdeSFabien Parent 430dafc7cdeSFabien Parent return 0; 431dafc7cdeSFabien Parent } 432dafc7cdeSFabien Parent 433dafc7cdeSFabien Parent static const struct platform_device_id mt6357_platform_ids[] = { 434dafc7cdeSFabien Parent { "mt6357-regulator" }, 435dafc7cdeSFabien Parent { /* sentinel */ }, 436dafc7cdeSFabien Parent }; 437dafc7cdeSFabien Parent MODULE_DEVICE_TABLE(platform, mt6357_platform_ids); 438dafc7cdeSFabien Parent 439dafc7cdeSFabien Parent static struct platform_driver mt6357_regulator_driver = { 440dafc7cdeSFabien Parent .driver = { 441dafc7cdeSFabien Parent .name = "mt6357-regulator", 442*bdce47bbSDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS, 443dafc7cdeSFabien Parent }, 444dafc7cdeSFabien Parent .probe = mt6357_regulator_probe, 445dafc7cdeSFabien Parent .id_table = mt6357_platform_ids, 446dafc7cdeSFabien Parent }; 447dafc7cdeSFabien Parent 448dafc7cdeSFabien Parent module_platform_driver(mt6357_regulator_driver); 449dafc7cdeSFabien Parent 450dafc7cdeSFabien Parent MODULE_AUTHOR("Chen Zhong <chen.zhong@mediatek.com>"); 451dafc7cdeSFabien Parent MODULE_AUTHOR("Fabien Parent <fabien.parent@linaro.org>"); 452dafc7cdeSFabien Parent MODULE_AUTHOR("Alexandre Mergnat <amergnat@baylibre.com>"); 453dafc7cdeSFabien Parent MODULE_DESCRIPTION("Regulator Driver for MediaTek MT6357 PMIC"); 454dafc7cdeSFabien Parent MODULE_LICENSE("GPL"); 455