From 43f7f1100393e533d2ea4f071c1d66544435e583 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 25 Feb 2018 20:43:33 +0000 Subject: [PATCH] Add RK805 support. --- sys/dev/fdt/rkpmic.c | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/sys/dev/fdt/rkpmic.c b/sys/dev/fdt/rkpmic.c index 8ccf41af636..9c7bf5bf55a 100644 --- a/sys/dev/fdt/rkpmic.c +++ b/sys/dev/fdt/rkpmic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rkpmic.c,v 1.3 2017/11/18 20:29:51 kettenis Exp $ */ +/* $OpenBSD: rkpmic.c,v 1.4 2018/02/25 20:43:33 kettenis Exp $ */ /* * Copyright (c) 2017 Mark Kettenis * @@ -50,6 +50,16 @@ struct rkpmic_regdata { uint32_t base, delta; }; +struct rkpmic_regdata rk805_regdata[] = { + { "DCDC_REG1", 0x2f, 0x3f, 712500, 12500 }, + { "DCDC_REG2", 0x33, 0x3f, 712500, 12500 }, + { "DCDC_REG4", 0x38, 0x1f, 800000, 100000 }, + { "LDO_REG1", 0x3b, 0x1f, 800000, 100000 }, + { "LDO_REG2", 0x3d, 0x1f, 800000, 100000 }, + { "LDO_REG3", 0x3f, 0x1f, 800000, 100000 }, + { } +}; + struct rkpmic_regdata rk808_regdata[] = { { "DCDC_REG1", 0x2f, 0x3f, 712500, 12500 }, { "DCDC_REG2", 0x33, 0x3f, 712500, 12500 }, @@ -62,6 +72,7 @@ struct rkpmic_regdata rk808_regdata[] = { { "LDO_REG6", 0x45, 0x1f, 800000, 100000 }, { "LDO_REG7", 0x47, 0x1f, 800000, 100000 }, { "LDO_REG8", 0x49, 0x1f, 1800000, 100000 }, + { } }; struct rkpmic_softc { @@ -70,6 +81,7 @@ struct rkpmic_softc { i2c_addr_t sc_addr; struct todr_chip_handle sc_todr; + struct rkpmic_regdata *sc_regdata; }; int rkpmic_match(struct device *, void *, void *); @@ -97,7 +109,8 @@ rkpmic_match(struct device *parent, void *match, void *aux) struct i2c_attach_args *ia = aux; int node = *(int *)ia->ia_cookie; - return (OF_is_compatible(node, "rockchip,rk808")); + return (OF_is_compatible(node, "rockchip,rk805") || + OF_is_compatible(node, "rockchip,rk808")); } void @@ -106,17 +119,25 @@ rkpmic_attach(struct device *parent, struct device *self, void *aux) struct rkpmic_softc *sc = (struct rkpmic_softc *)self; struct i2c_attach_args *ia = aux; int node = *(int *)ia->ia_cookie; + const char *chip; sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; - printf("\n"); - sc->sc_todr.cookie = sc; sc->sc_todr.todr_gettime = rkpmic_gettime; sc->sc_todr.todr_settime = rkpmic_settime; todr_handle = &sc->sc_todr; + if (OF_is_compatible(node, "rockchip,rk805")) { + chip = "RK805"; + sc->sc_regdata = rk805_regdata; + } else { + chip = "RK808"; + sc->sc_regdata = rk808_regdata; + } + printf(": %s\n", chip); + node = OF_getnodebyname(node, "regulators"); if (node == 0) return; @@ -145,20 +166,20 @@ rkpmic_attach_regulator(struct rkpmic_softc *sc, int node) name[0] = 0; OF_getprop(node, "name", name, sizeof(name)); name[sizeof(name) - 1] = 0; - for (i = 0; i < nitems(rk808_regdata); i++) { - if (strcmp(rk808_regdata[i].name, name) == 0) + for (i = 0; sc->sc_regdata[i].name; i++) { + if (strcmp(sc->sc_regdata[i].name, name) == 0) break; } - if (i == nitems(rk808_regdata)) + if (sc->sc_regdata[i].name == NULL) return; rr = malloc(sizeof(*rr), M_DEVBUF, M_WAITOK | M_ZERO); rr->rr_sc = sc; - rr->rr_reg = rk808_regdata[i].reg; - rr->rr_mask = rk808_regdata[i].mask; - rr->rr_base = rk808_regdata[i].base; - rr->rr_delta = rk808_regdata[i].delta; + rr->rr_reg = sc->sc_regdata[i].reg; + rr->rr_mask = sc->sc_regdata[i].mask; + rr->rr_base = sc->sc_regdata[i].base; + rr->rr_delta = sc->sc_regdata[i].delta; rr->rr_rd.rd_node = node; rr->rr_rd.rd_cookie = rr; -- 2.20.1