1 // SPDX-License-Identifier: GPL-2.0+
3 * amd5536udc_pci.c -- AMD 5536 UDC high/full speed USB device controller
5 * Copyright (C) 2005-2007 AMD (http://www.amd.com)
6 * Author: Thomas Dahlmann
10 * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
11 * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
12 * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
14 * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
15 * be used as host port) and UOC bits PAD_EN and APU are set (should be done
18 * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
19 * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
20 * can be used with gadget ether.
22 * This file does pci device registration, and the core driver implementation
23 * is done in amd5536udc.c
25 * The driver is split so as to use the core UDC driver which is based on
26 * Synopsys device controller IP (different than HS OTG IP) in UDCs
27 * integrated to SoC platforms.
32 #define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
35 #include <linux/device.h>
36 #include <linux/dmapool.h>
37 #include <linux/interrupt.h>
39 #include <linux/irq.h>
40 #include <linux/module.h>
41 #include <linux/moduleparam.h>
42 #include <linux/prefetch.h>
43 #include <linux/pci.h>
46 #include "amd5536udc.h"
48 /* pointer to device object */
49 static struct udc
*udc
;
52 static const char mod_desc
[] = UDC_MOD_DESCRIPTION
;
53 static const char name
[] = "amd5536udc-pci";
55 /* Reset all pci context */
56 static void udc_pci_remove(struct pci_dev
*pdev
)
60 dev
= pci_get_drvdata(pdev
);
62 usb_del_gadget_udc(&udc
->gadget
);
63 /* gadget driver must not be registered */
64 if (WARN_ON(dev
->driver
))
67 /* dma pool cleanup */
70 /* reset controller */
71 writel(AMD_BIT(UDC_DEVCFG_SOFTRESET
), &dev
->regs
->cfg
);
72 free_irq(pdev
->irq
, dev
);
73 iounmap(dev
->virt_addr
);
74 release_mem_region(pci_resource_start(pdev
, 0),
75 pci_resource_len(pdev
, 0));
76 pci_disable_device(pdev
);
81 /* Called by pci bus driver to init pci context */
82 static int udc_pci_probe(
84 const struct pci_device_id
*id
88 unsigned long resource
;
94 dev_dbg(&pdev
->dev
, "already probed\n");
99 dev
= kzalloc(sizeof(struct udc
), GFP_KERNEL
);
104 if (pci_enable_device(pdev
) < 0) {
109 /* PCI resource allocation */
110 resource
= pci_resource_start(pdev
, 0);
111 len
= pci_resource_len(pdev
, 0);
113 if (!request_mem_region(resource
, len
, name
)) {
114 dev_dbg(&pdev
->dev
, "pci device used already\n");
119 dev
->virt_addr
= ioremap_nocache(resource
, len
);
120 if (!dev
->virt_addr
) {
121 dev_dbg(&pdev
->dev
, "start address cannot be mapped\n");
127 dev_err(&pdev
->dev
, "irq not set\n");
132 spin_lock_init(&dev
->lock
);
133 /* udc csr registers base */
134 dev
->csr
= dev
->virt_addr
+ UDC_CSR_ADDR
;
135 /* dev registers base */
136 dev
->regs
= dev
->virt_addr
+ UDC_DEVCFG_ADDR
;
137 /* ep registers base */
138 dev
->ep_regs
= dev
->virt_addr
+ UDC_EPREGS_ADDR
;
140 dev
->rxfifo
= (u32 __iomem
*)(dev
->virt_addr
+ UDC_RXFIFO_ADDR
);
141 dev
->txfifo
= (u32 __iomem
*)(dev
->virt_addr
+ UDC_TXFIFO_ADDR
);
143 if (request_irq(pdev
->irq
, udc_irq
, IRQF_SHARED
, name
, dev
) != 0) {
144 dev_dbg(&pdev
->dev
, "request_irq(%d) fail\n", pdev
->irq
);
149 pci_set_drvdata(pdev
, dev
);
151 /* chip revision for Hs AMD5536 */
152 dev
->chiprev
= pdev
->revision
;
154 pci_set_master(pdev
);
155 pci_try_set_mwi(pdev
);
159 retval
= init_dma_pools(dev
);
164 dev
->phys_addr
= resource
;
165 dev
->irq
= pdev
->irq
;
167 dev
->dev
= &pdev
->dev
;
169 /* general probing */
170 if (udc_probe(dev
)) {
180 free_irq(pdev
->irq
, dev
);
182 iounmap(dev
->virt_addr
);
184 release_mem_region(resource
, len
);
186 pci_disable_device(pdev
);
192 /* PCI device parameters */
193 static const struct pci_device_id pci_id
[] = {
195 PCI_DEVICE(PCI_VENDOR_ID_AMD
, 0x2096),
196 .class = PCI_CLASS_SERIAL_USB_DEVICE
,
197 .class_mask
= 0xffffffff,
201 MODULE_DEVICE_TABLE(pci
, pci_id
);
204 static struct pci_driver udc_pci_driver
= {
205 .name
= (char *) name
,
207 .probe
= udc_pci_probe
,
208 .remove
= udc_pci_remove
,
210 module_pci_driver(udc_pci_driver
);
212 MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION
);
213 MODULE_AUTHOR("Thomas Dahlmann");
214 MODULE_LICENSE("GPL");