diff --git a/sys/arch/evbarm/conf/GENERIC64 b/sys/arch/evbarm/conf/GENERIC64 index 8cd644aacccb..137408f4e893 100644 --- a/sys/arch/evbarm/conf/GENERIC64 +++ b/sys/arch/evbarm/conf/GENERIC64 @@ -1,5 +1,5 @@ # -# $NetBSD: GENERIC64,v 1.10 2018/05/03 01:17:04 jmcneill Exp $ +# $NetBSD: GENERIC64,v 1.11 2018/05/04 21:09:55 jmcneill Exp $ # # GENERIC ARM (aarch64) kernel # @@ -209,8 +209,8 @@ titemp* at iic? seeprom* at iic? as3722pmic* at iic? as3722reg* at as3722pmic? -axp806pmic* at iic? # AXP805/806 Power Management IC -axp806reg* at axp806pmic? +axppmic* at iic? # X-Powers AXP Power Management IC +axpreg* at axppmic? max77620pmic* at iic? pcf8563rtc* at iic? # PCF8563 RTC tcagpio* at iic? diff --git a/sys/arch/evbarm/conf/SUNXI b/sys/arch/evbarm/conf/SUNXI index f76824b3d9a4..f7fcaabadb8b 100644 --- a/sys/arch/evbarm/conf/SUNXI +++ b/sys/arch/evbarm/conf/SUNXI @@ -1,5 +1,5 @@ # -# $NetBSD: SUNXI,v 1.69 2018/05/03 01:17:04 jmcneill Exp $ +# $NetBSD: SUNXI,v 1.70 2018/05/04 21:09:55 jmcneill Exp $ # # Allwinner sunxi family # @@ -245,8 +245,8 @@ wskbd* at tcakp? console ? axp20x* at iic? # AXP209 Power Management IC axp20xreg* at axp20x? axp22x* at iic? # AXP221 Power Management IC -axp806pmic* at iic? # AXP805/806 Power Management IC -axp806reg* at axp806pmic? +axppmic* at iic? # X-Powers AXP Power Management IC +axpreg* at axppmic? sy8106a* at iic? # Silergy SY81061 regulator pcf8563rtc* at iic? # PCF8563 RTC seeprom* at iic? # AT24Cxx Serial EEPROM diff --git a/sys/dev/i2c/axp806.c b/sys/dev/i2c/axppmic.c similarity index 50% rename from sys/dev/i2c/axp806.c rename to sys/dev/i2c/axppmic.c index 4b9d348d49ec..1670e0c43a0c 100644 --- a/sys/dev/i2c/axp806.c +++ b/sys/dev/i2c/axppmic.c @@ -1,4 +1,4 @@ -/* $NetBSD: axp806.c,v 1.4 2018/05/04 20:26:50 jmcneill Exp $ */ +/* $NetBSD: axppmic.c,v 1.1 2018/05/04 21:09:55 jmcneill Exp $ */ /*- * Copyright (c) 2014-2018 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: axp806.c,v 1.4 2018/05/04 20:26:50 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.1 2018/05/04 21:09:55 jmcneill Exp $"); #include #include @@ -44,51 +44,14 @@ __KERNEL_RCSID(0, "$NetBSD: axp806.c,v 1.4 2018/05/04 20:26:50 jmcneill Exp $"); #include -#define AXP_STARTUP_SOURCE_REG 0x00 -#define AXP_IC_TYPE_REG 0x03 -#define AXP_DATA0_REG 0x04 -#define AXP_DATA1_REG 0x05 -#define AXP_DATA2_REG 0x06 -#define AXP_DATA3_REG 0x07 -#define AXP_OUT_CTRL1_REG 0x10 -#define AXP_OUT_CTRL2_REG 0x11 -#define AXP_DCDCA_CTRL_REG 0x12 -#define AXP_DCDCB_CTRL_REG 0x13 -#define AXP_DCDCC_CTRL_REG 0x14 -#define AXP_DCDCD_CTRL_REG 0x15 -#define AXP_DCDCE_CTRL_REG 0x16 -#define AXP_ALDO1_CTRL_REG 0x17 -#define AXP_ALDO2_CTRL_REG 0x18 -#define AXP_ALDO3_CTRL_REG 0x19 -#define AXP_DCDC_MODE_CTRL1_REG 0x1a -#define AXP_DCDC_MODE_CTRL2_REG 0x1b -#define AXP_DCDC_FREQ_REG 0x1c -#define AXP_OUTPUT_MON_CTRL_REG 0x1d -#define AXP_IRQ_PWROK_REG 0x1f -#define AXP_BLDO1_CTRL_REG 0x20 -#define AXP_BLDO2_CTRL_REG 0x21 -#define AXP_BLDO3_CTRL_REG 0x22 -#define AXP_BLDO4_CTRL_REG 0x23 -#define AXP_CLDO1_CTRL_REG 0x24 -#define AXP_CLDO2_CTRL_REG 0x25 -#define AXP_CLDO3_CTRL_REG 0x26 -#define AXP_POWER_WAKE_CTRL_REG 0x31 #define AXP_POWER_DISABLE_REG 0x32 #define AXP_POWER_DISABLE_CTRL __BIT(7) -#define AXP_WAKEUP_PINFUNC_REG 0x35 -#define AXP_POK_SETTING_REG 0x36 -#define AXP_MODE_SEL_REG 0x3e -#define AXP_SPECIAL_CTRL_REG 0x3f -#define AXP_IRQ_ENABLE1_REG 0x40 -#define AXP_IRQ_ENABLE2_REG 0x41 -#define AXP_IRQ2_POKSIRQ __BIT(1) -#define AXP_IRQ_STATUS1_REG 0x48 -#define AXP_IRQ_STATUS2_REG 0x49 -#define AXP_VREF_TEMP_WARN_REG 0xf3 -#define AXP_SI_ADDR_EXT_REG 0xfe -#define AXP_REG_ADDR_EXT_REG 0xff -struct axp806_ctrl { +#define AXP_IRQ_ENABLE_REG(n) (0x40 + (n) - 1) +#define AXP_IRQ2_POKSIRQ __BIT(1) +#define AXP_IRQ_STATUS_REG(n) (0x48 + (n) - 1) + +struct axppmic_ctrl { device_t c_dev; const char * c_name; @@ -110,92 +73,157 @@ struct axp806_ctrl { { .c_name = (name), .c_min = (min), .c_max = (max), \ .c_step1 = (step), .c_step1cnt = (((max) - (min)) / (step)) + 1, \ .c_step2 = 0, .c_step2cnt = 0, \ - .c_enable_reg = AXP_##ereg##_REG, .c_enable_mask = (emask), \ - .c_voltage_reg = AXP_##vreg##_REG, .c_voltage_mask = (vmask) } + .c_enable_reg = (ereg), .c_enable_mask = (emask), \ + .c_voltage_reg = (vreg), .c_voltage_mask = (vmask) } #define AXP_CTRL2(name, min, max, step1, step1cnt, step2, step2cnt, ereg, emask, vreg, vmask) \ { .c_name = (name), .c_min = (min), .c_max = (max), \ .c_step1 = (step1), .c_step1cnt = (step1cnt), \ .c_step2 = (step2), .c_step2cnt = (step2cnt), \ - .c_enable_reg = AXP_##ereg##_REG, .c_enable_mask = (emask), \ - .c_voltage_reg = AXP_##vreg##_REG, .c_voltage_mask = (vmask) } + .c_enable_reg = (ereg), .c_enable_mask = (emask), \ + .c_voltage_reg = (vreg), .c_voltage_mask = (vmask) } -static const struct axp806_ctrl axp806_ctrls[] = { - AXP_CTRL2("dcdca", 600, 1520, 10, 51, 20, 21, - OUT_CTRL1, __BIT(0), DCDCA_CTRL, __BITS(6,0)), - AXP_CTRL("dcdcb", 1000, 2550, 50, - OUT_CTRL1, __BIT(1), DCDCB_CTRL, __BITS(4,0)), - AXP_CTRL2("dcdcc", 600, 1520, 10, 51, 20, 21, - OUT_CTRL1, __BIT(2), DCDCC_CTRL, __BITS(6,0)), - AXP_CTRL2("dcdcd", 600, 3300, 20, 46, 100, 18, - OUT_CTRL1, __BIT(3), DCDCD_CTRL, __BITS(5,0)), - AXP_CTRL("dcdce", 1100, 3400, 100, - OUT_CTRL1, __BIT(4), DCDCE_CTRL, __BITS(4,0)), +static const struct axppmic_ctrl axp803_ctrls[] = { + AXP_CTRL("dldo1", 700, 3300, 100, + 0x12, __BIT(3), 0x15, __BITS(4,0)), + AXP_CTRL2("dldo2", 700, 4200, 100, 28, 200, 4, + 0x12, __BIT(4), 0x16, __BITS(4,0)), + AXP_CTRL("dldo3", 700, 3300, 100, + 0x12, __BIT(5), 0x17, __BITS(4,0)), + AXP_CTRL("dldo4", 700, 3300, 100, + 0x12, __BIT(6), 0x18, __BITS(4,0)), + AXP_CTRL("eldo1", 700, 1900, 50, + 0x12, __BIT(0), 0x19, __BITS(4,0)), + AXP_CTRL("eldo2", 700, 1900, 50, + 0x12, __BIT(1), 0x1a, __BITS(4,0)), + AXP_CTRL("eldo3", 700, 1900, 50, + 0x12, __BIT(2), 0x1b, __BITS(4,0)), + AXP_CTRL("fldo1", 700, 1450, 50, + 0x13, __BIT(2), 0x1c, __BITS(3,0)), + AXP_CTRL("fldo2", 700, 1450, 50, + 0x13, __BIT(3), 0x1d, __BITS(3,0)), + AXP_CTRL("dcdc1", 1600, 3400, 100, + 0x10, __BIT(0), 0x20, __BITS(4,0)), + AXP_CTRL2("dcdc2", 500, 1300, 10, 71, 20, 5, + 0x10, __BIT(1), 0x21, __BITS(6,0)), + AXP_CTRL2("dcdc3", 500, 1300, 10, 71, 20, 5, + 0x10, __BIT(2), 0x22, __BITS(6,0)), + AXP_CTRL2("dcdc4", 500, 1300, 10, 71, 20, 5, + 0x10, __BIT(3), 0x23, __BITS(6,0)), + AXP_CTRL2("dcdc5", 800, 1840, 10, 33, 20, 36, + 0x10, __BIT(4), 0x24, __BITS(6,0)), + AXP_CTRL2("dcdc6", 600, 1520, 10, 51, 20, 21, + 0x10, __BIT(5), 0x25, __BITS(6,0)), AXP_CTRL("aldo1", 700, 3300, 100, - OUT_CTRL1, __BIT(5), ALDO1_CTRL, __BITS(4,0)), - AXP_CTRL("aldo2", 700, 3400, 100, - OUT_CTRL1, __BIT(6), ALDO2_CTRL, __BITS(4,0)), + 0x13, __BIT(5), 0x28, __BITS(4,0)), + AXP_CTRL("aldo2", 700, 3300, 100, + 0x13, __BIT(6), 0x29, __BITS(4,0)), AXP_CTRL("aldo3", 700, 3300, 100, - OUT_CTRL1, __BIT(7), ALDO3_CTRL, __BITS(4,0)), - AXP_CTRL("bldo1", 700, 1900, 100, - OUT_CTRL2, __BIT(0), BLDO1_CTRL, __BITS(3,0)), - AXP_CTRL("bldo2", 700, 1900, 100, - OUT_CTRL2, __BIT(1), BLDO2_CTRL, __BITS(3,0)), - AXP_CTRL("bldo3", 700, 1900, 100, - OUT_CTRL2, __BIT(2), BLDO3_CTRL, __BITS(3,0)), - AXP_CTRL("bldo4", 700, 1900, 100, - OUT_CTRL2, __BIT(3), BLDO4_CTRL, __BITS(3,0)), - AXP_CTRL("cldo1", 700, 3300, 100, - OUT_CTRL2, __BIT(4), CLDO1_CTRL, __BITS(4,0)), - AXP_CTRL2("cldo2", 700, 4200, 100, 28, 200, 4, - OUT_CTRL2, __BIT(5), CLDO2_CTRL, __BITS(4,0)), - AXP_CTRL("cldo3", 700, 3300, 100, - OUT_CTRL2, __BIT(6), CLDO3_CTRL, __BITS(4,0)), + 0x13, __BIT(7), 0x2a, __BITS(4,0)), }; -struct axp806_softc { +static const struct axppmic_ctrl axp805_ctrls[] = { + AXP_CTRL2("dcdca", 600, 1520, 10, 51, 20, 21, + 0x10, __BIT(0), 0x12, __BITS(6,0)), + AXP_CTRL("dcdcb", 1000, 2550, 50, + 0x10, __BIT(1), 0x13, __BITS(4,0)), + AXP_CTRL2("dcdcc", 600, 1520, 10, 51, 20, 21, + 0x10, __BIT(2), 0x14, __BITS(6,0)), + AXP_CTRL2("dcdcd", 600, 3300, 20, 46, 100, 18, + 0x10, __BIT(3), 0x15, __BITS(5,0)), + AXP_CTRL("dcdce", 1100, 3400, 100, + 0x10, __BIT(4), 0x16, __BITS(4,0)), + AXP_CTRL("aldo1", 700, 3300, 100, + 0x10, __BIT(5), 0x17, __BITS(4,0)), + AXP_CTRL("aldo2", 700, 3400, 100, + 0x10, __BIT(6), 0x18, __BITS(4,0)), + AXP_CTRL("aldo3", 700, 3300, 100, + 0x10, __BIT(7), 0x19, __BITS(4,0)), + AXP_CTRL("bldo1", 700, 1900, 100, + 0x11, __BIT(0), 0x20, __BITS(3,0)), + AXP_CTRL("bldo2", 700, 1900, 100, + 0x11, __BIT(1), 0x21, __BITS(3,0)), + AXP_CTRL("bldo3", 700, 1900, 100, + 0x11, __BIT(2), 0x22, __BITS(3,0)), + AXP_CTRL("bldo4", 700, 1900, 100, + 0x11, __BIT(3), 0x23, __BITS(3,0)), + AXP_CTRL("cldo1", 700, 3300, 100, + 0x11, __BIT(4), 0x24, __BITS(4,0)), + AXP_CTRL2("cldo2", 700, 4200, 100, 28, 200, 4, + 0x11, __BIT(5), 0x25, __BITS(4,0)), + AXP_CTRL("cldo3", 700, 3300, 100, + 0x11, __BIT(6), 0x26, __BITS(4,0)), +}; + +struct axppmic_config { + const char *name; + const struct axppmic_ctrl *controls; + u_int ncontrols; + u_int irq_regs; +}; + +struct axppmic_softc { device_t sc_dev; i2c_tag_t sc_i2c; i2c_addr_t sc_addr; int sc_phandle; struct sysmon_pswitch sc_smpsw; + + u_int sc_nirq; }; -struct axp806reg_softc { +struct axpreg_softc { device_t sc_dev; i2c_tag_t sc_i2c; i2c_addr_t sc_addr; - const struct axp806_ctrl *sc_ctrl; + const struct axppmic_ctrl *sc_ctrl; + + u_int sc_nirq; }; -struct axp806reg_attach_args { - const struct axp806_ctrl *reg_ctrl; +struct axpreg_attach_args { + const struct axppmic_ctrl *reg_ctrl; int reg_phandle; i2c_tag_t reg_i2c; i2c_addr_t reg_addr; }; -static const char *compatible[] = { - "x-powers,axp805", - "x-powers,axp806", - NULL +static const struct axppmic_config axp803_config = { + .name = "AXP803", + .controls = axp803_ctrls, + .ncontrols = __arraycount(axp803_ctrls), + .irq_regs = 6, +}; + +static const struct axppmic_config axp805_config = { + .name = "AXP805/806", + .controls = axp805_ctrls, + .ncontrols = __arraycount(axp805_ctrls), + .irq_regs = 2, +}; + +static const struct of_compat_data compat_data[] = { + { "x-powers,axp803", (uintptr_t)&axp803_config }, + { "x-powers,axp805", (uintptr_t)&axp805_config }, + { "x-powers,axp806", (uintptr_t)&axp805_config }, + { NULL } }; static int -axp806_read(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t *val, int flags) +axppmic_read(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t *val, int flags) { return iic_smbus_read_byte(tag, addr, reg, val, flags); } static int -axp806_write(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t val, int flags) +axppmic_write(i2c_tag_t tag, i2c_addr_t addr, uint8_t reg, uint8_t val, int flags) { return iic_smbus_write_byte(tag, addr, reg, val, flags); } static int -axp806_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, u_int min, u_int max) +axppmic_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int min, u_int max) { const int flags = (cold ? I2C_F_POLL : 0); u_int vol, reg_val; @@ -225,10 +253,10 @@ axp806_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, return EINVAL; iic_acquire_bus(tag, flags); - if ((error = axp806_read(tag, addr, c->c_voltage_reg, &val, flags)) == 0) { + if ((error = axppmic_read(tag, addr, c->c_voltage_reg, &val, flags)) == 0) { val &= ~c->c_voltage_mask; val |= __SHIFTIN(reg_val, c->c_voltage_mask); - error = axp806_write(tag, addr, c->c_voltage_reg, val, flags); + error = axppmic_write(tag, addr, c->c_voltage_reg, val, flags); } iic_release_bus(tag, flags); @@ -236,7 +264,7 @@ axp806_set_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, } static int -axp806_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, u_int *pvol) +axppmic_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axppmic_ctrl *c, u_int *pvol) { const int flags = (cold ? I2C_F_POLL : 0); int reg_val, error; @@ -246,7 +274,7 @@ axp806_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, return EINVAL; iic_acquire_bus(tag, flags); - error = axp806_read(tag, addr, c->c_voltage_reg, &val, flags); + error = axppmic_read(tag, addr, c->c_voltage_reg, &val, flags); iic_release_bus(tag, flags); if (error) return error; @@ -263,45 +291,42 @@ axp806_get_voltage(i2c_tag_t tag, i2c_addr_t addr, const struct axp806_ctrl *c, } static void -axp806_power_poweroff(device_t dev) +axppmic_power_poweroff(device_t dev) { - struct axp806_softc *sc = device_private(dev); + struct axppmic_softc *sc = device_private(dev); delay(1000000); iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); - axp806_write(sc->sc_i2c, sc->sc_addr, AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL); + axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_POWER_DISABLE_REG, AXP_POWER_DISABLE_CTRL, I2C_F_POLL); iic_release_bus(sc->sc_i2c, I2C_F_POLL); } -static struct fdtbus_power_controller_func axp806_power_funcs = { - .poweroff = axp806_power_poweroff, +static struct fdtbus_power_controller_func axppmic_power_funcs = { + .poweroff = axppmic_power_poweroff, }; static void -axp806_task_shut(void *priv) +axppmic_task_shut(void *priv) { - struct axp806_softc *sc = priv; + struct axppmic_softc *sc = priv; sysmon_pswitch_event(&sc->sc_smpsw, PSWITCH_EVENT_PRESSED); } static int -axp806_intr(void *priv) +axppmic_intr(void *priv) { - struct axp806_softc *sc = priv; + struct axppmic_softc *sc = priv; const int flags = I2C_F_POLL; - uint8_t stat1, stat2; + uint8_t stat; iic_acquire_bus(sc->sc_i2c, flags); - if (axp806_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS1_REG, &stat1, flags) == 0) { - axp806_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS1_REG, stat1, flags); - } - if (axp806_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS2_REG, &stat2, flags) == 0) { - if (stat2 & AXP_IRQ2_POKSIRQ) - sysmon_task_queue_sched(0, axp806_task_shut, sc); + if (sc->sc_nirq >= 2 && axppmic_read(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(2), &stat, flags) == 0) { + if (stat & AXP_IRQ2_POKSIRQ) + sysmon_task_queue_sched(0, axppmic_task_shut, sc); - axp806_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS2_REG, stat2, flags); + axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_STATUS_REG(2), stat, flags); } iic_release_bus(sc->sc_i2c, flags); @@ -309,50 +334,63 @@ axp806_intr(void *priv) } static int -axp806_match(device_t parent, cfdata_t match, void *aux) +axppmic_match(device_t parent, cfdata_t match, void *aux) { struct i2c_attach_args *ia = aux; - if (ia->ia_name != NULL) - return iic_compat_match(ia, compatible); + if (ia->ia_name != NULL) { + if (ia->ia_cookie) + return of_match_compat_data(ia->ia_cookie, compat_data); + else + return 0; + } return 1; } static void -axp806_attach(device_t parent, device_t self, void *aux) +axppmic_attach(device_t parent, device_t self, void *aux) { - struct axp806_softc *sc = device_private(self); - struct axp806reg_attach_args aaa; + struct axppmic_softc *sc = device_private(self); + const struct axppmic_config *c; + struct axpreg_attach_args aaa; struct i2c_attach_args *ia = aux; int phandle, child, i; + uint32_t irq_mask; void *ih; + c = (void *)of_search_compatible(ia->ia_cookie, compat_data)->data; + sc->sc_dev = self; sc->sc_i2c = ia->ia_tag; sc->sc_addr = ia->ia_addr; sc->sc_phandle = ia->ia_cookie; + sc->sc_nirq = c->irq_regs; aprint_naive("\n"); - aprint_normal(": PMIC\n"); + aprint_normal(": %s\n", c->name); sc->sc_smpsw.smpsw_name = device_xname(self); sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER; sysmon_pswitch_register(&sc->sc_smpsw); iic_acquire_bus(sc->sc_i2c, I2C_F_POLL); - axp806_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE1_REG, 0x00, I2C_F_POLL); - axp806_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE2_REG, AXP_IRQ2_POKSIRQ, I2C_F_POLL); + for (i = 1; i <= sc->sc_nirq; i++) { + irq_mask = 0; + if (i == 2) + irq_mask |= AXP_IRQ2_POKSIRQ; + axppmic_write(sc->sc_i2c, sc->sc_addr, AXP_IRQ_ENABLE_REG(i), irq_mask, I2C_F_POLL); + } iic_release_bus(sc->sc_i2c, I2C_F_POLL); ih = fdtbus_intr_establish(sc->sc_phandle, 0, IPL_VM, FDT_INTR_MPSAFE, - axp806_intr, sc); + axppmic_intr, sc); if (ih == NULL) { aprint_error_dev(self, "WARNING: couldn't establish interrupt handler\n"); } fdtbus_register_power_controller(sc->sc_dev, sc->sc_phandle, - &axp806_power_funcs); + &axppmic_power_funcs); phandle = of_find_firstchild_byname(sc->sc_phandle, "regulators"); if (phandle <= 0) @@ -360,8 +398,8 @@ axp806_attach(device_t parent, device_t self, void *aux) aaa.reg_i2c = sc->sc_i2c; aaa.reg_addr = sc->sc_addr; - for (i = 0; i < __arraycount(axp806_ctrls); i++) { - const struct axp806_ctrl *ctrl = &axp806_ctrls[i]; + for (i = 0; i < c->ncontrols; i++) { + const struct axppmic_ctrl *ctrl = &c->controls[i]; child = of_find_firstchild_byname(phandle, ctrl->c_name); if (child <= 0) continue; @@ -372,21 +410,21 @@ axp806_attach(device_t parent, device_t self, void *aux) } static int -axp806reg_acquire(device_t dev) +axpreg_acquire(device_t dev) { return 0; } static void -axp806reg_release(device_t dev) +axpreg_release(device_t dev) { } static int -axp806reg_enable(device_t dev, bool enable) +axpreg_enable(device_t dev, bool enable) { - struct axp806reg_softc *sc = device_private(dev); - const struct axp806_ctrl *c = sc->sc_ctrl; + struct axpreg_softc *sc = device_private(dev); + const struct axppmic_ctrl *c = sc->sc_ctrl; const int flags = (cold ? I2C_F_POLL : 0); uint8_t val; int error; @@ -395,12 +433,12 @@ axp806reg_enable(device_t dev, bool enable) return EINVAL; iic_acquire_bus(sc->sc_i2c, flags); - if ((error = axp806_read(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, &val, flags)) == 0) { + if ((error = axppmic_read(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, &val, flags)) == 0) { if (enable) val |= c->c_enable_mask; else val &= ~c->c_enable_mask; - error = axp806_write(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, val, flags); + error = axppmic_write(sc->sc_i2c, sc->sc_addr, c->c_enable_reg, val, flags); } iic_release_bus(sc->sc_i2c, flags); @@ -408,24 +446,24 @@ axp806reg_enable(device_t dev, bool enable) } static int -axp806reg_set_voltage(device_t dev, u_int min_uvol, u_int max_uvol) +axpreg_set_voltage(device_t dev, u_int min_uvol, u_int max_uvol) { - struct axp806reg_softc *sc = device_private(dev); - const struct axp806_ctrl *c = sc->sc_ctrl; + struct axpreg_softc *sc = device_private(dev); + const struct axppmic_ctrl *c = sc->sc_ctrl; - return axp806_set_voltage(sc->sc_i2c, sc->sc_addr, c, + return axppmic_set_voltage(sc->sc_i2c, sc->sc_addr, c, min_uvol / 1000, max_uvol / 1000); } static int -axp806reg_get_voltage(device_t dev, u_int *puvol) +axpreg_get_voltage(device_t dev, u_int *puvol) { - struct axp806reg_softc *sc = device_private(dev); - const struct axp806_ctrl *c = sc->sc_ctrl; + struct axpreg_softc *sc = device_private(dev); + const struct axppmic_ctrl *c = sc->sc_ctrl; int error; u_int vol; - error = axp806_get_voltage(sc->sc_i2c, sc->sc_addr, c, &vol); + error = axppmic_get_voltage(sc->sc_i2c, sc->sc_addr, c, &vol); if (error) return error; @@ -433,25 +471,25 @@ axp806reg_get_voltage(device_t dev, u_int *puvol) return 0; } -static struct fdtbus_regulator_controller_func axp806reg_funcs = { - .acquire = axp806reg_acquire, - .release = axp806reg_release, - .enable = axp806reg_enable, - .set_voltage = axp806reg_set_voltage, - .get_voltage = axp806reg_get_voltage, +static struct fdtbus_regulator_controller_func axpreg_funcs = { + .acquire = axpreg_acquire, + .release = axpreg_release, + .enable = axpreg_enable, + .set_voltage = axpreg_set_voltage, + .get_voltage = axpreg_get_voltage, }; static int -axp806reg_match(device_t parent, cfdata_t match, void *aux) +axpreg_match(device_t parent, cfdata_t match, void *aux) { return 1; } static void -axp806reg_attach(device_t parent, device_t self, void *aux) +axpreg_attach(device_t parent, device_t self, void *aux) { - struct axp806reg_softc *sc = device_private(self); - struct axp806reg_attach_args *aaa = aux; + struct axpreg_softc *sc = device_private(self); + struct axpreg_attach_args *aaa = aux; const int phandle = aaa->reg_phandle; const char *name; @@ -461,7 +499,7 @@ axp806reg_attach(device_t parent, device_t self, void *aux) sc->sc_ctrl = aaa->reg_ctrl; fdtbus_register_regulator_controller(self, phandle, - &axp806reg_funcs); + &axpreg_funcs); aprint_naive("\n"); name = fdtbus_get_string(phandle, "regulator-name"); @@ -471,8 +509,8 @@ axp806reg_attach(device_t parent, device_t self, void *aux) aprint_normal("\n"); } -CFATTACH_DECL_NEW(axp806pmic, sizeof(struct axp806_softc), - axp806_match, axp806_attach, NULL, NULL); +CFATTACH_DECL_NEW(axppmic, sizeof(struct axppmic_softc), + axppmic_match, axppmic_attach, NULL, NULL); -CFATTACH_DECL_NEW(axp806reg, sizeof(struct axp806reg_softc), - axp806reg_match, axp806reg_attach, NULL, NULL); +CFATTACH_DECL_NEW(axpreg, sizeof(struct axpreg_softc), + axpreg_match, axpreg_attach, NULL, NULL); diff --git a/sys/dev/i2c/files.i2c b/sys/dev/i2c/files.i2c index 83507e4dbe2d..397e8aac5411 100644 --- a/sys/dev/i2c/files.i2c +++ b/sys/dev/i2c/files.i2c @@ -1,4 +1,4 @@ -# $NetBSD: files.i2c,v 1.89 2018/05/03 02:10:17 jmcneill Exp $ +# $NetBSD: files.i2c,v 1.90 2018/05/04 21:09:55 jmcneill Exp $ obsolete defflag opt_i2cbus.h I2C_SCAN define i2cbus { } @@ -232,12 +232,12 @@ device axp22x: sysmon_envsys attach axp22x at iic file dev/i2c/axp22x.c axp22x -# AXP806 Power Management Unit -device axp806pmic { }: sysmon_taskq -device axp806reg: axp806pmic -attach axp806pmic at iic -attach axp806reg at axp806pmic -file dev/i2c/axp806.c axp806pmic needs-flag +# X-Powers AXP Power Management IC +device axppmic { }: sysmon_taskq +device axpreg: axppmic +attach axppmic at iic +attach axpreg at axppmic +file dev/i2c/axppmic.c axppmic # AXP809 Power Management Unit device axp809pm