From b1c2026746c97881fdd169f2d80edb131573d33b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Fri, 3 Oct 2014 07:29:42 +0000 Subject: [PATCH] tried to fix PCI - sometimes all three USB controllers are detected, sometimes not, sometimes there is even a PCI bus hang --- BaS_gcc/Makefile | 6 +- BaS_gcc/pci/ehci-hcd.c | 1835 +++++++++++----------- BaS_gcc/pci/ohci-hcd.c | 3105 +++++++++++++++++++------------------- BaS_gcc/pci/pci.c | 1361 +++++++++-------- BaS_gcc/sys/driver_mem.c | 432 +++--- BaS_gcc/sys/sysinit.c | 1539 ++++++++++--------- BaS_gcc/usb/usb.c | 1650 ++++++++++---------- BaS_gcc/usb/usb_hub.c | 833 +++++----- BaS_gcc/usb/usb_mouse.c | 368 ++--- 9 files changed, 5581 insertions(+), 5548 deletions(-) diff --git a/BaS_gcc/Makefile b/BaS_gcc/Makefile index 9fd36cb..333e431 100644 --- a/BaS_gcc/Makefile +++ b/BaS_gcc/Makefile @@ -32,19 +32,19 @@ NATIVECC=gcc INCLUDE=-Iinclude CFLAGS=-mcpu=5474 \ -Wall \ - -g3 \ + -g \ -fomit-frame-pointer \ -ffreestanding \ -fleading-underscore \ -Wa,--register-prefix-optional CFLAGS_OPTIMIZED = -mcpu=5474 \ -Wall \ - -g3 \ -O2 \ -fomit-frame-pointer \ -ffreestanding \ -fleading-underscore \ -Wa,--register-prefix-optional +LDFLAGS=-g TRGTDIRS= ./firebee ./m5484lite ./m54455 OBJDIRS=$(patsubst %, %/objs,$(TRGTDIRS)) @@ -271,7 +271,7 @@ endif $(1)_MAPFILE_RAM=$(1)/$$(basename $$(RAM_EXEC)).map $(1)/$$(RAM_EXEC): $(1)/$(LIBBAS) $(LDCSRC) $(CPP) $(INCLUDE) -DCOMPILE_RAM -DOBJDIR=$(1)/objs -P -DFORMAT_ELF=$(FORMAT_ELF) -D$$(MACHINE) $(LDCSRC) -o $(1)/$$(LDRFILE) - $(LD) -g --oformat $$(FORMAT) -Map $$($(1)_MAPFILE_RAM) --cref -T $(1)/$$(LDRFILE) -o $$@ + $(LD) $(LDFLAGS) --oformat $$(FORMAT) -Map $$($(1)_MAPFILE_RAM) --cref -T $(1)/$$(LDRFILE) -o $$@ ifeq ($(COMPILE_ELF),Y) $(OBJCOPY) -O srec $$@ $$(basename $$@).s19 else diff --git a/BaS_gcc/pci/ehci-hcd.c b/BaS_gcc/pci/ehci-hcd.c index eb393c5..4281e5e 100644 --- a/BaS_gcc/pci/ehci-hcd.c +++ b/BaS_gcc/pci/ehci-hcd.c @@ -29,11 +29,6 @@ #include "usb.h" #include "ehci.h" -//extern xQueueHandle queue_poll_hub; - -//#undef DEBUG -//#undef SHOW_INFO - static char ehci_inited; static int rootdev; @@ -41,69 +36,69 @@ static uint16_t portreset; static uint16_t companion; struct descriptor { - struct usb_hub_descriptor hub; - struct usb_device_descriptor device; - struct usb_linux_config_descriptor config; - struct usb_linux_interface_descriptor interface; - struct usb_endpoint_descriptor endpoint; + struct usb_hub_descriptor hub; + struct usb_device_descriptor device; + struct usb_linux_config_descriptor config; + struct usb_linux_interface_descriptor interface; + struct usb_endpoint_descriptor endpoint; } __attribute__ ((packed)); static struct descriptor rom_descriptor = { - { - 0x8, /* bDescLength */ - 0x29, /* bDescriptorType: hub descriptor */ - 2, /* bNrPorts -- runtime modified */ - 0, /* wHubCharacteristics */ - 0xff, /* bPwrOn2PwrGood */ - 0, /* bHubCntrCurrent */ - {}, /* Device removable */ - {} /* at most 7 ports! XXX */ - }, - { - 0x12, /* bLength */ - 1, /* bDescriptorType: UDESC_DEVICE */ - 0x0002, /* bcdUSB: v2.0 */ - 9, /* bDeviceClass: UDCLASS_HUB */ - 0, /* bDeviceSubClass: UDSUBCLASS_HUB */ - 1, /* bDeviceProtocol: UDPROTO_HSHUBSTT */ - 64, /* bMaxPacketSize: 64 bytes */ - 0x0000, /* idVendor */ - 0x0000, /* idProduct */ - 0x0001, /* bcdDevice */ - 1, /* iManufacturer */ - 2, /* iProduct */ - 0, /* iSerialNumber */ - 1 /* bNumConfigurations: 1 */ - }, - { - 0x9, - 2, /* bDescriptorType: UDESC_CONFIG */ - (0x19 << 8), /* cpu_to_le16(0x19), */ - 1, /* bNumInterface */ - 1, /* bConfigurationValue */ - 0, /* iConfiguration */ - 0x40, /* bmAttributes: UC_SELF_POWER */ - 0 /* bMaxPower */ - }, - { - 0x9, /* bLength */ - 4, /* bDescriptorType: UDESC_INTERFACE */ - 0, /* bInterfaceNumber */ - 0, /* bAlternateSetting */ - 1, /* bNumEndpoints */ - 9, /* bInterfaceClass: UICLASS_HUB */ - 0, /* bInterfaceSubClass: UISUBCLASS_HUB */ - 0, /* bInterfaceProtocol: UIPROTO_HSHUBSTT */ - 0 /* iInterface */ - }, - { - 0x7, /* bLength */ - 5, /* bDescriptorType: UDESC_ENDPOINT */ - 0x81, /* bEndpointAddress: UE_DIR_IN | EHCI_INTR_ENDPT */ - 3, /* bmAttributes: UE_INTERRUPT */ - 8, 0, /* wMaxPacketSize */ - 255 /* bInterval */ - }, + { + 0x8, /* bDescLength */ + 0x29, /* bDescriptorType: hub descriptor */ + 2, /* bNrPorts -- runtime modified */ + 0, /* wHubCharacteristics */ + 0xff, /* bPwrOn2PwrGood */ + 0, /* bHubCntrCurrent */ + {}, /* Device removable */ + {} /* at most 7 ports! XXX */ + }, + { + 0x12, /* bLength */ + 1, /* bDescriptorType: UDESC_DEVICE */ + 0x0002, /* bcdUSB: v2.0 */ + 9, /* bDeviceClass: UDCLASS_HUB */ + 0, /* bDeviceSubClass: UDSUBCLASS_HUB */ + 1, /* bDeviceProtocol: UDPROTO_HSHUBSTT */ + 64, /* bMaxPacketSize: 64 bytes */ + 0x0000, /* idVendor */ + 0x0000, /* idProduct */ + 0x0001, /* bcdDevice */ + 1, /* iManufacturer */ + 2, /* iProduct */ + 0, /* iSerialNumber */ + 1 /* bNumConfigurations: 1 */ + }, + { + 0x9, + 2, /* bDescriptorType: UDESC_CONFIG */ + (0x19 << 8), /* cpu_to_le16(0x19), */ + 1, /* bNumInterface */ + 1, /* bConfigurationValue */ + 0, /* iConfiguration */ + 0x40, /* bmAttributes: UC_SELF_POWER */ + 0 /* bMaxPower */ + }, + { + 0x9, /* bLength */ + 4, /* bDescriptorType: UDESC_INTERFACE */ + 0, /* bInterfaceNumber */ + 0, /* bAlternateSetting */ + 1, /* bNumEndpoints */ + 9, /* bInterfaceClass: UICLASS_HUB */ + 0, /* bInterfaceSubClass: UISUBCLASS_HUB */ + 0, /* bInterfaceProtocol: UIPROTO_HSHUBSTT */ + 0 /* iInterface */ + }, + { + 0x7, /* bLength */ + 5, /* bDescriptorType: UDESC_ENDPOINT */ + 0x81, /* bEndpointAddress: UE_DIR_IN | EHCI_INTR_ENDPT */ + 3, /* bmAttributes: UE_INTERRUPT */ + 8, 0, /* wMaxPacketSize */ + 255 /* bInterval */ + }, }; #if defined(CONFIG_EHCI_IS_TDI) @@ -114,69 +109,67 @@ static struct descriptor rom_descriptor = { struct pci_device_id ehci_usb_pci_table[] = { - { - PCI_VENDOR_ID_NEC, - PCI_DEVICE_ID_NEC_USB_2, - PCI_ANY_ID, - PCI_ANY_ID, - PCI_CLASS_SERIAL_USB_EHCI, - 0, - 0 - }, /* NEC PCI OHCI module ids */ - { - PCI_VENDOR_ID_PHILIPS, - PCI_DEVICE_ID_PHILIPS_ISP1561_2, - PCI_ANY_ID, - PCI_ANY_ID, - PCI_CLASS_SERIAL_USB_EHCI, - 0, - 0 - }, /* Philips 1561 PCI OHCI module ids */ - /* Please add supported PCI OHCI controller ids here */ - { - 0, - 0, - 0, - 0, - 0, - 0, - 0 - } + { + PCI_VENDOR_ID_NEC, + PCI_DEVICE_ID_NEC_USB_2, + PCI_ANY_ID, + PCI_ANY_ID, + PCI_CLASS_SERIAL_USB_EHCI, + 0, + 0 + }, /* NEC PCI OHCI module ids */ + { + PCI_VENDOR_ID_PHILIPS, + PCI_DEVICE_ID_PHILIPS_ISP1561_2, + PCI_ANY_ID, + PCI_ANY_ID, + PCI_CLASS_SERIAL_USB_EHCI, + 0, + 0 + }, /* Philips 1561 PCI OHCI module ids */ + /* Please add supported PCI OHCI controller ids here */ + { + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } }; static struct ehci { - /* ------- common part -------- */ - long handle; /* PCI BIOS */ - const struct pci_device_id *ent; - int usbnum; + /* ------- common part -------- */ + long handle; /* PCI BIOS */ + const struct pci_device_id *ent; + int usbnum; /* ---- end of common part ---- */ - int big_endian; /* PCI BIOS */ - struct ehci_hccr *hccr; /* R/O registers, not need for volatile */ - volatile struct ehci_hcor *hcor; - struct QH *qh_list_unaligned; - struct QH *qh_list; - struct QH *qh_unaligned; - struct QH *qh; - struct qTD *td_unaligned[3]; - struct qTD *td[3]; - struct descriptor *descriptor; - int irq; - uint32_t dma_offset; - const char *slot_name; + int big_endian; /* PCI BIOS */ + struct ehci_hccr *hccr; /* R/O registers, not need for volatile */ + volatile struct ehci_hcor *hcor; + struct QH *qh_list_unaligned; + struct QH *qh_list; + struct QH *qh_unaligned; + struct QH *qh; + struct qTD *td_unaligned[3]; + struct qTD *td[3]; + struct descriptor *descriptor; + int irq; + uint32_t dma_offset; + const char *slot_name; } gehci; -//#define DEBUG -//#define SHOW_INFO - +#define DEBUG #ifdef DEBUG -#define debug(format, arg...) xprintf("DEBUG: " format "\r\n", ## arg) +#define dbg(format, arg...) xprintf("DEBUG: " format, __FUNCTION__, ## arg) #else -#define debug(format, arg...) do {} while (0) +#define dbg(format, arg...) do {} while (0) #endif /* DEBUG */ #define err xprintf #ifdef SHOW_INFO -#define info(format, arg...) xprintf("INFO: " format "\r\n", ## arg) +#define info(format, arg...) xprintf("INFO: " format, __FUNCTION__, ## arg) #else #define info(format, arg...) do {} while (0) #endif @@ -184,84 +177,84 @@ static struct ehci static void cache_qtd(struct qTD *qtd, int flush) { - flush_and_invalidate_caches(); + flush_and_invalidate_caches(); } static inline struct QH *qh_addr(struct QH *qh) { - return (struct QH *)((uint32_t)qh & 0xffffffe0); + return (struct QH *)((uint32_t)qh & 0xffffffe0); } static void cache_qh(struct QH *qh, int flush) { - struct qTD *qtd; - struct qTD *next; - static struct qTD *first_qtd; + struct qTD *qtd; + struct qTD *next; + static struct qTD *first_qtd; - /* Walk the QH list and flush/invalidate all entries */ - while(1) - { - flush_and_invalidate_caches(); - if ((uint32_t)qh & QH_LINK_TYPE_QH) - break; - qh = qh_addr(qh); - qh = (struct QH *)(swpl(qh->qh_link) + gehci.dma_offset); - } - qh = qh_addr(qh); + /* Walk the QH list and flush/invalidate all entries */ + while(1) + { + flush_and_invalidate_caches(); + if ((uint32_t)qh & QH_LINK_TYPE_QH) + break; + qh = qh_addr(qh); + qh = (struct QH *)(swpl(qh->qh_link) + gehci.dma_offset); + } + qh = qh_addr(qh); - /* Save first qTD pointer, needed for invalidating pass on this QH */ - if (flush) - { - qtd = (struct qTD *)(swpl(*(uint32_t *)&qh->qh_overlay) & 0xffffffe0); - if (qtd != NULL) - qtd = (struct qTD *)(gehci.dma_offset + (uint32_t)qtd); - first_qtd = qtd; - } - else - qtd = first_qtd; + /* Save first qTD pointer, needed for invalidating pass on this QH */ + if (flush) + { + qtd = (struct qTD *)(swpl(*(uint32_t *)&qh->qh_overlay) & 0xffffffe0); + if (qtd != NULL) + qtd = (struct qTD *)(gehci.dma_offset + (uint32_t)qtd); + first_qtd = qtd; + } + else + qtd = first_qtd; - /* Walk the qTD list and flush/invalidate all entries */ - while(1) - { - if (qtd == NULL) - break; - cache_qtd(qtd, flush); - next = (struct qTD *)((uint32_t)swpl(qtd->qt_next) & 0xffffffe0); - if (next != NULL) - next = (struct qTD *)(gehci.dma_offset + (uint32_t)next); - if (next == qtd) - break; - qtd = next; - } + /* Walk the qTD list and flush/invalidate all entries */ + while(1) + { + if (qtd == NULL) + break; + cache_qtd(qtd, flush); + next = (struct qTD *)((uint32_t)swpl(qtd->qt_next) & 0xffffffe0); + if (next != NULL) + next = (struct qTD *)(gehci.dma_offset + (uint32_t)next); + if (next == qtd) + break; + qtd = next; + } } static inline void ehci_flush_dcache(struct QH *qh) { - cache_qh(qh, 1); + cache_qh(qh, 1); } static inline void ehci_invalidate_dcache(struct QH *qh) { - cache_qh(qh, 0); + cache_qh(qh, 0); } static int handshake(uint32_t *ptr, uint32_t mask, uint32_t done, int usec) { - uint32_t result; + uint32_t result; - do - { - result = ehci_readl(ptr); - if (result == ~(uint32_t)0) - return -1; - result &= mask; - if (result == done) - return 0; - wait(1); - usec--; - } - while (usec > 0); - return -1; + do + { + result = ehci_readl(ptr); + if (result == ~(uint32_t)0) + return -1; + result &= mask; + if (result == done) + return 0; + wait(1); + usec--; + } + while (usec > 0); + return -1; } static void ehci_free(void *p, size_t sz) @@ -270,891 +263,891 @@ static void ehci_free(void *p, size_t sz) static int ehci_reset(void) { - uint32_t cmd; - uint32_t tmp; - uint32_t *reg_ptr; - int ret = 0; + uint32_t cmd; + uint32_t tmp; + uint32_t *reg_ptr; + int ret = 0; - if ((gehci.ent->vendor == PCI_VENDOR_ID_NEC) && (gehci.ent->device == PCI_DEVICE_ID_NEC_USB_2)) - { - debug("ehci_reset set 48MHz clock\r\n"); - pci_write_config_longword(gehci.handle, 0xE4, 0x20); // oscillator - } - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - debug("%s cmd: 0x%08x\r\n", __FUNCTION__, cmd); - cmd |= CMD_RESET; - ehci_writel(&gehci.hcor->or_usbcmd, cmd); - ret = handshake((uint32_t *) &gehci.hcor->or_usbcmd, CMD_RESET, 0, 250); + if ((gehci.ent->vendor == PCI_VENDOR_ID_NEC) && (gehci.ent->device == PCI_DEVICE_ID_NEC_USB_2)) + { + dbg("ehci_reset set 48MHz clock\r\n"); + pci_write_config_longword(gehci.handle, 0xE4, 0x20); // oscillator + } + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + dbg("%s cmd: 0x%08x\r\n", __FUNCTION__, cmd); + cmd |= CMD_RESET; + ehci_writel(&gehci.hcor->or_usbcmd, cmd); + ret = handshake((uint32_t *) &gehci.hcor->or_usbcmd, CMD_RESET, 0, 250); - if (ret < 0) - { - err("EHCI fail to reset"); - goto out; - } + if (ret < 0) + { + err("EHCI fail to reset"); + goto out; + } - if (ehci_is_TDI()) - { - reg_ptr = (uint32_t *)((u8 *)gehci.hcor + USBMODE); - tmp = ehci_readl(reg_ptr); - tmp |= USBMODE_CM_HC; - tmp |= USBMODE_BE; - ehci_writel(reg_ptr, tmp); - } + if (ehci_is_TDI()) + { + reg_ptr = (uint32_t *)((u8 *)gehci.hcor + USBMODE); + tmp = ehci_readl(reg_ptr); + tmp |= USBMODE_CM_HC; + tmp |= USBMODE_BE; + ehci_writel(reg_ptr, tmp); + } out: - return ret; + return ret; } static void *ehci_alloc(size_t sz, size_t align) { - static int ntds; - void *p; - switch(sz) - { - case sizeof(struct QH): - p = gehci.qh; - ntds = 0; - break; + static int ntds; + void *p; + switch(sz) + { + case sizeof(struct QH): + p = gehci.qh; + ntds = 0; + break; - case sizeof(struct qTD): - if (ntds == 3) - { - debug("out of TDs\r\n"); - return NULL; - } - p = gehci.td[ntds]; - ntds++; - break; + case sizeof(struct qTD): + if (ntds == 3) + { + dbg("out of TDs\r\n"); + return NULL; + } + p = gehci.td[ntds]; + ntds++; + break; - default: - debug("unknown allocation size\r\n"); - return NULL; - } - memset(p, sz, 0); - return p; + default: + dbg("unknown allocation size\r\n"); + return NULL; + } + memset(p, sz, 0); + return p; } static int ehci_td_buffer(struct qTD *td, void *buf, size_t sz) { - uint32_t addr; - uint32_t delta; - uint32_t next; - int idx; + uint32_t addr; + uint32_t delta; + uint32_t next; + int idx; - addr = (uint32_t)buf; - idx = 0; + addr = (uint32_t)buf; + idx = 0; - while (idx < 5) - { - td->qt_buffer[idx] = swpl(addr - gehci.dma_offset); - next = (addr + 4096) & ~4095; - delta = next - addr; - if (delta >= sz) - break; - sz -= delta; - addr = next; - idx++; - } + while (idx < 5) + { + td->qt_buffer[idx] = swpl(addr - gehci.dma_offset); + next = (addr + 4096) & ~4095; + delta = next - addr; + if (delta >= sz) + break; + sz -= delta; + addr = next; + idx++; + } - if (idx == 5) - { - debug("out of buffer pointers (%u bytes left)\r\n", sz); - return -1; - } - return 0; + if (idx == 5) + { + dbg("out of buffer pointers (%u bytes left)\r\n", sz); + return -1; + } + return 0; } static int ehci_submit_async(struct usb_device *dev, uint32_t pipe, void *buffer, int length, struct devrequest *req) { - struct QH *qh; - struct qTD *td; - volatile struct qTD *vtd; - uint32_t ts; - uint32_t *tdp; - uint32_t endpt, token, usbsts; - uint32_t c, toggle; - uint32_t cmd; - int ret = 0; + struct QH *qh; + struct qTD *td; + volatile struct qTD *vtd; + uint32_t ts; + uint32_t *tdp; + uint32_t endpt, token, usbsts; + uint32_t c, toggle; + uint32_t cmd; + int ret = 0; - debug("%s: dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\r\n", __FUNCTION__, dev, pipe, buffer, length, req); + dbg("%s: dev=%p, pipe=%lx, buffer=%p, length=%d, req=%p\r\n", __FUNCTION__, dev, pipe, buffer, length, req); - if (req != NULL) - debug("ehci_submit_async req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\r\n", - req->request, req->request, - req->requesttype, req->requesttype, - swpw(req->value), swpw(req->value), swpw(req->index)); + if (req != NULL) + dbg("ehci_submit_async req=%u (%#x), type=%u (%#x), value=%u (%#x), index=%u\r\n", + req->request, req->request, + req->requesttype, req->requesttype, + swpw(req->value), swpw(req->value), swpw(req->index)); - qh = ehci_alloc(sizeof(struct QH), 32); - if (qh == NULL) - { - debug("unable to allocate QH\r\n"); - return -1; - } - qh->qh_link = swpl(((uint32_t) gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); + qh = ehci_alloc(sizeof(struct QH), 32); + if (qh == NULL) + { + dbg("unable to allocate QH\r\n"); + return -1; + } + qh->qh_link = swpl(((uint32_t) gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); - c = (usb_pipespeed(pipe) != USB_SPEED_HIGH && usb_pipeendpoint(pipe) == 0) ? 1 : 0; - endpt = (8 << 28) | - (c << 27) | - (usb_maxpacket(dev, pipe) << 16) | - (0 << 15) | - (1 << 14) | - (usb_pipespeed(pipe) << 12) | - (usb_pipeendpoint(pipe) << 8) | - (0 << 7) | - (usb_pipedevice(pipe) << 0); - qh->qh_endpt1 = swpl(endpt); - endpt = (1 << 30) | - (dev->portnr << 23) | - (dev->parent->devnum << 16) | - (0 << 8) | - (0 << 0); - qh->qh_endpt2 = swpl(endpt); - qh->qh_overlay.qt_next = swpl(QT_NEXT_TERMINATE); - qh->qh_overlay.qt_altnext = swpl(QT_NEXT_TERMINATE); - td = NULL; - tdp = &qh->qh_overlay.qt_next; - toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); + c = (usb_pipespeed(pipe) != USB_SPEED_HIGH && usb_pipeendpoint(pipe) == 0) ? 1 : 0; + endpt = (8 << 28) | + (c << 27) | + (usb_maxpacket(dev, pipe) << 16) | + (0 << 15) | + (1 << 14) | + (usb_pipespeed(pipe) << 12) | + (usb_pipeendpoint(pipe) << 8) | + (0 << 7) | + (usb_pipedevice(pipe) << 0); + qh->qh_endpt1 = swpl(endpt); + endpt = (1 << 30) | + (dev->portnr << 23) | + (dev->parent->devnum << 16) | + (0 << 8) | + (0 << 0); + qh->qh_endpt2 = swpl(endpt); + qh->qh_overlay.qt_next = swpl(QT_NEXT_TERMINATE); + qh->qh_overlay.qt_altnext = swpl(QT_NEXT_TERMINATE); + td = NULL; + tdp = &qh->qh_overlay.qt_next; + toggle = usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); - if (req != NULL) - { - td = ehci_alloc(sizeof(struct qTD), 32); - if (td == NULL) - { - debug("unable to allocate SETUP td\r\n"); - goto fail; - } - td->qt_next = swpl(QT_NEXT_TERMINATE); - td->qt_altnext = swpl(QT_NEXT_TERMINATE); - token = (0 << 31) | (sizeof(*req) << 16) | (0 << 15) | (0 << 12) | (3 << 10) | (2 << 8) | (0x80 << 0); - td->qt_token = swpl(token); - if (ehci_td_buffer(td, req, sizeof(*req)) != 0) - { - debug("unable construct SETUP td\r\n"); - ehci_free(td, sizeof(*td)); - goto fail; - } - *tdp = swpl((uint32_t)td - gehci.dma_offset); - tdp = &td->qt_next; - toggle = 1; - } + if (req != NULL) + { + td = ehci_alloc(sizeof(struct qTD), 32); + if (td == NULL) + { + dbg("unable to allocate SETUP td\r\n"); + goto fail; + } + td->qt_next = swpl(QT_NEXT_TERMINATE); + td->qt_altnext = swpl(QT_NEXT_TERMINATE); + token = (0 << 31) | (sizeof(*req) << 16) | (0 << 15) | (0 << 12) | (3 << 10) | (2 << 8) | (0x80 << 0); + td->qt_token = swpl(token); + if (ehci_td_buffer(td, req, sizeof(*req)) != 0) + { + dbg("unable construct SETUP td\r\n"); + ehci_free(td, sizeof(*td)); + goto fail; + } + *tdp = swpl((uint32_t)td - gehci.dma_offset); + tdp = &td->qt_next; + toggle = 1; + } - if (length > 0 || req == NULL) - { - td = ehci_alloc(sizeof(struct qTD), 32); - if (td == NULL) - { - debug("unable to allocate DATA td\r\n"); - goto fail; - } - td->qt_next = swpl(QT_NEXT_TERMINATE); - td->qt_altnext = swpl(QT_NEXT_TERMINATE); - token = (toggle << 31) | (length << 16) | ((req == NULL ? 1 : 0) << 15) | (0 << 12) | (3 << 10) | ((usb_pipein(pipe) ? 1 : 0) << 8) | (0x80 << 0); - td->qt_token = swpl(token); - if (ehci_td_buffer(td, buffer, length) != 0) - { - debug("unable construct DATA td\r\n"); - ehci_free(td, sizeof(*td)); - goto fail; - } - *tdp = swpl((uint32_t)td - gehci.dma_offset); - tdp = &td->qt_next; - } + if (length > 0 || req == NULL) + { + td = ehci_alloc(sizeof(struct qTD), 32); + if (td == NULL) + { + dbg("unable to allocate DATA td\r\n"); + goto fail; + } + td->qt_next = swpl(QT_NEXT_TERMINATE); + td->qt_altnext = swpl(QT_NEXT_TERMINATE); + token = (toggle << 31) | (length << 16) | ((req == NULL ? 1 : 0) << 15) | (0 << 12) | (3 << 10) | ((usb_pipein(pipe) ? 1 : 0) << 8) | (0x80 << 0); + td->qt_token = swpl(token); + if (ehci_td_buffer(td, buffer, length) != 0) + { + dbg("unable construct DATA td\r\n"); + ehci_free(td, sizeof(*td)); + goto fail; + } + *tdp = swpl((uint32_t)td - gehci.dma_offset); + tdp = &td->qt_next; + } - if (req != NULL) - { - td = ehci_alloc(sizeof(struct qTD), 32); - if (td == NULL) - { - debug("unable to allocate ACK td\r\n"); - goto fail; - } - td->qt_next = swpl(QT_NEXT_TERMINATE); - td->qt_altnext = swpl(QT_NEXT_TERMINATE); - token = (toggle << 31) | (0 << 16) | (1 << 15) | (0 << 12) | (3 << 10) | ((usb_pipein(pipe) ? 0 : 1) << 8) | (0x80 << 0); - td->qt_token = swpl(token); - *tdp = swpl((uint32_t)td - gehci.dma_offset); - tdp = &td->qt_next; - } + if (req != NULL) + { + td = ehci_alloc(sizeof(struct qTD), 32); + if (td == NULL) + { + dbg("unable to allocate ACK td\r\n"); + goto fail; + } + td->qt_next = swpl(QT_NEXT_TERMINATE); + td->qt_altnext = swpl(QT_NEXT_TERMINATE); + token = (toggle << 31) | (0 << 16) | (1 << 15) | (0 << 12) | (3 << 10) | ((usb_pipein(pipe) ? 0 : 1) << 8) | (0x80 << 0); + td->qt_token = swpl(token); + *tdp = swpl((uint32_t)td - gehci.dma_offset); + tdp = &td->qt_next; + } - gehci.qh_list->qh_link = swpl(((uint32_t)qh - gehci.dma_offset) | QH_LINK_TYPE_QH); - /* Flush dcache */ - ehci_flush_dcache(gehci.qh_list); - usbsts = ehci_readl(&gehci.hcor->or_usbsts); - ehci_writel(&gehci.hcor->or_usbsts, (usbsts & 0x3f)); - /* Enable async. schedule. */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - cmd |= CMD_ASE; - ehci_writel(&gehci.hcor->or_usbcmd, cmd); + gehci.qh_list->qh_link = swpl(((uint32_t)qh - gehci.dma_offset) | QH_LINK_TYPE_QH); + /* Flush dcache */ + ehci_flush_dcache(gehci.qh_list); + usbsts = ehci_readl(&gehci.hcor->or_usbsts); + ehci_writel(&gehci.hcor->or_usbsts, (usbsts & 0x3f)); + /* Enable async. schedule. */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + cmd |= CMD_ASE; + ehci_writel(&gehci.hcor->or_usbcmd, cmd); - ret = handshake((uint32_t *)&gehci.hcor->or_usbsts, STD_ASS, STD_ASS, 100 * 1000); - if (ret < 0) - { - err("EHCI fail timeout STD_ASS set (usbsts=%#x)", ehci_readl(&gehci.hcor->or_usbsts)); - goto fail; - } - /* Wait for TDs to be processed. */ - ts = 0; - vtd = td; - do - { - /* Invalidate dcache */ - ehci_invalidate_dcache(gehci.qh_list); - token = swpl(vtd->qt_token); - if (!(token & 0x80)) - break; - wait(1 * 1000); - ts++; - } - while(ts < 1000); - /* Disable async schedule. */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - cmd &= ~CMD_ASE; - ehci_writel(&gehci.hcor->or_usbcmd, cmd); - ret = handshake((uint32_t *)&gehci.hcor->or_usbsts, STD_ASS, 0, 100 * 1000); - if (ret < 0) - { - err("EHCI fail timeout STD_ASS reset (usbsts=%#x)", ehci_readl(&gehci.hcor->or_usbsts)); - goto fail; - } - gehci.qh_list->qh_link = swpl(((uint32_t)gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); + ret = handshake((uint32_t *)&gehci.hcor->or_usbsts, STD_ASS, STD_ASS, 100 * 1000); + if (ret < 0) + { + err("EHCI fail timeout STD_ASS set (usbsts=%#x)", ehci_readl(&gehci.hcor->or_usbsts)); + goto fail; + } + /* Wait for TDs to be processed. */ + ts = 0; + vtd = td; + do + { + /* Invalidate dcache */ + ehci_invalidate_dcache(gehci.qh_list); + token = swpl(vtd->qt_token); + if (!(token & 0x80)) + break; + wait(1 * 1000); + ts++; + } + while(ts < 1000); + /* Disable async schedule. */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + cmd &= ~CMD_ASE; + ehci_writel(&gehci.hcor->or_usbcmd, cmd); + ret = handshake((uint32_t *)&gehci.hcor->or_usbsts, STD_ASS, 0, 100 * 1000); + if (ret < 0) + { + err("EHCI fail timeout STD_ASS reset (usbsts=%#x)", ehci_readl(&gehci.hcor->or_usbsts)); + goto fail; + } + gehci.qh_list->qh_link = swpl(((uint32_t)gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); - token = swpl(qh->qh_overlay.qt_token); - if (!(token & 0x80)) - { - debug("TOKEN=%#x\r\n", token); - switch(token & 0xfc) - { - case 0: - toggle = token >> 31; - usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), toggle); - dev->status = 0; - break; + token = swpl(qh->qh_overlay.qt_token); + if (!(token & 0x80)) + { + dbg("TOKEN=%#x\r\n", token); + switch(token & 0xfc) + { + case 0: + toggle = token >> 31; + usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), toggle); + dev->status = 0; + break; - case 0x40: - dev->status = USB_ST_STALLED; - break; + case 0x40: + dev->status = USB_ST_STALLED; + break; - case 0xa0: - case 0x20: - dev->status = USB_ST_BUF_ERR; - break; + case 0xa0: + case 0x20: + dev->status = USB_ST_BUF_ERR; + break; - case 0x50: - case 0x10: - dev->status = USB_ST_BABBLE_DET; - break; + case 0x50: + case 0x10: + dev->status = USB_ST_BABBLE_DET; + break; - default: - dev->status = USB_ST_CRC_ERR; - break; - } - dev->act_len = length - ((token >> 16) & 0x7fff); - } - else - { - dev->act_len = 0; - debug("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\r\n", - dev->devnum, ehci_readl(&gehci.hcor->or_usbsts), - ehci_readl(&gehci.hcor->or_portsc[0]), ehci_readl(&gehci.hcor->or_portsc[1])); - } - return (dev->status != USB_ST_NOT_PROC) ? 0 : -1; + default: + dev->status = USB_ST_CRC_ERR; + break; + } + dev->act_len = length - ((token >> 16) & 0x7fff); + } + else + { + dev->act_len = 0; + dbg("dev=%u, usbsts=%#x, p[1]=%#x, p[2]=%#x\r\n", + dev->devnum, ehci_readl(&gehci.hcor->or_usbsts), + ehci_readl(&gehci.hcor->or_portsc[0]), ehci_readl(&gehci.hcor->or_portsc[1])); + } + return (dev->status != USB_ST_NOT_PROC) ? 0 : -1; fail: - td = (void *) swpl(qh->qh_overlay.qt_next); - if (td != (void *)QT_NEXT_TERMINATE) - td = (struct qTD *)(gehci.dma_offset + (uint32_t)td); - while(td != (void *)QT_NEXT_TERMINATE) - { - qh->qh_overlay.qt_next = td->qt_next; - ehci_free(td, sizeof(*td)); - td = (void *)swpl(qh->qh_overlay.qt_next); - if (td != (void *)QT_NEXT_TERMINATE) - td = (struct qTD *)(gehci.dma_offset + (uint32_t)td); - } - ehci_free(qh, sizeof(*qh)); - if (ehci_readl(&gehci.hcor->or_usbsts) & STS_HSE) /* Host System Error */ - { - unsigned short status = pci_read_config_word(gehci.handle, PCISR); - err("EHCI Host System Error, controller usb-%s disabled\r\n(SR:0x%04X%s%s%s%s%s%s)", - gehci.slot_name, status & 0xFFFF, status & 0x8000 ? ", Parity error" : "", - status & 0x4000 ? ", Signaled system error" : "", - status & 0x2000 ? ", Received master abort" : "", - status & 0x1000 ? ", Received target abort" : "", - status & 0x800 ? ", Signaled target abort" : "", - status & 0x100 ? ", Data parity error" : ""); - } - return -1; + td = (void *) swpl(qh->qh_overlay.qt_next); + if (td != (void *)QT_NEXT_TERMINATE) + td = (struct qTD *)(gehci.dma_offset + (uint32_t)td); + while(td != (void *)QT_NEXT_TERMINATE) + { + qh->qh_overlay.qt_next = td->qt_next; + ehci_free(td, sizeof(*td)); + td = (void *)swpl(qh->qh_overlay.qt_next); + if (td != (void *)QT_NEXT_TERMINATE) + td = (struct qTD *)(gehci.dma_offset + (uint32_t)td); + } + ehci_free(qh, sizeof(*qh)); + if (ehci_readl(&gehci.hcor->or_usbsts) & STS_HSE) /* Host System Error */ + { + unsigned short status = pci_read_config_word(gehci.handle, PCISR); + err("EHCI Host System Error, controller usb-%s disabled\r\n(SR:0x%04X%s%s%s%s%s%s)", + gehci.slot_name, status & 0xFFFF, status & 0x8000 ? ", Parity error" : "", + status & 0x4000 ? ", Signaled system error" : "", + status & 0x2000 ? ", Received master abort" : "", + status & 0x1000 ? ", Received target abort" : "", + status & 0x800 ? ", Signaled target abort" : "", + status & 0x100 ? ", Data parity error" : ""); + } + return -1; } static inline int min3(int a, int b, int c) { - if (b < a) - a = b; - if (c < a) - a = c; - return a; + if (b < a) + a = b; + if (c < a) + a = c; + return a; } static int ehci_submit_root(struct usb_device *dev, uint32_t pipe, void *buffer, int length, struct devrequest *req) { - uint8_t tmpbuf[4]; - u16 typeReq; - void *srcptr = NULL; - int len, srclen; - uint32_t reg; - uint32_t *status_reg; - if (swpw(req->index) > CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) - { - err("the requested port(%d) is not configured\r\n", swpw(req->index) - 1); - return -1; - } - status_reg = (uint32_t *)&gehci.hcor->or_portsc[swpw(req->index) - 1]; - srclen = 0; - debug("ehci_submit_root req=%u (%#x), type=%u (%#x), value=%u, index=%u\r\n", - req->request, req->request, req->requesttype, req->requesttype, swpw(req->value), swpw(req->index)); - typeReq = req->request | req->requesttype << 8; - switch(typeReq) - { - case DeviceRequest | USB_REQ_GET_DESCRIPTOR: - switch(swpw(req->value) >> 8) - { - case USB_DT_DEVICE: - debug("USB_DT_DEVICE request\r\n"); - srcptr = &gehci.descriptor->device; - srclen = 0x12; - break; + uint8_t tmpbuf[4]; + u16 typeReq; + void *srcptr = NULL; + int len, srclen; + uint32_t reg; + uint32_t *status_reg; + if (swpw(req->index) > CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) + { + err("the requested port(%d) is not configured\r\n", swpw(req->index) - 1); + return -1; + } + status_reg = (uint32_t *)&gehci.hcor->or_portsc[swpw(req->index) - 1]; + srclen = 0; + dbg("ehci_submit_root req=%u (%#x), type=%u (%#x), value=%u, index=%u\r\n", + req->request, req->request, req->requesttype, req->requesttype, swpw(req->value), swpw(req->index)); + typeReq = req->request | req->requesttype << 8; + switch(typeReq) + { + case DeviceRequest | USB_REQ_GET_DESCRIPTOR: + switch(swpw(req->value) >> 8) + { + case USB_DT_DEVICE: + dbg("USB_DT_DEVICE request\r\n"); + srcptr = &gehci.descriptor->device; + srclen = 0x12; + break; - case USB_DT_CONFIG: - debug("USB_DT_CONFIG config\r\n"); - srcptr = &gehci.descriptor->config; - srclen = 0x19; - break; + case USB_DT_CONFIG: + dbg("USB_DT_CONFIG config\r\n"); + srcptr = &gehci.descriptor->config; + srclen = 0x19; + break; - case USB_DT_STRING: - debug("USB_DT_STRING config\r\n"); - switch(swpw(req->value) & 0xff) - { - case 0: /* Language */ - srcptr = "\4\3\1\0"; - srclen = 4; - break; + case USB_DT_STRING: + dbg("USB_DT_STRING config\r\n"); + switch(swpw(req->value) & 0xff) + { + case 0: /* Language */ + srcptr = "\4\3\1\0"; + srclen = 4; + break; - case 1: /* Vendor */ - srcptr = "\2\3"; - srclen = 2; - break; + case 1: /* Vendor */ + srcptr = "\2\3"; + srclen = 2; + break; - case 2: /* Product */ - srcptr = "\34\3E\0H\0C\0I\0 \0R\0o\0o\0t\0 \0H\0u\0b\0"; - srclen = 28; - break; + case 2: /* Product */ + srcptr = "\34\3E\0H\0C\0I\0 \0R\0o\0o\0t\0 \0H\0u\0b\0"; + srclen = 28; + break; - default: - debug("unknown value DT_STRING %x\r\n", - swpw(req->value)); - goto unknown; - } - break; - default: - debug("unknown value %x\r\n", swpw(req->value)); - goto unknown; - } - break; + default: + dbg("unknown value DT_STRING %x\r\n", + swpw(req->value)); + goto unknown; + } + break; + default: + dbg("unknown value %x\r\n", swpw(req->value)); + goto unknown; + } + break; - case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8): - switch(swpw(req->value) >> 8) - { - case USB_DT_HUB: - debug("USB_DT_HUB config\r\n"); - srcptr = &gehci.descriptor->hub; - srclen = 0x8; - break; + case USB_REQ_GET_DESCRIPTOR | ((USB_DIR_IN | USB_RT_HUB) << 8): + switch(swpw(req->value) >> 8) + { + case USB_DT_HUB: + dbg("USB_DT_HUB config\r\n"); + srcptr = &gehci.descriptor->hub; + srclen = 0x8; + break; - default: - debug("unknown value %x\r\n", swpw(req->value)); - goto unknown; - } - break; + default: + dbg("unknown value %x\r\n", swpw(req->value)); + goto unknown; + } + break; - case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8): - debug("USB_REQ_SET_ADDRESS\r\n"); - rootdev = swpw(req->value); - break; + case USB_REQ_SET_ADDRESS | (USB_RECIP_DEVICE << 8): + dbg("USB_REQ_SET_ADDRESS\r\n"); + rootdev = swpw(req->value); + break; - case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: - debug("USB_REQ_SET_CONFIGURATION\r\n"); - /* Nothing to do */ - break; + case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: + dbg("USB_REQ_SET_CONFIGURATION\r\n"); + /* Nothing to do */ + break; - case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8): - tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */ - tmpbuf[1] = 0; - srcptr = tmpbuf; - srclen = 2; - break; + case USB_REQ_GET_STATUS | ((USB_DIR_IN | USB_RT_HUB) << 8): + tmpbuf[0] = 1; /* USB_STATUS_SELFPOWERED */ + tmpbuf[1] = 0; + srcptr = tmpbuf; + srclen = 2; + break; - case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8): - memset(tmpbuf, 0, 4); - reg = ehci_readl(status_reg); + case USB_REQ_GET_STATUS | ((USB_RT_PORT | USB_DIR_IN) << 8): + memset(tmpbuf, 0, 4); + reg = ehci_readl(status_reg); - if ((reg & EHCI_PS_PR) && (portreset & (1 << swpw(req->index)))) - { - int ret; - /* force reset to complete */ - reg = reg & ~(EHCI_PS_PR | EHCI_PS_CLEAR); - ehci_writel(status_reg, reg); - ret = handshake(status_reg, EHCI_PS_PR, 0, 2 * 1000); - if (!ret) - { - tmpbuf[0] |= USB_PORT_STAT_RESET; - reg = ehci_readl(status_reg); - } - else - err("port(%d) reset error", swpw(req->index) - 1); - } + if ((reg & EHCI_PS_PR) && (portreset & (1 << swpw(req->index)))) + { + int ret; + /* force reset to complete */ + reg = reg & ~(EHCI_PS_PR | EHCI_PS_CLEAR); + ehci_writel(status_reg, reg); + ret = handshake(status_reg, EHCI_PS_PR, 0, 2 * 1000); + if (!ret) + { + tmpbuf[0] |= USB_PORT_STAT_RESET; + reg = ehci_readl(status_reg); + } + else + err("port(%d) reset error", swpw(req->index) - 1); + } - if (reg & EHCI_PS_CS) - tmpbuf[0] |= USB_PORT_STAT_CONNECTION; - if (reg & EHCI_PS_PE) - tmpbuf[0] |= USB_PORT_STAT_ENABLE; - if (reg & EHCI_PS_SUSP) - tmpbuf[0] |= USB_PORT_STAT_SUSPEND; - if (reg & EHCI_PS_OCA) - tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT; - if (reg & EHCI_PS_PP) - tmpbuf[1] |= USB_PORT_STAT_POWER >> 8; - if (ehci_is_TDI()) - { - switch((reg >> 26) & 3) - { - case 0: - break; + if (reg & EHCI_PS_CS) + tmpbuf[0] |= USB_PORT_STAT_CONNECTION; + if (reg & EHCI_PS_PE) + tmpbuf[0] |= USB_PORT_STAT_ENABLE; + if (reg & EHCI_PS_SUSP) + tmpbuf[0] |= USB_PORT_STAT_SUSPEND; + if (reg & EHCI_PS_OCA) + tmpbuf[0] |= USB_PORT_STAT_OVERCURRENT; + if (reg & EHCI_PS_PP) + tmpbuf[1] |= USB_PORT_STAT_POWER >> 8; + if (ehci_is_TDI()) + { + switch((reg >> 26) & 3) + { + case 0: + break; - case 1: - tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8; - break; + case 1: + tmpbuf[1] |= USB_PORT_STAT_LOW_SPEED >> 8; + break; - case 2: - default: - tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; - break; - } - } - else - tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; + case 2: + default: + tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; + break; + } + } + else + tmpbuf[1] |= USB_PORT_STAT_HIGH_SPEED >> 8; - if (reg & EHCI_PS_CSC) - tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION; - if (reg & EHCI_PS_PEC) - tmpbuf[2] |= USB_PORT_STAT_C_ENABLE; - if (reg & EHCI_PS_OCC) - tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT; - if (portreset & (1 << swpw(req->index))) - tmpbuf[2] |= USB_PORT_STAT_C_RESET; + if (reg & EHCI_PS_CSC) + tmpbuf[2] |= USB_PORT_STAT_C_CONNECTION; + if (reg & EHCI_PS_PEC) + tmpbuf[2] |= USB_PORT_STAT_C_ENABLE; + if (reg & EHCI_PS_OCC) + tmpbuf[2] |= USB_PORT_STAT_C_OVERCURRENT; + if (portreset & (1 << swpw(req->index))) + tmpbuf[2] |= USB_PORT_STAT_C_RESET; - srcptr = tmpbuf; - srclen = 4; - break; + srcptr = tmpbuf; + srclen = 4; + break; - case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): - reg = ehci_readl(status_reg); - reg &= ~EHCI_PS_CLEAR; - switch(swpw(req->value)) - { - case USB_PORT_FEAT_ENABLE: - reg |= EHCI_PS_PE; - ehci_writel(status_reg, reg); - break; + case USB_REQ_SET_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): + reg = ehci_readl(status_reg); + reg &= ~EHCI_PS_CLEAR; + switch(swpw(req->value)) + { + case USB_PORT_FEAT_ENABLE: + reg |= EHCI_PS_PE; + ehci_writel(status_reg, reg); + break; - case USB_PORT_FEAT_POWER: - if (HCS_PPC(ehci_readl(&gehci.hccr->cr_hcsparams))) - { - reg |= EHCI_PS_PP; - ehci_writel(status_reg, reg); - } - break; + case USB_PORT_FEAT_POWER: + if (HCS_PPC(ehci_readl(&gehci.hccr->cr_hcsparams))) + { + reg |= EHCI_PS_PP; + ehci_writel(status_reg, reg); + } + break; - case USB_PORT_FEAT_RESET: - if ((reg & (EHCI_PS_PE | EHCI_PS_CS)) == EHCI_PS_CS && !ehci_is_TDI() && EHCI_PS_IS_LOWSPEED(reg)) - { - /* Low speed device, give up ownership. */ - debug("port %d low speed --> companion\r\n", swpw(req->index)); - reg |= EHCI_PS_PO; - ehci_writel(status_reg, reg); - companion |= (1 << swpw(req->index)); - break; - } - else - { - reg |= EHCI_PS_PR; - reg &= ~EHCI_PS_PE; - ehci_writel(status_reg, reg); - /* - * caller must wait, then call GetPortStatus - * usb 2.0 specification say 50 ms resets on root - */ - wait(50 * 1000); - portreset |= (1 << swpw(req->index)); - } - break; + case USB_PORT_FEAT_RESET: + if ((reg & (EHCI_PS_PE | EHCI_PS_CS)) == EHCI_PS_CS && !ehci_is_TDI() && EHCI_PS_IS_LOWSPEED(reg)) + { + /* Low speed device, give up ownership. */ + dbg("port %d low speed --> companion\r\n", swpw(req->index)); + reg |= EHCI_PS_PO; + ehci_writel(status_reg, reg); + companion |= (1 << swpw(req->index)); + break; + } + else + { + reg |= EHCI_PS_PR; + reg &= ~EHCI_PS_PE; + ehci_writel(status_reg, reg); + /* + * caller must wait, then call GetPortStatus + * usb 2.0 specification say 50 ms resets on root + */ + wait(50 * 1000); + portreset |= (1 << swpw(req->index)); + } + break; - default: - debug("unknown feature %x\r\n", swpw(req->value)); - goto unknown; - } - /* unblock posted writes */ - (void) ehci_readl(&gehci.hcor->or_usbcmd); - break; + default: + dbg("unknown feature %x\r\n", swpw(req->value)); + goto unknown; + } + /* unblock posted writes */ + (void) ehci_readl(&gehci.hcor->or_usbcmd); + break; - case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): - reg = ehci_readl(status_reg); - switch(swpw(req->value)) - { - case USB_PORT_FEAT_ENABLE: - reg &= ~EHCI_PS_PE; - break; + case USB_REQ_CLEAR_FEATURE | ((USB_DIR_OUT | USB_RT_PORT) << 8): + reg = ehci_readl(status_reg); + switch(swpw(req->value)) + { + case USB_PORT_FEAT_ENABLE: + reg &= ~EHCI_PS_PE; + break; - case USB_PORT_FEAT_C_ENABLE: - reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_PE; - break; + case USB_PORT_FEAT_C_ENABLE: + reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_PE; + break; - case USB_PORT_FEAT_POWER: - if (HCS_PPC(ehci_readl(&gehci.hccr->cr_hcsparams))) - reg = reg & ~(EHCI_PS_CLEAR | EHCI_PS_PP); - case USB_PORT_FEAT_C_CONNECTION: - reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_CSC; - break; + case USB_PORT_FEAT_POWER: + if (HCS_PPC(ehci_readl(&gehci.hccr->cr_hcsparams))) + reg = reg & ~(EHCI_PS_CLEAR | EHCI_PS_PP); + case USB_PORT_FEAT_C_CONNECTION: + reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_CSC; + break; - case USB_PORT_FEAT_OVER_CURRENT: - reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_OCC; - break; + case USB_PORT_FEAT_OVER_CURRENT: + reg = (reg & ~EHCI_PS_CLEAR) | EHCI_PS_OCC; + break; - case USB_PORT_FEAT_C_RESET: - portreset &= ~(1 << swpw(req->index)); - break; + case USB_PORT_FEAT_C_RESET: + portreset &= ~(1 << swpw(req->index)); + break; - default: - debug("unknown feature %x\r\n", swpw(req->value)); - goto unknown; - } - ehci_writel(status_reg, reg); - /* unblock posted write */ - (void) ehci_readl(&gehci.hcor->or_usbcmd); - break; + default: + dbg("unknown feature %x\r\n", swpw(req->value)); + goto unknown; + } + ehci_writel(status_reg, reg); + /* unblock posted write */ + (void) ehci_readl(&gehci.hcor->or_usbcmd); + break; - default: - debug("Unknown request\r\n"); - goto unknown; - } - wait(1 * 1000); - len = min3(srclen, swpw(req->length), length); - if (srcptr != NULL && len > 0) - memcpy(buffer, srcptr, len); - else - debug("Len is 0\r\n"); - dev->act_len = len; - dev->status = 0; - return 0; + default: + dbg("Unknown request\r\n"); + goto unknown; + } + wait(1 * 1000); + len = min3(srclen, swpw(req->length), length); + if (srcptr != NULL && len > 0) + memcpy(buffer, srcptr, len); + else + dbg("Len is 0\r\n"); + dev->act_len = len; + dev->status = 0; + return 0; unknown: - debug("requesttype=%x, request=%x, value=%x, index=%x, length=%x\r\n", - req->requesttype, req->request, swpw(req->value), swpw(req->index), swpw(req->length)); - dev->act_len = 0; - dev->status = USB_ST_STALLED; - return -1; + dbg("requesttype=%x, request=%x, value=%x, index=%x, length=%x\r\n", + req->requesttype, req->request, swpw(req->value), swpw(req->index), swpw(req->length)); + dev->act_len = 0; + dev->status = USB_ST_STALLED; + return -1; } /* an interrupt happens */ static int hc_interrupt(struct ehci *ehci) { - uint32_t status = ehci_readl(&ehci->hcor->or_usbsts); - if (status & STS_PCD) /* port change detect */ - { - uint32_t reg = ehci_readl(&ehci->hccr->cr_hcsparams); - uint32_t i = HCS_N_PORTS(reg); - while(i) - { - uint32_t pstatus = ehci_readl(&ehci->hcor->or_portsc[i-1]); - if (pstatus & EHCI_PS_PO) - { - i--; - continue; - } + uint32_t status = ehci_readl(&ehci->hcor->or_usbsts); + if (status & STS_PCD) /* port change detect */ + { + uint32_t reg = ehci_readl(&ehci->hccr->cr_hcsparams); + uint32_t i = HCS_N_PORTS(reg); + while(i) + { + uint32_t pstatus = ehci_readl(&ehci->hcor->or_portsc[i-1]); + if (pstatus & EHCI_PS_PO) + { + i--; + continue; + } - if (companion & (1 << i)) - { - /* Low speed device, give up ownership. */ - pstatus |= EHCI_PS_PO; - ehci_writel(&ehci->hcor->or_portsc[i-1], pstatus); - } - i--; - } - } - ehci_writel(&ehci->hcor->or_usbsts, status); + if (companion & (1 << i)) + { + /* Low speed device, give up ownership. */ + pstatus |= EHCI_PS_PO; + ehci_writel(&ehci->hcor->or_portsc[i-1], pstatus); + } + i--; + } + } + ehci_writel(&ehci->hcor->or_usbsts, status); - return(1); /* interrupt was from this card */ + return(1); /* interrupt was from this card */ } void ehci_usb_enable_interrupt(int enable) { - if (enable); + if (enable); } static int handle_usb_interrupt(struct ehci *ehci) { - return(hc_interrupt(ehci)); + return(hc_interrupt(ehci)); } static void hc_free_buffers(struct ehci *ehci) { - int i; + int i; - if (ehci->descriptor != NULL) - { - driver_mem_free(ehci->descriptor); - ehci->descriptor = NULL; - } + if (ehci->descriptor != NULL) + { + driver_mem_free(ehci->descriptor); + ehci->descriptor = NULL; + } - for (i = 0; i < 3; i++) - { - if (ehci->td_unaligned[i] != NULL) - { - driver_mem_free(ehci->td_unaligned[i]); - ehci->td_unaligned[i] = NULL; - } - } + for (i = 0; i < 3; i++) + { + if (ehci->td_unaligned[i] != NULL) + { + driver_mem_free(ehci->td_unaligned[i]); + ehci->td_unaligned[i] = NULL; + } + } - if (ehci->qh_unaligned != NULL) - { - driver_mem_free(ehci->qh_unaligned); - ehci->qh_unaligned = NULL; - } + if (ehci->qh_unaligned != NULL) + { + driver_mem_free(ehci->qh_unaligned); + ehci->qh_unaligned = NULL; + } - if (ehci->qh_list_unaligned != NULL) - { - driver_mem_free(ehci->qh_list_unaligned); - ehci->qh_list_unaligned = NULL; - } + if (ehci->qh_list_unaligned != NULL) + { + driver_mem_free(ehci->qh_list_unaligned); + ehci->qh_list_unaligned = NULL; + } } int ehci_usb_lowlevel_init(long handle, const struct pci_device_id *ent, void **priv) { - int i; - uint32_t reg; - uint32_t cmd; - uint32_t usb_base_addr = 0xFFFFFFFF; - struct pci_rd *pci_rsc_desc; + int i; + uint32_t reg; + uint32_t cmd; + uint32_t usb_base_addr = 0xFFFFFFFF; + struct pci_rd *pci_rsc_desc; - pci_rsc_desc = pci_get_resource(handle); /* USB EHCI */ - if (handle && (ent != NULL)) - { - memset(&gehci, 0, sizeof(struct ehci)); - gehci.handle = handle; - gehci.ent = ent; - } - else if (!gehci.handle) /* for restart USB cmd */ - return(-1); + pci_rsc_desc = pci_get_resource(handle); /* USB EHCI */ + if (handle && (ent != NULL)) + { + memset(&gehci, 0, sizeof(struct ehci)); + gehci.handle = handle; + gehci.ent = ent; + } + else if (!gehci.handle) /* for restart USB cmd */ + return(-1); - gehci.qh_list_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); - if (gehci.qh_list_unaligned == NULL) - { - debug("QHs malloc failed"); - hc_free_buffers(&gehci); - return(-1); - } + gehci.qh_list_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); + if (gehci.qh_list_unaligned == NULL) + { + dbg("QHs malloc failed"); + hc_free_buffers(&gehci); + return(-1); + } - gehci.qh_list = (struct QH *)(((uint32_t)gehci.qh_list_unaligned + 31) & ~31); - memset(gehci.qh_list, 0, sizeof(struct QH)); - gehci.qh_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); + gehci.qh_list = (struct QH *)(((uint32_t)gehci.qh_list_unaligned + 31) & ~31); + memset(gehci.qh_list, 0, sizeof(struct QH)); + gehci.qh_unaligned = (struct QH *)driver_mem_alloc(sizeof(struct QH) + 32); - if (gehci.qh_unaligned == NULL) - { - debug("QHs malloc failed"); - hc_free_buffers(&gehci); - return(-1); - } - gehci.qh = (struct QH *)(((uint32_t)gehci.qh_unaligned + 31) & ~31); - memset(gehci.qh, 0, sizeof(struct QH)); + if (gehci.qh_unaligned == NULL) + { + dbg("QHs malloc failed"); + hc_free_buffers(&gehci); + return(-1); + } + gehci.qh = (struct QH *)(((uint32_t)gehci.qh_unaligned + 31) & ~31); + memset(gehci.qh, 0, sizeof(struct QH)); - for (i = 0; i < 3; i++) - { - gehci.td_unaligned[i] = (struct qTD *)driver_mem_alloc(sizeof(struct qTD) + 32); - if (gehci.td_unaligned[i] == NULL) - { - debug("TDs malloc failed"); - hc_free_buffers(&gehci); - return(-1); - } - gehci.td[i] = (struct qTD *)(((uint32_t)gehci.td_unaligned[i] + 31) & ~31); - memset(gehci.td[i], 0, sizeof(struct qTD)); - } + for (i = 0; i < 3; i++) + { + gehci.td_unaligned[i] = (struct qTD *)driver_mem_alloc(sizeof(struct qTD) + 32); + if (gehci.td_unaligned[i] == NULL) + { + dbg("TDs malloc failed"); + hc_free_buffers(&gehci); + return(-1); + } + gehci.td[i] = (struct qTD *)(((uint32_t)gehci.td_unaligned[i] + 31) & ~31); + memset(gehci.td[i], 0, sizeof(struct qTD)); + } - gehci.descriptor = (struct descriptor *)driver_mem_alloc(sizeof(struct descriptor)); - if (gehci.descriptor == NULL) - { - debug("decriptor malloc failed"); - hc_free_buffers(&gehci); - return(-1); - } - memcpy(gehci.descriptor, &rom_descriptor, sizeof(struct descriptor)); + gehci.descriptor = (struct descriptor *)driver_mem_alloc(sizeof(struct descriptor)); + if (gehci.descriptor == NULL) + { + dbg("decriptor malloc failed"); + hc_free_buffers(&gehci); + return(-1); + } + memcpy(gehci.descriptor, &rom_descriptor, sizeof(struct descriptor)); - if ((long) pci_rsc_desc >= 0) - { - unsigned short flags; - do - { - debug("PCI USB descriptors (at %p): flags 0x%04x start 0x%08lx \r\n offset 0x%08lx dmaoffset 0x%08lx length 0x%08lx\r\n", pci_rsc_desc, - pci_rsc_desc->flags, pci_rsc_desc->start, pci_rsc_desc->offset, pci_rsc_desc->dmaoffset, pci_rsc_desc->length); - if (!(pci_rsc_desc->flags & FLG_IO)) - { - if (usb_base_addr == 0xFFFFFFFF) - { - usb_base_addr = pci_rsc_desc->start; - gehci.hccr = (struct ehci_hccr *)(pci_rsc_desc->offset + pci_rsc_desc->start); - gehci.dma_offset = pci_rsc_desc->dmaoffset; - if ((pci_rsc_desc->flags & FLG_ENDMASK) == ORD_MOTOROLA) - gehci.big_endian = 0; /* host bridge make swapping intel -> motorola */ - else - gehci.big_endian = 1; /* driver must swapping intel -> motorola */ - } - } - flags = pci_rsc_desc->flags; - pci_rsc_desc = (struct pci_rd *)((uint32_t)pci_rsc_desc->next + (uint32_t)pci_rsc_desc); - } - while (!(flags & FLG_LAST)); - } - else - { - hc_free_buffers(&gehci); - return(-1); /* get_resource error */ - } + if ((long) pci_rsc_desc >= 0) + { + unsigned short flags; + do + { + dbg("PCI USB descriptors (at %p): flags 0x%04x start 0x%08lx \r\n offset 0x%08lx dmaoffset 0x%08lx length 0x%08lx\r\n", pci_rsc_desc, + pci_rsc_desc->flags, pci_rsc_desc->start, pci_rsc_desc->offset, pci_rsc_desc->dmaoffset, pci_rsc_desc->length); + if (!(pci_rsc_desc->flags & FLG_IO)) + { + if (usb_base_addr == 0xFFFFFFFF) + { + usb_base_addr = pci_rsc_desc->start; + gehci.hccr = (struct ehci_hccr *)(pci_rsc_desc->offset + pci_rsc_desc->start); + gehci.dma_offset = pci_rsc_desc->dmaoffset; + if ((pci_rsc_desc->flags & FLG_ENDMASK) == ORD_MOTOROLA) + gehci.big_endian = 0; /* host bridge make swapping intel -> motorola */ + else + gehci.big_endian = 1; /* driver must swapping intel -> motorola */ + } + } + flags = pci_rsc_desc->flags; + pci_rsc_desc = (struct pci_rd *)((uint32_t)pci_rsc_desc->next + (uint32_t)pci_rsc_desc); + } + while (!(flags & FLG_LAST)); + } + else + { + hc_free_buffers(&gehci); + return(-1); /* get_resource error */ + } - if (usb_base_addr == 0xFFFFFFFF) - { - hc_free_buffers(&gehci); - return(-1); - } + if (usb_base_addr == 0xFFFFFFFF) + { + hc_free_buffers(&gehci); + return(-1); + } - if (handle && (ent != NULL)) - { - switch(ent->vendor) - { - case PCI_VENDOR_ID_NEC: gehci.slot_name = "uPD720101"; break; - case PCI_VENDOR_ID_PHILIPS: gehci.slot_name = "isp1561"; break; - default: gehci.slot_name = "generic"; break; - } - } - gehci.hcor = (struct ehci_hcor *)((uint32_t)gehci.hccr + HC_LENGTH(ehci_readl(&gehci.hccr->cr_capbase))); - xprintf("EHCI usb-%s, regs address 0x%08X, PCI handle 0x%X\r\n", gehci.slot_name, gehci.hccr, handle); + if (handle && (ent != NULL)) + { + switch(ent->vendor) + { + case PCI_VENDOR_ID_NEC: gehci.slot_name = "uPD720101"; break; + case PCI_VENDOR_ID_PHILIPS: gehci.slot_name = "isp1561"; break; + default: gehci.slot_name = "generic"; break; + } + } + gehci.hcor = (struct ehci_hcor *)((uint32_t)gehci.hccr + HC_LENGTH(ehci_readl(&gehci.hccr->cr_capbase))); + xprintf("EHCI usb-%s, regs address 0x%08X, PCI handle 0x%X\r\n", gehci.slot_name, gehci.hccr, handle); - /* EHCI spec section 4.1 */ - if (ehci_reset() != 0) - { - hc_free_buffers(&gehci); - return(-1); - } + /* EHCI spec section 4.1 */ + if (ehci_reset() != 0) + { + hc_free_buffers(&gehci); + return(-1); + } - /* Set head of reclaim list */ - gehci.qh_list->qh_link = swpl(((uint32_t)gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); - gehci.qh_list->qh_endpt1 = swpl((1 << 15) | (USB_SPEED_HIGH << 12)); - gehci.qh_list->qh_curtd = swpl(QT_NEXT_TERMINATE); - gehci.qh_list->qh_overlay.qt_next = swpl(QT_NEXT_TERMINATE); - gehci.qh_list->qh_overlay.qt_altnext = swpl(QT_NEXT_TERMINATE); - gehci.qh_list->qh_overlay.qt_token = swpl(0x40); - /* Set async. queue head pointer. */ - ehci_writel(&gehci.hcor->or_asynclistaddr, (uint32_t)gehci.qh_list - gehci.dma_offset); - reg = ehci_readl(&gehci.hccr->cr_hcsparams); - gehci.descriptor->hub.bNbrPorts = HCS_N_PORTS(reg); - info("Register %x NbrPorts %d", reg, gehci.descriptor->hub.bNbrPorts); + /* Set head of reclaim list */ + gehci.qh_list->qh_link = swpl(((uint32_t)gehci.qh_list - gehci.dma_offset) | QH_LINK_TYPE_QH); + gehci.qh_list->qh_endpt1 = swpl((1 << 15) | (USB_SPEED_HIGH << 12)); + gehci.qh_list->qh_curtd = swpl(QT_NEXT_TERMINATE); + gehci.qh_list->qh_overlay.qt_next = swpl(QT_NEXT_TERMINATE); + gehci.qh_list->qh_overlay.qt_altnext = swpl(QT_NEXT_TERMINATE); + gehci.qh_list->qh_overlay.qt_token = swpl(0x40); + /* Set async. queue head pointer. */ + ehci_writel(&gehci.hcor->or_asynclistaddr, (uint32_t)gehci.qh_list - gehci.dma_offset); + reg = ehci_readl(&gehci.hccr->cr_hcsparams); + gehci.descriptor->hub.bNbrPorts = HCS_N_PORTS(reg); + info("Register %x NbrPorts %d", reg, gehci.descriptor->hub.bNbrPorts); - /* Port Indicators */ - if (HCS_INDICATOR(reg)) - gehci.descriptor->hub.wHubCharacteristics |= 0x80; - /* Port Power Control */ - if (HCS_PPC(reg)) - gehci.descriptor->hub.wHubCharacteristics |= 0x01; - /* Start the host controller. */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - /* - * Philips, Intel, and maybe others need CMD_RUN before the - * root hub will detect new devices (why?); NEC doesn't - */ - cmd &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); - cmd |= CMD_RUN; - ehci_writel(&gehci.hcor->or_usbcmd, cmd); - /* take control over the ports */ - ehci_writel(&gehci.hcor->or_configflag, FLAG_CF); - /* unblock posted write */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - wait(5 * 1000); - reg = HC_VERSION(ehci_readl(&gehci.hccr->cr_capbase)); - info("USB EHCI %x.%02x", reg >> 8, reg & 0xff); + /* Port Indicators */ + if (HCS_INDICATOR(reg)) + gehci.descriptor->hub.wHubCharacteristics |= 0x80; + /* Port Power Control */ + if (HCS_PPC(reg)) + gehci.descriptor->hub.wHubCharacteristics |= 0x01; + /* Start the host controller. */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + /* + * Philips, Intel, and maybe others need CMD_RUN before the + * root hub will detect new devices (why?); NEC doesn't + */ + cmd &= ~(CMD_LRESET|CMD_IAAD|CMD_PSE|CMD_ASE|CMD_RESET); + cmd |= CMD_RUN; + ehci_writel(&gehci.hcor->or_usbcmd, cmd); + /* take control over the ports */ + ehci_writel(&gehci.hcor->or_configflag, FLAG_CF); + /* unblock posted write */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + wait(5 * 1000); + reg = HC_VERSION(ehci_readl(&gehci.hccr->cr_capbase)); + info("USB EHCI %x.%02x", reg >> 8, reg & 0xff); /* turn on interrupts */ - pci_hook_interrupt(handle, handle_usb_interrupt, &gehci); - ehci_writel(&gehci.hcor->or_usbintr, INTR_PCDE); - rootdev = 0; - if (priv != NULL) - *priv = (void *)&gehci; - ehci_inited = 1; - return(0); + pci_hook_interrupt(handle, handle_usb_interrupt, &gehci); + ehci_writel(&gehci.hcor->or_usbintr, INTR_PCDE); + rootdev = 0; + if (priv != NULL) + *priv = (void *)&gehci; + ehci_inited = 1; + return(0); } int ehci_usb_lowlevel_stop(void *priv) { - uint32_t cmd; + uint32_t cmd; - if (priv); - if (!ehci_inited) - return(0); + if (priv); + if (!ehci_inited) + return(0); - /* turn off interrupts */ - ehci_writel(&gehci.hcor->or_usbintr, 0); - pci_unhook_interrupt(gehci.handle); + /* turn off interrupts */ + ehci_writel(&gehci.hcor->or_usbintr, 0); + pci_unhook_interrupt(gehci.handle); - /* stop the controller */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - cmd &= ~CMD_RUN; - ehci_writel(&gehci.hcor->or_usbcmd, cmd); + /* stop the controller */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + cmd &= ~CMD_RUN; + ehci_writel(&gehci.hcor->or_usbcmd, cmd); - /* turn off all ports => todo */ - /* use the companions */ - ehci_writel(&gehci.hcor->or_configflag, 0); + /* turn off all ports => todo */ + /* use the companions */ + ehci_writel(&gehci.hcor->or_configflag, 0); - /* unblock posted write */ - cmd = ehci_readl(&gehci.hcor->or_usbcmd); - ehci_reset(); - hc_free_buffers(&gehci); - ehci_inited = 0; - return(0); + /* unblock posted write */ + cmd = ehci_readl(&gehci.hcor->or_usbcmd); + ehci_reset(); + hc_free_buffers(&gehci); + ehci_inited = 0; + return(0); } int ehci_submit_bulk_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int length) { - if (usb_pipetype(pipe) != PIPE_BULK) - { - debug("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); - return -1; - } - return ehci_submit_async(dev, pipe, buffer, length, NULL); + if (usb_pipetype(pipe) != PIPE_BULK) + { + dbg("non-bulk pipe (type=%lu)", usb_pipetype(pipe)); + return -1; + } + return ehci_submit_async(dev, pipe, buffer, length, NULL); } int ehci_submit_control_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int length, struct devrequest *setup) { - if (usb_pipetype(pipe) != PIPE_CONTROL) - { - debug("non-control pipe (type=%lu)", usb_pipetype(pipe)); - return -1; - } + if (usb_pipetype(pipe) != PIPE_CONTROL) + { + dbg("non-control pipe (type=%lu)", usb_pipetype(pipe)); + return -1; + } - if (usb_pipedevice(pipe) == rootdev) - { - if (rootdev == 0) - dev->speed = USB_SPEED_HIGH; - return ehci_submit_root(dev, pipe, buffer, length, setup); - } - return ehci_submit_async(dev, pipe, buffer, length, setup); + if (usb_pipedevice(pipe) == rootdev) + { + if (rootdev == 0) + dev->speed = USB_SPEED_HIGH; + return ehci_submit_root(dev, pipe, buffer, length, setup); + } + return ehci_submit_async(dev, pipe, buffer, length, setup); } int ehci_submit_int_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int length, int interval) { - debug("submit_int_msg dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d", dev, pipe, buffer, length, interval); - return -1; + dbg("submit_int_msg dev=%p, pipe=%lu, buffer=%p, length=%d, interval=%d", dev, pipe, buffer, length, interval); + return -1; } diff --git a/BaS_gcc/pci/ohci-hcd.c b/BaS_gcc/pci/ohci-hcd.c index 5660eea..9c09766 100644 --- a/BaS_gcc/pci/ohci-hcd.c +++ b/BaS_gcc/pci/ohci-hcd.c @@ -53,7 +53,7 @@ #undef OHCI_VERBOSE_DEBUG /* not always helpful */ #undef OHCI_FILL_TRACE -//#define DEBUG_OHCI +#define DEBUG_OHCI #ifdef DEBUG_OHCI #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #else @@ -80,12 +80,12 @@ */ inline uint32_t readl(volatile uint32_t *addr) { - uint32_t res; + uint32_t res; - res = swpl(*addr); - //chip_errata_135(); - //dbg("reading from 0x%08x = 0x%08x\r\n", addr, res); - return res; + res = swpl(*addr); + //chip_errata_135(); + //dbg("reading from 0x%08x = 0x%08x\r\n", addr, res); + return res; } /* @@ -93,8 +93,8 @@ inline uint32_t readl(volatile uint32_t *addr) */ inline void writel(uint32_t value, uint32_t *address) { - // dbg("writing %08x to %08x\r\n", value, address); - * (volatile uint32_t *) address = swpl(value); + // dbg("writing %08x to %08x\r\n", value, address); + * (volatile uint32_t *) address = swpl(value); } #else /* @@ -108,43 +108,43 @@ inline void writel(uint32_t value, uint32_t *address) struct pci_device_id ohci_usb_pci_table[] = { - { - PCI_VENDOR_ID_AL, - PCI_DEVICE_ID_AL_M5237, - PCI_ANY_ID, - PCI_ANY_ID, - PCI_CLASS_SERIAL_USB_OHCI, - 0, - 0 - }, /* ULI1575 PCI OHCI module ids */ - { - PCI_VENDOR_ID_NEC, - PCI_DEVICE_ID_NEC_USB, - PCI_ANY_ID, - PCI_ANY_ID, - PCI_CLASS_SERIAL_USB_OHCI, - 0, - 0 - }, /* NEC PCI OHCI module ids */ - { - PCI_VENDOR_ID_PHILIPS, - PCI_DEVICE_ID_PHILIPS_ISP1561, - PCI_ANY_ID, - PCI_ANY_ID, - PCI_CLASS_SERIAL_USB_OHCI, - 0, - 0 - }, /* Philips 1561 PCI OHCI module ids */ - /* Please add supported PCI OHCI controller ids here */ - { - 0, - 0, - 0, - 0, - 0, - 0, - 0 - } + { + PCI_VENDOR_ID_AL, + PCI_DEVICE_ID_AL_M5237, + PCI_ANY_ID, + PCI_ANY_ID, + PCI_CLASS_SERIAL_USB_OHCI, + 0, + 0 + }, /* ULI1575 PCI OHCI module ids */ + { + PCI_VENDOR_ID_NEC, + PCI_DEVICE_ID_NEC_USB, + PCI_ANY_ID, + PCI_ANY_ID, + PCI_CLASS_SERIAL_USB_OHCI, + 0, + 0 + }, /* NEC PCI OHCI module ids */ + { + PCI_VENDOR_ID_PHILIPS, + PCI_DEVICE_ID_PHILIPS_ISP1561, + PCI_ANY_ID, + PCI_ANY_ID, + PCI_CLASS_SERIAL_USB_OHCI, + 0, + 0 + }, /* Philips 1561 PCI OHCI module ids */ + /* Please add supported PCI OHCI controller ids here */ + { + 0, + 0, + 0, + 0, + 0, + 0, + 0 + } }; /* global ohci_t */ @@ -160,8 +160,8 @@ static inline uint32_t roothub_portstatus(ohci_t *ohci, int i) { return readl(&o static void flush_data_cache(ohci_t *ohci); static int hc_interrupt(ohci_t *ohci); static void td_submit_job(ohci_t *ohci, struct usb_device *dev, uint32_t pipe, - void *buffer, int transfer_len, struct devrequest *setup, - urb_priv_t *urb, int interval); + void *buffer, int transfer_len, struct devrequest *setup, + urb_priv_t *urb, int interval); static struct td *ptd; @@ -169,21 +169,21 @@ static struct td *ptd; /* TDs ... */ static struct td *td_alloc(struct usb_device *usb_dev) { - int i; - struct td *td; + int i; + struct td *td; - td = NULL; + td = NULL; - for (i = 0; i < NUM_TD; i++) - { - if (ptd[i].usb_dev == NULL) - { - td = &ptd[i]; - td->usb_dev = usb_dev; - break; - } - } - return td; + for (i = 0; i < NUM_TD; i++) + { + if (ptd[i].usb_dev == NULL) + { + td = &ptd[i]; + td->usb_dev = usb_dev; + break; + } + } + return td; } /*-------------------------------------------------------------------------* @@ -194,23 +194,23 @@ static struct td *td_alloc(struct usb_device *usb_dev) static void urb_free_priv(urb_priv_t *urb) { - int i; - struct td *td; - int last = urb->length - 1; + int i; + struct td *td; + int last = urb->length - 1; - if (last >= 0) - { - for (i = 0; i <= last; i++) - { - td = urb->td[i]; - if (td) - { - td->usb_dev = NULL; - urb->td[i] = NULL; - } - } - } - /* FIXME: driver_mem_free(urb); */ + if (last >= 0) + { + for (i = 0; i <= last; i++) + { + td = urb->td[i]; + if (td) + { + td->usb_dev = NULL; + urb->td[i] = NULL; + } + } + } + /* FIXME: driver_mem_free(urb); */ } /*-------------------------------------------------------------------------*/ @@ -222,44 +222,44 @@ static int sohci_get_current_frame_number(ohci_t *ohci, struct usb_device *dev); * small: 0) header + data packets 1) just header */ static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev, - uint32_t pipe, void *buffer, int transfer_len, - struct devrequest *setup, char *str, int small) + uint32_t pipe, void *buffer, int transfer_len, + struct devrequest *setup, char *str, int small) { - dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx\r\n", - str, - sohci_get_current_frame_number(ohci, dev), - usb_pipedevice(pipe), - usb_pipeendpoint(pipe), - usb_pipeout(pipe)? 'O': 'I', - usb_pipetype(pipe) < 2 ? \ - (usb_pipeint(pipe)? "INTR": "ISOC"): \ - (usb_pipecontrol(pipe)? "CTRL": "BULK"), - (purb ? purb->actual_length : 0), - transfer_len, dev->status); + dbg("%s URB:[%4x] dev:%2lu,ep:%2lu-%c,type:%s,len:%d/%d stat:%#lx\r\n", + str, + sohci_get_current_frame_number(ohci, dev), + usb_pipedevice(pipe), + usb_pipeendpoint(pipe), + usb_pipeout(pipe)? 'O': 'I', + usb_pipetype(pipe) < 2 ? \ + (usb_pipeint(pipe)? "INTR": "ISOC"): \ + (usb_pipecontrol(pipe)? "CTRL": "BULK"), + (purb ? purb->actual_length : 0), + transfer_len, dev->status); #ifdef OHCI_VERBOSE_DEBUG - if (!small) - { - int i; - int len; + if (!small) + { + int i; + int len; - if (usb_pipecontrol(pipe)) - { - dbg(__FILE__ ": cmd(8):"); - for (i = 0; i < 8 ; i++) - dbg(" %02x", ((uint8_t *)setup)[i]); - dbg("\r\n"); - } + if (usb_pipecontrol(pipe)) + { + dbg(__FILE__ ": cmd(8):"); + for (i = 0; i < 8 ; i++) + dbg(" %02x", ((uint8_t *)setup)[i]); + dbg("\r\n"); + } - if (transfer_len > 0 && buffer) - { - dbg(__FILE__ ": data(%d/%d):", (purb ? purb->actual_length : 0), transfer_len); - len = usb_pipeout(pipe)? transfer_len : (purb ? purb->actual_length : 0); + if (transfer_len > 0 && buffer) + { + dbg(__FILE__ ": data(%d/%d):", (purb ? purb->actual_length : 0), transfer_len); + len = usb_pipeout(pipe)? transfer_len : (purb ? purb->actual_length : 0); - for (i = 0; i < 16 && i < len; i++) - dbg(" %02x", ((uint8_t *)buffer)[i]); - dbg("%s\r\n", i < len? "...": ""); - } - } + for (i = 0; i < 16 && i < len; i++) + dbg(" %02x", ((uint8_t *)buffer)[i]); + dbg("%s\r\n", i < len? "...": ""); + } + } #endif } @@ -269,187 +269,187 @@ static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev, */ static void ep_print_int_eds(ohci_t *ohci, char *str) { - int i, j; - uint32_t *ed_p; + int i, j; + uint32_t *ed_p; - for (i = 0; i < 32; i++) - { - j = 5; - ed_p = &(ohci->hcca->int_table[i]); - if (*ed_p == 0) - continue; + for (i = 0; i < 32; i++) + { + j = 5; + ed_p = &(ohci->hcca->int_table[i]); + if (*ed_p == 0) + continue; - dbg("%s branch int %2d(%2x):\r\n", str, i, i); - while (*ed_p != 0 && j--) - { - ed_t *ed = (ed_t *) swpl((uint32_t) ed_p); - dbg(" ed: %4x;", ed->hwINFO); - ed_p = &ed->hwNextED; - } - dbg("\r\n"); - } + dbg("%s branch int %2d(%2x):\r\n", str, i, i); + while (*ed_p != 0 && j--) + { + ed_t *ed = (ed_t *) swpl((uint32_t) ed_p); + dbg(" ed: %4x;", ed->hwINFO); + ed_p = &ed->hwNextED; + } + dbg("\r\n"); + } } static void ohci_dump_intr_mask(char *label, uint32_t mask) { - dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s\r\n", - label, - mask, - (mask & OHCI_INTR_MIE) ? " MIE" : "", - (mask & OHCI_INTR_OC) ? " OC" : "", - (mask & OHCI_INTR_RHSC) ? " RHSC" : "", - (mask & OHCI_INTR_FNO) ? " FNO" : "", - (mask & OHCI_INTR_UE) ? " UE" : "", - (mask & OHCI_INTR_RD) ? " RD" : "", - (mask & OHCI_INTR_SF) ? " SF" : "", - (mask & OHCI_INTR_WDH) ? " WDH" : "", - (mask & OHCI_INTR_SO) ? " SO" : "" - ); + dbg("%s: 0x%08x%s%s%s%s%s%s%s%s%s\r\n", + label, + mask, + (mask & OHCI_INTR_MIE) ? " MIE" : "", + (mask & OHCI_INTR_OC) ? " OC" : "", + (mask & OHCI_INTR_RHSC) ? " RHSC" : "", + (mask & OHCI_INTR_FNO) ? " FNO" : "", + (mask & OHCI_INTR_UE) ? " UE" : "", + (mask & OHCI_INTR_RD) ? " RD" : "", + (mask & OHCI_INTR_SF) ? " SF" : "", + (mask & OHCI_INTR_WDH) ? " WDH" : "", + (mask & OHCI_INTR_SO) ? " SO" : "" + ); } static void maybe_print_eds(ohci_t *controller, char *label, uint32_t value) { - ed_t *edp; + ed_t *edp; - value += controller->dma_offset; - edp = (ed_t *) value; - (void) edp; + value += controller->dma_offset; + edp = (ed_t *) value; + (void) edp; - if (value && (value < 0xDFFFF0)) /* STRAM */ - { - dbg("%s %08x\r\n", label, value); - dbg("%08x\r\n", edp->hwINFO); - dbg("%08x\r\n", edp->hwTailP); - dbg("%08x\r\n", edp->hwHeadP); - dbg("%08x\r\n", edp->hwNextED); - } + if (value && (value < 0xDFFFF0)) /* STRAM */ + { + dbg("%s %08x\r\n", label, value); + dbg("%08x\r\n", edp->hwINFO); + dbg("%08x\r\n", edp->hwTailP); + dbg("%08x\r\n", edp->hwHeadP); + dbg("%08x\r\n", edp->hwNextED); + } } static char *hcfs2string(int state) { - switch (state) - { - case OHCI_USB_RESET: return "reset"; - case OHCI_USB_RESUME: return "resume"; - case OHCI_USB_OPER: return "operational"; - case OHCI_USB_SUSPEND: return "suspend"; - } - return "?"; + switch (state) + { + case OHCI_USB_RESET: return "reset"; + case OHCI_USB_RESUME: return "resume"; + case OHCI_USB_OPER: return "operational"; + case OHCI_USB_SUSPEND: return "suspend"; + } + return "?"; } /* dump control and status registers */ static void ohci_dump_status(ohci_t *controller) { - struct ohci_regs *regs = controller->regs; - uint32_t temp = readl(®s->revision) & 0xff; + struct ohci_regs *regs = controller->regs; + uint32_t temp = readl(®s->revision) & 0xff; - if (temp != 0x10) - dbg("spec %d.%d\r\n", (temp >> 4), (temp & 0x0f)); + if (temp != 0x10) + dbg("spec %d.%d\r\n", (temp >> 4), (temp & 0x0f)); - temp = readl(®s->control); - dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\r\n", temp, - (temp & OHCI_CTRL_RWE) ? " RWE" : "", - (temp & OHCI_CTRL_RWC) ? " RWC" : "", - (temp & OHCI_CTRL_IR) ? " IR" : "", - hcfs2string(temp & OHCI_CTRL_HCFS), - (temp & OHCI_CTRL_BLE) ? " BLE" : "", - (temp & OHCI_CTRL_CLE) ? " CLE" : "", - (temp & OHCI_CTRL_IE) ? " IE" : "", - (temp & OHCI_CTRL_PLE) ? " PLE" : "", - temp & OHCI_CTRL_CBSR - ); + temp = readl(®s->control); + dbg("control: 0x%08x%s%s%s HCFS=%s%s%s%s%s CBSR=%d\r\n", temp, + (temp & OHCI_CTRL_RWE) ? " RWE" : "", + (temp & OHCI_CTRL_RWC) ? " RWC" : "", + (temp & OHCI_CTRL_IR) ? " IR" : "", + hcfs2string(temp & OHCI_CTRL_HCFS), + (temp & OHCI_CTRL_BLE) ? " BLE" : "", + (temp & OHCI_CTRL_CLE) ? " CLE" : "", + (temp & OHCI_CTRL_IE) ? " IE" : "", + (temp & OHCI_CTRL_PLE) ? " PLE" : "", + temp & OHCI_CTRL_CBSR + ); - temp = readl(®s->cmdstatus); - dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s\r\n", temp, - (temp & OHCI_SOC) >> 16, - (temp & OHCI_OCR) ? " OCR" : "", - (temp & OHCI_BLF) ? " BLF" : "", - (temp & OHCI_CLF) ? " CLF" : "", - (temp & OHCI_HCR) ? " HCR" : "" - ); - ohci_dump_intr_mask("intrstatus", readl(®s->intrstatus)); - ohci_dump_intr_mask("intrenable", readl(®s->intrenable)); - maybe_print_eds(controller, "ed_periodcurrent", readl(®s->ed_periodcurrent)); - maybe_print_eds(controller, "ed_controlhead", readl(®s->ed_controlhead)); - maybe_print_eds(controller, "ed_controlcurrent", readl(®s->ed_controlcurrent)); - maybe_print_eds(controller, "ed_bulkhead", readl(®s->ed_bulkhead)); - maybe_print_eds(controller, "ed_bulkcurrent", readl(®s->ed_bulkcurrent)); - maybe_print_eds(controller, "donehead", readl(®s->donehead)); + temp = readl(®s->cmdstatus); + dbg("cmdstatus: 0x%08x SOC=%d%s%s%s%s\r\n", temp, + (temp & OHCI_SOC) >> 16, + (temp & OHCI_OCR) ? " OCR" : "", + (temp & OHCI_BLF) ? " BLF" : "", + (temp & OHCI_CLF) ? " CLF" : "", + (temp & OHCI_HCR) ? " HCR" : "" + ); + ohci_dump_intr_mask("intrstatus", readl(®s->intrstatus)); + ohci_dump_intr_mask("intrenable", readl(®s->intrenable)); + maybe_print_eds(controller, "ed_periodcurrent", readl(®s->ed_periodcurrent)); + maybe_print_eds(controller, "ed_controlhead", readl(®s->ed_controlhead)); + maybe_print_eds(controller, "ed_controlcurrent", readl(®s->ed_controlcurrent)); + maybe_print_eds(controller, "ed_bulkhead", readl(®s->ed_bulkhead)); + maybe_print_eds(controller, "ed_bulkcurrent", readl(®s->ed_bulkcurrent)); + maybe_print_eds(controller, "donehead", readl(®s->donehead)); } static void ohci_dump_roothub(ohci_t *controller, int verbose) { - uint32_t temp; - uint32_t ndp; - uint32_t i; + uint32_t temp; + uint32_t ndp; + uint32_t i; - temp = roothub_a(controller); - (void) temp; + temp = roothub_a(controller); + (void) temp; // ndp = (temp & RH_A_NDP); - ndp = controller->ndp; - if (verbose) - { - dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d\r\n", temp, - ((temp & RH_A_POTPGT) >> 24) & 0xff, - (temp & RH_A_NOCP) ? " NOCP" : "", - (temp & RH_A_OCPM) ? " OCPM" : "", - (temp & RH_A_DT) ? " DT" : "", - (temp & RH_A_NPS) ? " NPS" : "", - (temp & RH_A_PSM) ? " PSM" : "", - ndp - ); - temp = roothub_b(controller); - dbg("roothub.b: %08x PPCM=%04x DR=%04x\r\n", - temp, - (temp & RH_B_PPCM) >> 16, - (temp & RH_B_DR) - ); - temp = roothub_status(controller); - dbg("roothub.status: %08x%s%s%s%s%s%s\r\n", - temp, - (temp & RH_HS_CRWE) ? " CRWE" : "", - (temp & RH_HS_OCIC) ? " OCIC" : "", - (temp & RH_HS_LPSC) ? " LPSC" : "", - (temp & RH_HS_DRWE) ? " DRWE" : "", - (temp & RH_HS_OCI) ? " OCI" : "", - (temp & RH_HS_LPS) ? " LPS" : "" - ); - } + ndp = controller->ndp; + if (verbose) + { + dbg("roothub.a: %08x POTPGT=%d%s%s%s%s%s NDP=%d\r\n", temp, + ((temp & RH_A_POTPGT) >> 24) & 0xff, + (temp & RH_A_NOCP) ? " NOCP" : "", + (temp & RH_A_OCPM) ? " OCPM" : "", + (temp & RH_A_DT) ? " DT" : "", + (temp & RH_A_NPS) ? " NPS" : "", + (temp & RH_A_PSM) ? " PSM" : "", + ndp + ); + temp = roothub_b(controller); + dbg("roothub.b: %08x PPCM=%04x DR=%04x\r\n", + temp, + (temp & RH_B_PPCM) >> 16, + (temp & RH_B_DR) + ); + temp = roothub_status(controller); + dbg("roothub.status: %08x%s%s%s%s%s%s\r\n", + temp, + (temp & RH_HS_CRWE) ? " CRWE" : "", + (temp & RH_HS_OCIC) ? " OCIC" : "", + (temp & RH_HS_LPSC) ? " LPSC" : "", + (temp & RH_HS_DRWE) ? " DRWE" : "", + (temp & RH_HS_OCI) ? " OCI" : "", + (temp & RH_HS_LPS) ? " LPS" : "" + ); + } - for (i = 0; i < ndp; i++) - { - temp = roothub_portstatus(controller, i); - dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\r\n", - i, - temp, - (temp & RH_PS_PRSC) ? " PRSC" : "", - (temp & RH_PS_OCIC) ? " OCIC" : "", - (temp & RH_PS_PSSC) ? " PSSC" : "", - (temp & RH_PS_PESC) ? " PESC" : "", - (temp & RH_PS_CSC) ? " CSC" : "", + for (i = 0; i < ndp; i++) + { + temp = roothub_portstatus(controller, i); + dbg("roothub.portstatus [%d] = 0x%08x%s%s%s%s%s%s%s%s%s%s%s%s\r\n", + i, + temp, + (temp & RH_PS_PRSC) ? " PRSC" : "", + (temp & RH_PS_OCIC) ? " OCIC" : "", + (temp & RH_PS_PSSC) ? " PSSC" : "", + (temp & RH_PS_PESC) ? " PESC" : "", + (temp & RH_PS_CSC) ? " CSC" : "", - (temp & RH_PS_LSDA) ? " LSDA" : "", - (temp & RH_PS_PPS) ? " PPS" : "", - (temp & RH_PS_PRS) ? " PRS" : "", - (temp & RH_PS_POCI) ? " POCI" : "", - (temp & RH_PS_PSS) ? " PSS" : "", + (temp & RH_PS_LSDA) ? " LSDA" : "", + (temp & RH_PS_PPS) ? " PPS" : "", + (temp & RH_PS_PRS) ? " PRS" : "", + (temp & RH_PS_POCI) ? " POCI" : "", + (temp & RH_PS_PSS) ? " PSS" : "", - (temp & RH_PS_PES) ? " PES" : "", - (temp & RH_PS_CCS) ? " CCS" : "" - ); - } + (temp & RH_PS_PES) ? " PES" : "", + (temp & RH_PS_CCS) ? " CCS" : "" + ); + } } static void ohci_dump(ohci_t *ohci, int verbose) { - dbg("OHCI controller usb-%s-%c state\r\n", ohci->slot_name, (char)ohci->controller + '0'); - /* dumps some of the state we know about */ - ohci_dump_status(ohci); - if (verbose) - ep_print_int_eds(ohci, "hcca"); - dbg("hcca frame #%04x\r\n", ohci->hcca->frame_no); - ohci_dump_roothub(ohci, 1); + dbg("OHCI controller usb-%s-%c state\r\n", ohci->slot_name, (char)ohci->controller + '0'); + /* dumps some of the state we know about */ + ohci_dump_status(ohci); + if (verbose) + ep_print_int_eds(ohci, "hcca"); + dbg("hcca frame #%04x\r\n", ohci->hcca->frame_no); + ohci_dump_roothub(ohci, 1); } #endif /* DEBUG_OHCI */ @@ -461,134 +461,134 @@ static void ohci_dump(ohci_t *ohci, int verbose) static int sohci_submit_job(ohci_t *ohci, urb_priv_t *urb, struct devrequest *setup) { - ed_t *ed; - urb_priv_t *purb_priv = urb; - int i; - int size = 0; - struct usb_device *dev = urb->dev; - uint32_t pipe = urb->pipe; - void *buffer = urb->transfer_buffer; - int transfer_len = urb->transfer_buffer_length; - int interval = urb->interval; + ed_t *ed; + urb_priv_t *purb_priv = urb; + int i; + int size = 0; + struct usb_device *dev = urb->dev; + uint32_t pipe = urb->pipe; + void *buffer = urb->transfer_buffer; + int transfer_len = urb->transfer_buffer_length; + int interval = urb->interval; - /* - * when controller's hung, permit only roothub cleanup attempts - * such as powering down ports - */ - if (ohci->disabled) - { - urb_free_priv(purb_priv); // added - err("sohci_submit_job: EPIPE\r\n"); + /* + * when controller's hung, permit only roothub cleanup attempts + * such as powering down ports + */ + if (ohci->disabled) + { + urb_free_priv(purb_priv); // added + err("sohci_submit_job: EPIPE\r\n"); - return -1; - } + return -1; + } - /* - * we're about to begin a new transaction here so mark the - * URB unfinished - */ - urb->finished = 0; + /* + * we're about to begin a new transaction here so mark the + * URB unfinished + */ + urb->finished = 0; - /* every endpoint has an ed, locate and fill it */ - ed = ep_add_ed(ohci, dev, pipe, interval, 1); - if (!ed) - { - urb_free_priv(purb_priv); // added - err("sohci_submit_job: ENOMEM"); - return -1; - } + /* every endpoint has an ed, locate and fill it */ + ed = ep_add_ed(ohci, dev, pipe, interval, 1); + if (!ed) + { + urb_free_priv(purb_priv); // added + err("sohci_submit_job: ENOMEM"); + return -1; + } - /* for the private part of the URB we need the number of TDs (size) */ - switch (usb_pipetype(pipe)) - { - case PIPE_BULK: /* one TD for every 4096 Byte */ - size = (transfer_len - 1) / 4096 + 1; - break; + /* for the private part of the URB we need the number of TDs (size) */ + switch (usb_pipetype(pipe)) + { + case PIPE_BULK: /* one TD for every 4096 Byte */ + size = (transfer_len - 1) / 4096 + 1; + break; - case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */ - size = (transfer_len == 0) ? 2 : (transfer_len - 1) / 4096 + 3; - break; + case PIPE_CONTROL:/* 1 TD for setup, 1 for ACK and 1 for every 4096 B */ + size = (transfer_len == 0) ? 2 : (transfer_len - 1) / 4096 + 3; + break; - case PIPE_INTERRUPT: /* 1 TD */ - size = 1; - break; - } - ed->purb = urb; - if (size >= (N_URB_TD - 1)) - { - urb_free_priv(purb_priv); // added - err("need %d TDs, only have %d", size, N_URB_TD); - return -1; - } - purb_priv->pipe = pipe; + case PIPE_INTERRUPT: /* 1 TD */ + size = 1; + break; + } + ed->purb = urb; + if (size >= (N_URB_TD - 1)) + { + urb_free_priv(purb_priv); // added + err("need %d TDs, only have %d", size, N_URB_TD); + return -1; + } + purb_priv->pipe = pipe; - /* fill the private part of the URB */ - purb_priv->length = size; - purb_priv->ed = ed; - purb_priv->actual_length = 0; + /* fill the private part of the URB */ + purb_priv->length = size; + purb_priv->ed = ed; + purb_priv->actual_length = 0; - /* allocate the TDs */ - /* note that td[0] was allocated in ep_add_ed */ - for (i = 0; i < size; i++) - { - purb_priv->td[i] = td_alloc(dev); - if (!purb_priv->td[i]) - { - purb_priv->length = i; - urb_free_priv(purb_priv); - err("sohci_submit_job: ENOMEM\r\n"); - return -1; - } - } + /* allocate the TDs */ + /* note that td[0] was allocated in ep_add_ed */ + for (i = 0; i < size; i++) + { + purb_priv->td[i] = td_alloc(dev); + if (!purb_priv->td[i]) + { + purb_priv->length = i; + urb_free_priv(purb_priv); + err("sohci_submit_job: ENOMEM\r\n"); + return -1; + } + } - if (ed->state == ED_NEW || (ed->state & ED_DEL)) - { - urb_free_priv(purb_priv); - err("sohci_submit_job: EINVAL\r\n"); - return -1; - } + if (ed->state == ED_NEW || (ed->state & ED_DEL)) + { + urb_free_priv(purb_priv); + err("sohci_submit_job: EINVAL\r\n"); + return -1; + } - /* link the ed into a chain if is not already */ - if (ed->state != ED_OPER) - ep_link(ohci, ed); + /* link the ed into a chain if is not already */ + if (ed->state != ED_OPER) + ep_link(ohci, ed); - /* fill the TDs and link it to the ed */ - td_submit_job(ohci, dev, pipe, buffer, transfer_len, setup, purb_priv, interval); - return 0; + /* fill the TDs and link it to the ed */ + td_submit_job(ohci, dev, pipe, buffer, transfer_len, setup, purb_priv, interval); + return 0; } static inline int sohci_return_job(ohci_t *ohci, urb_priv_t *urb) { - struct ohci_regs *regs = ohci->regs; + struct ohci_regs *regs = ohci->regs; - switch (usb_pipetype(urb->pipe)) - { - case PIPE_INTERRUPT: - /* implicitly requeued */ - if ((urb->dev->irq_handle != NULL) && (urb->dev->irq_act_len = urb->actual_length)) - { - writel(OHCI_INTR_WDH, ®s->intrenable); - readl(®s->intrenable); /* PCI posting flush */ + switch (usb_pipetype(urb->pipe)) + { + case PIPE_INTERRUPT: + /* implicitly requeued */ + if ((urb->dev->irq_handle != NULL) && (urb->dev->irq_act_len = urb->actual_length)) + { + writel(OHCI_INTR_WDH, ®s->intrenable); + readl(®s->intrenable); /* PCI posting flush */ - /* call interrupt device routine */ + /* call interrupt device routine */ // dbg("irq_handle device %d", urb->dev->devnum); - urb->dev->irq_handle(urb->dev); + urb->dev->irq_handle(urb->dev); - writel(OHCI_INTR_WDH, ®s->intrdisable); - readl(®s->intrdisable); /* PCI posting flush */ - } - urb->actual_length = 0; - td_submit_job(ohci, urb->dev, urb->pipe, urb->transfer_buffer, urb->transfer_buffer_length, NULL, urb, urb->interval); - break; + writel(OHCI_INTR_WDH, ®s->intrdisable); + readl(®s->intrdisable); /* PCI posting flush */ + } + urb->actual_length = 0; + td_submit_job(ohci, urb->dev, urb->pipe, urb->transfer_buffer, urb->transfer_buffer_length, NULL, urb, urb->interval); + break; - case PIPE_CONTROL: - case PIPE_BULK: - break; + case PIPE_CONTROL: + case PIPE_BULK: + break; - default: - return 0; - } - return 1; + default: + return 0; + } + return 1; } /*-------------------------------------------------------------------------*/ @@ -598,7 +598,7 @@ static inline int sohci_return_job(ohci_t *ohci, urb_priv_t *urb) static int sohci_get_current_frame_number(ohci_t *ohci, struct usb_device *usb_dev) { - return swpw(ohci->hcca->frame_no); + return swpw(ohci->hcca->frame_no); } #endif @@ -615,22 +615,22 @@ static int sohci_get_current_frame_number(ohci_t *ohci, struct usb_device *usb_d static int ep_int_balance(ohci_t *ohci, int interval, int load) { - int i; - int branch = 0; + int i; + int branch = 0; - /* - * search for the least loaded interrupt endpoint - * branch of all 32 branches - */ - for (i = 0; i < 32; i++) - { - if (ohci->ohci_int_load[branch] > ohci->ohci_int_load[i]) - branch = i; - } - branch = branch % interval; - for (i = branch; i < 32; i += interval) - ohci->ohci_int_load[i] += load; - return branch; + /* + * search for the least loaded interrupt endpoint + * branch of all 32 branches + */ + for (i = 0; i < 32; i++) + { + if (ohci->ohci_int_load[branch] > ohci->ohci_int_load[i]) + branch = i; + } + branch = branch % interval; + for (i = branch; i < 32; i += interval) + ohci->ohci_int_load[i] += load; + return branch; } /*-------------------------------------------------------------------------*/ @@ -639,10 +639,10 @@ static int ep_int_balance(ohci_t *ohci, int interval, int load) static int ep_2_n_interval(int inter) { - int i; + int i; - for (i = 0; ((inter >> i) > 1) && (i < 5); i++); - return 1 << i; + for (i = 0; ((inter >> i) > 1) && (i < 5); i++); + return 1 << i; } /*-------------------------------------------------------------------------*/ @@ -654,13 +654,13 @@ static int ep_2_n_interval(int inter) */ static int ep_rev(int num_bits, int word) { - int i; - int wout = 0; + int i; + int wout = 0; - for (i = 0; i < num_bits; i++) - wout |= (((word >> i) & 1) << (num_bits - i - 1)); + for (i = 0; i < num_bits; i++) + wout |= (((word >> i) & 1) << (num_bits - i - 1)); - return wout; + return wout; } /*-------------------------------------------------------------------------* @@ -671,68 +671,68 @@ static int ep_rev(int num_bits, int word) static int ep_link(ohci_t *ohci, ed_t *edi) { - volatile ed_t *ed = edi; - int int_branch; - int i; - int inter; - int interval; - int load; - uint32_t *ed_p; + volatile ed_t *ed = edi; + int int_branch; + int i; + int inter; + int interval; + int load; + uint32_t *ed_p; - ed->state = ED_OPER; - ed->int_interval = 0; - switch (ed->type) - { - case PIPE_CONTROL: - ed->hwNextED = 0; - if (ohci->ed_controltail == NULL) - writel((uint32_t) ed - ohci->dma_offset, &ohci->regs->ed_controlhead); - else - ohci->ed_controltail->hwNextED = swpl((uint32_t)ed - ohci->dma_offset); + ed->state = ED_OPER; + ed->int_interval = 0; + switch (ed->type) + { + case PIPE_CONTROL: + ed->hwNextED = 0; + if (ohci->ed_controltail == NULL) + writel((uint32_t) ed - ohci->dma_offset, &ohci->regs->ed_controlhead); + else + ohci->ed_controltail->hwNextED = swpl((uint32_t)ed - ohci->dma_offset); - ed->ed_prev = ohci->ed_controltail; - if (!ohci->ed_controltail && !ohci->ed_rm_list[0] && !ohci->ed_rm_list[1] && !ohci->sleeping) - { - ohci->hc_control |= OHCI_CTRL_CLE; - writel(ohci->hc_control, &ohci->regs->control); - } - ohci->ed_controltail = edi; - break; + ed->ed_prev = ohci->ed_controltail; + if (!ohci->ed_controltail && !ohci->ed_rm_list[0] && !ohci->ed_rm_list[1] && !ohci->sleeping) + { + ohci->hc_control |= OHCI_CTRL_CLE; + writel(ohci->hc_control, &ohci->regs->control); + } + ohci->ed_controltail = edi; + break; - case PIPE_BULK: - ed->hwNextED = 0; - if (ohci->ed_bulktail == NULL) - writel((uint32_t) ed - ohci->dma_offset, &ohci->regs->ed_bulkhead); - else - ohci->ed_bulktail->hwNextED = swpl((uint32_t)ed - ohci->dma_offset); - ed->ed_prev = ohci->ed_bulktail; - if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] && !ohci->ed_rm_list[1] && !ohci->sleeping) - { - ohci->hc_control |= OHCI_CTRL_BLE; - writel(ohci->hc_control, &ohci->regs->control); - } - ohci->ed_bulktail = edi; - break; + case PIPE_BULK: + ed->hwNextED = 0; + if (ohci->ed_bulktail == NULL) + writel((uint32_t) ed - ohci->dma_offset, &ohci->regs->ed_bulkhead); + else + ohci->ed_bulktail->hwNextED = swpl((uint32_t)ed - ohci->dma_offset); + ed->ed_prev = ohci->ed_bulktail; + if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] && !ohci->ed_rm_list[1] && !ohci->sleeping) + { + ohci->hc_control |= OHCI_CTRL_BLE; + writel(ohci->hc_control, &ohci->regs->control); + } + ohci->ed_bulktail = edi; + break; - case PIPE_INTERRUPT: - load = ed->int_load; - interval = ep_2_n_interval(ed->int_period); - ed->int_interval = interval; - int_branch = ep_int_balance(ohci, interval, load); - ed->int_branch = int_branch; - for (i = 0; i < ep_rev(6, interval); i += inter) - { - inter = 1; - for (ed_p = &(ohci->hcca->int_table[ep_rev(5, i) + int_branch]); - (*ed_p != 0) && (((ed_t *)ed_p)->int_interval >= interval); - ed_p = &(((ed_t *)ed_p)->hwNextED)) - inter = ep_rev(6, ((ed_t *)ed_p)->int_interval); - ed->hwNextED = *ed_p; - *ed_p = swpl((uint32_t)ed - ohci->dma_offset); - } - break; - } - return 0; + case PIPE_INTERRUPT: + load = ed->int_load; + interval = ep_2_n_interval(ed->int_period); + ed->int_interval = interval; + int_branch = ep_int_balance(ohci, interval, load); + ed->int_branch = int_branch; + for (i = 0; i < ep_rev(6, interval); i += inter) + { + inter = 1; + for (ed_p = &(ohci->hcca->int_table[ep_rev(5, i) + int_branch]); + (*ed_p != 0) && (((ed_t *)ed_p)->int_interval >= interval); + ed_p = &(((ed_t *)ed_p)->hwNextED)) + inter = ep_rev(6, ((ed_t *)ed_p)->int_interval); + ed->hwNextED = *ed_p; + *ed_p = swpl((uint32_t)ed - ohci->dma_offset); + } + break; + } + return 0; } /*-------------------------------------------------------------------------*/ @@ -740,21 +740,21 @@ static int ep_link(ohci_t *ohci, ed_t *edi) /* scan the periodic table to find and unlink this ED */ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed, unsigned index, unsigned period) { - for ( ;index < NUM_INTS; index += period) - { - uint32_t *ed_p = &ohci->hcca->int_table[index]; + for ( ;index < NUM_INTS; index += period) + { + uint32_t *ed_p = &ohci->hcca->int_table[index]; - /* ED might have been unlinked through another path */ - while (*ed_p != 0) - { - if ((uint32_t)*ed_p == swpl((uint32_t)ed - ohci->dma_offset)) /* changed */ - { - *ed_p = ed->hwNextED; - break; - } - ed_p = &(((struct ed *)ed_p)->hwNextED); /* changed */ - } - } + /* ED might have been unlinked through another path */ + while (*ed_p != 0) + { + if ((uint32_t)*ed_p == swpl((uint32_t)ed - ohci->dma_offset)) /* changed */ + { + *ed_p = ed->hwNextED; + break; + } + ed_p = &(((struct ed *)ed_p)->hwNextED); /* changed */ + } + } } /* @@ -766,57 +766,57 @@ static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed, unsigned static int ep_unlink(ohci_t *ohci, ed_t *edi) { - volatile ed_t *ed = edi; - int i; + volatile ed_t *ed = edi; + int i; - ed->hwINFO |= swpl(OHCI_ED_SKIP); - switch (ed->type) - { - case PIPE_CONTROL: - if (ed->ed_prev == NULL) - { - if (!ed->hwNextED) - { - ohci->hc_control &= ~OHCI_CTRL_CLE; - writel(ohci->hc_control, &ohci->regs->control); - } - writel(swpl(*((uint32_t *)&ed->hwNextED)), &ohci->regs->ed_controlhead); - } - else - ed->ed_prev->hwNextED = ed->hwNextED; - if (ohci->ed_controltail == ed) - ohci->ed_controltail = ed->ed_prev; - else - ((ed_t *)(swpl(*((uint32_t *)&ed->hwNextED)) + ohci->dma_offset))->ed_prev = ed->ed_prev; - break; + ed->hwINFO |= swpl(OHCI_ED_SKIP); + switch (ed->type) + { + case PIPE_CONTROL: + if (ed->ed_prev == NULL) + { + if (!ed->hwNextED) + { + ohci->hc_control &= ~OHCI_CTRL_CLE; + writel(ohci->hc_control, &ohci->regs->control); + } + writel(swpl(*((uint32_t *)&ed->hwNextED)), &ohci->regs->ed_controlhead); + } + else + ed->ed_prev->hwNextED = ed->hwNextED; + if (ohci->ed_controltail == ed) + ohci->ed_controltail = ed->ed_prev; + else + ((ed_t *)(swpl(*((uint32_t *)&ed->hwNextED)) + ohci->dma_offset))->ed_prev = ed->ed_prev; + break; - case PIPE_BULK: - if (ed->ed_prev == NULL) - { - if (!ed->hwNextED) - { - ohci->hc_control &= ~OHCI_CTRL_BLE; - writel(ohci->hc_control, &ohci->regs->control); - } - writel(swpl(*((uint32_t *) &ed->hwNextED)), &ohci->regs->ed_bulkhead); - } - else - ed->ed_prev->hwNextED = ed->hwNextED; + case PIPE_BULK: + if (ed->ed_prev == NULL) + { + if (!ed->hwNextED) + { + ohci->hc_control &= ~OHCI_CTRL_BLE; + writel(ohci->hc_control, &ohci->regs->control); + } + writel(swpl(*((uint32_t *) &ed->hwNextED)), &ohci->regs->ed_bulkhead); + } + else + ed->ed_prev->hwNextED = ed->hwNextED; - if (ohci->ed_bulktail == ed) - ohci->ed_bulktail = ed->ed_prev; - else - ((ed_t *)(swpl(*((uint32_t *) &ed->hwNextED)) + ohci->dma_offset))->ed_prev = ed->ed_prev; - break; + if (ohci->ed_bulktail == ed) + ohci->ed_bulktail = ed->ed_prev; + else + ((ed_t *)(swpl(*((uint32_t *) &ed->hwNextED)) + ohci->dma_offset))->ed_prev = ed->ed_prev; + break; - case PIPE_INTERRUPT: - periodic_unlink(ohci, ed, 0, 1); - for (i = ed->int_branch; i < 32; i += ed->int_interval) - ohci->ohci_int_load[i] -= ed->int_load; - break; - } - ed->state = ED_UNLINK; - return 0; + case PIPE_INTERRUPT: + periodic_unlink(ohci, ed, 0, 1); + for (i = ed->int_branch; i < 32; i += ed->int_interval) + ohci->ohci_int_load[i] -= ed->int_load; + break; + } + ed->state = ED_UNLINK; + return 0; } /*-------------------------------------------------------------------------*/ @@ -832,43 +832,43 @@ static int ep_unlink(ohci_t *ohci, ed_t *edi) */ static ed_t *ep_add_ed(ohci_t *ohci, struct usb_device *usb_dev, uint32_t pipe, int interval, int load) { - td_t *td; - ed_t *ed_ret; - volatile ed_t *ed; - struct ohci_device *ohci_dev = ohci->ohci_dev; + td_t *td; + ed_t *ed_ret; + volatile ed_t *ed; + struct ohci_device *ohci_dev = ohci->ohci_dev; - ed = ed_ret = &ohci_dev->ed[(usb_pipeendpoint(pipe) << 1) | (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))]; - if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) - { - err("ep_add_ed: pending delete"); - /* pending delete request */ - return NULL; - } + ed = ed_ret = &ohci_dev->ed[(usb_pipeendpoint(pipe) << 1) | (usb_pipecontrol(pipe)? 0: usb_pipeout(pipe))]; + if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) + { + err("ep_add_ed: pending delete"); + /* pending delete request */ + return NULL; + } - if (ed->state == ED_NEW) - { - /* dummy td; end of td list for ed */ - td = td_alloc(usb_dev); - ed->hwTailP = swpl((uint32_t)td - ohci->dma_offset); - ed->hwHeadP = ed->hwTailP; - ed->state = ED_UNLINK; - ed->type = usb_pipetype(pipe); - ohci_dev->ed_cnt++; - } + if (ed->state == ED_NEW) + { + /* dummy td; end of td list for ed */ + td = td_alloc(usb_dev); + ed->hwTailP = swpl((uint32_t)td - ohci->dma_offset); + ed->hwHeadP = ed->hwTailP; + ed->state = ED_UNLINK; + ed->type = usb_pipetype(pipe); + ohci_dev->ed_cnt++; + } - ed->hwINFO = swpl(usb_pipedevice(pipe) - | usb_pipeendpoint(pipe) << 7 - | (usb_pipeisoc(pipe)? 0x8000: 0) - | (usb_pipecontrol(pipe)? 0: (usb_pipeout(pipe)? 0x800: 0x1000)) - | usb_pipeslow(pipe) << 13 - | usb_maxpacket(usb_dev, pipe) << 16); + ed->hwINFO = swpl(usb_pipedevice(pipe) + | usb_pipeendpoint(pipe) << 7 + | (usb_pipeisoc(pipe)? 0x8000: 0) + | (usb_pipecontrol(pipe)? 0: (usb_pipeout(pipe)? 0x800: 0x1000)) + | usb_pipeslow(pipe) << 13 + | usb_maxpacket(usb_dev, pipe) << 16); - if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) - { - ed->int_period = interval; - ed->int_load = load; - } - return ed_ret; + if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) + { + ed->int_period = interval; + ed->int_load = load; + } + return ed_ret; } /*-------------------------------------------------------------------------* @@ -878,67 +878,67 @@ static ed_t *ep_add_ed(ohci_t *ohci, struct usb_device *usb_dev, uint32_t pipe, /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */ static void td_fill(ohci_t *ohci, unsigned int info, void *data, int len, - struct usb_device *dev, int index, urb_priv_t *urb_priv) + struct usb_device *dev, int index, urb_priv_t *urb_priv) { - volatile td_t *td; - volatile td_t *td_pt; + volatile td_t *td; + volatile td_t *td_pt; #ifdef OHCI_FILL_TRACE - int i; + int i; #endif - if (index > urb_priv->length) - { - err("index > length"); - return; - } - /* use this td as the next dummy */ - td_pt = urb_priv->td[index]; - td_pt->hwNextTD = 0; + if (index > urb_priv->length) + { + err("index > length"); + return; + } + /* use this td as the next dummy */ + td_pt = urb_priv->td[index]; + td_pt->hwNextTD = 0; - /* fill the old dummy TD */ - td = urb_priv->td[index] = (td_t *)((swpl(urb_priv->ed->hwTailP) & ~0xf) + ohci->dma_offset); - td->ed = urb_priv->ed; - td->next_dl_td = NULL; - td->index = index; - td->data = (uint32_t)data; + /* fill the old dummy TD */ + td = urb_priv->td[index] = (td_t *)((swpl(urb_priv->ed->hwTailP) & ~0xf) + ohci->dma_offset); + td->ed = urb_priv->ed; + td->next_dl_td = NULL; + td->index = index; + td->data = (uint32_t)data; #ifdef OHCI_FILL_TRACE - if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) - { - for (i = 0; i < len; i++) - dbg("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]); - dbg("\r\n"); - } + if (usb_pipebulk(urb_priv->pipe) && usb_pipeout(urb_priv->pipe)) + { + for (i = 0; i < len; i++) + dbg("td->data[%d] %#2x ", i, ((unsigned char *)td->data)[i]); + dbg("\r\n"); + } #endif - if (!len) - data = NULL; - td->hwINFO = swpl(info); - if (data != NULL) - { - td->hwCBP = swpl((uint32_t)data - ohci->dma_offset); - td->hwBE = swpl((uint32_t)(data + len - 1 - ohci->dma_offset)); - } - else - { - td->hwCBP = 0; - td->hwBE = 0; - } - td->hwNextTD = swpl((uint32_t)td_pt - ohci->dma_offset); - /* append to queue */ - td->ed->hwTailP = td->hwNextTD; + if (!len) + data = NULL; + td->hwINFO = swpl(info); + if (data != NULL) + { + td->hwCBP = swpl((uint32_t)data - ohci->dma_offset); + td->hwBE = swpl((uint32_t)(data + len - 1 - ohci->dma_offset)); + } + else + { + td->hwCBP = 0; + td->hwBE = 0; + } + td->hwNextTD = swpl((uint32_t)td_pt - ohci->dma_offset); + /* append to queue */ + td->ed->hwTailP = td->hwNextTD; #if 0 - if (data) - { - int i; - dbg("td_fill: %08x %08x %08X %08X at 0x%08X\r\n", - swpl(td->hwINFO), swpl(td->hwCBP), swpl(td->hwNextTD), swpl(td->hwBE), td); - for (i = 0; i < len; i++) - dbg("%02X ", *(unsigned char *)(data + i) & 0xff); - dbg("\r\n"); - } - else - dbg("td_fill: %08x %08x %08X %08X at 0x%08X\r\n", - swpl(td->hwINFO), swpl(td->hwCBP), swpl(td->hwNextTD), swpl(td->hwBE), td); + if (data) + { + int i; + dbg("td_fill: %08x %08x %08X %08X at 0x%08X\r\n", + swpl(td->hwINFO), swpl(td->hwCBP), swpl(td->hwNextTD), swpl(td->hwBE), td); + for (i = 0; i < len; i++) + dbg("%02X ", *(unsigned char *)(data + i) & 0xff); + dbg("\r\n"); + } + else + dbg("td_fill: %08x %08x %08X %08X at 0x%08X\r\n", + swpl(td->hwINFO), swpl(td->hwCBP), swpl(td->hwNextTD), swpl(td->hwBE), td); #endif } @@ -947,72 +947,72 @@ static void td_fill(ohci_t *ohci, unsigned int info, void *data, int len, /* prepare all TDs of a transfer */ static void td_submit_job(ohci_t *ohci, struct usb_device *dev, uint32_t pipe, - void *buffer, int transfer_len, struct devrequest *setup, - urb_priv_t *urb, int interval) + void *buffer, int transfer_len, struct devrequest *setup, + urb_priv_t *urb, int interval) { - int data_len = transfer_len; - void *data; - int cnt = 0; - uint32_t info = 0; - unsigned int toggle = 0; + int data_len = transfer_len; + void *data; + int cnt = 0; + uint32_t info = 0; + unsigned int toggle = 0; - /* OHCI handles the DATA-toggles itself, we just use the USB-toggle - * bits for reseting */ - if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) - toggle = TD_T_TOGGLE; - else - { - toggle = TD_T_DATA0; - usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1); - } + /* OHCI handles the DATA-toggles itself, we just use the USB-toggle + * bits for reseting */ + if (usb_gettoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) + toggle = TD_T_TOGGLE; + else + { + toggle = TD_T_DATA0; + usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 1); + } - urb->td_cnt = 0; - if (data_len) - data = buffer; - else - data = NULL; + urb->td_cnt = 0; + if (data_len) + data = buffer; + else + data = NULL; - switch (usb_pipetype(pipe)) - { - case PIPE_BULK: - info = usb_pipeout(pipe) ? TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ; - while (data_len > 4096) - { - td_fill(ohci, info | (cnt? TD_T_TOGGLE : toggle), data, 4096, dev, cnt, urb); - data += 4096; data_len -= 4096; cnt++; - } - info = usb_pipeout(pipe) ? TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ; - td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb); - cnt++; - if (!ohci->sleeping) /* start bulk list */ - writel(OHCI_BLF, &ohci->regs->cmdstatus); - break; + switch (usb_pipetype(pipe)) + { + case PIPE_BULK: + info = usb_pipeout(pipe) ? TD_CC | TD_DP_OUT : TD_CC | TD_DP_IN ; + while (data_len > 4096) + { + td_fill(ohci, info | (cnt? TD_T_TOGGLE : toggle), data, 4096, dev, cnt, urb); + data += 4096; data_len -= 4096; cnt++; + } + info = usb_pipeout(pipe) ? TD_CC | TD_DP_OUT : TD_CC | TD_R | TD_DP_IN ; + td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data, data_len, dev, cnt, urb); + cnt++; + if (!ohci->sleeping) /* start bulk list */ + writel(OHCI_BLF, &ohci->regs->cmdstatus); + break; - case PIPE_CONTROL: - /* Setup phase */ - info = TD_CC | TD_DP_SETUP | TD_T_DATA0; - td_fill(ohci, info, setup, 8, dev, cnt++, urb); - /* Optional Data phase */ - if (data_len > 0) - { - info = usb_pipeout(pipe) ? TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1; - /* NOTE: mishandles transfers >8K, some >4K */ - td_fill(ohci, info, data, data_len, dev, cnt++, urb); - } - /* Status phase */ - info = usb_pipeout(pipe) ? TD_CC | TD_DP_IN | TD_T_DATA1 : TD_CC | TD_DP_OUT | TD_T_DATA1; - td_fill(ohci, info, data, 0, dev, cnt++, urb); - if (!ohci->sleeping) /* start Control list */ - writel(OHCI_CLF, &ohci->regs->cmdstatus); - break; + case PIPE_CONTROL: + /* Setup phase */ + info = TD_CC | TD_DP_SETUP | TD_T_DATA0; + td_fill(ohci, info, setup, 8, dev, cnt++, urb); + /* Optional Data phase */ + if (data_len > 0) + { + info = usb_pipeout(pipe) ? TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1; + /* NOTE: mishandles transfers >8K, some >4K */ + td_fill(ohci, info, data, data_len, dev, cnt++, urb); + } + /* Status phase */ + info = usb_pipeout(pipe) ? TD_CC | TD_DP_IN | TD_T_DATA1 : TD_CC | TD_DP_OUT | TD_T_DATA1; + td_fill(ohci, info, data, 0, dev, cnt++, urb); + if (!ohci->sleeping) /* start Control list */ + writel(OHCI_CLF, &ohci->regs->cmdstatus); + break; - case PIPE_INTERRUPT: - info = usb_pipeout(urb->pipe) ? TD_CC | TD_DP_OUT | toggle : TD_CC | TD_R | TD_DP_IN | toggle; - td_fill(ohci, info, data, data_len, dev, cnt++, urb); - break; - } - if (urb->length != cnt) - dbg("TD LENGTH %d != CNT %d", urb->length, cnt); + case PIPE_INTERRUPT: + info = usb_pipeout(urb->pipe) ? TD_CC | TD_DP_OUT | toggle : TD_CC | TD_R | TD_DP_IN | toggle; + td_fill(ohci, info, data, data_len, dev, cnt++, urb); + break; + } + if (urb->length != cnt) + dbg("TD LENGTH %d != CNT %d", urb->length, cnt); } /*-------------------------------------------------------------------------* @@ -1023,56 +1023,56 @@ static void td_submit_job(ohci_t *ohci, struct usb_device *dev, uint32_t pipe, static void dl_transfer_length(ohci_t *ohci, td_t *td) { - uint32_t tdBE; - uint32_t tdCBP; + uint32_t tdBE; + uint32_t tdCBP; - urb_priv_t *lurb_priv = td->ed->purb; + urb_priv_t *lurb_priv = td->ed->purb; - tdBE = swpl(td->hwBE); - tdCBP = swpl(td->hwCBP); + tdBE = swpl(td->hwBE); + tdCBP = swpl(td->hwCBP); - if (tdBE) - tdBE += ohci->dma_offset; - if (tdCBP) - tdCBP += ohci->dma_offset; + if (tdBE) + tdBE += ohci->dma_offset; + if (tdCBP) + tdCBP += ohci->dma_offset; - if (!(usb_pipecontrol(lurb_priv->pipe) && ((td->index == 0) || (td->index == lurb_priv->length - 1)))) - { - if (tdBE != 0) - { - if (td->hwCBP == 0) - lurb_priv->actual_length += (tdBE - td->data + 1); - else - lurb_priv->actual_length += (tdCBP - td->data); - } - } + if (!(usb_pipecontrol(lurb_priv->pipe) && ((td->index == 0) || (td->index == lurb_priv->length - 1)))) + { + if (tdBE != 0) + { + if (td->hwCBP == 0) + lurb_priv->actual_length += (tdBE - td->data + 1); + else + lurb_priv->actual_length += (tdCBP - td->data); + } + } } /*-------------------------------------------------------------------------*/ static void check_status(ohci_t *ohci, td_t *td_list) { - urb_priv_t *lurb_priv = td_list->ed->purb; - int urb_len = lurb_priv->length; - uint32_t *phwHeadP = &td_list->ed->hwHeadP; - int cc = TD_CC_GET(swpl(td_list->hwINFO)); + urb_priv_t *lurb_priv = td_list->ed->purb; + int urb_len = lurb_priv->length; + uint32_t *phwHeadP = &td_list->ed->hwHeadP; + int cc = TD_CC_GET(swpl(td_list->hwINFO)); - if (cc) - { - err("OHCI usb-%s-%c error: %s (%x)\r\n", ohci->slot_name, (char) ohci->controller + '0', cc_to_string[cc], cc); - if (*phwHeadP & swpl(0x1)) - { - if (lurb_priv && ((td_list->index + 1) < urb_len)) - { - *phwHeadP = (lurb_priv->td[urb_len - 1]->hwNextTD & swpl(0xfffffff0)) | (*phwHeadP & swpl(0x2)); - lurb_priv->td_cnt += urb_len - td_list->index - 1; - } - else - *phwHeadP &= swpl(0xfffffff2); - } + if (cc) + { + err("OHCI usb-%s-%c error: %s (%x)\r\n", ohci->slot_name, (char) ohci->controller + '0', cc_to_string[cc], cc); + if (*phwHeadP & swpl(0x1)) + { + if (lurb_priv && ((td_list->index + 1) < urb_len)) + { + *phwHeadP = (lurb_priv->td[urb_len - 1]->hwNextTD & swpl(0xfffffff0)) | (*phwHeadP & swpl(0x2)); + lurb_priv->td_cnt += urb_len - td_list->index - 1; + } + else + *phwHeadP &= swpl(0xfffffff2); + } #ifdef CONFIG_MPC5200 - td_list->hwNextTD = 0; + td_list->hwNextTD = 0; #endif - } + } } /* @@ -1081,44 +1081,44 @@ static void check_status(ohci_t *ohci, td_t *td_list) */ static td_t *dl_reverse_done_list(ohci_t *ohci) { - uint32_t td_list_hc; - td_t *td_rev = NULL; - td_t *td_list = NULL; + uint32_t td_list_hc; + td_t *td_rev = NULL; + td_t *td_list = NULL; - td_list_hc = swpl(ohci->hcca->done_head) & ~0xf; + td_list_hc = swpl(ohci->hcca->done_head) & ~0xf; - if (td_list_hc) + if (td_list_hc) { - td_list_hc += ohci->dma_offset; + td_list_hc += ohci->dma_offset; } - ohci->hcca->done_head = 0; - while (td_list_hc) - { + ohci->hcca->done_head = 0; + while (td_list_hc) + { td_list = (td_t *) td_list_hc; - check_status(ohci, td_list); - td_list->next_dl_td = td_rev; - td_rev = td_list; - td_list_hc = swpl(td_list->hwNextTD) & ~0xf; - if (td_list_hc) + check_status(ohci, td_list); + td_list->next_dl_td = td_rev; + td_rev = td_list; + td_list_hc = swpl(td_list->hwNextTD) & ~0xf; + if (td_list_hc) { - td_list_hc += ohci->dma_offset; + td_list_hc += ohci->dma_offset; } - } - return td_list; + } + return td_list; } /*-------------------------------------------------------------------------*/ static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status) { - if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL)) + if ((status & (ED_OPER | ED_UNLINK)) && (urb->state != URB_DEL)) { - urb->finished = sohci_return_job(ohci, urb); + urb->finished = sohci_return_job(ohci, urb); } - else + else { - dbg("finish_urb: strange.., ED state %x, \r\n", status); + dbg("finish_urb: strange.., ED state %x, \r\n", status); } } @@ -1130,82 +1130,82 @@ static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status) */ static int takeback_td(ohci_t *ohci, td_t *td_list) { - ed_t *ed; - int cc; + ed_t *ed; + int cc; int stat = 0; - urb_priv_t *lurb_priv; + urb_priv_t *lurb_priv; uint32_t tdINFO; uint32_t edHeadP; uint32_t edTailP; - tdINFO = swpl(td_list->hwINFO); + tdINFO = swpl(td_list->hwINFO); - ed = td_list->ed; - if (ed == NULL) - { + ed = td_list->ed; + if (ed == NULL) + { err("OHCI usb-%s-%c cannot get error code ED is null\r\n", ohci->slot_name, (char) ohci->controller + '0'); - return stat; - } + return stat; + } - lurb_priv = ed->purb; - dl_transfer_length(ohci, td_list); - lurb_priv->td_cnt++; + lurb_priv = ed->purb; + dl_transfer_length(ohci, td_list); + lurb_priv->td_cnt++; - /* error code of transfer */ - cc = TD_CC_GET(tdINFO); - if (cc) - { + /* error code of transfer */ + cc = TD_CC_GET(tdINFO); + if (cc) + { err("OHCI usb-%s-%c error: %s (%x)\r\n", ohci->slot_name, (char) ohci->controller + '0', cc_to_string[cc], cc); - stat = cc_to_error[cc]; - } + stat = cc_to_error[cc]; + } /* * see if this done list makes for all TD's of current URB, * and mark the URB finished if so */ - if (lurb_priv->td_cnt == lurb_priv->length) + if (lurb_priv->td_cnt == lurb_priv->length) { - finish_urb(ohci, lurb_priv, ed->state); + finish_urb(ohci, lurb_priv, ed->state); } - if (ohci->irq) + if (ohci->irq) { dbg("dl_done_list: processing TD %x, len %x\r\n", lurb_priv->td_cnt, lurb_priv->length); } - if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) - { - edHeadP = swpl(ed->hwHeadP) & ~0xf; - edTailP = swpl(ed->hwTailP); - - /* unlink eds if they are not busy */ - if ((edHeadP == edTailP) && (ed->state == ED_OPER)) - { - ep_unlink(ohci, ed); - } - } - - if (cc && (ed->type == PIPE_INTERRUPT)) /* added, but it's not the better method */ + if (ed->state != ED_NEW && (!usb_pipeint(lurb_priv->pipe))) { - ep_unlink(ohci, ed); + edHeadP = swpl(ed->hwHeadP) & ~0xf; + edTailP = swpl(ed->hwTailP); + + /* unlink eds if they are not busy */ + if ((edHeadP == edTailP) && (ed->state == ED_OPER)) + { + ep_unlink(ohci, ed); + } } - return stat; + + if (cc && (ed->type == PIPE_INTERRUPT)) /* added, but it's not the better method */ + { + ep_unlink(ohci, ed); + } + return stat; } static int dl_done_list(ohci_t *ohci) { - int stat = 0; - td_t *td_list = dl_reverse_done_list(ohci); + int stat = 0; + td_t *td_list = dl_reverse_done_list(ohci); - while (td_list) - { - td_t *td_next = td_list->next_dl_td; + while (td_list) + { + td_t *td_next = td_list->next_dl_td; - stat = takeback_td(ohci, td_list); - td_list = td_next; - } - return stat; + stat = takeback_td(ohci, td_list); + td_list = td_next; + } + return stat; } /*-------------------------------------------------------------------------* @@ -1215,99 +1215,99 @@ static int dl_done_list(ohci_t *ohci) /* Device descriptor */ static uint8_t root_hub_dev_des[] = { - 0x12, /* uint8_t bLength; */ - 0x01, /* uint8_t bDescriptorType; Device */ - 0x10, /* uint16_t bcdUSB; v1.1 */ - 0x01, - 0x09, /* uint8_t bDeviceClass; HUB_CLASSCODE */ - 0x00, /* uint8_t bDeviceSubClass; */ - 0x00, /* uint8_t bDeviceProtocol; */ - 0x08, /* uint8_t bMaxPacketSize0; 8 Bytes */ - 0x00, /* uint16_t idVendor; */ - 0x00, - 0x00, /* uint16_t idProduct; */ - 0x00, - 0x00, /* uint16_t bcdDevice; */ - 0x00, - 0x00, /* uint8_t iManufacturer; */ - 0x01, /* uint8_t iProduct; */ - 0x00, /* uint8_t iSerialNumber; */ - 0x01 /* uint8_t bNumConfigurations; */ + 0x12, /* uint8_t bLength; */ + 0x01, /* uint8_t bDescriptorType; Device */ + 0x10, /* uint16_t bcdUSB; v1.1 */ + 0x01, + 0x09, /* uint8_t bDeviceClass; HUB_CLASSCODE */ + 0x00, /* uint8_t bDeviceSubClass; */ + 0x00, /* uint8_t bDeviceProtocol; */ + 0x08, /* uint8_t bMaxPacketSize0; 8 Bytes */ + 0x00, /* uint16_t idVendor; */ + 0x00, + 0x00, /* uint16_t idProduct; */ + 0x00, + 0x00, /* uint16_t bcdDevice; */ + 0x00, + 0x00, /* uint8_t iManufacturer; */ + 0x01, /* uint8_t iProduct; */ + 0x00, /* uint8_t iSerialNumber; */ + 0x01 /* uint8_t bNumConfigurations; */ }; /* Configuration descriptor */ static uint8_t root_hub_config_des[] = { - 0x09, /* uint8_t bLength; */ - 0x02, /* uint8_t bDescriptorType; Configuration */ - 0x19, /* uint16_t wTotalLength; */ - 0x00, - 0x01, /* uint8_t bNumInterfaces; */ - 0x01, /* uint8_t bConfigurationValue; */ - 0x00, /* uint8_t iConfiguration; */ - 0x40, /* uint8_t bmAttributes; - Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */ - 0x00, /* uint8_t MaxPower; */ + 0x09, /* uint8_t bLength; */ + 0x02, /* uint8_t bDescriptorType; Configuration */ + 0x19, /* uint16_t wTotalLength; */ + 0x00, + 0x01, /* uint8_t bNumInterfaces; */ + 0x01, /* uint8_t bConfigurationValue; */ + 0x00, /* uint8_t iConfiguration; */ + 0x40, /* uint8_t bmAttributes; + Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */ + 0x00, /* uint8_t MaxPower; */ - /* interface */ - 0x09, /* uint8_t if_bLength; */ - 0x04, /* uint8_t if_bDescriptorType; Interface */ - 0x00, /* uint8_t if_bInterfaceNumber; */ - 0x00, /* uint8_t if_bAlternateSetting; */ - 0x01, /* uint8_t if_bNumEndpoints; */ - 0x09, /* uint8_t if_bInterfaceClass; HUB_CLASSCODE */ - 0x00, /* uint8_t if_bInterfaceSubClass; */ - 0x00, /* uint8_t if_bInterfaceProtocol; */ - 0x00, /* uint8_t if_iInterface; */ + /* interface */ + 0x09, /* uint8_t if_bLength; */ + 0x04, /* uint8_t if_bDescriptorType; Interface */ + 0x00, /* uint8_t if_bInterfaceNumber; */ + 0x00, /* uint8_t if_bAlternateSetting; */ + 0x01, /* uint8_t if_bNumEndpoints; */ + 0x09, /* uint8_t if_bInterfaceClass; HUB_CLASSCODE */ + 0x00, /* uint8_t if_bInterfaceSubClass; */ + 0x00, /* uint8_t if_bInterfaceProtocol; */ + 0x00, /* uint8_t if_iInterface; */ - /* endpoint */ - 0x07, /* uint8_t ep_bLength; */ - 0x05, /* uint8_t ep_bDescriptorType; Endpoint */ - 0x81, /* uint8_t ep_bEndpointAddress; IN Endpoint 1 */ - 0x03, /* uint8_t ep_bmAttributes; Interrupt */ - 0x02, /* uint16_t ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */ - 0x00, - 0xff /* uint8_t ep_bInterval; 255 ms */ + /* endpoint */ + 0x07, /* uint8_t ep_bLength; */ + 0x05, /* uint8_t ep_bDescriptorType; Endpoint */ + 0x81, /* uint8_t ep_bEndpointAddress; IN Endpoint 1 */ + 0x03, /* uint8_t ep_bmAttributes; Interrupt */ + 0x02, /* uint16_t ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */ + 0x00, + 0xff /* uint8_t ep_bInterval; 255 ms */ }; static unsigned char root_hub_str_index0[] = { - 0x04, /* uint8_t bLength; */ - 0x03, /* uint8_t bDescriptorType; String-descriptor */ - 0x09, /* uint8_t lang ID */ - 0x04, /* uint8_t lang ID */ + 0x04, /* uint8_t bLength; */ + 0x03, /* uint8_t bDescriptorType; String-descriptor */ + 0x09, /* uint8_t lang ID */ + 0x04, /* uint8_t lang ID */ }; static unsigned char root_hub_str_index1[] = { - 28, /* uint8_t bLength; */ - 0x03, /* uint8_t bDescriptorType; String-descriptor */ - 'O', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'H', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'C', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'I', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - ' ', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'R', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'o', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'o', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 't', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - ' ', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'H', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'u', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ - 'b', /* uint8_t Unicode */ - 0, /* uint8_t Unicode */ + 28, /* uint8_t bLength; */ + 0x03, /* uint8_t bDescriptorType; String-descriptor */ + 'O', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'H', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'C', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'I', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + ' ', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'R', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'o', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'o', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 't', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + ' ', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'H', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'u', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ + 'b', /* uint8_t Unicode */ + 0, /* uint8_t Unicode */ }; /* Hub class-specific descriptor is constructed dynamically */ @@ -1316,8 +1316,8 @@ static unsigned char root_hub_str_index1[] = #define OK(x) len = (x); break #ifdef DEBUG_OHCI -#define WR_RH_STAT(x) { info("WR:status %#8x", (x)); writel((x), &ohci->regs->roothub.status); } -#define WR_RH_PORTSTAT(x) { info("WR:portstatus[%d] %#8x", wIndex - 1, (x)); writel((x), &ohci->regs->roothub.portstatus[wIndex - 1]); } +#define WR_RH_STAT(x) { err("WR:status %#8x", (x)); writel((x), &ohci->regs->roothub.status); } +#define WR_RH_PORTSTAT(x) { err("WR:portstatus[%d] %#8x", wIndex - 1, (x)); writel((x), &ohci->regs->roothub.portstatus[wIndex - 1]); } #else #define WR_RH_STAT(x) { writel((x), &ohci->regs->roothub.status); } #define WR_RH_PORTSTAT(x) { writel((x), &ohci->regs->roothub.portstatus[wIndex - 1]); } @@ -1329,69 +1329,70 @@ static unsigned char root_hub_str_index1[] = int rh_check_port_status(ohci_t *controller) { - uint32_t temp, ndp, i; - int res = -1; - temp = roothub_a(controller); + uint32_t temp, ndp, i; + int res = -1; + temp = roothub_a(controller); // ndp = (temp & RH_A_NDP); - ndp = controller->ndp; - for (i = 0; i < ndp; i++) - { - temp = roothub_portstatus(controller, i); + ndp = controller->ndp; + for (i = 0; i < ndp; i++) + { + temp = roothub_portstatus(controller, i); - /* check for a device disconnect */ - if (((temp & (RH_PS_PESC | RH_PS_CSC)) == (RH_PS_PESC | RH_PS_CSC)) && ((temp & RH_PS_CCS) == 0)) - { - res = i; - break; - } + /* check for a device disconnect */ + if (((temp & (RH_PS_PESC | RH_PS_CSC)) == (RH_PS_PESC | RH_PS_CSC)) && ((temp & RH_PS_CCS) == 0)) + { + res = i; + break; + } - /* check for a device connect */ - if ((temp & RH_PS_CSC) && (temp & RH_PS_CCS)) - { - res = i; - break; - } - } - return res; + /* check for a device connect */ + if ((temp & RH_PS_CSC) && (temp & RH_PS_CCS)) + { + res = i; + break; + } + } + return res; } static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pipe, - void *buffer, int transfer_len, struct devrequest *cmd) + void *buffer, int transfer_len, struct devrequest *cmd) { - void *data = buffer; - int leni = transfer_len; - int len = 0; - int stat = 0; - uint32_t datab[4]; - uint8_t *data_buf = (uint8_t *)datab; - uint16_t bmRType_bReq; - uint16_t wValue; - uint16_t wIndex; - uint16_t wLength; + void *data = buffer; + int leni = transfer_len; + int len = 0; + int stat = 0; + uint32_t datab[4]; + uint8_t *data_buf = (uint8_t *)datab; + uint16_t bmRType_bReq; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; #ifdef DEBUG_OHCI - pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe)); + pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, cmd, "SUB(rh)", usb_pipein(pipe)); #else - if (ohci->irq) + if (ohci->irq) { - wait(1 * 1000); + wait(10); } #endif - if (usb_pipeint(pipe)) - { - err("Root-Hub submit IRQ: NOT implemented"); - return 0; - } + if (usb_pipeint(pipe)) + { + err("Root-Hub submit IRQ: NOT implemented\r\n"); - bmRType_bReq = cmd->requesttype | (cmd->request << 8); - wValue = swpw(cmd->value); - wIndex = swpw(cmd->index); - wLength = swpw(cmd->length); + return 0; + } + + bmRType_bReq = cmd->requesttype | (cmd->request << 8); + wValue = swpw(cmd->value); + wIndex = swpw(cmd->index); + wLength = swpw(cmd->length); dbg("Root-Hub: adr: %2x cmd(%1x): %08x %04x %04x %04x\r\n", dev->devnum, 8, bmRType_bReq, wValue, wIndex, wLength); - switch (bmRType_bReq) - { + switch (bmRType_bReq) + { /* * Request Destination: * without flags: Device, @@ -1400,113 +1401,113 @@ static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pip * RH_CLASS means HUB here, * RH_OTHER | RH_CLASS almost ever means HUB_PORT here */ - case RH_GET_STATUS: + case RH_GET_STATUS: *(uint16_t *) data_buf = swpw(1); - OK(2); + OK(2); - case RH_GET_STATUS | RH_INTERFACE: - *(uint16_t *)data_buf = swpw(0); - OK(2); + case RH_GET_STATUS | RH_INTERFACE: + *(uint16_t *) data_buf = swpw(0); + OK(2); - case RH_GET_STATUS | RH_ENDPOINT: - *(uint16_t *)data_buf = swpw(0); - OK(2); + case RH_GET_STATUS | RH_ENDPOINT: + *(uint16_t *) data_buf = swpw(0); + OK(2); - case RH_GET_STATUS | RH_CLASS: - *(uint32_t *)data_buf = swpl(RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE)); - OK(4); + case RH_GET_STATUS | RH_CLASS: + *(uint32_t *) data_buf = swpl(RD_RH_STAT & ~(RH_HS_CRWE | RH_HS_DRWE)); + OK(4); - case RH_GET_STATUS | RH_OTHER | RH_CLASS: - *(uint32_t *)data_buf = swpl(RD_RH_PORTSTAT); - OK(4); + case RH_GET_STATUS | RH_OTHER | RH_CLASS: + *(uint32_t *) data_buf = swpl(RD_RH_PORTSTAT); + OK(4); - case RH_CLEAR_FEATURE | RH_ENDPOINT: - switch (wValue) - { - case (RH_ENDPOINT_STALL): OK(0); - } - break; + case RH_CLEAR_FEATURE | RH_ENDPOINT: + switch (wValue) + { + case (RH_ENDPOINT_STALL): OK(0); + } + break; - case RH_CLEAR_FEATURE | RH_CLASS: - switch (wValue) - { - case RH_C_HUB_LOCAL_POWER: OK(0); - case (RH_C_HUB_OVER_CURRENT): WR_RH_STAT(RH_HS_OCIC); OK(0); - } - break; + case RH_CLEAR_FEATURE | RH_CLASS: + switch (wValue) + { + case RH_C_HUB_LOCAL_POWER: OK(0); + case (RH_C_HUB_OVER_CURRENT): WR_RH_STAT(RH_HS_OCIC); OK(0); + } + break; - case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS: - switch (wValue) - { - case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0); - case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0); - case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0); - case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0); - case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0); - case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0); - case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0); - case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0); - } - break; + case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS: + switch (wValue) + { + case (RH_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_CCS); OK(0); + case (RH_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_POCI); OK(0); + case (RH_PORT_POWER): WR_RH_PORTSTAT(RH_PS_LSDA); OK(0); + case (RH_C_PORT_CONNECTION): WR_RH_PORTSTAT(RH_PS_CSC); OK(0); + case (RH_C_PORT_ENABLE): WR_RH_PORTSTAT(RH_PS_PESC); OK(0); + case (RH_C_PORT_SUSPEND): WR_RH_PORTSTAT(RH_PS_PSSC); OK(0); + case (RH_C_PORT_OVER_CURRENT):WR_RH_PORTSTAT(RH_PS_OCIC); OK(0); + case (RH_C_PORT_RESET): WR_RH_PORTSTAT(RH_PS_PRSC); OK(0); + } + break; - case RH_SET_FEATURE | RH_OTHER | RH_CLASS: - switch (wValue) - { - case (RH_PORT_SUSPEND): - WR_RH_PORTSTAT(RH_PS_PSS); - OK(0); - case (RH_PORT_RESET): /* BUG IN HUP CODE *********/ - if (RD_RH_PORTSTAT & RH_PS_CCS) - WR_RH_PORTSTAT(RH_PS_PRS); - OK(0); - case (RH_PORT_POWER): - WR_RH_PORTSTAT(RH_PS_PPS); - wait(100 * 1000); - OK(0); - case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/ - if (RD_RH_PORTSTAT & RH_PS_CCS) - WR_RH_PORTSTAT(RH_PS_PES); - OK(0); - } - break; + case RH_SET_FEATURE | RH_OTHER | RH_CLASS: + switch (wValue) + { + case (RH_PORT_SUSPEND): + WR_RH_PORTSTAT(RH_PS_PSS); + OK(0); + case (RH_PORT_RESET): /* BUG IN HUP CODE *********/ + if (RD_RH_PORTSTAT & RH_PS_CCS) + WR_RH_PORTSTAT(RH_PS_PRS); + OK(0); + case (RH_PORT_POWER): + WR_RH_PORTSTAT(RH_PS_PPS); + wait(100); + OK(0); + case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/ + if (RD_RH_PORTSTAT & RH_PS_CCS) + WR_RH_PORTSTAT(RH_PS_PES); + OK(0); + } + break; - case RH_SET_ADDRESS: - ohci->rh.devnum = wValue; - OK(0); + case RH_SET_ADDRESS: + ohci->rh.devnum = wValue; + OK(0); - case RH_GET_DESCRIPTOR: - switch ((wValue & 0xff00) >> 8) - { - case(0x01): /* device descriptor */ - len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_dev_des), wLength)); - data_buf = root_hub_dev_des; - OK(len); + case RH_GET_DESCRIPTOR: + switch ((wValue & 0xff00) >> 8) + { + case(0x01): /* device descriptor */ + len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_dev_des), wLength)); + data_buf = root_hub_dev_des; + OK(len); - case(0x02): /* configuration descriptor */ - len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_config_des), wLength)); - data_buf = root_hub_config_des; - OK(len); + case(0x02): /* configuration descriptor */ + len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_config_des), wLength)); + data_buf = root_hub_config_des; + OK(len); - case(0x03): /* string descriptors */ - if (wValue == 0x0300) - { - len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_str_index0), wLength)); - data_buf = root_hub_str_index0; - OK(len); - } - if (wValue == 0x0301) - { - len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_str_index1), wLength)); - data_buf = root_hub_str_index1; - OK(len); - } + case(0x03): /* string descriptors */ + if (wValue == 0x0300) + { + len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_str_index0), wLength)); + data_buf = root_hub_str_index0; + OK(len); + } + if (wValue == 0x0301) + { + len = min_t(unsigned int, leni, min_t(unsigned int, sizeof(root_hub_str_index1), wLength)); + data_buf = root_hub_str_index1; + OK(len); + } - default: - stat = USB_ST_STALLED; - } - break; + default: + stat = USB_ST_STALLED; + } + break; - case RH_GET_DESCRIPTOR | RH_CLASS: + case RH_GET_DESCRIPTOR | RH_CLASS: { uint32_t temp = roothub_a(ohci); data_buf[0] = 9; /* min length; */ @@ -1553,35 +1554,35 @@ static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pip case RH_SET_CONFIGURATION: WR_RH_STAT(0x10000); OK(0); default: - dbg("unsupported root hub command"); - stat = USB_ST_STALLED; - } + dbg("unsupported root hub command"); + stat = USB_ST_STALLED; + } #ifdef DEBUG_OHCI - ohci_dump_roothub(ohci, 1); + ohci_dump_roothub(ohci, 1); #else - if (ohci->irq) + if (ohci->irq) { - wait(1 * 1000); + wait(10); } #endif len = min_t(int, len, leni); - if (data != data_buf) + if (data != data_buf) { - memcpy(data, data_buf, len); + memcpy(data, data_buf, len); } dev->act_len = len; - dev->status = stat; + dev->status = stat; #ifdef DEBUG_OHCI - pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/); + pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, cmd, "RET(rh)", 0/*usb_pipein(pipe)*/); #else if (ohci->irq) { - wait(1 * 1000); + wait(10); } #endif @@ -1594,180 +1595,184 @@ static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pip */ static int submit_common_msg(ohci_t *ohci, struct usb_device *dev, uint32_t pipe, void *buffer, - int transfer_len, struct devrequest *setup, int interval) + int transfer_len, struct devrequest *setup, int interval) { - int stat = 0; - int maxsize = usb_maxpacket(dev, pipe); - int timeout; + int stat = 0; + int maxsize = usb_maxpacket(dev, pipe); + int timeout; urb_priv_t *urb = driver_mem_alloc(sizeof(urb_priv_t)); - if (urb == NULL) - { + if (urb == NULL) + { err("submit_common_msg driver_mem_alloc() failed\r\n"); - return -1; - } - memset(urb, 0, sizeof(urb_priv_t)); + return -1; + } + memset(urb, 0, sizeof(urb_priv_t)); - urb->dev = dev; - urb->pipe = pipe; - urb->transfer_buffer = buffer; - urb->transfer_buffer_length = transfer_len; - urb->interval = interval; + urb->dev = dev; + urb->pipe = pipe; + urb->transfer_buffer = buffer; + urb->transfer_buffer_length = transfer_len; + urb->interval = interval; - /* device pulled? Shortcut the action. */ - if (ohci->devgone == dev) - { - dev->status = USB_ST_CRC_ERR; - dbg("device is gone...\r\n"); - return 0; - } -#ifdef DEBUG_OHCI - urb->actual_length = 0; - pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); -#else - if (ohci->irq) + /* device pulled? Shortcut the action. */ + if (ohci->devgone == dev) { - wait(1 * 1000); + dev->status = USB_ST_CRC_ERR; + dbg("device is gone...\r\n"); + return 0; + } +#ifdef DEBUG_OHCI + urb->actual_length = 0; + pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); +#else + if (ohci->irq) + { + wait(10); } #endif - if (!maxsize) - { + if (!maxsize) + { err("submit_common_message: pipesize for pipe %lx is zero\r\n", pipe); - return -1; - } + return -1; + } - if (sohci_submit_job(ohci, urb, setup) < 0) - { + if (sohci_submit_job(ohci, urb, setup) < 0) + { err("sohci_submit_job failed\r\n"); - return -1; - } + return -1; + } #if 0 - wait(10 * 1000); - /* ohci_dump_status(ohci); */ + wait(10); + /* ohci_dump_status(ohci); */ #endif - /* allow more time for a BULK device to react - some are slow */ + /* allow more time for a BULK device to react - some are slow */ #define BULK_TO 5000 /* timeout in milliseconds */ - if (usb_pipebulk(pipe)) + if (usb_pipebulk(pipe)) { - timeout = BULK_TO; + timeout = BULK_TO; } - else + else { - timeout = 1000; + timeout = 1000; } - /* wait for it to complete */ - while (ohci->irq) - { - /* check whether the controller is done */ - flush_data_cache(ohci); + /* wait for it to complete */ + while (ohci->irq) + { + /* check whether the controller is done */ + // flush_data_cache(ohci); no need to do that, PCI is uncached, as well as USB memory #ifndef CONFIG_USB_INTERRUPT_POLLING - if (ohci->irq_enabled) + if (ohci->irq_enabled) { - stat = ohci->stat_irq; + stat = ohci->stat_irq; } - else + else #endif - stat = hc_interrupt(ohci); - if (stat < 0) - { - stat = USB_ST_CRC_ERR; - break; - } - /* NOTE: since we are not interrupt driven in U-Boot and always - * handle only one URB at a time, we cannot assume the - * transaction finished on the first successful return from - * hc_interrupt().. unless the flag for current URB is set, - * meaning that all TD's to/from device got actually - * transferred and processed. If the current URB is not - * finished we need to re-iterate this loop so as - * hc_interrupt() gets called again as there needs to be some - * more TD's to process still */ - if ((stat >= 0) && (stat != 0xff) && (urb->finished)) - { - /* 0xff is returned for an SF-interrupt */ - break; - } + stat = hc_interrupt(ohci); + if (stat < 0) + { + dbg("USB CRC error\r\n"); + stat = USB_ST_CRC_ERR; + break; + } + /* + * NOTE: since we are not interrupt driven in U-Boot and always + * handle only one URB at a time, we cannot assume the + * transaction finished on the first successful return from + * hc_interrupt().. unless the flag for current URB is set, + * meaning that all TD's to/from device got actually + * transferred and processed. If the current URB is not + * finished we need to re-iterate this loop so as + * hc_interrupt() gets called again as there needs to be some + * more TD's to process still + */ + if ((stat >= 0) && (stat != 0xff) && (urb->finished)) + { + /* 0xff is returned for an SF-interrupt */ + break; + } - if (--timeout) - { - wait(1 * 1000); -// if (!urb->finished) -// dbg("*"); - } - else - { - err("OHCI usb-%s-%c CTL:TIMEOUT", ohci->slot_name, (char)ohci->controller + '0'); - dbg("submit_common_msg: TO status %x\r\n", stat); - urb->finished = 1; - stat = USB_ST_CRC_ERR; - break; - } - } - dev->status = stat; - dev->act_len = transfer_len; + if (--timeout) + { + wait(10); + if (!urb->finished) + xprintf("*"); + } + else + { + err("OHCI usb-%s-%c CTL:TIMEOUT", ohci->slot_name, (char)ohci->controller + '0'); + dbg("submit_common_msg: TO status %x\r\n", stat); + urb->finished = 1; + stat = USB_ST_CRC_ERR; + break; + } + } + dbg("\n"); + dev->status = stat; + dev->act_len = transfer_len; #ifdef DEBUG_OHCI - pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe)); + pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, setup, "RET(ctlr)", usb_pipein(pipe)); #else - if (ohci->irq) - wait(1 * 1000); + if (ohci->irq) + wait(10); #endif - /* free TDs in urb_priv */ - if (!usb_pipeint(pipe)) - urb_free_priv(urb); - return 0; + /* free TDs in urb_priv */ + if (!usb_pipeint(pipe)) + urb_free_priv(urb); + return 0; } /* submit routines called from usb.c */ int ohci_submit_bulk_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int transfer_len) { err("submit_bulk_msg dev 0x%p ohci 0x%p buffer 0x%p len %d", dev, dev->priv_hcd, buffer, transfer_len); - return submit_common_msg((ohci_t *)dev->priv_hcd, dev, pipe, buffer, transfer_len, NULL, 0); + return submit_common_msg((ohci_t *)dev->priv_hcd, dev, pipe, buffer, transfer_len, NULL, 0); } int ohci_submit_control_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int transfer_len, struct devrequest *setup) { - ohci_t *ohci = (ohci_t *)dev->priv_hcd; - int maxsize = usb_maxpacket(dev, pipe); + ohci_t *ohci = (ohci_t *)dev->priv_hcd; + int maxsize = usb_maxpacket(dev, pipe); dbg("submit_control_msg dev 0x%p ohci 0x%p\r\n", dev, ohci); #ifdef DEBUG_OHCI - pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); + pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, setup, "SUB", usb_pipein(pipe)); #else - if (ohci->irq) + if (ohci->irq) { - wait(1 * 1000); + wait(10); } #endif - if (!maxsize) - { - err("submit_control_message: pipesize for pipe %lx is zero", pipe); - return -1; - } + if (!maxsize) + { + err("submit_control_message: pipesize for pipe %lx is zero", pipe); + return -1; + } - if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) - { - ohci->rh.dev = dev; + if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) + { + ohci->rh.dev = dev; - /* root hub - redirect */ - return ohci_submit_rh_msg(ohci, dev, pipe, buffer, transfer_len, setup); - } - return submit_common_msg(ohci, dev, pipe, buffer, transfer_len, setup, 0); + /* root hub - redirect */ + return ohci_submit_rh_msg(ohci, dev, pipe, buffer, transfer_len, setup); + } + return submit_common_msg(ohci, dev, pipe, buffer, transfer_len, setup, 0); } int ohci_submit_int_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int transfer_len, int interval) { err("submit_int_msg dev 0x%p ohci 0x%p buffer 0x%p len %d", dev, dev->priv_hcd, buffer, transfer_len); - return submit_common_msg((ohci_t *)dev->priv_hcd, dev, pipe, buffer, transfer_len, NULL, interval); + return submit_common_msg((ohci_t *)dev->priv_hcd, dev, pipe, buffer, transfer_len, NULL, interval); } /*-------------------------------------------------------------------------* @@ -1778,214 +1783,228 @@ int ohci_submit_int_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int static int hc_reset(ohci_t *ohci) { - int timeout = 30; - int smm_timeout = 50; /* 0,5 sec */ + int timeout = 30; + int smm_timeout = 50; /* 0,5 sec */ - if ((ohci->ent->vendor == PCI_VENDOR_ID_PHILIPS) - && (ohci->ent->device == PCI_DEVICE_ID_PHILIPS_ISP1561)) - { + if ((ohci->ent->vendor == PCI_VENDOR_ID_PHILIPS) + && (ohci->ent->device == PCI_DEVICE_ID_PHILIPS_ISP1561)) + { #define EHCI_USBCMD_OFF 0x20 #define EHCI_USBCMD_HCRESET (1 << 1) - /* - * Some multi-function controllers (e.g. ISP1562) allow root hub - * resetting via EHCI registers only. - */ - short index = 0; - long handle; + /* + * Some multi-function controllers (e.g. ISP1562) allow root hub + * resetting via EHCI registers only. + */ + short index = 0; + long handle; - do - { - handle = pci_find_device(0x0, 0xffff, index++); + do + { + handle = pci_find_device(0x0, 0xffff, index++); - if (handle >= 0) - { - uint32_t id = 0; - id = pci_read_config_longword(handle, PCIIDR); - if ((PCI_VENDOR_ID_PHILIPS == (id & 0xFFFF)) && (PCI_DEVICE_ID_PHILIPS_ISP1561_2 == (id >> 16))) - { - int timeout = 1000; - uint32_t usb_base_addr = 0xFFFFFFFF; - struct pci_rd *pci_rsc_desc; - pci_rsc_desc = pci_get_resource(handle); /* USB OHCI */ - if ((long)pci_rsc_desc >= 0) - { - unsigned short flags; - do - { - if (!(pci_rsc_desc->flags & FLG_IO)) - { - if (usb_base_addr == 0xFFFFFFFF) - { - uint32_t base = pci_rsc_desc->offset + pci_rsc_desc->start; - writel((uint32_t) readl((uint32_t *) base + EHCI_USBCMD_OFF) | EHCI_USBCMD_HCRESET, (uint32_t *) base + EHCI_USBCMD_OFF); - while (readl((uint32_t *) base + EHCI_USBCMD_OFF) & EHCI_USBCMD_HCRESET) - { - if (timeout-- <= 0) - { - err("USB RootHub reset timed out!\r\n"); - break; - } - wait(1); - } - } - } - flags = pci_rsc_desc->flags; - pci_rsc_desc = (struct pci_rd *) ((uint32_t) pci_rsc_desc->next + (uint32_t) pci_rsc_desc); - } - while (!(flags & FLG_LAST)); - } - } - } - } - while (handle >= 0); - } - if ((ohci->controller == 0) && (ohci->ent->vendor == PCI_VENDOR_ID_NEC) - && (ohci->ent->device == PCI_DEVICE_ID_NEC_USB)) - { - //if (ohci->handle == 1) /* NEC on motherboard has FPGA clock */ + if (handle >= 0) + { + uint32_t id = 0; + id = pci_read_config_longword(handle, PCIIDR); + if ((PCI_VENDOR_ID_PHILIPS == (id & 0xFFFF)) && (PCI_DEVICE_ID_PHILIPS_ISP1561_2 == (id >> 16))) + { + int timeout = 1000; + uint32_t usb_base_addr = 0xFFFFFFFF; + struct pci_rd *pci_rsc_desc; + pci_rsc_desc = pci_get_resource(handle); /* USB OHCI */ + if ((long)pci_rsc_desc >= 0) + { + unsigned short flags; + do + { + if (!(pci_rsc_desc->flags & FLG_IO)) + { + if (usb_base_addr == 0xFFFFFFFF) + { + uint32_t base = pci_rsc_desc->offset + pci_rsc_desc->start; + writel((uint32_t) readl((uint32_t *) base + EHCI_USBCMD_OFF) | EHCI_USBCMD_HCRESET, (uint32_t *) base + EHCI_USBCMD_OFF); + while (readl((uint32_t *) base + EHCI_USBCMD_OFF) & EHCI_USBCMD_HCRESET) + { + if (timeout-- <= 0) + { + err("USB RootHub reset timed out!\r\n"); + break; + } + wait(1); + } + } + } + flags = pci_rsc_desc->flags; + pci_rsc_desc = (struct pci_rd *) ((uint32_t) pci_rsc_desc->next + (uint32_t) pci_rsc_desc); + } + while (!(flags & FLG_LAST)); + } + } + } + } + while (handle >= 0); + } + if ((ohci->controller == 0) && (ohci->ent->vendor == PCI_VENDOR_ID_NEC) + && (ohci->ent->device == PCI_DEVICE_ID_NEC_USB)) + { + //if (ohci->handle == 1) /* NEC on motherboard has FPGA clock */ #if defined(MACHINE_FIREBEE) - { - dbg("USB OHCI set 48MHz clock\r\n"); - pci_write_config_longword(ohci->handle, 0xE4, 0x21); // oscillator & disable ehci - wait(10); - } - //else + { + dbg("USB OHCI set 48MHz clock\r\n"); + pci_write_config_longword(ohci->handle, 0xE4, 0x21); // oscillator & disable ehci + wait(10); + } + //else #else - { - pci_write_config_longword(ohci->handle, 0xE4, pci_read_config_longword(ohci->handle, 0xE4) | 0x01); // disable ehci - wait(10); - } + { + pci_write_config_longword(ohci->handle, 0xE4, pci_read_config_longword(ohci->handle, 0xE4) | 0x01); // disable ehci + wait(10); + } #endif - } + } - dbg("control: %x\r\n", readl(&ohci->regs->control)); - if (readl(&ohci->regs->control) & OHCI_CTRL_IR) - { - /* SMM owns the HC */ - writel(OHCI_OCR, &ohci->regs->cmdstatus);/* request ownership */ + dbg("control: %x\r\n", readl(&ohci->regs->control)); + if (readl(&ohci->regs->control) & OHCI_CTRL_IR) + { + /* SMM owns the HC */ + writel(OHCI_OCR, &ohci->regs->cmdstatus);/* request ownership */ err("USB HC TakeOver from SMM"); - while (readl(&ohci->regs->control) & OHCI_CTRL_IR) - { - wait(10); - if (--smm_timeout == 0) - { - err("USB HC TakeOver failed!"); - return -1; - } - } - } + while (readl(&ohci->regs->control) & OHCI_CTRL_IR) + { + wait(10); + if (--smm_timeout == 0) + { + err("USB HC TakeOver failed!"); + return -1; + } + } + } - /* Disable HC interrupts */ - writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); + /* Disable HC interrupts */ + writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); #ifdef DEBUG_OHCI - ohci_dump_status(ohci); + ohci_dump_status(ohci); #endif /* DEBUG_OHCI */ - dbg("USB OHCI HC reset_hc usb-%s-%c: ctrl = 0x%X\r\n", ohci->slot_name, - (char) ohci->controller + '0', readl(&ohci->regs->control)); + dbg("USB OHCI HC reset_hc usb-%s-%c: ctrl = 0x%X\r\n", ohci->slot_name, + (char) ohci->controller + '0', readl(&ohci->regs->control)); - /* Reset USB (needed by some controllers) */ - ohci->hc_control = 0; - writel(ohci->hc_control, &ohci->regs->control); - wait(50); + /* Reset USB (needed by some controllers) */ + ohci->hc_control = 0; + writel(ohci->hc_control, &ohci->regs->control); + wait(50); - /* HC Reset requires max 10 us delay */ - writel(OHCI_HCR, &ohci->regs->cmdstatus); - while ((readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) - { - if (--timeout == 0) - { - err("USB HC reset timed out!"); + /* HC Reset requires max 10 us delay */ + writel(OHCI_HCR, &ohci->regs->cmdstatus); + while ((readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) + { + if (--timeout == 0) + { + err("USB HC reset timed out!"); #ifdef DEBUG_OHCI - ohci_dump_status(ohci); + ohci_dump_status(ohci); #endif /* DEBUG_OHCI */ - return -1; - } - wait(10); - } - return 0; + return -1; + } + wait(10); + } + return 0; } /*-------------------------------------------------------------------------*/ -/* Start an OHCI controller, set the BUS operational +/* + * Start an OHCI controller, set the BUS operational * enable interrupts - * connect the virtual root hub */ + * connect the virtual root hub + */ static int hc_start(ohci_t *ohci) { - uint32_t mask; - unsigned int fminterval; - ohci->disabled = 1; - /* Tell the controller where the control and bulk lists are - * The lists are empty now. */ - writel(0, &ohci->regs->ed_controlhead); - writel(0, &ohci->regs->ed_bulkhead); - writel((uint32_t)ohci->hcca - ohci->dma_offset, &ohci->regs->hcca); /* a reset clears this */ - fminterval = 0x2edf; - writel((fminterval * 9) / 10, &ohci->regs->periodicstart); - fminterval |= ((((fminterval - 210) * 6) / 7) << 16); - writel(fminterval, &ohci->regs->fminterval); - writel(0x628, &ohci->regs->lsthresh); - /* start controller operations */ - ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER; - ohci->disabled = 0; - writel(ohci->hc_control, &ohci->regs->control); - /* disable all interrupts */ - mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD | - OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC | OHCI_INTR_OC | OHCI_INTR_MIE); - writel(mask, &ohci->regs->intrdisable); - /* clear all interrupts */ - mask &= ~OHCI_INTR_MIE; - writel(mask, &ohci->regs->intrstatus); - /* Choose the interrupts we care about now - but w/o MIE */ - mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO; - writel(mask, &ohci->regs->intrenable); - ohci->ndp = roothub_a(ohci); + uint32_t mask; + unsigned int fminterval; + + ohci->disabled = 1; + + /* + * Tell the controller where the control and bulk lists are + * The lists are empty now. + */ + writel(0, &ohci->regs->ed_controlhead); + writel(0, &ohci->regs->ed_bulkhead); + + writel((uint32_t) ohci->hcca - ohci->dma_offset, &ohci->regs->hcca); /* a reset clears this */ + + fminterval = 0x2edf; + writel((fminterval * 9) / 10, &ohci->regs->periodicstart); + + fminterval |= ((((fminterval - 210) * 6) / 7) << 16); + writel(fminterval, &ohci->regs->fminterval); + writel(0x628, &ohci->regs->lsthresh); + + /* start controller operations */ + ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER; + ohci->disabled = 0; + writel(ohci->hc_control, &ohci->regs->control); + + /* disable all interrupts */ + mask = (OHCI_INTR_SO | OHCI_INTR_WDH | OHCI_INTR_SF | OHCI_INTR_RD | + OHCI_INTR_UE | OHCI_INTR_FNO | OHCI_INTR_RHSC | OHCI_INTR_OC | OHCI_INTR_MIE); + writel(mask, &ohci->regs->intrdisable); + + /* clear all interrupts */ + mask &= ~OHCI_INTR_MIE; + writel(mask, &ohci->regs->intrstatus); + + /* Choose the interrupts we care about now - but w/o MIE */ + mask = OHCI_INTR_RHSC | OHCI_INTR_UE | OHCI_INTR_WDH | OHCI_INTR_SO; + writel(mask, &ohci->regs->intrenable); + ohci->ndp = roothub_a(ohci); + #ifdef OHCI_USE_NPS - /* required for AMD-756 and some Mac platforms */ - writel((ohci->ndp | RH_A_NPS) & ~RH_A_PSM, &ohci->regs->roothub.a); - writel(RH_HS_LPSC, &ohci->regs->roothub.status); + /* required for AMD-756 and some Mac platforms */ + writel((ohci->ndp | RH_A_NPS) & ~RH_A_PSM, &ohci->regs->roothub.a); + writel(RH_HS_LPSC, &ohci->regs->roothub.status); #endif /* OHCI_USE_NPS */ - /* POTPGT delay is bits 24-31, in 2 ms units. */ - wait((ohci->ndp >> 23) & 0x1fe); - ohci->ndp &= RH_A_NDP; - /* connect the virtual root hub */ - ohci->rh.devnum = 0; - return 0; + + /* POTPGT delay is bits 24-31, in 2 ms units. */ +#define mdelay(n) ({unsigned long msec = (n); while (msec--) wait(1); }) + mdelay((ohci->ndp >> 23) & 0x1fe); + ohci->ndp &= RH_A_NDP; + + /* connect the virtual root hub */ + ohci->rh.devnum = 0; + + return 0; } -static void flush_data_cache(ohci_t *ohci) -{ - /* flush caches here */ -} #ifdef CONFIG_USB_INTERRUPT_POLLING /* Poll USB interrupt. */ void ohci_usb_event_poll(int interrupt) { - if (ohci_inited) - { - int i; - for (i = 0; i < (sizeof(gohci) / sizeof(ohci_t)); i++) - { - ohci_t *ohci = &gohci[i]; - if (!ohci->handle || ohci->disabled) - continue; - else - { - flush_data_cache(ohci); - if (interrupt) - ohci->irq = 0; - hc_interrupt(ohci); - if (interrupt) - ohci->irq = -1; - } - } - } + if (ohci_inited) + { + int i; + for (i = 0; i < (sizeof(gohci) / sizeof(ohci_t)); i++) + { + ohci_t *ohci = &gohci[i]; + if (!ohci->handle || ohci->disabled) + continue; + else + { + flush_data_cache(ohci); + if (interrupt) + ohci->irq = 0; + hc_interrupt(ohci); + if (interrupt) + ohci->irq = -1; + } + } + } } #endif /* CONFIG_USB_INTERRUPT_POLLING */ @@ -1995,156 +2014,160 @@ void ohci_usb_event_poll(int interrupt) */ static int hc_interrupt(ohci_t *ohci) { - struct ohci_regs *regs = ohci->regs; + struct ohci_regs *regs = ohci->regs; int ints; int stat = -1; - if ((ohci->hcca->done_head != 0) && !(swpl(ohci->hcca->done_head) & 0x01)) + if ((ohci->hcca->done_head != 0) && !(swpl(ohci->hcca->done_head) & 0x01)) { - ints = OHCI_INTR_WDH; + ints = OHCI_INTR_WDH; } - else - { - ints = readl(®s->intrstatus); + else + { + ints = readl(®s->intrstatus); if (ints == ~ 0UL) - { - ohci->disabled++; + { + ohci->disabled++; err("OHCI usb-%s-%c device removed!\r\n", ohci->slot_name, (char) ohci->controller + '0'); - return -1; - } - else - { - ints &= readl(®s->intrenable); - if (ints == 0) - { + return -1; + } + else + { + ints &= readl(®s->intrenable); + if (ints == 0) + { dbg("no interrupt...\r\n"); return 0xff; - } - } - } + } + } + } - if (ohci->irq) + if (ohci->irq) { dbg("Interrupt: 0x%x frame: 0x%x bus: %d\r\n", ints, swpw(ohci->hcca->frame_no), ohci->controller); } - if (ints & OHCI_INTR_RHSC) /* root hub status change */ - { + if (ints & OHCI_INTR_RHSC) /* root hub status change */ + { #ifdef USB_POLL_HUB - if ((queue_poll_hub != NULL) && (rh_check_port_status(ohci) >= 0)) - { - if (ohci->irq) - xQueueAltSend(queue_poll_hub, (void *)&ohci->usbnum, 0); - else - { - portBASE_TYPE xNeedSwitch = pdFALSE; - xNeedSwitch = xQueueSendFromISR(queue_poll_hub, &ohci->usbnum, xNeedSwitch); - } /* to fix xNeedSwitch usage */ - } -#endif /* USB_POLL_HUB */ - stat = 0xff; - } - - if (ints & OHCI_INTR_UE) /* e.g. due to PCI Master/Target Abort */ - { - unsigned short status = pci_read_config_word(ohci->handle, PCISR); - - (void) status; - - err("OHCI Unrecoverable Error, controller usb-%s-%c disabled\r\n(SR:0x%04X%s%s%s%s%s%s)", - ohci->slot_name, (char) ohci->controller + '0', status & 0xFFFF, - status & 0x8000 ? ", Parity error" : "", - status & 0x4000 ? ", Signaled system error" : "", - status & 0x2000 ? ", Received master abort" : "", - status & 0x1000 ? ", Received target abort" : "", - status & 0x800 ? ", Signaled target abort" : "", - status & 0x100 ? ", Data parity error" : ""); - ohci->disabled++; -#ifdef DEBUG_OHCI - ohci_dump(ohci, 1); -#else - if (ohci->irq) + if ((queue_poll_hub != NULL) && (rh_check_port_status(ohci) >= 0)) { - wait(1); + if (ohci->irq) + xQueueAltSend(queue_poll_hub, (void *)&ohci->usbnum, 0); + else + { + portBASE_TYPE xNeedSwitch = pdFALSE; + xNeedSwitch = xQueueSendFromISR(queue_poll_hub, &ohci->usbnum, xNeedSwitch); + } /* to fix xNeedSwitch usage */ + } +#endif /* USB_POLL_HUB */ + stat = 0xff; + } + + if (ints & OHCI_INTR_UE) /* e.g. due to PCI Master/Target Abort */ + { + unsigned short status = pci_read_config_word(ohci->handle, PCISR); + + (void) status; + + err("OHCI Unrecoverable Error, controller usb-%s-%c disabled\r\n(SR:0x%04X%s%s%s%s%s%s)", + ohci->slot_name, (char) ohci->controller + '0', status & 0xFFFF, + status & 0x8000 ? ", Parity error" : "", + status & 0x4000 ? ", Signaled system error" : "", + status & 0x2000 ? ", Received master abort" : "", + status & 0x1000 ? ", Received target abort" : "", + status & 0x800 ? ", Signaled target abort" : "", + status & 0x100 ? ", Data parity error" : ""); + ohci->disabled++; +#ifdef DEBUG_OHCI + ohci_dump(ohci, 1); +#else + if (ohci->irq) + { + wait(1); } #endif - /* HC Reset */ - ohci->hc_control = 0; - writel(ohci->hc_control, &ohci->regs->control); + /* HC Reset */ + ohci->hc_control = 0; + writel(ohci->hc_control, &ohci->regs->control); return -1; - } + } - if (ints & OHCI_INTR_WDH) - { - if (ohci->irq) + if (ints & OHCI_INTR_WDH) + { + if (ohci->irq) { - wait(1); + wait(1); } - writel(OHCI_INTR_WDH, ®s->intrdisable); - (void) readl(®s->intrdisable); /* flush */ - stat = dl_done_list(ohci); + writel(OHCI_INTR_WDH, ®s->intrdisable); + (void) readl(®s->intrdisable); /* flush */ + stat = dl_done_list(ohci); - writel(OHCI_INTR_WDH, ®s->intrenable); - (void) readl(®s->intrdisable); /* flush */ - } + writel(OHCI_INTR_WDH, ®s->intrenable); + (void) readl(®s->intrdisable); /* flush */ + } - if (ints & OHCI_INTR_SO) - { - dbg("USB Schedule overrun\r\n"); - writel(OHCI_INTR_SO, ®s->intrenable); - stat = -1; - } + if (ints & OHCI_INTR_SO) + { + dbg("USB Schedule overrun\r\n"); + writel(OHCI_INTR_SO, ®s->intrenable); + stat = -1; + } - /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */ - if (ints & OHCI_INTR_SF) - { - unsigned int frame = swpw(ohci->hcca->frame_no) & 1; + /* FIXME: this assumes SOF (1/ms) interrupts don't get lost... */ + if (ints & OHCI_INTR_SF) + { + unsigned int frame = swpw(ohci->hcca->frame_no) & 1; - if (ohci->irq) - wait(1 * 1000); - writel(OHCI_INTR_SF, ®s->intrdisable); - if (ohci->ed_rm_list[frame] != NULL) - writel(OHCI_INTR_SF, ®s->intrenable); - stat = 0xff; - } - writel(ints, ®s->intrstatus); - return stat; + if (ohci->irq) + wait(1); + writel(OHCI_INTR_SF, ®s->intrdisable); + if (ohci->ed_rm_list[frame] != NULL) + writel(OHCI_INTR_SF, ®s->intrenable); + stat = 0xff; + } + writel(ints, ®s->intrstatus); + return stat; } #ifndef CONFIG_USB_INTERRUPT_POLLING static int handle_usb_interrupt(ohci_t *ohci) { - if (!ohci->irq_enabled) - return 0; + if (!ohci->irq_enabled) + { + dbg("no interrupts enabled\r\n"); - flush_data_cache(ohci); - ohci->irq = 0; - ohci->stat_irq = hc_interrupt(ohci); - ohci->irq = -1; + return 0; + } - return 1; /* clear interrupt, 0: disable interrupt */ + // flush_data_cache(ohci); no need for that + ohci->irq = 0; + ohci->stat_irq = hc_interrupt(ohci); + ohci->irq = -1; + + return 1; /* clear interrupt, 0: disable interrupt */ } void ohci_usb_enable_interrupt(int enable) { - int i; + int i; - dbg("usb_enable_interrupt(%d)", enable); - for (i = 0; i < (sizeof(gohci) / sizeof(ohci_t)); i++) - { - ohci_t *ohci = &gohci[i]; - if (!ohci->handle) - continue; - ohci->irq_enabled = enable; - if (enable) - writel(OHCI_INTR_MIE, &ohci->regs->intrenable); - else - writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); - } + dbg("usb_enable_interrupt(%d)", enable); + for (i = 0; i < (sizeof(gohci) / sizeof(ohci_t)); i++) + { + ohci_t *ohci = &gohci[i]; + if (!ohci->handle) + continue; + ohci->irq_enabled = enable; + if (enable) + writel(OHCI_INTR_MIE, &ohci->regs->intrenable); + else + writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); + } } #endif /* !CONFIG_USB_INTERRUPT_POLLING */ @@ -2153,28 +2176,28 @@ void ohci_usb_enable_interrupt(int enable) static void hc_release_ohci(ohci_t *ohci) { - dbg("USB HC release OHCI usb-%s-%c", ohci->slot_name, (char)ohci->controller + '0'); - if (!ohci->disabled) - hc_reset(ohci); + dbg("USB HC release OHCI usb-%s-%c", ohci->slot_name, (char)ohci->controller + '0'); + if (!ohci->disabled) + hc_reset(ohci); } static void hc_free_buffers(ohci_t *ohci) { - if (ohci->td_unaligned != NULL) - { - /* FIXME: driver_mem_free(ohci->td_unaligned); */ - ohci->td_unaligned = NULL; - } - if (ohci->ohci_dev_unaligned != NULL) - { - /* FIXME: driver_mem_free(ohci->ohci_dev_unaligned); */ - ohci->ohci_dev_unaligned = NULL; - } - if (ohci->hcca_unaligned != NULL) - { - /* FIXME: driver_mem_free(ohci->hcca_unaligned); */ - ohci->hcca_unaligned = NULL; - } + if (ohci->td_unaligned != NULL) + { + /* FIXME: driver_mem_free(ohci->td_unaligned); */ + ohci->td_unaligned = NULL; + } + if (ohci->ohci_dev_unaligned != NULL) + { + /* FIXME: driver_mem_free(ohci->ohci_dev_unaligned); */ + ohci->ohci_dev_unaligned = NULL; + } + if (ohci->hcca_unaligned != NULL) + { + /* FIXME: driver_mem_free(ohci->hcca_unaligned); */ + ohci->hcca_unaligned = NULL; + } } /* @@ -2182,199 +2205,205 @@ static void hc_free_buffers(ohci_t *ohci) */ int ohci_usb_lowlevel_init(int32_t handle, const struct pci_device_id *ent, void **priv) { - uint32_t usb_base_addr = 0xFFFFFFFF; - ohci_t *ohci = &gohci[PCI_FUNCTION_FROM_HANDLE(handle) & 1]; - struct pci_rd *pci_rsc_desc = pci_get_resource(handle); /* USB OHCI */ + uint32_t usb_base_addr = 0xFFFFFFFF; + ohci_t *ohci = &gohci[PCI_FUNCTION_FROM_HANDLE(handle) & 1]; + struct pci_rd *pci_rsc_desc = pci_get_resource(handle); /* USB OHCI */ - if (handle && (ent != NULL)) - { - memset(ohci, 0, sizeof(ohci_t)); - ohci->handle = handle; - ohci->ent = ent; - } - else if (!ohci->handle) /* for restart USB cmd */ - return(-1); + if (handle && (ent != NULL)) + { + memset(ohci, 0, sizeof(ohci_t)); + ohci->handle = handle; + ohci->ent = ent; + } + else if (!ohci->handle) /* for restart USB cmd */ + { + return -1; + } - err("ohci %p", ohci); + err("ohci %p, handle = 0x%x, fctn = 0x%x\r\n", ohci, handle, PCI_FUNCTION_FROM_HANDLE(handle)); - ohci->controller = PCI_FUNCTION_FROM_HANDLE(ohci->handle); - // ohci->controller = (ohci->handle >> 16) & 3; /* PCI function */ + ohci->controller = PCI_FUNCTION_FROM_HANDLE(ohci->handle); - /* this must be aligned to a 256 byte boundary */ + dbg("handle = 0x%x, function = 0x%x\r\n", ohci->handle, ohci->controller); + // ohci->controller = (ohci->handle >> 16) & 3; /* PCI function */ + + /* this must be aligned to a 256 byte boundary */ ohci->hcca_unaligned = driver_mem_alloc(sizeof(struct ohci_hcca) + 256); - if (ohci->hcca_unaligned == NULL) - { - err("HCCA malloc failed"); - return(-1); - } + if (ohci->hcca_unaligned == NULL) + { + err("HCCA malloc failed\r\n"); + return -1; + } - /* align the storage */ - ohci->hcca = (struct ohci_hcca *) (((uint32_t) ohci->hcca_unaligned + 255) & ~255); - memset(ohci->hcca, 0, sizeof(struct ohci_hcca)); - err("aligned ghcca %p", ohci->hcca); + /* align the storage */ + ohci->hcca = (struct ohci_hcca *) (((uint32_t) ohci->hcca_unaligned + 255) & ~255); + memset(ohci->hcca, 0, sizeof(struct ohci_hcca)); + err("aligned ghcca %p\r\n", ohci->hcca); ohci->ohci_dev_unaligned = driver_mem_alloc(sizeof(struct ohci_device) + 8); - if (ohci->ohci_dev_unaligned == NULL) - { - err("EDs malloc failed"); - hc_free_buffers(ohci); - return(-1); - } - ohci->ohci_dev = (struct ohci_device *) (((uint32_t) ohci->ohci_dev_unaligned + 7) & ~7); - memset(ohci->ohci_dev, 0, sizeof(struct ohci_device)); - err("aligned EDs %p", ohci->ohci_dev); + if (ohci->ohci_dev_unaligned == NULL) + { + err("EDs malloc failed\r\n"); + hc_free_buffers(ohci); + + return -1; + } + ohci->ohci_dev = (struct ohci_device *) (((uint32_t) ohci->ohci_dev_unaligned + 7) & ~7); + memset(ohci->ohci_dev, 0, sizeof(struct ohci_device)); + err("aligned EDs %p\r\n", ohci->ohci_dev); ohci->td_unaligned = driver_mem_alloc(sizeof(struct td) * (NUM_TD + 1)); - if (ohci->td_unaligned == NULL) - { - err("TDs malloc failed"); - hc_free_buffers(ohci); - return(-1); - } + if (ohci->td_unaligned == NULL) + { + err("TDs malloc failed\r\n"); + hc_free_buffers(ohci); - ptd = (struct td *) (((uint32_t) ohci->td_unaligned + 7) & ~7); + return -1; + } - dbg("memset from %p to %p\r\n", ptd, ptd + sizeof(td_t) * NUM_TD); - memset(ptd, 0, sizeof(td_t) * NUM_TD); - err("aligned TDs %p", ptd); + ptd = (struct td *) (((uint32_t) ohci->td_unaligned + 7) & ~7); - ohci->disabled = 1; - ohci->sleeping = 0; - ohci->irq = -1; + dbg("memset from %p to %p\r\n", ptd, ptd + sizeof(td_t) * NUM_TD); + memset(ptd, 0, sizeof(td_t) * NUM_TD); + dbg("aligned TDs %p\r\n", ptd); - if (pci_rsc_desc != NULL) - { - unsigned short flags; - do - { - dbg("\r\nPCI USB descriptors (at %p): flags 0x%04x start 0x%08lx \r\n offset 0x%08lx dmaoffset 0x%08lx length 0x%08lx\r\n", - pci_rsc_desc, - pci_rsc_desc->flags, - pci_rsc_desc->start, - pci_rsc_desc->offset, - pci_rsc_desc->dmaoffset, - pci_rsc_desc->length); + ohci->disabled = 1; + ohci->sleeping = 0; + ohci->irq = -1; - if (!(pci_rsc_desc->flags & FLG_IO)) - { - /* if this is a memory-mapped resource */ + if (pci_rsc_desc != NULL) + { + unsigned short flags; + do + { + dbg("\r\nPCI USB descriptors (at %p): flags 0x%04x start 0x%08lx \r\n offset 0x%08lx dmaoffset 0x%08lx length 0x%08lx\r\n", + pci_rsc_desc, + pci_rsc_desc->flags, + pci_rsc_desc->start, + pci_rsc_desc->offset, + pci_rsc_desc->dmaoffset, + pci_rsc_desc->length); - if (usb_base_addr == 0xFFFFFFFF) - { - /* and if its not initialized yet */ + if (!(pci_rsc_desc->flags & FLG_IO)) + { + /* if this is a memory-mapped resource */ - usb_base_addr = pci_rsc_desc->start; - ohci->offset = pci_rsc_desc->offset; - ohci->regs = (void *) (pci_rsc_desc->offset + pci_rsc_desc->start); - ohci->dma_offset = pci_rsc_desc->dmaoffset; + if (usb_base_addr == 0xFFFFFFFF) + { + /* and if its not initialized yet */ - /* big_endian unused actually */ - if ((pci_rsc_desc->flags & FLG_ENDMASK) == ORD_MOTOROLA) - ohci->big_endian = 0; /* host bridge make swapping intel -> motorola */ - else - ohci->big_endian = 1; /* driver must do swapping intel -> motorola */ - } - } - flags = pci_rsc_desc->flags; - pci_rsc_desc = (struct pci_rd *) ((uint32_t) pci_rsc_desc->next + (uint32_t) pci_rsc_desc); - } - while (!(flags & FLG_LAST)); - } - else - { - hc_free_buffers(ohci); - dbg("pci_get_resource() failed\r\n"); + usb_base_addr = pci_rsc_desc->start; + ohci->offset = pci_rsc_desc->offset; + ohci->regs = (void *) (pci_rsc_desc->offset + pci_rsc_desc->start); + ohci->dma_offset = pci_rsc_desc->dmaoffset; - return -1; /* get_resource error */ - } + /* big_endian unused actually */ + if ((pci_rsc_desc->flags & FLG_ENDMASK) == ORD_MOTOROLA) + ohci->big_endian = 0; /* host bridge make swapping intel -> motorola */ + else + ohci->big_endian = 1; /* driver must do swapping intel -> motorola */ + } + } + flags = pci_rsc_desc->flags; + pci_rsc_desc = (struct pci_rd *) ((uint32_t) pci_rsc_desc->next + (uint32_t) pci_rsc_desc); + } + while (!(flags & FLG_LAST)); + } + else + { + hc_free_buffers(ohci); + dbg("pci_get_resource() failed\r\n"); - if (usb_base_addr == 0xFFFFFFFF) - { - hc_free_buffers(ohci); - return -1; - } + return -1; /* get_resource error */ + } - if (handle && (ent != NULL)) - { - ohci->flags = 0; - switch (ent->vendor) - { - case PCI_VENDOR_ID_AL: - ohci->slot_name = "uli1575"; - break; + if (usb_base_addr == 0xFFFFFFFF) + { + hc_free_buffers(ohci); + return -1; + } - case PCI_VENDOR_ID_NEC: - ohci->slot_name = "uPD720101"; - ohci->flags |= OHCI_FLAGS_NEC; - break; + if (handle && (ent != NULL)) + { + ohci->flags = 0; + switch (ent->vendor) + { + case PCI_VENDOR_ID_AL: + ohci->slot_name = "uli1575"; + break; - case PCI_VENDOR_ID_PHILIPS: - ohci->slot_name = "isp1561"; - break; + case PCI_VENDOR_ID_NEC: + ohci->slot_name = "uPD720101"; + ohci->flags |= OHCI_FLAGS_NEC; + break; - default: - ohci->slot_name = "generic"; - break; - } - } + case PCI_VENDOR_ID_PHILIPS: + ohci->slot_name = "isp1561"; + break; - dbg("OHCI usb-%s-%c, regs address 0x%08X, PCI handle 0x%X\r\n", - ohci->slot_name, - (char) ohci->controller + '0', - ohci->regs, handle); + default: + ohci->slot_name = "generic"; + break; + } + } - if (hc_reset(ohci) < 0) - { - err("Can't reset OHCI usb-%s-%c", ohci->slot_name, (char) ohci->controller + '0'); - hc_release_ohci(ohci); - hc_free_buffers(ohci); - return -1; - } + dbg("OHCI usb-%s-%c, regs address 0x%08X, PCI handle 0x%X\r\n", + ohci->slot_name, + (char) ohci->controller + '0', + ohci->regs, handle); - if (hc_start(ohci) < 0) - { - err("Can't start OHCI usb-%s-%c", ohci->slot_name, (char) ohci->controller + '0'); - hc_release_ohci(ohci); - hc_free_buffers(ohci); + if (hc_reset(ohci) < 0) + { + err("Can't reset OHCI usb-%s-%c", ohci->slot_name, (char) ohci->controller + '0'); + hc_release_ohci(ohci); + hc_free_buffers(ohci); + return -1; + } - /* Initialization failed */ - return -1; - } + if (hc_start(ohci) < 0) + { + err("Can't start OHCI usb-%s-%c", ohci->slot_name, (char) ohci->controller + '0'); + hc_release_ohci(ohci); + hc_free_buffers(ohci); + + /* Initialization failed */ + return -1; + } #ifdef DEBUG_OHCI - ohci_dump(ohci, 1); + ohci_dump(ohci, 1); #endif - pci_hook_interrupt(handle, handle_usb_interrupt, ohci); - if (priv != NULL) - *priv = (void *) ohci; + pci_hook_interrupt(handle, handle_usb_interrupt, ohci); + if (priv != NULL) + *priv = (void *) ohci; - ohci_inited = 1; + ohci_inited = 1; - return 0; + return 0; } int ohci_usb_lowlevel_stop(void *priv) { - /* this gets called really early - before the controller has */ - /* even been initialized! */ + /* this gets called really early - before the controller has */ + /* even been initialized! */ - ohci_t *ohci = (ohci_t *) priv; + ohci_t *ohci = (ohci_t *) priv; - if (!ohci_inited) - return 0; + if (!ohci_inited) + return 0; - if (ohci == NULL) - ohci = &gohci[0]; + if (ohci == NULL) + ohci = &gohci[0]; - pci_unhook_interrupt(ohci->handle); + pci_unhook_interrupt(ohci->handle); - hc_reset(ohci); - hc_free_buffers(ohci); + hc_reset(ohci); + hc_free_buffers(ohci); - /* This driver is no longer initialised. It needs a new low-level - * init (board/cpu) before it can be used again. */ + /* This driver is no longer initialised. It needs a new low-level + * init (board/cpu) before it can be used again. */ - ohci_inited = 0; + ohci_inited = 0; - return 0; + return 0; } diff --git a/BaS_gcc/pci/pci.c b/BaS_gcc/pci/pci.c index 54eb004..bb2e82d 100644 --- a/BaS_gcc/pci/pci.c +++ b/BaS_gcc/pci/pci.c @@ -47,29 +47,29 @@ */ static struct pci_class { - int classcode; - char *description; + int classcode; + char *description; } pci_classes[] = { - { 0x00, "device was built prior definition of the class code field" }, - { 0x01, "Mass Storage Controller" }, - { 0x02, "Network Controller" }, - { 0x03, "Display Controller" }, - { 0x04, "Multimedia Controller" }, - { 0x05, "Memory Controller" }, - { 0x06, "Bridge Device" }, - { 0x07, "Simple Communication Controller" }, - { 0x08, "Base System Peripherial" }, - { 0x09, "Input Device" }, - { 0x0a, "Docking Station" }, - { 0x0b, "Processor" }, - { 0x0c, "Serial Bus Controller" }, - { 0x0d, "Wireless Controller" }, - { 0x0e, "Intelligent I/O Controller" }, - { 0x0f, "Satellite Communication Controller" }, - { 0x10, "Encryption/Decryption Controller" }, - { 0x11, "Data Acquisition and Signal Processing Controller" }, - { 0xff, "Device does not fit any defined class" }, + { 0x00, "device was built prior definition of the class code field" }, + { 0x01, "Mass Storage Controller" }, + { 0x02, "Network Controller" }, + { 0x03, "Display Controller" }, + { 0x04, "Multimedia Controller" }, + { 0x05, "Memory Controller" }, + { 0x06, "Bridge Device" }, + { 0x07, "Simple Communication Controller" }, + { 0x08, "Base System Peripherial" }, + { 0x09, "Input Device" }, + { 0x0a, "Docking Station" }, + { 0x0b, "Processor" }, + { 0x0c, "Serial Bus Controller" }, + { 0x0d, "Wireless Controller" }, + { 0x0e, "Intelligent I/O Controller" }, + { 0x0f, "Satellite Communication Controller" }, + { 0x10, "Encryption/Decryption Controller" }, + { 0x11, "Data Acquisition and Signal Processing Controller" }, + { 0xff, "Device does not fit any defined class" }, }; static int num_pci_classes = sizeof(pci_classes) / sizeof(struct pci_class); @@ -101,57 +101,57 @@ static struct pci_interrupt interrupts[MAX_INTERRUPTS]; static inline __attribute__((aligned(16))) void chip_errata_135(void) { - /* - * Errata type: Silicon - * Affected component: PCI - * Description: When core PCI transactions that involve writes to configuration or I/O space - * are followed by a core line access to line addresses 0x4 and 0xC, core access - * to the XL bus can hang. - * Workaround: Prevent PCI configuration and I/O writes from being followed by the described - * line access by the core by generating a known good XL bus transaction after - * the PCI transaction. - * Create a dummy function which is called immediately after each of the affected - * transactions. There are three requirements for this dummy function. - * 1. The function must be aligned to a 16-byte boundary. - * 2. The function must contain a dummy write to a location on the XL bus, - * preferably one with no side effects. - * 3. The function must be longer than 32 bytes. If it is not, the function should - * be padded with 16- or 48-bit TPF instructions placed after the end of - * the function (after the RTS instruction) such that the length is longer - * than 32 bytes. - */ + /* + * Errata type: Silicon + * Affected component: PCI + * Description: When core PCI transactions that involve writes to configuration or I/O space + * are followed by a core line access to line addresses 0x4 and 0xC, core access + * to the XL bus can hang. + * Workaround: Prevent PCI configuration and I/O writes from being followed by the described + * line access by the core by generating a known good XL bus transaction after + * the PCI transaction. + * Create a dummy function which is called immediately after each of the affected + * transactions. There are three requirements for this dummy function. + * 1. The function must be aligned to a 16-byte boundary. + * 2. The function must contain a dummy write to a location on the XL bus, + * preferably one with no side effects. + * 3. The function must be longer than 32 bytes. If it is not, the function should + * be padded with 16- or 48-bit TPF instructions placed after the end of + * the function (after the RTS instruction) such that the length is longer + * than 32 bytes. + */ - __asm__ __volatile( - " .extern __MBAR\n\t" - " clr.l d0\n\t" - " move.l d0,__MBAR+0xF0C\n\t" /* Must use direct addressing. write to EPORT module */ - /* xlbus -> slavebus -> eport, writing '0' to register */ - /* has no effect */ - " rts\n\t" - " tpf.l #0x0\n\t" - " tpf.l #0x0\n\t" - " tpf.l #0x0\n\t" - " tpf.l #0x0\n\t" - " tpf.l #0x0\n\t" - ::: "memory"); + __asm__ __volatile( + " .extern __MBAR\n\t" + " clr.l d0\n\t" + " move.l d0,__MBAR+0xF0C\n\t" /* Must use direct addressing. write to EPORT module */ + /* xlbus -> slavebus -> eport, writing '0' to register */ + /* has no effect */ + " rts\n\t" + " tpf.l #0x0\n\t" + " tpf.l #0x0\n\t" + " tpf.l #0x0\n\t" + " tpf.l #0x0\n\t" + " tpf.l #0x0\n\t" + ::: "memory"); } __attribute__((interrupt)) void pci_arb_interrupt(void) { - dbg("XLBARB slave error interrupt\r\n"); - MCF_XLB_XARB_SR |= ~MCF_XLB_XARB_SR_SEA; + dbg("XLBARB slave error interrupt\r\n"); + MCF_XLB_XARB_SR |= ~MCF_XLB_XARB_SR_SEA; } __attribute__((interrupt)) void xlb_pci_interrupt(void) { - dbg("XLBPCI interrupt\r\n"); + dbg("XLBPCI interrupt\r\n"); } __attribute__((interrupt)) void pci_interrupt(void) { - dbg("PCI interrupt\r\n"); + dbg("PCI interrupt\r\n"); } /* @@ -164,13 +164,13 @@ __attribute__((interrupt)) void pci_interrupt(void) static int32_t pci_get_interrupt_cause(int32_t *handles) { - int32_t handle; + int32_t handle; /* * loop through all PCI devices... */ - while ((handle = *handles++) != -1) - { + while ((handle = *handles++) != -1) + { uint16_t command_register = swpw(pci_read_config_word(handle, PCICR)); uint16_t status_register = swpw(pci_read_config_word(handle, PCISR)); @@ -178,14 +178,14 @@ static int32_t pci_get_interrupt_cause(int32_t *handles) * ...to see which device caused the interrupt */ if ((status_register & PCICSR_INTERRUPT) && !(command_register & PCICSR_INT_DISABLE)) - { - /* device has interrupts enabled and has an active interrupt, so its probably ours */ + { + /* device has interrupts enabled and has an active interrupt, so its probably ours */ - return handle; - } - } - dbg("%s: no interrupt cause found\r\n"); - return -1; + return handle; + } + } + dbg("%s: no interrupt cause found\r\n"); + return -1; } static int32_t pci_call_interrupt_chain(int32_t handle, int32_t data) @@ -201,7 +201,7 @@ static int32_t pci_call_interrupt_chain(int32_t handle, int32_t data) return 1; } } - return data; /* unmodified - means: not handled */ + return data; /* unmodified - means: not handled */ } #pragma GCC diagnostic pop @@ -211,22 +211,22 @@ static int32_t pci_call_interrupt_chain(int32_t handle, int32_t data) */ void irq5_handler(void) { - int32_t handle; - int32_t value = 0; - int32_t newvalue; + int32_t handle; + int32_t value = 0; + int32_t newvalue; - MCF_EPORT_EPFR |= (1 << 5); /* clear interrupt from edge port */ + MCF_EPORT_EPFR |= (1 << 5); /* clear interrupt from edge port */ xprintf("IRQ5!\r\n"); - if ((handle = pci_get_interrupt_cause(handles)) > 0) - { - newvalue = pci_call_interrupt_chain(handle, value); - if (newvalue == value) - { - dbg("%s: interrupt not handled!\r\n"); - } - } + if ((handle = pci_get_interrupt_cause(handles)) > 0) + { + newvalue = pci_call_interrupt_chain(handle, value); + if (newvalue == value) + { + dbg("%s: interrupt not handled!\r\n"); + } + } } #ifdef MACHINE_M5484LITE @@ -236,20 +236,20 @@ void irq5_handler(void) */ void irq7_handler(void) { - int32_t handle; - int32_t value = 0; - int32_t newvalue; + int32_t handle; + int32_t value = 0; + int32_t newvalue; - MCF_EPORT_EPFR |= (1 << 7); - dbg("IRQ7!\r\n"); - if ((handle = pci_get_interrupt_cause(handles)) > 0) - { - newvalue = pci_call_interrupt_chain(handle, value); - if (newvalue == value) - { - dbg("%s: interrupt not handled!\r\n"); - } - } + MCF_EPORT_EPFR |= (1 << 7); + dbg("IRQ7!\r\n"); + if ((handle = pci_get_interrupt_cause(handles)) > 0) + { + newvalue = pci_call_interrupt_chain(handle, value); + if (newvalue == value) + { + dbg("%s: interrupt not handled!\r\n"); + } + } } #endif /* MACHINE_M548X */ @@ -258,16 +258,16 @@ void irq7_handler(void) */ static int handle2index(int32_t handle) { - int i; + int i; - for (i = 0; i < NUM_CARDS; i++) - { - if (handles[i] == handle) - { - return i; - } - } - return -1; + for (i = 0; i < NUM_CARDS; i++) + { + if (handles[i] == handle) + { + return i; + } + } + return -1; } /* @@ -275,16 +275,16 @@ static int handle2index(int32_t handle) */ static char *device_class(int classcode) { - int i; + int i; - for (i = 0; i < num_pci_classes; i++) - { - if (pci_classes[i].classcode == classcode) - { - return pci_classes[i].description; - } - } - return "not found"; + for (i = 0; i < num_pci_classes; i++) + { + if (pci_classes[i].classcode == classcode) + { + return pci_classes[i].description; + } + } + return "not found"; } /* @@ -294,73 +294,73 @@ static char *device_class(int classcode) */ uint32_t pci_read_config_longword(int32_t handle, int offset) { - uint32_t value; + uint32_t value; - /* initiate PCI configuration access to device */ - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ - MCF_PCI_PCICAR_DWORD(offset / 4); + /* initiate PCI configuration access to device */ + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ + MCF_PCI_PCICAR_DWORD(offset / 4); - __asm__ __volatile__("nop" ::: "memory"); /* this is what the Linux BSP does */ + __asm__ __volatile__("nop" ::: "memory"); /* this is what the Linux BSP does */ - pci_config_wait(); - value = * (volatile uint32_t *) PCI_IO_OFFSET; /* access device */ + pci_config_wait(); + value = * (volatile uint32_t *) PCI_IO_OFFSET; /* access device */ - __asm__ __volatile__("tpf" ::: "memory"); /* this is what the Linux BSP does */ + __asm__ __volatile__("tpf" ::: "memory"); /* this is what the Linux BSP does */ - /* finish PCI configuration access special cycle (allow regular PCI accesses) */ - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + /* finish PCI configuration access special cycle (allow regular PCI accesses) */ + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; - return value; + return value; } uint16_t pci_read_config_word(int32_t handle, int offset) { - uint16_t value; + uint16_t value; - /* - * initiate PCI configuration space access to device - */ - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration space special cycle */ - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DWORD(offset / 4); + /* + * initiate PCI configuration space access to device + */ + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration space special cycle */ + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DWORD(offset / 4); - __asm__ __volatile("nop" ::: "memory"); /* this is what Linux BSP does */ + __asm__ __volatile("nop" ::: "memory"); /* this is what Linux BSP does */ - value = * (volatile uint16_t *) PCI_IO_OFFSET + (offset & 2); + value = * (volatile uint16_t *) PCI_IO_OFFSET + (offset & 2); - __asm__ __volatile("tpf" ::: "memory"); + __asm__ __volatile("tpf" ::: "memory"); - /* finish PCI configuration access special cycle */ - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + /* finish PCI configuration access special cycle */ + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; - return value; + return value; } uint8_t pci_read_config_byte(int32_t handle, int offset) { - uint8_t value; + uint8_t value; - /* initiate PCI configuration access to device */ - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ - MCF_PCI_PCICAR_DWORD(offset / 4); + /* initiate PCI configuration access to device */ + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ + MCF_PCI_PCICAR_DWORD(offset / 4); - __asm__ __volatile__("nop" ::: "memory"); + __asm__ __volatile__("nop" ::: "memory"); - value = * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)); + value = * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; - return value; + return value; } /* @@ -370,27 +370,26 @@ uint8_t pci_read_config_byte(int32_t handle, int offset) */ int32_t pci_write_config_longword(int32_t handle, int offset, uint32_t value) { - /* initiate PCI configuration access to device */ - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ - MCF_PCI_PCICAR_DWORD(offset / 4); + /* initiate PCI configuration access to device */ + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | /* device number, devices 0 - 9 are reserved */ + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | /* function number */ + MCF_PCI_PCICAR_DWORD(offset / 4); chip_errata_135(); - __asm__ __volatile__("nop" ::: "memory"); + __asm__ __volatile__("nop" ::: "memory"); - * (volatile uint32_t *) PCI_IO_OFFSET = value; /* access device */ + * (volatile uint32_t *) PCI_IO_OFFSET = value; /* access device */ chip_errata_135(); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - /* finish configuration space access cycle */ - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + /* finish configuration space access cycle */ + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; chip_errata_135(); - - return PCI_SUCCESSFUL; + return PCI_SUCCESSFUL; } /* @@ -398,26 +397,26 @@ int32_t pci_write_config_longword(int32_t handle, int offset, uint32_t value) */ int32_t pci_write_config_word(int32_t handle, int offset, uint16_t value) { - /* initiate PCI configuration access to device */ - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DWORD(offset / 4); + /* initiate PCI configuration access to device */ + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | /* enable configuration access special cycle */ + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DWORD(offset / 4); chip_errata_135(); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - * (volatile uint16_t *) (PCI_IO_OFFSET + (offset & 2)) = value; + * (volatile uint16_t *) (PCI_IO_OFFSET + (offset & 2)) = value; chip_errata_135(); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - /* finish configuration space access cycle */ - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + /* finish configuration space access cycle */ + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; chip_errata_135(); - return PCI_SUCCESSFUL; + return PCI_SUCCESSFUL; } /* @@ -425,26 +424,26 @@ int32_t pci_write_config_word(int32_t handle, int offset, uint16_t value) */ int32_t pci_write_config_byte(int32_t handle, int offset, uint8_t value) { - MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | - MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | - MCF_PCI_PCICAR_DWORD(offset / 4); + MCF_PCI_PCICAR = MCF_PCI_PCICAR_E | + MCF_PCI_PCICAR_BUSNUM(PCI_BUS_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DEVNUM(PCI_DEVICE_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_FUNCNUM(PCI_FUNCTION_FROM_HANDLE(handle)) | + MCF_PCI_PCICAR_DWORD(offset / 4); chip_errata_135(); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)) = value; + * (volatile uint8_t *) (PCI_IO_OFFSET + (offset & 3)) = value; chip_errata_135(); - __asm__ __volatile__("tpf" ::: "memory"); + __asm__ __volatile__("tpf" ::: "memory"); - /* finish configuration space access cycle */ - MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; + /* finish configuration space access cycle */ + MCF_PCI_PCICAR &= ~MCF_PCI_PCICAR_E; - chip_errata_135(); + chip_errata_135(); - return PCI_SUCCESSFUL; + return PCI_SUCCESSFUL; } /* * pci_get_resource @@ -453,18 +452,18 @@ int32_t pci_write_config_byte(int32_t handle, int offset, uint8_t value) */ struct pci_rd *pci_get_resource(int32_t handle) { - int index = -1; - struct pci_rd *ret; + int index = -1; + struct pci_rd *ret; - index = handle2index(handle); - if (index == -1) - ret = NULL; - else - ret = &resource_descriptors[index][0]; + index = handle2index(handle); + if (index == -1) + ret = NULL; + else + ret = &resource_descriptors[index][0]; - dbg("pci_get_resource: resource struct for handle %lx (index %d) is at %p\r\n", handle, index, ret); + dbg("pci_get_resource: resource struct for handle %lx (index %d) is at %p\r\n", handle, index, ret); - return ret; + return ret; } /* @@ -475,64 +474,64 @@ struct pci_rd *pci_get_resource(int32_t handle) */ int32_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index) { - uint16_t bus; - uint16_t device; - uint16_t function = 0; - uint16_t n = 0; - int32_t handle; + uint16_t bus; + uint16_t device; + uint16_t function = 0; + uint16_t n = 0; + int32_t handle; - for (bus = 0; bus < 1; bus++) - { - for (device = 10; device < 31; device++) - { - uint32_t value; - uint8_t htr; + for (bus = 0; bus < 1; bus++) + { + for (device = 10; device < 31; device++) + { + uint32_t value; + uint8_t htr; - handle = PCI_HANDLE(bus, device, 0); - value = pci_read_config_longword(handle, PCIIDR); - if (value != 0xffffffff) /* we have a device at this position */ - { - if (vendor_id == 0xffff || - (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) - { - if (n == index) - { - return handle; - } - n++; - } + handle = PCI_HANDLE(bus, device, 0); + value = pci_read_config_longword(handle, PCIIDR); + if (value != 0xffffffff) /* we have a device at this position */ + { + if (vendor_id == 0xffff || + (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) + { + if (n == index) + { + return handle; + } + n++; + } - /* - * There is a device at this position, but not the one we are looking for. - * Check to see if it is a multi-function device. We need to look "behind" it - * for the other functions in that case. - */ - if ((htr = pci_read_config_byte(handle, PCIHTR)) & 0x80) - { - /* yes, this is a multi-function device, look for more functions */ + /* + * There is a device at this position, but not the one we are looking for. + * Check to see if it is a multi-function device. We need to look "behind" it + * for the other functions in that case. + */ + if ((htr = pci_read_config_byte(handle, PCIHTR)) & 0x80) + { + /* yes, this is a multi-function device, look for more functions */ - for (function = 1; function < 8; function++) - { - handle = PCI_HANDLE(bus, device, function); - value = pci_read_config_longword(handle, PCIIDR); - if (value != 0xFFFFFFFF) /* device found */ - { - if (vendor_id == 0xffff || - (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) - { - if (n == index) - { - return handle; - } - n++; - } - } - } - } - } - } - } - return PCI_DEVICE_NOT_FOUND; + for (function = 1; function < 8; function++) + { + handle = PCI_HANDLE(bus, device, function); + value = pci_read_config_longword(handle, PCIIDR); + if (value != 0xffffffff) /* device found */ + { + if (vendor_id == 0xffff || + (PCI_VENDOR_ID(value) == vendor_id && PCI_DEVICE_ID(value) == device_id)) + { + if (n == index) + { + return handle; + } + n++; + } + } + } + } + } + } + } + return PCI_DEVICE_NOT_FOUND; } /* @@ -544,73 +543,73 @@ int32_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index) */ int32_t pci_find_classcode(uint32_t classcode, int index) { - uint16_t bus; - uint16_t device; - uint16_t function = 0; - uint16_t n = 0; - int32_t handle; + uint16_t bus; + uint16_t device; + uint16_t function = 0; + uint16_t n = 0; + int32_t handle; - for (bus = 0; bus < 2; bus++) - { - for (device = 10; device < 31; device++) - { - uint32_t value; - uint8_t htr; + for (bus = 0; bus < 2; bus++) + { + for (device = 10; device < 31; device++) + { + uint32_t value; + uint8_t htr; - handle = PCI_HANDLE(bus, device, 0); + handle = PCI_HANDLE(bus, device, 0); - value = pci_read_config_longword(handle, PCIIDR); + value = pci_read_config_longword(handle, PCIIDR); - if (value != 0xffffffff) /* device found */ - { - value = pci_read_config_longword(handle, PCICCR); + if (value != 0xffffffff) /* device found */ + { + value = pci_read_config_longword(handle, PCICCR); - if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) && - (classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) && - (classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true)) - { - if (n == index) - { - return handle; - } - n++; - } + if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) && + (classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) && + (classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true)) + { + if (n == index) + { + return handle; + } + n++; + } - /* - * there is a device at this position, but not the one we are looking for. - * Check to see if it is a multi-function device. We need to look "behind" it - * for the other functions in that case. - */ - if ((htr = pci_read_config_byte(handle, PCIHTR)) & 0x80) - { - /* yes, this is a multi-function device, look for more functions */ + /* + * there is a device at this position, but not the one we are looking for. + * Check to see if it is a multi-function device. We need to look "behind" it + * for the other functions in that case. + */ + if ((htr = pci_read_config_byte(handle, PCIHTR)) & 0x80) + { + /* yes, this is a multi-function device, look for more functions */ - for (function = 1; function < 8; function++) - { - handle = PCI_HANDLE(bus, device, function); - value = pci_read_config_longword(handle, PCIIDR); + for (function = 1; function < 8; function++) + { + handle = PCI_HANDLE(bus, device, function); + value = pci_read_config_longword(handle, PCIIDR); - if (value != 0xffffffff) /* device found */ - { - value = pci_read_config_longword(handle, PCICCR); + if (value != 0xffffffff) /* device found */ + { + value = pci_read_config_longword(handle, PCICCR); - if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) && - (classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) && - (classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true)) - { - if (n == index) - { - return handle; - } - n++; - } - } - } - } - } - } - } - return PCI_DEVICE_NOT_FOUND; + if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) && + (classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) && + (classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true)) + { + if (n == index) + { + return handle; + } + n++; + } + } + } + } + } + } + } + return PCI_DEVICE_NOT_FOUND; } int32_t pci_hook_interrupt(int32_t handle, pci_interrupt_handler handler, void *parameter) @@ -656,161 +655,161 @@ int32_t pci_unhook_interrupt(int32_t handle) uint8_t pci_fast_read_config_byte(int32_t handle, uint16_t reg) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint16_t pci_fast_read_config_word(int32_t handle, uint16_t reg) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint32_t pci_fast_read_config_longword(int32_t handle, uint16_t reg) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_special_cycle(uint16_t bus, uint32_t data) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_get_routing(int32_t handle) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_set_interrupt(int32_t handle) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_get_card_used(int32_t handle, uint32_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_set_card_used(int32_t handle, uint32_t *callback) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_mem_byte(int32_t handle, uint32_t offset, uint8_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_mem_word(int32_t handle, uint32_t offset, uint16_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_mem_longword(int32_t handle, uint32_t offset, uint32_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint8_t pci_fast_read_mem_byte(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint16_t pci_fast_read_mem_word(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint32_t pci_fast_read_mem_longword(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_mem_byte(int32_t handle, uint32_t offset, uint16_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_mem_word(int32_t handle, uint32_t offset, uint16_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_mem_longword(int32_t handle, uint32_t offset, uint32_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_io_byte(int32_t handle, uint32_t offset, uint8_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_io_word(int32_t handle, uint32_t offset, uint16_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_read_io_longword(int32_t handle, uint32_t offset, uint32_t *address) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint8_t pci_fast_read_io_byte(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint16_t pci_fast_read_io_word(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } uint32_t pci_fast_read_io_longword(int32_t handle, uint32_t offset) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_io_byte(int32_t handle, uint32_t offset, uint16_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_io_word(int32_t handle, uint32_t offset, uint16_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_write_io_longword(int32_t handle, uint32_t offset, uint32_t val) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_get_machine_id(void) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_get_pagesize(void) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_virt_to_bus(int32_t handle, uint32_t address, PCI_CONV_ADR *pointer) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_bus_to_virt(int32_t handle, uint32_t address, PCI_CONV_ADR *pointer) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_virt_to_phys(uint32_t address, PCI_CONV_ADR *pointer) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } int32_t pci_phys_to_virt(uint32_t address, PCI_CONV_ADR *pointer) { - return PCI_FUNC_NOT_SUPPORTED; + return PCI_FUNC_NOT_SUPPORTED; } /* @@ -820,203 +819,203 @@ int32_t pci_phys_to_virt(uint32_t address, PCI_CONV_ADR *pointer) */ static void pci_device_config(uint16_t bus, uint16_t device, uint16_t function) { - uint32_t address; - int32_t handle; - int16_t index = - 1; - uint8_t il; - struct pci_rd *descriptors; - int i; - uint32_t value; - static uint32_t mem_address = PCI_MEMORY_OFFSET; - static uint32_t io_address = PCI_IO_OFFSET; - uint16_t cr; + uint32_t address; + int32_t handle; + int16_t index = - 1; + uint8_t il; + struct pci_rd *descriptors; + int i; + uint32_t value; + static uint32_t mem_address = PCI_MEMORY_OFFSET; + static uint32_t io_address = PCI_IO_OFFSET; + uint16_t cr; - /* - * should make compiler happy (these are used only in debug builds) - */ - (void) value; - (void) il; + /* + * should make compiler happy (these are used only in debug builds) + */ + (void) value; + (void) il; - /* determine pci handle from bus, device + function number */ - handle = PCI_HANDLE(bus, device, function); + /* determine pci handle from bus, device + function number */ + handle = PCI_HANDLE(bus, device, function); - /* find index into resource descriptor table for handle */ - index = handle2index(handle); + /* find index into resource descriptor table for handle */ + index = handle2index(handle); - if (index == -1) - { - dbg("cannot find index for handle %d\r\n", handle); - return; - } + if (index == -1) + { + dbg("cannot find index for handle %d\r\n", handle); + return; + } - /* - * disable device - */ + /* + * disable device + */ - cr = swpw(pci_read_config_word(handle, PCICSR)); - cr &= ~3; /* disable device response to address */ - pci_write_config_word(handle, PCICSR, swpw(cr)); + cr = swpw(pci_read_config_word(handle, PCICSR)); + cr &= ~3; /* disable device response to address */ + pci_write_config_word(handle, PCICSR, swpw(cr)); - int barnum = 0; + int barnum = 0; - descriptors = resource_descriptors[index]; - for (i = 0; i < 6 * 4; i += 4) /* for all bars */ - { - /* - * write all bits of BAR[i] - */ - pci_write_config_longword(handle, PCIBAR0 + i, 0xffffffff); + descriptors = resource_descriptors[index]; + for (i = 0; i < 6 * 4; i += 4) /* for all bars */ + { + /* + * write all bits of BAR[i] + */ + pci_write_config_longword(handle, PCIBAR0 + i, 0xffffffff); - /* - * read back value to see which bits have been set - */ - address = swpl(pci_read_config_longword(handle, PCIBAR0 + i)); + /* + * read back value to see which bits have been set + */ + address = swpl(pci_read_config_longword(handle, PCIBAR0 + i)); - if (address) /* is bar in use? */ - { - /* - * resource descriptor for this device - */ - struct pci_rd *rd = &descriptors[barnum]; + if (address) /* is bar in use? */ + { + /* + * resource descriptor for this device + */ + struct pci_rd *rd = &descriptors[barnum]; - dbg("%s: address = %08x\r\n", address); - if (IS_PCI_MEM_BAR(address)) - { - /* adjust base address to card's alignment requirements */ - int size = ~(address & 0xfffffff0) + 1; - dbg("device 0x%x: BAR[%d] requests %d bytes of memory\r\n", handle, i / 4, size); + dbg("%s: address = %08x\r\n", address); + if (IS_PCI_MEM_BAR(address)) + { + /* adjust base address to card's alignment requirements */ + int size = ~(address & 0xfffffff0) + 1; + dbg("device 0x%x: BAR[%d] requests %d bytes of memory\r\n", handle, i / 4, size); - /* calculate a valid map adress with alignment requirements */ - address = (mem_address + size - 1) & ~(size - 1); + /* calculate a valid map adress with alignment requirements */ + address = (mem_address + size - 1) & ~(size - 1); - /* write it to the BAR */ - pci_write_config_longword(handle, PCIBAR0 + i, swpl(address)); + /* write it to the BAR */ + pci_write_config_longword(handle, PCIBAR0 + i, swpl(address)); - /* read it back, just to be sure */ - value = swpl(pci_read_config_longword(handle, PCIBAR0 + i)) & ~1; + /* read it back, just to be sure */ + value = swpl(pci_read_config_longword(handle, PCIBAR0 + i)) & ~1; - dbg("set PCIBAR%d on device 0x%02x to 0x%08x\r\n", - i / 4, handle, value); + dbg("set PCIBAR%d on device 0x%02x to 0x%08x\r\n", + i / 4, handle, value); - /* fill resource descriptor */ - rd->next = sizeof(struct pci_rd); - rd->flags = 0 | FLG_32BIT | FLG_16BIT | FLG_8BIT | 2; /* little endian, lane swapped */ - rd->start = address; - rd->length = size; - rd->offset = 0; - rd->dmaoffset = 0; + /* fill resource descriptor */ + rd->next = sizeof(struct pci_rd); + rd->flags = 0 | FLG_32BIT | FLG_16BIT | FLG_8BIT | 2; /* little endian, lane swapped */ + rd->start = address; + rd->length = size; + rd->offset = 0; + rd->dmaoffset = 0; - /* adjust memory adress for next turn */ - mem_address += size; + /* adjust memory adress for next turn */ + mem_address += size; - cr |= 2; + cr |= 2; - /* index to next unused resource descriptor */ - barnum++; - } - else if (IS_PCI_IO_BAR(address)) /* same as above for I/O resources */ - { - int size = ~(address & 0xfffffffc) + 1; - dbg("device 0x%x: BAR[%d] requests %d bytes of I/O space\r\n", handle, i, size); + /* index to next unused resource descriptor */ + barnum++; + } + else if (IS_PCI_IO_BAR(address)) /* same as above for I/O resources */ + { + int size = ~(address & 0xfffffffc) + 1; + dbg("device 0x%x: BAR[%d] requests %d bytes of I/O space\r\n", handle, i, size); - address = (io_address + size - 1) & ~(size - 1); - pci_write_config_longword(handle, PCIBAR0 + i, swpl(address | 1)); - value = swpl(pci_read_config_longword(handle, PCIBAR0 + i)); + address = (io_address + size - 1) & ~(size - 1); + pci_write_config_longword(handle, PCIBAR0 + i, swpl(address | 1)); + value = swpl(pci_read_config_longword(handle, PCIBAR0 + i)); - dbg("set PCIBAR%d on device 0x%02x to 0x%08x\r\n", - i / 4, handle, value); + dbg("set PCIBAR%d on device 0x%02x to 0x%08x\r\n", + i / 4, handle, value); - rd->next = sizeof(struct pci_rd); - rd->flags = FLG_IO | FLG_8BIT | FLG_16BIT | FLG_32BIT | 2; - rd->start = address; - rd->offset = 0; - rd->length = size; - rd->dmaoffset = 0; + rd->next = sizeof(struct pci_rd); + rd->flags = FLG_IO | FLG_8BIT | FLG_16BIT | FLG_32BIT | 2; + rd->start = address; + rd->offset = 0; + rd->length = size; + rd->dmaoffset = 0; - io_address += size; + io_address += size; - cr |= 1; + cr |= 1; - barnum++; - } - } - } + barnum++; + } + } + } - /* - * check if we have an expansion ROM - */ - value = swpl(pci_read_config_longword(handle, PCIERBAR)); + /* + * check if we have an expansion ROM + */ + value = swpl(pci_read_config_longword(handle, PCIERBAR)); - /* - * write all bits of PCIERBAR - */ - pci_write_config_longword(handle, PCIERBAR, 0xffffffff); + /* + * write all bits of PCIERBAR + */ + pci_write_config_longword(handle, PCIERBAR, 0xffffffff); - /* - * read back value to see which bits have been set - */ - address = swpl(pci_read_config_longword(handle, PCIERBAR)); - if (address & 1) - { - struct pci_rd *rd = &descriptors[barnum]; - int size = ~(address & ~0x7ff); + /* + * read back value to see which bits have been set + */ + address = swpl(pci_read_config_longword(handle, PCIERBAR)); + if (address & 1) + { + struct pci_rd *rd = &descriptors[barnum]; + int size = ~(address & ~0x7ff); - /* expansion ROM active and mapped */ + /* expansion ROM active and mapped */ - /* calculate a valid map adress with alignment requirements */ - address = (mem_address + size - 1) & ~(size - 1); + /* calculate a valid map adress with alignment requirements */ + address = (mem_address + size - 1) & ~(size - 1); - /* write it to PCIERBAR and enable ROM */ - pci_write_config_longword(handle, PCIERBAR, swpl(address | 1)); - dbg("%s: set PCIERBAR on device 0x%02x to 0x%08x\r\n", handle, address | 1); + /* write it to PCIERBAR and enable ROM */ + pci_write_config_longword(handle, PCIERBAR, swpl(address | 1)); + dbg("%s: set PCIERBAR on device 0x%02x to 0x%08x\r\n", handle, address | 1); - /* read value back just to be sure */ - dbg("%s: PCIERBAR = %p\r\n", swpl(pci_read_config_longword(handle, PCIERBAR))); + /* read value back just to be sure */ + dbg("%s: PCIERBAR = %p\r\n", swpl(pci_read_config_longword(handle, PCIERBAR))); - rd->next = sizeof(struct pci_rd); - rd->flags = FLG_ROM | FLG_8BIT | FLG_16BIT | FLG_32BIT | 2; - rd->start = address; - rd->offset = 0; - rd->length = size; - rd->dmaoffset = 0; + rd->next = sizeof(struct pci_rd); + rd->flags = FLG_ROM | FLG_8BIT | FLG_16BIT | FLG_32BIT | 2; + rd->start = address; + rd->offset = 0; + rd->length = size; + rd->dmaoffset = 0; - mem_address += size; - barnum++; - } + mem_address += size; + barnum++; + } - /* mark end of resource chain */ - if (barnum > 0) - descriptors[barnum - 1].flags |= FLG_LAST; + /* mark end of resource chain */ + if (barnum > 0) + descriptors[barnum - 1].flags |= FLG_LAST; - /* check if device requests an interrupt */ - il = pci_read_config_byte(handle, PCIIPR); - dbg("device requests interrupts on interrupt pin %d\r\n", il); + /* check if device requests an interrupt */ + il = pci_read_config_byte(handle, PCIIPR); + dbg("device requests interrupts on interrupt pin %d\r\n", il); - /* if so, register interrupts */ + /* if so, register interrupts */ - /* TODO: register interrupts here */ + /* TODO: register interrupts here */ - /* - * enable device memory or I/O access - */ - pci_write_config_word(handle, PCICSR, swpw(cr)); + /* + * enable device memory or I/O access + */ + pci_write_config_word(handle, PCICSR, swpw(cr)); } static void pci_bridge_config(uint16_t bus, uint16_t device, uint16_t function) { - int32_t handle; + int32_t handle; - if (function != 0) - { - dbg("trying to configure a multi-function bridge. Cancelled\r\n"); - return; - } - handle = PCI_HANDLE(bus, device, function); + if (function != 0) + { + dbg("trying to configure a multi-function bridge. Cancelled\r\n"); + return; + } + handle = PCI_HANDLE(bus, device, function); - pci_write_config_longword(handle, PCIBAR0, 0x40000000); - pci_write_config_longword(handle, PCIBAR1, 0x0); - pci_write_config_longword(handle, PCICSR, 0x146); + pci_write_config_longword(handle, PCIBAR0, 0x40000000); + pci_write_config_longword(handle, PCIBAR1, 0x0); + pci_write_config_longword(handle, PCICSR, 0x146); } /* @@ -1024,264 +1023,264 @@ static void pci_bridge_config(uint16_t bus, uint16_t device, uint16_t function) */ void pci_scan(void) { - int16_t handle; - int16_t index = 0; + int16_t handle; + int16_t index = 0; - xprintf("\r\nPCI bus scan...\r\n\r\n"); - xprintf(" Bus| Dev|Func|Vndr|D-ID|Hndl|\r\n"); - xprintf("----+----+----+----+----+----+\r\n"); + xprintf("\r\nPCI bus scan...\r\n\r\n"); + xprintf(" Bus| Dev|Func|Vndr|D-ID|Hndl|\r\n"); + xprintf("----+----+----+----+----+----+\r\n"); - handle = pci_find_device(0x0, 0xFFFF, index); - while (handle > 0) - { - uint32_t value; + handle = pci_find_device(0x0, 0xFFFF, index); + while (handle > 0) + { + uint32_t value; - value = pci_read_config_longword(handle, PCIIDR); - xprintf(" %02x | %02x | %02x |%04x|%04x|%04x| %s (0x%02x)\r\n", - PCI_BUS_FROM_HANDLE(handle), - PCI_DEVICE_FROM_HANDLE(handle), - PCI_FUNCTION_FROM_HANDLE(handle), - PCI_VENDOR_ID(value), PCI_DEVICE_ID(value), - handle, - device_class(pci_read_config_byte(handle, PCICCR)), - pci_read_config_byte(handle, PCICCR)); + value = pci_read_config_longword(handle, PCIIDR); + xprintf(" %02x | %02x | %02x |%04x|%04x|%04x| %s (0x%02x)\r\n", + PCI_BUS_FROM_HANDLE(handle), + PCI_DEVICE_FROM_HANDLE(handle), + PCI_FUNCTION_FROM_HANDLE(handle), + PCI_VENDOR_ID(value), PCI_DEVICE_ID(value), + handle, + device_class(pci_read_config_byte(handle, PCICCR)), + pci_read_config_byte(handle, PCICCR)); - /* save handle to index value so that we'll be able to later find our resources */ - handles[index] = handle; - if (PCI_VENDOR_ID(value) != 0x1057 && PCI_DEVICE_ID(value) != 0x5806) /* do not configure bridge */ - { - /* configure memory and I/O for card */ - pci_device_config(PCI_BUS_FROM_HANDLE(handle), - PCI_DEVICE_FROM_HANDLE(handle), - PCI_FUNCTION_FROM_HANDLE(handle)); - } - else - { - pci_bridge_config(PCI_BUS_FROM_HANDLE(handle), - PCI_DEVICE_FROM_HANDLE(handle), - PCI_FUNCTION_FROM_HANDLE(handle)); - } + /* save handle to index value so that we'll be able to later find our resources */ + handles[index] = handle; + if (PCI_VENDOR_ID(value) != 0x1057 && PCI_DEVICE_ID(value) != 0x5806) /* do not configure bridge */ + { + /* configure memory and I/O for card */ + pci_device_config(PCI_BUS_FROM_HANDLE(handle), + PCI_DEVICE_FROM_HANDLE(handle), + PCI_FUNCTION_FROM_HANDLE(handle)); + } + else + { + pci_bridge_config(PCI_BUS_FROM_HANDLE(handle), + PCI_DEVICE_FROM_HANDLE(handle), + PCI_FUNCTION_FROM_HANDLE(handle)); + } - handle = pci_find_device(0x0, 0xFFFF, ++index); - } - xprintf("\r\n...finished\r\n"); + handle = pci_find_device(0x0, 0xFFFF, ++index); + } + xprintf("\r\n...finished\r\n"); } /* start of PCI initialization code */ void init_eport(void) { - /* configure IRQ1-7 pins on EPORT falling edge triggered */ - MCF_EPORT_EPPAR = MCF_EPORT_EPPAR_EPPA7(MCF_EPORT_EPPAR_FALLING) | - MCF_EPORT_EPPAR_EPPA6(MCF_EPORT_EPPAR_FALLING) | + /* configure IRQ1-7 pins on EPORT falling edge triggered */ + MCF_EPORT_EPPAR = MCF_EPORT_EPPAR_EPPA7(MCF_EPORT_EPPAR_FALLING) | + MCF_EPORT_EPPAR_EPPA6(MCF_EPORT_EPPAR_FALLING) | #if MACHINE_FIREBEE /* irq5 level triggered on FireBee */ - MCF_EPORT_EPPAR_EPPA5(MCF_EPORT_EPPAR_LEVEL) | + MCF_EPORT_EPPAR_EPPA5(MCF_EPORT_EPPAR_LEVEL) | #elif MACHINE_M5484LITE - MCF_EPORT_EPPAR_EPPA5(MCF_EPORT_EPPAR_FALLING) | + MCF_EPORT_EPPAR_EPPA5(MCF_EPORT_EPPAR_FALLING) | #endif /* MACHINE_FIREBEE */ - MCF_EPORT_EPPAR_EPPA4(MCF_EPORT_EPPAR_FALLING) | - MCF_EPORT_EPPAR_EPPA3(MCF_EPORT_EPPAR_FALLING) | - MCF_EPORT_EPPAR_EPPA2(MCF_EPORT_EPPAR_FALLING) | - MCF_EPORT_EPPAR_EPPA1(MCF_EPORT_EPPAR_FALLING); - MCF_EPORT_EPDDR = 0; /* clear data direction register. All pins as input */ - MCF_EPORT_EPFR = -1; /* clear all EPORT interrupt flags */ - MCF_EPORT_EPIER = 0xfe; /* enable all EPORT interrupts (for now) */ + MCF_EPORT_EPPAR_EPPA4(MCF_EPORT_EPPAR_FALLING) | + MCF_EPORT_EPPAR_EPPA3(MCF_EPORT_EPPAR_FALLING) | + MCF_EPORT_EPPAR_EPPA2(MCF_EPORT_EPPAR_FALLING) | + MCF_EPORT_EPPAR_EPPA1(MCF_EPORT_EPPAR_FALLING); + MCF_EPORT_EPDDR = 0; /* clear data direction register. All pins as input */ + MCF_EPORT_EPFR = -1; /* clear all EPORT interrupt flags */ + MCF_EPORT_EPIER = 0xfe; /* enable all EPORT interrupts (for now) */ } void init_xlbus_arbiter(void) { - uint8_t clock_ratio; + uint8_t clock_ratio; - /* setup XL bus arbiter */ - clock_ratio = (MCF_PCI_PCIGSCR >> 24) & 0x07; - if (clock_ratio == 4) - { - MCF_XLB_XARB_CFG = MCF_XLB_XARB_CFG_BA | - MCF_XLB_XARB_CFG_DT | - MCF_XLB_XARB_CFG_AT | - MCF_XLB_XARB_CFG_PLDIS; - } - else - { - MCF_XLB_XARB_CFG = MCF_XLB_XARB_CFG_BA | - MCF_XLB_XARB_CFG_DT | - MCF_XLB_XARB_CFG_AT; - } + /* setup XL bus arbiter */ + clock_ratio = (MCF_PCI_PCIGSCR >> 24) & 0x07; + if (clock_ratio == 4) + { + MCF_XLB_XARB_CFG = MCF_XLB_XARB_CFG_BA | + MCF_XLB_XARB_CFG_DT | + MCF_XLB_XARB_CFG_AT | + MCF_XLB_XARB_CFG_PLDIS; + } + else + { + MCF_XLB_XARB_CFG = MCF_XLB_XARB_CFG_BA | + MCF_XLB_XARB_CFG_DT | + MCF_XLB_XARB_CFG_AT; + } - MCF_XLB_XARB_ADRTO = 0x1fffff; - MCF_XLB_XARB_DATTO = 0x1fffff; - MCF_XLB_XARB_BUSTO = 0xffffff; + MCF_XLB_XARB_ADRTO = 0x1fffff; + MCF_XLB_XARB_DATTO = 0x1fffff; + MCF_XLB_XARB_BUSTO = 0xffffff; - /* - * set arbitration priorities for XL bus masters - * - * M0 = ColdFire core - * M2 = Multichannel DMA - * M3 = PCI target interface - */ + /* + * set arbitration priorities for XL bus masters + * + * M0 = ColdFire core + * M2 = Multichannel DMA + * M3 = PCI target interface + */ - MCF_XLB_XARB_PRIEN = MCF_XLB_XARB_PRIEN_M0 | /* activate programmed priority for Coldfire core */ - MCF_XLB_XARB_PRIEN_M2 | /* activate programmed priority for Multichannel DMA */ - MCF_XLB_XARB_PRIEN_M3; /* activate programmed priority for PCI target interface */ - MCF_XLB_XARB_PRI = MCF_XLB_XARB_PRI_M0P(7) | /* Coldfire core gets lowest */ - MCF_XLB_XARB_PRI_M2P(5) | /* Multichannel DMA mid priority */ - MCF_XLB_XARB_PRI_M3P(3); /* PCI target interface is highest priority */ + MCF_XLB_XARB_PRIEN = MCF_XLB_XARB_PRIEN_M0 | /* activate programmed priority for Coldfire core */ + MCF_XLB_XARB_PRIEN_M2 | /* activate programmed priority for Multichannel DMA */ + MCF_XLB_XARB_PRIEN_M3; /* activate programmed priority for PCI target interface */ + MCF_XLB_XARB_PRI = MCF_XLB_XARB_PRI_M0P(7) | /* Coldfire core gets lowest */ + MCF_XLB_XARB_PRI_M2P(5) | /* Multichannel DMA mid priority */ + MCF_XLB_XARB_PRI_M3P(3); /* PCI target interface is highest priority */ } void init_pci(void) { - int res; + int res; - xprintf("initializing PCI bridge:\r\n"); + xprintf("initializing PCI bridge:\r\n"); (void) res; /* for now */ - res = register_interrupt_handler(0, INT_SOURCE_PCIARB, 5, 5, pci_arb_interrupt); - dbg("registered interrupt handler for PCI arbiter: %s\r\n", - (res < 0 ? "failed" : "succeeded")); - register_interrupt_handler(0, INT_SOURCE_XLBPCI, 5, 5, xlb_pci_interrupt); - dbg("registered interrupt handler for XLB PCI: %s\r\n", - (res < 0 ? "failed" : "succeeded")); + res = register_interrupt_handler(0, INT_SOURCE_PCIARB, 5, 5, pci_arb_interrupt); + dbg("registered interrupt handler for PCI arbiter: %s\r\n", + (res < 0 ? "failed" : "succeeded")); + register_interrupt_handler(0, INT_SOURCE_XLBPCI, 5, 5, xlb_pci_interrupt); + dbg("registered interrupt handler for XLB PCI: %s\r\n", + (res < 0 ? "failed" : "succeeded")); - init_eport(); - init_xlbus_arbiter(); + init_eport(); + init_xlbus_arbiter(); - MCF_PCI_PCIGSCR = 1; /* reset PCI */ + MCF_PCI_PCIGSCR = 1; /* reset PCI */ - /* - * setup the PCI arbiter - */ - MCF_PCIARB_PACR = MCF_PCIARB_PACR_INTMPRI /* internal master priority: high */ - | MCF_PCIARB_PACR_EXTMPRI(0xf) /* external master priority: high */ - | MCF_PCIARB_PACR_INTMINTEN /* enable "internal master broken" interrupt */ - | MCF_PCIARB_PACR_EXTMINTEN(0x0f); /* enable "external master broken" interrupt */ + /* + * setup the PCI arbiter + */ + MCF_PCIARB_PACR = MCF_PCIARB_PACR_INTMPRI /* internal master priority: high */ + | MCF_PCIARB_PACR_EXTMPRI(0xf) /* external master priority: high */ + | MCF_PCIARB_PACR_INTMINTEN /* enable "internal master broken" interrupt */ + | MCF_PCIARB_PACR_EXTMINTEN(0x0f); /* enable "external master broken" interrupt */ #ifdef _NOT_USED_ /* since this is already done in sysinit.c */ #if MACHINE_FIREBEE - //MCF_PAD_PAR_PCIBG = 0x3f; // FIXME: MiNT initialization hangs if this is enabled ??? - //MCF_PAD_PAR_PCIBR = 0x3f; + //MCF_PAD_PAR_PCIBG = 0x3f; // FIXME: MiNT initialization hangs if this is enabled ??? + //MCF_PAD_PAR_PCIBR = 0x3f; #elif MACHINE_M5484LITE - MCF_PAD_PAR_PCIBG = 0x3ff; /* enable all PCI bus grant and bus requests on the LITE board */ - MCF_PAD_PAR_PCIBR = 0x3ff; + MCF_PAD_PAR_PCIBG = 0x3ff; /* enable all PCI bus grant and bus requests on the LITE board */ + MCF_PAD_PAR_PCIBR = 0x3ff; #endif /* MACHINE_FIREBEE */ #endif /* _NOT_USED_ */ - MCF_PCI_PCISCR = MCF_PCI_PCISCR_M | /* memory access control enabled */ - MCF_PCI_PCISCR_B | /* bus master enabled */ - MCF_PCI_PCISCR_M | /* mem access enable */ - MCF_PCI_PCISCR_MA | /* clear master abort error */ - MCF_PCI_PCISCR_MW; /* memory write and invalidate enabled */ + MCF_PCI_PCISCR = MCF_PCI_PCISCR_M | /* memory access control enabled */ + MCF_PCI_PCISCR_B | /* bus master enabled */ + MCF_PCI_PCISCR_M | /* mem access enable */ + MCF_PCI_PCISCR_MA | /* clear master abort error */ + MCF_PCI_PCISCR_MW; /* memory write and invalidate enabled */ - /* Setup burst parameters */ - MCF_PCI_PCICR1 = MCF_PCI_PCICR1_CACHELINESIZE(8) | - MCF_PCI_PCICR1_LATTIMER(0xff); /* TODO: test increased latency timer */ + /* Setup burst parameters */ + MCF_PCI_PCICR1 = MCF_PCI_PCICR1_CACHELINESIZE(8) | + MCF_PCI_PCICR1_LATTIMER(0xff); /* TODO: test increased latency timer */ #ifdef _NOT_USED_ - MCF_PCI_PCICR2 = MCF_PCI_PCICR2_MINGNT(1) | - MCF_PCI_PCICR2_MAXLAT(32); + MCF_PCI_PCICR2 = MCF_PCI_PCICR2_MINGNT(1) | + MCF_PCI_PCICR2_MAXLAT(32); #endif /* _NOT_USED_ */ - MCF_PCI_PCICR2 = 0; /* this is what Linux does */ + MCF_PCI_PCICR2 = 0; /* this is what Linux does */ - /* error signaling */ + /* error signaling */ #ifdef NOT_USED - MCF_PCI_PCIICR = MCF_PCI_PCIICR_TAE | /* target abort enable */ - MCF_PCI_PCIICR_IAE; /* initiator abort enable */ + MCF_PCI_PCIICR = MCF_PCI_PCIICR_TAE | /* target abort enable */ + MCF_PCI_PCIICR_IAE; /* initiator abort enable */ #endif /* NOT_USED */ - MCF_PCI_PCIICR = 0; /* this is what Linux does */ + MCF_PCI_PCIICR = 0; /* this is what Linux does */ - MCF_PCI_PCIGSCR |= MCF_PCI_PCIGSCR_SEE; /* system error interrupt enable */ + MCF_PCI_PCIGSCR |= MCF_PCI_PCIGSCR_SEE; /* system error interrupt enable */ - /* Configure Initiator Windows */ + /* Configure Initiator Windows */ - /* initiator window 0 base / translation adress register */ - MCF_PCI_PCIIW0BTAR = (PCI_MEMORY_OFFSET | (((PCI_MEMORY_SIZE - 1) >> 8) & 0xffff0000)) - | ((PCI_MEMORY_OFFSET >> 16) & 0xff00); + /* initiator window 0 base / translation adress register */ + MCF_PCI_PCIIW0BTAR = (PCI_MEMORY_OFFSET | (((PCI_MEMORY_SIZE - 1) >> 8) & 0xffff0000)) + | ((PCI_MEMORY_OFFSET >> 16) & 0xff00); - dbg("PCIIW0BTAR=0x%08x\r\n", MCF_PCI_PCIIW0BTAR); + dbg("PCIIW0BTAR=0x%08x\r\n", MCF_PCI_PCIIW0BTAR); - /* initiator window 1 base / translation adress register */ - MCF_PCI_PCIIW1BTAR = (PCI_IO_OFFSET | ((PCI_IO_SIZE - 1) >> 8)) & 0xffff0000; + /* initiator window 1 base / translation adress register */ + MCF_PCI_PCIIW1BTAR = (PCI_IO_OFFSET | ((PCI_IO_SIZE - 1) >> 8)) & 0xffff0000; - /* initiator window 2 base / translation address register */ - MCF_PCI_PCIIW2BTAR = 0L; /* not used */ + /* initiator window 2 base / translation address register */ + MCF_PCI_PCIIW2BTAR = 0L; /* not used */ - /* initiator window configuration register */ - MCF_PCI_PCIIWCR = MCF_PCI_PCIIWCR_WINCTRL0_MEMRDLINE | - MCF_PCI_PCIIWCR_WINCTRL1_IO | - MCF_PCI_PCIIWCR_WINCTRL0_E | - MCF_PCI_PCIIWCR_WINCTRL1_E; + /* initiator window configuration register */ + MCF_PCI_PCIIWCR = MCF_PCI_PCIIWCR_WINCTRL0_MEMRDLINE | + MCF_PCI_PCIIWCR_WINCTRL1_IO | + MCF_PCI_PCIIWCR_WINCTRL0_E | + MCF_PCI_PCIIWCR_WINCTRL1_E; - /* - * Initialize target control register. - * Used when an external bus master accesses the Coldfire PCI as target - */ - MCF_PCI_PCIBAR0 = 0x40000000; /* 256 kB window */ - MCF_PCI_PCITBATR0 = (uint32_t) &_MBAR[0] | MCF_PCI_PCITBATR0_EN; /* target base address translation register 0 */ - MCF_PCI_PCIBAR1 = 0; /* 1GB window */ - MCF_PCI_PCITBATR1 = MCF_PCI_PCITBATR1_EN; + /* + * Initialize target control register. + * Used when an external bus master accesses the Coldfire PCI as target + */ + MCF_PCI_PCIBAR0 = 0x40000000; /* 256 kB window */ + MCF_PCI_PCITBATR0 = (uint32_t) &_MBAR[0] | MCF_PCI_PCITBATR0_EN; /* target base address translation register 0 */ + MCF_PCI_PCIBAR1 = 0; /* 1GB window */ + MCF_PCI_PCITBATR1 = MCF_PCI_PCITBATR1_EN; - /* reset PCI devices */ - MCF_PCI_PCIGSCR &= ~MCF_PCI_PCIGSCR_PR; - do {;} while (MCF_PCI_PCIGSCR & MCF_PCI_PCIGSCR_PR); /* wait until reset finished */ - xprintf("finished\r\n"); + /* reset PCI devices */ + MCF_PCI_PCIGSCR &= ~MCF_PCI_PCIGSCR_PR; + do {;} while (MCF_PCI_PCIGSCR & MCF_PCI_PCIGSCR_PR); /* wait until reset finished */ + xprintf("finished\r\n"); - /* initialize/clear resource descriptor table */ - memset(&resource_descriptors, 0, NUM_CARDS * NUM_RESOURCES * sizeof(struct pci_rd)); - /* initialize/clear handles array */ - memset(handles, 0, NUM_CARDS * sizeof(int32_t)); - /* initialize/clear interrupts array */ - memset(interrupts, 0, MAX_INTERRUPTS * sizeof(struct pci_interrupt)); + /* initialize/clear resource descriptor table */ + memset(&resource_descriptors, 0, NUM_CARDS * NUM_RESOURCES * sizeof(struct pci_rd)); + /* initialize/clear handles array */ + memset(handles, 0, NUM_CARDS * sizeof(int32_t)); + /* initialize/clear interrupts array */ + memset(interrupts, 0, MAX_INTERRUPTS * sizeof(struct pci_interrupt)); - /* - * give devices a chance to come up befor attempting to configure them, - * necessary to properly detect the FireBee USB chip - */ - wait(400000); + /* + * give devices a chance to come up befor attempting to configure them, + * necessary to properly detect the FireBee USB chip + */ + wait(400000); - /* - * do normal initialization - */ - pci_scan(); + /* + * do normal initialization + */ + pci_scan(); } #ifdef DEBUG_PCI void pci_print_device_abilities(int32_t handle) { - uint16_t value; - uint16_t saved_value; + uint16_t value; + uint16_t saved_value; - saved_value = pci_read_config_word(handle, PCICSR); - pci_write_config_word(handle, PCICSR, 0xffff); - value = swpw(pci_read_config_word(handle, PCICSR)); - dbg("IO: %1d MEM: %1d MSTR:%1d SPCC: %1d MEMW: %1d VGAS: %1d PERR: %1d STEP: %1d SERR: %1d FBTB: %1d\r\n", - value & PCICSR_IO ? 1 : 0, - value & PCICSR_MEMORY ? 1 : 0, - value & PCICSR_MASTER ? 1 : 0, - value & PCICSR_SPECIAL ? 1 : 0, - value & PCICSR_MEMWI ? 1 : 0, - value & PCICSR_VGA_SNOOP ? 1 : 0, - value & PCICSR_PERR ? 1 : 0, - value & PCICSR_STEPPING ? 1 : 0, - value & PCICSR_SERR ? 1 : 0, - value & PCICSR_FAST_BTOB_E ? 1 : 0); - pci_write_config_word(handle, PCICSR, saved_value); + saved_value = pci_read_config_word(handle, PCICSR); + pci_write_config_word(handle, PCICSR, 0xffff); + value = swpw(pci_read_config_word(handle, PCICSR)); + dbg("IO: %1d MEM: %1d MSTR:%1d SPCC: %1d MEMW: %1d VGAS: %1d PERR: %1d STEP: %1d SERR: %1d FBTB: %1d\r\n", + value & PCICSR_IO ? 1 : 0, + value & PCICSR_MEMORY ? 1 : 0, + value & PCICSR_MASTER ? 1 : 0, + value & PCICSR_SPECIAL ? 1 : 0, + value & PCICSR_MEMWI ? 1 : 0, + value & PCICSR_VGA_SNOOP ? 1 : 0, + value & PCICSR_PERR ? 1 : 0, + value & PCICSR_STEPPING ? 1 : 0, + value & PCICSR_SERR ? 1 : 0, + value & PCICSR_FAST_BTOB_E ? 1 : 0); + pci_write_config_word(handle, PCICSR, saved_value); } void pci_print_device_config(int32_t handle) { - uint16_t value; + uint16_t value; - value = swpw(pci_read_config_word(handle, PCICSR + 2)); - dbg("66M: %1d UDF: %1d FB2B:%1d PERR: %1d TABR: %1d DABR: %1d SERR: %1d PPER: %1d\r\n", - value & PCICSR_66MHZ ? 1 : 0, - value & PCICSR_UDF ? 1 : 0, - value & PCICSR_FAST_BTOB ? 1 : 0, - value & PCICSR_DPARITY_ERROR ? 1 : 0, - value & PCICSR_T_ABORT_S ? 1 : 0, - value & PCICSR_T_ABORT_R ? 1 : 0, - value & PCICSR_M_ABORT_R ? 1 : 0, - value & PCICSR_S_ERROR_S ? 1 : 0, - value & PCICSR_PARITY_ERR ? 1 : 0); + value = swpw(pci_read_config_word(handle, PCICSR + 2)); + dbg("66M: %1d UDF: %1d FB2B:%1d PERR: %1d TABR: %1d DABR: %1d SERR: %1d PPER: %1d\r\n", + value & PCICSR_66MHZ ? 1 : 0, + value & PCICSR_UDF ? 1 : 0, + value & PCICSR_FAST_BTOB ? 1 : 0, + value & PCICSR_DPARITY_ERROR ? 1 : 0, + value & PCICSR_T_ABORT_S ? 1 : 0, + value & PCICSR_T_ABORT_R ? 1 : 0, + value & PCICSR_M_ABORT_R ? 1 : 0, + value & PCICSR_S_ERROR_S ? 1 : 0, + value & PCICSR_PARITY_ERR ? 1 : 0); } #endif /* DEBUG_PCI */ diff --git a/BaS_gcc/sys/driver_mem.c b/BaS_gcc/sys/driver_mem.c index 3163958..dd5cd27 100644 --- a/BaS_gcc/sys/driver_mem.c +++ b/BaS_gcc/sys/driver_mem.c @@ -27,7 +27,7 @@ #error "unknown machine!" #endif -#define DBG_DM +//#define DBG_DM #ifdef DBG_DM #define dbg(fmt, args...) xprintf(fmt, ##args) #else @@ -44,10 +44,10 @@ extern uint8_t driver_mem_buffer[DRIVER_MEM_BUFFER_SIZE]; /* defined in linker c MD { - MD *m_link; - long m_start; - long m_length; - void *m_own; + MD *m_link; + long m_start; + long m_length; + void *m_own; }; /* MPB - Memory Partition Block */ @@ -56,9 +56,9 @@ MD MPB { - MD *mp_mfl; - MD *mp_mal; - MD *mp_rover; + MD *mp_mfl; + MD *mp_mal; + MD *mp_rover; }; #define MAXMD 256 @@ -68,273 +68,273 @@ static MPB pmd; static void *xmgetblk(void) { - int i; + int i; - for (i = 0; i < MAXMD; i++) - { - if (tab_md[i].m_own == NULL) - { - tab_md[i].m_own = (void*)1L; - return(&tab_md[i]); - } - } - return NULL; + for (i = 0; i < MAXMD; i++) + { + if (tab_md[i].m_own == NULL) + { + tab_md[i].m_own = (void*)1L; + return(&tab_md[i]); + } + } + return NULL; } static void xmfreblk(void *m) { - int i = (int)(((long) m - (long) tab_md) / sizeof(MD)); - if ((i > 0) && (i < MAXMD)) - { - tab_md[i].m_own = NULL; - } + int i = (int)(((long) m - (long) tab_md) / sizeof(MD)); + if ((i > 0) && (i < MAXMD)) + { + tab_md[i].m_own = NULL; + } } static MD *ffit(long amount, MPB *mp) { - MD *p, *q, *p1; /* free list is composed of MD's */ - int maxflg; - long maxval; + MD *p, *q, *p1; /* free list is composed of MD's */ + int maxflg; + long maxval; - if (amount != -1) - { - amount += 15; /* 16 bytes alignment */ - amount &= 0xFFFFFFF0; - } + if (amount != -1) + { + amount += 15; /* 16 bytes alignment */ + amount &= 0xFFFFFFF0; + } - if ((q = mp->mp_rover) == 0) /* get rotating pointer */ - { - return 0; - } + if ((q = mp->mp_rover) == 0) /* get rotating pointer */ + { + return 0; + } - maxval = 0; - maxflg = ((amount == -1) ? true : false) ; - p = q->m_link; /* start with next MD */ - do /* search the list for an MD with enough space */ - { - if (p == 0) - { - /* at end of list, wrap back to start */ - q = (MD *) &mp->mp_mfl; /* q => mfl field */ - p = q->m_link; /* p => 1st MD */ - } - if ((!maxflg) && (p->m_length >= amount)) - { - /* big enough */ - if (p->m_length == amount) - { - q->m_link = p->m_link; /* take the whole thing */ - } - else - { - /* - * break it up - 1st allocate a new - * MD to describe the remainder - */ - p1 = xmgetblk(); - if (p1 == NULL) - { - return(NULL); - } + maxval = 0; + maxflg = ((amount == -1) ? true : false) ; + p = q->m_link; /* start with next MD */ + do /* search the list for an MD with enough space */ + { + if (p == 0) + { + /* at end of list, wrap back to start */ + q = (MD *) &mp->mp_mfl; /* q => mfl field */ + p = q->m_link; /* p => 1st MD */ + } + if ((!maxflg) && (p->m_length >= amount)) + { + /* big enough */ + if (p->m_length == amount) + { + q->m_link = p->m_link; /* take the whole thing */ + } + else + { + /* + * break it up - 1st allocate a new + * MD to describe the remainder + */ + p1 = xmgetblk(); + if (p1 == NULL) + { + return(NULL); + } - /* init new MD */ - p1->m_length = p->m_length - amount; - p1->m_start = p->m_start + amount; - p1->m_link = p->m_link; - p->m_length = amount; /* adjust allocated block */ - q->m_link = p1; - } - /* link allocate block into allocated list, - mark owner of block, & adjust rover */ - p->m_link = mp->mp_mal; - mp->mp_mal = p; - mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q); - return(p); /* got some */ - } - else if (p->m_length > maxval) - maxval = p->m_length; - p = ( q=p )->m_link; - } while(q != mp->mp_rover); + /* init new MD */ + p1->m_length = p->m_length - amount; + p1->m_start = p->m_start + amount; + p1->m_link = p->m_link; + p->m_length = amount; /* adjust allocated block */ + q->m_link = p1; + } + /* link allocate block into allocated list, + mark owner of block, & adjust rover */ + p->m_link = mp->mp_mal; + mp->mp_mal = p; + mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q); + return(p); /* got some */ + } + else if (p->m_length > maxval) + maxval = p->m_length; + p = ( q=p )->m_link; + } while(q != mp->mp_rover); - /* - * return either the max, or 0 (error) - */ - if (maxflg) - { - maxval -= 15; /* 16 bytes alignment */ - if (maxval < 0) - { - maxval = 0; - } - else - { - maxval &= 0xFFFFFFF0; - } - } - return(maxflg ? (MD *) maxval : 0); + /* + * return either the max, or 0 (error) + */ + if (maxflg) + { + maxval -= 15; /* 16 bytes alignment */ + if (maxval < 0) + { + maxval = 0; + } + else + { + maxval &= 0xFFFFFFF0; + } + } + return(maxflg ? (MD *) maxval : 0); } static void freeit(MD *m, MPB *mp) { - MD *p, *q; + MD *p, *q; - q = 0; - for (p = mp->mp_mfl; p ; p = (q = p) -> m_link) - { - if (m->m_start <= p->m_start) - { - break; - } - } - m->m_link = p; + q = 0; + for (p = mp->mp_mfl; p ; p = (q = p) -> m_link) + { + if (m->m_start <= p->m_start) + { + break; + } + } + m->m_link = p; - if (q) - { - q->m_link = m; - } - else - { - mp->mp_mfl = m; - } + if (q) + { + q->m_link = m; + } + else + { + mp->mp_mfl = m; + } - if (!mp->mp_rover) - { - mp->mp_rover = m; - } + if (!mp->mp_rover) + { + mp->mp_rover = m; + } - if (p) - { - if (m->m_start + m->m_length == p->m_start) - { - /* join to higher neighbor */ - m->m_length += p->m_length; - m->m_link = p->m_link; - if (p == mp->mp_rover) - { - mp->mp_rover = m; - } - xmfreblk(p); - } - } - if (q) - { - if (q->m_start + q->m_length == m->m_start) - { - /* join to lower neighbor */ - q->m_length += m->m_length; - q->m_link = m->m_link; - if (m == mp->mp_rover) - { - mp->mp_rover = q; - } - xmfreblk(m); - } - } + if (p) + { + if (m->m_start + m->m_length == p->m_start) + { + /* join to higher neighbor */ + m->m_length += p->m_length; + m->m_link = p->m_link; + if (p == mp->mp_rover) + { + mp->mp_rover = m; + } + xmfreblk(p); + } + } + if (q) + { + if (q->m_start + q->m_length == m->m_start) + { + /* join to lower neighbor */ + q->m_length += m->m_length; + q->m_link = m->m_link; + if (m == mp->mp_rover) + { + mp->mp_rover = q; + } + xmfreblk(m); + } + } } int32_t driver_mem_free(void *addr) { - int level; - MD *p, **q; - MPB *mpb; - mpb = &pmd; - level = set_ipl(7); + int level; + MD *p, **q; + MPB *mpb; + mpb = &pmd; + level = set_ipl(7); - for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) - { - if ((long) addr == p->m_start) - { - break; - } - } + for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link)) + { + if ((long) addr == p->m_start) + { + break; + } + } - if (!p) - { - set_ipl(level); - return(-1); - } + if (!p) + { + set_ipl(level); + return(-1); + } - *q = p->m_link; - freeit(p, mpb); - set_ipl(level); + *q = p->m_link; + freeit(p, mpb); + set_ipl(level); - dbg("%s: driver_mem_free(0x%08X)\r\n", __FUNCTION__, addr); + dbg("%s: driver_mem_free(0x%08X)\r\n", __FUNCTION__, addr); - return(0); + return(0); } void *driver_mem_alloc(uint32_t amount) { - void *ret = NULL; - int level; - MD *m; + void *ret = NULL; + int level; + MD *m; - if (amount == -1L) - { - return (void *) ffit(-1L, &pmd); - } + if (amount == -1L) + { + return (void *) ffit(-1L, &pmd); + } - if (amount <= 0 ) - { - return(0); - } + if (amount <= 0 ) + { + return(0); + } - if ((amount & 1)) - { - amount++; - } + if ((amount & 1)) + { + amount++; + } - level = set_ipl(7); - m = ffit(amount, &pmd); + level = set_ipl(7); + m = ffit(amount, &pmd); - if (m != NULL) - { - ret = (void *) m->m_start; - } - set_ipl(level); - dbg("%s: driver_mem_alloc(%d) = 0x%08X\r\n", __FUNCTION__, amount, ret); + if (m != NULL) + { + ret = (void *) m->m_start; + } + set_ipl(level); + dbg("%s: driver_mem_alloc(%d) = 0x%08X\r\n", __FUNCTION__, amount, ret); - return ret; + return ret; } static int use_count = 0; int driver_mem_init(void) { - if (use_count == 0) - { - dbg("%s: initialise driver_mem_buffer[] at %p, size 0x%x\r\n", __FUNCTION__, driver_mem_buffer, DRIVER_MEM_BUFFER_SIZE); - memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE); + if (use_count == 0) + { + dbg("%s: initialise driver_mem_buffer[] at %p, size 0x%x\r\n", __FUNCTION__, driver_mem_buffer, DRIVER_MEM_BUFFER_SIZE); + memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE); - pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; - tab_md[0].m_link = (MD *) NULL; - tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15; - tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; - tab_md[0].m_own = (void *) 1L; - pmd.mp_mal = (MD *) NULL; - memset(driver_mem_buffer, 0, tab_md[0].m_length); + pmd.mp_mfl = pmd.mp_rover = &tab_md[0]; + tab_md[0].m_link = (MD *) NULL; + tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15; + tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE; + tab_md[0].m_own = (void *) 1L; + pmd.mp_mal = (MD *) NULL; + memset(driver_mem_buffer, 0, tab_md[0].m_length); - dbg("%s: uncached driver memory buffer at 0x%08X size %d\r\n", __FUNCTION__, tab_md[0].m_start, tab_md[0].m_length); - } - use_count++; - dbg("%s: driver_mem now has a use count of %d\r\n", __FUNCTION__, use_count); + dbg("%s: uncached driver memory buffer at 0x%08X size %d\r\n", __FUNCTION__, tab_md[0].m_start, tab_md[0].m_length); + } + use_count++; + dbg("%s: driver_mem now has a use count of %d\r\n", __FUNCTION__, use_count); - return 0; + return 0; } void driver_mem_release(void) { - if (use_count-- == 0) - { + if (use_count-- == 0) + { #ifndef CONFIG_USB_MEM_NO_CACHE #ifdef USE_RADEON_MEMORY - if (driver_mem_buffer == (void *) offscren_reserved()) - return; + if (driver_mem_buffer == (void *) offscren_reserved()) + return; #endif #endif - } - dbg("%s: driver_mem use count now %d\r\n", __FUNCTION__, use_count); + } + dbg("%s: driver_mem use count now %d\r\n", __FUNCTION__, use_count); } diff --git a/BaS_gcc/sys/sysinit.c b/BaS_gcc/sys/sysinit.c index f90b26a..3ea14b9 100644 --- a/BaS_gcc/sys/sysinit.c +++ b/BaS_gcc/sys/sysinit.c @@ -47,7 +47,6 @@ #error "unknown machine" #endif /* MACHINE_M5484LITE */ -# #include "dma.h" #include "mod_devicetable.h" #include "pci_ids.h" @@ -55,7 +54,7 @@ #include "usb.h" #include "video.h" -// #define DEBUG_SYSINIT +//#define DEBUG_SYSINIT #ifdef DEBUG_SYSINIT #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #else @@ -79,10 +78,10 @@ extern volatile long _VRAM; /* start address of video ram from linker script */ */ void init_slt(void) { - xprintf("slice timer initialization: "); - MCF_SLT0_STCNT = 0xffffffff; - MCF_SLT0_SCR = MCF_SLT_SCR_TEN | MCF_SLT_SCR_RUN; /* enable and run continuously */ - xprintf("finished\r\n"); + xprintf("slice timer initialization: "); + MCF_SLT0_STCNT = 0xffffffff; + MCF_SLT0_SCR = MCF_SLT_SCR_TEN | MCF_SLT_SCR_RUN; /* enable and run continuously */ + xprintf("finished\r\n"); } /* @@ -90,132 +89,132 @@ void init_slt(void) */ void init_gpio(void) { - /* - * pad register P.S.:FBCTL and FBCS set correctly at reset - */ + /* + * pad register P.S.:FBCTL and FBCS set correctly at reset + */ - /* - * configure all four 547x GPIO module DMA pins: - * - * /DACK1 - DMA acknowledge 1 - * /DACK0 - DMA acknowledge 0 - * /DREQ1 - DMA request 1 - * /DREQ0 - DMA request 0 - * - * for DMA operation - */ - MCF_PAD_PAR_DMA = MCF_PAD_PAR_DMA_PAR_DACK0(0x3) | - MCF_PAD_PAR_DMA_PAR_DACK1(0x3) | - MCF_PAD_PAR_DMA_PAR_DREQ1(0x3) | - MCF_PAD_PAR_DMA_PAR_DREQ0(0x3); + /* + * configure all four 547x GPIO module DMA pins: + * + * /DACK1 - DMA acknowledge 1 + * /DACK0 - DMA acknowledge 0 + * /DREQ1 - DMA request 1 + * /DREQ0 - DMA request 0 + * + * for DMA operation + */ + MCF_PAD_PAR_DMA = MCF_PAD_PAR_DMA_PAR_DACK0(0x3) | + MCF_PAD_PAR_DMA_PAR_DACK1(0x3) | + MCF_PAD_PAR_DMA_PAR_DREQ1(0x3) | + MCF_PAD_PAR_DMA_PAR_DREQ0(0x3); - /* - * configure FEC0 pin assignment on GPIO module as FEC0 - * configure FEC1 pin assignment (PAR_E17, PAR_E1MII) as GPIO, - * /IRQ5 and /IRQ6 from GPIO (needs to be disabled on EPORT module, which also can - * use those INTs). - */ - MCF_PAD_PAR_FECI2CIRQ = MCF_PAD_PAR_FECI2CIRQ_PAR_E07 | - MCF_PAD_PAR_FECI2CIRQ_PAR_E0MII | - MCF_PAD_PAR_FECI2CIRQ_PAR_E0MDIO | - MCF_PAD_PAR_FECI2CIRQ_PAR_E0MDC | - MCF_PAD_PAR_FECI2CIRQ_PAR_E1MDIO_E1MDIO | - MCF_PAD_PAR_FECI2CIRQ_PAR_E1MDC_E1MDC | - MCF_PAD_PAR_FECI2CIRQ_PAR_SDA | - MCF_PAD_PAR_FECI2CIRQ_PAR_SCL | - MCF_PAD_PAR_FECI2CIRQ_PAR_IRQ6 | - MCF_PAD_PAR_FECI2CIRQ_PAR_IRQ5; + /* + * configure FEC0 pin assignment on GPIO module as FEC0 + * configure FEC1 pin assignment (PAR_E17, PAR_E1MII) as GPIO, + * /IRQ5 and /IRQ6 from GPIO (needs to be disabled on EPORT module, which also can + * use those INTs). + */ + MCF_PAD_PAR_FECI2CIRQ = MCF_PAD_PAR_FECI2CIRQ_PAR_E07 | + MCF_PAD_PAR_FECI2CIRQ_PAR_E0MII | + MCF_PAD_PAR_FECI2CIRQ_PAR_E0MDIO | + MCF_PAD_PAR_FECI2CIRQ_PAR_E0MDC | + MCF_PAD_PAR_FECI2CIRQ_PAR_E1MDIO_E1MDIO | + MCF_PAD_PAR_FECI2CIRQ_PAR_E1MDC_E1MDC | + MCF_PAD_PAR_FECI2CIRQ_PAR_SDA | + MCF_PAD_PAR_FECI2CIRQ_PAR_SCL | + MCF_PAD_PAR_FECI2CIRQ_PAR_IRQ6 | + MCF_PAD_PAR_FECI2CIRQ_PAR_IRQ5; - /* - * configure PCI Grant pin assignment on GPIO module: - * - * /PCIBG4 used as FlexBus /TBST - * /PCIBG3 used as general purpose I/O - * /PCIBG2 used as /PCIBG2 - * /PCIBG1 used as /PCIBG1 - * /PCIBG0 used as /PCIBG0 - */ + /* + * configure PCI Grant pin assignment on GPIO module: + * + * /PCIBG4 used as FlexBus /TBST + * /PCIBG3 used as general purpose I/O + * /PCIBG2 used as /PCIBG2 + * /PCIBG1 used as /PCIBG1 + * /PCIBG0 used as /PCIBG0 + */ #if MACHINE_FIREBEE - MCF_PAD_PAR_PCIBG = MCF_PAD_PAR_PCIBG_PAR_PCIBG4_TBST | - MCF_PAD_PAR_PCIBG_PAR_PCIBG3_GPIO | - MCF_PAD_PAR_PCIBG_PAR_PCIBG2_PCIBG2 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG1_PCIBG1 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG0_PCIBG0; + MCF_PAD_PAR_PCIBG = MCF_PAD_PAR_PCIBG_PAR_PCIBG4_TBST | + MCF_PAD_PAR_PCIBG_PAR_PCIBG3_GPIO | + MCF_PAD_PAR_PCIBG_PAR_PCIBG2_PCIBG2 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG1_PCIBG1 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG0_PCIBG0; #elif MACHINE_M5484LITE - MCF_PAD_PAR_PCIBG = MCF_PAD_PAR_PCIBG_PAR_PCIBG4_PCIBG4 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG3_PCIBG3 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG2_PCIBG2 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG1_PCIBG1 | - MCF_PAD_PAR_PCIBG_PAR_PCIBG0_PCIBG0; + MCF_PAD_PAR_PCIBG = MCF_PAD_PAR_PCIBG_PAR_PCIBG4_PCIBG4 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG3_PCIBG3 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG2_PCIBG2 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG1_PCIBG1 | + MCF_PAD_PAR_PCIBG_PAR_PCIBG0_PCIBG0; #endif /* MACHINE_FIREBEE */ - /* - * configure PCI request pin assignment on GPIO module: - * /PCIBR4 as /IRQ4 - * /PCIBR3 as GPIO (PIC) - * /PCIBR2 as /PCIBR2 - * /PCIBR1 as /PCIBR1 - * /PCIBR0 as /PCIBR0 - */ + /* + * configure PCI request pin assignment on GPIO module: + * /PCIBR4 as /IRQ4 + * /PCIBR3 as GPIO (PIC) + * /PCIBR2 as /PCIBR2 + * /PCIBR1 as /PCIBR1 + * /PCIBR0 as /PCIBR0 + */ #if defined(MACHINE_FIREBEE) - MCF_PAD_PAR_PCIBR = MCF_PAD_PAR_PCIBR_PAR_PCIBR4_IRQ4 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR3_GPIO | - MCF_PAD_PAR_PCIBR_PAR_PCIBR2_PCIBR2 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR1_PCIBR1 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR0_PCIBR0; + MCF_PAD_PAR_PCIBR = MCF_PAD_PAR_PCIBR_PAR_PCIBR4_IRQ4 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR3_GPIO | + MCF_PAD_PAR_PCIBR_PAR_PCIBR2_PCIBR2 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR1_PCIBR1 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR0_PCIBR0; #elif defined(MACHINE_M5484LITE) - MCF_PAD_PAR_PCIBR = MCF_PAD_PAR_PCIBR_PAR_PCIBR4_PCIBR4 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR3_PCIBR3 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR2_PCIBR2 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR1_PCIBR1 | - MCF_PAD_PAR_PCIBR_PAR_PCIBR0_PCIBR0; + MCF_PAD_PAR_PCIBR = MCF_PAD_PAR_PCIBR_PAR_PCIBR4_PCIBR4 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR3_PCIBR3 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR2_PCIBR2 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR1_PCIBR1 | + MCF_PAD_PAR_PCIBR_PAR_PCIBR0_PCIBR0; #endif /* MACHINE_FIREBEE */ - /* - * configure PSC3 pin assignment on GPIO module: - * /PSC3CTS as /PSC3PTS - * /PSC3RTS as /PSC3RTS - * PSC3RXD as PSC3RXD - * PSC3TXD as PSC3TXD - */ + /* + * configure PSC3 pin assignment on GPIO module: + * /PSC3CTS as /PSC3PTS + * /PSC3RTS as /PSC3RTS + * PSC3RXD as PSC3RXD + * PSC3TXD as PSC3TXD + */ - MCF_PAD_PAR_PSC3 = MCF_PAD_PAR_PSC3_PAR_TXD3 | MCF_PAD_PAR_PSC3_PAR_RXD3; + MCF_PAD_PAR_PSC3 = MCF_PAD_PAR_PSC3_PAR_TXD3 | MCF_PAD_PAR_PSC3_PAR_RXD3; - /* - * Configure PSC1 pin assignment on GPIO module: - * - all pins configured for serial interface operation - */ + /* + * Configure PSC1 pin assignment on GPIO module: + * - all pins configured for serial interface operation + */ - MCF_PAD_PAR_PSC1 = MCF_PAD_PAR_PSC1_PAR_CTS1_CTS | - MCF_PAD_PAR_PSC1_PAR_RTS1_RTS | - MCF_PAD_PAR_PSC1_PAR_RXD1 | - MCF_PAD_PAR_PSC1_PAR_TXD1; + MCF_PAD_PAR_PSC1 = MCF_PAD_PAR_PSC1_PAR_CTS1_CTS | + MCF_PAD_PAR_PSC1_PAR_RTS1_RTS | + MCF_PAD_PAR_PSC1_PAR_RXD1 | + MCF_PAD_PAR_PSC1_PAR_TXD1; - /* - * Configure PSC0 Pin Assignment on GPIO module: - * - all pins configured for serial interface operation - */ + /* + * Configure PSC0 Pin Assignment on GPIO module: + * - all pins configured for serial interface operation + */ - MCF_PAD_PAR_PSC0 = MCF_PAD_PAR_PSC0_PAR_CTS0_CTS | - MCF_PAD_PAR_PSC0_PAR_RTS0_RTS | - MCF_PAD_PAR_PSC0_PAR_RXD0 | - MCF_PAD_PAR_PSC0_PAR_TXD0; + MCF_PAD_PAR_PSC0 = MCF_PAD_PAR_PSC0_PAR_CTS0_CTS | + MCF_PAD_PAR_PSC0_PAR_RTS0_RTS | + MCF_PAD_PAR_PSC0_PAR_RXD0 | + MCF_PAD_PAR_PSC0_PAR_TXD0; - /* - * Configure all DSPI pins on the GPIO module for there primary function - */ - MCF_PAD_PAR_DSPI = MCF_PAD_PAR_DSPI_PAR_SOUT(MCF_PAD_PAR_DSPI_PAR_SOUT_SOUT) | - MCF_PAD_PAR_DSPI_PAR_SIN(MCF_PAD_PAR_DSPI_PAR_SIN_SIN) | - MCF_PAD_PAR_DSPI_PAR_SCK(MCF_PAD_PAR_DSPI_PAR_SCK_SCK) | - MCF_PAD_PAR_DSPI_PAR_CS0(MCF_PAD_PAR_DSPI_PAR_CS0_DSPICS0) | - MCF_PAD_PAR_DSPI_PAR_CS2(MCF_PAD_PAR_DSPI_PAR_CS2_DSPICS2) | - MCF_PAD_PAR_DSPI_PAR_CS3(MCF_PAD_PAR_DSPI_PAR_CS3_DSPICS3) | - MCF_PAD_PAR_DSPI_PAR_CS5; + /* + * Configure all DSPI pins on the GPIO module for there primary function + */ + MCF_PAD_PAR_DSPI = MCF_PAD_PAR_DSPI_PAR_SOUT(MCF_PAD_PAR_DSPI_PAR_SOUT_SOUT) | + MCF_PAD_PAR_DSPI_PAR_SIN(MCF_PAD_PAR_DSPI_PAR_SIN_SIN) | + MCF_PAD_PAR_DSPI_PAR_SCK(MCF_PAD_PAR_DSPI_PAR_SCK_SCK) | + MCF_PAD_PAR_DSPI_PAR_CS0(MCF_PAD_PAR_DSPI_PAR_CS0_DSPICS0) | + MCF_PAD_PAR_DSPI_PAR_CS2(MCF_PAD_PAR_DSPI_PAR_CS2_DSPICS2) | + MCF_PAD_PAR_DSPI_PAR_CS3(MCF_PAD_PAR_DSPI_PAR_CS3_DSPICS3) | + MCF_PAD_PAR_DSPI_PAR_CS5; - MCF_PAD_PAR_TIMER = MCF_PAD_PAR_TIMER_PAR_TIN3(MCF_PAD_PAR_TIMER_PAR_TIN3_IRQ3) | - MCF_PAD_PAR_TIMER_PAR_TOUT3 | - MCF_PAD_PAR_TIMER_PAR_TIN2(MCF_PAD_PAR_TIMER_PAR_TIN2_IRQ2) | - MCF_PAD_PAR_TIMER_PAR_TOUT2; + MCF_PAD_PAR_TIMER = MCF_PAD_PAR_TIMER_PAR_TIN3(MCF_PAD_PAR_TIMER_PAR_TIN3_IRQ3) | + MCF_PAD_PAR_TIMER_PAR_TOUT3 | + MCF_PAD_PAR_TIMER_PAR_TIN2(MCF_PAD_PAR_TIMER_PAR_TIN2_IRQ2) | + MCF_PAD_PAR_TIMER_PAR_TOUT2; } /* @@ -223,60 +222,60 @@ void init_gpio(void) */ void init_serial(void) { - /* PSC0: SER1 */ - MCF_PSC0_PSCSICR = 0; /* PSC control register: select UART mode */ - MCF_PSC0_PSCCSR = 0xDD; /* use TX and RX baud rate from PSC timer */ - MCF_PSC0_PSCCTUR = 0x00; /* =\ */ + /* PSC0: SER1 */ + MCF_PSC0_PSCSICR = 0; /* PSC control register: select UART mode */ + MCF_PSC0_PSCCSR = 0xDD; /* use TX and RX baud rate from PSC timer */ + MCF_PSC0_PSCCTUR = 0x00; /* =\ */ #ifdef MACHINE_FIREBEE - MCF_PSC0_PSCCTLR = 36; /* divide sys_clk by 36 => BAUD RATE = 115200 bps */ + MCF_PSC0_PSCCTLR = 36; /* divide sys_clk by 36 => BAUD RATE = 115200 bps */ #endif #ifdef MACHINE_M5484LITE - MCF_PSC0_PSCCTLR = 27; /* LITE board has 100 MHz sys_clk only */ + MCF_PSC0_PSCCTLR = 27; /* LITE board has 100 MHz sys_clk only */ #endif - MCF_PSC0_PSCCR = 0x20; /* reset receiver and RxFIFO */ - MCF_PSC0_PSCCR = 0x30; /* reset transmitter and TxFIFO */ - MCF_PSC0_PSCCR = 0x40; /* reset all error status */ - MCF_PSC0_PSCCR = 0x50; /* reset break change interrupt */ - MCF_PSC0_PSCCR = 0x10; /* reset MR pointer */ - MCF_PSC0_PSCIMR = 0x8700; /* enable input port change interrupt, enable delta break interrupt, */ - /* enable receiver interrupt/request, enable transceiver interrupt/request */ + MCF_PSC0_PSCCR = 0x20; /* reset receiver and RxFIFO */ + MCF_PSC0_PSCCR = 0x30; /* reset transmitter and TxFIFO */ + MCF_PSC0_PSCCR = 0x40; /* reset all error status */ + MCF_PSC0_PSCCR = 0x50; /* reset break change interrupt */ + MCF_PSC0_PSCCR = 0x10; /* reset MR pointer */ + MCF_PSC0_PSCIMR = 0x8700; /* enable input port change interrupt, enable delta break interrupt, */ + /* enable receiver interrupt/request, enable transceiver interrupt/request */ - MCF_PSC0_PSCACR = 0x03; /* enable state change of CTS */ - MCF_PSC0_PSCMR1 = 0xb3; /* 8 bit, no parity */ - MCF_PSC0_PSCMR2 = 0x07; /* 1 stop bit */ - MCF_PSC0_PSCRFCR = 0x0F; - MCF_PSC0_PSCTFCR = 0x0F; - MCF_PSC0_PSCRFAR = 0x00F0; - MCF_PSC0_PSCTFAR = 0x00F0; - MCF_PSC0_PSCOPSET = 0x01; - MCF_PSC0_PSCCR = 0x05; + MCF_PSC0_PSCACR = 0x03; /* enable state change of CTS */ + MCF_PSC0_PSCMR1 = 0xb3; /* 8 bit, no parity */ + MCF_PSC0_PSCMR2 = 0x07; /* 1 stop bit */ + MCF_PSC0_PSCRFCR = 0x0F; + MCF_PSC0_PSCTFCR = 0x0F; + MCF_PSC0_PSCRFAR = 0x00F0; + MCF_PSC0_PSCTFAR = 0x00F0; + MCF_PSC0_PSCOPSET = 0x01; + MCF_PSC0_PSCCR = 0x05; #if defined(MACHINE_FIREBEE) /* PSC3 is not connected to anything on the LITE board */ - /* PSC3: PIC */ - MCF_PSC3_PSCSICR = 0; // UART - MCF_PSC3_PSCCSR = 0xDD; - MCF_PSC3_PSCCTUR = 0x00; - MCF_PSC3_PSCCTLR = 36; // BAUD RATE = 115200 - MCF_PSC3_PSCCR = 0x20; - MCF_PSC3_PSCCR = 0x30; - MCF_PSC3_PSCCR = 0x40; - MCF_PSC3_PSCCR = 0x50; - MCF_PSC3_PSCCR = 0x10; - MCF_PSC3_PSCIMR = 0x0200; // receiver interrupt enable - MCF_PSC3_PSCACR = 0x03; - MCF_PSC3_PSCMR1 = 0xb3; - MCF_PSC3_PSCMR2 = 0x07; - MCF_PSC3_PSCRFCR = 0x0F; - MCF_PSC3_PSCTFCR = 0x0F; - MCF_PSC3_PSCRFAR = 0x00F0; - MCF_PSC3_PSCTFAR = 0x00F0; - MCF_PSC3_PSCOPSET = 0x01; - MCF_PSC3_PSCCR = 0x05; + /* PSC3: PIC */ + MCF_PSC3_PSCSICR = 0; // UART + MCF_PSC3_PSCCSR = 0xDD; + MCF_PSC3_PSCCTUR = 0x00; + MCF_PSC3_PSCCTLR = 36; // BAUD RATE = 115200 + MCF_PSC3_PSCCR = 0x20; + MCF_PSC3_PSCCR = 0x30; + MCF_PSC3_PSCCR = 0x40; + MCF_PSC3_PSCCR = 0x50; + MCF_PSC3_PSCCR = 0x10; + MCF_PSC3_PSCIMR = 0x0200; // receiver interrupt enable + MCF_PSC3_PSCACR = 0x03; + MCF_PSC3_PSCMR1 = 0xb3; + MCF_PSC3_PSCMR2 = 0x07; + MCF_PSC3_PSCRFCR = 0x0F; + MCF_PSC3_PSCTFCR = 0x0F; + MCF_PSC3_PSCRFAR = 0x00F0; + MCF_PSC3_PSCTFAR = 0x00F0; + MCF_PSC3_PSCOPSET = 0x01; + MCF_PSC3_PSCCR = 0x05; #endif /* MACHINE_FIREBEE */ - MCF_INTC_ICR32 = 0x3F; /* PSC3 interrupt vector. Do we need it? */ + MCF_INTC_ICR32 = 0x3F; /* PSC3 interrupt vector. Do we need it? */ - xprintf("\r\nserial interfaces initialization: finished\r\n"); + xprintf("\r\nserial interfaces initialization: finished\r\n"); } /********************************************************************/ @@ -284,124 +283,124 @@ void init_serial(void) /********************************************************************/ bool init_ddram(void) { - xprintf("SDRAM controller initialization: "); + xprintf("SDRAM controller initialization: "); - /* - * Check to see if the SDRAM has already been initialized - * by a run control tool - */ - if (!(MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)) { - /* Basic configuration and initialization */ + /* + * Check to see if the SDRAM has already been initialized + * by a run control tool + */ + if (!(MCF_SDRAMC_SDCR & MCF_SDRAMC_SDCR_REF)) { + /* Basic configuration and initialization */ - /* - * SB_E (Bits 9-8): 10 <=> 7.6 mA (SDCKE) - * SB_C (Bits 7-6): 10 <=> 7.6 mA (SDRAM Clocks) - * SB_A (Bits 5-4): 10 <=> 7.6 mA (RAS, CAS, SDWE, SDADDR[12:0], and SDBA) - * SB_S (Bits 3-2): 10 <=> 7.6 mA (SDRDQS) - * SB_D (Bits 1-0): 10 <=> 7.6 mA (SDRDQS) - * - * -> lowest setting the Coldfire SDRAM controller allows - */ - MCF_SDRAMC_SDRAMDS = 0x000002AA;/* SDRAMDS configuration */ + /* + * SB_E (Bits 9-8): 10 <=> 7.6 mA (SDCKE) + * SB_C (Bits 7-6): 10 <=> 7.6 mA (SDRAM Clocks) + * SB_A (Bits 5-4): 10 <=> 7.6 mA (RAS, CAS, SDWE, SDADDR[12:0], and SDBA) + * SB_S (Bits 3-2): 10 <=> 7.6 mA (SDRDQS) + * SB_D (Bits 1-0): 10 <=> 7.6 mA (SDRDQS) + * + * -> lowest setting the Coldfire SDRAM controller allows + */ + MCF_SDRAMC_SDRAMDS = 0x000002AA;/* SDRAMDS configuration */ #if MACHINE_FIREBEE - MCF_SDRAMC_CS0CFG = 0x0000001A; /* SDRAM CS0 configuration (128Mbytes 0000_0000 - 07FF_FFFF) */ - MCF_SDRAMC_CS1CFG = 0x0800001A; /* SDRAM CS1 configuration (128Mbytes 0800_0000 - 0FFF_FFFF) */ - MCF_SDRAMC_CS2CFG = 0x1000001A; /* SDRAM CS2 configuration (128Mbytes 1000_0000 - 07FF_FFFF) */ - MCF_SDRAMC_CS3CFG = 0x1800001A; /* SDRAM CS3 configuration (128Mbytes 1800_0000 - 1FFF_FFFF) */ + MCF_SDRAMC_CS0CFG = 0x0000001A; /* SDRAM CS0 configuration (128Mbytes 0000_0000 - 07FF_FFFF) */ + MCF_SDRAMC_CS1CFG = 0x0800001A; /* SDRAM CS1 configuration (128Mbytes 0800_0000 - 0FFF_FFFF) */ + MCF_SDRAMC_CS2CFG = 0x1000001A; /* SDRAM CS2 configuration (128Mbytes 1000_0000 - 07FF_FFFF) */ + MCF_SDRAMC_CS3CFG = 0x1800001A; /* SDRAM CS3 configuration (128Mbytes 1800_0000 - 1FFF_FFFF) */ - /* - * - */ - MCF_SDRAMC_SDCFG1 = MCF_SDRAMC_SDCFG1_WTLAT(3) /* Write latency */ - | MCF_SDRAMC_SDCFG1_REF2ACT(8) /* Refresh to Active Delay */ - | MCF_SDRAMC_SDCFG1_PRE2ACT(2) /* Precharge to Active Delay */ - | MCF_SDRAMC_SDCFG1_ACT2RW(2) /* Active to Read/Write Delay */ - | MCF_SDRAMC_SDCFG1_RDLAT(6) /* Read CAS latency */ - | MCF_SDRAMC_SDCFG1_SWT2RD(3) /* Single Write to Read/Write/Precharge delay */ - | MCF_SDRAMC_SDCFG1_SRD2RW(7); /* Single Read to Read/Write/Precharge delay */ + /* + * + */ + MCF_SDRAMC_SDCFG1 = MCF_SDRAMC_SDCFG1_WTLAT(3) /* Write latency */ + | MCF_SDRAMC_SDCFG1_REF2ACT(8) /* Refresh to Active Delay */ + | MCF_SDRAMC_SDCFG1_PRE2ACT(2) /* Precharge to Active Delay */ + | MCF_SDRAMC_SDCFG1_ACT2RW(2) /* Active to Read/Write Delay */ + | MCF_SDRAMC_SDCFG1_RDLAT(6) /* Read CAS latency */ + | MCF_SDRAMC_SDCFG1_SWT2RD(3) /* Single Write to Read/Write/Precharge delay */ + | MCF_SDRAMC_SDCFG1_SRD2RW(7); /* Single Read to Read/Write/Precharge delay */ - MCF_SDRAMC_SDCFG2 = MCF_SDRAMC_SDCFG2_BL(7) /* Burst Length */ - | MCF_SDRAMC_SDCFG2_BRD2WT(7) /* Burst Read to Write delay */ - | MCF_SDRAMC_SDCFG2_BWT2RW(6) /* Burst Write to Read/Write/Precharge delay */ - | MCF_SDRAMC_SDCFG2_BRD2PRE(4); /* Burst Read to Read/Precharge delay */ + MCF_SDRAMC_SDCFG2 = MCF_SDRAMC_SDCFG2_BL(7) /* Burst Length */ + | MCF_SDRAMC_SDCFG2_BRD2WT(7) /* Burst Read to Write delay */ + | MCF_SDRAMC_SDCFG2_BWT2RW(6) /* Burst Write to Read/Write/Precharge delay */ + | MCF_SDRAMC_SDCFG2_BRD2PRE(4); /* Burst Read to Read/Precharge delay */ - MCF_SDRAMC_SDCR = MCF_SDRAMC_SDCR_IPALL /* initiate Precharge All command */ - | MCF_SDRAMC_SDCR_RCNT(13) /* Refresh Count (= (x + 1) * 64 */ - | MCF_SDRAMC_SDCR_MUX(1) /* Muxing control */ - | MCF_SDRAMC_SDCR_DDR - | MCF_SDRAMC_SDCR_CKE - | MCF_SDRAMC_SDCR_MODE_EN; + MCF_SDRAMC_SDCR = MCF_SDRAMC_SDCR_IPALL /* initiate Precharge All command */ + | MCF_SDRAMC_SDCR_RCNT(13) /* Refresh Count (= (x + 1) * 64 */ + | MCF_SDRAMC_SDCR_MUX(1) /* Muxing control */ + | MCF_SDRAMC_SDCR_DDR + | MCF_SDRAMC_SDCR_CKE + | MCF_SDRAMC_SDCR_MODE_EN; - MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ - | MCF_SDRAMC_SDMR_AD(0) /* Address */ - | MCF_SDRAMC_SDMR_BNKAD(1); /* LEMR */ - MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ - | MCF_SDRAMC_SDMR_AD(0x123) - | MCF_SDRAMC_SDMR_BNKAD(0); /* LMR */ + MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ + | MCF_SDRAMC_SDMR_AD(0) /* Address */ + | MCF_SDRAMC_SDMR_BNKAD(1); /* LEMR */ + MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ + | MCF_SDRAMC_SDMR_AD(0x123) + | MCF_SDRAMC_SDMR_BNKAD(0); /* LMR */ - MCF_SDRAMC_SDCR = 0xE10D0002; /* SDCR + IPALL */ - MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (first refresh) */ - MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (second refresh) */ - MCF_SDRAMC_SDMR = 0x008D0000; /* SDMR (write to LMR) */ - MCF_SDRAMC_SDCR = 0x710D0F00; /* SDCR (lock SDMR and enable refresh) */ + MCF_SDRAMC_SDCR = 0xE10D0002; /* SDCR + IPALL */ + MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (first refresh) */ + MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (second refresh) */ + MCF_SDRAMC_SDMR = 0x008D0000; /* SDMR (write to LMR) */ + MCF_SDRAMC_SDCR = 0x710D0F00; /* SDCR (lock SDMR and enable refresh) */ #elif MACHINE_M5484LITE - MCF_SDRAMC_CS0CFG = 0x00000019; /* SDRAM CS0 configuration (64 Mbytes 0000_0000 - 03FF_FFFF) */ - MCF_SDRAMC_CS1CFG = 0x00000000; /* SDRAM CS1 configuration - off */ - MCF_SDRAMC_CS2CFG = 0x00000000; /* SDRAM CS2 configuration - off */ - MCF_SDRAMC_CS3CFG = 0x00000000; /* SDRAM CS3 configuration - off */ + MCF_SDRAMC_CS0CFG = 0x00000019; /* SDRAM CS0 configuration (64 Mbytes 0000_0000 - 03FF_FFFF) */ + MCF_SDRAMC_CS1CFG = 0x00000000; /* SDRAM CS1 configuration - off */ + MCF_SDRAMC_CS2CFG = 0x00000000; /* SDRAM CS2 configuration - off */ + MCF_SDRAMC_CS3CFG = 0x00000000; /* SDRAM CS3 configuration - off */ - /* - * - */ - MCF_SDRAMC_SDCFG1 = MCF_SDRAMC_SDCFG1_WTLAT(3) /* Write latency */ - | MCF_SDRAMC_SDCFG1_REF2ACT(8) /* Refresh to Active Delay */ - | MCF_SDRAMC_SDCFG1_PRE2ACT(2) /* Precharge to Active Delay */ - | MCF_SDRAMC_SDCFG1_ACT2RW(2) /* Active to Read/Write Delay */ - | MCF_SDRAMC_SDCFG1_RDLAT(6) /* Read CAS latency */ - | MCF_SDRAMC_SDCFG1_SWT2RD(3) /* Single Write to Read/Write/Precharge delay */ - | MCF_SDRAMC_SDCFG1_SRD2RW(7); /* Single Read to Read/Write/Precharge delay */ + /* + * + */ + MCF_SDRAMC_SDCFG1 = MCF_SDRAMC_SDCFG1_WTLAT(3) /* Write latency */ + | MCF_SDRAMC_SDCFG1_REF2ACT(8) /* Refresh to Active Delay */ + | MCF_SDRAMC_SDCFG1_PRE2ACT(2) /* Precharge to Active Delay */ + | MCF_SDRAMC_SDCFG1_ACT2RW(2) /* Active to Read/Write Delay */ + | MCF_SDRAMC_SDCFG1_RDLAT(6) /* Read CAS latency */ + | MCF_SDRAMC_SDCFG1_SWT2RD(3) /* Single Write to Read/Write/Precharge delay */ + | MCF_SDRAMC_SDCFG1_SRD2RW(7); /* Single Read to Read/Write/Precharge delay */ - MCF_SDRAMC_SDCFG2 = MCF_SDRAMC_SDCFG2_BL(7) /* Burst Length */ - | MCF_SDRAMC_SDCFG2_BRD2WT(7) /* Burst Read to Write delay */ - | MCF_SDRAMC_SDCFG2_BWT2RW(6) /* Burst Write to Read/Write/Precharge delay */ - | MCF_SDRAMC_SDCFG2_BRD2PRE(4); /* Burst Read to Read/Precharge delay */ + MCF_SDRAMC_SDCFG2 = MCF_SDRAMC_SDCFG2_BL(7) /* Burst Length */ + | MCF_SDRAMC_SDCFG2_BRD2WT(7) /* Burst Read to Write delay */ + | MCF_SDRAMC_SDCFG2_BWT2RW(6) /* Burst Write to Read/Write/Precharge delay */ + | MCF_SDRAMC_SDCFG2_BRD2PRE(4); /* Burst Read to Read/Precharge delay */ - MCF_SDRAMC_SDCR = MCF_SDRAMC_SDCR_IPALL /* initiate Precharge All command */ - | MCF_SDRAMC_SDCR_RCNT(13) /* Refresh Count (= (x + 1) * 64 */ - | MCF_SDRAMC_SDCR_MUX(1) /* Muxing control */ - | MCF_SDRAMC_SDCR_DDR - | MCF_SDRAMC_SDCR_CKE - | MCF_SDRAMC_SDCR_MODE_EN; + MCF_SDRAMC_SDCR = MCF_SDRAMC_SDCR_IPALL /* initiate Precharge All command */ + | MCF_SDRAMC_SDCR_RCNT(13) /* Refresh Count (= (x + 1) * 64 */ + | MCF_SDRAMC_SDCR_MUX(1) /* Muxing control */ + | MCF_SDRAMC_SDCR_DDR + | MCF_SDRAMC_SDCR_CKE + | MCF_SDRAMC_SDCR_MODE_EN; - MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ - | MCF_SDRAMC_SDMR_AD(0) /* Address */ - | MCF_SDRAMC_SDMR_BNKAD(1); /* LEMR */ - MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ - | MCF_SDRAMC_SDMR_AD(0x123) - | MCF_SDRAMC_SDMR_BNKAD(0); /* LMR */ + MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ + | MCF_SDRAMC_SDMR_AD(0) /* Address */ + | MCF_SDRAMC_SDMR_BNKAD(1); /* LEMR */ + MCF_SDRAMC_SDMR = MCF_SDRAMC_SDMR_CMD /* Generate an LMR/LEMR command */ + | MCF_SDRAMC_SDMR_AD(0x123) + | MCF_SDRAMC_SDMR_BNKAD(0); /* LMR */ - MCF_SDRAMC_SDCR = 0xE10D0002; /* SDCR + IPALL */ - MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (first refresh) */ - MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (second refresh) */ - MCF_SDRAMC_SDMR = 0x008D0000; /* SDMR (write to LMR) */ - MCF_SDRAMC_SDCR = 0x710D0F00; /* SDCR (lock SDMR and enable refresh) */ + MCF_SDRAMC_SDCR = 0xE10D0002; /* SDCR + IPALL */ + MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (first refresh) */ + MCF_SDRAMC_SDCR = 0xE10D0004; /* SDCR + IREF (second refresh) */ + MCF_SDRAMC_SDMR = 0x008D0000; /* SDMR (write to LMR) */ + MCF_SDRAMC_SDCR = 0x710D0F00; /* SDCR (lock SDMR and enable refresh) */ #endif /* MACHINE_FIREBEE */ - xprintf("finished\r\n"); + xprintf("finished\r\n"); - return true; - } - else - { - xprintf("skipped. Already initialized (running from RAM)\r\n"); - } - return false; + return true; + } + else + { + xprintf("skipped. Already initialized (running from RAM)\r\n"); + } + return false; } /* @@ -409,82 +408,82 @@ bool init_ddram(void) */ void init_fbcs() { - xprintf("FlexBus chip select registers initialization: "); + xprintf("FlexBus chip select registers initialization: "); - /* Flash */ - MCF_FBCS0_CSAR = BOOTFLASH_BASE_ADDRESS; /* flash base address */ - MCF_FBCS0_CSCR = MCF_FBCS_CSCR_PS_16 | /* 16 bit word access */ - MCF_FBCS_CSCR_WS(6)| /* 6 Waitstates */ - MCF_FBCS_CSCR_AA | - MCF_FBCS_CSCR_ASET(1) | - MCF_FBCS_CSCR_RDAH(1); /* chip errata SECF077 */ - MCF_FBCS0_CSMR = BOOTFLASH_BAM | - MCF_FBCS_CSMR_V; /* enable */ + /* Flash */ + MCF_FBCS0_CSAR = BOOTFLASH_BASE_ADDRESS; /* flash base address */ + MCF_FBCS0_CSCR = MCF_FBCS_CSCR_PS_16 | /* 16 bit word access */ + MCF_FBCS_CSCR_WS(6)| /* 6 Waitstates */ + MCF_FBCS_CSCR_AA | + MCF_FBCS_CSCR_ASET(1) | + MCF_FBCS_CSCR_RDAH(1); /* chip errata SECF077 */ + MCF_FBCS0_CSMR = BOOTFLASH_BAM | + MCF_FBCS_CSMR_V; /* enable */ #if MACHINE_FIREBEE /* FBC setup for FireBee */ - MCF_FBCS1_CSAR = 0xFFF00000; /* ATARI I/O ADRESS */ - MCF_FBCS1_CSCR = MCF_FBCS_CSCR_PS_16 /* 16BIT PORT */ - | MCF_FBCS_CSCR_WS(8) /* DEFAULT 8WS */ - | MCF_FBCS_CSCR_AA; /* AA */ - MCF_FBCS1_CSMR = MCF_FBCS_CSMR_BAM_1M | MCF_FBCS_CSMR_V; + MCF_FBCS1_CSAR = 0xFFF00000; /* ATARI I/O ADRESS */ + MCF_FBCS1_CSCR = MCF_FBCS_CSCR_PS_16 /* 16BIT PORT */ + | MCF_FBCS_CSCR_WS(8) /* DEFAULT 8WS */ + | MCF_FBCS_CSCR_AA; /* AA */ + MCF_FBCS1_CSMR = MCF_FBCS_CSMR_BAM_1M | MCF_FBCS_CSMR_V; - MCF_FBCS2_CSAR = 0xF0000000; // NEUER I/O ADRESS-BEREICH - MCF_FBCS2_CSCR = MCF_FBCS_CSCR_PS_32 // 32BIT PORT - | MCF_FBCS_CSCR_WS(8) // DEFAULT 4WS - | MCF_FBCS_CSCR_AA; // AA - MCF_FBCS2_CSMR = (MCF_FBCS_CSMR_BAM_128M // F000'0000-F7FF'FFFF - | MCF_FBCS_CSMR_V); + MCF_FBCS2_CSAR = 0xF0000000; // NEUER I/O ADRESS-BEREICH + MCF_FBCS2_CSCR = MCF_FBCS_CSCR_PS_32 // 32BIT PORT + | MCF_FBCS_CSCR_WS(8) // DEFAULT 4WS + | MCF_FBCS_CSCR_AA; // AA + MCF_FBCS2_CSMR = (MCF_FBCS_CSMR_BAM_128M // F000'0000-F7FF'FFFF + | MCF_FBCS_CSMR_V); - MCF_FBCS3_CSAR = 0xF8000000; // NEUER I/O ADRESS-BEREICH - MCF_FBCS3_CSCR = MCF_FBCS_CSCR_PS_16 // 16BIT PORT - | MCF_FBCS_CSCR_AA; // AA - MCF_FBCS3_CSMR = (MCF_FBCS_CSMR_BAM_64M // F800'0000-FBFF'FFFF - | MCF_FBCS_CSMR_V); + MCF_FBCS3_CSAR = 0xF8000000; // NEUER I/O ADRESS-BEREICH + MCF_FBCS3_CSCR = MCF_FBCS_CSCR_PS_16 // 16BIT PORT + | MCF_FBCS_CSCR_AA; // AA + MCF_FBCS3_CSMR = (MCF_FBCS_CSMR_BAM_64M // F800'0000-FBFF'FFFF + | MCF_FBCS_CSMR_V); - MCF_FBCS4_CSAR = 0x40000000; // VIDEO RAM BEREICH, #FB_CS3 WIRD NICHT BENÜTZT, DECODE DIREKT AUF DEM FPGA - MCF_FBCS4_CSCR = MCF_FBCS_CSCR_PS_32 // 32BIT PORT - | MCF_FBCS_CSCR_BSTR // BURST READ ENABLE - | MCF_FBCS_CSCR_BSTW; // BURST WRITE ENABLE - MCF_FBCS4_CSMR = MCF_FBCS_CSMR_BAM_1G // 4000'0000-7FFF'FFFF - | MCF_FBCS_CSMR_V; + MCF_FBCS4_CSAR = 0x40000000; // VIDEO RAM BEREICH, #FB_CS3 WIRD NICHT BENÜTZT, DECODE DIREKT AUF DEM FPGA + MCF_FBCS4_CSCR = MCF_FBCS_CSCR_PS_32 // 32BIT PORT + | MCF_FBCS_CSCR_BSTR // BURST READ ENABLE + | MCF_FBCS_CSCR_BSTW; // BURST WRITE ENABLE + MCF_FBCS4_CSMR = MCF_FBCS_CSMR_BAM_1G // 4000'0000-7FFF'FFFF + | MCF_FBCS_CSMR_V; #elif MACHINE_M5484LITE - /* disable other FBCS for now */ - MCF_FBCS1_CSMR = 0; - MCF_FBCS2_CSMR = 0; - MCF_FBCS3_CSMR = 0; - MCF_FBCS4_CSMR = 0; + /* disable other FBCS for now */ + MCF_FBCS1_CSMR = 0; + MCF_FBCS2_CSMR = 0; + MCF_FBCS3_CSMR = 0; + MCF_FBCS4_CSMR = 0; - MCF_FBCS5_CSAR = MCF_FBCS_CSAR_BA(0x60000000); - MCF_FBCS5_CSCR = MCF_FBCS_CSCR_PS_16 /* CPLD access */ - | MCF_FBCS_CSCR_WS(32) - | MCF_FBCS_CSCR_ASET(1) - | MCF_FBCS_CSCR_AA; - MCF_FBCS5_CSMR = MCF_FBCS_CSMR_BAM_256M - | MCF_FBCS_CSMR_V; + MCF_FBCS5_CSAR = MCF_FBCS_CSAR_BA(0x60000000); + MCF_FBCS5_CSCR = MCF_FBCS_CSCR_PS_16 /* CPLD access */ + | MCF_FBCS_CSCR_WS(32) + | MCF_FBCS_CSCR_ASET(1) + | MCF_FBCS_CSCR_AA; + MCF_FBCS5_CSMR = MCF_FBCS_CSMR_BAM_256M + | MCF_FBCS_CSMR_V; #endif /* MACHINE_FIREBEE */ #ifndef MACHINE_M5484LITE - MCF_FBCS5_CSAR = 0x0; - MCF_FBCS5_CSCR = MCF_FBCS_CSCR_PS_8 - | MCF_FBCS_CSCR_BSTR - | MCF_FBCS_CSCR_BSTW - | MCF_FBCS_CSCR_RDAH(1); /* chip errata SECF077 */ - MCF_FBCS5_CSMR = MCF_FBCS_CSMR_BAM_1G; - //| MCF_FBCS_CSMR_V; + MCF_FBCS5_CSAR = 0x0; + MCF_FBCS5_CSCR = MCF_FBCS_CSCR_PS_8 + | MCF_FBCS_CSCR_BSTR + | MCF_FBCS_CSCR_BSTW + | MCF_FBCS_CSCR_RDAH(1); /* chip errata SECF077 */ + MCF_FBCS5_CSMR = MCF_FBCS_CSMR_BAM_1G; + //| MCF_FBCS_CSMR_V; #endif /* MACHINE_M5484LITE */ - xprintf("finished\r\n"); + xprintf("finished\r\n"); } void wait_pll(void) { - int32_t trgt = MCF_SLT0_SCNT - 100000; - do - { - ; - } while ((* (volatile int16_t *) 0xf0000800 < 0) && MCF_SLT0_SCNT > trgt); + int32_t trgt = MCF_SLT0_SCNT - 100000; + do + { + ; + } while ((* (volatile int16_t *) 0xf0000800 < 0) && MCF_SLT0_SCNT > trgt); } @@ -562,90 +561,90 @@ volatile uint8_t *pll_base = (volatile uint8_t *) 0xf0000600; void pll_write(int type, int param, int data) { - wait_pll(); - * (volatile uint16_t *) (pll_base + ((param << 6) | (type << 2))) = data; + wait_pll(); + * (volatile uint16_t *) (pll_base + ((param << 6) | (type << 2))) = data; } struct pll_init { - int type; - int param; - int data; + int type; + int param; + int data; }; struct pll_init pll_values[] = { - { PLL_COUNTER_TYPE_CPLF, PLL_COUNTER_PARAM_LF_R, 27 }, /* loopfilter R */ - { PLL_COUNTER_TYPE_CPLF, PLL_COUNTER_PARAM_LF_C, 1 }, /* charge pump 1 */ - { PLL_COUNTER_TYPE_N, PLL_COUNTER_PARAM_HC, 12 }, /* N counter high */ - { PLL_COUNTER_TYPE_N, PLL_COUNTER_PARAM_LC, 12 }, /* N counter low */ - { PLL_COUNTER_TYPE_C1, PLL_COUNTER_PARAM_BP, 1 }, /* c1 bypass */ - { PLL_COUNTER_TYPE_C2, PLL_COUNTER_PARAM_BP, 1 }, /* c2 bypass */ - { PLL_COUNTER_TYPE_C3, PLL_COUNTER_PARAM_BP, 1 }, /* c3 bypass */ - { PLL_COUNTER_TYPE_C0, PLL_COUNTER_PARAM_HC, 1 }, /* c0 high */ - { PLL_COUNTER_TYPE_C0, PLL_COUNTER_PARAM_LC, 1 }, /* c0 low */ - { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_MODE, 1 }, /* M odd division */ - { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_LC, 1 }, /* M low = 1 */ - { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_HC, 145 } /* M high = 145 = 146 MHz */ + { PLL_COUNTER_TYPE_CPLF, PLL_COUNTER_PARAM_LF_R, 27 }, /* loopfilter R */ + { PLL_COUNTER_TYPE_CPLF, PLL_COUNTER_PARAM_LF_C, 1 }, /* charge pump 1 */ + { PLL_COUNTER_TYPE_N, PLL_COUNTER_PARAM_HC, 12 }, /* N counter high */ + { PLL_COUNTER_TYPE_N, PLL_COUNTER_PARAM_LC, 12 }, /* N counter low */ + { PLL_COUNTER_TYPE_C1, PLL_COUNTER_PARAM_BP, 1 }, /* c1 bypass */ + { PLL_COUNTER_TYPE_C2, PLL_COUNTER_PARAM_BP, 1 }, /* c2 bypass */ + { PLL_COUNTER_TYPE_C3, PLL_COUNTER_PARAM_BP, 1 }, /* c3 bypass */ + { PLL_COUNTER_TYPE_C0, PLL_COUNTER_PARAM_HC, 1 }, /* c0 high */ + { PLL_COUNTER_TYPE_C0, PLL_COUNTER_PARAM_LC, 1 }, /* c0 low */ + { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_MODE, 1 }, /* M odd division */ + { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_LC, 1 }, /* M low = 1 */ + { PLL_COUNTER_TYPE_M, PLL_COUNTER_PARAM_HC, 145 } /* M high = 145 = 146 MHz */ }; int num_pll_values = sizeof(pll_values) / sizeof(struct pll_init); #endif /* _OLD_CODE_ */ void init_pll(void) { - int i; + int i; - xprintf("FPGA PLL initialization: "); + xprintf("FPGA PLL initialization: "); #ifndef _OLD_CODE_ - for (i = 0; i < num_pll_values; i++) - { - pll_write(pll_values[i].type, pll_values[i].param, pll_values[i].data); - } + for (i = 0; i < num_pll_values; i++) + { + pll_write(pll_values[i].type, pll_values[i].param, pll_values[i].data); + } #else /* _OLD_CODE_ */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x48) = 27; /* loopfilter r */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x48) = 27; /* loopfilter r */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x08) = 1; /* charge pump 1 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x08) = 1; /* charge pump 1 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x00) = 12; /* N counter high = 12 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x00) = 12; /* N counter high = 12 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x40) = 12; /* N counter low = 12 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x40) = 12; /* N counter low = 12 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x114) = 1; /* ck1 bypass */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x114) = 1; /* ck1 bypass */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x118) = 1; /* ck2 bypass */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x118) = 1; /* ck2 bypass */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x11c) = 1; /* ck3 bypass */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x11c) = 1; /* ck3 bypass */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x10) = 1; /* ck0 high = 1 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x10) = 1; /* ck0 high = 1 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x50) = 1; /* ck0 low = 1 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x50) = 1; /* ck0 low = 1 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x144) = 1; /* M odd division */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x144) = 1; /* M odd division */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x44) = 1; /* M low = 1 */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x44) = 1; /* M low = 1 */ - wait_pll(); - * (volatile uint16_t *) (pll_base + 0x04) = 145; /* M high = 145 = 146 MHz */ + wait_pll(); + * (volatile uint16_t *) (pll_base + 0x04) = 145; /* M high = 145 = 146 MHz */ - wait_pll(); + wait_pll(); #endif /* _OLD_CODE_ */ - * (volatile uint8_t *) 0xf0000800 = 0; /* set */ + * (volatile uint8_t *) 0xf0000800 = 0; /* set */ - xprintf("finished\r\n"); + xprintf("finished\r\n"); } @@ -655,35 +654,35 @@ void init_pll(void) */ void init_video_ddr(void) { - xprintf("init video RAM: "); + xprintf("init video RAM: "); - * (volatile uint16_t *) 0xf0000400 = 0xb; /* set cke = 1, cs=1, config = 1 */ - NOP(); + * (volatile uint16_t *) 0xf0000400 = 0xb; /* set cke = 1, cs=1, config = 1 */ + NOP(); - _VRAM = 0x00050400; /* IPALL */ - NOP(); + _VRAM = 0x00050400; /* IPALL */ + NOP(); - _VRAM = 0x00072000; /* load EMR pll on */ - NOP(); + _VRAM = 0x00072000; /* load EMR pll on */ + NOP(); - _VRAM = 0x00070122; /* load MR: reset pll, cl=2, burst=4lw */ - NOP(); + _VRAM = 0x00070122; /* load MR: reset pll, cl=2, burst=4lw */ + NOP(); - _VRAM = 0x00050400; /* IPALL */ - NOP(); + _VRAM = 0x00050400; /* IPALL */ + NOP(); - _VRAM = 0x00060000; /* auto refresh */ - NOP(); + _VRAM = 0x00060000; /* auto refresh */ + NOP(); - _VRAM = 0x00060000; /* auto refresh */ - NOP(); + _VRAM = 0x00060000; /* auto refresh */ + NOP(); - _VRAM = 0000070022; /* load MR dll on */ - NOP(); + _VRAM = 0000070022; /* load MR dll on */ + NOP(); - * (uint32_t *) 0xf0000400 = 0x01070002; /* fifo on, refresh on, ddrcs and cke on, video dac on */ + * (uint32_t *) 0xf0000400 = 0x01070002; /* fifo on, refresh on, ddrcs and cke on, video dac on */ - xprintf("finished\r\n"); + xprintf("finished\r\n"); } @@ -692,97 +691,97 @@ void init_video_ddr(void) { */ void init_usb(void) { - extern struct pci_device_id ohci_usb_pci_table[]; - extern struct pci_device_id ehci_usb_pci_table[]; - struct pci_device_id *board; - int32_t handle; - int usb_found = 0; - int index = 0; + extern struct pci_device_id ohci_usb_pci_table[]; + extern struct pci_device_id ehci_usb_pci_table[]; + struct pci_device_id *board; + int32_t handle; + int usb_found = 0; + int index = 0; - xprintf("USB controller initialization:\r\n"); + xprintf("USB controller initialization:\r\n"); - do - { - handle = pci_find_device(0x0000, 0xffff, index++); - if (handle > 0) - { - uint32_t id = 0; - uint32_t pci_class = 0; + do + { + handle = pci_find_device(0x0000, 0xffff, index++); + if (handle > 0) + { + uint32_t id = 0; + uint32_t pci_class = 0; - id = pci_read_config_longword(handle, PCIIDR); - pci_class = pci_read_config_longword(handle, PCIREV); - dbg("compare class code 0x%x to 0x%x\r\n", PCI_CLASS_CODE(pci_class), PCI_CLASS_SERIAL_USB); - if (PCI_CLASS_CODE(pci_class) == PCI_CLASS_SERIAL_USB) - { - xprintf("serial USB found at bus=0x%x, dev=0x%x, fnc=0x%x (0x%x)\r\n", - PCI_BUS_FROM_HANDLE(handle), - PCI_DEVICE_FROM_HANDLE(handle), - PCI_FUNCTION_FROM_HANDLE(handle), - handle); - dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_EHCI); - if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_EHCI) - { - board = ehci_usb_pci_table; - while (board->vendor) - { - dbg("compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); - dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); - if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) - { -#ifdef _NOT_YET_ /* FIXME: usb_init() is broken */ - dbg("match. trying to init board\r\n"); - if (usb_init(handle, board) >= 0) - { - usb_found++; - } -#endif /* _NOT_YET_ */ - } - board++; - } - } + id = pci_read_config_longword(handle, PCIIDR); + pci_class = pci_read_config_longword(handle, PCIREV); + dbg("compare class code 0x%x to 0x%x\r\n", PCI_CLASS_CODE(pci_class), PCI_CLASS_SERIAL_USB); + if (PCI_CLASS_CODE(pci_class) == PCI_CLASS_SERIAL_USB) + { + xprintf("serial USB found at bus=0x%x, dev=0x%x, fnc=0x%x (0x%x)\r\n", + PCI_BUS_FROM_HANDLE(handle), + PCI_DEVICE_FROM_HANDLE(handle), + PCI_FUNCTION_FROM_HANDLE(handle), + handle); + dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_EHCI); + if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_EHCI) + { + board = ehci_usb_pci_table; + while (board->vendor) + { + dbg("compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); + dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); + if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) + { + dbg("match. trying to init board\r\n"); + if (usb_init(handle, board) >= 0) + { + usb_found++; + } + } + board++; + } + } - dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_OHCI); - if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_OHCI) - { - board = ohci_usb_pci_table; + dbg("compare subclass code 0x%x against 0x%x\r\n", PCI_SUBCLASS(pci_class), PCI_CLASS_SERIAL_USB_OHCI); + if (PCI_SUBCLASS(pci_class) == PCI_CLASS_SERIAL_USB_OHCI) + { + board = ohci_usb_pci_table; - while (board->vendor) - { - dbg("matched. compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); - dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); - if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) - { - // if (usb_init(handle, board) >= 0) - usb_found++; - } - board++; - } - } - } - } - dbg("PCI device handle = %x\r\n", handle); - } while (handle >= 0); + while (board->vendor) + { + dbg("matched. compare vendor id 0x%x against 0x%x\r\n", board->vendor, PCI_VENDOR_ID(id)); + dbg("compare device id 0x%x against 0x%x\r\n", board->device, PCI_DEVICE_ID(id)); + if ((board->vendor == PCI_VENDOR_ID(id)) && board->device == PCI_DEVICE_ID(id)) + { + if (usb_init(handle, board) >= 0) + { + usb_found++; + } + } + board++; + } + } + } + } + dbg("PCI device handle = %x\r\n", handle); + } while (handle >= 0); - xprintf("finished (found %d USB controller(s))\r\n", usb_found); + xprintf("finished (found %d USB host controller(s))\r\n", usb_found); } static bool i2c_transfer_finished(void) { - if (MCF_I2C_I2SR & MCF_I2C_I2SR_IIF) - return true; + if (MCF_I2C_I2SR & MCF_I2C_I2SR_IIF) + return true; - return false; + return false; } static void wait_i2c_transfer_finished(void) { - waitfor(100000, i2c_transfer_finished); /* wait until interrupt bit has been set */ - MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF; /* clear interrupt bit (byte transfer finished */ + waitfor(100000, i2c_transfer_finished); /* wait until interrupt bit has been set */ + MCF_I2C_I2SR &= ~MCF_I2C_I2SR_IIF; /* clear interrupt bit (byte transfer finished */ } static bool i2c_bus_free(void) { - return (MCF_I2C_I2SR & MCF_I2C_I2SR_IBB); + return (MCF_I2C_I2SR & MCF_I2C_I2SR_IBB); } /* @@ -790,141 +789,141 @@ static bool i2c_bus_free(void) */ void dvi_on(void) { - uint8_t receivedByte; - uint8_t dummyByte; /* only used for a dummy read */ - int num_tries = 0; + uint8_t receivedByte; + uint8_t dummyByte; /* only used for a dummy read */ + int num_tries = 0; - xprintf("DVI digital video output initialization: "); + xprintf("DVI digital video output initialization: "); - MCF_I2C_I2FDR = 0x3c; /* divide system clock by 1280: 100kHz standard */ + MCF_I2C_I2FDR = 0x3c; /* divide system clock by 1280: 100kHz standard */ - do - { - /* disable all i2c interrupt routing targets */ - MCF_I2C_I2ICR = 0x0; // ~(MCF_I2C_I2ICR_IE | MCF_I2C_I2ICR_RE | MCF_I2C_I2ICR_TE | MCF_I2C_I2ICR_BNBE); + do + { + /* disable all i2c interrupt routing targets */ + MCF_I2C_I2ICR = 0x0; // ~(MCF_I2C_I2ICR_IE | MCF_I2C_I2ICR_RE | MCF_I2C_I2ICR_TE | MCF_I2C_I2ICR_BNBE); - /* disable i2c, disable i2c interrupts, slave, receive, i2c = acknowledge, no repeat start */ - MCF_I2C_I2CR = 0x0; + /* disable i2c, disable i2c interrupts, slave, receive, i2c = acknowledge, no repeat start */ + MCF_I2C_I2CR = 0x0; - /* repeat start, transmit acknowledge */ - MCF_I2C_I2CR = MCF_I2C_I2CR_RSTA | MCF_I2C_I2CR_TXAK; + /* repeat start, transmit acknowledge */ + MCF_I2C_I2CR = MCF_I2C_I2CR_RSTA | MCF_I2C_I2CR_TXAK; - receivedByte = MCF_I2C_I2DR; /* read a byte */ - MCF_I2C_I2SR = 0x0; /* clear status register */ - MCF_I2C_I2CR = 0x0; /* disable i2c */ + receivedByte = MCF_I2C_I2DR; /* read a byte */ + MCF_I2C_I2SR = 0x0; /* clear status register */ + MCF_I2C_I2CR = 0x0; /* disable i2c */ - MCF_I2C_I2ICR = MCF_I2C_I2ICR_IE; /* route i2c interrupts to cpu */ - /* i2c enable, master mode, transmit acknowledge */ - MCF_I2C_I2CR = MCF_I2C_I2CR_IEN | MCF_I2C_I2CR_MSTA | MCF_I2C_I2CR_MTX; + MCF_I2C_I2ICR = MCF_I2C_I2ICR_IE; /* route i2c interrupts to cpu */ + /* i2c enable, master mode, transmit acknowledge */ + MCF_I2C_I2CR = MCF_I2C_I2CR_IEN | MCF_I2C_I2CR_MSTA | MCF_I2C_I2CR_MTX; - MCF_I2C_I2DR = 0x7a; /* send data: address of TFP410 */ - wait_i2c_transfer_finished(); + MCF_I2C_I2DR = 0x7a; /* send data: address of TFP410 */ + wait_i2c_transfer_finished(); - if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) /* next try if no acknowledge */ - continue; + if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) /* next try if no acknowledge */ + continue; - MCF_I2C_I2DR = 0x00; /* send data: SUB ADRESS 0 */ - wait_i2c_transfer_finished(); + MCF_I2C_I2DR = 0x00; /* send data: SUB ADRESS 0 */ + wait_i2c_transfer_finished(); - MCF_I2C_I2CR |= MCF_I2C_I2CR_RSTA; /* repeat start */ - MCF_I2C_I2DR = 0x7b; /* begin read */ + MCF_I2C_I2CR |= MCF_I2C_I2CR_RSTA; /* repeat start */ + MCF_I2C_I2DR = 0x7b; /* begin read */ - wait_i2c_transfer_finished(); - if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) /* next try if no acknowledge */ - continue; + wait_i2c_transfer_finished(); + if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) /* next try if no acknowledge */ + continue; #ifdef _NOT_USED_ - MCH_I2C_I2CR &= ~MCF_I2C_I2CR_MTX; /* FIXME: not clear where this came from ... */ + MCH_I2C_I2CR &= ~MCF_I2C_I2CR_MTX; /* FIXME: not clear where this came from ... */ #endif /* _NOT_USED_ */ - MCF_I2C_I2CR &= 0xef; /* ... this actually disables the I2C module... */ - dummyByte = MCF_I2C_I2DR; /* dummy read */ + MCF_I2C_I2CR &= 0xef; /* ... this actually disables the I2C module... */ + dummyByte = MCF_I2C_I2DR; /* dummy read */ - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2CR |= MCF_I2C_I2CR_TXAK; /* transmit acknowledge enable */ - receivedByte = MCF_I2C_I2DR; /* read a byte */ + MCF_I2C_I2CR |= MCF_I2C_I2CR_TXAK; /* transmit acknowledge enable */ + receivedByte = MCF_I2C_I2DR; /* read a byte */ - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2CR = MCF_I2C_I2CR_IEN; /* stop */ + MCF_I2C_I2CR = MCF_I2C_I2CR_IEN; /* stop */ - dummyByte = MCF_I2C_I2DR; // dummy read + dummyByte = MCF_I2C_I2DR; // dummy read - if (receivedByte != 0x4c) - continue; + if (receivedByte != 0x4c) + continue; - MCF_I2C_I2CR = 0x0; // stop - MCF_I2C_I2SR = 0x0; // clear sr + MCF_I2C_I2CR = 0x0; // stop + MCF_I2C_I2SR = 0x0; // clear sr - waitfor(10000, i2c_bus_free); + waitfor(10000, i2c_bus_free); - MCF_I2C_I2CR = 0xb0; // on tx master - MCF_I2C_I2DR = 0x7A; + MCF_I2C_I2CR = 0xb0; // on tx master + MCF_I2C_I2DR = 0x7A; - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) - continue; + if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) + continue; - MCF_I2C_I2DR = 0x08; // SUB ADRESS 8 + MCF_I2C_I2DR = 0x08; // SUB ADRESS 8 - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2DR = 0xbf; // ctl1: power on, T:M:D:S: enable + MCF_I2C_I2DR = 0xbf; // ctl1: power on, T:M:D:S: enable - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2CR = 0x80; // stop - dummyByte = MCF_I2C_I2DR; // dummy read - MCF_I2C_I2SR = 0x0; // clear sr + MCF_I2C_I2CR = 0x80; // stop + dummyByte = MCF_I2C_I2DR; // dummy read + MCF_I2C_I2SR = 0x0; // clear sr - waitfor(10000, i2c_bus_free); + waitfor(10000, i2c_bus_free); - MCF_I2C_I2CR = 0xb0; - MCF_I2C_I2DR = 0x7A; + MCF_I2C_I2CR = 0xb0; + MCF_I2C_I2DR = 0x7A; - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) - continue; + if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) + continue; - MCF_I2C_I2DR = 0x08; // SUB ADRESS 8 + MCF_I2C_I2DR = 0x08; // SUB ADRESS 8 - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2CR |= 0x4; // repeat start - MCF_I2C_I2DR = 0x7b; // beginn read + MCF_I2C_I2CR |= 0x4; // repeat start + MCF_I2C_I2DR = 0x7b; // beginn read - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) - continue; + if (MCF_I2C_I2SR & MCF_I2C_I2SR_RXAK) + continue; - MCF_I2C_I2CR &= 0xef; // switch to rx - dummyByte = MCF_I2C_I2DR; // dummy read + MCF_I2C_I2CR &= 0xef; // switch to rx + dummyByte = MCF_I2C_I2DR; // dummy read - wait_i2c_transfer_finished(); - MCF_I2C_I2CR |= 0x08; // txak=1 + wait_i2c_transfer_finished(); + MCF_I2C_I2CR |= 0x08; // txak=1 - wait(50); + wait(50); - receivedByte = MCF_I2C_I2DR; + receivedByte = MCF_I2C_I2DR; - wait_i2c_transfer_finished(); + wait_i2c_transfer_finished(); - MCF_I2C_I2CR = 0x80; // stop + MCF_I2C_I2CR = 0x80; // stop - dummyByte = MCF_I2C_I2DR; // dummy read - num_tries++; - } while ((receivedByte != 0xbf) && (num_tries < 10)); + dummyByte = MCF_I2C_I2DR; // dummy read + num_tries++; + } while ((receivedByte != 0xbf) && (num_tries < 10)); - if (num_tries >= 10) { - xprintf("FAILED!\r\n"); - } else { - xprintf("finished\r\n"); - } - UNUSED(dummyByte); - // Avoid warning + if (num_tries >= 10) { + xprintf("FAILED!\r\n"); + } else { + xprintf("finished\r\n"); + } + UNUSED(dummyByte); + // Avoid warning } @@ -932,97 +931,97 @@ void dvi_on(void) * AC97 */ void init_ac97(void) { - // PSC2: AC97 ---------- - int i; - int zm; - int va; - int vb; - int vc; + // PSC2: AC97 ---------- + int i; + int zm; + int va; + int vb; + int vc; - xprintf("AC97 sound chip initialization: "); - MCF_PAD_PAR_PSC2 = MCF_PAD_PAR_PSC2_PAR_RTS2_RTS // PSC2=TX,RX BCLK,CTS->AC'97 - | MCF_PAD_PAR_PSC2_PAR_CTS2_BCLK - | MCF_PAD_PAR_PSC2_PAR_TXD2 - | MCF_PAD_PAR_PSC2_PAR_RXD2; - MCF_PSC2_PSCMR1 = 0x0; - MCF_PSC2_PSCMR2 = 0x0; - MCF_PSC2_PSCIMR = 0x0300; - MCF_PSC2_PSCSICR = 0x03; //AC97 - MCF_PSC2_PSCRFCR = 0x0f000000; - MCF_PSC2_PSCTFCR = 0x0f000000; - MCF_PSC2_PSCRFAR = 0x00F0; - MCF_PSC2_PSCTFAR = 0x00F0; + xprintf("AC97 sound chip initialization: "); + MCF_PAD_PAR_PSC2 = MCF_PAD_PAR_PSC2_PAR_RTS2_RTS // PSC2=TX,RX BCLK,CTS->AC'97 + | MCF_PAD_PAR_PSC2_PAR_CTS2_BCLK + | MCF_PAD_PAR_PSC2_PAR_TXD2 + | MCF_PAD_PAR_PSC2_PAR_RXD2; + MCF_PSC2_PSCMR1 = 0x0; + MCF_PSC2_PSCMR2 = 0x0; + MCF_PSC2_PSCIMR = 0x0300; + MCF_PSC2_PSCSICR = 0x03; //AC97 + MCF_PSC2_PSCRFCR = 0x0f000000; + MCF_PSC2_PSCTFCR = 0x0f000000; + MCF_PSC2_PSCRFAR = 0x00F0; + MCF_PSC2_PSCTFAR = 0x00F0; - for (zm = 0; zm < 100000; zm++) // wiederholen bis synchron - { - MCF_PSC2_PSCCR = 0x20; - MCF_PSC2_PSCCR = 0x30; - MCF_PSC2_PSCCR = 0x40; - MCF_PSC2_PSCCR = 0x05; + for (zm = 0; zm < 100000; zm++) // wiederholen bis synchron + { + MCF_PSC2_PSCCR = 0x20; + MCF_PSC2_PSCCR = 0x30; + MCF_PSC2_PSCCR = 0x40; + MCF_PSC2_PSCCR = 0x05; - // MASTER VOLUME -0dB - MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x02000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 + // MASTER VOLUME -0dB + MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x02000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 - for (i = 2; i < 13; i++) - { - MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 - } + for (i = 2; i < 13; i++) + { + MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 + } - // read register - MCF_PSC2_PSCTB_AC97 = 0xc0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x82000000; //SLOT1:master volume + // read register + MCF_PSC2_PSCTB_AC97 = 0xc0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x82000000; //SLOT1:master volume - for (i = 2; i < 13; i++) - { - MCF_PSC2_PSCTB_AC97 = 0x00000000; //SLOT2-12:RD REG ALLES 0 - } - wait(50); + for (i = 2; i < 13; i++) + { + MCF_PSC2_PSCTB_AC97 = 0x00000000; //SLOT2-12:RD REG ALLES 0 + } + wait(50); - va = MCF_PSC2_PSCTB_AC97; - if ((va & 0x80000fff) == 0x80000800) { - vb = MCF_PSC2_PSCTB_AC97; - vc = MCF_PSC2_PSCTB_AC97; + va = MCF_PSC2_PSCTB_AC97; + if ((va & 0x80000fff) == 0x80000800) { + vb = MCF_PSC2_PSCTB_AC97; + vc = MCF_PSC2_PSCTB_AC97; - /* FIXME: that looks more than suspicious (Fredi?) */ - /* fixed with parentheses to avoid compiler warnings, but this looks still more than wrong to me */ - if (((va & 0xE0000fff) == 0xE0000800) & (vb == 0x02000000) & (vc == 0x00000000)) { - goto livo; - } - } - } - xprintf(" NOT"); + /* FIXME: that looks more than suspicious (Fredi?) */ + /* fixed with parentheses to avoid compiler warnings, but this looks still more than wrong to me */ + if (((va & 0xE0000fff) == 0xE0000800) & (vb == 0x02000000) & (vc == 0x00000000)) { + goto livo; + } + } + } + xprintf(" NOT"); livo: - // AUX VOLUME ->-0dB - MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x16000000; //SLOT1:WR REG AUX VOLUME adr 0x16 - MCF_PSC2_PSCTB_AC97 = 0x06060000; //SLOT1:VOLUME - for (i = 3; i < 13; i++) { - MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 - } + // AUX VOLUME ->-0dB + MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x16000000; //SLOT1:WR REG AUX VOLUME adr 0x16 + MCF_PSC2_PSCTB_AC97 = 0x06060000; //SLOT1:VOLUME + for (i = 3; i < 13; i++) { + MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 + } - // line in VOLUME +12dB - MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x10000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 - for (i = 2; i < 13; i++) { - MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 - } - // cd in VOLUME 0dB - MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x12000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 - for (i = 2; i < 13; i++) { - MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 - } - // mono out VOLUME 0dB - MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME - MCF_PSC2_PSCTB_AC97 = 0x06000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 - MCF_PSC2_PSCTB_AC97 = 0x00000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 - for (i = 3; i < 13; i++) { - MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 - } - MCF_PSC2_PSCTFCR |= MCF_PSC_PSCTFCR_WFR; //set EOF - MCF_PSC2_PSCTB_AC97 = 0x00000000; //last data - xprintf(" finished\r\n"); + // line in VOLUME +12dB + MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x10000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 + for (i = 2; i < 13; i++) { + MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 + } + // cd in VOLUME 0dB + MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x12000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 + for (i = 2; i < 13; i++) { + MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 + } + // mono out VOLUME 0dB + MCF_PSC2_PSCTB_AC97 = 0xE0000000; //START SLOT1 + SLOT2, FIRST FRAME + MCF_PSC2_PSCTB_AC97 = 0x06000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 + MCF_PSC2_PSCTB_AC97 = 0x00000000; //SLOT1:WR REG MASTER VOLUME adr 0x02 + for (i = 3; i < 13; i++) { + MCF_PSC2_PSCTB_AC97 = 0x0; //SLOT2-12:WR REG ALLES 0 + } + MCF_PSC2_PSCTFCR |= MCF_PSC_PSCTFCR_WFR; //set EOF + MCF_PSC2_PSCTB_AC97 = 0x00000000; //last data + xprintf(" finished\r\n"); } /* Symbols from the linker script */ @@ -1053,194 +1052,194 @@ extern uint8_t _BAS_RESIDENT_TEXT_SIZE[]; void clear_bss_segment(void) { - extern uint8_t _BAS_BSS_START[]; - uint8_t * BAS_BSS_START = &_BAS_BSS_START[0]; - extern uint8_t _BAS_BSS_END[]; - uint8_t *BAS_BSS_END = &_BAS_BSS_END[0]; + extern uint8_t _BAS_BSS_START[]; + uint8_t * BAS_BSS_START = &_BAS_BSS_START[0]; + extern uint8_t _BAS_BSS_END[]; + uint8_t *BAS_BSS_END = &_BAS_BSS_END[0]; - bzero(BAS_BSS_START, BAS_BSS_END - BAS_BSS_START - 1); + bzero(BAS_BSS_START, BAS_BSS_END - BAS_BSS_START - 1); } void initialize_hardware(void) { - /* Test for FireTOS switch: DIP switch #5 up */ + /* Test for FireTOS switch: DIP switch #5 up */ #ifdef MACHINE_FIREBEE - if (!(DIP_SWITCH & (1 << 6))) { - /* Minimal hardware initialization */ - init_gpio(); - init_serial(); - init_slt(); - init_fbcs(); - init_ddram(); - init_fpga(); + if (!(DIP_SWITCH & (1 << 6))) { + /* Minimal hardware initialization */ + init_gpio(); + init_serial(); + init_slt(); + init_fbcs(); + init_ddram(); + init_fpga(); - /* Validate ST RAM */ - * (volatile uint32_t *) 0x42e = STRAM_END; /* phystop TOS system variable */ - * (volatile uint32_t *) 0x420 = 0x752019f3; /* memvalid TOS system variable */ - * (volatile uint32_t *) 0x43a = 0x237698aa; /* memval2 TOS system variable */ - * (volatile uint32_t *) 0x51a = 0x5555aaaa; /* memval3 TOS system variable */ + /* Validate ST RAM */ + * (volatile uint32_t *) 0x42e = STRAM_END; /* phystop TOS system variable */ + * (volatile uint32_t *) 0x420 = 0x752019f3; /* memvalid TOS system variable */ + * (volatile uint32_t *) 0x43a = 0x237698aa; /* memval2 TOS system variable */ + * (volatile uint32_t *) 0x51a = 0x5555aaaa; /* memval3 TOS system variable */ - /* TT-RAM */ + /* TT-RAM */ - * (uint32_t *) 0x5a4 = FASTRAM_END; /* ramtop TOS system variable */ - * (uint32_t *) 0x5a8 = 0x1357bd13; /* ramvalid TOS system variable */ + * (uint32_t *) 0x5a4 = FASTRAM_END; /* ramtop TOS system variable */ + * (uint32_t *) 0x5a8 = 0x1357bd13; /* ramvalid TOS system variable */ - /* Jump into FireTOS */ - typedef void void_func(void); - void_func* FireTOS = (void_func*) FIRETOS; - FireTOS(); // Should never return - return; - } + /* Jump into FireTOS */ + typedef void void_func(void); + void_func* FireTOS = (void_func*) FIRETOS; + FireTOS(); // Should never return + return; + } #endif /* MACHINE_FIREBEE */ - init_gpio(); - init_serial(); + init_gpio(); + init_serial(); - xprintf("\n\n"); - xprintf("%s BASIS system (BaS) v %d.%d (%s, %s)\r\n\r\n", + xprintf("\n\n"); + xprintf("%s BASIS system (BaS) v %d.%d (%s, %s)\r\n\r\n", #if MACHINE_FIREBEE - "Firebee" + "Firebee" #elif MACHINE_M5484LITE - "m5484 LITEKIT" + "m5484 LITEKIT" #else - "unknown platform" + "unknown platform" #endif - , MAJOR_VERSION, MINOR_VERSION, __DATE__, __TIME__); + , MAJOR_VERSION, MINOR_VERSION, __DATE__, __TIME__); - extern char *rom_header; + extern char *rom_header; - xprintf("running from %p\r\n\r\n", &rom_header); - /* - * Determine cause(s) of Reset - */ - if (MCF_SIU_RSR & MCF_SIU_RSR_RST) - xprintf("Reset. Cause: External Reset\r\n"); - if (MCF_SIU_RSR & MCF_SIU_RSR_RSTWD) - xprintf("Reset. Cause: Watchdog Timer Reset\n"); - if (MCF_SIU_RSR & MCF_SIU_RSR_RSTJTG) - xprintf("Reset. Cause: BDM/JTAG Reset\r\n"); + xprintf("running from %p\r\n\r\n", &rom_header); + /* + * Determine cause(s) of Reset + */ + if (MCF_SIU_RSR & MCF_SIU_RSR_RST) + xprintf("Reset. Cause: External Reset\r\n"); + if (MCF_SIU_RSR & MCF_SIU_RSR_RSTWD) + xprintf("Reset. Cause: Watchdog Timer Reset\n"); + if (MCF_SIU_RSR & MCF_SIU_RSR_RSTJTG) + xprintf("Reset. Cause: BDM/JTAG Reset\r\n"); - /* - * Clear the Reset Status Register - */ - MCF_SIU_RSR = (MCF_SIU_RSR_RST - | MCF_SIU_RSR_RSTWD - | MCF_SIU_RSR_RSTJTG); + /* + * Clear the Reset Status Register + */ + MCF_SIU_RSR = (MCF_SIU_RSR_RST + | MCF_SIU_RSR_RSTWD + | MCF_SIU_RSR_RSTJTG); - /* - * Determine which processor we are running on - */ - xprintf("JTAGID: "); - switch (MCF_SIU_JTAGID & MCF_SIU_JTAGID_PROCESSOR) - { - case MCF_SIU_JTAGID_MCF5485: - xprintf("MCF5485"); - break; - case MCF_SIU_JTAGID_MCF5484: - xprintf("MCF5484"); - break; - case MCF_SIU_JTAGID_MCF5483: - xprintf("MCF5483"); - break; - case MCF_SIU_JTAGID_MCF5482: - xprintf("MCF5482"); - break; - case MCF_SIU_JTAGID_MCF5481: - xprintf("MCF5481"); - break; - case MCF_SIU_JTAGID_MCF5480: - xprintf("MCF5480"); - break; - case MCF_SIU_JTAGID_MCF5475: - xprintf("MCF5475"); - break; - case MCF_SIU_JTAGID_MCF5474: - xprintf("MCF5474"); - break; - case MCF_SIU_JTAGID_MCF5473: - xprintf("MCF5473"); - break; - case MCF_SIU_JTAGID_MCF5472: - xprintf("MCF5472"); - break; - case MCF_SIU_JTAGID_MCF5471: - xprintf("MCF5471"); - break; - case MCF_SIU_JTAGID_MCF5470: - xprintf("MCF5470"); - break; - } + /* + * Determine which processor we are running on + */ + xprintf("JTAGID: "); + switch (MCF_SIU_JTAGID & MCF_SIU_JTAGID_PROCESSOR) + { + case MCF_SIU_JTAGID_MCF5485: + xprintf("MCF5485"); + break; + case MCF_SIU_JTAGID_MCF5484: + xprintf("MCF5484"); + break; + case MCF_SIU_JTAGID_MCF5483: + xprintf("MCF5483"); + break; + case MCF_SIU_JTAGID_MCF5482: + xprintf("MCF5482"); + break; + case MCF_SIU_JTAGID_MCF5481: + xprintf("MCF5481"); + break; + case MCF_SIU_JTAGID_MCF5480: + xprintf("MCF5480"); + break; + case MCF_SIU_JTAGID_MCF5475: + xprintf("MCF5475"); + break; + case MCF_SIU_JTAGID_MCF5474: + xprintf("MCF5474"); + break; + case MCF_SIU_JTAGID_MCF5473: + xprintf("MCF5473"); + break; + case MCF_SIU_JTAGID_MCF5472: + xprintf("MCF5472"); + break; + case MCF_SIU_JTAGID_MCF5471: + xprintf("MCF5471"); + break; + case MCF_SIU_JTAGID_MCF5470: + xprintf("MCF5470"); + break; + } - /* make sure MMU is disabled */ - MCF_MMU_MMUCR = 0; /* MMU off */ - NOP(); /* force pipeline sync */ + /* make sure MMU is disabled */ + MCF_MMU_MMUCR = 0; /* MMU off */ + NOP(); /* force pipeline sync */ - /* - * Determine the processor revision - */ - xprintf(" (revision %d)\r\n", ((MCF_SIU_JTAGID & MCF_SIU_JTAGID_REV) >> 28)); + /* + * Determine the processor revision + */ + xprintf(" (revision %d)\r\n", ((MCF_SIU_JTAGID & MCF_SIU_JTAGID_REV) >> 28)); - init_slt(); - init_fbcs(); - init_ddram(); + init_slt(); + init_fbcs(); + init_ddram(); - /* - * install (preliminary) exception vectors - */ - setup_vectors(); + /* + * install (preliminary) exception vectors + */ + setup_vectors(); - /* - * save the planet (and reduce case heat): disable clocks of unused SOC modules - */ - MCF_CLOCK_SPCR = 0xffffffff & ~( - 0 | /* leave memory clock enabled */ - 0 | /* leave PCI clock enabled */ - 0 | /* leave FlexBus clock enabled */ - MCF_CLOCK_SPCR_CAN0EN | /* disable CAN0 */ - 0 | /* leave DMA clock enabled */ - 0 | /* leave FEC0 clock enabled */ - MCF_CLOCK_SPCR_FEC1EN | /* disable FEC1 */ - MCF_CLOCK_SPCR_USBEN | /* disable USB slave */ - 0 | /* leave PSC clock enabled */ - MCF_CLOCK_SPCR_CAN1EN | /* disable CAN1 */ - MCF_CLOCK_SPCR_CRYENA | /* disable crypto clock A */ - MCF_CLOCK_SPCR_CRYENB | /* disable crypto clock B */ - 0 /* leave core clock enabled */ - ); + /* + * save the planet (and reduce case heat): disable clocks of unused SOC modules + */ + MCF_CLOCK_SPCR = 0xffffffff & ~( + 0 | /* leave memory clock enabled */ + 0 | /* leave PCI clock enabled */ + 0 | /* leave FlexBus clock enabled */ + MCF_CLOCK_SPCR_CAN0EN | /* disable CAN0 */ + 0 | /* leave DMA clock enabled */ + 0 | /* leave FEC0 clock enabled */ + MCF_CLOCK_SPCR_FEC1EN | /* disable FEC1 */ + MCF_CLOCK_SPCR_USBEN | /* disable USB slave */ + 0 | /* leave PSC clock enabled */ + MCF_CLOCK_SPCR_CAN1EN | /* disable CAN1 */ + MCF_CLOCK_SPCR_CRYENA | /* disable crypto clock A */ + MCF_CLOCK_SPCR_CRYENB | /* disable crypto clock B */ + 0 /* leave core clock enabled */ + ); - /* the following only makes sense _after_ DDRAM has been initialized */ - clear_bss_segment(); - xprintf(".bss segment cleared\r\n"); + /* the following only makes sense _after_ DDRAM has been initialized */ + clear_bss_segment(); + xprintf(".bss segment cleared\r\n"); - if (BAS_LMA != BAS_IN_RAM) - { - memcpy((void *) BAS_IN_RAM, BAS_LMA, BAS_SIZE); + if (BAS_LMA != BAS_IN_RAM) + { + memcpy((void *) BAS_IN_RAM, BAS_LMA, BAS_SIZE); - /* we have copied a code area, so flush the caches */ - flush_and_invalidate_caches(); + /* we have copied a code area, so flush the caches */ + flush_and_invalidate_caches(); - } + } #if MACHINE_FIREBEE - fpga_configured = init_fpga(); + fpga_configured = init_fpga(); - init_pll(); - init_video_ddr(); - dvi_on(); + init_pll(); + init_video_ddr(); + dvi_on(); #endif /* MACHINE_FIREBEE */ - driver_mem_init(); - init_pci(); - video_init(); + driver_mem_init(); + init_pci(); + video_init(); - /* initialize USB devices */ - init_usb(); + /* initialize USB devices */ + init_usb(); #if MACHINE_FIREBEE - init_ac97(); + init_ac97(); #endif /* MACHINE_FIREBEE */ - dma_init(); + dma_init(); - /* jump into the BaS */ - extern void BaS(void); - BaS(); + /* jump into the BaS */ + extern void BaS(void); + BaS(); } diff --git a/BaS_gcc/usb/usb.c b/BaS_gcc/usb/usb.c index 7f47b58..a591872 100644 --- a/BaS_gcc/usb/usb.c +++ b/BaS_gcc/usb/usb.c @@ -54,20 +54,21 @@ #include "usb.h" #include "usb_hub.h" -//#define DEBUG_USB +#define DEBUG_USB #ifdef DEBUG_USB #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #else #define dbg(format, arg...) do { ; } while (0) #endif /* DEBUG_USB */ #define err(format, arg...) do { xprintf("ERROR: %s(): " format, __FUNCTION__, ##arg); } while (0) +#define info(format, arg...) do { xprintf("INFO: %s(): " format, __FUNCTION__, ##arg); } while (0) struct hci { - /* ------- common part -------- */ - long handle; /* PCI BIOS */ - const struct pci_device_id *ent; - int usbnum; + /* ------- common part -------- */ + long handle; /* PCI BIOS */ + const struct pci_device_id *ent; + int usbnum; /* ---- end of common part ---- */ }; @@ -91,124 +92,126 @@ void usb_scan_devices(void *priv); */ int usb_init(int32_t handle, const struct pci_device_id *ent) { - struct hci *priv; - int res = 0; - if (bus_index >= USB_MAX_BUS) + struct hci *priv; + int res = 0; + + bus_index = 0; + if (bus_index >= USB_MAX_BUS) { dbg("bus_index >= USB_MAX_BUS"); return -1; } - dev_index[bus_index] = 0; - asynch_allowed = 1; + dev_index[bus_index] = 0; + asynch_allowed = 1; - if (handle && (ent != NULL)) - { - if (driver_mem_init()) - { - usb_started = 0; + if (handle && (ent != NULL)) + { + if (driver_mem_init()) + { + usb_started = 0; dbg("driver_mem_init failed\r\n"); - return -1; /* out of memory */ - } - - if (usb_dev == NULL) - { - usb_dev = (struct usb_device *) driver_mem_alloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); + return -1; /* out of memory */ } - if (usb_dev == NULL) - { - usb_started = 0; + if (usb_dev == NULL) + { + usb_dev = (struct usb_device *) driver_mem_alloc(sizeof(struct usb_device) * USB_MAX_BUS * USB_MAX_DEVICE); + } + + if (usb_dev == NULL) + { + usb_started = 0; dbg("could not allocate memory\r\n"); - return -1; /* out of memory */ - } - } - else /* restart */ - { - int i; + return -1; /* out of memory */ + } + } + else /* restart */ + { + int i; - res = 0; - for (i = 0; i < USB_MAX_BUS; i++) - { - if (controller_priv[i] != NULL) - { - long handle = controller_priv[i]->handle; + res = 0; + for (i = 0; i < USB_MAX_BUS; i++) + { + if (controller_priv[i] != NULL) + { + long handle = controller_priv[i]->handle; - if (handle) - { + if (handle) + { res |= usb_init(handle, NULL); /* FIXME: recursive call!? */ - } - } - } - return res; - } + } + } + } + return res; + } - usb_hub_reset(bus_index); + usb_hub_reset(bus_index); - /* init low_level USB */ + /* init low_level USB */ - switch(ent->class) - { - case PCI_CLASS_SERIAL_USB_UHCI: - //res = uhci_usb_lowlevel_init(handle, ent, &priv); - dbg("sorry, no uhci driver available\r\n"); - break; + switch(ent->class) + { + case PCI_CLASS_SERIAL_USB_UHCI: + //res = uhci_usb_lowlevel_init(handle, ent, &priv); + dbg("sorry, no uhci driver available\r\n"); + break; - case PCI_CLASS_SERIAL_USB_OHCI: - dbg("initialize ohci host controller interface\r\n"); - res = ohci_usb_lowlevel_init(handle, ent, (void *) &priv); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + dbg("initialize ohci host controller interface\r\n"); + res = ohci_usb_lowlevel_init(handle, ent, (void *) &priv); + break; - case PCI_CLASS_SERIAL_USB_EHCI: - dbg("initialize ehci host controller interface\r\n"); - res = ehci_usb_lowlevel_init(handle, ent, (void *) &priv); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + dbg("initialize ehci host controller interface\r\n"); + res = ehci_usb_lowlevel_init(handle, ent, (void *) &priv); + break; - default: - res = -1; - break; - } + default: + res = -1; + break; + } - if (!res) - { - /* - * if lowlevel init is OK, scan the bus for devices - * i.e. search HUBs and configure them - */ - if (setup_packet == NULL) - { - setup_packet = driver_mem_alloc(sizeof(struct devrequest)); - if (setup_packet == NULL) - { - usb_started = 0; + if (!res) + { + /* + * if lowlevel init is OK, scan the bus for devices + * i.e. search HUBs and configure them + */ + if (setup_packet == NULL) + { + setup_packet = driver_mem_alloc(sizeof(struct devrequest)); + if (setup_packet == NULL) + { + usb_started = 0; dbg("could not allocate memory\r\n"); - return -1; /* no memory, no USB */ - } - } + return -1; /* no memory, no USB */ + } + } - xprintf("Scanning bus for devices... "); + xprintf("Scanning bus for devices... "); - controller_priv[bus_index] = priv; - controller_priv[bus_index]->usbnum = bus_index; + controller_priv[bus_index] = priv; + controller_priv[bus_index]->usbnum = bus_index; - usb_scan_devices(priv); - bus_index++; - usb_started = 1; + usb_scan_devices(priv); + bus_index++; + usb_started = 1; - return 0; - } - else - { - xprintf("\r\nError, couldn't init Lowlevel part\r\n"); - usb_started = 0; + return 0; + } + else + { + xprintf("\r\nError, couldn't init Lowlevel part\r\n"); + usb_started = 0; - return -1; - } + return -1; + } } /* @@ -216,51 +219,51 @@ int usb_init(int32_t handle, const struct pci_device_id *ent) */ int usb_stop(void) { - int i; - int res = 0; + int i; + int res = 0; - if (usb_started) - { - asynch_allowed = 1; - usb_started = 0; - usb_hub_reset(bus_index); - driver_mem_free(setup_packet); - for (i = 0; i < USB_MAX_BUS; i++) - { - struct hci *priv = controller_priv[i]; - if (priv != NULL) - { - switch(priv->ent->class) - { + if (usb_started) + { + asynch_allowed = 1; + usb_started = 0; + usb_hub_reset(bus_index); + driver_mem_free(setup_packet); + for (i = 0; i < USB_MAX_BUS; i++) + { + struct hci *priv = controller_priv[i]; + if (priv != NULL) + { + switch(priv->ent->class) + { #ifdef CONFIG_USB_UHCI - case PCI_CLASS_SERIAL_USB_UHCI: - res |= uhci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_UHCI: + res |= uhci_usb_lowlevel_stop(priv); + break; #endif #ifdef CONFIG_USB_OHCI - case PCI_CLASS_SERIAL_USB_OHCI: - res |= ohci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_OHCI: + res |= ohci_usb_lowlevel_stop(priv); + break; #endif #ifdef CONFIG_USB_EHCI - case PCI_CLASS_SERIAL_USB_EHCI: - res |= ehci_usb_lowlevel_stop(priv); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + res |= ehci_usb_lowlevel_stop(priv); + break; #endif - } - } - } - bus_index = 0; - driver_mem_release(); /* release all driver mem */ - } - return res; + } + } + } + bus_index = 0; + driver_mem_release(); /* release all driver mem */ + } + return res; } void usb_enable_interrupt(int enable) { - ohci_usb_enable_interrupt(enable); - ehci_usb_enable_interrupt(enable); + ohci_usb_enable_interrupt(enable); + ehci_usb_enable_interrupt(enable); } @@ -270,7 +273,7 @@ void usb_enable_interrupt(int enable) */ void usb_disable_asynch(int disable) { - asynch_allowed = !disable; + asynch_allowed = !disable; } /* @@ -283,24 +286,24 @@ void usb_disable_asynch(int disable) */ int usb_submit_int_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int transfer_len, int interval) { - struct hci *priv = (struct hci *) dev->priv_hcd; - int ret = 0; + struct hci *priv = (struct hci *) dev->priv_hcd; + int ret = 0; - switch(priv->ent->class) - { - case PCI_CLASS_SERIAL_USB_OHCI: - ret = ohci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); - break; + switch(priv->ent->class) + { + case PCI_CLASS_SERIAL_USB_OHCI: + ret = ohci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); + break; - case PCI_CLASS_SERIAL_USB_EHCI: - ret = ehci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + ret = ehci_submit_int_msg(dev, pipe, buffer, transfer_len, interval); + break; - default: - ret = -1; - break; - } - return ret; + default: + ret = -1; + break; + } + return ret; } /* @@ -313,59 +316,59 @@ int usb_submit_int_msg(struct usb_device *dev, uint32_t pipe, void *buffer, int * and the current status are stored in the dev->act_len and dev->status. */ int usb_control_msg(struct usb_device *dev, unsigned int pipe, - unsigned char request, unsigned char requesttype, - unsigned short value, unsigned short index, - void *data, unsigned short size, int timeout) + unsigned char request, unsigned char requesttype, + unsigned short value, unsigned short index, + void *data, unsigned short size, int timeout) { struct hci *priv = (struct hci *) dev->priv_hcd; - if ((timeout == 0) && (!asynch_allowed)) - { - /* request for a asynch control pipe is not allowed */ + if ((timeout == 0) && (!asynch_allowed)) + { + /* request for a asynch control pipe is not allowed */ dbg("request for an async control pipe is not allowed\r\n"); - return -1; - } + return -1; + } - /* set setup command */ - setup_packet->requesttype = requesttype; - setup_packet->request = request; - setup_packet->value = swpw(value); - setup_packet->index = swpw(index); - setup_packet->length = swpw(size); + /* set setup command */ + setup_packet->requesttype = requesttype; + setup_packet->request = request; + setup_packet->value = swpw(value); + setup_packet->index = swpw(index); + setup_packet->length = swpw(size); - dbg("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\r\n", request, requesttype, value, index, size); + dbg("usb_control_msg: request: 0x%X, requesttype: 0x%X, value 0x%X index 0x%X length 0x%X\r\n", request, requesttype, value, index, size); - switch(priv->ent->class) - { - case PCI_CLASS_SERIAL_USB_OHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ohci_submit_control_msg(dev, pipe, data, size, setup_packet); - break; + switch(priv->ent->class) + { + case PCI_CLASS_SERIAL_USB_OHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ohci_submit_control_msg(dev, pipe, data, size, setup_packet); + break; - case PCI_CLASS_SERIAL_USB_EHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ehci_submit_control_msg(dev, pipe, data, size, setup_packet); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ehci_submit_control_msg(dev, pipe, data, size, setup_packet); + break; - default: - return -1; - } + default: + return -1; + } - if (timeout == 0) - { - return (int) size; - } + if (timeout == 0) + { + return (int) size; + } - if (dev->status != 0) - { - /* - * Let's wait a while for the timeout to elapse. - * It has no real use, but it keeps the interface happy. - */ - return -1; - } - return dev->act_len; + if (dev->status != 0) + { + /* + * Let's wait a while for the timeout to elapse. + * It has no real use, but it keeps the interface happy. + */ + return -1; + } + return dev->act_len; } /* @@ -375,46 +378,46 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe, */ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, int *actual_length, int timeout) { - struct hci *priv = (struct hci *) dev->priv_hcd; + struct hci *priv = (struct hci *) dev->priv_hcd; - if (len < 0) - { - return -1; - } + if (len < 0) + { + return -1; + } - switch(priv->ent->class) - { - case PCI_CLASS_SERIAL_USB_OHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ohci_submit_bulk_msg(dev, pipe, data, len); - break; + switch(priv->ent->class) + { + case PCI_CLASS_SERIAL_USB_OHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ohci_submit_bulk_msg(dev, pipe, data, len); + break; - case PCI_CLASS_SERIAL_USB_EHCI: - dev->status = USB_ST_NOT_PROC; /* not yet processed */ - ehci_submit_bulk_msg(dev, pipe, data, len); - break; + case PCI_CLASS_SERIAL_USB_EHCI: + dev->status = USB_ST_NOT_PROC; /* not yet processed */ + ehci_submit_bulk_msg(dev, pipe, data, len); + break; - default: - return -1; - } + default: + return -1; + } - while (timeout--) - { - if (!((volatile uint32_t) dev->status & USB_ST_NOT_PROC)) /* FIXME: this volatile does nothing! */ - break; - wait(1 * 1000); - } + while (timeout--) + { + if (!((volatile uint32_t) dev->status & USB_ST_NOT_PROC)) /* FIXME: this volatile does nothing! */ + break; + wait(1); + } - *actual_length = dev->act_len; + *actual_length = dev->act_len; - if (dev->status == 0) - { - return 0; - } - else - { - return -1; - } + if (dev->status == 0) + { + return 0; + } + else + { + return -1; + } } @@ -428,15 +431,15 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe, void *data, int len, */ int usb_maxpacket(struct usb_device *dev, uint32_t pipe) { - /* direction is out -> use emaxpacket out */ - if ((pipe & USB_DIR_IN) == 0) - { - return dev->epmaxpacketout[((pipe >> 15) & 0xf)]; - } - else - { - return dev->epmaxpacketin[((pipe >> 15) & 0xf)]; - } + /* direction is out -> use emaxpacket out */ + if ((pipe & USB_DIR_IN) == 0) + { + return dev->epmaxpacketout[((pipe >> 15) & 0xf)]; + } + else + { + return dev->epmaxpacketin[((pipe >> 15) & 0xf)]; + } } /* @@ -452,38 +455,38 @@ int usb_maxpacket(struct usb_device *dev, uint32_t pipe) */ static void usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_descriptor *ep) { - int b; + int b; - b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; + b = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; - if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL) - { - /* Control => bidirectional */ - dev->epmaxpacketout[b] = ep->wMaxPacketSize; - dev->epmaxpacketin[b] = ep->wMaxPacketSize; - dbg("##Control EP epmaxpacketout/in[%d] = %d\r\n", b, dev->epmaxpacketin[b]); - } - else - { - if ((ep->bEndpointAddress & 0x80) == 0) - { - /* OUT Endpoint */ - if (ep->wMaxPacketSize > dev->epmaxpacketout[b]) - { - dev->epmaxpacketout[b] = ep->wMaxPacketSize; - dbg("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]); - } - } - else - { - /* IN Endpoint */ - if (ep->wMaxPacketSize > dev->epmaxpacketin[b]) - { - dev->epmaxpacketin[b] = ep->wMaxPacketSize; - dbg("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]); - } - } /* if out */ - } /* if control */ + if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_CONTROL) + { + /* Control => bidirectional */ + dev->epmaxpacketout[b] = ep->wMaxPacketSize; + dev->epmaxpacketin[b] = ep->wMaxPacketSize; + dbg("##Control EP epmaxpacketout/in[%d] = %d\r\n", b, dev->epmaxpacketin[b]); + } + else + { + if ((ep->bEndpointAddress & 0x80) == 0) + { + /* OUT Endpoint */ + if (ep->wMaxPacketSize > dev->epmaxpacketout[b]) + { + dev->epmaxpacketout[b] = ep->wMaxPacketSize; + dbg("##EP epmaxpacketout[%d] = %d\r\n", b, dev->epmaxpacketout[b]); + } + } + else + { + /* IN Endpoint */ + if (ep->wMaxPacketSize > dev->epmaxpacketin[b]) + { + dev->epmaxpacketin[b] = ep->wMaxPacketSize; + dbg("##EP epmaxpacketin[%d] = %d\r\n", b, dev->epmaxpacketin[b]); + } + } /* if out */ + } /* if control */ } /* @@ -491,17 +494,17 @@ static void usb_set_maxpacket_ep(struct usb_device *dev, struct usb_endpoint_des */ int usb_set_maxpacket(struct usb_device *dev) { - int i; - int ii; + int i; + int ii; - for (i = 0; i < dev->config.bNumInterfaces; i++) - { - for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++) - { - usb_set_maxpacket_ep(dev,&dev->config.if_desc[i].ep_desc[ii]); - } - } - return 0; + for (i = 0; i < dev->config.bNumInterfaces; i++) + { + for (ii = 0; ii < dev->config.if_desc[i].bNumEndpoints; ii++) + { + usb_set_maxpacket_ep(dev,&dev->config.if_desc[i].ep_desc[ii]); + } + } + return 0; } /* @@ -510,88 +513,88 @@ int usb_set_maxpacket(struct usb_device *dev) */ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno) { - struct usb_descriptor_header *head; - int index; - int ifno; - int epno; - int curr_if_num; + struct usb_descriptor_header *head; + int index; + int ifno; + int epno; + int curr_if_num; - ifno = -1; - epno = -1; - curr_if_num = -1; - dev->configno = cfgno; - head = (struct usb_descriptor_header *) &buffer[0]; + ifno = -1; + epno = -1; + curr_if_num = -1; + dev->configno = cfgno; + head = (struct usb_descriptor_header *) &buffer[0]; - if (head->bDescriptorType != USB_DT_CONFIG) - { - dbg(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType); - return -1; - } - memcpy(&dev->config, buffer, buffer[0]); - dev->config.wTotalLength = swpw(dev->config.wTotalLength); - dev->config.no_of_if = 0; - index = dev->config.bLength; + if (head->bDescriptorType != USB_DT_CONFIG) + { + dbg(" ERROR: NOT USB_CONFIG_DESC %x\r\n", head->bDescriptorType); + return -1; + } + memcpy(&dev->config, buffer, buffer[0]); + dev->config.wTotalLength = swpw(dev->config.wTotalLength); + dev->config.no_of_if = 0; + index = dev->config.bLength; - /* - * Ok the first entry must be a configuration entry, - * now process the others - */ - head = (struct usb_descriptor_header *) &buffer[index]; + /* + * Ok the first entry must be a configuration entry, + * now process the others + */ + head = (struct usb_descriptor_header *) &buffer[index]; - while (index + 1 < dev->config.wTotalLength) - { - switch (head->bDescriptorType) - { - case USB_DT_INTERFACE: - if (((struct usb_interface_descriptor *) &buffer[index])->bInterfaceNumber != curr_if_num) - { - /* this is a new interface, copy new desc */ - ifno = dev->config.no_of_if; - dev->config.no_of_if++; - memcpy(&dev->config.if_desc[ifno], &buffer[index], buffer[index]); - dev->config.if_desc[ifno].no_of_ep = 0; - dev->config.if_desc[ifno].num_altsetting = 1; - curr_if_num = dev->config.if_desc[ifno].bInterfaceNumber; - } - else - { - /* found alternate setting for the interface */ - dev->config.if_desc[ifno].num_altsetting++; - } - break; + while (index + 1 < dev->config.wTotalLength) + { + switch (head->bDescriptorType) + { + case USB_DT_INTERFACE: + if (((struct usb_interface_descriptor *) &buffer[index])->bInterfaceNumber != curr_if_num) + { + /* this is a new interface, copy new desc */ + ifno = dev->config.no_of_if; + dev->config.no_of_if++; + memcpy(&dev->config.if_desc[ifno], &buffer[index], buffer[index]); + dev->config.if_desc[ifno].no_of_ep = 0; + dev->config.if_desc[ifno].num_altsetting = 1; + curr_if_num = dev->config.if_desc[ifno].bInterfaceNumber; + } + else + { + /* found alternate setting for the interface */ + dev->config.if_desc[ifno].num_altsetting++; + } + break; - case USB_DT_ENDPOINT: - epno = dev->config.if_desc[ifno].no_of_ep; - /* found an endpoint */ - dev->config.if_desc[ifno].no_of_ep++; - memcpy(&dev->config.if_desc[ifno].ep_desc[epno], &buffer[index], buffer[index]); - dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize = swpw(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize); - dbg("if %d, ep %d\r\n", ifno, epno); - break; + case USB_DT_ENDPOINT: + epno = dev->config.if_desc[ifno].no_of_ep; + /* found an endpoint */ + dev->config.if_desc[ifno].no_of_ep++; + memcpy(&dev->config.if_desc[ifno].ep_desc[epno], &buffer[index], buffer[index]); + dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize = swpw(dev->config.if_desc[ifno].ep_desc[epno].wMaxPacketSize); + dbg("if %d, ep %d\r\n", ifno, epno); + break; - default: - if (head->bLength == 0) - return 1; - dbg("unknown Descriptor Type : %x\r\n", head->bDescriptorType); + default: + if (head->bLength == 0) + return 1; + dbg("unknown Descriptor Type : %x\r\n", head->bDescriptorType); #ifdef USB_DEBUG - { - unsigned char *ch; - int i; + { + unsigned char *ch; + int i; - ch = (unsigned char *) head; - for (i = 0; i < head->bLength; i++) - { - dbg(" %02X", *ch++); - } - dbg("\r\n"); - } + ch = (unsigned char *) head; + for (i = 0; i < head->bLength; i++) + { + dbg(" %02X", *ch++); + } + dbg("\r\n"); + } #endif /* USB_DEBUG */ - break; - } - index += head->bLength; - head = (struct usb_descriptor_header *) &buffer[index]; - } - return 1; + break; + } + index += head->bLength; + head = (struct usb_descriptor_header *) &buffer[index]; + } + return 1; } /* @@ -601,28 +604,28 @@ int usb_parse_config(struct usb_device *dev, unsigned char *buffer, int cfgno) */ int usb_clear_halt(struct usb_device *dev, int pipe) { - int result; - int endp = usb_pipeendpoint(pipe) | (usb_pipein(pipe) << 7); + int result; + int endp = usb_pipeendpoint(pipe) | (usb_pipein(pipe) << 7); - result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL, 0, USB_CNTL_TIMEOUT * 3); + result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0, endp, NULL, 0, USB_CNTL_TIMEOUT * 3); - /* don't clear if failed */ - if (result < 0) - { - return result; - } + /* don't clear if failed */ + if (result < 0) + { + return result; + } - /* - * NOTE: we do not get status and verify reset was successful - * as some devices are reported to lock up upon this check.. - */ - usb_endpoint_running(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); + /* + * NOTE: we do not get status and verify reset was successful + * as some devices are reported to lock up upon this check.. + */ + usb_endpoint_running(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)); - /* toggle is reset on clear */ - usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0); + /* toggle is reset on clear */ + usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0); - return 0; + return 0; } /* @@ -630,11 +633,11 @@ int usb_clear_halt(struct usb_device *dev, int pipe) */ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) { - int res; + int res; - res = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, (type << 8) + index, 0, buf, size, USB_CNTL_TIMEOUT); - return res; + res = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, (type << 8) + index, 0, buf, size, USB_CNTL_TIMEOUT); + return res; } /* @@ -642,37 +645,37 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char */ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int cfgno) { - int result; - unsigned int tmp; - struct usb_config_descriptor *config; + int result; + unsigned int tmp; + struct usb_config_descriptor *config; - config = (struct usb_config_descriptor *) &buffer[0]; - result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9); + config = (struct usb_config_descriptor *) &buffer[0]; + result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9); - if (result < 9) - { - if (result < 0) - { - dbg("unable to get descriptor, error %lX\r\n", dev->status); - } - else - { - dbg("config descriptor too short (expected %i, got %i)\n", 9, result); - } - return -1; - } + if (result < 9) + { + if (result < 0) + { + dbg("unable to get descriptor, error %lX\r\n", dev->status); + } + else + { + dbg("config descriptor too short (expected %i, got %i)\n", 9, result); + } + return -1; + } - tmp = swpw(config->wTotalLength); + tmp = swpw(config->wTotalLength); - if (tmp > USB_BUFSIZ) - { - dbg("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp); - return -1; - } - result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp); - dbg("get_conf_no %d Result %d, wLength %d\r\n", cfgno, result, tmp); + if (tmp > USB_BUFSIZ) + { + dbg("usb_get_configuration_no: failed to get descriptor - too long: %d\r\n", tmp); + return -1; + } + result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, tmp); + dbg("get_conf_no %d Result %d, wLength %d\r\n", cfgno, result, tmp); - return result; + return result; } /* @@ -681,11 +684,11 @@ int usb_get_configuration_no(struct usb_device *dev, unsigned char *buffer, int */ int usb_set_address(struct usb_device *dev) { - int res; + int res; - dbg("set address %d\r\n", dev->devnum); - res = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS, 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT); - return res; + dbg("set address %d\r\n", dev->devnum); + res = usb_control_msg(dev, usb_snddefctrl(dev), USB_REQ_SET_ADDRESS, 0, (dev->devnum), 0, NULL, 0, USB_CNTL_TIMEOUT); + return res; } /* @@ -693,46 +696,46 @@ int usb_set_address(struct usb_device *dev) */ int usb_set_interface(struct usb_device *dev, int interface, int alternate) { - struct usb_interface_descriptor *if_face = NULL; - int ret, i; + struct usb_interface_descriptor *if_face = NULL; + int ret, i; - for (i = 0; i < dev->config.bNumInterfaces; i++) - { - if (dev->config.if_desc[i].bInterfaceNumber == interface) - { - if_face = &dev->config.if_desc[i]; + for (i = 0; i < dev->config.bNumInterfaces; i++) + { + if (dev->config.if_desc[i].bInterfaceNumber == interface) + { + if_face = &dev->config.if_desc[i]; - break; - } - } + break; + } + } - if (!if_face) - { - dbg("selecting invalid interface %d", interface); + if (!if_face) + { + dbg("selecting invalid interface %d", interface); - return -1; - } + return -1; + } - /* - * We should return now for devices with only one alternate setting. - * According to 9.4.10 of the Universal Serial Bus Specification - * Revision 2.0 such devices can return with a STALL. This results in - * some USB sticks timeouting during initialization and then being - * unusable in U-Boot. - */ - if (if_face->num_altsetting == 1) - { - return 0; - } + /* + * We should return now for devices with only one alternate setting. + * According to 9.4.10 of the Universal Serial Bus Specification + * Revision 2.0 such devices can return with a STALL. This results in + * some USB sticks timeouting during initialization and then being + * unusable in U-Boot. + */ + if (if_face->num_altsetting == 1) + { + return 0; + } - ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate, interface, NULL, 0, USB_CNTL_TIMEOUT * 5); - if (ret < 0) - { - return ret; - } + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, alternate, interface, NULL, 0, USB_CNTL_TIMEOUT * 5); + if (ret < 0) + { + return ret; + } - return 0; + return 0; } /* @@ -740,23 +743,23 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate) */ int usb_set_configuration(struct usb_device *dev, int configuration) { - int res; + int res; - dbg("set configuration %d\r\n", configuration); - /* set setup command */ - res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CNTL_TIMEOUT); - if (res == 0) - { - dev->toggle[0] = 0; - dev->toggle[1] = 0; + dbg("set configuration %d\r\n", configuration); + /* set setup command */ + res = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_CONFIGURATION, 0, configuration, 0, NULL, 0, USB_CNTL_TIMEOUT); + if (res == 0) + { + dev->toggle[0] = 0; + dev->toggle[1] = 0; - return 0; - } - else - { - return -1; - } + return 0; + } + else + { + return -1; + } } /* @@ -764,9 +767,9 @@ int usb_set_configuration(struct usb_device *dev, int configuration) */ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_PROTOCOL, USB_TYPE_CLASS | USB_RECIP_INTERFACE, - protocol, ifnum, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_PROTOCOL, USB_TYPE_CLASS | USB_RECIP_INTERFACE, + protocol, ifnum, NULL, 0, USB_CNTL_TIMEOUT); } /* @@ -774,31 +777,31 @@ int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol) */ int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, - (duration << 8) | report_id, ifnum, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_IDLE, USB_TYPE_CLASS | USB_RECIP_INTERFACE, + (duration << 8) | report_id, ifnum, NULL, 0, USB_CNTL_TIMEOUT); } /* * get report */ int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type, - unsigned char id, void *buf, int size) + unsigned char id, void *buf, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_REPORT, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, - (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_REPORT, USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE, + (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); } /* * get class descriptor */ int usb_get_class_descriptor(struct usb_device *dev, int ifnum, - unsigned char type, unsigned char id, void *buf, int size) + unsigned char type, unsigned char id, void *buf, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, - (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_DESCRIPTOR, USB_RECIP_INTERFACE | USB_DIR_IN, + (type << 8) + id, ifnum, buf, size, USB_CNTL_TIMEOUT); } /* @@ -806,86 +809,86 @@ int usb_get_class_descriptor(struct usb_device *dev, int ifnum, */ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char index, void *buf, int size) { - int i; - int result; + int i; + int result; - for (i = 0; i < 3; ++i) - { - /* some devices are flaky */ - result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, - (USB_DT_STRING << 8) + index, langid, buf, size, USB_CNTL_TIMEOUT); - if (result > 0) - { - break; - } - } - return result; + for (i = 0; i < 3; ++i) + { + /* some devices are flaky */ + result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), USB_REQ_GET_DESCRIPTOR, USB_DIR_IN, + (USB_DT_STRING << 8) + index, langid, buf, size, USB_CNTL_TIMEOUT); + if (result > 0) + { + break; + } + } + return result; } static void usb_try_string_workarounds(unsigned char *buf, int *length) { - int newlength; - int oldlength = *length; + int newlength; + int oldlength = *length; - for (newlength = 2; newlength + 1 < oldlength; newlength += 2) - { - char c = buf[newlength]; + for (newlength = 2; newlength + 1 < oldlength; newlength += 2) + { + char c = buf[newlength]; - if ((c < ' ') || (c >= 127) || buf[newlength + 1]) - break; - } + if ((c < ' ') || (c >= 127) || buf[newlength + 1]) + break; + } - if (newlength > 2) - { - buf[0] = newlength; - *length = newlength; - } + if (newlength > 2) + { + buf[0] = newlength; + *length = newlength; + } } static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned int index, unsigned char *buf) { - int rc; + int rc; - /* - * Try to read the string descriptor by asking for the maximum - * possible number of bytes - */ - rc = usb_get_string(dev, langid, index, buf, 255); + /* + * Try to read the string descriptor by asking for the maximum + * possible number of bytes + */ + rc = usb_get_string(dev, langid, index, buf, 255); - /* - * If that failed try to read the descriptor length, then - * ask for just that many bytes - */ - if (rc < 2) - { - rc = usb_get_string(dev, langid, index, buf, 2); - if (rc == 2) - { - rc = usb_get_string(dev, langid, index, buf, buf[0]); - } - } + /* + * If that failed try to read the descriptor length, then + * ask for just that many bytes + */ + if (rc < 2) + { + rc = usb_get_string(dev, langid, index, buf, 2); + if (rc == 2) + { + rc = usb_get_string(dev, langid, index, buf, buf[0]); + } + } - if (rc >= 2) - { - if (!buf[0] && !buf[1]) - { - usb_try_string_workarounds(buf, &rc); - } + if (rc >= 2) + { + if (!buf[0] && !buf[1]) + { + usb_try_string_workarounds(buf, &rc); + } - /* There might be extra junk at the end of the descriptor */ - if (buf[0] < rc) - { - rc = buf[0]; - } - rc = rc - (rc & 1); /* force a multiple of two */ - } + /* There might be extra junk at the end of the descriptor */ + if (buf[0] < rc) + { + rc = buf[0]; + } + rc = rc - (rc & 1); /* force a multiple of two */ + } - if (rc < 2) - { - rc = -1; - } + if (rc < 2) + { + rc = -1; + } - return rc; + return rc; } /* @@ -895,75 +898,75 @@ static int usb_string_sub(struct usb_device *dev, unsigned int langid, unsigned */ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) { - unsigned char *tbuf; - int err; - unsigned int u, idx; + unsigned char *tbuf; + int err; + unsigned int u, idx; - if (size <= 0 || !buf || !index) - { - return -1; - } + if (size <= 0 || !buf || !index) + { + return -1; + } - buf[0] = 0; - tbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); + buf[0] = 0; + tbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); - if (tbuf == NULL) - { - dbg("usb_string: malloc failure\r\n"); - return -1; - } + if (tbuf == NULL) + { + dbg("usb_string: malloc failure\r\n"); + return -1; + } - /* get langid for strings if it's not yet known */ - if (!dev->have_langid) - { - err = usb_string_sub(dev, 0, 0, tbuf); - if (err < 0) - { - dbg("error getting string descriptor 0 (error=%lx)\r\n", dev->status); - driver_mem_free(tbuf); - return -1; - } - else if (tbuf[0] < 4) - { - dbg("string descriptor 0 too short\r\n"); - driver_mem_free(tbuf); - return -1; - } - else - { - dev->have_langid = -1; - dev->string_langid = tbuf[2] | (tbuf[3] << 8); - /* always use the first langid listed */ - dbg("USB device number %d default language ID 0x%x\r\n", dev->devnum, dev->string_langid); - } - } - err = usb_string_sub(dev, dev->string_langid, index, tbuf); - if (err < 0) - { - driver_mem_free(tbuf); - return err; - } + /* get langid for strings if it's not yet known */ + if (!dev->have_langid) + { + err = usb_string_sub(dev, 0, 0, tbuf); + if (err < 0) + { + dbg("error getting string descriptor 0 (error=%lx)\r\n", dev->status); + driver_mem_free(tbuf); + return -1; + } + else if (tbuf[0] < 4) + { + dbg("string descriptor 0 too short\r\n"); + driver_mem_free(tbuf); + return -1; + } + else + { + dev->have_langid = -1; + dev->string_langid = tbuf[2] | (tbuf[3] << 8); + /* always use the first langid listed */ + dbg("USB device number %d default language ID 0x%x\r\n", dev->devnum, dev->string_langid); + } + } + err = usb_string_sub(dev, dev->string_langid, index, tbuf); + if (err < 0) + { + driver_mem_free(tbuf); + return err; + } - size--; /* leave room for trailing NULL char in output buffer */ - for (idx = 0, u = 2; u < err; u += 2) - { - if (idx >= size) - { - break; - } - if (tbuf[u + 1]) /* high byte */ - { - buf[idx++] = '?'; /* non-ASCII character */ - } - else - { - buf[idx++] = tbuf[u]; - } - } - buf[idx] = 0; - err = idx; - driver_mem_free(tbuf); - return err; + size--; /* leave room for trailing NULL char in output buffer */ + for (idx = 0, u = 2; u < err; u += 2) + { + if (idx >= size) + { + break; + } + if (tbuf[u + 1]) /* high byte */ + { + buf[idx++] = '?'; /* non-ASCII character */ + } + else + { + buf[idx++] = tbuf[u]; + } + } + buf[idx] = 0; + err = idx; + driver_mem_free(tbuf); + return err; } /* @@ -976,39 +979,39 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size) */ void usb_disconnect(struct usb_device **pdev) { - struct usb_device *dev = *pdev; - if (dev != NULL) - { - int i; + struct usb_device *dev = *pdev; + if (dev != NULL) + { + int i; - dbg("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum); - dbg("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum); + dbg("USB %d disconnect on device %d\r\n", dev->parent->usbnum, dev->parent->devnum); + dbg("USB %d disconnected, device number %d\r\n", dev->usbnum, dev->devnum); - if (dev->deregister != NULL) - { - dev->deregister(dev); - } + if (dev->deregister != NULL) + { + dev->deregister(dev); + } - /* Free up all the children.. */ - for (i = 0; i < USB_MAXCHILDREN; i++) - { - if (dev->children[i] != NULL) - { - dbg("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum); - usb_disconnect(&dev->children[i]); - dev->children[i] = NULL; - } - } + /* Free up all the children.. */ + for (i = 0; i < USB_MAXCHILDREN; i++) + { + if (dev->children[i] != NULL) + { + dbg("USB %d, disconnect children %d\r\n", dev->usbnum, dev->children[i]->devnum); + usb_disconnect(&dev->children[i]); + dev->children[i] = NULL; + } + } - /* Free up the device itself, including its device number */ - if (dev->devnum > 0) - { - dev_index[dev->usbnum]--; - memset(dev, 0, sizeof(struct usb_device)); - dev->devnum = -1; - } - *pdev = NULL; - } + /* Free up the device itself, including its device number */ + if (dev->devnum > 0) + { + dev_index[dev->usbnum]--; + memset(dev, 0, sizeof(struct usb_device)); + dev->devnum = -1; + } + *pdev = NULL; + } } /* @@ -1017,22 +1020,22 @@ void usb_disconnect(struct usb_device **pdev) */ struct usb_device *usb_get_dev_index(int index, int index_bus) { - struct usb_device *dev; + struct usb_device *dev; - if ((index_bus >= USB_MAX_BUS) || (index_bus < 0) - || (index >= USB_MAX_DEVICE) || (index < 0)) - { - return NULL; - } + if ((index_bus >= USB_MAX_BUS) || (index_bus < 0) + || (index >= USB_MAX_DEVICE) || (index < 0)) + { + return NULL; + } - dev = &usb_dev[(index_bus * USB_MAX_DEVICE) + index]; + dev = &usb_dev[(index_bus * USB_MAX_DEVICE) + index]; - if ((controller_priv[index_bus] == NULL) || (dev->devnum == -1)) - { - return NULL; - } + if ((controller_priv[index_bus] == NULL) || (dev->devnum == -1)) + { + return NULL; + } - return dev; + return dev; } /* @@ -1041,30 +1044,31 @@ struct usb_device *usb_get_dev_index(int index, int index_bus) */ struct usb_device *usb_alloc_new_device(int bus_index, void *priv) { - int i; - int index = dev_index[bus_index]; - struct usb_device *dev; + int i; + int index = dev_index[bus_index]; + struct usb_device *dev; - dbg("USB %d new device %d\r\n", bus_index, index); - if (index >= USB_MAX_DEVICE) - { - dbg("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE); - return NULL; - } + dbg("USB %d new device %d\r\n", bus_index, index); + if (index >= USB_MAX_DEVICE) + { + dbg("ERROR, too many USB Devices, max=%d\r\n", USB_MAX_DEVICE); + return NULL; + } - /* default Address is 0, real addresses start with 1 */ - dev = &usb_dev[(bus_index * USB_MAX_DEVICE) + index]; - dev->devnum = index + 1; - dev->maxchild = 0; - for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL) - ; + /* default Address is 0, real addresses start with 1 */ + dev = &usb_dev[(bus_index * USB_MAX_DEVICE) + index]; + dev->devnum = index + 1; + dev->maxchild = 0; - dev->parent = NULL; - dev->priv_hcd = priv; - dev->usbnum = bus_index; - dev_index[bus_index]++; + for (i = 0; i < USB_MAXCHILDREN; dev->children[i++] = NULL) + ; - return dev; + dev->parent = NULL; + dev->priv_hcd = priv; + dev->usbnum = bus_index; + dev_index[bus_index]++; + + return dev; } // #define CONFIG_LEGACY_USB_INIT_SEQ @@ -1080,203 +1084,205 @@ int usb_new_device(struct usb_device *dev) int addr; int err; int tmp; - unsigned char *tmpbuf; + unsigned char *tmpbuf; + dbg("\r\n"); #ifndef CONFIG_LEGACY_USB_INIT_SEQ - struct usb_device_descriptor *desc; - int port = -1; - struct usb_device *parent = dev->parent; - unsigned short portstatus; + struct usb_device_descriptor *desc; + int port = -1; + struct usb_device *parent = dev->parent; + unsigned short portstatus; #endif - if (dev == NULL) + if (dev == NULL) { dbg("called with NULL device\r\n"); - return 1; + return 1; } - /* We still haven't set the Address yet */ - addr = dev->devnum; - dev->devnum = 0; + /* We still haven't set the Address yet */ + addr = dev->devnum; + dev->devnum = 0; - tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); - if (tmpbuf == NULL) - { + tmpbuf = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); + if (tmpbuf == NULL) + { dbg("malloc failure\r\n"); - return 1; - } + return 1; + } #ifdef CONFIG_LEGACY_USB_INIT_SEQ - /* - * this is the old and known way of initializing devices, it is - * different than what Windows and Linux are doing. Windows and Linux - * both retrieve 64 bytes while reading the device descriptor - * Several USB stick devices report ERR: CTL_TIMEOUT, caused by an - * invalid header while reading 8 bytes as device descriptor. - */ - dev->descriptor.bMaxPacketSize0 = 8; /* Start off at 8 bytes */ - dev->maxpacketsize = PACKET_SIZE_8; - dev->epmaxpacketin[0] = 8; - dev->epmaxpacketout[0] = 8; - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8); - if (err < 8) - { - dbg("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status); - driver_mem_free(tmpbuf); - return 1; - } + /* + * this is the old and known way of initializing devices, it is + * different than what Windows and Linux are doing. Windows and Linux + * both retrieve 64 bytes while reading the device descriptor + * Several USB stick devices report ERR: CTL_TIMEOUT, caused by an + * invalid header while reading 8 bytes as device descriptor. + */ + dev->descriptor.bMaxPacketSize0 = 8; /* Start off at 8 bytes */ + dev->maxpacketsize = PACKET_SIZE_8; + dev->epmaxpacketin[0] = 8; + dev->epmaxpacketout[0] = 8; + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, 8); + if (err < 8) + { + dbg("\r\nUSB device not responding, giving up (status=%lX)\r\n", dev->status); + driver_mem_free(tmpbuf); + return 1; + } #else - /* - * This is a Windows scheme of initialization sequence, with double - * reset of the device (Linux uses the same sequence) - * Some equipment is said to work only with such init sequence; this - * patch is based on the work by Alan Stern: - * http://sourceforge.net/mailarchive/forum.php? - * thread_id=5729457&forum_id=5398 - */ + /* + * This is a Windows scheme of initialization sequence, with double + * reset of the device (Linux uses the same sequence) + * Some equipment is said to work only with such init sequence; this + * patch is based on the work by Alan Stern: + * http://sourceforge.net/mailarchive/forum.php? + * thread_id=5729457&forum_id=5398 + */ - /* - * send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is - * only 18 bytes long, this will terminate with a short packet. But if - * the maxpacket size is 8 or 16 the device may be waiting to transmit - * some more, or keeps on retransmitting the 8 byte header. - */ - desc = (struct usb_device_descriptor *) tmpbuf; - dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */ + /* + * send 64-byte GET-DEVICE-DESCRIPTOR request. Since the descriptor is + * only 18 bytes long, this will terminate with a short packet. But if + * the maxpacket size is 8 or 16 the device may be waiting to transmit + * some more, or keeps on retransmitting the 8 byte header. + */ + desc = (struct usb_device_descriptor *) tmpbuf; + dev->descriptor.bMaxPacketSize0 = 64; /* Start off at 64 bytes */ - /* Default to 64 byte max packet size */ - dev->maxpacketsize = PACKET_SIZE_64; - dev->epmaxpacketin[0] = 64; - dev->epmaxpacketout[0] = 64; - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); + /* Default to 64 byte max packet size */ + dev->maxpacketsize = PACKET_SIZE_64; + dev->epmaxpacketin[0] = 64; + dev->epmaxpacketout[0] = 64; + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, 64); - if (err < 0) - { - dbg("usb_new_device: usb_get_descriptor() failed\r\n"); - driver_mem_free(tmpbuf); - return 1; - } - dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0; + if (err < 0) + { + dbg("usb_new_device: usb_get_descriptor() failed\r\n"); + driver_mem_free(tmpbuf); + return 1; + } + dev->descriptor.bMaxPacketSize0 = desc->bMaxPacketSize0; - /* find the port number we're at */ - if (parent) - { - int j; - for (j = 0; j < parent->maxchild; j++) - { - if (parent->children[j] == dev) - { - port = j; - break; - } - } + /* find the port number we're at */ + if (parent) + { + int j; + for (j = 0; j < parent->maxchild; j++) + { + if (parent->children[j] == dev) + { + port = j; + break; + } + } + dbg("port = %d\r\n", port); - if (port < 0) - { - dbg("usb_new_device: cannot locate device's port.\r\n"); - driver_mem_free(tmpbuf); + if (port < 0) + { + dbg("usb_new_device: cannot locate device's port.\r\n"); + driver_mem_free(tmpbuf); - return 1; - } + return 1; + } - /* reset the port for the second time */ - err = hub_port_reset(dev->parent, port, &portstatus); - if (err < 0) - { - dbg("\r\nCouldn't reset port %d\r\n", port); - driver_mem_free(tmpbuf); + /* reset the port for the second time */ + err = hub_port_reset(dev->parent, port, &portstatus); + if (err < 0) + { + dbg("\r\nCouldn't reset port %d\r\n", port); + driver_mem_free(tmpbuf); - return 1; - } - } + return 1; + } + } #endif - dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; - dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; + dev->epmaxpacketin[0] = dev->descriptor.bMaxPacketSize0; + dev->epmaxpacketout[0] = dev->descriptor.bMaxPacketSize0; - switch (dev->descriptor.bMaxPacketSize0) - { - case 8: dev->maxpacketsize = PACKET_SIZE_8; break; - case 16: dev->maxpacketsize = PACKET_SIZE_16; break; - case 32: dev->maxpacketsize = PACKET_SIZE_32; break; - case 64: dev->maxpacketsize = PACKET_SIZE_64; break; - } + switch (dev->descriptor.bMaxPacketSize0) + { + case 8: dev->maxpacketsize = PACKET_SIZE_8; break; + case 16: dev->maxpacketsize = PACKET_SIZE_16; break; + case 32: dev->maxpacketsize = PACKET_SIZE_32; break; + case 64: dev->maxpacketsize = PACKET_SIZE_64; break; + } - dev->devnum = addr; - err = usb_set_address(dev); /* set address */ + dev->devnum = addr; + err = usb_set_address(dev); /* set address */ - if (err < 0) - { - dbg("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status); - driver_mem_free(tmpbuf); + if (err < 0) + { + dbg("\r\nUSB device not accepting new address (error=%lX)\r\n", dev->status); + driver_mem_free(tmpbuf); - return 1; - } + return 1; + } - wait(10 * 1000); /* Let the SET_ADDRESS settle */ - tmp = sizeof(dev->descriptor); - err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor)); - if (err < tmp) - { - if (err < 0) - { - dbg("unable to get device descriptor (error=%d)\r\n", err); - } - else - { - dbg("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err); - } - driver_mem_free(tmpbuf); + wait(10); /* Let the SET_ADDRESS settle */ + tmp = sizeof(dev->descriptor); + err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &dev->descriptor, sizeof(dev->descriptor)); + if (err < tmp) + { + if (err < 0) + { + dbg("unable to get device descriptor (error=%d)\r\n", err); + } + else + { + dbg("USB device descriptor short read (expected %i, got %i)\r\n", tmp, err); + } + driver_mem_free(tmpbuf); - return 1; - } + return 1; + } - /* correct values */ - dev->descriptor.bcdUSB = swpw(dev->descriptor.bcdUSB); - dev->descriptor.idVendor = swpw(dev->descriptor.idVendor); - dev->descriptor.idProduct = swpw(dev->descriptor.idProduct); - dev->descriptor.bcdDevice = swpw(dev->descriptor.bcdDevice); + /* correct values */ + dev->descriptor.bcdUSB = swpw(dev->descriptor.bcdUSB); + dev->descriptor.idVendor = swpw(dev->descriptor.idVendor); + dev->descriptor.idProduct = swpw(dev->descriptor.idProduct); + dev->descriptor.bcdDevice = swpw(dev->descriptor.bcdDevice); - /* only support for one config for now */ - usb_get_configuration_no(dev, &tmpbuf[0], 0); - usb_parse_config(dev, &tmpbuf[0], 0); - usb_set_maxpacket(dev); + /* only support for one config for now */ + usb_get_configuration_no(dev, &tmpbuf[0], 0); + usb_parse_config(dev, &tmpbuf[0], 0); + usb_set_maxpacket(dev); - /* we set the default configuration here */ - if (usb_set_configuration(dev, dev->config.bConfigurationValue)) - { - dbg("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status); - driver_mem_free(tmpbuf); - return -1; - } - dbg("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", - dev->descriptor.iManufacturer, dev->descriptor.iProduct, - dev->descriptor.iSerialNumber); + /* we set the default configuration here */ + if (usb_set_configuration(dev, dev->config.bConfigurationValue)) + { + dbg("failed to set default configuration len %d, status %lX\r\n", dev->act_len, dev->status); + driver_mem_free(tmpbuf); + return -1; + } + dbg("new device strings: Mfr=%d, Product=%d, SerialNumber=%d\r\n", + dev->descriptor.iManufacturer, dev->descriptor.iProduct, + dev->descriptor.iSerialNumber); - memset(dev->mf, 0, sizeof(dev->mf)); - memset(dev->prod, 0, sizeof(dev->prod)); - memset(dev->serial, 0, sizeof(dev->serial)); + memset(dev->mf, 0, sizeof(dev->mf)); + memset(dev->prod, 0, sizeof(dev->prod)); + memset(dev->serial, 0, sizeof(dev->serial)); - if (dev->descriptor.iManufacturer) - { - usb_string(dev, dev->descriptor.iManufacturer, dev->mf, sizeof(dev->mf)); - } - if (dev->descriptor.iProduct) - { - usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod)); - } - if (dev->descriptor.iSerialNumber) - { - usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial)); - } - dbg("Manufacturer %s\r\n", dev->mf); - dbg("Product %s\r\n", dev->prod); - dbg("SerialNumber %s\r\n", dev->serial); + if (dev->descriptor.iManufacturer) + { + usb_string(dev, dev->descriptor.iManufacturer, dev->mf, sizeof(dev->mf)); + } + if (dev->descriptor.iProduct) + { + usb_string(dev, dev->descriptor.iProduct, dev->prod, sizeof(dev->prod)); + } + if (dev->descriptor.iSerialNumber) + { + usb_string(dev, dev->descriptor.iSerialNumber, dev->serial, sizeof(dev->serial)); + } + dbg("Manufacturer %s\r\n", dev->mf); + dbg("Product %s\r\n", dev->prod); + dbg("SerialNumber %s\r\n", dev->serial); - /* now probe if the device is a hub */ - usb_hub_probe(dev, 0); - driver_mem_free(tmpbuf); + /* now probe if the device is a hub */ + usb_hub_probe(dev, 0); + driver_mem_free(tmpbuf); - return 0; + return 0; } /* @@ -1284,33 +1290,33 @@ int usb_new_device(struct usb_device *dev) */ void usb_scan_devices(void *priv) { - int i; - struct usb_device *dev; + int i; + struct usb_device *dev; - /* first make all devices unknown */ - for (i = 0; i < USB_MAX_DEVICE; i++) - { - memset(&usb_dev[(bus_index * USB_MAX_DEVICE) + i], 0, sizeof(struct usb_device)); - usb_dev[(bus_index * USB_MAX_DEVICE) + i].devnum = -1; - } - dev_index[bus_index] = 0; + /* first make all devices unknown */ + for (i = 0; i < USB_MAX_DEVICE; i++) + { + memset(&usb_dev[(bus_index * USB_MAX_DEVICE) + i], 0, sizeof(struct usb_device)); + usb_dev[(bus_index * USB_MAX_DEVICE) + i].devnum = -1; + } + dev_index[bus_index] = 0; /* * device 0 is always present (root hub, so let it analyze) */ - dev = usb_alloc_new_device(bus_index, priv); - if (usb_new_device(dev)) - { - xprintf("No USB Device found\r\n"); - if (dev != NULL) - { - dev_index[bus_index]--; - } - } - else - { - xprintf("%d USB Device(s) found\r\n", dev_index[bus_index]); - } + dev = usb_alloc_new_device(bus_index, priv); + if (usb_new_device(dev)) + { + xprintf("No USB Device found\r\n"); + if (dev != NULL) + { + dev_index[bus_index]--; + } + } + else + { + xprintf("%d USB Device(s) found\r\n", dev_index[bus_index]); + } /* insert "driver" if possible */ if (drv_usb_kbd_init() < 0) @@ -1330,6 +1336,6 @@ void usb_scan_devices(void *priv) { xprintf("USB HID mouse driver installed\r\n"); } - xprintf("Scan end\r\n"); + xprintf("Scan end\r\n"); } diff --git a/BaS_gcc/usb/usb_hub.c b/BaS_gcc/usb/usb_hub.c index dcbd47b..bfef2f6 100644 --- a/BaS_gcc/usb/usb_hub.c +++ b/BaS_gcc/usb/usb_hub.c @@ -19,596 +19,601 @@ #define dbg(format, arg...) do { ; } while (0) #endif /* DEBUG_HUB */ #define err(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) +#define info(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) static struct usb_hub_device hub_dev[USB_MAX_BUS][USB_MAX_HUB]; static int usb_hub_index[USB_MAX_BUS]; int usb_get_hub_descriptor(struct usb_device *dev, void *data, int size) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB, USB_DT_HUB << 8, 0, data, size, USB_CNTL_TIMEOUT); } int usb_clear_hub_feature(struct usb_device *dev, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, USB_CNTL_TIMEOUT); } int usb_clear_port_feature(struct usb_device *dev, int port, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); } int usb_set_port_feature(struct usb_device *dev, int port, int feature) { - return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), - USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, USB_CNTL_TIMEOUT); } int usb_get_hub_status(struct usb_device *dev, void *data) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_HUB, 0, 0, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); } int usb_get_port_status(struct usb_device *dev, int port, void *data) { - return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), - USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); + return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port, data, sizeof(struct usb_hub_status), USB_CNTL_TIMEOUT); } static void usb_hub_power_on(struct usb_hub_device *hub) { - int i; - struct usb_device *dev; + int i; + struct usb_device *dev; - dev = hub->pusb_dev; - /* Enable power to the ports */ - dbg("enabling power on all ports\r\n"); - for (i = 0; i < dev->maxchild; i++) - { - usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); - dbg("port %d returns %lX\r\n", i + 1, dev->status); - wait(hub->desc.bPwrOn2PwrGood * 2 * 1000); - } + dev = hub->pusb_dev; + /* Enable power to the ports */ + dbg("enabling power on all ports\r\n"); + for (i = 0; i < dev->maxchild; i++) + { + usb_set_port_feature(dev, i + 1, USB_PORT_FEAT_POWER); + dbg("port %d returns %lx\r\n", i + 1, dev->status); + wait(hub->desc.bPwrOn2PwrGood * 2 * 1000); + } } void usb_hub_reset(int bus_index) { - usb_hub_index[bus_index] = 0; + usb_hub_index[bus_index] = 0; } struct usb_hub_device *usb_hub_allocate(void) { - if (usb_hub_index[bus_index] < USB_MAX_HUB) - { - return &hub_dev[bus_index][usb_hub_index[bus_index]++]; - } + if (usb_hub_index[bus_index] < USB_MAX_HUB) + { + return &hub_dev[bus_index][usb_hub_index[bus_index]++]; + } - dbg("ERROR: USB_MAX_HUB (%d) reached\r\n", USB_MAX_HUB); + dbg("ERROR: USB_MAX_HUB (%d) reached\r\n", USB_MAX_HUB); - return NULL; + return NULL; } #define MAX_TRIES 5 static inline char *portspeed(int portstatus) { - if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) - { - return "480 Mb/s"; - } - else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) - { - return "1.5 Mb/s"; - } - else - { - return "12 Mb/s"; - } + if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) + { + return "480 Mb/s"; + } + else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) + { + return "1.5 Mb/s"; + } + else + { + return "12 Mb/s"; + } } int hub_port_reset(struct usb_device *dev, int port, unsigned short *portstat) { - int tries; - struct usb_port_status portsts; - unsigned short portstatus, portchange; + int tries; + struct usb_port_status portsts; + unsigned short portstatus, portchange; - dbg("hub_port_reset: resetting port %d...\r\n", port + 1); + dbg(""); + dbg("hub_port_reset: resetting port %d...\r\n", port + 1); - for (tries = 0; tries < MAX_TRIES; tries++) - { - usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET); + for (tries = 0; tries < MAX_TRIES; tries++) + { + usb_set_port_feature(dev, port + 1, USB_PORT_FEAT_RESET); #ifdef USB_POLL_HUB - if (pxCurrentTCB != NULL) - vTaskDelay((200 * configTICK_RATE_HZ) / 1000); - else + if (pxCurrentTCB != NULL) + vTaskDelay((200 * configTICK_RATE_HZ) / 1000); + else #endif - wait(10000); - if (usb_get_port_status(dev, port + 1, &portsts) < 0) - { - dbg("get_port_status failed status %lX\r\n", dev->status); - return -1; - } + wait(10 * 1000); + if (usb_get_port_status(dev, port + 1, &portsts) < 0) + { + dbg("get_port_status failed status %lX\r\n", dev->status); + return -1; + } - portstatus = swpw(portsts.wPortStatus); - portchange = swpw(portsts.wPortChange); + portstatus = swpw(portsts.wPortStatus); + portchange = swpw(portsts.wPortChange); - dbg("USB %d portstatus 0x%x, change 0x%x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); - dbg("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n", - (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, - (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0, - (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0); + dbg("USB %d portstatus 0x%x, change 0x%x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); + dbg("STAT_C_CONNECTION = %d STAT_CONNECTION = %d USB_PORT_STAT_ENABLE = %d\r\n", + (portchange & USB_PORT_STAT_C_CONNECTION) ? 1 : 0, + (portstatus & USB_PORT_STAT_CONNECTION) ? 1 : 0, + (portstatus & USB_PORT_STAT_ENABLE) ? 1 : 0); - if ((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION)) - { - return -1; - } + if ((portchange & USB_PORT_STAT_C_CONNECTION) || !(portstatus & USB_PORT_STAT_CONNECTION)) + { + return -1; + } - if (portstatus & USB_PORT_STAT_ENABLE) - { - break; - } + if (portstatus & USB_PORT_STAT_ENABLE) + { + break; + } #ifdef USB_POLL_HUB - if (pxCurrentTCB != NULL) - vTaskDelay((200*configTICK_RATE_HZ)/1000); - else + if (pxCurrentTCB != NULL) + vTaskDelay((200*configTICK_RATE_HZ)/1000); + else #endif - wait(20000); - } + wait(20 * 1000); + } - if (tries == MAX_TRIES) - { - dbg("USB %d, cannot enable port %d after %d retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES); - dbg("Maybe the USB cable is bad?\r\n"); + if (tries == MAX_TRIES) + { + dbg("USB %d, cannot enable port %d after %d retries, disabling port.\r\n", dev->usbnum, port + 1, MAX_TRIES); + dbg("Maybe the USB cable is bad?\r\n"); - return -1; - } - usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET); + return -1; + } + usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_RESET); - *portstat = portstatus; + *portstat = portstatus; - return 0; + return 0; } void usb_hub_port_connect_change(struct usb_device *dev, int port) { - struct usb_device *usb; - struct usb_port_status portsts; - unsigned short portstatus; + struct usb_device *usb; + struct usb_port_status portsts; + unsigned short portstatus; - /* Check status */ - if (usb_get_port_status(dev, port + 1, &portsts) < 0) - { - dbg("USB %d get_port_status failed\r\n", dev->usbnum); + /* Check status */ + if (usb_get_port_status(dev, port + 1, &portsts) < 0) + { + dbg("USB %d get_port_status failed\r\n", dev->usbnum); - return; - } + return; + } - portstatus = swpw(portsts.wPortStatus); + portstatus = swpw(portsts.wPortStatus); #ifdef USB_DEBUG - { - unsigned short portchange; + { + unsigned short portchange; - portchange = swpw(portsts.wPortChange); - dbg("USB %d, portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); - } + portchange = swpw(portsts.wPortChange); + dbg("USB %d, portstatus %x, change %x, %s\r\n", dev->usbnum, portstatus, portchange, portspeed(portstatus)); + } #endif /* USB_DEBUG */ - /* Clear the connection change status */ - usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); + /* Clear the connection change status */ + usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_C_CONNECTION); - /* Disconnect any existing devices under this port */ + /* Disconnect any existing devices under this port */ - if (((!(portstatus & USB_PORT_STAT_CONNECTION)) - && (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) - { - dbg("USB %d port %i disconnected\r\n", dev->usbnum, port + 1); - usb_disconnect(&dev->children[port]); - /* Return now if nothing is connected */ - if (!(portstatus & USB_PORT_STAT_CONNECTION)) - { - return; - } - } + if (((!(portstatus & USB_PORT_STAT_CONNECTION)) + && (!(portstatus & USB_PORT_STAT_ENABLE))) || (dev->children[port])) + { + dbg("USB %d port %i disconnected\r\n", dev->usbnum, port + 1); + usb_disconnect(&dev->children[port]); + + /* Return now if nothing is connected */ + if (!(portstatus & USB_PORT_STAT_CONNECTION)) + { + return; + } + } #ifdef USB_POLL_HUB - if (pxCurrentTCB != NULL) - vTaskDelay((200*configTICK_RATE_HZ)/1000); - else + if (pxCurrentTCB != NULL) + vTaskDelay((200*configTICK_RATE_HZ)/1000); + else #endif - wait(2000); - /* Reset the port */ - if (hub_port_reset(dev, port, &portstatus) < 0) - { - dbg("USB %d cannot reset port %i!?\r\n", dev->usbnum, port + 1); + wait(2000); + /* Reset the port */ + if (hub_port_reset(dev, port, &portstatus) < 0) + { + dbg("USB %d cannot reset port %i!?\r\n", dev->usbnum, port + 1); - return; - } + return; + } #ifdef USB_POLL_HUB - if (pxCurrentTCB != NULL) - vTaskDelay((200*configTICK_RATE_HZ)/1000); - else + if (pxCurrentTCB != NULL) + vTaskDelay((200*configTICK_RATE_HZ)/1000); + else #endif - wait(2000); + wait(2000); - /* Allocate a new device struct for it */ - usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd); + /* Allocate a new device struct for it */ + usb = usb_alloc_new_device(dev->usbnum, dev->priv_hcd); - if (portstatus & USB_PORT_STAT_HIGH_SPEED) - usb->speed = USB_SPEED_HIGH; - else if (portstatus & USB_PORT_STAT_LOW_SPEED) - usb->speed = USB_SPEED_LOW; - else - usb->speed = USB_SPEED_FULL; + if (portstatus & USB_PORT_STAT_HIGH_SPEED) + { + usb->speed = USB_SPEED_HIGH; + } + else if (portstatus & USB_PORT_STAT_LOW_SPEED) + { + usb->speed = USB_SPEED_LOW; + } + else + { + usb->speed = USB_SPEED_FULL; + } - dbg("usb=%p\r\n", usb); - dev->children[port] = usb; - usb->parent = dev; + dbg("usb device = %p\r\n", usb); + dev->children[port] = usb; + usb->parent = dev; - /* Run it through the hoops (find a driver, etc) */ - if (usb_new_device(usb)) - { - /* Woops, disable the port */ - dbg("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1); - usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); - } + /* Run it through the hoops (find a driver, etc) */ + if (usb_new_device(usb)) + { + /* Woops, disable the port */ + dbg("USB %d hub: disabling port %d\r\n", dev->usbnum, port + 1); + usb_clear_port_feature(dev, port + 1, USB_PORT_FEAT_ENABLE); + } #ifdef USB_POLL_HUB - else if (pxCurrentTCB != NULL) - { -#ifdef CONFIG_USB_KEYBOARD - usb_kbd_register(usb); -#endif /* CONFIG_USB_KEYBOARD */ -#ifdef CONFIG_USB_MOUSE - usb_mouse_register(usb); -#endif /* CONFIG_USB_MOUSE */ + else if (pxCurrentTCB != NULL) + { + usb_kbd_register(usb); + usb_mouse_register(usb); #ifdef CONFIG_USB_STORAGE - usb_stor_register(usb); + usb_stor_register(usb); #endif /* CONFIG_USB_STORAGE */ - } + } #endif } static void usb_hub_events(struct usb_device *dev) { - int i; - struct usb_hub_device *hub = dev->hub; + int i; + struct usb_hub_device *hub = dev->hub; - if (hub == NULL) - { - return; - } + if (hub == NULL) + { + return; + } - for (i = 0; i < dev->maxchild; i++) - { - struct usb_port_status portsts; - unsigned short portstatus, portchange; + for (i = 0; i < dev->maxchild; i++) + { + struct usb_port_status portsts; + unsigned short portstatus, portchange; - if (usb_get_port_status(dev, i + 1, &portsts) < 0) - { - dbg("get_port_status failed\r\n"); - continue; - } - portstatus = swpw(portsts.wPortStatus); - portchange = swpw(portsts.wPortChange); + if (usb_get_port_status(dev, i + 1, &portsts) < 0) + { + dbg("get_port_status failed\r\n"); + continue; + } + portstatus = swpw(portsts.wPortStatus); + portchange = swpw(portsts.wPortChange); - dbg("USB %d Port %d Status %X Change %X\r\n", dev->usbnum, i + 1, portstatus, portchange); + dbg("USB %d Port %d Status %X Change %X\r\n", dev->usbnum, i + 1, portstatus, portchange); - if (portchange & USB_PORT_STAT_C_CONNECTION) - { - dbg("USB %d port %d connection change\r\n", dev->usbnum, i + 1); - usb_hub_port_connect_change(dev, i); - } + if (portchange & USB_PORT_STAT_C_CONNECTION) + { + dbg("USB %d port %d connection change\r\n", dev->usbnum, i + 1); + usb_hub_port_connect_change(dev, i); + } - if (portchange & USB_PORT_STAT_C_ENABLE) - { - dbg("USB %d port %d enable change, status %x\r\n", dev->usbnum, i + 1, portstatus); - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE); + if (portchange & USB_PORT_STAT_C_ENABLE) + { + dbg("USB %d port %d enable change, status %x\r\n", dev->usbnum, i + 1, portstatus); + usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_ENABLE); - /* - * EM interference sometimes causes bad shielded USB - * devices to be shutdown by the hub, this hack enables - * them again. Works at least with mouse driver - */ - if (!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i]))) - { - dbg("USB %d already running port %i disabled by hub (EMI?), re-enabling...\r\n", dev->usbnum, i + 1); - usb_hub_port_connect_change(dev, i); - } - } + /* + * EM interference sometimes causes bad shielded USB + * devices to be shutdown by the hub, this hack enables + * them again. Works at least with mouse driver + */ + if (!(portstatus & USB_PORT_STAT_ENABLE) && (portstatus & USB_PORT_STAT_CONNECTION) && ((dev->children[i]))) + { + dbg("USB %d already running port %i disabled by hub (EMI?), re-enabling...\r\n", dev->usbnum, i + 1); + usb_hub_port_connect_change(dev, i); + } + } - if (portstatus & USB_PORT_STAT_SUSPEND) - { - dbg("USB %d port %d suspend change\r\n", dev->usbnum, i + 1); - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND); - } + if (portstatus & USB_PORT_STAT_SUSPEND) + { + dbg("USB %d port %d suspend change\r\n", dev->usbnum, i + 1); + usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_SUSPEND); + } - if (portchange & USB_PORT_STAT_C_OVERCURRENT) - { - dbg("USB %d port %d over-current change\r\n", dev->usbnum, i + 1); - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT); - usb_hub_power_on(hub); - } + if (portchange & USB_PORT_STAT_C_OVERCURRENT) + { + dbg("USB %d port %d over-current change\r\n", dev->usbnum, i + 1); + usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_OVER_CURRENT); + usb_hub_power_on(hub); + } - if (portchange & USB_PORT_STAT_C_RESET) - { - dbg("USB %d port %d reset change\r\n", dev->usbnum, i + 1); - usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET); - } - } /* end for i all ports */ + if (portchange & USB_PORT_STAT_C_RESET) + { + dbg("USB %d port %d reset change\r\n", dev->usbnum, i + 1); + usb_clear_port_feature(dev, i + 1, USB_PORT_FEAT_C_RESET); + } + } /* end for i all ports */ } #ifdef USB_POLL_HUB void usb_poll_hub_task(void *pvParameters) { - int index_bus = 0; - portTickType timeout = configTICK_RATE_HZ/10; - if (pvParameters); - while(1) - { - if (xQueueAltReceive(queue_poll_hub, &index_bus, timeout) == pdPASS) - { - if ((index_bus >= 0) && (index_bus < USB_MAX_BUS) && (controller_priv[index_bus] != NULL)) - { - dbg("USB %d event change\r\n", index_bus); + int index_bus = 0; + portTickType timeout = configTICK_RATE_HZ/10; + if (pvParameters); + while(1) + { + if (xQueueAltReceive(queue_poll_hub, &index_bus, timeout) == pdPASS) + { + if ((index_bus >= 0) && (index_bus < USB_MAX_BUS) && (controller_priv[index_bus] != NULL)) + { + dbg("USB %d event change\r\n", index_bus); #ifdef CONFIG_USB_INTERRUPT_POLLING - *vblsem = 0; + *vblsem = 0; #endif - usb_hub_events(&usb_dev[index_bus * USB_MAX_DEVICE]); + usb_hub_events(&usb_dev[index_bus * USB_MAX_DEVICE]); #ifdef CONFIG_USB_INTERRUPT_POLLING - *vblsem = 1; + *vblsem = 1; #endif - } - } - else /* timeout */ - { - int i; + } + } + else /* timeout */ + { + int i; #ifdef CONFIG_USB_INTERRUPT_POLLING - *vblsem = 0; + *vblsem = 0; #endif - for (i = 0; i < USB_MAX_BUS ; i++) - { - if (controller_priv[i] != NULL) - usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); - } + for (i = 0; i < USB_MAX_BUS ; i++) + { + if (controller_priv[i] != NULL) + usb_hub_events(&usb_dev[i * USB_MAX_DEVICE]); + } #ifdef CONFIG_USB_INTERRUPT_POLLING - *vblsem = 1; + *vblsem = 1; #endif - } - timeout = portMAX_DELAY; - } + } + timeout = portMAX_DELAY; + } } #endif /* USB_POLL_HUB */ int usb_hub_configure(struct usb_device *dev) { - unsigned char *buffer; - unsigned char *bitmap; - struct usb_hub_descriptor *descriptor; - int i; - struct usb_hub_device *hub; + unsigned char *buffer; + unsigned char *bitmap; + struct usb_hub_descriptor *descriptor; + int i; + struct usb_hub_device *hub; - /* "allocate" Hub device */ - hub = usb_hub_allocate(); - dev->hub = hub; + /* "allocate" Hub device */ + hub = usb_hub_allocate(); + dev->hub = hub; - if (hub == NULL) - { - dbg("could not allocate hub\r\n"); + if (hub == NULL) + { + dbg("could not allocate hub\r\n"); - return -1; - } + return -1; + } - hub->pusb_dev = dev; - buffer = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); + hub->pusb_dev = dev; + buffer = (unsigned char *) driver_mem_alloc(USB_BUFSIZ); - if (buffer == NULL) - { - dbg("driver_mem_alloc() failure\r\n"); - return -1; - } + if (buffer == NULL) + { + dbg("driver_mem_alloc() failure\r\n"); + return -1; + } - /* Get the the hub descriptor */ - if (usb_get_hub_descriptor(dev, buffer, 4) < 0) - { - dbg("failed to get hub descriptor, giving up %lX\r\n", dev->status); - driver_mem_free(buffer); - return -1; - } - dbg("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); - descriptor = (struct usb_hub_descriptor *)buffer; + /* Get the the hub descriptor */ + if (usb_get_hub_descriptor(dev, buffer, 4) < 0) + { + dbg("failed to get hub descriptor, giving up %lX\r\n", dev->status); + driver_mem_free(buffer); + return -1; + } + dbg("bLength:%02X bDescriptorType:%02X bNbrPorts:%02X\r\n", buffer[0], buffer[1], buffer[2]); + descriptor = (struct usb_hub_descriptor *)buffer; - /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */ - i = descriptor->bLength; + /* silence compiler warning if USB_BUFSIZ is > 256 [= sizeof(char)] */ + i = descriptor->bLength; - if (i > USB_BUFSIZ) - { - dbg("failed to get hub descriptor - too long: %d\r\n", descriptor->bLength); - driver_mem_free(buffer); + if (i > USB_BUFSIZ) + { + dbg("failed to get hub descriptor - too long: %d\r\n", descriptor->bLength); + driver_mem_free(buffer); - return -1; - } + return -1; + } - if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) - { - dbg("failed to get hub descriptor 2nd giving up %lX\r\n", dev->status); - driver_mem_free(buffer); + if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) + { + dbg("failed to get hub descriptor 2nd giving up %lX\r\n", dev->status); + driver_mem_free(buffer); - return -1; - } + return -1; + } - memcpy((unsigned char *) &hub->desc, buffer, descriptor->bLength); + memcpy((unsigned char *) &hub->desc, buffer, descriptor->bLength); - /* adjust 16bit values */ - hub->desc.wHubCharacteristics = swpw(descriptor->wHubCharacteristics); + /* adjust 16bit values */ + hub->desc.wHubCharacteristics = swpw(descriptor->wHubCharacteristics); - /* set the bitmap */ - bitmap = (unsigned char *) &hub->desc.DeviceRemovable[0]; + /* set the bitmap */ + bitmap = (unsigned char *) &hub->desc.DeviceRemovable[0]; - /* devices not removable by default */ + /* devices not removable by default */ - memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); - bitmap = (unsigned char *) &hub->desc.PortPowerCtrlMask[0]; - memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); /* PowerMask = 1B */ + memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); + bitmap = (unsigned char *) &hub->desc.PortPowerCtrlMask[0]; + memset(bitmap, 0xff, (USB_MAXCHILDREN + 1 + 7) / 8); /* PowerMask = 1B */ - for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++) - { - hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i]; - } + for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7) / 8); i++) + { + hub->desc.DeviceRemovable[i] = descriptor->DeviceRemovable[i]; + } - for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++) - { - hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i]; - } + for (i = 0; i < ((hub->desc.bNbrPorts + 1 + 7)/8); i++) + { + hub->desc.DeviceRemovable[i] = descriptor->PortPowerCtrlMask[i]; + } - dev->maxchild = descriptor->bNbrPorts; - dbg("USB %d, %d ports detected\r\n", dev->usbnum, dev->maxchild); - if (dev->maxchild >= 10) - { - dev->maxchild = 10; - } + dev->maxchild = descriptor->bNbrPorts; + dbg("USB %d, %d ports detected\r\n", dev->usbnum, dev->maxchild); + if (dev->maxchild >= 10) + { + dev->maxchild = 10; + } - switch(hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) - { - case 0x00: dbg("ganged power switching\r\n"); break; - case 0x01: dbg("individual port power switching\r\n"); break; - case 0x02: - case 0x03: dbg("unknown reserved power switching mode\r\n"); break; - } + switch(hub->desc.wHubCharacteristics & HUB_CHAR_LPSM) + { + case 0x00: dbg("ganged power switching\r\n"); break; + case 0x01: dbg("individual port power switching\r\n"); break; + case 0x02: + case 0x03: dbg("unknown reserved power switching mode\r\n"); break; + } - if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND) - { - dbg("part of a compound device\r\n"); - } - else - { - dbg("standalone hub\r\n"); - } + if (hub->desc.wHubCharacteristics & HUB_CHAR_COMPOUND) + { + dbg("part of a compound device\r\n"); + } + else + { + dbg("standalone hub\r\n"); + } - switch(hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) - { - case 0x00: dbg("global over-current protection\r\n"); break; - case 0x08: dbg("individual port over-current protection\r\n"); break; - case 0x10: - case 0x18: dbg("no over-current protection\r\n"); break; - } + switch(hub->desc.wHubCharacteristics & HUB_CHAR_OCPM) + { + case 0x00: dbg("global over-current protection\r\n"); break; + case 0x08: dbg("individual port over-current protection\r\n"); break; + case 0x10: + case 0x18: dbg("no over-current protection\r\n"); break; + } - dbg("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2); - dbg("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent); + dbg("power on to power good time: %dms\r\n", descriptor->bPwrOn2PwrGood * 2); + dbg("hub controller current requirement: %dmA\r\n", descriptor->bHubContrCurrent); - for (i = 0; i < dev->maxchild; i++) - { - dbg("USB %d port %d is%s removable\r\n", dev->usbnum, i + 1, hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : ""); - } + for (i = 0; i < dev->maxchild; i++) + { + dbg("USB %d port %d is%s removable\r\n", dev->usbnum, i + 1, hub->desc.DeviceRemovable[(i + 1) / 8] & (1 << ((i + 1) % 8)) ? " not" : ""); + } - if (sizeof(struct usb_hub_status) > USB_BUFSIZ) - { - dbg("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength); - driver_mem_free(buffer); + if (sizeof(struct usb_hub_status) > USB_BUFSIZ) + { + dbg("usb_hub_configure: failed to get Status - too long: %d\r\n", descriptor->bLength); + driver_mem_free(buffer); - return -1; - } + return -1; + } - if (usb_get_hub_status(dev, buffer) < 0) - { - dbg("usb_hub_configure: failed to get Status %lX\r\n", dev->status); - driver_mem_free(buffer); + if (usb_get_hub_status(dev, buffer) < 0) + { + dbg("usb_hub_configure: failed to get Status %lX\r\n", dev->status); + driver_mem_free(buffer); - return -1; - } + return -1; + } #ifdef USB_DEBUG - { - struct usb_hub_status *hubsts; + { + struct usb_hub_status *hubsts; - hubsts = (struct usb_hub_status *)buffer; - dbg("get_hub_status returned status %X, change %X\r\n", - swpw(hubsts->wHubStatus), swpw(hubsts->wHubChange)); - dbg("local power source is %s\r\n", - (swpw(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good"); - dbg("%sover-current condition exists\r\n", - (swpw(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no "); - } + hubsts = (struct usb_hub_status *)buffer; + dbg("get_hub_status returned status %X, change %X\r\n", + swpw(hubsts->wHubStatus), swpw(hubsts->wHubChange)); + dbg("local power source is %s\r\n", + (swpw(hubsts->wHubStatus) & HUB_STATUS_LOCAL_POWER) ? "lost (inactive)" : "good"); + dbg("%sover-current condition exists\r\n", + (swpw(hubsts->wHubStatus) & HUB_STATUS_OVERCURRENT) ? "" : "no "); + } #endif /* USB_DEBUG */ - usb_hub_power_on(hub); + usb_hub_power_on(hub); #ifdef USB_POLL_HUB - if ((queue_poll_hub == NULL) && (pxCurrentTCB != NULL)) - { - queue_poll_hub = xQueueCreate(64, sizeof(int)); - if (queue_poll_hub != NULL) - { - /* Create poll/event task */ - if (xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS) - { - vQueueDelete(queue_poll_hub); - queue_poll_hub = NULL; - } - } - vTaskDelay(configTICK_RATE_HZ); - } - if (queue_poll_hub == NULL) + if ((queue_poll_hub == NULL) && (pxCurrentTCB != NULL)) + { + queue_poll_hub = xQueueCreate(64, sizeof(int)); + if (queue_poll_hub != NULL) + { + /* Create poll/event task */ + if (xTaskCreate(usb_poll_hub_task, (void *)"USBHub", configMINIMAL_STACK_SIZE, NULL, 16, NULL) != pdPASS) + { + vQueueDelete(queue_poll_hub); + queue_poll_hub = NULL; + } + } + vTaskDelay(configTICK_RATE_HZ); + } + if (queue_poll_hub == NULL) #endif - usb_hub_events(dev); - driver_mem_free(buffer); + usb_hub_events(dev); + driver_mem_free(buffer); - return 0; + return 0; } int usb_hub_probe(struct usb_device *dev, int ifnum) { - struct usb_interface_descriptor *iface; - struct usb_endpoint_descriptor *ep; - int ret; + struct usb_interface_descriptor *iface; + struct usb_endpoint_descriptor *ep; + int ret; - iface = &dev->config.if_desc[ifnum]; + iface = &dev->config.if_desc[ifnum]; - /* Is it a hub? */ - if (iface->bInterfaceClass != USB_CLASS_HUB) - { - dbg("iface->bInterfaceClass != USB_CLASS_HUB (%d), %d instead\r\n", USB_CLASS_HUB, iface->bInterfaceClass); - return 0; - } + /* Is it a hub? */ + if (iface->bInterfaceClass != USB_CLASS_HUB) + { + dbg("iface->bInterfaceClass != USB_CLASS_HUB (%d), %d instead\r\n", USB_CLASS_HUB, iface->bInterfaceClass); + return 0; + } - /* - * Some hubs have a subclass of 1, which AFAICT according to the - * specs is not defined, but it works - */ - if ((iface->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1)) - { - return 0; - } + /* + * Some hubs have a subclass of 1, which AFAICT according to the + * specs is not defined, but it works + */ + if ((iface->bInterfaceSubClass != 0) && (iface->bInterfaceSubClass != 1)) + { + return 0; + } - /* Multiple endpoints? What kind of mutant ninja-hub is this? */ - if (iface->bNumEndpoints != 1) - { - return 0; - } + /* Multiple endpoints? What kind of mutant ninja-hub is this? */ + if (iface->bNumEndpoints != 1) + { + return 0; + } - ep = &iface->ep_desc[0]; + ep = &iface->ep_desc[0]; - /* Output endpoint? Curiousier and curiousier.. */ - if (!(ep->bEndpointAddress & USB_DIR_IN)) - { - return 0; - } + /* Output endpoint? Curiousier and curiousier.. */ + if (!(ep->bEndpointAddress & USB_DIR_IN)) + { + return 0; + } - /* If it's not an interrupt endpoint, we'd better punt! */ - if ((ep->bmAttributes & 3) != 3) - { - return 0; - } + /* If it's not an interrupt endpoint, we'd better punt! */ + if ((ep->bmAttributes & 3) != 3) + { + return 0; + } - /* We found a hub */ - dbg("USB %d hub found\r\n", dev->usbnum); - ret = usb_hub_configure(dev); + /* We found a hub */ + dbg("USB %d hub found\r\n", dev->usbnum); + ret = usb_hub_configure(dev); - return ret; + return ret; } diff --git a/BaS_gcc/usb/usb_mouse.c b/BaS_gcc/usb/usb_mouse.c index 2bb7ec2..f8c842c 100644 --- a/BaS_gcc/usb/usb_mouse.c +++ b/BaS_gcc/usb/usb_mouse.c @@ -26,7 +26,7 @@ #include "exceptions.h" #include "driver_mem.h" -//#define DEBUG_USBMOUSE +#define DEBUG_USBMOUSE #ifdef DEBUG_USBMOUSE #define dbg(format, arg...) do { xprintf("DEBUG: %s(): " format, __FUNCTION__, ##arg); } while (0) #else @@ -48,65 +48,67 @@ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum); /* deregistering the mouse */ int usb_mouse_deregister(struct usb_device *dev) { - dev->irq_handle = NULL; - if (new != NULL) - { - driver_mem_free(new); - new = NULL; - } - mouse_installed = 0; - dbg("USB MOUSE deregister\r\n"); - return 1; + dev->irq_handle = NULL; + if (new != NULL) + { + driver_mem_free(new); + new = NULL; + } + mouse_installed = 0; + dbg("USB MOUSE deregister\r\n"); + return 1; } /* registering the mouse */ int usb_mouse_register(struct usb_device *dev) { - if (!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1)) - { - /* Ok, we found a mouse */ - dbg("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum); - mouse_installed = 1; - dev->deregister = usb_mouse_deregister; - return 1; - } - /* no USB Mouse found */ - return -1; + if (!mouse_installed && (dev->devnum != -1) && (usb_mouse_probe(dev, 0) == 1)) + { + /* Ok, we found a mouse */ + dbg("USB MOUSE found (USB: %d, devnum: %d)\r\n", dev->usbnum, dev->devnum); + mouse_installed = 1; + dev->deregister = usb_mouse_deregister; + return 1; + } + /* no USB Mouse found */ + return -1; } /* search for mouse and register it if found */ int drv_usb_mouse_init(void) { - int i; - int j; + int i; + int j; - /* - * check if mouse is already initialized - */ - if (mouse_installed) - { - xprintf("USB mouse already initialized\r\n"); + /* + * check if mouse is already initialized + */ + if (mouse_installed) + { + xprintf("USB mouse already initialized\r\n"); - return -1; - } + return -1; + } - /* scan all USB Devices */ - for (j = 0; j < USB_MAX_BUS; j++) - { - for (i = 0; i < USB_MAX_DEVICE; i++) - { - struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ + /* scan all USB Devices */ + for (j = 0; j < USB_MAX_BUS; j++) + { + for (i = 0; i < USB_MAX_DEVICE; i++) + { + struct usb_device *dev = usb_get_dev_index(i, j); /* get device */ - if (dev == NULL) - break; + if (dev == NULL) + { + break; + } - xprintf("Try to register usb device %d,%d as mouse\r\n", i, j); - if (usb_mouse_register(dev) > 0) - return 1; - } - } - /* no USB Mouse found */ - return -1; + xprintf("Try to register usb device %d,%d as mouse\r\n", i, j); + if (usb_mouse_register(dev) > 0) + return 1; + } + } + /* no USB Mouse found */ + return -1; } /************************************************************************** @@ -114,184 +116,184 @@ int drv_usb_mouse_init(void) */ static void usb_kbd_send_code(unsigned char code) { - dbg("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code); + dbg("FIXME: usb_kbd_send_code 0x%x not implemented\r\n", code); } /* Interrupt service routine */ static int usb_mouse_irq(struct usb_device *dev) { #ifdef CONFIG_USB_INTERRUPT_POLLING - int level; + int level; #endif - int i, change = 0; - if ((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8)) - { - dbg("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len); - return 1; - } - for (i = 0; i < dev->irq_act_len; i++) - { - if (new[i] != old[i]) - { - change = 1; - break; - } - } - if (change) - { - char wheel = 0, buttons, old_buttons; - dbg("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]); + int i, change = 0; + if ((dev->irq_status != 0) || (dev->irq_act_len < 3) || (dev->irq_act_len > 8)) + { + dbg("USB MOUSE error %lX, len %d\r\n", dev->irq_status, dev->irq_act_len); + return 1; + } + for (i = 0; i < dev->irq_act_len; i++) + { + if (new[i] != old[i]) + { + change = 1; + break; + } + } + if (change) + { + char wheel = 0, buttons, old_buttons; + dbg("USB MOUSE len:%d %02X %02X %02X %02X %02X %02X\r\n", dev->irq_act_len, new[0], new[1], new[2], new[3], new[4], new[5]); #ifdef CONFIG_USB_INTERRUPT_POLLING - level = set_ipl(7); /* mask interrupts */ + level = set_ipl(7); /* mask interrupts */ #endif - if ((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */ - { - buttons = new[1]; - old_buttons = old[1]; - new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8; - new[1] = new[2]; - new[2] = new[3]; - wheel = new[4]; - } - else /* boot report */ - { - buttons = new[0]; - old_buttons = old[0]; - new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8; - if (dev->irq_act_len >= 3) - wheel = new[3]; - } - if ((buttons ^ old_buttons) & 4) /* 3rd button */ - { - if (buttons & 4) - { - usb_kbd_send_code(0x72); /* ENTER */ - usb_kbd_send_code(0xF2); - } - } - if (wheel != 0) /* actually like Eiffel */ - { + if ((dev->irq_act_len >= 6) && (new[0] == 1)) /* report-ID */ + { + buttons = new[1]; + old_buttons = old[1]; + new[0] = ((new[1] & 1) << 1) + ((new[1] & 2) >> 1) + 0xF8; + new[1] = new[2]; + new[2] = new[3]; + wheel = new[4]; + } + else /* boot report */ + { + buttons = new[0]; + old_buttons = old[0]; + new[0] = ((new[0] & 1) << 1) + ((new[0] & 2) >> 1) + 0xF8; + if (dev->irq_act_len >= 3) + wheel = new[3]; + } + if ((buttons ^ old_buttons) & 4) /* 3rd button */ + { + if (buttons & 4) + { + usb_kbd_send_code(0x72); /* ENTER */ + usb_kbd_send_code(0xF2); + } + } + if (wheel != 0) /* actually like Eiffel */ + { #define REPEAT_WHEEL 3 - int i; - if (wheel > 0) - { - for (i = 0; i < REPEAT_WHEEL; i++) - { - usb_kbd_send_code(0x48); /* UP */ - usb_kbd_send_code(0xC8); - } - } - else - { - for (i = 0; i < REPEAT_WHEEL; i++) - { - usb_kbd_send_code(0x50); /* DOWN */ - usb_kbd_send_code(0xD0); - } - } - } - xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n"); - //if(mousevec != NULL) - //call_mousevec(new, mousevec); + int i; + if (wheel > 0) + { + for (i = 0; i < REPEAT_WHEEL; i++) + { + usb_kbd_send_code(0x48); /* UP */ + usb_kbd_send_code(0xC8); + } + } + else + { + for (i = 0; i < REPEAT_WHEEL; i++) + { + usb_kbd_send_code(0x50); /* DOWN */ + usb_kbd_send_code(0xD0); + } + } + } + xprintf("FIXME: call_mousevec(new, mousevec) not implemented\r\n"); + //if(mousevec != NULL) + //call_mousevec(new, mousevec); #ifdef CONFIG_USB_INTERRUPT_POLLING - set_ipl(level); + set_ipl(level); #endif - old[0] = new[0]; - old[1] = new[1]; - old[2] = new[2]; - old[3] = new[3]; - old[4] = new[4]; - old[5] = new[5]; - } - return 1; /* install IRQ Handler again */ + old[0] = new[0]; + old[1] = new[1]; + old[2] = new[2]; + old[3] = new[3]; + old[4] = new[4]; + old[5] = new[5]; + } + return 1; /* install IRQ Handler again */ } /* probes the USB device dev for mouse type */ static int usb_mouse_probe(struct usb_device *dev, unsigned int ifnum) { - struct usb_interface_descriptor *iface; - struct usb_endpoint_descriptor *ep; - int pipe; - int maxp; + struct usb_interface_descriptor *iface; + struct usb_endpoint_descriptor *ep; + int pipe; + int maxp; - if (dev->descriptor.bNumConfigurations != 1) - { - dbg("dev->descriptor.bNumConfigurations != 1\r\n"); + if (dev->descriptor.bNumConfigurations != 1) + { + dbg("dev->descriptor.bNumConfigurations != 1\r\n"); - return 0; - } + return 0; + } - iface = &dev->config.if_desc[ifnum]; + iface = &dev->config.if_desc[ifnum]; - if (iface->bInterfaceClass != USB_CLASS_HID) - { - dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass); + if (iface->bInterfaceClass != USB_CLASS_HID) + { + dbg("iface->bInterfaceClass != USB_CLASS_HID (%d instead)\r\n", iface->bInterfaceClass); - return 0; - } + return 0; + } - if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT) - { - dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass); + if (iface->bInterfaceSubClass != USB_SUB_HID_BOOT) + { + dbg("iface->bInterfaceSubClass != USB_SUB_HID_BOOT (%d instead)\r\n", iface->bInterfaceSubClass); - return 0; - } + return 0; + } - if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE) - { - dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol); + if (iface->bInterfaceProtocol != USB_PROT_HID_MOUSE) + { + dbg("iface->bInterfaceProtocol != USB_PROT_HID_MOUSE (%d)\r\n", iface->bInterfaceProtocol); - return 0; - } + return 0; + } - if (iface->bNumEndpoints != 1) - { - dbg("iface->bNumEndpoints != 1\r\n"); + if (iface->bNumEndpoints != 1) + { + dbg("iface->bNumEndpoints != 1\r\n"); - return 0; - } + return 0; + } - ep = &iface->ep_desc[0]; + ep = &iface->ep_desc[0]; - if (!(ep->bEndpointAddress & 0x80)) - { - dbg("! ep->bEndpointAddress & 0x80\r\n"); + if (!(ep->bEndpointAddress & 0x80)) + { + dbg("! ep->bEndpointAddress & 0x80\r\n"); - return 0; - } + return 0; + } - if ((ep->bmAttributes & 3) != 3) - { - dbg("ep->bmAttributes & 3 != 3\r\n"); + if ((ep->bmAttributes & 3) != 3) + { + dbg("ep->bmAttributes & 3 != 3\r\n"); - return 0; - } + return 0; + } - new = (unsigned char *) driver_mem_alloc(8); - if (new == NULL) - { - dbg("new == NULL\r\n"); + new = (unsigned char *) driver_mem_alloc(8); + if (new == NULL) + { + dbg("new == NULL\r\n"); - return 0; - } + return 0; + } - dbg("USB MOUSE found set protocol...\r\n"); + dbg("USB MOUSE found set protocol...\r\n"); - /* ok, we found a USB Mouse, install it */ - pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); - maxp = usb_maxpacket(dev, pipe); + /* ok, we found a USB Mouse, install it */ + pipe = usb_rcvintpipe(dev, ep->bEndpointAddress); + maxp = usb_maxpacket(dev, pipe); // if(maxp < 6) // usb_set_protocol(dev, iface->bInterfaceNumber, 0); /* boot */ // else - usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */ - dbg("USB MOUSE found set idle...\r\n"); - usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */ - memset(&new[0], 0, 8); - memset(&old[0], 0, 8); - dev->irq_handle = usb_mouse_irq; - dbg("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp); - usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval); - return 1; + usb_set_protocol(dev, iface->bInterfaceNumber, 1); /* report */ + dbg("USB MOUSE found set idle...\r\n"); + usb_set_idle(dev, iface->bInterfaceNumber, 0, 0); /* report infinite */ + memset(&new[0], 0, 8); + memset(&old[0], 0, 8); + dev->irq_handle = usb_mouse_irq; + dbg("USB MOUSE enable interrupt pipe (maxp: %d)...\r\n", maxp); + usb_submit_int_msg(dev, pipe, &new[0], maxp > 8 ? 8 : maxp, ep->bInterval); + return 1; }