From 70132794d9e593067b4a867af6462c065726590d Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 15 Aug 2009 23:07:47 +0200 Subject: [PATCH 06/10] Palm USB rework --- sys/arch/arm/xscale/files.pxa2x0 | 1 - sys/arch/arm/xscale/pxa27x_udc.c | 103 +++++------------------------------ sys/arch/arm/xscale/pxa27x_udc.h | 52 ++++++++++++++++++ sys/arch/palm/conf/RAMDISK | 36 ++++++------ sys/arch/palm/conf/files.palm | 3 + sys/arch/palm/dev/palm_udc.c | 93 +++++++++++++++++++++++++++++++ sys/arch/palm/include/conf.h | 1 + sys/arch/palm/include/machine_reg.h | 4 ++ 8 files changed, 186 insertions(+), 107 deletions(-) create mode 100644 sys/arch/arm/xscale/pxa27x_udc.h create mode 100644 sys/arch/palm/dev/palm_udc.c diff --git a/sys/arch/arm/xscale/files.pxa2x0 b/sys/arch/arm/xscale/files.pxa2x0 index d313689..785cdfe 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..ec6e793 100644 --- a/sys/arch/arm/xscale/pxa27x_udc.c +++ b/sys/arch/arm/xscale/pxa27x_udc.c @@ -38,11 +38,8 @@ #include #include -#include +#include #define PXAUDC_EP0MAXP 16 /* XXX */ -#define PXAUDC_NEP 24 /* total number of endpoints */ - -#include /* XXX */ #include "usbf.h" @@ -56,43 +53,9 @@ 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 *); @@ -127,11 +90,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 +144,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 +153,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, @@ -234,7 +193,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 +221,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); @@ -313,52 +270,23 @@ 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(sc->sc_gpio_detect, GPIO_IN); /* 41 */ + pxa2x0_gpio_set_function(sc->sc_gpio_pullup, GPIO_OUT | + (sc->sc_gpio_pullup_inv ? 0 : GPIO_SET)); 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 +718,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..c6253d7 --- /dev/null +++ b/sys/arch/arm/xscale/pxa27x_udc.h @@ -0,0 +1,52 @@ +/* + * Marek Vasut + * + * 2009 AD + * + * Public Domain + * */ + +#include + +#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/palm/conf/RAMDISK b/sys/arch/palm/conf/RAMDISK index 974b955..b2d3723 100644 --- a/sys/arch/palm/conf/RAMDISK +++ b/sys/arch/palm/conf/RAMDISK @@ -49,44 +49,44 @@ pxagpio0 at pxaip? # GPIO pxaost0 at pxaip? addr 0x40a00000 size 0x20 # USB controllers -#pxaudc0 at pxaip? # USB Device Controller -#ohci0 at pxaip? # Open Host Controller +pxaudc0 at pxaip? # USB Device Controller +ohci0 at pxaip? # Open Host Controller # USB function support -#usbf* at pxaudc? # USB logical device +usbf* at pxaudc? # USB logical device #cdcef* at usbf? # CDC ethernet function # USB bus support -#usb* at ohci? -#uhub* at usb? # USB Root Hub -#uhub* at uhub? # USB Hubs +usb* at ohci? +uhub* at usb? # USB Root Hub +uhub* at uhub? # USB Hubs # USB devices -#uhidev* at uhub? -#uhid* at uhidev? # USB Generic HID devices -#ukbd* at uhidev? # USB HID Keyboard devices -#wskbd* at ukbd? mux 1 +uhidev* at uhub? +uhid* at uhidev? # USB Generic HID devices +ukbd* at uhidev? # USB HID Keyboard devices +wskbd* at ukbd? mux 1 #ums* at uhub? # USB Mice #wsmouse* at ums? mux 0 #ulpt* at uhub? # USB Printer #atu* at uhub? # Atmel AT76C50x based 802.11b #aue* at uhub? # ADMtek AN986 Pegasus Ethernet #axe* at uhub? # ASIX Electronics AX88172 USB Ethernet -#cdce* at uhub? # CDC Ethernet -#cue* at uhub? # CATC USB-EL1201A based Ethernet -#kue* at uhub? # Kawasaki KL5KUSB101B based Ethernet +cdce* at uhub? # CDC Ethernet +cue* at uhub? # CATC USB-EL1201A based Ethernet +kue* at uhub? # Kawasaki KL5KUSB101B based Ethernet #udav* at uhub? # Davicom DM9601 based Ethernet -#ural* at uhub? # Ralink RT2500 +ural* at uhub? # Ralink RT2500 #url* at uhub? # Realtek RTL8150L based adapters -#wi* at uhub? # WaveLAN IEEE 802.11DS -#upl* at uhub? # Prolific PL2301/PL2302 host-to-host +wi* at uhub? # WaveLAN IEEE 802.11DS +upl* at uhub? # Prolific PL2301/PL2302 host-to-host #uscanner* at uhub? # USB Scanner driver #usscanner* at uhub? # USB SCSI scanners #scsibus* at usscanner? #uyap* at uhub? # Y@P firmware loader #ugen* at uhub? # USB Generic driver -#umass* at uhub? # USB Mass Storage devices -#scsibus* at umass? +umass* at uhub? # USB Mass Storage devices +scsibus* at umass? # SD/MMC support pxammc0 at pxaip? # MMC/SD/SDIO controller diff --git a/sys/arch/palm/conf/files.palm b/sys/arch/palm/conf/files.palm index 96efcf9..e1645aa 100644 --- a/sys/arch/palm/conf/files.palm +++ b/sys/arch/palm/conf/files.palm @@ -69,6 +69,9 @@ include "dev/pckbc/files.pckbc" # Include USB stuff include "dev/usb/files.usb" +attach pxaudc at pxaip with pxaudc_palm +file arch/palm/dev/palm_udc.c pxaudc_palm + # Bluetooth include "dev/bluetooth/files.bluetooth" diff --git a/sys/arch/palm/dev/palm_udc.c b/sys/arch/palm/dev/palm_udc.c new file mode 100644 index 0000000..d3ba182 --- /dev/null +++ b/sys/arch/palm/dev/palm_udc.c @@ -0,0 +1,93 @@ +/* $OpenBSD: scoop_mmc.c,v 1.1 2007/03/18 20:53:10 uwe Exp $ */ + +/* + * Copyright (c) 2007 Uwe Stuehler + * + * 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 pxammc(4) on Palm */ + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +int palm_udc_match(struct device *, void *, void *); +void palm_udc_attach(struct device *, struct device *, void *); +int palm_udc_detach(struct device *, int); +int palm_udc_is_host(void); + +struct cfattach pxaudc_palm_ca = { + sizeof(struct pxaudc_softc), + palm_udc_match, + palm_udc_attach, + palm_udc_detach, +}; + +int +palm_udc_match(struct device *parent, void *match, void *aux) +{ + if (mach_is_palmld) + return 0; + return pxaudc_match(); +} + +int +palm_udc_is_host(void) +{ + return 1; +} + +void +palm_udc_attach(struct device *parent, struct device *self, void *aux) +{ + struct pxaudc_softc *sc = (struct pxaudc_softc *)self; + + if (mach_is_palmtx) + sc->sc_gpio_detect = GPIO13_PALMTX_USB_DETECT; + else if (mach_is_palmt5 || mach_is_palmz72) + sc->sc_gpio_detect = GPIO15_USB_DETECT; + else { + printf(": No suitable GPIO setup found\n"); + return; + } + + sc->sc_gpio_detect_inv = 1; + sc->sc_gpio_pullup = GPIO95_USB_PULLUP; + sc->sc_gpio_pullup_inv = 0; + sc->sc_is_host = palm_udc_is_host; + + pxaudc_attach(sc, aux); +} + +int +palm_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/palm/include/conf.h b/sys/arch/palm/include/conf.h index f29b7fb..fe0d062 100644 --- a/sys/arch/palm/include/conf.h +++ b/sys/arch/palm/include/conf.h @@ -10,6 +10,7 @@ * PALM specific device includes go in here */ +#define CONF_HAVE_USB #define CONF_HAVE_WSCONS #include diff --git a/sys/arch/palm/include/machine_reg.h b/sys/arch/palm/include/machine_reg.h index 4da7560..fab9c8a 100644 --- a/sys/arch/palm/include/machine_reg.h +++ b/sys/arch/palm/include/machine_reg.h @@ -60,4 +60,8 @@ #define GPIO114_MMC_POWER 114 /* MMC power */ #define GPIO98_PALMZ72_MMC_POWER 98 /* Z72 MMC power */ +#define GPIO13_PALMTX_USB_DETECT 13 +#define GPIO15_USB_DETECT 15 +#define GPIO95_USB_PULLUP 95 + #endif /* _PALM_REG_H */ -- 1.6.3.4