1*197ba5f4SPaul Zimmerman /* 2*197ba5f4SPaul Zimmerman * pci.c - DesignWare HS OTG Controller PCI driver 3*197ba5f4SPaul Zimmerman * 4*197ba5f4SPaul Zimmerman * Copyright (C) 2004-2013 Synopsys, Inc. 5*197ba5f4SPaul Zimmerman * 6*197ba5f4SPaul Zimmerman * Redistribution and use in source and binary forms, with or without 7*197ba5f4SPaul Zimmerman * modification, are permitted provided that the following conditions 8*197ba5f4SPaul Zimmerman * are met: 9*197ba5f4SPaul Zimmerman * 1. Redistributions of source code must retain the above copyright 10*197ba5f4SPaul Zimmerman * notice, this list of conditions, and the following disclaimer, 11*197ba5f4SPaul Zimmerman * without modification. 12*197ba5f4SPaul Zimmerman * 2. Redistributions in binary form must reproduce the above copyright 13*197ba5f4SPaul Zimmerman * notice, this list of conditions and the following disclaimer in the 14*197ba5f4SPaul Zimmerman * documentation and/or other materials provided with the distribution. 15*197ba5f4SPaul Zimmerman * 3. The names of the above-listed copyright holders may not be used 16*197ba5f4SPaul Zimmerman * to endorse or promote products derived from this software without 17*197ba5f4SPaul Zimmerman * specific prior written permission. 18*197ba5f4SPaul Zimmerman * 19*197ba5f4SPaul Zimmerman * ALTERNATIVELY, this software may be distributed under the terms of the 20*197ba5f4SPaul Zimmerman * GNU General Public License ("GPL") as published by the Free Software 21*197ba5f4SPaul Zimmerman * Foundation; either version 2 of the License, or (at your option) any 22*197ba5f4SPaul Zimmerman * later version. 23*197ba5f4SPaul Zimmerman * 24*197ba5f4SPaul Zimmerman * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25*197ba5f4SPaul Zimmerman * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 26*197ba5f4SPaul Zimmerman * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27*197ba5f4SPaul Zimmerman * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28*197ba5f4SPaul Zimmerman * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29*197ba5f4SPaul Zimmerman * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30*197ba5f4SPaul Zimmerman * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31*197ba5f4SPaul Zimmerman * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32*197ba5f4SPaul Zimmerman * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33*197ba5f4SPaul Zimmerman * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34*197ba5f4SPaul Zimmerman * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35*197ba5f4SPaul Zimmerman */ 36*197ba5f4SPaul Zimmerman 37*197ba5f4SPaul Zimmerman /* 38*197ba5f4SPaul Zimmerman * Provides the initialization and cleanup entry points for the DWC_otg PCI 39*197ba5f4SPaul Zimmerman * driver 40*197ba5f4SPaul Zimmerman */ 41*197ba5f4SPaul Zimmerman #include <linux/kernel.h> 42*197ba5f4SPaul Zimmerman #include <linux/module.h> 43*197ba5f4SPaul Zimmerman #include <linux/moduleparam.h> 44*197ba5f4SPaul Zimmerman #include <linux/spinlock.h> 45*197ba5f4SPaul Zimmerman #include <linux/interrupt.h> 46*197ba5f4SPaul Zimmerman #include <linux/io.h> 47*197ba5f4SPaul Zimmerman #include <linux/slab.h> 48*197ba5f4SPaul Zimmerman #include <linux/pci.h> 49*197ba5f4SPaul Zimmerman #include <linux/usb.h> 50*197ba5f4SPaul Zimmerman 51*197ba5f4SPaul Zimmerman #include <linux/usb/hcd.h> 52*197ba5f4SPaul Zimmerman #include <linux/usb/ch11.h> 53*197ba5f4SPaul Zimmerman 54*197ba5f4SPaul Zimmerman #include "core.h" 55*197ba5f4SPaul Zimmerman #include "hcd.h" 56*197ba5f4SPaul Zimmerman 57*197ba5f4SPaul Zimmerman #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 58*197ba5f4SPaul Zimmerman #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 59*197ba5f4SPaul Zimmerman 60*197ba5f4SPaul Zimmerman static const char dwc2_driver_name[] = "dwc2"; 61*197ba5f4SPaul Zimmerman 62*197ba5f4SPaul Zimmerman static const struct dwc2_core_params dwc2_module_params = { 63*197ba5f4SPaul Zimmerman .otg_cap = -1, 64*197ba5f4SPaul Zimmerman .otg_ver = -1, 65*197ba5f4SPaul Zimmerman .dma_enable = -1, 66*197ba5f4SPaul Zimmerman .dma_desc_enable = 0, 67*197ba5f4SPaul Zimmerman .speed = -1, 68*197ba5f4SPaul Zimmerman .enable_dynamic_fifo = -1, 69*197ba5f4SPaul Zimmerman .en_multiple_tx_fifo = -1, 70*197ba5f4SPaul Zimmerman .host_rx_fifo_size = 1024, 71*197ba5f4SPaul Zimmerman .host_nperio_tx_fifo_size = 256, 72*197ba5f4SPaul Zimmerman .host_perio_tx_fifo_size = 1024, 73*197ba5f4SPaul Zimmerman .max_transfer_size = 65535, 74*197ba5f4SPaul Zimmerman .max_packet_count = 511, 75*197ba5f4SPaul Zimmerman .host_channels = -1, 76*197ba5f4SPaul Zimmerman .phy_type = -1, 77*197ba5f4SPaul Zimmerman .phy_utmi_width = -1, 78*197ba5f4SPaul Zimmerman .phy_ulpi_ddr = -1, 79*197ba5f4SPaul Zimmerman .phy_ulpi_ext_vbus = -1, 80*197ba5f4SPaul Zimmerman .i2c_enable = -1, 81*197ba5f4SPaul Zimmerman .ulpi_fs_ls = -1, 82*197ba5f4SPaul Zimmerman .host_support_fs_ls_low_power = -1, 83*197ba5f4SPaul Zimmerman .host_ls_low_power_phy_clk = -1, 84*197ba5f4SPaul Zimmerman .ts_dline = -1, 85*197ba5f4SPaul Zimmerman .reload_ctl = -1, 86*197ba5f4SPaul Zimmerman .ahbcfg = -1, 87*197ba5f4SPaul Zimmerman .uframe_sched = -1, 88*197ba5f4SPaul Zimmerman }; 89*197ba5f4SPaul Zimmerman 90*197ba5f4SPaul Zimmerman /** 91*197ba5f4SPaul Zimmerman * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the 92*197ba5f4SPaul Zimmerman * DWC_otg driver 93*197ba5f4SPaul Zimmerman * 94*197ba5f4SPaul Zimmerman * @dev: Bus device 95*197ba5f4SPaul Zimmerman * 96*197ba5f4SPaul Zimmerman * This routine is called, for example, when the rmmod command is executed. The 97*197ba5f4SPaul Zimmerman * device may or may not be electrically present. If it is present, the driver 98*197ba5f4SPaul Zimmerman * stops device processing. Any resources used on behalf of this device are 99*197ba5f4SPaul Zimmerman * freed. 100*197ba5f4SPaul Zimmerman */ 101*197ba5f4SPaul Zimmerman static void dwc2_driver_remove(struct pci_dev *dev) 102*197ba5f4SPaul Zimmerman { 103*197ba5f4SPaul Zimmerman struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); 104*197ba5f4SPaul Zimmerman 105*197ba5f4SPaul Zimmerman dwc2_hcd_remove(hsotg); 106*197ba5f4SPaul Zimmerman pci_disable_device(dev); 107*197ba5f4SPaul Zimmerman } 108*197ba5f4SPaul Zimmerman 109*197ba5f4SPaul Zimmerman /** 110*197ba5f4SPaul Zimmerman * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg 111*197ba5f4SPaul Zimmerman * driver 112*197ba5f4SPaul Zimmerman * 113*197ba5f4SPaul Zimmerman * @dev: Bus device 114*197ba5f4SPaul Zimmerman * 115*197ba5f4SPaul Zimmerman * This routine creates the driver components required to control the device 116*197ba5f4SPaul Zimmerman * (core, HCD, and PCD) and initializes the device. The driver components are 117*197ba5f4SPaul Zimmerman * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved 118*197ba5f4SPaul Zimmerman * in the device private data. This allows the driver to access the dwc2_hsotg 119*197ba5f4SPaul Zimmerman * structure on subsequent calls to driver methods for this device. 120*197ba5f4SPaul Zimmerman */ 121*197ba5f4SPaul Zimmerman static int dwc2_driver_probe(struct pci_dev *dev, 122*197ba5f4SPaul Zimmerman const struct pci_device_id *id) 123*197ba5f4SPaul Zimmerman { 124*197ba5f4SPaul Zimmerman struct dwc2_hsotg *hsotg; 125*197ba5f4SPaul Zimmerman int retval; 126*197ba5f4SPaul Zimmerman 127*197ba5f4SPaul Zimmerman hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); 128*197ba5f4SPaul Zimmerman if (!hsotg) 129*197ba5f4SPaul Zimmerman return -ENOMEM; 130*197ba5f4SPaul Zimmerman 131*197ba5f4SPaul Zimmerman hsotg->dev = &dev->dev; 132*197ba5f4SPaul Zimmerman hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); 133*197ba5f4SPaul Zimmerman if (IS_ERR(hsotg->regs)) 134*197ba5f4SPaul Zimmerman return PTR_ERR(hsotg->regs); 135*197ba5f4SPaul Zimmerman 136*197ba5f4SPaul Zimmerman dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 137*197ba5f4SPaul Zimmerman (unsigned long)pci_resource_start(dev, 0), hsotg->regs); 138*197ba5f4SPaul Zimmerman 139*197ba5f4SPaul Zimmerman if (pci_enable_device(dev) < 0) 140*197ba5f4SPaul Zimmerman return -ENODEV; 141*197ba5f4SPaul Zimmerman 142*197ba5f4SPaul Zimmerman pci_set_master(dev); 143*197ba5f4SPaul Zimmerman 144*197ba5f4SPaul Zimmerman retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); 145*197ba5f4SPaul Zimmerman if (retval) { 146*197ba5f4SPaul Zimmerman pci_disable_device(dev); 147*197ba5f4SPaul Zimmerman return retval; 148*197ba5f4SPaul Zimmerman } 149*197ba5f4SPaul Zimmerman 150*197ba5f4SPaul Zimmerman pci_set_drvdata(dev, hsotg); 151*197ba5f4SPaul Zimmerman 152*197ba5f4SPaul Zimmerman return retval; 153*197ba5f4SPaul Zimmerman } 154*197ba5f4SPaul Zimmerman 155*197ba5f4SPaul Zimmerman static const struct pci_device_id dwc2_pci_ids[] = { 156*197ba5f4SPaul Zimmerman { 157*197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 158*197ba5f4SPaul Zimmerman }, 159*197ba5f4SPaul Zimmerman { 160*197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 161*197ba5f4SPaul Zimmerman PCI_DEVICE_ID_STMICRO_USB_OTG), 162*197ba5f4SPaul Zimmerman }, 163*197ba5f4SPaul Zimmerman { /* end: all zeroes */ } 164*197ba5f4SPaul Zimmerman }; 165*197ba5f4SPaul Zimmerman MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 166*197ba5f4SPaul Zimmerman 167*197ba5f4SPaul Zimmerman static struct pci_driver dwc2_pci_driver = { 168*197ba5f4SPaul Zimmerman .name = dwc2_driver_name, 169*197ba5f4SPaul Zimmerman .id_table = dwc2_pci_ids, 170*197ba5f4SPaul Zimmerman .probe = dwc2_driver_probe, 171*197ba5f4SPaul Zimmerman .remove = dwc2_driver_remove, 172*197ba5f4SPaul Zimmerman }; 173*197ba5f4SPaul Zimmerman 174*197ba5f4SPaul Zimmerman module_pci_driver(dwc2_pci_driver); 175*197ba5f4SPaul Zimmerman 176*197ba5f4SPaul Zimmerman MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); 177*197ba5f4SPaul Zimmerman MODULE_AUTHOR("Synopsys, Inc."); 178*197ba5f4SPaul Zimmerman MODULE_LICENSE("Dual BSD/GPL"); 179