1197ba5f4SPaul Zimmerman /* 2197ba5f4SPaul Zimmerman * pci.c - DesignWare HS OTG Controller PCI driver 3197ba5f4SPaul Zimmerman * 4197ba5f4SPaul Zimmerman * Copyright (C) 2004-2013 Synopsys, Inc. 5197ba5f4SPaul Zimmerman * 6197ba5f4SPaul Zimmerman * Redistribution and use in source and binary forms, with or without 7197ba5f4SPaul Zimmerman * modification, are permitted provided that the following conditions 8197ba5f4SPaul Zimmerman * are met: 9197ba5f4SPaul Zimmerman * 1. Redistributions of source code must retain the above copyright 10197ba5f4SPaul Zimmerman * notice, this list of conditions, and the following disclaimer, 11197ba5f4SPaul Zimmerman * without modification. 12197ba5f4SPaul Zimmerman * 2. Redistributions in binary form must reproduce the above copyright 13197ba5f4SPaul Zimmerman * notice, this list of conditions and the following disclaimer in the 14197ba5f4SPaul Zimmerman * documentation and/or other materials provided with the distribution. 15197ba5f4SPaul Zimmerman * 3. The names of the above-listed copyright holders may not be used 16197ba5f4SPaul Zimmerman * to endorse or promote products derived from this software without 17197ba5f4SPaul Zimmerman * specific prior written permission. 18197ba5f4SPaul Zimmerman * 19197ba5f4SPaul Zimmerman * ALTERNATIVELY, this software may be distributed under the terms of the 20197ba5f4SPaul Zimmerman * GNU General Public License ("GPL") as published by the Free Software 21197ba5f4SPaul Zimmerman * Foundation; either version 2 of the License, or (at your option) any 22197ba5f4SPaul Zimmerman * later version. 23197ba5f4SPaul Zimmerman * 24197ba5f4SPaul Zimmerman * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25197ba5f4SPaul Zimmerman * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 26197ba5f4SPaul Zimmerman * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27197ba5f4SPaul Zimmerman * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28197ba5f4SPaul Zimmerman * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29197ba5f4SPaul Zimmerman * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30197ba5f4SPaul Zimmerman * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31197ba5f4SPaul Zimmerman * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32197ba5f4SPaul Zimmerman * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33197ba5f4SPaul Zimmerman * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34197ba5f4SPaul Zimmerman * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35197ba5f4SPaul Zimmerman */ 36197ba5f4SPaul Zimmerman 37197ba5f4SPaul Zimmerman /* 38197ba5f4SPaul Zimmerman * Provides the initialization and cleanup entry points for the DWC_otg PCI 39197ba5f4SPaul Zimmerman * driver 40197ba5f4SPaul Zimmerman */ 41197ba5f4SPaul Zimmerman #include <linux/kernel.h> 42197ba5f4SPaul Zimmerman #include <linux/module.h> 43197ba5f4SPaul Zimmerman #include <linux/moduleparam.h> 44197ba5f4SPaul Zimmerman #include <linux/spinlock.h> 45197ba5f4SPaul Zimmerman #include <linux/interrupt.h> 46197ba5f4SPaul Zimmerman #include <linux/io.h> 47197ba5f4SPaul Zimmerman #include <linux/slab.h> 48197ba5f4SPaul Zimmerman #include <linux/pci.h> 49197ba5f4SPaul Zimmerman #include <linux/usb.h> 50197ba5f4SPaul Zimmerman 51197ba5f4SPaul Zimmerman #include <linux/usb/hcd.h> 52197ba5f4SPaul Zimmerman #include <linux/usb/ch11.h> 53*9024c495SJohn Youn #include <linux/platform_device.h> 54*9024c495SJohn Youn #include <linux/usb/usb_phy_generic.h> 55197ba5f4SPaul Zimmerman 56197ba5f4SPaul Zimmerman #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 57197ba5f4SPaul Zimmerman 58*9024c495SJohn Youn static const char dwc2_driver_name[] = "dwc2-pci"; 59197ba5f4SPaul Zimmerman 60*9024c495SJohn Youn struct dwc2_pci_glue { 61*9024c495SJohn Youn struct platform_device *dwc2; 62*9024c495SJohn Youn struct platform_device *phy; 63197ba5f4SPaul Zimmerman }; 64197ba5f4SPaul Zimmerman 65*9024c495SJohn Youn static void dwc2_pci_remove(struct pci_dev *pci) 66197ba5f4SPaul Zimmerman { 67*9024c495SJohn Youn struct dwc2_pci_glue *glue = pci_get_drvdata(pci); 68197ba5f4SPaul Zimmerman 69*9024c495SJohn Youn platform_device_unregister(glue->dwc2); 70*9024c495SJohn Youn usb_phy_generic_unregister(glue->phy); 71*9024c495SJohn Youn kfree(glue); 72*9024c495SJohn Youn pci_set_drvdata(pci, NULL); 73197ba5f4SPaul Zimmerman } 74197ba5f4SPaul Zimmerman 75*9024c495SJohn Youn static int dwc2_pci_probe(struct pci_dev *pci, 76197ba5f4SPaul Zimmerman const struct pci_device_id *id) 77197ba5f4SPaul Zimmerman { 78*9024c495SJohn Youn struct resource res[2]; 79*9024c495SJohn Youn struct platform_device *dwc2; 80*9024c495SJohn Youn struct platform_device *phy; 81*9024c495SJohn Youn int ret; 82*9024c495SJohn Youn struct device *dev = &pci->dev; 83*9024c495SJohn Youn struct dwc2_pci_glue *glue; 84197ba5f4SPaul Zimmerman 85*9024c495SJohn Youn ret = pcim_enable_device(pci); 86*9024c495SJohn Youn if (ret) { 87*9024c495SJohn Youn dev_err(dev, "failed to enable pci device\n"); 88197ba5f4SPaul Zimmerman return -ENODEV; 89197ba5f4SPaul Zimmerman } 90197ba5f4SPaul Zimmerman 91*9024c495SJohn Youn pci_set_master(pci); 92197ba5f4SPaul Zimmerman 93*9024c495SJohn Youn dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO); 94*9024c495SJohn Youn if (!dwc2) { 95*9024c495SJohn Youn dev_err(dev, "couldn't allocate dwc2 device\n"); 96*9024c495SJohn Youn return -ENOMEM; 97*9024c495SJohn Youn } 98*9024c495SJohn Youn 99*9024c495SJohn Youn memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 100*9024c495SJohn Youn 101*9024c495SJohn Youn res[0].start = pci_resource_start(pci, 0); 102*9024c495SJohn Youn res[0].end = pci_resource_end(pci, 0); 103*9024c495SJohn Youn res[0].name = "dwc2"; 104*9024c495SJohn Youn res[0].flags = IORESOURCE_MEM; 105*9024c495SJohn Youn 106*9024c495SJohn Youn res[1].start = pci->irq; 107*9024c495SJohn Youn res[1].name = "dwc2"; 108*9024c495SJohn Youn res[1].flags = IORESOURCE_IRQ; 109*9024c495SJohn Youn 110*9024c495SJohn Youn ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res)); 111*9024c495SJohn Youn if (ret) { 112*9024c495SJohn Youn dev_err(dev, "couldn't add resources to dwc2 device\n"); 113*9024c495SJohn Youn return ret; 114*9024c495SJohn Youn } 115*9024c495SJohn Youn 116*9024c495SJohn Youn dwc2->dev.parent = dev; 117*9024c495SJohn Youn 118*9024c495SJohn Youn phy = usb_phy_generic_register(); 119*9024c495SJohn Youn if (IS_ERR(phy)) { 120*9024c495SJohn Youn dev_err(dev, "error registering generic PHY (%ld)\n", 121*9024c495SJohn Youn PTR_ERR(phy)); 122*9024c495SJohn Youn return PTR_ERR(phy); 123*9024c495SJohn Youn } 124*9024c495SJohn Youn 125*9024c495SJohn Youn ret = platform_device_add(dwc2); 126*9024c495SJohn Youn if (ret) { 127*9024c495SJohn Youn dev_err(dev, "failed to register dwc2 device\n"); 128*9024c495SJohn Youn goto err; 129*9024c495SJohn Youn } 130*9024c495SJohn Youn 131*9024c495SJohn Youn glue = kzalloc(sizeof(*glue), GFP_KERNEL); 132*9024c495SJohn Youn if (!glue) 133*9024c495SJohn Youn return -ENOMEM; 134*9024c495SJohn Youn 135*9024c495SJohn Youn glue->phy = phy; 136*9024c495SJohn Youn glue->dwc2 = dwc2; 137*9024c495SJohn Youn pci_set_drvdata(pci, glue); 138*9024c495SJohn Youn 139*9024c495SJohn Youn return 0; 140*9024c495SJohn Youn err: 141*9024c495SJohn Youn usb_phy_generic_unregister(phy); 142*9024c495SJohn Youn platform_device_put(dwc2); 143*9024c495SJohn Youn return ret; 144197ba5f4SPaul Zimmerman } 145197ba5f4SPaul Zimmerman 146197ba5f4SPaul Zimmerman static const struct pci_device_id dwc2_pci_ids[] = { 147197ba5f4SPaul Zimmerman { 148197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 149197ba5f4SPaul Zimmerman }, 150197ba5f4SPaul Zimmerman { 151197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 152197ba5f4SPaul Zimmerman PCI_DEVICE_ID_STMICRO_USB_OTG), 153197ba5f4SPaul Zimmerman }, 154197ba5f4SPaul Zimmerman { /* end: all zeroes */ } 155197ba5f4SPaul Zimmerman }; 156197ba5f4SPaul Zimmerman MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 157197ba5f4SPaul Zimmerman 158197ba5f4SPaul Zimmerman static struct pci_driver dwc2_pci_driver = { 159197ba5f4SPaul Zimmerman .name = dwc2_driver_name, 160197ba5f4SPaul Zimmerman .id_table = dwc2_pci_ids, 161*9024c495SJohn Youn .probe = dwc2_pci_probe, 162*9024c495SJohn Youn .remove = dwc2_pci_remove, 163197ba5f4SPaul Zimmerman }; 164197ba5f4SPaul Zimmerman 165197ba5f4SPaul Zimmerman module_pci_driver(dwc2_pci_driver); 166197ba5f4SPaul Zimmerman 167197ba5f4SPaul Zimmerman MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); 168197ba5f4SPaul Zimmerman MODULE_AUTHOR("Synopsys, Inc."); 169197ba5f4SPaul Zimmerman MODULE_LICENSE("Dual BSD/GPL"); 170