Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: dwc3: Add a glue driver for Synopsys HAPS platform

This driver is to be used for Synopsys PCIe-base HAPS platform. Move the
the HAPS support from dwc3-pci to this driver.

Signed-off-by: Thinh Nguyen <thinhn@synopsys.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>

authored by

Thinh Nguyen and committed by
Felipe Balbi
3fe314ca e610257e

+147 -34
+9 -4
drivers/usb/dwc3/Kconfig
··· 74 74 depends on USB_PCI && ACPI 75 75 default USB_DWC3 76 76 help 77 - If you're using the DesignWare Core IP with a PCIe, please say 78 - 'Y' or 'M' here. 77 + If you're using the DesignWare Core IP with a PCIe (but not HAPS 78 + platform), please say 'Y' or 'M' here. 79 79 80 - One such PCIe-based platform is Synopsys' PCIe HAPS model of 81 - this IP. 80 + config USB_DWC3_HAPS 81 + tristate "Synopsys PCIe-based HAPS Platforms" 82 + depends on USB_PCI 83 + default USB_DWC3 84 + help 85 + If you're using the DesignWare Core IP with a Synopsys PCIe HAPS 86 + platform, please say 'Y' or 'M' here. 82 87 83 88 config USB_DWC3_KEYSTONE 84 89 tristate "Texas Instruments Keystone2 Platforms"
+1
drivers/usb/dwc3/Makefile
··· 45 45 obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o 46 46 obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o 47 47 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o 48 + obj-$(CONFIG_USB_DWC3_HAPS) += dwc3-haps.o 48 49 obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o 49 50 obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o 50 51 obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o
+137
drivers/usb/dwc3/dwc3-haps.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /** 3 + * dwc3-haps.c - Synopsys HAPS PCI Specific glue layer 4 + * 5 + * Copyright (C) 2018 Synopsys, Inc. 6 + * 7 + * Authors: Thinh Nguyen <thinhn@synopsys.com>, 8 + * John Youn <johnyoun@synopsys.com> 9 + */ 10 + 11 + #include <linux/kernel.h> 12 + #include <linux/module.h> 13 + #include <linux/slab.h> 14 + #include <linux/pci.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/property.h> 17 + 18 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 19 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce 20 + #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf 21 + 22 + /** 23 + * struct dwc3_haps - Driver private structure 24 + * @dwc3: child dwc3 platform_device 25 + * @pci: our link to PCI bus 26 + */ 27 + struct dwc3_haps { 28 + struct platform_device *dwc3; 29 + struct pci_dev *pci; 30 + }; 31 + 32 + static const struct property_entry initial_properties[] = { 33 + PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 34 + PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 35 + PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 36 + PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 37 + { }, 38 + }; 39 + 40 + static int dwc3_haps_probe(struct pci_dev *pci, 41 + const struct pci_device_id *id) 42 + { 43 + struct dwc3_haps *dwc; 44 + struct device *dev = &pci->dev; 45 + struct resource res[2]; 46 + int ret; 47 + 48 + ret = pcim_enable_device(pci); 49 + if (ret) { 50 + dev_err(dev, "failed to enable pci device\n"); 51 + return -ENODEV; 52 + } 53 + 54 + pci_set_master(pci); 55 + 56 + dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL); 57 + if (!dwc) 58 + return -ENOMEM; 59 + 60 + dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); 61 + if (!dwc->dwc3) 62 + return -ENOMEM; 63 + 64 + memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 65 + 66 + res[0].start = pci_resource_start(pci, 0); 67 + res[0].end = pci_resource_end(pci, 0); 68 + res[0].name = "dwc_usb3"; 69 + res[0].flags = IORESOURCE_MEM; 70 + 71 + res[1].start = pci->irq; 72 + res[1].name = "dwc_usb3"; 73 + res[1].flags = IORESOURCE_IRQ; 74 + 75 + ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res)); 76 + if (ret) { 77 + dev_err(dev, "couldn't add resources to dwc3 device\n"); 78 + goto err; 79 + } 80 + 81 + dwc->pci = pci; 82 + dwc->dwc3->dev.parent = dev; 83 + 84 + ret = platform_device_add_properties(dwc->dwc3, initial_properties); 85 + if (ret) 86 + goto err; 87 + 88 + ret = platform_device_add(dwc->dwc3); 89 + if (ret) { 90 + dev_err(dev, "failed to register dwc3 device\n"); 91 + goto err; 92 + } 93 + 94 + pci_set_drvdata(pci, dwc); 95 + 96 + return 0; 97 + err: 98 + platform_device_put(dwc->dwc3); 99 + return ret; 100 + } 101 + 102 + static void dwc3_haps_remove(struct pci_dev *pci) 103 + { 104 + struct dwc3_haps *dwc = pci_get_drvdata(pci); 105 + 106 + platform_device_unregister(dwc->dwc3); 107 + } 108 + 109 + static const struct pci_device_id dwc3_haps_id_table[] = { 110 + { 111 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 112 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 113 + }, 114 + { 115 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 116 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI), 117 + }, 118 + { 119 + PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 120 + PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31), 121 + }, 122 + { } /* Terminating Entry */ 123 + }; 124 + MODULE_DEVICE_TABLE(pci, dwc3_haps_id_table); 125 + 126 + static struct pci_driver dwc3_haps_driver = { 127 + .name = "dwc3-haps", 128 + .id_table = dwc3_haps_id_table, 129 + .probe = dwc3_haps_probe, 130 + .remove = dwc3_haps_remove, 131 + }; 132 + 133 + MODULE_AUTHOR("Thinh Nguyen <thinhn@synopsys.com>"); 134 + MODULE_LICENSE("GPL v2"); 135 + MODULE_DESCRIPTION("Synopsys HAPS PCI Glue Layer"); 136 + 137 + module_pci_driver(dwc3_haps_driver);
-30
drivers/usb/dwc3/dwc3-pci.c
··· 19 19 #include <linux/acpi.h> 20 20 #include <linux/delay.h> 21 21 22 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 0xabcd 23 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI 0xabce 24 - #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31 0xabcf 25 22 #define PCI_DEVICE_ID_INTEL_BYT 0x0f37 26 23 #define PCI_DEVICE_ID_INTEL_MRFLD 0x119e 27 24 #define PCI_DEVICE_ID_INTEL_BSW 0x22b7 ··· 148 151 } 149 152 } 150 153 151 - if (pdev->vendor == PCI_VENDOR_ID_SYNOPSYS && 152 - (pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3 || 153 - pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI || 154 - pdev->device == PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31)) { 155 - struct property_entry properties[] = { 156 - PROPERTY_ENTRY_BOOL("snps,usb3_lpm_capable"), 157 - PROPERTY_ENTRY_BOOL("snps,has-lpm-erratum"), 158 - PROPERTY_ENTRY_BOOL("snps,dis_enblslpm_quirk"), 159 - PROPERTY_ENTRY_BOOL("linux,sysdev_is_parent"), 160 - { }, 161 - }; 162 - 163 - return platform_device_add_properties(dwc3, properties); 164 - } 165 - 166 154 return 0; 167 155 } 168 156 ··· 248 266 } 249 267 250 268 static const struct pci_device_id dwc3_pci_id_table[] = { 251 - { 252 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 253 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3), 254 - }, 255 - { 256 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 257 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI), 258 - }, 259 - { 260 - PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 261 - PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31), 262 - }, 263 269 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), }, 264 270 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), }, 265 271 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },