From dd0655155159a5aef9027b45c197114cd421ac8a Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Mon, 27 Apr 2020 20:09:56 +0000 Subject: Use the device tree properties to setup imxehci(4)'s USB non-core instead of hardcoding the values. Tested on a Cubox-i by kettenis@ ok kettenis@ --- sys/dev/fdt/imxehci.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/fdt/imxehci.c b/sys/dev/fdt/imxehci.c index 0df6e702a9e..4c565aeb299 100644 --- a/sys/dev/fdt/imxehci.c +++ b/sys/dev/fdt/imxehci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imxehci.c,v 1.2 2020/04/27 20:07:39 patrick Exp $ */ +/* $OpenBSD: imxehci.c,v 1.3 2020/04/27 20:09:55 patrick Exp $ */ /* * Copyright (c) 2012-2013 Patrick Wildt * @@ -64,10 +64,10 @@ #define USBNC_USB_OTG_CTRL 0x00 #define USBNC_USB_UH1_CTRL 0x04 -#define USBNC_USB_OTG_CTRL_OVER_CUR_POL (1 << 8) -#define USBNC_USB_OTG_CTRL_OVER_CUR_DIS (1 << 7) -#define USBNC_USB_UH1_CTRL_OVER_CUR_POL (1 << 8) -#define USBNC_USB_UH1_CTRL_OVER_CUR_DIS (1 << 7) +#define USBNC_USB_CTRL_PWR_POL (1 << 9) +#define USBNC_USB_CTRL_OVER_CUR_POL (1 << 8) +#define USBNC_USB_CTRL_OVER_CUR_DIS (1 << 7) +#define USBNC_USB_CTRL_NON_BURST (1 << 1) /* anatop */ #define ANALOG_USB1_CHRG_DETECT 0x1b0 @@ -122,6 +122,7 @@ imxehci_attach(struct device *parent, struct device *self, void *aux) char *devname = sc->sc.sc_bus.bdev.dv_xname; uint32_t phy[1], misc[2]; uint32_t misc_reg[2]; + uint32_t off, reg; uint32_t vbus; int misc_node; @@ -179,17 +180,29 @@ imxehci_attach(struct device *parent, struct device *self, void *aux) /* over current and polarity setting */ switch (misc[1]) { case 0: - bus_space_write_4(sc->sc.iot, sc->nc_ioh, USBNC_USB_OTG_CTRL, - bus_space_read_4(sc->sc.iot, sc->nc_ioh, USBNC_USB_OTG_CTRL) | - (USBNC_USB_OTG_CTRL_OVER_CUR_POL | USBNC_USB_OTG_CTRL_OVER_CUR_DIS)); + off = USBNC_USB_OTG_CTRL; break; case 1: - bus_space_write_4(sc->sc.iot, sc->nc_ioh, USBNC_USB_UH1_CTRL, - bus_space_read_4(sc->sc.iot, sc->nc_ioh, USBNC_USB_UH1_CTRL) | - (USBNC_USB_UH1_CTRL_OVER_CUR_POL | USBNC_USB_UH1_CTRL_OVER_CUR_DIS)); + off = USBNC_USB_UH1_CTRL; break; + default: + printf("%s: invalid usbmisc property\n", devname); + return; } + reg = bus_space_read_4(sc->sc.iot, sc->nc_ioh, off); + reg &= ~USBNC_USB_CTRL_OVER_CUR_DIS; + if (OF_getproplen(faa->fa_node, "disable-over-current") == 0) + reg |= USBNC_USB_CTRL_OVER_CUR_DIS; + if (OF_getproplen(faa->fa_node, "over-current-active-low") == 0) + reg |= USBNC_USB_CTRL_OVER_CUR_POL; + else if (OF_getproplen(faa->fa_node, "over-current-active-high") == 0) + reg &= ~USBNC_USB_CTRL_OVER_CUR_POL; + if (OF_getproplen(faa->fa_node, "power-active-high") == 0) + reg |= USBNC_USB_CTRL_PWR_POL; + reg |= USBNC_USB_CTRL_NON_BURST; + bus_space_write_4(sc->sc.iot, sc->nc_ioh, off, reg); + /* enable usb bus power */ vbus = OF_getpropint(faa->fa_node, "vbus-supply", 0); if (vbus) -- cgit v1.2.3