10935ff5fSRobin Gong // SPDX-License-Identifier: GPL-2.0
20935ff5fSRobin Gong /*
30935ff5fSRobin Gong * Copyright 2020 NXP.
40935ff5fSRobin Gong * NXP PCA9450 pmic driver
50935ff5fSRobin Gong */
60935ff5fSRobin Gong
70935ff5fSRobin Gong #include <linux/err.h>
88c67a11bSFrieder Schrempf #include <linux/gpio/consumer.h>
90935ff5fSRobin Gong #include <linux/i2c.h>
100935ff5fSRobin Gong #include <linux/interrupt.h>
110935ff5fSRobin Gong #include <linux/kernel.h>
120935ff5fSRobin Gong #include <linux/module.h>
130935ff5fSRobin Gong #include <linux/of.h>
140935ff5fSRobin Gong #include <linux/platform_device.h>
150935ff5fSRobin Gong #include <linux/regulator/driver.h>
160935ff5fSRobin Gong #include <linux/regulator/machine.h>
170935ff5fSRobin Gong #include <linux/regulator/of_regulator.h>
180935ff5fSRobin Gong #include <linux/regulator/pca9450.h>
190935ff5fSRobin Gong
200935ff5fSRobin Gong struct pc9450_dvs_config {
210935ff5fSRobin Gong unsigned int run_reg; /* dvs0 */
220935ff5fSRobin Gong unsigned int run_mask;
230935ff5fSRobin Gong unsigned int standby_reg; /* dvs1 */
240935ff5fSRobin Gong unsigned int standby_mask;
250935ff5fSRobin Gong };
260935ff5fSRobin Gong
270935ff5fSRobin Gong struct pca9450_regulator_desc {
280935ff5fSRobin Gong struct regulator_desc desc;
290935ff5fSRobin Gong const struct pc9450_dvs_config dvs;
300935ff5fSRobin Gong };
310935ff5fSRobin Gong
320935ff5fSRobin Gong struct pca9450 {
330935ff5fSRobin Gong struct device *dev;
340935ff5fSRobin Gong struct regmap *regmap;
358c67a11bSFrieder Schrempf struct gpio_desc *sd_vsel_gpio;
360935ff5fSRobin Gong enum pca9450_chip_type type;
370935ff5fSRobin Gong unsigned int rcnt;
380935ff5fSRobin Gong int irq;
390935ff5fSRobin Gong };
400935ff5fSRobin Gong
410935ff5fSRobin Gong static const struct regmap_range pca9450_status_range = {
420935ff5fSRobin Gong .range_min = PCA9450_REG_INT1,
430935ff5fSRobin Gong .range_max = PCA9450_REG_PWRON_STAT,
440935ff5fSRobin Gong };
450935ff5fSRobin Gong
460935ff5fSRobin Gong static const struct regmap_access_table pca9450_volatile_regs = {
470935ff5fSRobin Gong .yes_ranges = &pca9450_status_range,
480935ff5fSRobin Gong .n_yes_ranges = 1,
490935ff5fSRobin Gong };
500935ff5fSRobin Gong
510935ff5fSRobin Gong static const struct regmap_config pca9450_regmap_config = {
520935ff5fSRobin Gong .reg_bits = 8,
530935ff5fSRobin Gong .val_bits = 8,
540935ff5fSRobin Gong .volatile_table = &pca9450_volatile_regs,
550935ff5fSRobin Gong .max_register = PCA9450_MAX_REGISTER - 1,
560935ff5fSRobin Gong .cache_type = REGCACHE_RBTREE,
570935ff5fSRobin Gong };
580935ff5fSRobin Gong
590935ff5fSRobin Gong /*
600935ff5fSRobin Gong * BUCK1/2/3
610935ff5fSRobin Gong * BUCK1RAM[1:0] BUCK1 DVS ramp rate setting
620935ff5fSRobin Gong * 00: 25mV/1usec
630935ff5fSRobin Gong * 01: 25mV/2usec
640935ff5fSRobin Gong * 10: 25mV/4usec
650935ff5fSRobin Gong * 11: 25mV/8usec
660935ff5fSRobin Gong */
674c4fce17SAxel Lin static const unsigned int pca9450_dvs_buck_ramp_table[] = {
684c4fce17SAxel Lin 25000, 12500, 6250, 3125
694c4fce17SAxel Lin };
700935ff5fSRobin Gong
7172f2746cSRikard Falkeborn static const struct regulator_ops pca9450_dvs_buck_regulator_ops = {
720935ff5fSRobin Gong .enable = regulator_enable_regmap,
730935ff5fSRobin Gong .disable = regulator_disable_regmap,
740935ff5fSRobin Gong .is_enabled = regulator_is_enabled_regmap,
750935ff5fSRobin Gong .list_voltage = regulator_list_voltage_linear_range,
760935ff5fSRobin Gong .set_voltage_sel = regulator_set_voltage_sel_regmap,
770935ff5fSRobin Gong .get_voltage_sel = regulator_get_voltage_sel_regmap,
780935ff5fSRobin Gong .set_voltage_time_sel = regulator_set_voltage_time_sel,
794c4fce17SAxel Lin .set_ramp_delay = regulator_set_ramp_delay_regmap,
800935ff5fSRobin Gong };
810935ff5fSRobin Gong
8272f2746cSRikard Falkeborn static const struct regulator_ops pca9450_buck_regulator_ops = {
830935ff5fSRobin Gong .enable = regulator_enable_regmap,
840935ff5fSRobin Gong .disable = regulator_disable_regmap,
850935ff5fSRobin Gong .is_enabled = regulator_is_enabled_regmap,
860935ff5fSRobin Gong .list_voltage = regulator_list_voltage_linear_range,
870935ff5fSRobin Gong .set_voltage_sel = regulator_set_voltage_sel_regmap,
880935ff5fSRobin Gong .get_voltage_sel = regulator_get_voltage_sel_regmap,
890935ff5fSRobin Gong .set_voltage_time_sel = regulator_set_voltage_time_sel,
900935ff5fSRobin Gong };
910935ff5fSRobin Gong
9272f2746cSRikard Falkeborn static const struct regulator_ops pca9450_ldo_regulator_ops = {
930935ff5fSRobin Gong .enable = regulator_enable_regmap,
940935ff5fSRobin Gong .disable = regulator_disable_regmap,
950935ff5fSRobin Gong .is_enabled = regulator_is_enabled_regmap,
960935ff5fSRobin Gong .list_voltage = regulator_list_voltage_linear_range,
970935ff5fSRobin Gong .set_voltage_sel = regulator_set_voltage_sel_regmap,
980935ff5fSRobin Gong .get_voltage_sel = regulator_get_voltage_sel_regmap,
990935ff5fSRobin Gong };
1000935ff5fSRobin Gong
1010935ff5fSRobin Gong /*
1020935ff5fSRobin Gong * BUCK1/2/3
1030935ff5fSRobin Gong * 0.60 to 2.1875V (12.5mV step)
1040935ff5fSRobin Gong */
1050935ff5fSRobin Gong static const struct linear_range pca9450_dvs_buck_volts[] = {
1060935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(600000, 0x00, 0x7F, 12500),
1070935ff5fSRobin Gong };
1080935ff5fSRobin Gong
1090935ff5fSRobin Gong /*
1100935ff5fSRobin Gong * BUCK4/5/6
1110935ff5fSRobin Gong * 0.6V to 3.4V (25mV step)
1120935ff5fSRobin Gong */
1130935ff5fSRobin Gong static const struct linear_range pca9450_buck_volts[] = {
1140935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(600000, 0x00, 0x70, 25000),
1150935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(3400000, 0x71, 0x7F, 0),
1160935ff5fSRobin Gong };
1170935ff5fSRobin Gong
1180935ff5fSRobin Gong /*
1190935ff5fSRobin Gong * LDO1
1200935ff5fSRobin Gong * 1.6 to 3.3V ()
1210935ff5fSRobin Gong */
1220935ff5fSRobin Gong static const struct linear_range pca9450_ldo1_volts[] = {
1230935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
1240935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(3000000, 0x04, 0x07, 100000),
1250935ff5fSRobin Gong };
1260935ff5fSRobin Gong
1270935ff5fSRobin Gong /*
1280935ff5fSRobin Gong * LDO2
1290935ff5fSRobin Gong * 0.8 to 1.15V (50mV step)
1300935ff5fSRobin Gong */
1310935ff5fSRobin Gong static const struct linear_range pca9450_ldo2_volts[] = {
1320935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(800000, 0x00, 0x07, 50000),
1330935ff5fSRobin Gong };
1340935ff5fSRobin Gong
1350935ff5fSRobin Gong /*
1360935ff5fSRobin Gong * LDO3/4
1370935ff5fSRobin Gong * 0.8 to 3.3V (100mV step)
1380935ff5fSRobin Gong */
1390935ff5fSRobin Gong static const struct linear_range pca9450_ldo34_volts[] = {
1400935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(800000, 0x00, 0x19, 100000),
1410935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(3300000, 0x1A, 0x1F, 0),
1420935ff5fSRobin Gong };
1430935ff5fSRobin Gong
1440935ff5fSRobin Gong /*
1450935ff5fSRobin Gong * LDO5
1460935ff5fSRobin Gong * 1.8 to 3.3V (100mV step)
1470935ff5fSRobin Gong */
1480935ff5fSRobin Gong static const struct linear_range pca9450_ldo5_volts[] = {
1490935ff5fSRobin Gong REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
1500935ff5fSRobin Gong };
1510935ff5fSRobin Gong
buck_set_dvs(const struct regulator_desc * desc,struct device_node * np,struct regmap * regmap,char * prop,unsigned int reg,unsigned int mask)1520935ff5fSRobin Gong static int buck_set_dvs(const struct regulator_desc *desc,
1530935ff5fSRobin Gong struct device_node *np, struct regmap *regmap,
1540935ff5fSRobin Gong char *prop, unsigned int reg, unsigned int mask)
1550935ff5fSRobin Gong {
1560935ff5fSRobin Gong int ret, i;
1570935ff5fSRobin Gong uint32_t uv;
1580935ff5fSRobin Gong
1590935ff5fSRobin Gong ret = of_property_read_u32(np, prop, &uv);
1600935ff5fSRobin Gong if (ret == -EINVAL)
1610935ff5fSRobin Gong return 0;
1620935ff5fSRobin Gong else if (ret)
1630935ff5fSRobin Gong return ret;
1640935ff5fSRobin Gong
1650935ff5fSRobin Gong for (i = 0; i < desc->n_voltages; i++) {
1660935ff5fSRobin Gong ret = regulator_desc_list_voltage_linear_range(desc, i);
1670935ff5fSRobin Gong if (ret < 0)
1680935ff5fSRobin Gong continue;
1690935ff5fSRobin Gong if (ret == uv) {
1700935ff5fSRobin Gong i <<= ffs(desc->vsel_mask) - 1;
1710935ff5fSRobin Gong ret = regmap_update_bits(regmap, reg, mask, i);
1720935ff5fSRobin Gong break;
1730935ff5fSRobin Gong }
1740935ff5fSRobin Gong }
1750935ff5fSRobin Gong
17620078e3bSRickard x Andersson if (ret == 0) {
17720078e3bSRickard x Andersson struct pca9450_regulator_desc *regulator = container_of(desc,
17820078e3bSRickard x Andersson struct pca9450_regulator_desc, desc);
17920078e3bSRickard x Andersson
18020078e3bSRickard x Andersson /* Enable DVS control through PMIC_STBY_REQ for this BUCK */
18120078e3bSRickard x Andersson ret = regmap_update_bits(regmap, regulator->desc.enable_reg,
18220078e3bSRickard x Andersson BUCK1_DVS_CTRL, BUCK1_DVS_CTRL);
18320078e3bSRickard x Andersson }
1840935ff5fSRobin Gong return ret;
1850935ff5fSRobin Gong }
1860935ff5fSRobin Gong
pca9450_set_dvs_levels(struct device_node * np,const struct regulator_desc * desc,struct regulator_config * cfg)1870935ff5fSRobin Gong static int pca9450_set_dvs_levels(struct device_node *np,
1880935ff5fSRobin Gong const struct regulator_desc *desc,
1890935ff5fSRobin Gong struct regulator_config *cfg)
1900935ff5fSRobin Gong {
1910935ff5fSRobin Gong struct pca9450_regulator_desc *data = container_of(desc,
1920935ff5fSRobin Gong struct pca9450_regulator_desc, desc);
1930935ff5fSRobin Gong const struct pc9450_dvs_config *dvs = &data->dvs;
1940935ff5fSRobin Gong unsigned int reg, mask;
1950935ff5fSRobin Gong char *prop;
1960935ff5fSRobin Gong int i, ret = 0;
1970935ff5fSRobin Gong
1980935ff5fSRobin Gong for (i = 0; i < PCA9450_DVS_LEVEL_MAX; i++) {
1990935ff5fSRobin Gong switch (i) {
2000935ff5fSRobin Gong case PCA9450_DVS_LEVEL_RUN:
2010935ff5fSRobin Gong prop = "nxp,dvs-run-voltage";
2020935ff5fSRobin Gong reg = dvs->run_reg;
2030935ff5fSRobin Gong mask = dvs->run_mask;
2040935ff5fSRobin Gong break;
2050935ff5fSRobin Gong case PCA9450_DVS_LEVEL_STANDBY:
2060935ff5fSRobin Gong prop = "nxp,dvs-standby-voltage";
2070935ff5fSRobin Gong reg = dvs->standby_reg;
2080935ff5fSRobin Gong mask = dvs->standby_mask;
2090935ff5fSRobin Gong break;
2100935ff5fSRobin Gong default:
2110935ff5fSRobin Gong return -EINVAL;
2120935ff5fSRobin Gong }
2130935ff5fSRobin Gong
2140935ff5fSRobin Gong ret = buck_set_dvs(desc, np, cfg->regmap, prop, reg, mask);
2150935ff5fSRobin Gong if (ret)
2160935ff5fSRobin Gong break;
2170935ff5fSRobin Gong }
2180935ff5fSRobin Gong
2190935ff5fSRobin Gong return ret;
2200935ff5fSRobin Gong }
2210935ff5fSRobin Gong
2220935ff5fSRobin Gong static const struct pca9450_regulator_desc pca9450a_regulators[] = {
2230935ff5fSRobin Gong {
2240935ff5fSRobin Gong .desc = {
2250935ff5fSRobin Gong .name = "buck1",
2260935ff5fSRobin Gong .of_match = of_match_ptr("BUCK1"),
2270935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
2280935ff5fSRobin Gong .id = PCA9450_BUCK1,
2290935ff5fSRobin Gong .ops = &pca9450_dvs_buck_regulator_ops,
2300935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
2310935ff5fSRobin Gong .n_voltages = PCA9450_BUCK1_VOLTAGE_NUM,
2320935ff5fSRobin Gong .linear_ranges = pca9450_dvs_buck_volts,
2330935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
2340935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK1OUT_DVS0,
2350935ff5fSRobin Gong .vsel_mask = BUCK1OUT_DVS0_MASK,
2360935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK1CTRL,
2370935ff5fSRobin Gong .enable_mask = BUCK1_ENMODE_MASK,
2384c4fce17SAxel Lin .ramp_reg = PCA9450_REG_BUCK1CTRL,
2394c4fce17SAxel Lin .ramp_mask = BUCK1_RAMP_MASK,
2404c4fce17SAxel Lin .ramp_delay_table = pca9450_dvs_buck_ramp_table,
2414c4fce17SAxel Lin .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
2420935ff5fSRobin Gong .owner = THIS_MODULE,
2430935ff5fSRobin Gong .of_parse_cb = pca9450_set_dvs_levels,
2440935ff5fSRobin Gong },
2450935ff5fSRobin Gong .dvs = {
2460935ff5fSRobin Gong .run_reg = PCA9450_REG_BUCK1OUT_DVS0,
2470935ff5fSRobin Gong .run_mask = BUCK1OUT_DVS0_MASK,
2480935ff5fSRobin Gong .standby_reg = PCA9450_REG_BUCK1OUT_DVS1,
2490935ff5fSRobin Gong .standby_mask = BUCK1OUT_DVS1_MASK,
2500935ff5fSRobin Gong },
2510935ff5fSRobin Gong },
2520935ff5fSRobin Gong {
2530935ff5fSRobin Gong .desc = {
2540935ff5fSRobin Gong .name = "buck2",
2550935ff5fSRobin Gong .of_match = of_match_ptr("BUCK2"),
2560935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
2570935ff5fSRobin Gong .id = PCA9450_BUCK2,
2580935ff5fSRobin Gong .ops = &pca9450_dvs_buck_regulator_ops,
2590935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
2600935ff5fSRobin Gong .n_voltages = PCA9450_BUCK2_VOLTAGE_NUM,
2610935ff5fSRobin Gong .linear_ranges = pca9450_dvs_buck_volts,
2620935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
2630935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK2OUT_DVS0,
2640935ff5fSRobin Gong .vsel_mask = BUCK2OUT_DVS0_MASK,
2650935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK2CTRL,
266*d67dada3SAlexander Stein .enable_mask = BUCK2_ENMODE_MASK,
2674c4fce17SAxel Lin .ramp_reg = PCA9450_REG_BUCK2CTRL,
2684c4fce17SAxel Lin .ramp_mask = BUCK2_RAMP_MASK,
2694c4fce17SAxel Lin .ramp_delay_table = pca9450_dvs_buck_ramp_table,
2704c4fce17SAxel Lin .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
2710935ff5fSRobin Gong .owner = THIS_MODULE,
2720935ff5fSRobin Gong .of_parse_cb = pca9450_set_dvs_levels,
2730935ff5fSRobin Gong },
2740935ff5fSRobin Gong .dvs = {
2750935ff5fSRobin Gong .run_reg = PCA9450_REG_BUCK2OUT_DVS0,
2760935ff5fSRobin Gong .run_mask = BUCK2OUT_DVS0_MASK,
2770935ff5fSRobin Gong .standby_reg = PCA9450_REG_BUCK2OUT_DVS1,
2780935ff5fSRobin Gong .standby_mask = BUCK2OUT_DVS1_MASK,
2790935ff5fSRobin Gong },
2800935ff5fSRobin Gong },
2810935ff5fSRobin Gong {
2820935ff5fSRobin Gong .desc = {
2830935ff5fSRobin Gong .name = "buck3",
2840935ff5fSRobin Gong .of_match = of_match_ptr("BUCK3"),
2850935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
2860935ff5fSRobin Gong .id = PCA9450_BUCK3,
2870935ff5fSRobin Gong .ops = &pca9450_dvs_buck_regulator_ops,
2880935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
2890935ff5fSRobin Gong .n_voltages = PCA9450_BUCK3_VOLTAGE_NUM,
2900935ff5fSRobin Gong .linear_ranges = pca9450_dvs_buck_volts,
2910935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
2920935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK3OUT_DVS0,
2930935ff5fSRobin Gong .vsel_mask = BUCK3OUT_DVS0_MASK,
2940935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK3CTRL,
2950935ff5fSRobin Gong .enable_mask = BUCK3_ENMODE_MASK,
2964c4fce17SAxel Lin .ramp_reg = PCA9450_REG_BUCK3CTRL,
2974c4fce17SAxel Lin .ramp_mask = BUCK3_RAMP_MASK,
2984c4fce17SAxel Lin .ramp_delay_table = pca9450_dvs_buck_ramp_table,
2994c4fce17SAxel Lin .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
3000935ff5fSRobin Gong .owner = THIS_MODULE,
3010935ff5fSRobin Gong .of_parse_cb = pca9450_set_dvs_levels,
3020935ff5fSRobin Gong },
3030935ff5fSRobin Gong .dvs = {
3040935ff5fSRobin Gong .run_reg = PCA9450_REG_BUCK3OUT_DVS0,
3050935ff5fSRobin Gong .run_mask = BUCK3OUT_DVS0_MASK,
3060935ff5fSRobin Gong .standby_reg = PCA9450_REG_BUCK3OUT_DVS1,
3070935ff5fSRobin Gong .standby_mask = BUCK3OUT_DVS1_MASK,
3080935ff5fSRobin Gong },
3090935ff5fSRobin Gong },
3100935ff5fSRobin Gong {
3110935ff5fSRobin Gong .desc = {
3120935ff5fSRobin Gong .name = "buck4",
3130935ff5fSRobin Gong .of_match = of_match_ptr("BUCK4"),
3140935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
3150935ff5fSRobin Gong .id = PCA9450_BUCK4,
3160935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
3170935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
3180935ff5fSRobin Gong .n_voltages = PCA9450_BUCK4_VOLTAGE_NUM,
3190935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
3200935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
3210935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK4OUT,
3220935ff5fSRobin Gong .vsel_mask = BUCK4OUT_MASK,
3230935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK4CTRL,
3240935ff5fSRobin Gong .enable_mask = BUCK4_ENMODE_MASK,
3250935ff5fSRobin Gong .owner = THIS_MODULE,
3260935ff5fSRobin Gong },
3270935ff5fSRobin Gong },
3280935ff5fSRobin Gong {
3290935ff5fSRobin Gong .desc = {
3300935ff5fSRobin Gong .name = "buck5",
3310935ff5fSRobin Gong .of_match = of_match_ptr("BUCK5"),
3320935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
3330935ff5fSRobin Gong .id = PCA9450_BUCK5,
3340935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
3350935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
3360935ff5fSRobin Gong .n_voltages = PCA9450_BUCK5_VOLTAGE_NUM,
3370935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
3380935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
3390935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK5OUT,
3400935ff5fSRobin Gong .vsel_mask = BUCK5OUT_MASK,
3410935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK5CTRL,
3420935ff5fSRobin Gong .enable_mask = BUCK5_ENMODE_MASK,
3430935ff5fSRobin Gong .owner = THIS_MODULE,
3440935ff5fSRobin Gong },
3450935ff5fSRobin Gong },
3460935ff5fSRobin Gong {
3470935ff5fSRobin Gong .desc = {
3480935ff5fSRobin Gong .name = "buck6",
3490935ff5fSRobin Gong .of_match = of_match_ptr("BUCK6"),
3500935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
3510935ff5fSRobin Gong .id = PCA9450_BUCK6,
3520935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
3530935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
3540935ff5fSRobin Gong .n_voltages = PCA9450_BUCK6_VOLTAGE_NUM,
3550935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
3560935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
3570935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK6OUT,
3580935ff5fSRobin Gong .vsel_mask = BUCK6OUT_MASK,
3590935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK6CTRL,
3600935ff5fSRobin Gong .enable_mask = BUCK6_ENMODE_MASK,
3610935ff5fSRobin Gong .owner = THIS_MODULE,
3620935ff5fSRobin Gong },
3630935ff5fSRobin Gong },
3640935ff5fSRobin Gong {
3650935ff5fSRobin Gong .desc = {
3660935ff5fSRobin Gong .name = "ldo1",
3670935ff5fSRobin Gong .of_match = of_match_ptr("LDO1"),
3680935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
3690935ff5fSRobin Gong .id = PCA9450_LDO1,
3700935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
3710935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
3720935ff5fSRobin Gong .n_voltages = PCA9450_LDO1_VOLTAGE_NUM,
3730935ff5fSRobin Gong .linear_ranges = pca9450_ldo1_volts,
3740935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo1_volts),
3750935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO1CTRL,
3760935ff5fSRobin Gong .vsel_mask = LDO1OUT_MASK,
3770935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO1CTRL,
3780935ff5fSRobin Gong .enable_mask = LDO1_EN_MASK,
3790935ff5fSRobin Gong .owner = THIS_MODULE,
3800935ff5fSRobin Gong },
3810935ff5fSRobin Gong },
3820935ff5fSRobin Gong {
3830935ff5fSRobin Gong .desc = {
3840935ff5fSRobin Gong .name = "ldo2",
3850935ff5fSRobin Gong .of_match = of_match_ptr("LDO2"),
3860935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
3870935ff5fSRobin Gong .id = PCA9450_LDO2,
3880935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
3890935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
3900935ff5fSRobin Gong .n_voltages = PCA9450_LDO2_VOLTAGE_NUM,
3910935ff5fSRobin Gong .linear_ranges = pca9450_ldo2_volts,
3920935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo2_volts),
3930935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO2CTRL,
3940935ff5fSRobin Gong .vsel_mask = LDO2OUT_MASK,
3950935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO2CTRL,
3960935ff5fSRobin Gong .enable_mask = LDO2_EN_MASK,
3970935ff5fSRobin Gong .owner = THIS_MODULE,
3980935ff5fSRobin Gong },
3990935ff5fSRobin Gong },
4000935ff5fSRobin Gong {
4010935ff5fSRobin Gong .desc = {
4020935ff5fSRobin Gong .name = "ldo3",
4030935ff5fSRobin Gong .of_match = of_match_ptr("LDO3"),
4040935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
4050935ff5fSRobin Gong .id = PCA9450_LDO3,
4060935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
4070935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
4080935ff5fSRobin Gong .n_voltages = PCA9450_LDO3_VOLTAGE_NUM,
4090935ff5fSRobin Gong .linear_ranges = pca9450_ldo34_volts,
4100935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
4110935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO3CTRL,
4120935ff5fSRobin Gong .vsel_mask = LDO3OUT_MASK,
4130935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO3CTRL,
4140935ff5fSRobin Gong .enable_mask = LDO3_EN_MASK,
4150935ff5fSRobin Gong .owner = THIS_MODULE,
4160935ff5fSRobin Gong },
4170935ff5fSRobin Gong },
4180935ff5fSRobin Gong {
4190935ff5fSRobin Gong .desc = {
4200935ff5fSRobin Gong .name = "ldo4",
4210935ff5fSRobin Gong .of_match = of_match_ptr("LDO4"),
4220935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
4230935ff5fSRobin Gong .id = PCA9450_LDO4,
4240935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
4250935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
4260935ff5fSRobin Gong .n_voltages = PCA9450_LDO4_VOLTAGE_NUM,
4270935ff5fSRobin Gong .linear_ranges = pca9450_ldo34_volts,
4280935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
4290935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO4CTRL,
4300935ff5fSRobin Gong .vsel_mask = LDO4OUT_MASK,
4310935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO4CTRL,
4320935ff5fSRobin Gong .enable_mask = LDO4_EN_MASK,
4330935ff5fSRobin Gong .owner = THIS_MODULE,
4340935ff5fSRobin Gong },
4350935ff5fSRobin Gong },
4360935ff5fSRobin Gong {
4370935ff5fSRobin Gong .desc = {
4380935ff5fSRobin Gong .name = "ldo5",
4390935ff5fSRobin Gong .of_match = of_match_ptr("LDO5"),
4400935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
4410935ff5fSRobin Gong .id = PCA9450_LDO5,
4420935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
4430935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
4440935ff5fSRobin Gong .n_voltages = PCA9450_LDO5_VOLTAGE_NUM,
4450935ff5fSRobin Gong .linear_ranges = pca9450_ldo5_volts,
4460935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts),
4470935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO5CTRL_H,
4480935ff5fSRobin Gong .vsel_mask = LDO5HOUT_MASK,
4490935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO5CTRL_H,
4500935ff5fSRobin Gong .enable_mask = LDO5H_EN_MASK,
4510935ff5fSRobin Gong .owner = THIS_MODULE,
4520935ff5fSRobin Gong },
4530935ff5fSRobin Gong },
4540935ff5fSRobin Gong };
4550935ff5fSRobin Gong
4560935ff5fSRobin Gong /*
4570935ff5fSRobin Gong * Buck3 removed on PCA9450B and connected with Buck1 internal for dual phase
4580935ff5fSRobin Gong * on PCA9450C as no Buck3.
4590935ff5fSRobin Gong */
4600935ff5fSRobin Gong static const struct pca9450_regulator_desc pca9450bc_regulators[] = {
4610935ff5fSRobin Gong {
4620935ff5fSRobin Gong .desc = {
4630935ff5fSRobin Gong .name = "buck1",
4640935ff5fSRobin Gong .of_match = of_match_ptr("BUCK1"),
4650935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
4660935ff5fSRobin Gong .id = PCA9450_BUCK1,
4670935ff5fSRobin Gong .ops = &pca9450_dvs_buck_regulator_ops,
4680935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
4690935ff5fSRobin Gong .n_voltages = PCA9450_BUCK1_VOLTAGE_NUM,
4700935ff5fSRobin Gong .linear_ranges = pca9450_dvs_buck_volts,
4710935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
4720935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK1OUT_DVS0,
4730935ff5fSRobin Gong .vsel_mask = BUCK1OUT_DVS0_MASK,
4740935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK1CTRL,
4750935ff5fSRobin Gong .enable_mask = BUCK1_ENMODE_MASK,
4764c4fce17SAxel Lin .ramp_reg = PCA9450_REG_BUCK1CTRL,
4774c4fce17SAxel Lin .ramp_mask = BUCK1_RAMP_MASK,
4784c4fce17SAxel Lin .ramp_delay_table = pca9450_dvs_buck_ramp_table,
4794c4fce17SAxel Lin .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
4800935ff5fSRobin Gong .owner = THIS_MODULE,
4810935ff5fSRobin Gong .of_parse_cb = pca9450_set_dvs_levels,
4820935ff5fSRobin Gong },
4830935ff5fSRobin Gong .dvs = {
4840935ff5fSRobin Gong .run_reg = PCA9450_REG_BUCK1OUT_DVS0,
4850935ff5fSRobin Gong .run_mask = BUCK1OUT_DVS0_MASK,
4860935ff5fSRobin Gong .standby_reg = PCA9450_REG_BUCK1OUT_DVS1,
4870935ff5fSRobin Gong .standby_mask = BUCK1OUT_DVS1_MASK,
4880935ff5fSRobin Gong },
4890935ff5fSRobin Gong },
4900935ff5fSRobin Gong {
4910935ff5fSRobin Gong .desc = {
4920935ff5fSRobin Gong .name = "buck2",
4930935ff5fSRobin Gong .of_match = of_match_ptr("BUCK2"),
4940935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
4950935ff5fSRobin Gong .id = PCA9450_BUCK2,
4960935ff5fSRobin Gong .ops = &pca9450_dvs_buck_regulator_ops,
4970935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
4980935ff5fSRobin Gong .n_voltages = PCA9450_BUCK2_VOLTAGE_NUM,
4990935ff5fSRobin Gong .linear_ranges = pca9450_dvs_buck_volts,
5000935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_dvs_buck_volts),
5010935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK2OUT_DVS0,
5020935ff5fSRobin Gong .vsel_mask = BUCK2OUT_DVS0_MASK,
5030935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK2CTRL,
504*d67dada3SAlexander Stein .enable_mask = BUCK2_ENMODE_MASK,
5054c4fce17SAxel Lin .ramp_reg = PCA9450_REG_BUCK2CTRL,
5064c4fce17SAxel Lin .ramp_mask = BUCK2_RAMP_MASK,
5074c4fce17SAxel Lin .ramp_delay_table = pca9450_dvs_buck_ramp_table,
5084c4fce17SAxel Lin .n_ramp_values = ARRAY_SIZE(pca9450_dvs_buck_ramp_table),
5090935ff5fSRobin Gong .owner = THIS_MODULE,
5100935ff5fSRobin Gong .of_parse_cb = pca9450_set_dvs_levels,
5110935ff5fSRobin Gong },
5120935ff5fSRobin Gong .dvs = {
5130935ff5fSRobin Gong .run_reg = PCA9450_REG_BUCK2OUT_DVS0,
5140935ff5fSRobin Gong .run_mask = BUCK2OUT_DVS0_MASK,
5150935ff5fSRobin Gong .standby_reg = PCA9450_REG_BUCK2OUT_DVS1,
5160935ff5fSRobin Gong .standby_mask = BUCK2OUT_DVS1_MASK,
5170935ff5fSRobin Gong },
5180935ff5fSRobin Gong },
5190935ff5fSRobin Gong {
5200935ff5fSRobin Gong .desc = {
5210935ff5fSRobin Gong .name = "buck4",
5220935ff5fSRobin Gong .of_match = of_match_ptr("BUCK4"),
5230935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
5240935ff5fSRobin Gong .id = PCA9450_BUCK4,
5250935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
5260935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
5270935ff5fSRobin Gong .n_voltages = PCA9450_BUCK4_VOLTAGE_NUM,
5280935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
5290935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
5300935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK4OUT,
5310935ff5fSRobin Gong .vsel_mask = BUCK4OUT_MASK,
5320935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK4CTRL,
5330935ff5fSRobin Gong .enable_mask = BUCK4_ENMODE_MASK,
5340935ff5fSRobin Gong .owner = THIS_MODULE,
5350935ff5fSRobin Gong },
5360935ff5fSRobin Gong },
5370935ff5fSRobin Gong {
5380935ff5fSRobin Gong .desc = {
5390935ff5fSRobin Gong .name = "buck5",
5400935ff5fSRobin Gong .of_match = of_match_ptr("BUCK5"),
5410935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
5420935ff5fSRobin Gong .id = PCA9450_BUCK5,
5430935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
5440935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
5450935ff5fSRobin Gong .n_voltages = PCA9450_BUCK5_VOLTAGE_NUM,
5460935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
5470935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
5480935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK5OUT,
5490935ff5fSRobin Gong .vsel_mask = BUCK5OUT_MASK,
5500935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK5CTRL,
5510935ff5fSRobin Gong .enable_mask = BUCK5_ENMODE_MASK,
5520935ff5fSRobin Gong .owner = THIS_MODULE,
5530935ff5fSRobin Gong },
5540935ff5fSRobin Gong },
5550935ff5fSRobin Gong {
5560935ff5fSRobin Gong .desc = {
5570935ff5fSRobin Gong .name = "buck6",
5580935ff5fSRobin Gong .of_match = of_match_ptr("BUCK6"),
5590935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
5600935ff5fSRobin Gong .id = PCA9450_BUCK6,
5610935ff5fSRobin Gong .ops = &pca9450_buck_regulator_ops,
5620935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
5630935ff5fSRobin Gong .n_voltages = PCA9450_BUCK6_VOLTAGE_NUM,
5640935ff5fSRobin Gong .linear_ranges = pca9450_buck_volts,
5650935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_buck_volts),
5660935ff5fSRobin Gong .vsel_reg = PCA9450_REG_BUCK6OUT,
5670935ff5fSRobin Gong .vsel_mask = BUCK6OUT_MASK,
5680935ff5fSRobin Gong .enable_reg = PCA9450_REG_BUCK6CTRL,
5690935ff5fSRobin Gong .enable_mask = BUCK6_ENMODE_MASK,
5700935ff5fSRobin Gong .owner = THIS_MODULE,
5710935ff5fSRobin Gong },
5720935ff5fSRobin Gong },
5730935ff5fSRobin Gong {
5740935ff5fSRobin Gong .desc = {
5750935ff5fSRobin Gong .name = "ldo1",
5760935ff5fSRobin Gong .of_match = of_match_ptr("LDO1"),
5770935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
5780935ff5fSRobin Gong .id = PCA9450_LDO1,
5790935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
5800935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
5810935ff5fSRobin Gong .n_voltages = PCA9450_LDO1_VOLTAGE_NUM,
5820935ff5fSRobin Gong .linear_ranges = pca9450_ldo1_volts,
5830935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo1_volts),
5840935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO1CTRL,
5850935ff5fSRobin Gong .vsel_mask = LDO1OUT_MASK,
5860935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO1CTRL,
5870935ff5fSRobin Gong .enable_mask = LDO1_EN_MASK,
5880935ff5fSRobin Gong .owner = THIS_MODULE,
5890935ff5fSRobin Gong },
5900935ff5fSRobin Gong },
5910935ff5fSRobin Gong {
5920935ff5fSRobin Gong .desc = {
5930935ff5fSRobin Gong .name = "ldo2",
5940935ff5fSRobin Gong .of_match = of_match_ptr("LDO2"),
5950935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
5960935ff5fSRobin Gong .id = PCA9450_LDO2,
5970935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
5980935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
5990935ff5fSRobin Gong .n_voltages = PCA9450_LDO2_VOLTAGE_NUM,
6000935ff5fSRobin Gong .linear_ranges = pca9450_ldo2_volts,
6010935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo2_volts),
6020935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO2CTRL,
6030935ff5fSRobin Gong .vsel_mask = LDO2OUT_MASK,
6040935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO2CTRL,
6050935ff5fSRobin Gong .enable_mask = LDO2_EN_MASK,
6060935ff5fSRobin Gong .owner = THIS_MODULE,
6070935ff5fSRobin Gong },
6080935ff5fSRobin Gong },
6090935ff5fSRobin Gong {
6100935ff5fSRobin Gong .desc = {
6110935ff5fSRobin Gong .name = "ldo3",
6120935ff5fSRobin Gong .of_match = of_match_ptr("LDO3"),
6130935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
6140935ff5fSRobin Gong .id = PCA9450_LDO3,
6150935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
6160935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
6170935ff5fSRobin Gong .n_voltages = PCA9450_LDO3_VOLTAGE_NUM,
6180935ff5fSRobin Gong .linear_ranges = pca9450_ldo34_volts,
6190935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
6200935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO3CTRL,
6210935ff5fSRobin Gong .vsel_mask = LDO3OUT_MASK,
6220935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO3CTRL,
6230935ff5fSRobin Gong .enable_mask = LDO3_EN_MASK,
6240935ff5fSRobin Gong .owner = THIS_MODULE,
6250935ff5fSRobin Gong },
6260935ff5fSRobin Gong },
6270935ff5fSRobin Gong {
6280935ff5fSRobin Gong .desc = {
6290935ff5fSRobin Gong .name = "ldo4",
6300935ff5fSRobin Gong .of_match = of_match_ptr("LDO4"),
6310935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
6320935ff5fSRobin Gong .id = PCA9450_LDO4,
6330935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
6340935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
6350935ff5fSRobin Gong .n_voltages = PCA9450_LDO4_VOLTAGE_NUM,
6360935ff5fSRobin Gong .linear_ranges = pca9450_ldo34_volts,
6370935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo34_volts),
6380935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO4CTRL,
6390935ff5fSRobin Gong .vsel_mask = LDO4OUT_MASK,
6400935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO4CTRL,
6410935ff5fSRobin Gong .enable_mask = LDO4_EN_MASK,
6420935ff5fSRobin Gong .owner = THIS_MODULE,
6430935ff5fSRobin Gong },
6440935ff5fSRobin Gong },
6450935ff5fSRobin Gong {
6460935ff5fSRobin Gong .desc = {
6470935ff5fSRobin Gong .name = "ldo5",
6480935ff5fSRobin Gong .of_match = of_match_ptr("LDO5"),
6490935ff5fSRobin Gong .regulators_node = of_match_ptr("regulators"),
6500935ff5fSRobin Gong .id = PCA9450_LDO5,
6510935ff5fSRobin Gong .ops = &pca9450_ldo_regulator_ops,
6520935ff5fSRobin Gong .type = REGULATOR_VOLTAGE,
6530935ff5fSRobin Gong .n_voltages = PCA9450_LDO5_VOLTAGE_NUM,
6540935ff5fSRobin Gong .linear_ranges = pca9450_ldo5_volts,
6550935ff5fSRobin Gong .n_linear_ranges = ARRAY_SIZE(pca9450_ldo5_volts),
6560935ff5fSRobin Gong .vsel_reg = PCA9450_REG_LDO5CTRL_H,
6570935ff5fSRobin Gong .vsel_mask = LDO5HOUT_MASK,
6580935ff5fSRobin Gong .enable_reg = PCA9450_REG_LDO5CTRL_H,
6590935ff5fSRobin Gong .enable_mask = LDO5H_EN_MASK,
6600935ff5fSRobin Gong .owner = THIS_MODULE,
6610935ff5fSRobin Gong },
6620935ff5fSRobin Gong },
6630935ff5fSRobin Gong };
6640935ff5fSRobin Gong
pca9450_irq_handler(int irq,void * data)6650935ff5fSRobin Gong static irqreturn_t pca9450_irq_handler(int irq, void *data)
6660935ff5fSRobin Gong {
6670935ff5fSRobin Gong struct pca9450 *pca9450 = data;
6680935ff5fSRobin Gong struct regmap *regmap = pca9450->regmap;
6690935ff5fSRobin Gong unsigned int status;
6700935ff5fSRobin Gong int ret;
6710935ff5fSRobin Gong
6720935ff5fSRobin Gong ret = regmap_read(regmap, PCA9450_REG_INT1, &status);
6730935ff5fSRobin Gong if (ret < 0) {
6740935ff5fSRobin Gong dev_err(pca9450->dev,
6750935ff5fSRobin Gong "Failed to read INT1(%d)\n", ret);
6760935ff5fSRobin Gong return IRQ_NONE;
6770935ff5fSRobin Gong }
6780935ff5fSRobin Gong
6790935ff5fSRobin Gong if (status & IRQ_PWRON)
6800935ff5fSRobin Gong dev_warn(pca9450->dev, "PWRON interrupt.\n");
6810935ff5fSRobin Gong
6820935ff5fSRobin Gong if (status & IRQ_WDOGB)
6830935ff5fSRobin Gong dev_warn(pca9450->dev, "WDOGB interrupt.\n");
6840935ff5fSRobin Gong
6850935ff5fSRobin Gong if (status & IRQ_VR_FLT1)
6860935ff5fSRobin Gong dev_warn(pca9450->dev, "VRFLT1 interrupt.\n");
6870935ff5fSRobin Gong
6880935ff5fSRobin Gong if (status & IRQ_VR_FLT2)
6890935ff5fSRobin Gong dev_warn(pca9450->dev, "VRFLT2 interrupt.\n");
6900935ff5fSRobin Gong
6910935ff5fSRobin Gong if (status & IRQ_LOWVSYS)
6920935ff5fSRobin Gong dev_warn(pca9450->dev, "LOWVSYS interrupt.\n");
6930935ff5fSRobin Gong
6940935ff5fSRobin Gong if (status & IRQ_THERM_105)
6950935ff5fSRobin Gong dev_warn(pca9450->dev, "IRQ_THERM_105 interrupt.\n");
6960935ff5fSRobin Gong
6970935ff5fSRobin Gong if (status & IRQ_THERM_125)
6980935ff5fSRobin Gong dev_warn(pca9450->dev, "IRQ_THERM_125 interrupt.\n");
6990935ff5fSRobin Gong
7000935ff5fSRobin Gong return IRQ_HANDLED;
7010935ff5fSRobin Gong }
7020935ff5fSRobin Gong
pca9450_i2c_probe(struct i2c_client * i2c)703ed56fa6eSUwe Kleine-König static int pca9450_i2c_probe(struct i2c_client *i2c)
7040935ff5fSRobin Gong {
7050935ff5fSRobin Gong enum pca9450_chip_type type = (unsigned int)(uintptr_t)
7060935ff5fSRobin Gong of_device_get_match_data(&i2c->dev);
7070935ff5fSRobin Gong const struct pca9450_regulator_desc *regulator_desc;
7080935ff5fSRobin Gong struct regulator_config config = { };
7090935ff5fSRobin Gong struct pca9450 *pca9450;
7100935ff5fSRobin Gong unsigned int device_id, i;
7112364a64dSRickard x Andersson unsigned int reset_ctrl;
7120935ff5fSRobin Gong int ret;
7130935ff5fSRobin Gong
7140935ff5fSRobin Gong if (!i2c->irq) {
7150935ff5fSRobin Gong dev_err(&i2c->dev, "No IRQ configured?\n");
7160935ff5fSRobin Gong return -EINVAL;
7170935ff5fSRobin Gong }
7180935ff5fSRobin Gong
7190935ff5fSRobin Gong pca9450 = devm_kzalloc(&i2c->dev, sizeof(struct pca9450), GFP_KERNEL);
7200935ff5fSRobin Gong if (!pca9450)
7210935ff5fSRobin Gong return -ENOMEM;
7220935ff5fSRobin Gong
7230935ff5fSRobin Gong switch (type) {
7240935ff5fSRobin Gong case PCA9450_TYPE_PCA9450A:
7250935ff5fSRobin Gong regulator_desc = pca9450a_regulators;
7260935ff5fSRobin Gong pca9450->rcnt = ARRAY_SIZE(pca9450a_regulators);
7270935ff5fSRobin Gong break;
7280935ff5fSRobin Gong case PCA9450_TYPE_PCA9450BC:
7290935ff5fSRobin Gong regulator_desc = pca9450bc_regulators;
7300935ff5fSRobin Gong pca9450->rcnt = ARRAY_SIZE(pca9450bc_regulators);
7310935ff5fSRobin Gong break;
7320935ff5fSRobin Gong default:
7330935ff5fSRobin Gong dev_err(&i2c->dev, "Unknown device type");
7340935ff5fSRobin Gong return -EINVAL;
7350935ff5fSRobin Gong }
7360935ff5fSRobin Gong
7370935ff5fSRobin Gong pca9450->irq = i2c->irq;
7380935ff5fSRobin Gong pca9450->type = type;
7390935ff5fSRobin Gong pca9450->dev = &i2c->dev;
7400935ff5fSRobin Gong
7410935ff5fSRobin Gong dev_set_drvdata(&i2c->dev, pca9450);
7420935ff5fSRobin Gong
7430935ff5fSRobin Gong pca9450->regmap = devm_regmap_init_i2c(i2c,
7440935ff5fSRobin Gong &pca9450_regmap_config);
7450935ff5fSRobin Gong if (IS_ERR(pca9450->regmap)) {
7460935ff5fSRobin Gong dev_err(&i2c->dev, "regmap initialization failed\n");
7470935ff5fSRobin Gong return PTR_ERR(pca9450->regmap);
7480935ff5fSRobin Gong }
7490935ff5fSRobin Gong
7500935ff5fSRobin Gong ret = regmap_read(pca9450->regmap, PCA9450_REG_DEV_ID, &device_id);
7510935ff5fSRobin Gong if (ret) {
7520935ff5fSRobin Gong dev_err(&i2c->dev, "Read device id error\n");
7530935ff5fSRobin Gong return ret;
7540935ff5fSRobin Gong }
7550935ff5fSRobin Gong
7560935ff5fSRobin Gong /* Check your board and dts for match the right pmic */
7570935ff5fSRobin Gong if (((device_id >> 4) != 0x1 && type == PCA9450_TYPE_PCA9450A) ||
7580935ff5fSRobin Gong ((device_id >> 4) != 0x3 && type == PCA9450_TYPE_PCA9450BC)) {
7590935ff5fSRobin Gong dev_err(&i2c->dev, "Device id(%x) mismatched\n",
7600935ff5fSRobin Gong device_id >> 4);
7610935ff5fSRobin Gong return -EINVAL;
7620935ff5fSRobin Gong }
7630935ff5fSRobin Gong
7640935ff5fSRobin Gong for (i = 0; i < pca9450->rcnt; i++) {
7650935ff5fSRobin Gong const struct regulator_desc *desc;
7660935ff5fSRobin Gong struct regulator_dev *rdev;
7670935ff5fSRobin Gong const struct pca9450_regulator_desc *r;
7680935ff5fSRobin Gong
7690935ff5fSRobin Gong r = ®ulator_desc[i];
7700935ff5fSRobin Gong desc = &r->desc;
7710935ff5fSRobin Gong
7720935ff5fSRobin Gong config.regmap = pca9450->regmap;
7730935ff5fSRobin Gong config.dev = pca9450->dev;
7740935ff5fSRobin Gong
7750935ff5fSRobin Gong rdev = devm_regulator_register(pca9450->dev, desc, &config);
7760935ff5fSRobin Gong if (IS_ERR(rdev)) {
7770935ff5fSRobin Gong ret = PTR_ERR(rdev);
7780935ff5fSRobin Gong dev_err(pca9450->dev,
7790935ff5fSRobin Gong "Failed to register regulator(%s): %d\n",
7800935ff5fSRobin Gong desc->name, ret);
7810935ff5fSRobin Gong return ret;
7820935ff5fSRobin Gong }
7830935ff5fSRobin Gong }
7840935ff5fSRobin Gong
7850935ff5fSRobin Gong ret = devm_request_threaded_irq(pca9450->dev, pca9450->irq, NULL,
7860935ff5fSRobin Gong pca9450_irq_handler,
7870935ff5fSRobin Gong (IRQF_TRIGGER_FALLING | IRQF_ONESHOT),
7880935ff5fSRobin Gong "pca9450-irq", pca9450);
7890935ff5fSRobin Gong if (ret != 0) {
7900935ff5fSRobin Gong dev_err(pca9450->dev, "Failed to request IRQ: %d\n",
7910935ff5fSRobin Gong pca9450->irq);
7920935ff5fSRobin Gong return ret;
7930935ff5fSRobin Gong }
7940935ff5fSRobin Gong /* Unmask all interrupt except PWRON/WDOG/RSVD */
7950935ff5fSRobin Gong ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_INT1_MSK,
7960935ff5fSRobin Gong IRQ_VR_FLT1 | IRQ_VR_FLT2 | IRQ_LOWVSYS |
7970935ff5fSRobin Gong IRQ_THERM_105 | IRQ_THERM_125,
7980935ff5fSRobin Gong IRQ_PWRON | IRQ_WDOGB | IRQ_RSVD);
7990935ff5fSRobin Gong if (ret) {
8000935ff5fSRobin Gong dev_err(&i2c->dev, "Unmask irq error\n");
8010935ff5fSRobin Gong return ret;
8020935ff5fSRobin Gong }
8030935ff5fSRobin Gong
80498b94b6eSFrieder Schrempf /* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
80598b94b6eSFrieder Schrempf ret = regmap_clear_bits(pca9450->regmap, PCA9450_REG_BUCK123_DVS,
80698b94b6eSFrieder Schrempf BUCK123_PRESET_EN);
80798b94b6eSFrieder Schrempf if (ret) {
80898b94b6eSFrieder Schrempf dev_err(&i2c->dev, "Failed to clear PRESET_EN bit: %d\n", ret);
80998b94b6eSFrieder Schrempf return ret;
81098b94b6eSFrieder Schrempf }
81198b94b6eSFrieder Schrempf
8122364a64dSRickard x Andersson if (of_property_read_bool(i2c->dev.of_node, "nxp,wdog_b-warm-reset"))
8132364a64dSRickard x Andersson reset_ctrl = WDOG_B_CFG_WARM;
8142364a64dSRickard x Andersson else
8152364a64dSRickard x Andersson reset_ctrl = WDOG_B_CFG_COLD_LDO12;
8162364a64dSRickard x Andersson
817f7684f5aSFrieder Schrempf /* Set reset behavior on assertion of WDOG_B signal */
818f7684f5aSFrieder Schrempf ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_RESET_CTRL,
8192364a64dSRickard x Andersson WDOG_B_CFG_MASK, reset_ctrl);
820f7684f5aSFrieder Schrempf if (ret) {
821f7684f5aSFrieder Schrempf dev_err(&i2c->dev, "Failed to set WDOG_B reset behavior\n");
822f7684f5aSFrieder Schrempf return ret;
823f7684f5aSFrieder Schrempf }
824f7684f5aSFrieder Schrempf
82562139f52SPer-Daniel Olsson if (of_property_read_bool(i2c->dev.of_node, "nxp,i2c-lt-enable")) {
82662139f52SPer-Daniel Olsson /* Enable I2C Level Translator */
82762139f52SPer-Daniel Olsson ret = regmap_update_bits(pca9450->regmap, PCA9450_REG_CONFIG2,
82862139f52SPer-Daniel Olsson I2C_LT_MASK, I2C_LT_ON_STANDBY_RUN);
82962139f52SPer-Daniel Olsson if (ret) {
83062139f52SPer-Daniel Olsson dev_err(&i2c->dev,
83162139f52SPer-Daniel Olsson "Failed to enable I2C level translator\n");
83262139f52SPer-Daniel Olsson return ret;
83362139f52SPer-Daniel Olsson }
83462139f52SPer-Daniel Olsson }
83562139f52SPer-Daniel Olsson
8368c67a11bSFrieder Schrempf /*
8378c67a11bSFrieder Schrempf * The driver uses the LDO5CTRL_H register to control the LDO5 regulator.
8388c67a11bSFrieder Schrempf * This is only valid if the SD_VSEL input of the PMIC is high. Let's
8398c67a11bSFrieder Schrempf * check if the pin is available as GPIO and set it to high.
8408c67a11bSFrieder Schrempf */
8418c67a11bSFrieder Schrempf pca9450->sd_vsel_gpio = gpiod_get_optional(pca9450->dev, "sd-vsel", GPIOD_OUT_HIGH);
8428c67a11bSFrieder Schrempf
8438c67a11bSFrieder Schrempf if (IS_ERR(pca9450->sd_vsel_gpio)) {
8448c67a11bSFrieder Schrempf dev_err(&i2c->dev, "Failed to get SD_VSEL GPIO\n");
8455fe5f17dSFrieder Schrempf return PTR_ERR(pca9450->sd_vsel_gpio);
8468c67a11bSFrieder Schrempf }
8478c67a11bSFrieder Schrempf
8480935ff5fSRobin Gong dev_info(&i2c->dev, "%s probed.\n",
8490935ff5fSRobin Gong type == PCA9450_TYPE_PCA9450A ? "pca9450a" : "pca9450bc");
8500935ff5fSRobin Gong
8510935ff5fSRobin Gong return 0;
8520935ff5fSRobin Gong }
8530935ff5fSRobin Gong
8540935ff5fSRobin Gong static const struct of_device_id pca9450_of_match[] = {
8550935ff5fSRobin Gong {
8560935ff5fSRobin Gong .compatible = "nxp,pca9450a",
8570935ff5fSRobin Gong .data = (void *)PCA9450_TYPE_PCA9450A,
8580935ff5fSRobin Gong },
8590935ff5fSRobin Gong {
8600935ff5fSRobin Gong .compatible = "nxp,pca9450b",
8610935ff5fSRobin Gong .data = (void *)PCA9450_TYPE_PCA9450BC,
8620935ff5fSRobin Gong },
8630935ff5fSRobin Gong {
8640935ff5fSRobin Gong .compatible = "nxp,pca9450c",
8650935ff5fSRobin Gong .data = (void *)PCA9450_TYPE_PCA9450BC,
8660935ff5fSRobin Gong },
8670935ff5fSRobin Gong { }
8680935ff5fSRobin Gong };
8690935ff5fSRobin Gong MODULE_DEVICE_TABLE(of, pca9450_of_match);
8700935ff5fSRobin Gong
8710935ff5fSRobin Gong static struct i2c_driver pca9450_i2c_driver = {
8720935ff5fSRobin Gong .driver = {
8730935ff5fSRobin Gong .name = "nxp-pca9450",
87467dc71c6SDouglas Anderson .probe_type = PROBE_PREFER_ASYNCHRONOUS,
8750935ff5fSRobin Gong .of_match_table = pca9450_of_match,
8760935ff5fSRobin Gong },
877964e1865SUwe Kleine-König .probe = pca9450_i2c_probe,
8780935ff5fSRobin Gong };
8790935ff5fSRobin Gong
8803bda44ffSAxel Lin module_i2c_driver(pca9450_i2c_driver);
8810935ff5fSRobin Gong
8820935ff5fSRobin Gong MODULE_AUTHOR("Robin Gong <yibin.gong@nxp.com>");
8830935ff5fSRobin Gong MODULE_DESCRIPTION("NXP PCA9450 Power Management IC driver");
8840935ff5fSRobin Gong MODULE_LICENSE("GPL");
885