diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-10-23 17:37:52 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-10-23 17:37:52 +0000 |
commit | 949081e1cf4e6dc136ece25e38b9ee871348dbad (patch) | |
tree | b90d937b065349570dc41c69d78814bbfa6e831f /sys/arch/armv7/imx | |
parent | 4e050b8961c8f90991cd05b8bcbdf34630128f13 (diff) |
Replace imxocotp(4) with a regmap-based approach.
ok patrick@
Diffstat (limited to 'sys/arch/armv7/imx')
-rw-r--r-- | sys/arch/armv7/imx/files.imx | 8 | ||||
-rw-r--r-- | sys/arch/armv7/imx/imxanatop.c | 80 | ||||
-rw-r--r-- | sys/arch/armv7/imx/imxocotp.c | 94 | ||||
-rw-r--r-- | sys/arch/armv7/imx/imxocotpvar.h | 18 | ||||
-rw-r--r-- | sys/arch/armv7/imx/imxtemp.c | 42 |
5 files changed, 108 insertions, 134 deletions
diff --git a/sys/arch/armv7/imx/files.imx b/sys/arch/armv7/imx/files.imx index 99e6002c05c..a286af0cd09 100644 --- a/sys/arch/armv7/imx/files.imx +++ b/sys/arch/armv7/imx/files.imx @@ -1,4 +1,4 @@ -# $OpenBSD: files.imx,v 1.20 2016/10/05 22:06:48 kettenis Exp $ +# $OpenBSD: files.imx,v 1.21 2017/10/23 17:37:51 kettenis Exp $ device imxuart attach imxuart at fdt @@ -20,9 +20,9 @@ device imxdog attach imxdog at fdt file arch/armv7/imx/imxdog.c imxdog -device imxocotp -attach imxocotp at fdt -file arch/armv7/imx/imxocotp.c imxocotp +device imxanatop +attach imxanatop at fdt +file arch/armv7/imx/imxanatop.c imxanatop device imxgpio attach imxgpio at fdt diff --git a/sys/arch/armv7/imx/imxanatop.c b/sys/arch/armv7/imx/imxanatop.c new file mode 100644 index 00000000000..41ab44f9ce2 --- /dev/null +++ b/sys/arch/armv7/imx/imxanatop.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2016 Mark Kettenis <kettenis@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> +#include <sys/malloc.h> + +#include <machine/bus.h> +#include <machine/fdt.h> + +#include <dev/ofw/openfirm.h> +#include <dev/ofw/ofw_misc.h> +#include <dev/ofw/fdt.h> + +struct imxanatop_softc { + struct device sc_dev; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; +}; + +int imxanatop_match(struct device *, void *, void *); +void imxanatop_attach(struct device *, struct device *, void *); + +struct cfattach imxanatop_ca = { + sizeof(struct imxanatop_softc), imxanatop_match, imxanatop_attach +}; + +struct cfdriver imxanatop_cd = { + NULL, "imxanatop", DV_DULL +}; + +int +imxanatop_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + if (OF_is_compatible(faa->fa_node, "fsl,imx6q-anatop")) + return 10; /* Must beat simplebus(4) and syscon(4). */ + + return 0; +} + +void +imxanatop_attach(struct device *parent, struct device *self, void *aux) +{ + struct imxanatop_softc *sc = (struct imxanatop_softc *)self; + struct fdt_attach_args *faa = aux; + + if (faa->fa_nreg < 1) { + printf(": no registers\n"); + return; + } + + sc->sc_iot = faa->fa_iot; + + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_ioh)) { + printf(": can't map registers\n"); + return; + } + + regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh, + faa->fa_reg[0].size); + + printf("\n"); +} diff --git a/sys/arch/armv7/imx/imxocotp.c b/sys/arch/armv7/imx/imxocotp.c deleted file mode 100644 index aa17d5357ed..00000000000 --- a/sys/arch/armv7/imx/imxocotp.c +++ /dev/null @@ -1,94 +0,0 @@ -/* $OpenBSD: imxocotp.c,v 1.6 2017/09/22 09:34:23 kettenis Exp $ */ -/* - * Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/queue.h> -#include <sys/malloc.h> -#include <sys/device.h> -#include <sys/evcount.h> -#include <sys/socket.h> -#include <sys/timeout.h> - -#include <machine/intr.h> -#include <machine/bus.h> -#include <machine/fdt.h> - -#include <armv7/imx/imxocotpvar.h> - -#include <dev/ofw/openfirm.h> -#include <dev/ofw/fdt.h> - -/* registers */ -#define OCOTP_ANA0 0x4d0 -#define OCOTP_ANA1 0x4e0 -#define OCOTP_ANA2 0x4f0 -#define OCOTP_MAC0 0x620 -#define OCOTP_MAC1 0x630 - -struct imxocotp_softc { - struct device sc_dev; - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; -}; - -struct imxocotp_softc *imxocotp_sc; - -int imxocotp_match(struct device *, void *, void *); -void imxocotp_attach(struct device *, struct device *, void *); - -struct cfattach imxocotp_ca = { - sizeof (struct imxocotp_softc), imxocotp_match, imxocotp_attach -}; - -struct cfdriver imxocotp_cd = { - NULL, "imxocotp", DV_DULL -}; - -int -imxocotp_match(struct device *parent, void *match, void *aux) -{ - struct fdt_attach_args *faa = aux; - - if (OF_is_compatible(faa->fa_node, "fsl,imx6q-ocotp")) - return 10; /* Must beat syscon(4). */ - - return 0; -} - -void -imxocotp_attach(struct device *parent, struct device *self, void *aux) -{ - struct imxocotp_softc *sc = (struct imxocotp_softc *)self; - struct fdt_attach_args *faa = aux; - - KASSERT(faa->fa_nreg >= 1); - - sc->sc_iot = faa->fa_iot; - if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, - faa->fa_reg[0].size, 0, &sc->sc_ioh)) - panic("%s: bus_space_map failed!", __func__); - - imxocotp_sc = sc; - printf("\n"); -} - -uint32_t -imxocotp_get_temperature_calibration(void) -{ - return bus_space_read_4(imxocotp_sc->sc_iot, imxocotp_sc->sc_ioh, OCOTP_ANA1); -} diff --git a/sys/arch/armv7/imx/imxocotpvar.h b/sys/arch/armv7/imx/imxocotpvar.h deleted file mode 100644 index 245f91a7fee..00000000000 --- a/sys/arch/armv7/imx/imxocotpvar.h +++ /dev/null @@ -1,18 +0,0 @@ -/* $OpenBSD: imxocotpvar.h,v 1.3 2017/09/22 09:34:23 kettenis Exp $ */ -/* - * Copyright (c) 2012-2013 Patrick Wildt <patrick@blueri.se> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -uint32_t imxocotp_get_temperature_calibration(void); diff --git a/sys/arch/armv7/imx/imxtemp.c b/sys/arch/armv7/imx/imxtemp.c index 577cb68f9ce..5b65c29a06c 100644 --- a/sys/arch/armv7/imx/imxtemp.c +++ b/sys/arch/armv7/imx/imxtemp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imxtemp.c,v 1.3 2016/12/31 15:29:14 kettenis Exp $ */ +/* $OpenBSD: imxtemp.c,v 1.4 2017/10/23 17:37:51 kettenis Exp $ */ /* * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se> * Copyright (c) 2016 Mark Kettenis <kettenis@openbsd.org> @@ -31,11 +31,11 @@ #include <machine/fdt.h> #include <armv7/armv7/armv7var.h> -#include <armv7/imx/imxocotpvar.h> #include <armv7/imx/imxccmvar.h> #include <dev/ofw/openfirm.h> #include <dev/ofw/fdt.h> +#include <dev/ofw/ofw_misc.h> /* registers */ #define TEMPMON_TEMPSENSE0 0x180 @@ -56,7 +56,10 @@ #define TEMPMON_TEMPSENSE0_ALARM_VALUE_MASK 0xfff #define TEMPMON_TEMPSENSE0_ALARM_VALUE_SHIFT 20 -/* calibration */ +/* calibration registers */ +#define OCOTP_ANA1 0x4e0 + +/* calibration bits and bytes */ #define OCOTP_ANA1_HOT_TEMP_MASK 0xff #define OCOTP_ANA1_HOT_TEMP_SHIFT 0 #define OCOTP_ANA1_HOT_COUNT_MASK 0xfff @@ -65,9 +68,9 @@ #define OCOTP_ANA1_ROOM_COUNT_SHIFT 20 #define HREAD4(sc, reg) \ - (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) + regmap_read_4((sc)->sc_rm, (reg)) #define HWRITE4(sc, reg, val) \ - bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) + regmap_write_4((sc)->sc_rm, (reg), (val)) #define HSET4(sc, reg, bits) \ HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) #define HCLR4(sc, reg, bits) \ @@ -75,8 +78,8 @@ struct imxtemp_softc { struct device sc_dev; - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; + int sc_node; + struct regmap *sc_rm; uint32_t sc_hot_count; uint32_t sc_hot_temp; @@ -108,10 +111,7 @@ imxtemp_match(struct device *parent, void *match, void *aux) { struct fdt_attach_args *faa = aux; - if (OF_is_compatible(faa->fa_node, "fsl,imx6q-anatop")) - return 10; /* Must beat simplebus(4). */ - - return 0; + return OF_is_compatible(faa->fa_node, "fsl,imx6q-tempmon"); } void @@ -119,15 +119,14 @@ imxtemp_attach(struct device *parent, struct device *self, void *aux) { struct imxtemp_softc *sc = (struct imxtemp_softc *)self; struct fdt_attach_args *faa = aux; + uint32_t phandle; - if (faa->fa_nreg < 1) + sc->sc_node = faa->fa_node; + phandle = OF_getpropint(sc->sc_node, "fsl,tempmon", 0); + sc->sc_rm = regmap_byphandle(phandle); + if (sc->sc_rm == NULL) return; - sc->sc_iot = faa->fa_iot; - if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, - faa->fa_reg[0].size, 0, &sc->sc_ioh)) - panic("%s: bus_space_map failed!", __func__); - printf("\n"); config_mountroot(self, imxtemp_calibration); @@ -138,8 +137,15 @@ imxtemp_calibration(struct device *self) { struct imxtemp_softc *sc = (struct imxtemp_softc *)self; uint32_t calibration; + uint32_t phandle; + struct regmap *rm; + + phandle = OF_getpropint(sc->sc_node, "fsl,tempmon-data", 0); + rm = regmap_byphandle(phandle); + if (rm == NULL) + return; - calibration = imxocotp_get_temperature_calibration(); + calibration = regmap_read_4(rm, OCOTP_ANA1); sc->sc_hot_count = (calibration >> OCOTP_ANA1_HOT_COUNT_SHIFT) & OCOTP_ANA1_HOT_COUNT_MASK; sc->sc_hot_temp = (calibration >> OCOTP_ANA1_HOT_TEMP_SHIFT) & |