amd5536udc_pci.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * amd5536udc_pci.c -- AMD 5536 UDC high/full speed USB device controller
  3. *
  4. * Copyright (C) 2005-2007 AMD (http://www.amd.com)
  5. * Author: Thomas Dahlmann
  6. *
  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.
  11. */
  12. /*
  13. * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
  14. * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
  15. * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
  16. *
  17. * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
  18. * be used as host port) and UOC bits PAD_EN and APU are set (should be done
  19. * by BIOS init).
  20. *
  21. * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
  22. * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
  23. * can be used with gadget ether.
  24. *
  25. * This file does pci device registration, and the core driver implementation
  26. * is done in amd5536udc.c
  27. *
  28. * The driver is split so as to use the core UDC driver which is based on
  29. * Synopsys device controller IP (different than HS OTG IP) in UDCs
  30. * integrated to SoC platforms.
  31. *
  32. */
  33. /* Driver strings */
  34. #define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
  35. /* system */
  36. #include <linux/device.h>
  37. #include <linux/dmapool.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/io.h>
  40. #include <linux/irq.h>
  41. #include <linux/module.h>
  42. #include <linux/moduleparam.h>
  43. #include <linux/prefetch.h>
  44. #include <linux/pci.h>
  45. /* udc specific */
  46. #include "amd5536udc.h"
  47. /* pointer to device object */
  48. static struct udc *udc;
  49. /* description */
  50. static const char mod_desc[] = UDC_MOD_DESCRIPTION;
  51. static const char name[] = "amd5536udc-pci";
  52. /* Reset all pci context */
  53. static void udc_pci_remove(struct pci_dev *pdev)
  54. {
  55. struct udc *dev;
  56. dev = pci_get_drvdata(pdev);
  57. usb_del_gadget_udc(&udc->gadget);
  58. /* gadget driver must not be registered */
  59. if (WARN_ON(dev->driver))
  60. return;
  61. /* dma pool cleanup */
  62. free_dma_pools(dev);
  63. /* reset controller */
  64. writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg);
  65. free_irq(pdev->irq, dev);
  66. iounmap(dev->virt_addr);
  67. release_mem_region(pci_resource_start(pdev, 0),
  68. pci_resource_len(pdev, 0));
  69. pci_disable_device(pdev);
  70. udc_remove(dev);
  71. }
  72. /* Called by pci bus driver to init pci context */
  73. static int udc_pci_probe(
  74. struct pci_dev *pdev,
  75. const struct pci_device_id *id
  76. )
  77. {
  78. struct udc *dev;
  79. unsigned long resource;
  80. unsigned long len;
  81. int retval = 0;
  82. /* one udc only */
  83. if (udc) {
  84. dev_dbg(&pdev->dev, "already probed\n");
  85. return -EBUSY;
  86. }
  87. /* init */
  88. dev = kzalloc(sizeof(struct udc), GFP_KERNEL);
  89. if (!dev)
  90. return -ENOMEM;
  91. /* pci setup */
  92. if (pci_enable_device(pdev) < 0) {
  93. retval = -ENODEV;
  94. goto err_pcidev;
  95. }
  96. /* PCI resource allocation */
  97. resource = pci_resource_start(pdev, 0);
  98. len = pci_resource_len(pdev, 0);
  99. if (!request_mem_region(resource, len, name)) {
  100. dev_dbg(&pdev->dev, "pci device used already\n");
  101. retval = -EBUSY;
  102. goto err_memreg;
  103. }
  104. dev->virt_addr = ioremap_nocache(resource, len);
  105. if (!dev->virt_addr) {
  106. dev_dbg(&pdev->dev, "start address cannot be mapped\n");
  107. retval = -EFAULT;
  108. goto err_ioremap;
  109. }
  110. if (!pdev->irq) {
  111. dev_err(&pdev->dev, "irq not set\n");
  112. retval = -ENODEV;
  113. goto err_irq;
  114. }
  115. spin_lock_init(&dev->lock);
  116. /* udc csr registers base */
  117. dev->csr = dev->virt_addr + UDC_CSR_ADDR;
  118. /* dev registers base */
  119. dev->regs = dev->virt_addr + UDC_DEVCFG_ADDR;
  120. /* ep registers base */
  121. dev->ep_regs = dev->virt_addr + UDC_EPREGS_ADDR;
  122. /* fifo's base */
  123. dev->rxfifo = (u32 __iomem *)(dev->virt_addr + UDC_RXFIFO_ADDR);
  124. dev->txfifo = (u32 __iomem *)(dev->virt_addr + UDC_TXFIFO_ADDR);
  125. if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) {
  126. dev_dbg(&pdev->dev, "request_irq(%d) fail\n", pdev->irq);
  127. retval = -EBUSY;
  128. goto err_irq;
  129. }
  130. pci_set_drvdata(pdev, dev);
  131. /* chip revision for Hs AMD5536 */
  132. dev->chiprev = pdev->revision;
  133. pci_set_master(pdev);
  134. pci_try_set_mwi(pdev);
  135. /* init dma pools */
  136. if (use_dma) {
  137. retval = init_dma_pools(dev);
  138. if (retval != 0)
  139. goto err_dma;
  140. }
  141. dev->phys_addr = resource;
  142. dev->irq = pdev->irq;
  143. dev->pdev = pdev;
  144. /* general probing */
  145. if (udc_probe(dev)) {
  146. retval = -ENODEV;
  147. goto err_probe;
  148. }
  149. return 0;
  150. err_probe:
  151. if (use_dma)
  152. free_dma_pools(dev);
  153. err_dma:
  154. free_irq(pdev->irq, dev);
  155. err_irq:
  156. iounmap(dev->virt_addr);
  157. err_ioremap:
  158. release_mem_region(resource, len);
  159. err_memreg:
  160. pci_disable_device(pdev);
  161. err_pcidev:
  162. kfree(dev);
  163. return retval;
  164. }
  165. /* PCI device parameters */
  166. static const struct pci_device_id pci_id[] = {
  167. {
  168. PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096),
  169. .class = PCI_CLASS_SERIAL_USB_DEVICE,
  170. .class_mask = 0xffffffff,
  171. },
  172. {},
  173. };
  174. MODULE_DEVICE_TABLE(pci, pci_id);
  175. /* PCI functions */
  176. static struct pci_driver udc_pci_driver = {
  177. .name = (char *) name,
  178. .id_table = pci_id,
  179. .probe = udc_pci_probe,
  180. .remove = udc_pci_remove,
  181. };
  182. module_pci_driver(udc_pci_driver);
  183. MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION);
  184. MODULE_AUTHOR("Thomas Dahlmann");
  185. MODULE_LICENSE("GPL");