13b15ccacSCristian Ciocaltea // SPDX-License-Identifier: GPL-2.0+ 23b15ccacSCristian Ciocaltea // 33b15ccacSCristian Ciocaltea // Regulator driver for ATC260x PMICs 43b15ccacSCristian Ciocaltea // 53b15ccacSCristian Ciocaltea // Copyright (C) 2019 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> 63b15ccacSCristian Ciocaltea // Copyright (C) 2020 Cristian Ciocaltea <cristian.ciocaltea@gmail.com> 73b15ccacSCristian Ciocaltea 83b15ccacSCristian Ciocaltea #include <linux/mfd/atc260x/core.h> 93b15ccacSCristian Ciocaltea #include <linux/module.h> 10045a44d4SRob Herring #include <linux/of.h> 11045a44d4SRob Herring #include <linux/platform_device.h> 123b15ccacSCristian Ciocaltea #include <linux/regmap.h> 133b15ccacSCristian Ciocaltea #include <linux/regulator/driver.h> 143b15ccacSCristian Ciocaltea 153b15ccacSCristian Ciocaltea struct atc260x_regulator_data { 163b15ccacSCristian Ciocaltea int voltage_time_dcdc; 173b15ccacSCristian Ciocaltea int voltage_time_ldo; 183b15ccacSCristian Ciocaltea }; 193b15ccacSCristian Ciocaltea 203b15ccacSCristian Ciocaltea static const struct linear_range atc2603c_dcdc_voltage_ranges[] = { 213b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(1300000, 0, 13, 50000), 223b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(1950000, 14, 15, 100000), 233b15ccacSCristian Ciocaltea }; 243b15ccacSCristian Ciocaltea 253b15ccacSCristian Ciocaltea static const struct linear_range atc2609a_dcdc_voltage_ranges[] = { 263b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(600000, 0, 127, 6250), 273b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(1400000, 128, 232, 25000), 283b15ccacSCristian Ciocaltea }; 293b15ccacSCristian Ciocaltea 303b15ccacSCristian Ciocaltea static const struct linear_range atc2609a_ldo_voltage_ranges0[] = { 313b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(700000, 0, 15, 100000), 321963fa67SAxel Lin REGULATOR_LINEAR_RANGE(2100000, 0, 12, 100000), 333b15ccacSCristian Ciocaltea }; 343b15ccacSCristian Ciocaltea 353b15ccacSCristian Ciocaltea static const struct linear_range atc2609a_ldo_voltage_ranges1[] = { 363b15ccacSCristian Ciocaltea REGULATOR_LINEAR_RANGE(850000, 0, 15, 100000), 371963fa67SAxel Lin REGULATOR_LINEAR_RANGE(2100000, 0, 11, 100000), 383b15ccacSCristian Ciocaltea }; 393b15ccacSCristian Ciocaltea 403b15ccacSCristian Ciocaltea static const unsigned int atc260x_ldo_voltage_range_sel[] = { 41*269cb04bSChen-Yu Tsai 0x0, 0x1, 423b15ccacSCristian Ciocaltea }; 433b15ccacSCristian Ciocaltea 443b15ccacSCristian Ciocaltea static int atc260x_dcdc_set_voltage_time_sel(struct regulator_dev *rdev, 453b15ccacSCristian Ciocaltea unsigned int old_selector, 463b15ccacSCristian Ciocaltea unsigned int new_selector) 473b15ccacSCristian Ciocaltea { 483b15ccacSCristian Ciocaltea struct atc260x_regulator_data *data = rdev_get_drvdata(rdev); 493b15ccacSCristian Ciocaltea 503b15ccacSCristian Ciocaltea if (new_selector > old_selector) 513b15ccacSCristian Ciocaltea return data->voltage_time_dcdc; 523b15ccacSCristian Ciocaltea 533b15ccacSCristian Ciocaltea return 0; 543b15ccacSCristian Ciocaltea } 553b15ccacSCristian Ciocaltea 563b15ccacSCristian Ciocaltea static int atc260x_ldo_set_voltage_time_sel(struct regulator_dev *rdev, 573b15ccacSCristian Ciocaltea unsigned int old_selector, 583b15ccacSCristian Ciocaltea unsigned int new_selector) 593b15ccacSCristian Ciocaltea { 603b15ccacSCristian Ciocaltea struct atc260x_regulator_data *data = rdev_get_drvdata(rdev); 613b15ccacSCristian Ciocaltea 623b15ccacSCristian Ciocaltea if (new_selector > old_selector) 633b15ccacSCristian Ciocaltea return data->voltage_time_ldo; 643b15ccacSCristian Ciocaltea 653b15ccacSCristian Ciocaltea return 0; 663b15ccacSCristian Ciocaltea } 673b15ccacSCristian Ciocaltea 683b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_dcdc_ops = { 693b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 703b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 713b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 723b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 733b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 743b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 753b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel, 763b15ccacSCristian Ciocaltea }; 773b15ccacSCristian Ciocaltea 783b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_ldo_ops = { 793b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 803b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 813b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 823b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 833b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 843b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 853b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel, 863b15ccacSCristian Ciocaltea }; 873b15ccacSCristian Ciocaltea 883b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_ldo_bypass_ops = { 893b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 903b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 913b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 923b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 933b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 943b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 953b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel, 963b15ccacSCristian Ciocaltea .set_bypass = regulator_set_bypass_regmap, 973b15ccacSCristian Ciocaltea .get_bypass = regulator_get_bypass_regmap, 983b15ccacSCristian Ciocaltea }; 993b15ccacSCristian Ciocaltea 1003b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_ldo_bypass_discharge_ops = { 1013b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 1023b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 1033b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 1043b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 1053b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 1063b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 1073b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel, 1083b15ccacSCristian Ciocaltea .set_bypass = regulator_set_bypass_regmap, 1093b15ccacSCristian Ciocaltea .get_bypass = regulator_get_bypass_regmap, 1103b15ccacSCristian Ciocaltea .set_active_discharge = regulator_set_active_discharge_regmap, 1113b15ccacSCristian Ciocaltea }; 1123b15ccacSCristian Ciocaltea 1133b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_dcdc_range_ops = { 1143b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 1153b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 1163b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 1173b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear_range, 1183b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 1193b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 1203b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel, 1213b15ccacSCristian Ciocaltea }; 1223b15ccacSCristian Ciocaltea 1233b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_ldo_range_pick_ops = { 1243b15ccacSCristian Ciocaltea .enable = regulator_enable_regmap, 1253b15ccacSCristian Ciocaltea .disable = regulator_disable_regmap, 1263b15ccacSCristian Ciocaltea .is_enabled = regulator_is_enabled_regmap, 1273b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_pickable_linear_range, 1283b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, 1293b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, 1303b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel, 1313b15ccacSCristian Ciocaltea }; 1323b15ccacSCristian Ciocaltea 1333b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_dcdc_fixed_ops = { 1343b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 1353b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 1363b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 1373b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_dcdc_set_voltage_time_sel, 1383b15ccacSCristian Ciocaltea }; 1393b15ccacSCristian Ciocaltea 1403b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_ldo_fixed_ops = { 1413b15ccacSCristian Ciocaltea .list_voltage = regulator_list_voltage_linear, 1423b15ccacSCristian Ciocaltea .set_voltage_sel = regulator_set_voltage_sel_regmap, 1433b15ccacSCristian Ciocaltea .get_voltage_sel = regulator_get_voltage_sel_regmap, 1443b15ccacSCristian Ciocaltea .set_voltage_time_sel = atc260x_ldo_set_voltage_time_sel, 1453b15ccacSCristian Ciocaltea }; 1463b15ccacSCristian Ciocaltea 1473b15ccacSCristian Ciocaltea static const struct regulator_ops atc260x_no_ops = { 1483b15ccacSCristian Ciocaltea }; 1493b15ccacSCristian Ciocaltea 1503b15ccacSCristian Ciocaltea /* 1513b15ccacSCristian Ciocaltea * Note LDO8 is not documented in datasheet (v2.4), but supported 1523b15ccacSCristian Ciocaltea * in the vendor's driver implementation (xapp-le-kernel). 1533b15ccacSCristian Ciocaltea */ 1543b15ccacSCristian Ciocaltea enum atc2603c_reg_ids { 1553b15ccacSCristian Ciocaltea ATC2603C_ID_DCDC1, 1563b15ccacSCristian Ciocaltea ATC2603C_ID_DCDC2, 1573b15ccacSCristian Ciocaltea ATC2603C_ID_DCDC3, 1583b15ccacSCristian Ciocaltea ATC2603C_ID_LDO1, 1593b15ccacSCristian Ciocaltea ATC2603C_ID_LDO2, 1603b15ccacSCristian Ciocaltea ATC2603C_ID_LDO3, 1613b15ccacSCristian Ciocaltea ATC2603C_ID_LDO5, 1623b15ccacSCristian Ciocaltea ATC2603C_ID_LDO6, 1633b15ccacSCristian Ciocaltea ATC2603C_ID_LDO7, 1643b15ccacSCristian Ciocaltea ATC2603C_ID_LDO8, 1653b15ccacSCristian Ciocaltea ATC2603C_ID_LDO11, 1663b15ccacSCristian Ciocaltea ATC2603C_ID_LDO12, 1673b15ccacSCristian Ciocaltea ATC2603C_ID_SWITCHLDO1, 1683b15ccacSCristian Ciocaltea ATC2603C_ID_MAX, 1693b15ccacSCristian Ciocaltea }; 1703b15ccacSCristian Ciocaltea 1713b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_dcdc(num, min, step, n_volt, vsel_h, vsel_l) { \ 1723b15ccacSCristian Ciocaltea .name = "DCDC"#num, \ 1733b15ccacSCristian Ciocaltea .supply_name = "dcdc"#num, \ 1743b15ccacSCristian Ciocaltea .of_match = of_match_ptr("dcdc"#num), \ 1753b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 1763b15ccacSCristian Ciocaltea .id = ATC2603C_ID_DCDC##num, \ 1773b15ccacSCristian Ciocaltea .ops = &atc260x_dcdc_ops, \ 1783b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 1793b15ccacSCristian Ciocaltea .min_uV = min, \ 1803b15ccacSCristian Ciocaltea .uV_step = step, \ 1813b15ccacSCristian Ciocaltea .n_voltages = n_volt, \ 1823b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \ 1833b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 1843b15ccacSCristian Ciocaltea .enable_reg = ATC2603C_PMU_DC##num##_CTL0, \ 1853b15ccacSCristian Ciocaltea .enable_mask = BIT(15), \ 1863b15ccacSCristian Ciocaltea .enable_time = 800, \ 1873b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 1883b15ccacSCristian Ciocaltea } 1893b15ccacSCristian Ciocaltea 1903b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_dcdc_range(num, vsel_h, vsel_l) { \ 1913b15ccacSCristian Ciocaltea .name = "DCDC"#num, \ 1923b15ccacSCristian Ciocaltea .supply_name = "dcdc"#num, \ 1933b15ccacSCristian Ciocaltea .of_match = of_match_ptr("dcdc"#num), \ 1943b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 1953b15ccacSCristian Ciocaltea .id = ATC2603C_ID_DCDC##num, \ 1963b15ccacSCristian Ciocaltea .ops = &atc260x_dcdc_range_ops, \ 1973b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 1983b15ccacSCristian Ciocaltea .n_voltages = 16, \ 1993b15ccacSCristian Ciocaltea .linear_ranges = atc2603c_dcdc_voltage_ranges, \ 2003b15ccacSCristian Ciocaltea .n_linear_ranges = ARRAY_SIZE(atc2603c_dcdc_voltage_ranges), \ 2013b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \ 2023b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 2033b15ccacSCristian Ciocaltea .enable_reg = ATC2603C_PMU_DC##num##_CTL0, \ 2043b15ccacSCristian Ciocaltea .enable_mask = BIT(15), \ 2053b15ccacSCristian Ciocaltea .enable_time = 800, \ 2063b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2073b15ccacSCristian Ciocaltea } 2083b15ccacSCristian Ciocaltea 2093b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_dcdc_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \ 2103b15ccacSCristian Ciocaltea .name = "DCDC"#num, \ 2113b15ccacSCristian Ciocaltea .supply_name = "dcdc"#num, \ 2123b15ccacSCristian Ciocaltea .of_match = of_match_ptr("dcdc"#num), \ 2133b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 2143b15ccacSCristian Ciocaltea .id = ATC2603C_ID_DCDC##num, \ 2153b15ccacSCristian Ciocaltea .ops = &atc260x_dcdc_fixed_ops, \ 2163b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 2173b15ccacSCristian Ciocaltea .min_uV = min, \ 2183b15ccacSCristian Ciocaltea .uV_step = step, \ 2193b15ccacSCristian Ciocaltea .n_voltages = n_volt, \ 2203b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_DC##num##_CTL0, \ 2213b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 2223b15ccacSCristian Ciocaltea .enable_time = 800, \ 2233b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2243b15ccacSCristian Ciocaltea } 2253b15ccacSCristian Ciocaltea 2263b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_ldo(num, min, step, n_volt, vsel_h, vsel_l) { \ 2273b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 2283b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 2293b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 2303b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 2313b15ccacSCristian Ciocaltea .id = ATC2603C_ID_LDO##num, \ 2323b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_ops, \ 2333b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 2343b15ccacSCristian Ciocaltea .min_uV = min, \ 2353b15ccacSCristian Ciocaltea .uV_step = step, \ 2363b15ccacSCristian Ciocaltea .n_voltages = n_volt, \ 2373b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \ 2383b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 2393b15ccacSCristian Ciocaltea .enable_reg = ATC2603C_PMU_LDO##num##_CTL, \ 2403b15ccacSCristian Ciocaltea .enable_mask = BIT(0), \ 2413b15ccacSCristian Ciocaltea .enable_time = 2000, \ 2423b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2433b15ccacSCristian Ciocaltea } 2443b15ccacSCristian Ciocaltea 2453b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_ldo_fixed(num, min, step, n_volt, vsel_h, vsel_l) { \ 2463b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 2473b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 2483b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 2493b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 2503b15ccacSCristian Ciocaltea .id = ATC2603C_ID_LDO##num, \ 2513b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_fixed_ops, \ 2523b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 2533b15ccacSCristian Ciocaltea .min_uV = min, \ 2543b15ccacSCristian Ciocaltea .uV_step = step, \ 2553b15ccacSCristian Ciocaltea .n_voltages = n_volt, \ 2563b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_LDO##num##_CTL, \ 2573b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 2583b15ccacSCristian Ciocaltea .enable_time = 2000, \ 2593b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2603b15ccacSCristian Ciocaltea } 2613b15ccacSCristian Ciocaltea 2623b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_ldo_noops(num, vfixed) { \ 2633b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 2643b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 2653b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 2663b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 2673b15ccacSCristian Ciocaltea .id = ATC2603C_ID_LDO##num, \ 2683b15ccacSCristian Ciocaltea .ops = &atc260x_no_ops, \ 2693b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 2703b15ccacSCristian Ciocaltea .fixed_uV = vfixed, \ 2713b15ccacSCristian Ciocaltea .n_voltages = 1, \ 2723b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2733b15ccacSCristian Ciocaltea } 2743b15ccacSCristian Ciocaltea 2753b15ccacSCristian Ciocaltea #define atc2603c_reg_desc_ldo_switch(num, min, step, n_volt, vsel_h, vsel_l) { \ 2763b15ccacSCristian Ciocaltea .name = "SWITCHLDO"#num, \ 2773b15ccacSCristian Ciocaltea .supply_name = "switchldo"#num, \ 2783b15ccacSCristian Ciocaltea .of_match = of_match_ptr("switchldo"#num), \ 2793b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 2803b15ccacSCristian Ciocaltea .id = ATC2603C_ID_SWITCHLDO##num, \ 2813b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_bypass_discharge_ops, \ 2823b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 2833b15ccacSCristian Ciocaltea .min_uV = min, \ 2843b15ccacSCristian Ciocaltea .uV_step = step, \ 2853b15ccacSCristian Ciocaltea .n_voltages = n_volt, \ 2863b15ccacSCristian Ciocaltea .vsel_reg = ATC2603C_PMU_SWITCH_CTL, \ 2873b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(vsel_h, vsel_l), \ 2883b15ccacSCristian Ciocaltea .enable_reg = ATC2603C_PMU_SWITCH_CTL, \ 2893b15ccacSCristian Ciocaltea .enable_mask = BIT(15), \ 2903b15ccacSCristian Ciocaltea .enable_is_inverted = true, \ 2913b15ccacSCristian Ciocaltea .enable_time = 2000, \ 2923b15ccacSCristian Ciocaltea .bypass_reg = ATC2603C_PMU_SWITCH_CTL, \ 2933b15ccacSCristian Ciocaltea .bypass_mask = BIT(5), \ 2943b15ccacSCristian Ciocaltea .active_discharge_reg = ATC2603C_PMU_SWITCH_CTL, \ 2953b15ccacSCristian Ciocaltea .active_discharge_mask = BIT(1), \ 2962316f0fcSAxel Lin .active_discharge_on = BIT(1), \ 2973b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 2983b15ccacSCristian Ciocaltea } 2993b15ccacSCristian Ciocaltea 3003b15ccacSCristian Ciocaltea static const struct regulator_desc atc2603c_reg[] = { 3013b15ccacSCristian Ciocaltea atc2603c_reg_desc_dcdc_fixed(1, 700000, 25000, 29, 11, 7), 3023b15ccacSCristian Ciocaltea atc2603c_reg_desc_dcdc_range(2, 12, 8), 3033b15ccacSCristian Ciocaltea atc2603c_reg_desc_dcdc_fixed(3, 2600000, 100000, 8, 11, 9), 3043b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_fixed(1, 2600000, 100000, 8, 15, 13), 3053b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_fixed(2, 2600000, 100000, 8, 15, 13), 3063b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_fixed(3, 1500000, 100000, 6, 15, 13), 3073b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo(5, 2600000, 100000, 8, 15, 13), 3083b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_fixed(6, 700000, 25000, 29, 15, 11), 3093b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo(7, 1500000, 100000, 6, 15, 13), 3103b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo(8, 2300000, 100000, 11, 15, 12), 3113b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_fixed(11, 2600000, 100000, 8, 15, 13), 3123b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_noops(12, 1800000), 3133b15ccacSCristian Ciocaltea atc2603c_reg_desc_ldo_switch(1, 3000000, 100000, 4, 4, 3), 3143b15ccacSCristian Ciocaltea }; 3153b15ccacSCristian Ciocaltea 3163b15ccacSCristian Ciocaltea static const struct regulator_desc atc2603c_reg_dcdc2_ver_b = 3173b15ccacSCristian Ciocaltea atc2603c_reg_desc_dcdc(2, 1000000, 50000, 18, 12, 8); 3183b15ccacSCristian Ciocaltea 3193b15ccacSCristian Ciocaltea enum atc2609a_reg_ids { 3203b15ccacSCristian Ciocaltea ATC2609A_ID_DCDC0, 3213b15ccacSCristian Ciocaltea ATC2609A_ID_DCDC1, 3223b15ccacSCristian Ciocaltea ATC2609A_ID_DCDC2, 3233b15ccacSCristian Ciocaltea ATC2609A_ID_DCDC3, 3243b15ccacSCristian Ciocaltea ATC2609A_ID_DCDC4, 3253b15ccacSCristian Ciocaltea ATC2609A_ID_LDO0, 3263b15ccacSCristian Ciocaltea ATC2609A_ID_LDO1, 3273b15ccacSCristian Ciocaltea ATC2609A_ID_LDO2, 3283b15ccacSCristian Ciocaltea ATC2609A_ID_LDO3, 3293b15ccacSCristian Ciocaltea ATC2609A_ID_LDO4, 3303b15ccacSCristian Ciocaltea ATC2609A_ID_LDO5, 3313b15ccacSCristian Ciocaltea ATC2609A_ID_LDO6, 3323b15ccacSCristian Ciocaltea ATC2609A_ID_LDO7, 3333b15ccacSCristian Ciocaltea ATC2609A_ID_LDO8, 3343b15ccacSCristian Ciocaltea ATC2609A_ID_LDO9, 3353b15ccacSCristian Ciocaltea ATC2609A_ID_MAX, 3363b15ccacSCristian Ciocaltea }; 3373b15ccacSCristian Ciocaltea 3383b15ccacSCristian Ciocaltea #define atc2609a_reg_desc_dcdc(num, en_bit) { \ 3393b15ccacSCristian Ciocaltea .name = "DCDC"#num, \ 3403b15ccacSCristian Ciocaltea .supply_name = "dcdc"#num, \ 3413b15ccacSCristian Ciocaltea .of_match = of_match_ptr("dcdc"#num), \ 3423b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 3433b15ccacSCristian Ciocaltea .id = ATC2609A_ID_DCDC##num, \ 3443b15ccacSCristian Ciocaltea .ops = &atc260x_dcdc_ops, \ 3453b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 3463b15ccacSCristian Ciocaltea .min_uV = 600000, \ 3473b15ccacSCristian Ciocaltea .uV_step = 6250, \ 3483b15ccacSCristian Ciocaltea .n_voltages = 256, \ 3493b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \ 3503b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(15, 8), \ 3513b15ccacSCristian Ciocaltea .enable_reg = ATC2609A_PMU_DC_OSC, \ 3523b15ccacSCristian Ciocaltea .enable_mask = BIT(en_bit), \ 3533b15ccacSCristian Ciocaltea .enable_time = 800, \ 3543b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 3553b15ccacSCristian Ciocaltea } 3563b15ccacSCristian Ciocaltea 3573b15ccacSCristian Ciocaltea #define atc2609a_reg_desc_dcdc_range(num, en_bit) { \ 3583b15ccacSCristian Ciocaltea .name = "DCDC"#num, \ 3593b15ccacSCristian Ciocaltea .supply_name = "dcdc"#num, \ 3603b15ccacSCristian Ciocaltea .of_match = of_match_ptr("dcdc"#num), \ 3613b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 3623b15ccacSCristian Ciocaltea .id = ATC2609A_ID_DCDC##num, \ 3633b15ccacSCristian Ciocaltea .ops = &atc260x_dcdc_range_ops, \ 3643b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 3653b15ccacSCristian Ciocaltea .n_voltages = 233, \ 3663b15ccacSCristian Ciocaltea .linear_ranges = atc2609a_dcdc_voltage_ranges, \ 3673b15ccacSCristian Ciocaltea .n_linear_ranges = ARRAY_SIZE(atc2609a_dcdc_voltage_ranges), \ 3683b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_DC##num##_CTL0, \ 3693b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(15, 8), \ 3703b15ccacSCristian Ciocaltea .enable_reg = ATC2609A_PMU_DC_OSC, \ 3713b15ccacSCristian Ciocaltea .enable_mask = BIT(en_bit), \ 3723b15ccacSCristian Ciocaltea .enable_time = 800, \ 3733b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 3743b15ccacSCristian Ciocaltea } 3753b15ccacSCristian Ciocaltea 3763b15ccacSCristian Ciocaltea #define atc2609a_reg_desc_ldo(num) { \ 3773b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 3783b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 3793b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 3803b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 3813b15ccacSCristian Ciocaltea .id = ATC2609A_ID_LDO##num, \ 3823b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_ops, \ 3833b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 3843b15ccacSCristian Ciocaltea .min_uV = 700000, \ 3853b15ccacSCristian Ciocaltea .uV_step = 100000, \ 3863b15ccacSCristian Ciocaltea .n_voltages = 16, \ 3873b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 3883b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(4, 1), \ 3893b15ccacSCristian Ciocaltea .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 3903b15ccacSCristian Ciocaltea .enable_mask = BIT(0), \ 3913b15ccacSCristian Ciocaltea .enable_time = 2000, \ 3923b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 3933b15ccacSCristian Ciocaltea } 3943b15ccacSCristian Ciocaltea 3953b15ccacSCristian Ciocaltea #define atc2609a_reg_desc_ldo_bypass(num) { \ 3963b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 3973b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 3983b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 3993b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 4003b15ccacSCristian Ciocaltea .id = ATC2609A_ID_LDO##num, \ 4013b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_bypass_ops, \ 4023b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 4033b15ccacSCristian Ciocaltea .min_uV = 2300000, \ 4043b15ccacSCristian Ciocaltea .uV_step = 100000, \ 4053b15ccacSCristian Ciocaltea .n_voltages = 12, \ 4063b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4073b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(5, 2), \ 4083b15ccacSCristian Ciocaltea .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4093b15ccacSCristian Ciocaltea .enable_mask = BIT(0), \ 4103b15ccacSCristian Ciocaltea .enable_time = 2000, \ 4113b15ccacSCristian Ciocaltea .bypass_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4123b15ccacSCristian Ciocaltea .bypass_mask = BIT(1), \ 4133b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 4143b15ccacSCristian Ciocaltea } 4153b15ccacSCristian Ciocaltea 4161963fa67SAxel Lin #define atc2609a_reg_desc_ldo_range_pick(num, n_range, n_volt) { \ 4173b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 4183b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 4193b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 4203b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 4213b15ccacSCristian Ciocaltea .id = ATC2609A_ID_LDO##num, \ 4223b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_range_pick_ops, \ 4233b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 4243b15ccacSCristian Ciocaltea .linear_ranges = atc2609a_ldo_voltage_ranges##n_range, \ 4253b15ccacSCristian Ciocaltea .n_linear_ranges = ARRAY_SIZE(atc2609a_ldo_voltage_ranges##n_range), \ 4261963fa67SAxel Lin .n_voltages = n_volt, \ 4273b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4283b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(4, 1), \ 4293b15ccacSCristian Ciocaltea .vsel_range_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4303b15ccacSCristian Ciocaltea .vsel_range_mask = BIT(5), \ 431*269cb04bSChen-Yu Tsai .linear_range_selectors_bitfield = atc260x_ldo_voltage_range_sel, \ 4323b15ccacSCristian Ciocaltea .enable_reg = ATC2609A_PMU_LDO##num##_CTL0, \ 4333b15ccacSCristian Ciocaltea .enable_mask = BIT(0), \ 4343b15ccacSCristian Ciocaltea .enable_time = 2000, \ 4353b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 4363b15ccacSCristian Ciocaltea } 4373b15ccacSCristian Ciocaltea 4383b15ccacSCristian Ciocaltea #define atc2609a_reg_desc_ldo_fixed(num) { \ 4393b15ccacSCristian Ciocaltea .name = "LDO"#num, \ 4403b15ccacSCristian Ciocaltea .supply_name = "ldo"#num, \ 4413b15ccacSCristian Ciocaltea .of_match = of_match_ptr("ldo"#num), \ 4423b15ccacSCristian Ciocaltea .regulators_node = of_match_ptr("regulators"), \ 4433b15ccacSCristian Ciocaltea .id = ATC2609A_ID_LDO##num, \ 4443b15ccacSCristian Ciocaltea .ops = &atc260x_ldo_fixed_ops, \ 4453b15ccacSCristian Ciocaltea .type = REGULATOR_VOLTAGE, \ 4463b15ccacSCristian Ciocaltea .min_uV = 2600000, \ 4473b15ccacSCristian Ciocaltea .uV_step = 100000, \ 4483b15ccacSCristian Ciocaltea .n_voltages = 8, \ 4493b15ccacSCristian Ciocaltea .vsel_reg = ATC2609A_PMU_LDO##num##_CTL, \ 4503b15ccacSCristian Ciocaltea .vsel_mask = GENMASK(15, 13), \ 4513b15ccacSCristian Ciocaltea .enable_time = 2000, \ 4523b15ccacSCristian Ciocaltea .owner = THIS_MODULE, \ 4533b15ccacSCristian Ciocaltea } 4543b15ccacSCristian Ciocaltea 4553b15ccacSCristian Ciocaltea static const struct regulator_desc atc2609a_reg[] = { 4563b15ccacSCristian Ciocaltea atc2609a_reg_desc_dcdc(0, 4), 4573b15ccacSCristian Ciocaltea atc2609a_reg_desc_dcdc(1, 5), 4583b15ccacSCristian Ciocaltea atc2609a_reg_desc_dcdc(2, 6), 4593b15ccacSCristian Ciocaltea atc2609a_reg_desc_dcdc_range(3, 7), 4603b15ccacSCristian Ciocaltea atc2609a_reg_desc_dcdc(4, 8), 4613b15ccacSCristian Ciocaltea atc2609a_reg_desc_ldo_bypass(0), 4623b15ccacSCristian Ciocaltea atc2609a_reg_desc_ldo_bypass(1), 4633b15ccacSCristian Ciocaltea atc2609a_reg_desc_ldo_bypass(2), 4641963fa67SAxel Lin atc2609a_reg_desc_ldo_range_pick(3, 0, 29), 4651963fa67SAxel Lin atc2609a_reg_desc_ldo_range_pick(4, 0, 29), 4663b15ccacSCristian Ciocaltea atc2609a_reg_desc_ldo(5), 4671963fa67SAxel Lin atc2609a_reg_desc_ldo_range_pick(6, 1, 28), 4681963fa67SAxel Lin atc2609a_reg_desc_ldo_range_pick(7, 0, 29), 4691963fa67SAxel Lin atc2609a_reg_desc_ldo_range_pick(8, 0, 29), 4703b15ccacSCristian Ciocaltea atc2609a_reg_desc_ldo_fixed(9), 4713b15ccacSCristian Ciocaltea }; 4723b15ccacSCristian Ciocaltea 4733b15ccacSCristian Ciocaltea static int atc260x_regulator_probe(struct platform_device *pdev) 4743b15ccacSCristian Ciocaltea { 4753b15ccacSCristian Ciocaltea struct atc260x *atc260x = dev_get_drvdata(pdev->dev.parent); 4763b15ccacSCristian Ciocaltea struct device *dev = atc260x->dev; 4773b15ccacSCristian Ciocaltea struct atc260x_regulator_data *atc260x_data; 4783b15ccacSCristian Ciocaltea struct regulator_config config = {}; 4793b15ccacSCristian Ciocaltea struct regulator_dev *atc260x_rdev; 4803b15ccacSCristian Ciocaltea const struct regulator_desc *regulators; 4813b15ccacSCristian Ciocaltea bool atc2603c_ver_b = false; 4823b15ccacSCristian Ciocaltea int i, nregulators; 4833b15ccacSCristian Ciocaltea 4843b15ccacSCristian Ciocaltea atc260x_data = devm_kzalloc(&pdev->dev, sizeof(*atc260x_data), GFP_KERNEL); 4853b15ccacSCristian Ciocaltea if (!atc260x_data) 4863b15ccacSCristian Ciocaltea return -ENOMEM; 4873b15ccacSCristian Ciocaltea 4883b15ccacSCristian Ciocaltea atc260x_data->voltage_time_dcdc = 350; 4893b15ccacSCristian Ciocaltea atc260x_data->voltage_time_ldo = 800; 4903b15ccacSCristian Ciocaltea 4913b15ccacSCristian Ciocaltea switch (atc260x->ic_type) { 4923b15ccacSCristian Ciocaltea case ATC2603C: 4933b15ccacSCristian Ciocaltea regulators = atc2603c_reg; 4943b15ccacSCristian Ciocaltea nregulators = ATC2603C_ID_MAX; 4953b15ccacSCristian Ciocaltea atc2603c_ver_b = atc260x->ic_ver == ATC260X_B; 4963b15ccacSCristian Ciocaltea break; 4973b15ccacSCristian Ciocaltea case ATC2609A: 4983b15ccacSCristian Ciocaltea atc260x_data->voltage_time_dcdc = 250; 4993b15ccacSCristian Ciocaltea regulators = atc2609a_reg; 5003b15ccacSCristian Ciocaltea nregulators = ATC2609A_ID_MAX; 5013b15ccacSCristian Ciocaltea break; 5023b15ccacSCristian Ciocaltea default: 5033b15ccacSCristian Ciocaltea dev_err(dev, "unsupported ATC260X ID %d\n", atc260x->ic_type); 5043b15ccacSCristian Ciocaltea return -EINVAL; 5053b15ccacSCristian Ciocaltea } 5063b15ccacSCristian Ciocaltea 5073b15ccacSCristian Ciocaltea config.dev = dev; 5083b15ccacSCristian Ciocaltea config.regmap = atc260x->regmap; 5093b15ccacSCristian Ciocaltea config.driver_data = atc260x_data; 5103b15ccacSCristian Ciocaltea 5113b15ccacSCristian Ciocaltea /* Instantiate the regulators */ 5123b15ccacSCristian Ciocaltea for (i = 0; i < nregulators; i++) { 5133b15ccacSCristian Ciocaltea if (atc2603c_ver_b && regulators[i].id == ATC2603C_ID_DCDC2) 5143b15ccacSCristian Ciocaltea atc260x_rdev = devm_regulator_register(&pdev->dev, 5153b15ccacSCristian Ciocaltea &atc2603c_reg_dcdc2_ver_b, 5163b15ccacSCristian Ciocaltea &config); 5173b15ccacSCristian Ciocaltea else 5183b15ccacSCristian Ciocaltea atc260x_rdev = devm_regulator_register(&pdev->dev, 5193b15ccacSCristian Ciocaltea ®ulators[i], 5203b15ccacSCristian Ciocaltea &config); 5213b15ccacSCristian Ciocaltea if (IS_ERR(atc260x_rdev)) { 5223b15ccacSCristian Ciocaltea dev_err(dev, "failed to register regulator: %d\n", i); 5233b15ccacSCristian Ciocaltea return PTR_ERR(atc260x_rdev); 5243b15ccacSCristian Ciocaltea } 5253b15ccacSCristian Ciocaltea } 5263b15ccacSCristian Ciocaltea 5273b15ccacSCristian Ciocaltea return 0; 5283b15ccacSCristian Ciocaltea } 5293b15ccacSCristian Ciocaltea 5303b15ccacSCristian Ciocaltea static struct platform_driver atc260x_regulator_driver = { 5313b15ccacSCristian Ciocaltea .probe = atc260x_regulator_probe, 5323b15ccacSCristian Ciocaltea .driver = { 5333b15ccacSCristian Ciocaltea .name = "atc260x-regulator", 53446600ab1SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS, 5353b15ccacSCristian Ciocaltea }, 5363b15ccacSCristian Ciocaltea }; 5373b15ccacSCristian Ciocaltea 5383b15ccacSCristian Ciocaltea module_platform_driver(atc260x_regulator_driver); 5393b15ccacSCristian Ciocaltea 5403b15ccacSCristian Ciocaltea MODULE_DESCRIPTION("Regulator driver for ATC260x PMICs"); 5413b15ccacSCristian Ciocaltea MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>"); 5423b15ccacSCristian Ciocaltea MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@gmail.com>"); 5433b15ccacSCristian Ciocaltea MODULE_LICENSE("GPL"); 544