xref: /linux/drivers/usb/dwc3/dwc3-pci.c (revision a89d977cc04c77d9aa45d426dbf8de9dd1326c77)
172246da4SFelipe Balbi /**
272246da4SFelipe Balbi  * dwc3-pci.c - PCI Specific glue layer
372246da4SFelipe Balbi  *
472246da4SFelipe Balbi  * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
572246da4SFelipe Balbi  *
672246da4SFelipe Balbi  * Authors: Felipe Balbi <balbi@ti.com>,
772246da4SFelipe Balbi  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
872246da4SFelipe Balbi  *
95945f789SFelipe Balbi  * This program is free software: you can redistribute it and/or modify
105945f789SFelipe Balbi  * it under the terms of the GNU General Public License version 2  of
115945f789SFelipe Balbi  * the License as published by the Free Software Foundation.
1272246da4SFelipe Balbi  *
135945f789SFelipe Balbi  * This program is distributed in the hope that it will be useful,
145945f789SFelipe Balbi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
155945f789SFelipe Balbi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165945f789SFelipe Balbi  * GNU General Public License for more details.
1772246da4SFelipe Balbi  */
1872246da4SFelipe Balbi 
1972246da4SFelipe Balbi #include <linux/kernel.h>
2046a57283SStephen Rothwell #include <linux/module.h>
2172246da4SFelipe Balbi #include <linux/slab.h>
2272246da4SFelipe Balbi #include <linux/pci.h>
2372246da4SFelipe Balbi #include <linux/platform_device.h>
24*a89d977cSHeikki Krogerus #include <linux/gpio/consumer.h>
25*a89d977cSHeikki Krogerus #include <linux/acpi.h>
2672246da4SFelipe Balbi 
278f317b47SHuang Rui #include "platform_data.h"
288f317b47SHuang Rui 
2972246da4SFelipe Balbi #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3	0xabcd
30b62cd96dSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_BYT		0x0f37
3185601f8cSDavid Cohen #define PCI_DEVICE_ID_INTEL_MRFLD	0x119e
327d643664SAlan Cox #define PCI_DEVICE_ID_INTEL_BSW		0x22B7
3384a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTLP	0x9d30
3484a2b61bSHeikki Krogerus #define PCI_DEVICE_ID_INTEL_SPTH	0xa130
3572246da4SFelipe Balbi 
36*a89d977cSHeikki Krogerus static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
37*a89d977cSHeikki Krogerus static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
38*a89d977cSHeikki Krogerus 
39*a89d977cSHeikki Krogerus static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
40*a89d977cSHeikki Krogerus 	{ "reset-gpios", &reset_gpios, 1 },
41*a89d977cSHeikki Krogerus 	{ "cs-gpios", &cs_gpios, 1 },
42*a89d977cSHeikki Krogerus 	{ },
43*a89d977cSHeikki Krogerus };
44*a89d977cSHeikki Krogerus 
452cd9ddf7SHeikki Krogerus static int dwc3_pci_quirks(struct pci_dev *pdev)
462cd9ddf7SHeikki Krogerus {
472cd9ddf7SHeikki Krogerus 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
482cd9ddf7SHeikki Krogerus 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
492cd9ddf7SHeikki Krogerus 		struct dwc3_platform_data pdata;
502cd9ddf7SHeikki Krogerus 
512cd9ddf7SHeikki Krogerus 		memset(&pdata, 0, sizeof(pdata));
522cd9ddf7SHeikki Krogerus 
532cd9ddf7SHeikki Krogerus 		pdata.has_lpm_erratum = true;
542cd9ddf7SHeikki Krogerus 		pdata.lpm_nyet_threshold = 0xf;
552cd9ddf7SHeikki Krogerus 
562cd9ddf7SHeikki Krogerus 		pdata.u2exit_lfps_quirk = true;
572cd9ddf7SHeikki Krogerus 		pdata.u2ss_inp3_quirk = true;
582cd9ddf7SHeikki Krogerus 		pdata.req_p1p2p3_quirk = true;
592cd9ddf7SHeikki Krogerus 		pdata.del_p1p2p3_quirk = true;
602cd9ddf7SHeikki Krogerus 		pdata.del_phy_power_chg_quirk = true;
612cd9ddf7SHeikki Krogerus 		pdata.lfps_filter_quirk = true;
622cd9ddf7SHeikki Krogerus 		pdata.rx_detect_poll_quirk = true;
632cd9ddf7SHeikki Krogerus 
642cd9ddf7SHeikki Krogerus 		pdata.tx_de_emphasis_quirk = true;
652cd9ddf7SHeikki Krogerus 		pdata.tx_de_emphasis = 1;
662cd9ddf7SHeikki Krogerus 
672cd9ddf7SHeikki Krogerus 		/*
682cd9ddf7SHeikki Krogerus 		 * FIXME these quirks should be removed when AMD NL
692cd9ddf7SHeikki Krogerus 		 * taps out
702cd9ddf7SHeikki Krogerus 		 */
712cd9ddf7SHeikki Krogerus 		pdata.disable_scramble_quirk = true;
722cd9ddf7SHeikki Krogerus 		pdata.dis_u3_susphy_quirk = true;
732cd9ddf7SHeikki Krogerus 		pdata.dis_u2_susphy_quirk = true;
742cd9ddf7SHeikki Krogerus 
752cd9ddf7SHeikki Krogerus 		return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
762cd9ddf7SHeikki Krogerus 						sizeof(pdata));
772cd9ddf7SHeikki Krogerus 	}
782cd9ddf7SHeikki Krogerus 
79*a89d977cSHeikki Krogerus 	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
80*a89d977cSHeikki Krogerus 	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
81*a89d977cSHeikki Krogerus 		struct gpio_desc *gpio;
82*a89d977cSHeikki Krogerus 
83*a89d977cSHeikki Krogerus 		acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev),
84*a89d977cSHeikki Krogerus 					  acpi_dwc3_byt_gpios);
85*a89d977cSHeikki Krogerus 
86*a89d977cSHeikki Krogerus 		/* These GPIOs will turn on the USB2 PHY */
87*a89d977cSHeikki Krogerus 		gpio = gpiod_get(&pdev->dev, "cs");
88*a89d977cSHeikki Krogerus 		if (!IS_ERR(gpio)) {
89*a89d977cSHeikki Krogerus 			gpiod_direction_output(gpio, 0);
90*a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
91*a89d977cSHeikki Krogerus 			gpiod_put(gpio);
92*a89d977cSHeikki Krogerus 		}
93*a89d977cSHeikki Krogerus 
94*a89d977cSHeikki Krogerus 		gpio = gpiod_get(&pdev->dev, "reset");
95*a89d977cSHeikki Krogerus 		if (!IS_ERR(gpio)) {
96*a89d977cSHeikki Krogerus 			gpiod_direction_output(gpio, 0);
97*a89d977cSHeikki Krogerus 			gpiod_set_value_cansleep(gpio, 1);
98*a89d977cSHeikki Krogerus 			gpiod_put(gpio);
99*a89d977cSHeikki Krogerus 			usleep_range(10000, 11000);
100*a89d977cSHeikki Krogerus 		}
101*a89d977cSHeikki Krogerus 	}
102*a89d977cSHeikki Krogerus 
1032cd9ddf7SHeikki Krogerus 	return 0;
1042cd9ddf7SHeikki Krogerus }
10572246da4SFelipe Balbi 
10641ac7b3aSBill Pemberton static int dwc3_pci_probe(struct pci_dev *pci,
10772246da4SFelipe Balbi 		const struct pci_device_id *id)
10872246da4SFelipe Balbi {
10972246da4SFelipe Balbi 	struct resource		res[2];
11072246da4SFelipe Balbi 	struct platform_device	*dwc3;
111b09e99eeSAndy Shevchenko 	int			ret;
112802ca850SChanho Park 	struct device		*dev = &pci->dev;
11372246da4SFelipe Balbi 
114f1c7e710SAndy Shevchenko 	ret = pcim_enable_device(pci);
11572246da4SFelipe Balbi 	if (ret) {
116802ca850SChanho Park 		dev_err(dev, "failed to enable pci device\n");
117802ca850SChanho Park 		return -ENODEV;
11872246da4SFelipe Balbi 	}
11972246da4SFelipe Balbi 
12072246da4SFelipe Balbi 	pci_set_master(pci);
12172246da4SFelipe Balbi 
122124dafdeSSebastian Andrzej Siewior 	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
12372246da4SFelipe Balbi 	if (!dwc3) {
124802ca850SChanho Park 		dev_err(dev, "couldn't allocate dwc3 device\n");
125f1c7e710SAndy Shevchenko 		return -ENOMEM;
12672246da4SFelipe Balbi 	}
12772246da4SFelipe Balbi 
12872246da4SFelipe Balbi 	memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
12972246da4SFelipe Balbi 
13072246da4SFelipe Balbi 	res[0].start	= pci_resource_start(pci, 0);
13172246da4SFelipe Balbi 	res[0].end	= pci_resource_end(pci, 0);
13272246da4SFelipe Balbi 	res[0].name	= "dwc_usb3";
13372246da4SFelipe Balbi 	res[0].flags	= IORESOURCE_MEM;
13472246da4SFelipe Balbi 
13572246da4SFelipe Balbi 	res[1].start	= pci->irq;
13672246da4SFelipe Balbi 	res[1].name	= "dwc_usb3";
13772246da4SFelipe Balbi 	res[1].flags	= IORESOURCE_IRQ;
13872246da4SFelipe Balbi 
13972246da4SFelipe Balbi 	ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
14072246da4SFelipe Balbi 	if (ret) {
141802ca850SChanho Park 		dev_err(dev, "couldn't add resources to dwc3 device\n");
142f1c7e710SAndy Shevchenko 		return ret;
14372246da4SFelipe Balbi 	}
14472246da4SFelipe Balbi 
1452cd9ddf7SHeikki Krogerus 	pci_set_drvdata(pci, dwc3);
1462cd9ddf7SHeikki Krogerus 	ret = dwc3_pci_quirks(pci);
1478f317b47SHuang Rui 	if (ret)
1482cd9ddf7SHeikki Krogerus 		goto err;
1498f317b47SHuang Rui 
150802ca850SChanho Park 	dwc3->dev.parent = dev;
15172246da4SFelipe Balbi 
15272246da4SFelipe Balbi 	ret = platform_device_add(dwc3);
15372246da4SFelipe Balbi 	if (ret) {
154802ca850SChanho Park 		dev_err(dev, "failed to register dwc3 device\n");
1552cd9ddf7SHeikki Krogerus 		goto err;
15672246da4SFelipe Balbi 	}
15772246da4SFelipe Balbi 
15872246da4SFelipe Balbi 	return 0;
1592cd9ddf7SHeikki Krogerus err:
16072246da4SFelipe Balbi 	platform_device_put(dwc3);
16172246da4SFelipe Balbi 	return ret;
16272246da4SFelipe Balbi }
16372246da4SFelipe Balbi 
164fb4e98abSBill Pemberton static void dwc3_pci_remove(struct pci_dev *pci)
16572246da4SFelipe Balbi {
166*a89d977cSHeikki Krogerus 	acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pci->dev));
1672cd9ddf7SHeikki Krogerus 	platform_device_unregister(pci_get_drvdata(pci));
16872246da4SFelipe Balbi }
16972246da4SFelipe Balbi 
170782df20cSJingoo Han static const struct pci_device_id dwc3_pci_id_table[] = {
17172246da4SFelipe Balbi 	{
17272246da4SFelipe Balbi 		PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS,
17372246da4SFelipe Balbi 				PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
17472246da4SFelipe Balbi 	},
1757d643664SAlan Cox 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BSW), },
176b62cd96dSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
17785601f8cSDavid Cohen 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
17884a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTLP), },
17984a2b61bSHeikki Krogerus 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SPTH), },
1809755449dSHuang Rui 	{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB), },
18172246da4SFelipe Balbi 	{  }	/* Terminating Entry */
18272246da4SFelipe Balbi };
18372246da4SFelipe Balbi MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
18472246da4SFelipe Balbi 
18572246da4SFelipe Balbi static struct pci_driver dwc3_pci_driver = {
1860949e99bSFelipe Balbi 	.name		= "dwc3-pci",
18772246da4SFelipe Balbi 	.id_table	= dwc3_pci_id_table,
18872246da4SFelipe Balbi 	.probe		= dwc3_pci_probe,
1897690417dSBill Pemberton 	.remove		= dwc3_pci_remove,
19072246da4SFelipe Balbi };
19172246da4SFelipe Balbi 
19272246da4SFelipe Balbi MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
1935945f789SFelipe Balbi MODULE_LICENSE("GPL v2");
19472246da4SFelipe Balbi MODULE_DESCRIPTION("DesignWare USB3 PCI Glue Layer");
19572246da4SFelipe Balbi 
19695656336SGreg Kroah-Hartman module_pci_driver(dwc3_pci_driver);
197