blob: d63479e1ad104ec9f0189c29044428a62f46265d [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05302/*
Alexander Shishkin8e229782013-06-24 14:46:36 +03003 * ci_hdrc_pci.c - MIPS USB IP core family device controller
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05304 *
5 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
6 *
7 * Author: David Lopo
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05308 */
9
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030010#include <linux/platform_device.h>
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053011#include <linux/module.h>
12#include <linux/pci.h>
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030013#include <linux/interrupt.h>
14#include <linux/usb/gadget.h>
Alexander Shishkine443b332012-05-11 17:25:46 +030015#include <linux/usb/chipidea.h>
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080016#include <linux/usb/usb_phy_generic.h>
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053017
18/* driver name */
Alexander Shishkin8e229782013-06-24 14:46:36 +030019#define UDC_DRIVER_NAME "ci_hdrc_pci"
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053020
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080021struct ci_hdrc_pci {
22 struct platform_device *ci;
23 struct platform_device *phy;
24};
25
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053026/******************************************************************************
27 * PCI block
28 *****************************************************************************/
Alexander Shishkin8e229782013-06-24 14:46:36 +030029static struct ci_hdrc_platform_data pci_platdata = {
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053030 .name = UDC_DRIVER_NAME,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030031 .capoffset = DEF_CAPOFFSET,
32};
33
Alexander Shishkin8e229782013-06-24 14:46:36 +030034static struct ci_hdrc_platform_data langwell_pci_platdata = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030035 .name = UDC_DRIVER_NAME,
36 .capoffset = 0,
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053037};
38
Alexander Shishkin8e229782013-06-24 14:46:36 +030039static struct ci_hdrc_platform_data penwell_pci_platdata = {
Alexander Shishkinbd841982012-05-11 17:25:55 +030040 .name = UDC_DRIVER_NAME,
41 .capoffset = 0,
42 .power_budget = 200,
43};
44
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053045/**
Alexander Shishkin8e229782013-06-24 14:46:36 +030046 * ci_hdrc_pci_probe: PCI probe
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053047 * @pdev: USB device controller being probed
48 * @id: PCI hotplug ID connecting controller to UDC framework
49 *
50 * This function returns an error code
51 * Allocates basic PCI resources for this USB device controller, and then
52 * invokes the udc_probe() method to start the UDC associated with it
53 */
Alexander Shishkin8e229782013-06-24 14:46:36 +030054static int ci_hdrc_pci_probe(struct pci_dev *pdev,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053055 const struct pci_device_id *id)
56{
Alexander Shishkin8e229782013-06-24 14:46:36 +030057 struct ci_hdrc_platform_data *platdata = (void *)id->driver_data;
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080058 struct ci_hdrc_pci *ci;
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030059 struct resource res[3];
60 int retval = 0, nres = 2;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053061
Richard Zhao77c44002012-06-29 17:48:53 +080062 if (!platdata) {
Alexander Shishkin1989b5c2012-05-11 17:25:40 +030063 dev_err(&pdev->dev, "device doesn't provide driver data\n");
64 return -ENODEV;
65 }
66
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080067 ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL);
68 if (!ci)
69 return -ENOMEM;
70
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030071 retval = pcim_enable_device(pdev);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053072 if (retval)
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030073 return retval;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053074
75 if (!pdev->irq) {
76 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030077 return -ENODEV;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053078 }
79
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053080 pci_set_master(pdev);
81 pci_try_set_mwi(pdev);
82
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080083 /* register a nop PHY */
84 ci->phy = usb_phy_generic_register();
Wei Yongjun8c0614c2016-02-06 22:57:06 +080085 if (IS_ERR(ci->phy))
86 return PTR_ERR(ci->phy);
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080087
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030088 memset(res, 0, sizeof(res));
89 res[0].start = pci_resource_start(pdev, 0);
90 res[0].end = pci_resource_end(pdev, 0);
91 res[0].flags = IORESOURCE_MEM;
92 res[1].start = pdev->irq;
93 res[1].flags = IORESOURCE_IRQ;
94
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080095 ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
96 if (IS_ERR(ci->ci)) {
Alexander Shishkin8e229782013-06-24 14:46:36 +030097 dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
Andy Shevchenkoba1aff62015-02-11 12:45:00 +080098 usb_phy_generic_unregister(ci->phy);
99 return PTR_ERR(ci->ci);
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300100 }
101
Andy Shevchenkoba1aff62015-02-11 12:45:00 +0800102 pci_set_drvdata(pdev, ci);
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300103
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530104 return 0;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530105}
106
107/**
Alexander Shishkin8e229782013-06-24 14:46:36 +0300108 * ci_hdrc_pci_remove: PCI remove
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530109 * @pdev: USB Device Controller being removed
110 *
Alexander Shishkin8e229782013-06-24 14:46:36 +0300111 * Reverses the effect of ci_hdrc_pci_probe(),
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530112 * first invoking the udc_remove() and then releases
113 * all PCI resources allocated for this USB device controller
114 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300115static void ci_hdrc_pci_remove(struct pci_dev *pdev)
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530116{
Andy Shevchenkoba1aff62015-02-11 12:45:00 +0800117 struct ci_hdrc_pci *ci = pci_get_drvdata(pdev);
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300118
Andy Shevchenkoba1aff62015-02-11 12:45:00 +0800119 ci_hdrc_remove_device(ci->ci);
120 usb_phy_generic_unregister(ci->phy);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530121}
122
Lee Jonesf2db5f22020-07-06 14:33:11 +0100123/*
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530124 * PCI device table
125 * PCI device structure
126 *
127 * Check "pci.h" for details
Andy Shevchenko518ca8d2015-02-03 18:08:39 +0200128 *
129 * Note: ehci-pci driver may try to probe the device first. You have to add an
130 * ID to the bypass_pci_id_table in ehci-pci driver to prevent this.
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530131 */
Jingoo Han4e065b82013-11-28 14:15:26 +0900132static const struct pci_device_id ci_hdrc_pci_id_table[] = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300133 {
134 PCI_DEVICE(0x153F, 0x1004),
Richard Zhao77c44002012-06-29 17:48:53 +0800135 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300136 },
137 {
138 PCI_DEVICE(0x153F, 0x1006),
Richard Zhao77c44002012-06-29 17:48:53 +0800139 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300140 },
141 {
Sergei Shtylyov46b95a1d2015-10-04 23:55:35 +0300142 PCI_VDEVICE(INTEL, 0x0811),
Richard Zhao77c44002012-06-29 17:48:53 +0800143 .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300144 },
145 {
Sergei Shtylyov46b95a1d2015-10-04 23:55:35 +0300146 PCI_VDEVICE(INTEL, 0x0829),
Richard Zhao77c44002012-06-29 17:48:53 +0800147 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300148 },
David Cohena2143392013-10-01 14:32:58 -0700149 {
150 /* Intel Clovertrail */
Sergei Shtylyov46b95a1d2015-10-04 23:55:35 +0300151 PCI_VDEVICE(INTEL, 0xe006),
David Cohena2143392013-10-01 14:32:58 -0700152 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
153 },
154 { 0 } /* end: all zeroes */
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530155};
Alexander Shishkin8e229782013-06-24 14:46:36 +0300156MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530157
Alexander Shishkin8e229782013-06-24 14:46:36 +0300158static struct pci_driver ci_hdrc_pci_driver = {
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530159 .name = UDC_DRIVER_NAME,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300160 .id_table = ci_hdrc_pci_id_table,
161 .probe = ci_hdrc_pci_probe,
162 .remove = ci_hdrc_pci_remove,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530163};
164
Alexander Shishkin8e229782013-06-24 14:46:36 +0300165module_pci_driver(ci_hdrc_pci_driver);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530166
167MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
168MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
169MODULE_LICENSE("GPL");
Alexander Shishkin8e229782013-06-24 14:46:36 +0300170MODULE_ALIAS("platform:ci13xxx_pci");