2 * amd5536udc_pci.c -- AMD 5536 UDC high/full speed USB device controller
4 * Copyright (C) 2005-2007 AMD (http://www.amd.com)
5 * Author: Thomas Dahlmann
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
14 * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
15 * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
16 * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
18 * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
19 * be used as host port) and UOC bits PAD_EN and APU are set (should be done
22 * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
23 * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
24 * can be used with gadget ether.
26 * This file does pci device registration, and the core driver implementation
27 * is done in amd5536udc.c
29 * The driver is split so as to use the core UDC driver which is based on
30 * Synopsys device controller IP (different than HS OTG IP) in UDCs
31 * integrated to SoC platforms.
36 #define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
39 #include <linux/device.h>
40 #include <linux/dmapool.h>
41 #include <linux/interrupt.h>
43 #include <linux/irq.h>
44 #include <linux/module.h>
45 #include <linux/moduleparam.h>
46 #include <linux/prefetch.h>
47 #include <linux/pci.h>
50 #include "amd5536udc.h"
52 /* pointer to device object */
53 static struct udc *udc;
56 static const char mod_desc[] = UDC_MOD_DESCRIPTION;
57 static const char name[] = "amd5536udc-pci";
59 /* Reset all pci context */
60 static void udc_pci_remove(struct pci_dev *pdev)
64 dev = pci_get_drvdata(pdev);
66 usb_del_gadget_udc(&udc->gadget);
67 /* gadget driver must not be registered */
68 if (WARN_ON(dev->driver))
71 /* dma pool cleanup */
74 /* reset controller */
75 writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg);
76 free_irq(pdev->irq, dev);
77 iounmap(dev->virt_addr);
78 release_mem_region(pci_resource_start(pdev, 0),
79 pci_resource_len(pdev, 0));
80 pci_disable_device(pdev);
85 /* Called by pci bus driver to init pci context */
86 static int udc_pci_probe(
88 const struct pci_device_id *id
92 unsigned long resource;
98 dev_dbg(&pdev->dev, "already probed\n");
103 dev = kzalloc(sizeof(struct udc), GFP_KERNEL);
108 if (pci_enable_device(pdev) < 0) {
113 /* PCI resource allocation */
114 resource = pci_resource_start(pdev, 0);
115 len = pci_resource_len(pdev, 0);
117 if (!request_mem_region(resource, len, name)) {
118 dev_dbg(&pdev->dev, "pci device used already\n");
123 dev->virt_addr = ioremap_nocache(resource, len);
124 if (!dev->virt_addr) {
125 dev_dbg(&pdev->dev, "start address cannot be mapped\n");
131 dev_err(&pdev->dev, "irq not set\n");
136 spin_lock_init(&dev->lock);
137 /* udc csr registers base */
138 dev->csr = dev->virt_addr + UDC_CSR_ADDR;
139 /* dev registers base */
140 dev->regs = dev->virt_addr + UDC_DEVCFG_ADDR;
141 /* ep registers base */
142 dev->ep_regs = dev->virt_addr + UDC_EPREGS_ADDR;
144 dev->rxfifo = (u32 __iomem *)(dev->virt_addr + UDC_RXFIFO_ADDR);
145 dev->txfifo = (u32 __iomem *)(dev->virt_addr + UDC_TXFIFO_ADDR);
147 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) {
148 dev_dbg(&pdev->dev, "request_irq(%d) fail\n", pdev->irq);
153 pci_set_drvdata(pdev, dev);
155 /* chip revision for Hs AMD5536 */
156 dev->chiprev = pdev->revision;
158 pci_set_master(pdev);
159 pci_try_set_mwi(pdev);
161 dev->phys_addr = resource;
162 dev->irq = pdev->irq;
164 dev->dev = &pdev->dev;
168 retval = init_dma_pools(dev);
173 /* general probing */
174 if (udc_probe(dev)) {
184 free_irq(pdev->irq, dev);
186 iounmap(dev->virt_addr);
188 release_mem_region(resource, len);
190 pci_disable_device(pdev);
196 /* PCI device parameters */
197 static const struct pci_device_id pci_id[] = {
199 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096),
200 .class = PCI_CLASS_SERIAL_USB_DEVICE,
201 .class_mask = 0xffffffff,
205 MODULE_DEVICE_TABLE(pci, pci_id);
208 static struct pci_driver udc_pci_driver = {
209 .name = (char *) name,
211 .probe = udc_pci_probe,
212 .remove = udc_pci_remove,
214 module_pci_driver(udc_pci_driver);
216 MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION);
217 MODULE_AUTHOR("Thomas Dahlmann");
218 MODULE_LICENSE("GPL");