summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2020-04-27 20:09:56 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2020-04-27 20:09:56 +0000
commitdd0655155159a5aef9027b45c197114cd421ac8a (patch)
tree9a7a6d7316012c1d72d72fb8a51eaf85a848bbf2 /sys/dev
parent8c3f9286125c0d9647c7b9de5b09c432c57f19d5 (diff)
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@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/fdt/imxehci.c35
1 files changed, 24 insertions, 11 deletions
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 <patrick@blueri.se>
*
@@ -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)