From 79f9b182e8edfa2a69db45d93d64dd7646468592 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 5 Sep 2009 04:11:27 +0200 Subject: [PATCH 02/12] pxa27x_udc.c: allow passing GPIOs from platform --- sys/arch/arm/xscale/files.pxa2x0 | 1 - sys/arch/arm/xscale/pxa27x_udc.c | 122 +++----------------------------- sys/arch/arm/xscale/pxa27x_udc.h | 67 ++++++++++++++++++ sys/arch/zaurus/conf/files.zaurus | 2 + sys/arch/zaurus/dev/zaurus_udc.c | 97 ++++++++++++++++++++++++++ sys/arch/zaurus/include/machine_reg.h | 6 +- 6 files changed, 181 insertions(+), 114 deletions(-) create mode 100644 sys/arch/arm/xscale/pxa27x_udc.h create mode 100644 sys/arch/zaurus/dev/zaurus_udc.c diff --git a/sys/arch/arm/xscale/files.pxa2x0 b/sys/arch/arm/xscale/files.pxa2x0 index e1493b4..ebff8a5 100644 --- a/sys/arch/arm/xscale/files.pxa2x0 +++ b/sys/arch/arm/xscale/files.pxa2x0 @@ -48,7 +48,6 @@ file arch/arm/xscale/pxa2x0_a4x_io.S com_pxaip # PXA27x USB Device Controller device pxaudc: usbdev -attach pxaudc at pxaip file arch/arm/xscale/pxa27x_udc.c pxaudc # OHCI USB Controller diff --git a/sys/arch/arm/xscale/pxa27x_udc.c b/sys/arch/arm/xscale/pxa27x_udc.c index c83bb4e..7fdd02e 100644 --- a/sys/arch/arm/xscale/pxa27x_udc.c +++ b/sys/arch/arm/xscale/pxa27x_udc.c @@ -38,11 +38,7 @@ #include #include -#include -#define PXAUDC_EP0MAXP 16 /* XXX */ -#define PXAUDC_NEP 24 /* total number of endpoints */ - -#include /* XXX */ +#include #include "usbf.h" @@ -56,44 +52,8 @@ struct pxaudc_pipe { // LIST_ENTRY(pxaudc_pipe) list; }; -struct pxaudc_softc { - struct usbf_bus sc_bus; - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; - bus_size_t sc_size; - void *sc_ih; - void *sc_conn_ih; - void *sc_powerhook; - SIMPLEQ_HEAD(,usbf_xfer) sc_free_xfers; /* recycled xfers */ - u_int32_t sc_icr0; /* enabled EP interrupts */ - u_int32_t sc_icr1; /* enabled EP interrupts */ - enum { - EP0_SETUP, - EP0_IN - } sc_ep0state; - u_int32_t sc_isr0; /* XXX deferred interrupts */ - u_int32_t sc_isr1; /* XXX deferred interrupts */ - u_int32_t sc_otgisr; /* XXX deferred interrupts */ - struct pxaudc_pipe *sc_pipe[PXAUDC_NEP]; - int sc_npipe; - - int sc_cn; - int sc_in; - int sc_isn; - int8_t sc_ep_map[16]; -}; - -int pxaudc_match(struct device *, void *, void *); -void pxaudc_attach(struct device *, struct device *, void *); -int pxaudc_detach(struct device *, int); void pxaudc_power(int, void *); -int pxaudc_is_host(void); -int pxaudc_is_device(void); -void pxaudc_setup(struct pxaudc_softc *); -void pxaudc_hide(struct pxaudc_softc *); -void pxaudc_show(struct pxaudc_softc *); - void pxaudc_enable(struct pxaudc_softc *); void pxaudc_disable(struct pxaudc_softc *); void pxaudc_read_ep0(struct pxaudc_softc *, usbf_xfer_handle); @@ -127,11 +87,6 @@ void pxaudc_bulk_abort(usbf_xfer_handle); void pxaudc_bulk_done(usbf_xfer_handle); void pxaudc_bulk_close(usbf_pipe_handle); -struct cfattach pxaudc_ca = { - sizeof(struct pxaudc_softc), pxaudc_match, pxaudc_attach, - pxaudc_detach -}; - struct cfdriver pxaudc_cd = { NULL, "pxaudc", DV_DULL }; @@ -186,7 +141,7 @@ int pxaudcdebug = 0; #endif int -pxaudc_match(struct device *parent, void *match, void *aux) +pxaudc_match(void) { if ((cputype & ~CPU_ID_XSCALE_COREREV_MASK) != CPU_ID_PXA27X) return (0); @@ -195,11 +150,12 @@ pxaudc_match(struct device *parent, void *match, void *aux) } void -pxaudc_attach(struct device *parent, struct device *self, void *aux) +pxaudc_attach(struct pxaudc_softc *sc, void *aux) { - struct pxaudc_softc *sc = (struct pxaudc_softc *)self; struct pxaip_attach_args *pxa = aux; +#if NUSBF > 0 int i; +#endif sc->sc_iot = pxa->pxa_iot; if (bus_space_map(sc->sc_iot, PXA2X0_USBDC_BASE, PXA2X0_USBDC_SIZE, 0, @@ -215,7 +171,6 @@ pxaudc_attach(struct device *parent, struct device *self, void *aux) BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE); /* Set up GPIO pins and disable the controller. */ - pxaudc_setup(sc); pxaudc_disable(sc); #if NUSBF > 0 @@ -234,7 +189,7 @@ pxaudc_attach(struct device *parent, struct device *self, void *aux) sc->sc_conn_ih = pxa2x0_gpio_intr_establish(PXA_USB_DEVICE_PIN, /* XXX */ IST_EDGE_BOTH, IPL_USB, pxaudc_connect_intr, sc, "usbc"); #endif - sc->sc_conn_ih = pxa2x0_gpio_intr_establish(PXA_USB_CONNECT_PIN, + sc->sc_conn_ih = pxa2x0_gpio_intr_establish(sc->sc_gpio_detect, IST_EDGE_BOTH, IPL_USB, pxaudc_connect_intr, sc, "usbc"); if (sc->sc_conn_ih == NULL) { printf(": unable to establish connect interrupt\n"); @@ -262,19 +217,17 @@ pxaudc_attach(struct device *parent, struct device *self, void *aux) } /* Attach logical device and function. */ - (void)config_found(self, &sc->sc_bus, NULL); + (void)config_found((struct device *)sc, &sc->sc_bus, NULL); /* Enable the controller unless we're now acting as a host. */ - if (!pxaudc_is_host()) + if (!sc->sc_is_host()) pxaudc_enable(sc); #endif } int -pxaudc_detach(struct device *self, int flags) +pxaudc_detach(struct pxaudc_softc *sc, int flags) { - struct pxaudc_softc *sc = (struct pxaudc_softc *)self; - if (sc->sc_powerhook != NULL) powerhook_disestablish(sc->sc_powerhook); @@ -310,56 +263,6 @@ pxaudc_power(int why, void *arg) } /* - * Machine-specific functions - */ - -/* XXX move to machine-specific file */ - -int -pxaudc_is_host(void) -{ - return (!pxa2x0_gpio_get_bit(PXA_USB_CONNECT_PIN) && - !pxa2x0_gpio_get_bit(PXA_USB_DEVICE_PIN)); -} - -int -pxaudc_is_device(void) -{ - return (pxa2x0_gpio_get_bit(PXA_USB_CONNECT_PIN) && - pxa2x0_gpio_get_bit(PXA_USB_DEVICE_PIN)); -} - -void -pxaudc_setup(struct pxaudc_softc *sc) -{ - pxa2x0_gpio_set_function(45, GPIO_OUT); - pxa2x0_gpio_set_function(PXA_USB_CONNECT_PIN, GPIO_IN); /* 41 */ - pxa2x0_gpio_set_function(40, GPIO_OUT); - pxa2x0_gpio_set_function(39, GPIO_IN); - pxa2x0_gpio_set_function(38, GPIO_IN); - pxa2x0_gpio_set_function(37, GPIO_OUT); - pxa2x0_gpio_set_function(36, GPIO_IN); - pxa2x0_gpio_set_function(PXA_USB_DEVICE_PIN, GPIO_IN); /* 35 */ - pxa2x0_gpio_set_function(34, GPIO_IN); - pxa2x0_gpio_set_function(89, GPIO_OUT); - pxa2x0_gpio_set_function(120, GPIO_OUT); -} - -/* Hide us from the host. */ -void -pxaudc_hide(struct pxaudc_softc *sc) -{ - pxa2x0_gpio_clear_bit(PXA_USB_PULLUP_PIN); -} - -/* Show us to the host. */ -void -pxaudc_show(struct pxaudc_softc *sc) -{ - pxa2x0_gpio_set_bit(PXA_USB_PULLUP_PIN); -} - -/* * Register manipulation */ @@ -790,12 +693,11 @@ pxaudc_connect_intr(void *v) { struct pxaudc_softc *sc = v; - DPRINTF(10,("pxaudc_connect_intr: connect=%d device=%d\n", - pxa2x0_gpio_get_bit(PXA_USB_CONNECT_PIN), - pxa2x0_gpio_get_bit(PXA_USB_DEVICE_PIN))); + DPRINTF(10,("pxaudc_connect_intr: connect=%d\n", + pxa2x0_gpio_get_bit(sc->sc_gpio_detect))); /* XXX only set a flag here */ - if (pxaudc_is_host()) { + if (sc->sc_is_host()) { #if 0 printf("%s:switching to host\n", sc->sc_bus.bdev.dv_xname); #endif diff --git a/sys/arch/arm/xscale/pxa27x_udc.h b/sys/arch/arm/xscale/pxa27x_udc.h new file mode 100644 index 0000000..db34ebd --- /dev/null +++ b/sys/arch/arm/xscale/pxa27x_udc.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009 Marek Vasut + * + * Moved from pxa27x_udc.c: + * + * Copyright (c) 2007 Dale Rahn + * Copyright (c) 2006 Uwe Stuehler + * Copyright (c) 2005 David Gwynne + * + * 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 + +#define PXAUDC_EP0MAXP 16 /* XXX */ +#define PXAUDC_NEP 24 /* total number of endpoints */ + +struct pxaudc_softc { + struct usbf_bus sc_bus; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + bus_size_t sc_size; + void *sc_ih; + void *sc_conn_ih; + void *sc_powerhook; + SIMPLEQ_HEAD(,usbf_xfer) sc_free_xfers; /* recycled xfers */ + u_int32_t sc_icr0; /* enabled EP interrupts */ + u_int32_t sc_icr1; /* enabled EP interrupts */ + enum { + EP0_SETUP, + EP0_IN + } sc_ep0state; + u_int32_t sc_isr0; /* XXX deferred interrupts */ + u_int32_t sc_isr1; /* XXX deferred interrupts */ + u_int32_t sc_otgisr; /* XXX deferred interrupts */ + struct pxaudc_pipe *sc_pipe[PXAUDC_NEP]; + int sc_npipe; + + int sc_cn; + int sc_in; + int sc_isn; + int8_t sc_ep_map[16]; + + struct device *sc_dev; + + int sc_gpio_detect; + int sc_gpio_detect_inv; + + int sc_gpio_pullup; + int sc_gpio_pullup_inv; + + int (*sc_is_host)(void); +}; + +int pxaudc_match(void); +void pxaudc_attach(struct pxaudc_softc *, void *); +int pxaudc_detach(struct pxaudc_softc *, int); diff --git a/sys/arch/zaurus/conf/files.zaurus b/sys/arch/zaurus/conf/files.zaurus index 3e6337d..493b969 100644 --- a/sys/arch/zaurus/conf/files.zaurus +++ b/sys/arch/zaurus/conf/files.zaurus @@ -102,6 +102,8 @@ include "dev/pckbc/files.pckbc" # Include USB stuff include "dev/usb/files.usb" +attach pxaudc at pxaip with pxaudc_zaurus +file arch/zaurus/dev/zaurus_udc.c pxaudc_zaurus # Bluetooth include "dev/bluetooth/files.bluetooth" diff --git a/sys/arch/zaurus/dev/zaurus_udc.c b/sys/arch/zaurus/dev/zaurus_udc.c new file mode 100644 index 0000000..11f0ed2 --- /dev/null +++ b/sys/arch/zaurus/dev/zaurus_udc.c @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2009 Marek Vasut + * + * 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. + */ + +/* Attachment driver for pxaudc(4) on Zaurus */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +int zaurus_udc_match(struct device *, void *, void *); +void zaurus_udc_attach(struct device *, struct device *, void *); +int zaurus_udc_detach(struct device *, int); +int zaurus_udc_is_host(void); + +struct cfattach pxaudc_zaurus_ca = { + sizeof(struct pxaudc_softc), + zaurus_udc_match, + zaurus_udc_attach, + zaurus_udc_detach, +}; + +int +zaurus_udc_match(struct device *parent, void *match, void *aux) +{ + return pxaudc_match(); +} + +int +zaurus_udc_is_host(void) +{ + return !(pxa2x0_gpio_get_bit(GPIO_USB_DETECT) || + pxa2x0_gpio_get_bit(GPIO_USB_DEVICE)); +} + +void +zaurus_udc_attach(struct device *parent, struct device *self, void *aux) +{ + struct pxaudc_softc *sc = (struct pxaudc_softc *)self; + + + sc->sc_gpio_detect = GPIO_USB_DETECT; + sc->sc_gpio_pullup = GPIO_USB_PULLUP; + sc->sc_gpio_pullup_inv = 0; + sc->sc_is_host = zaurus_udc_is_host; + + /* Platform specific GPIO configuration */ + pxa2x0_gpio_set_function(GPIO_USB_DETECT, GPIO_IN); + pxa2x0_gpio_set_function(GPIO_USB_DEVICE, GPIO_IN); + pxa2x0_gpio_set_function(GPIO_USB_PULLUP, GPIO_OUT); + + pxa2x0_gpio_set_function(45, GPIO_OUT); + pxa2x0_gpio_set_function(40, GPIO_OUT); + pxa2x0_gpio_set_function(39, GPIO_IN); + pxa2x0_gpio_set_function(38, GPIO_IN); + pxa2x0_gpio_set_function(37, GPIO_OUT); + pxa2x0_gpio_set_function(36, GPIO_IN); + pxa2x0_gpio_set_function(34, GPIO_IN); + pxa2x0_gpio_set_function(89, GPIO_OUT); + pxa2x0_gpio_set_function(120, GPIO_OUT); + + pxaudc_attach(sc, aux); +} + +int +zaurus_udc_detach(struct device *self, int flags) +{ + struct pxaudc_softc *sc = (struct pxaudc_softc *)self; + + return pxaudc_detach(sc, flags); +} diff --git a/sys/arch/zaurus/include/machine_reg.h b/sys/arch/zaurus/include/machine_reg.h index c3f279a..b17b8bc 100644 --- a/sys/arch/zaurus/include/machine_reg.h +++ b/sys/arch/zaurus/include/machine_reg.h @@ -75,9 +75,9 @@ #define C3000_RC_IRQ_PIN 13 /* remote control */ #define C3000_CF0_IRQ_PIN 94 #define C3000_CF1_IRQ_PIN 93 -#define PXA_USB_DEVICE_PIN 35 /* indicate connection type */ -#define PXA_USB_CONNECT_PIN 41 /* connection interrupt */ -#define PXA_USB_PULLUP_PIN 45 /* show/hide device presence */ +#define GPIO_USB_DEVICE 35 /* indicate connection type */ +#define GPIO_USB_DETECT 41 /* connection interrupt */ +#define GPIO_USB_PULLUP 45 /* show/hide device presence */ #define GPIO_HP_IN_C3000 116 /* headphone jack */ #define GPIO_MMC_DETECT 9 /* card detect */ -- 1.6.3.4