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> 53197ba5f4SPaul Zimmerman 54197ba5f4SPaul Zimmerman #include "core.h" 55197ba5f4SPaul Zimmerman #include "hcd.h" 56197ba5f4SPaul Zimmerman 57197ba5f4SPaul Zimmerman #define PCI_VENDOR_ID_SYNOPSYS 0x16c3 58197ba5f4SPaul Zimmerman #define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 59197ba5f4SPaul Zimmerman 60197ba5f4SPaul Zimmerman static const char dwc2_driver_name[] = "dwc2"; 61197ba5f4SPaul Zimmerman 62197ba5f4SPaul Zimmerman static const struct dwc2_core_params dwc2_module_params = { 63197ba5f4SPaul Zimmerman .otg_cap = -1, 64197ba5f4SPaul Zimmerman .otg_ver = -1, 65197ba5f4SPaul Zimmerman .dma_enable = -1, 66197ba5f4SPaul Zimmerman .dma_desc_enable = 0, 67197ba5f4SPaul Zimmerman .speed = -1, 68197ba5f4SPaul Zimmerman .enable_dynamic_fifo = -1, 69197ba5f4SPaul Zimmerman .en_multiple_tx_fifo = -1, 70197ba5f4SPaul Zimmerman .host_rx_fifo_size = 1024, 71197ba5f4SPaul Zimmerman .host_nperio_tx_fifo_size = 256, 72197ba5f4SPaul Zimmerman .host_perio_tx_fifo_size = 1024, 73197ba5f4SPaul Zimmerman .max_transfer_size = 65535, 74197ba5f4SPaul Zimmerman .max_packet_count = 511, 75197ba5f4SPaul Zimmerman .host_channels = -1, 76197ba5f4SPaul Zimmerman .phy_type = -1, 77197ba5f4SPaul Zimmerman .phy_utmi_width = -1, 78197ba5f4SPaul Zimmerman .phy_ulpi_ddr = -1, 79197ba5f4SPaul Zimmerman .phy_ulpi_ext_vbus = -1, 80197ba5f4SPaul Zimmerman .i2c_enable = -1, 81197ba5f4SPaul Zimmerman .ulpi_fs_ls = -1, 82197ba5f4SPaul Zimmerman .host_support_fs_ls_low_power = -1, 83197ba5f4SPaul Zimmerman .host_ls_low_power_phy_clk = -1, 84197ba5f4SPaul Zimmerman .ts_dline = -1, 85197ba5f4SPaul Zimmerman .reload_ctl = -1, 86197ba5f4SPaul Zimmerman .ahbcfg = -1, 87197ba5f4SPaul Zimmerman .uframe_sched = -1, 88197ba5f4SPaul Zimmerman }; 89197ba5f4SPaul Zimmerman 90197ba5f4SPaul Zimmerman /** 91197ba5f4SPaul Zimmerman * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the 92197ba5f4SPaul Zimmerman * DWC_otg driver 93197ba5f4SPaul Zimmerman * 94197ba5f4SPaul Zimmerman * @dev: Bus device 95197ba5f4SPaul Zimmerman * 96197ba5f4SPaul Zimmerman * This routine is called, for example, when the rmmod command is executed. The 97197ba5f4SPaul Zimmerman * device may or may not be electrically present. If it is present, the driver 98197ba5f4SPaul Zimmerman * stops device processing. Any resources used on behalf of this device are 99197ba5f4SPaul Zimmerman * freed. 100197ba5f4SPaul Zimmerman */ 101197ba5f4SPaul Zimmerman static void dwc2_driver_remove(struct pci_dev *dev) 102197ba5f4SPaul Zimmerman { 103197ba5f4SPaul Zimmerman struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); 104197ba5f4SPaul Zimmerman 105197ba5f4SPaul Zimmerman dwc2_hcd_remove(hsotg); 106197ba5f4SPaul Zimmerman pci_disable_device(dev); 107197ba5f4SPaul Zimmerman } 108197ba5f4SPaul Zimmerman 109197ba5f4SPaul Zimmerman /** 110197ba5f4SPaul Zimmerman * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg 111197ba5f4SPaul Zimmerman * driver 112197ba5f4SPaul Zimmerman * 113197ba5f4SPaul Zimmerman * @dev: Bus device 114197ba5f4SPaul Zimmerman * 115197ba5f4SPaul Zimmerman * This routine creates the driver components required to control the device 116197ba5f4SPaul Zimmerman * (core, HCD, and PCD) and initializes the device. The driver components are 117197ba5f4SPaul Zimmerman * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved 118197ba5f4SPaul Zimmerman * in the device private data. This allows the driver to access the dwc2_hsotg 119197ba5f4SPaul Zimmerman * structure on subsequent calls to driver methods for this device. 120197ba5f4SPaul Zimmerman */ 121197ba5f4SPaul Zimmerman static int dwc2_driver_probe(struct pci_dev *dev, 122197ba5f4SPaul Zimmerman const struct pci_device_id *id) 123197ba5f4SPaul Zimmerman { 124197ba5f4SPaul Zimmerman struct dwc2_hsotg *hsotg; 125197ba5f4SPaul Zimmerman int retval; 126197ba5f4SPaul Zimmerman 127197ba5f4SPaul Zimmerman hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); 128197ba5f4SPaul Zimmerman if (!hsotg) 129197ba5f4SPaul Zimmerman return -ENOMEM; 130197ba5f4SPaul Zimmerman 131197ba5f4SPaul Zimmerman hsotg->dev = &dev->dev; 132197ba5f4SPaul Zimmerman hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); 133197ba5f4SPaul Zimmerman if (IS_ERR(hsotg->regs)) 134197ba5f4SPaul Zimmerman return PTR_ERR(hsotg->regs); 135197ba5f4SPaul Zimmerman 136197ba5f4SPaul Zimmerman dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 137197ba5f4SPaul Zimmerman (unsigned long)pci_resource_start(dev, 0), hsotg->regs); 138197ba5f4SPaul Zimmerman 139197ba5f4SPaul Zimmerman if (pci_enable_device(dev) < 0) 140197ba5f4SPaul Zimmerman return -ENODEV; 141197ba5f4SPaul Zimmerman 142197ba5f4SPaul Zimmerman pci_set_master(dev); 143197ba5f4SPaul Zimmerman 144197ba5f4SPaul Zimmerman retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); 145197ba5f4SPaul Zimmerman if (retval) { 146197ba5f4SPaul Zimmerman pci_disable_device(dev); 147197ba5f4SPaul Zimmerman return retval; 148197ba5f4SPaul Zimmerman } 149197ba5f4SPaul Zimmerman 150197ba5f4SPaul Zimmerman pci_set_drvdata(dev, hsotg); 151197ba5f4SPaul Zimmerman 152197ba5f4SPaul Zimmerman return retval; 153197ba5f4SPaul Zimmerman } 154197ba5f4SPaul Zimmerman 155197ba5f4SPaul Zimmerman static const struct pci_device_id dwc2_pci_ids[] = { 156197ba5f4SPaul Zimmerman { 157197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 158197ba5f4SPaul Zimmerman }, 159197ba5f4SPaul Zimmerman { 160197ba5f4SPaul Zimmerman PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 161197ba5f4SPaul Zimmerman PCI_DEVICE_ID_STMICRO_USB_OTG), 162197ba5f4SPaul Zimmerman }, 163197ba5f4SPaul Zimmerman { /* end: all zeroes */ } 164197ba5f4SPaul Zimmerman }; 165197ba5f4SPaul Zimmerman MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 166197ba5f4SPaul Zimmerman 167197ba5f4SPaul Zimmerman static struct pci_driver dwc2_pci_driver = { 168197ba5f4SPaul Zimmerman .name = dwc2_driver_name, 169197ba5f4SPaul Zimmerman .id_table = dwc2_pci_ids, 170197ba5f4SPaul Zimmerman .probe = dwc2_driver_probe, 171197ba5f4SPaul Zimmerman .remove = dwc2_driver_remove, 172197ba5f4SPaul Zimmerman }; 173197ba5f4SPaul Zimmerman 174197ba5f4SPaul Zimmerman module_pci_driver(dwc2_pci_driver); 175197ba5f4SPaul Zimmerman 176197ba5f4SPaul Zimmerman MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); 177197ba5f4SPaul Zimmerman MODULE_AUTHOR("Synopsys, Inc."); 178197ba5f4SPaul Zimmerman MODULE_LICENSE("Dual BSD/GPL"); 179