Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 1 | /* |
| 2 | * ci13xxx_pci.c - MIPS USB IP core family device controller |
| 3 | * |
| 4 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. |
| 5 | * |
| 6 | * Author: David Lopo |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 13 | #include <linux/platform_device.h> |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/pci.h> |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/usb/gadget.h> |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 18 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 19 | #include "ci13xxx_udc.h" |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 20 | |
| 21 | /* driver name */ |
| 22 | #define UDC_DRIVER_NAME "ci13xxx_pci" |
| 23 | |
| 24 | /****************************************************************************** |
| 25 | * PCI block |
| 26 | *****************************************************************************/ |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 27 | struct ci13xxx_udc_driver pci_driver = { |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 28 | .name = UDC_DRIVER_NAME, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 29 | .capoffset = DEF_CAPOFFSET, |
| 30 | }; |
| 31 | |
| 32 | struct ci13xxx_udc_driver langwell_pci_driver = { |
| 33 | .name = UDC_DRIVER_NAME, |
| 34 | .capoffset = 0, |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 35 | }; |
| 36 | |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 37 | /** |
| 38 | * ci13xxx_pci_probe: PCI probe |
| 39 | * @pdev: USB device controller being probed |
| 40 | * @id: PCI hotplug ID connecting controller to UDC framework |
| 41 | * |
| 42 | * This function returns an error code |
| 43 | * Allocates basic PCI resources for this USB device controller, and then |
| 44 | * invokes the udc_probe() method to start the UDC associated with it |
| 45 | */ |
| 46 | static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev, |
| 47 | const struct pci_device_id *id) |
| 48 | { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 49 | struct ci13xxx_udc_driver *driver = (void *)id->driver_data; |
| 50 | struct platform_device *plat_ci; |
| 51 | struct resource res[3]; |
| 52 | int retval = 0, nres = 2; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 53 | |
| 54 | if (id == NULL) |
| 55 | return -EINVAL; |
| 56 | |
| 57 | retval = pci_enable_device(pdev); |
| 58 | if (retval) |
| 59 | goto done; |
| 60 | |
| 61 | if (!pdev->irq) { |
| 62 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); |
| 63 | retval = -ENODEV; |
| 64 | goto disable_device; |
| 65 | } |
| 66 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 67 | pci_set_power_state(pdev, PCI_D0); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 68 | pci_set_master(pdev); |
| 69 | pci_try_set_mwi(pdev); |
| 70 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 71 | plat_ci = platform_device_alloc("ci_udc", -1); |
| 72 | if (!plat_ci) { |
| 73 | dev_err(&pdev->dev, "can't allocate ci_udc platform device\n"); |
| 74 | retval = -ENOMEM; |
| 75 | goto disable_device; |
| 76 | } |
Alexander Shishkin | f9df839 | 2012-05-04 16:47:16 +0300 | [diff] [blame] | 77 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 78 | memset(res, 0, sizeof(res)); |
| 79 | res[0].start = pci_resource_start(pdev, 0); |
| 80 | res[0].end = pci_resource_end(pdev, 0); |
| 81 | res[0].flags = IORESOURCE_MEM; |
| 82 | res[1].start = pdev->irq; |
| 83 | res[1].flags = IORESOURCE_IRQ; |
| 84 | |
| 85 | retval = platform_device_add_resources(plat_ci, res, nres); |
| 86 | if (retval) { |
| 87 | dev_err(&pdev->dev, "can't add resources to platform device\n"); |
| 88 | goto put_platform; |
| 89 | } |
| 90 | |
| 91 | retval = platform_device_add_data(plat_ci, driver, sizeof(*driver)); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 92 | if (retval) |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 93 | goto put_platform; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 94 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 95 | dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask); |
| 96 | plat_ci->dev.dma_mask = pdev->dev.dma_mask; |
| 97 | plat_ci->dev.dma_parms = pdev->dev.dma_parms; |
| 98 | plat_ci->dev.parent = &pdev->dev; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 99 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 100 | pci_set_drvdata(pdev, plat_ci); |
| 101 | |
| 102 | retval = platform_device_add(plat_ci); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 103 | if (retval) |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 104 | goto put_platform; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 108 | put_platform: |
| 109 | pci_set_drvdata(pdev, NULL); |
| 110 | platform_device_put(plat_ci); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 111 | disable_device: |
| 112 | pci_disable_device(pdev); |
| 113 | done: |
| 114 | return retval; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * ci13xxx_pci_remove: PCI remove |
| 119 | * @pdev: USB Device Controller being removed |
| 120 | * |
| 121 | * Reverses the effect of ci13xxx_pci_probe(), |
| 122 | * first invoking the udc_remove() and then releases |
| 123 | * all PCI resources allocated for this USB device controller |
| 124 | */ |
| 125 | static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev) |
| 126 | { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 127 | struct platform_device *plat_ci = pci_get_drvdata(pdev); |
| 128 | |
| 129 | platform_device_unregister(plat_ci); |
| 130 | pci_set_drvdata(pdev, NULL); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 131 | pci_disable_device(pdev); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * PCI device table |
| 136 | * PCI device structure |
| 137 | * |
| 138 | * Check "pci.h" for details |
| 139 | */ |
| 140 | static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame^] | 141 | { |
| 142 | PCI_DEVICE(0x153F, 0x1004), |
| 143 | .driver_data = (kernel_ulong_t)&pci_driver, |
| 144 | }, |
| 145 | { |
| 146 | PCI_DEVICE(0x153F, 0x1006), |
| 147 | .driver_data = (kernel_ulong_t)&pci_driver, |
| 148 | }, |
| 149 | { |
| 150 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811), |
| 151 | .driver_data = (kernel_ulong_t)&langwell_pci_driver, |
| 152 | }, |
| 153 | { |
| 154 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829), |
| 155 | .driver_data = (kernel_ulong_t)&langwell_pci_driver, |
| 156 | }, |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 157 | { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } |
| 158 | }; |
| 159 | MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table); |
| 160 | |
| 161 | static struct pci_driver ci13xxx_pci_driver = { |
| 162 | .name = UDC_DRIVER_NAME, |
| 163 | .id_table = ci13xxx_pci_id_table, |
| 164 | .probe = ci13xxx_pci_probe, |
| 165 | .remove = __devexit_p(ci13xxx_pci_remove), |
| 166 | }; |
| 167 | |
Axel Lin | 3cdb772 | 2012-04-04 22:14:58 +0800 | [diff] [blame] | 168 | module_pci_driver(ci13xxx_pci_driver); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 169 | |
| 170 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); |
| 171 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); |
| 172 | MODULE_LICENSE("GPL"); |
| 173 | MODULE_VERSION("June 2008"); |