isp1760-if.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. /*
  2. * Glue code for the ISP1760 driver and bus
  3. * Currently there is support for
  4. * - OpenFirmware
  5. * - PCI
  6. *
  7. * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
  8. *
  9. */
  10. #include <linux/usb.h>
  11. #include <linux/io.h>
  12. #include "../core/hcd.h"
  13. #include "isp1760-hcd.h"
  14. #ifdef CONFIG_PPC_OF
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. #endif
  18. #ifdef CONFIG_PCI
  19. #include <linux/pci.h>
  20. #endif
  21. #ifdef CONFIG_PPC_OF
  22. static int of_isp1760_probe(struct of_device *dev,
  23. const struct of_device_id *match)
  24. {
  25. struct usb_hcd *hcd;
  26. struct device_node *dp = dev->node;
  27. struct resource *res;
  28. struct resource memory;
  29. struct of_irq oirq;
  30. int virq;
  31. u64 res_len;
  32. int ret;
  33. const unsigned int *prop;
  34. unsigned int devflags = 0;
  35. ret = of_address_to_resource(dp, 0, &memory);
  36. if (ret)
  37. return -ENXIO;
  38. res = request_mem_region(memory.start, memory.end - memory.start + 1,
  39. dev_name(&dev->dev));
  40. if (!res)
  41. return -EBUSY;
  42. res_len = memory.end - memory.start + 1;
  43. if (of_irq_map_one(dp, 0, &oirq)) {
  44. ret = -ENODEV;
  45. goto release_reg;
  46. }
  47. virq = irq_create_of_mapping(oirq.controller, oirq.specifier,
  48. oirq.size);
  49. if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
  50. devflags |= ISP1760_FLAG_ISP1761;
  51. /* Some systems wire up only 16 of the 32 data lines */
  52. prop = of_get_property(dp, "bus-width", NULL);
  53. if (prop && *prop == 16)
  54. devflags |= ISP1760_FLAG_BUS_WIDTH_16;
  55. if (of_get_property(dp, "port1-otg", NULL) != NULL)
  56. devflags |= ISP1760_FLAG_OTG_EN;
  57. if (of_get_property(dp, "analog-oc", NULL) != NULL)
  58. devflags |= ISP1760_FLAG_ANALOG_OC;
  59. if (of_get_property(dp, "dack-polarity", NULL) != NULL)
  60. devflags |= ISP1760_FLAG_DACK_POL_HIGH;
  61. if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
  62. devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
  63. hcd = isp1760_register(memory.start, res_len, virq,
  64. IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
  65. devflags);
  66. if (IS_ERR(hcd)) {
  67. ret = PTR_ERR(hcd);
  68. goto release_reg;
  69. }
  70. dev_set_drvdata(&dev->dev, hcd);
  71. return ret;
  72. release_reg:
  73. release_mem_region(memory.start, memory.end - memory.start + 1);
  74. return ret;
  75. }
  76. static int of_isp1760_remove(struct of_device *dev)
  77. {
  78. struct usb_hcd *hcd = dev_get_drvdata(&dev->dev);
  79. dev_set_drvdata(&dev->dev, NULL);
  80. usb_remove_hcd(hcd);
  81. iounmap(hcd->regs);
  82. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  83. usb_put_hcd(hcd);
  84. return 0;
  85. }
  86. static struct of_device_id of_isp1760_match[] = {
  87. {
  88. .compatible = "nxp,usb-isp1760",
  89. },
  90. {
  91. .compatible = "nxp,usb-isp1761",
  92. },
  93. { },
  94. };
  95. MODULE_DEVICE_TABLE(of, of_isp1760_match);
  96. static struct of_platform_driver isp1760_of_driver = {
  97. .name = "nxp-isp1760",
  98. .match_table = of_isp1760_match,
  99. .probe = of_isp1760_probe,
  100. .remove = of_isp1760_remove,
  101. };
  102. #endif
  103. #ifdef CONFIG_PCI
  104. static int __devinit isp1761_pci_probe(struct pci_dev *dev,
  105. const struct pci_device_id *id)
  106. {
  107. u8 latency, limit;
  108. __u32 reg_data;
  109. int retry_count;
  110. struct usb_hcd *hcd;
  111. unsigned int devflags = 0;
  112. int ret_status = 0;
  113. resource_size_t pci_mem_phy0;
  114. resource_size_t memlength;
  115. u8 __iomem *chip_addr;
  116. u8 __iomem *iobase;
  117. resource_size_t nxp_pci_io_base;
  118. resource_size_t iolength;
  119. if (usb_disabled())
  120. return -ENODEV;
  121. if (pci_enable_device(dev) < 0)
  122. return -ENODEV;
  123. if (!dev->irq)
  124. return -ENODEV;
  125. /* Grab the PLX PCI mem maped port start address we need */
  126. nxp_pci_io_base = pci_resource_start(dev, 0);
  127. iolength = pci_resource_len(dev, 0);
  128. if (!request_mem_region(nxp_pci_io_base, iolength, "ISP1761 IO MEM")) {
  129. printk(KERN_ERR "request region #1\n");
  130. return -EBUSY;
  131. }
  132. iobase = ioremap_nocache(nxp_pci_io_base, iolength);
  133. if (!iobase) {
  134. printk(KERN_ERR "ioremap #1\n");
  135. ret_status = -ENOMEM;
  136. goto cleanup1;
  137. }
  138. /* Grab the PLX PCI shared memory of the ISP 1761 we need */
  139. pci_mem_phy0 = pci_resource_start(dev, 3);
  140. memlength = pci_resource_len(dev, 3);
  141. if (memlength < 0xffff) {
  142. printk(KERN_ERR "memory length for this resource is wrong\n");
  143. ret_status = -ENOMEM;
  144. goto cleanup2;
  145. }
  146. if (!request_mem_region(pci_mem_phy0, memlength, "ISP-PCI")) {
  147. printk(KERN_ERR "host controller already in use\n");
  148. ret_status = -EBUSY;
  149. goto cleanup2;
  150. }
  151. /* map available memory */
  152. chip_addr = ioremap_nocache(pci_mem_phy0,memlength);
  153. if (!chip_addr) {
  154. printk(KERN_ERR "Error ioremap failed\n");
  155. ret_status = -ENOMEM;
  156. goto cleanup3;
  157. }
  158. /* bad pci latencies can contribute to overruns */
  159. pci_read_config_byte(dev, PCI_LATENCY_TIMER, &latency);
  160. if (latency) {
  161. pci_read_config_byte(dev, PCI_MAX_LAT, &limit);
  162. if (limit && limit < latency)
  163. pci_write_config_byte(dev, PCI_LATENCY_TIMER, limit);
  164. }
  165. /* Try to check whether we can access Scratch Register of
  166. * Host Controller or not. The initial PCI access is retried until
  167. * local init for the PCI bridge is completed
  168. */
  169. retry_count = 20;
  170. reg_data = 0;
  171. while ((reg_data != 0xFACE) && retry_count) {
  172. /*by default host is in 16bit mode, so
  173. * io operations at this stage must be 16 bit
  174. * */
  175. writel(0xface, chip_addr + HC_SCRATCH_REG);
  176. udelay(100);
  177. reg_data = readl(chip_addr + HC_SCRATCH_REG) & 0x0000ffff;
  178. retry_count--;
  179. }
  180. iounmap(chip_addr);
  181. /* Host Controller presence is detected by writing to scratch register
  182. * and reading back and checking the contents are same or not
  183. */
  184. if (reg_data != 0xFACE) {
  185. dev_err(&dev->dev, "scratch register mismatch %x\n", reg_data);
  186. ret_status = -ENOMEM;
  187. goto cleanup3;
  188. }
  189. pci_set_master(dev);
  190. /* configure PLX PCI chip to pass interrupts */
  191. #define PLX_INT_CSR_REG 0x68
  192. reg_data = readl(iobase + PLX_INT_CSR_REG);
  193. reg_data |= 0x900;
  194. writel(reg_data, iobase + PLX_INT_CSR_REG);
  195. dev->dev.dma_mask = NULL;
  196. hcd = isp1760_register(pci_mem_phy0, memlength, dev->irq,
  197. IRQF_SHARED | IRQF_DISABLED, &dev->dev, dev_name(&dev->dev),
  198. devflags);
  199. if (IS_ERR(hcd)) {
  200. ret_status = -ENODEV;
  201. goto cleanup3;
  202. }
  203. /* done with PLX IO access */
  204. iounmap(iobase);
  205. release_mem_region(nxp_pci_io_base, iolength);
  206. pci_set_drvdata(dev, hcd);
  207. return 0;
  208. cleanup3:
  209. release_mem_region(pci_mem_phy0, memlength);
  210. cleanup2:
  211. iounmap(iobase);
  212. cleanup1:
  213. release_mem_region(nxp_pci_io_base, iolength);
  214. return ret_status;
  215. }
  216. static void isp1761_pci_remove(struct pci_dev *dev)
  217. {
  218. struct usb_hcd *hcd;
  219. hcd = pci_get_drvdata(dev);
  220. usb_remove_hcd(hcd);
  221. iounmap(hcd->regs);
  222. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  223. usb_put_hcd(hcd);
  224. pci_disable_device(dev);
  225. }
  226. static void isp1761_pci_shutdown(struct pci_dev *dev)
  227. {
  228. printk(KERN_ERR "ips1761_pci_shutdown\n");
  229. }
  230. static const struct pci_device_id isp1760_plx [] = {
  231. {
  232. .class = PCI_CLASS_BRIDGE_OTHER << 8,
  233. .class_mask = ~0,
  234. .vendor = PCI_VENDOR_ID_PLX,
  235. .device = 0x5406,
  236. .subvendor = PCI_VENDOR_ID_PLX,
  237. .subdevice = 0x9054,
  238. },
  239. { }
  240. };
  241. MODULE_DEVICE_TABLE(pci, isp1760_plx);
  242. static struct pci_driver isp1761_pci_driver = {
  243. .name = "isp1760",
  244. .id_table = isp1760_plx,
  245. .probe = isp1761_pci_probe,
  246. .remove = isp1761_pci_remove,
  247. .shutdown = isp1761_pci_shutdown,
  248. };
  249. #endif
  250. static int __init isp1760_init(void)
  251. {
  252. int ret;
  253. init_kmem_once();
  254. #ifdef CONFIG_PPC_OF
  255. ret = of_register_platform_driver(&isp1760_of_driver);
  256. if (ret) {
  257. deinit_kmem_cache();
  258. return ret;
  259. }
  260. #endif
  261. #ifdef CONFIG_PCI
  262. ret = pci_register_driver(&isp1761_pci_driver);
  263. if (ret)
  264. goto unreg_of;
  265. #endif
  266. return ret;
  267. #ifdef CONFIG_PCI
  268. unreg_of:
  269. #endif
  270. #ifdef CONFIG_PPC_OF
  271. of_unregister_platform_driver(&isp1760_of_driver);
  272. #endif
  273. deinit_kmem_cache();
  274. return ret;
  275. }
  276. module_init(isp1760_init);
  277. static void __exit isp1760_exit(void)
  278. {
  279. #ifdef CONFIG_PPC_OF
  280. of_unregister_platform_driver(&isp1760_of_driver);
  281. #endif
  282. #ifdef CONFIG_PCI
  283. pci_unregister_driver(&isp1761_pci_driver);
  284. #endif
  285. deinit_kmem_cache();
  286. }
  287. module_exit(isp1760_exit);