pci.c (adf9c3c85615f41c08559086e0d9ecdc6cc9db71) | pci.c (9024c495f35be735a917571406fab30a789c27d1) |
---|---|
1/* 2 * pci.c - DesignWare HS OTG Controller PCI driver 3 * 4 * Copyright (C) 2004-2013 Synopsys, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 36 unchanged lines hidden (view full) --- 45#include <linux/interrupt.h> 46#include <linux/io.h> 47#include <linux/slab.h> 48#include <linux/pci.h> 49#include <linux/usb.h> 50 51#include <linux/usb/hcd.h> 52#include <linux/usb/ch11.h> | 1/* 2 * pci.c - DesignWare HS OTG Controller PCI driver 3 * 4 * Copyright (C) 2004-2013 Synopsys, Inc. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 36 unchanged lines hidden (view full) --- 45#include <linux/interrupt.h> 46#include <linux/io.h> 47#include <linux/slab.h> 48#include <linux/pci.h> 49#include <linux/usb.h> 50 51#include <linux/usb/hcd.h> 52#include <linux/usb/ch11.h> |
53#include <linux/platform_device.h> 54#include <linux/usb/usb_phy_generic.h> |
|
53 | 55 |
54#include "core.h" 55#include "hcd.h" 56 | |
57#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 58 | 56#define PCI_PRODUCT_ID_HAPS_HSOTG 0xabc0 57 |
59static const char dwc2_driver_name[] = "dwc2"; | 58static const char dwc2_driver_name[] = "dwc2-pci"; |
60 | 59 |
61static const struct dwc2_core_params dwc2_module_params = { 62 .otg_cap = -1, 63 .otg_ver = -1, 64 .dma_enable = -1, 65 .dma_desc_enable = 0, 66 .speed = -1, 67 .enable_dynamic_fifo = -1, 68 .en_multiple_tx_fifo = -1, 69 .host_rx_fifo_size = 1024, 70 .host_nperio_tx_fifo_size = 256, 71 .host_perio_tx_fifo_size = 1024, 72 .max_transfer_size = 65535, 73 .max_packet_count = 511, 74 .host_channels = -1, 75 .phy_type = -1, 76 .phy_utmi_width = -1, 77 .phy_ulpi_ddr = -1, 78 .phy_ulpi_ext_vbus = -1, 79 .i2c_enable = -1, 80 .ulpi_fs_ls = -1, 81 .host_support_fs_ls_low_power = -1, 82 .host_ls_low_power_phy_clk = -1, 83 .ts_dline = -1, 84 .reload_ctl = -1, 85 .ahbcfg = -1, 86 .uframe_sched = -1, | 60struct dwc2_pci_glue { 61 struct platform_device *dwc2; 62 struct platform_device *phy; |
87}; 88 | 63}; 64 |
89/** 90 * dwc2_driver_remove() - Called when the DWC_otg core is unregistered with the 91 * DWC_otg driver 92 * 93 * @dev: Bus device 94 * 95 * This routine is called, for example, when the rmmod command is executed. The 96 * device may or may not be electrically present. If it is present, the driver 97 * stops device processing. Any resources used on behalf of this device are 98 * freed. 99 */ 100static void dwc2_driver_remove(struct pci_dev *dev) | 65static void dwc2_pci_remove(struct pci_dev *pci) |
101{ | 66{ |
102 struct dwc2_hsotg *hsotg = pci_get_drvdata(dev); | 67 struct dwc2_pci_glue *glue = pci_get_drvdata(pci); |
103 | 68 |
104 dwc2_hcd_remove(hsotg); 105 pci_disable_device(dev); | 69 platform_device_unregister(glue->dwc2); 70 usb_phy_generic_unregister(glue->phy); 71 kfree(glue); 72 pci_set_drvdata(pci, NULL); |
106} 107 | 73} 74 |
108/** 109 * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg 110 * driver 111 * 112 * @dev: Bus device 113 * 114 * This routine creates the driver components required to control the device 115 * (core, HCD, and PCD) and initializes the device. The driver components are 116 * stored in a dwc2_hsotg structure. A reference to the dwc2_hsotg is saved 117 * in the device private data. This allows the driver to access the dwc2_hsotg 118 * structure on subsequent calls to driver methods for this device. 119 */ 120static int dwc2_driver_probe(struct pci_dev *dev, 121 const struct pci_device_id *id) | 75static int dwc2_pci_probe(struct pci_dev *pci, 76 const struct pci_device_id *id) |
122{ | 77{ |
123 struct dwc2_hsotg *hsotg; 124 int retval; | 78 struct resource res[2]; 79 struct platform_device *dwc2; 80 struct platform_device *phy; 81 int ret; 82 struct device *dev = &pci->dev; 83 struct dwc2_pci_glue *glue; |
125 | 84 |
126 hsotg = devm_kzalloc(&dev->dev, sizeof(*hsotg), GFP_KERNEL); 127 if (!hsotg) | 85 ret = pcim_enable_device(pci); 86 if (ret) { 87 dev_err(dev, "failed to enable pci device\n"); 88 return -ENODEV; 89 } 90 91 pci_set_master(pci); 92 93 dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO); 94 if (!dwc2) { 95 dev_err(dev, "couldn't allocate dwc2 device\n"); |
128 return -ENOMEM; | 96 return -ENOMEM; |
97 } |
|
129 | 98 |
130 hsotg->dev = &dev->dev; 131 hsotg->regs = devm_ioremap_resource(&dev->dev, &dev->resource[0]); 132 if (IS_ERR(hsotg->regs)) 133 return PTR_ERR(hsotg->regs); | 99 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); |
134 | 100 |
135 dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n", 136 (unsigned long)pci_resource_start(dev, 0), hsotg->regs); | 101 res[0].start = pci_resource_start(pci, 0); 102 res[0].end = pci_resource_end(pci, 0); 103 res[0].name = "dwc2"; 104 res[0].flags = IORESOURCE_MEM; |
137 | 105 |
138 if (pci_enable_device(dev) < 0) 139 return -ENODEV; | 106 res[1].start = pci->irq; 107 res[1].name = "dwc2"; 108 res[1].flags = IORESOURCE_IRQ; |
140 | 109 |
141 pci_set_master(dev); | 110 ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res)); 111 if (ret) { 112 dev_err(dev, "couldn't add resources to dwc2 device\n"); 113 return ret; 114 } |
142 | 115 |
143 retval = devm_request_irq(hsotg->dev, dev->irq, 144 dwc2_handle_common_intr, IRQF_SHARED, 145 dev_name(hsotg->dev), hsotg); 146 if (retval) 147 return retval; | 116 dwc2->dev.parent = dev; |
148 | 117 |
149 spin_lock_init(&hsotg->lock); 150 retval = dwc2_hcd_init(hsotg, dev->irq, &dwc2_module_params); 151 if (retval) { 152 pci_disable_device(dev); 153 return retval; | 118 phy = usb_phy_generic_register(); 119 if (IS_ERR(phy)) { 120 dev_err(dev, "error registering generic PHY (%ld)\n", 121 PTR_ERR(phy)); 122 return PTR_ERR(phy); |
154 } 155 | 123 } 124 |
156 pci_set_drvdata(dev, hsotg); | 125 ret = platform_device_add(dwc2); 126 if (ret) { 127 dev_err(dev, "failed to register dwc2 device\n"); 128 goto err; 129 } |
157 | 130 |
158 return retval; | 131 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 132 if (!glue) 133 return -ENOMEM; 134 135 glue->phy = phy; 136 glue->dwc2 = dwc2; 137 pci_set_drvdata(pci, glue); 138 139 return 0; 140err: 141 usb_phy_generic_unregister(phy); 142 platform_device_put(dwc2); 143 return ret; |
159} 160 161static const struct pci_device_id dwc2_pci_ids[] = { 162 { 163 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 164 }, 165 { 166 PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 167 PCI_DEVICE_ID_STMICRO_USB_OTG), 168 }, 169 { /* end: all zeroes */ } 170}; 171MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 172 173static struct pci_driver dwc2_pci_driver = { 174 .name = dwc2_driver_name, 175 .id_table = dwc2_pci_ids, | 144} 145 146static const struct pci_device_id dwc2_pci_ids[] = { 147 { 148 PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, PCI_PRODUCT_ID_HAPS_HSOTG), 149 }, 150 { 151 PCI_DEVICE(PCI_VENDOR_ID_STMICRO, 152 PCI_DEVICE_ID_STMICRO_USB_OTG), 153 }, 154 { /* end: all zeroes */ } 155}; 156MODULE_DEVICE_TABLE(pci, dwc2_pci_ids); 157 158static struct pci_driver dwc2_pci_driver = { 159 .name = dwc2_driver_name, 160 .id_table = dwc2_pci_ids, |
176 .probe = dwc2_driver_probe, 177 .remove = dwc2_driver_remove, | 161 .probe = dwc2_pci_probe, 162 .remove = dwc2_pci_remove, |
178}; 179 180module_pci_driver(dwc2_pci_driver); 181 182MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); 183MODULE_AUTHOR("Synopsys, Inc."); 184MODULE_LICENSE("Dual BSD/GPL"); | 163}; 164 165module_pci_driver(dwc2_pci_driver); 166 167MODULE_DESCRIPTION("DESIGNWARE HS OTG PCI Bus Glue"); 168MODULE_AUTHOR("Synopsys, Inc."); 169MODULE_LICENSE("Dual BSD/GPL"); |