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