Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 2 | /* |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 3 | * ci_hdrc_pci.c - MIPS USB IP core family device controller |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. |
| 6 | * |
| 7 | * Author: David Lopo |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 10 | #include <linux/platform_device.h> |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/pci.h> |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/usb/gadget.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 15 | #include <linux/usb/chipidea.h> |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 16 | #include <linux/usb/usb_phy_generic.h> |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 17 | |
| 18 | /* driver name */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 19 | #define UDC_DRIVER_NAME "ci_hdrc_pci" |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 20 | |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 21 | struct ci_hdrc_pci { |
| 22 | struct platform_device *ci; |
| 23 | struct platform_device *phy; |
| 24 | }; |
| 25 | |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 26 | /****************************************************************************** |
| 27 | * PCI block |
| 28 | *****************************************************************************/ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 29 | static struct ci_hdrc_platform_data pci_platdata = { |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 30 | .name = UDC_DRIVER_NAME, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 31 | .capoffset = DEF_CAPOFFSET, |
| 32 | }; |
| 33 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 34 | static struct ci_hdrc_platform_data langwell_pci_platdata = { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 35 | .name = UDC_DRIVER_NAME, |
| 36 | .capoffset = 0, |
Pavankumar Kondeti | f01ef57 | 2010-12-07 17:54:02 +0530 | [diff] [blame] | 37 | }; |
| 38 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 39 | static struct ci_hdrc_platform_data penwell_pci_platdata = { |
Alexander Shishkin | bd84198 | 2012-05-11 17:25:55 +0300 | [diff] [blame] | 40 | .name = UDC_DRIVER_NAME, |
| 41 | .capoffset = 0, |
| 42 | .power_budget = 200, |
| 43 | }; |
| 44 | |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 45 | /** |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 46 | * ci_hdrc_pci_probe: PCI probe |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 47 | * @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 Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 54 | static int ci_hdrc_pci_probe(struct pci_dev *pdev, |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 55 | const struct pci_device_id *id) |
| 56 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 57 | struct ci_hdrc_platform_data *platdata = (void *)id->driver_data; |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 58 | struct ci_hdrc_pci *ci; |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 59 | struct resource res[3]; |
| 60 | int retval = 0, nres = 2; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 61 | |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 62 | if (!platdata) { |
Alexander Shishkin | 1989b5c | 2012-05-11 17:25:40 +0300 | [diff] [blame] | 63 | dev_err(&pdev->dev, "device doesn't provide driver data\n"); |
| 64 | return -ENODEV; |
| 65 | } |
| 66 | |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 67 | ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); |
| 68 | if (!ci) |
| 69 | return -ENOMEM; |
| 70 | |
Andy Shevchenko | 8b2379b | 2013-06-13 18:00:02 +0300 | [diff] [blame] | 71 | retval = pcim_enable_device(pdev); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 72 | if (retval) |
Andy Shevchenko | 8b2379b | 2013-06-13 18:00:02 +0300 | [diff] [blame] | 73 | return retval; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 74 | |
| 75 | if (!pdev->irq) { |
| 76 | dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); |
Andy Shevchenko | 8b2379b | 2013-06-13 18:00:02 +0300 | [diff] [blame] | 77 | return -ENODEV; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 78 | } |
| 79 | |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 80 | pci_set_master(pdev); |
| 81 | pci_try_set_mwi(pdev); |
| 82 | |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 83 | /* register a nop PHY */ |
| 84 | ci->phy = usb_phy_generic_register(); |
Wei Yongjun | 8c0614c | 2016-02-06 22:57:06 +0800 | [diff] [blame] | 85 | if (IS_ERR(ci->phy)) |
| 86 | return PTR_ERR(ci->phy); |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 87 | |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 88 | 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 Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 95 | ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); |
| 96 | if (IS_ERR(ci->ci)) { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 97 | dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 98 | usb_phy_generic_unregister(ci->phy); |
| 99 | return PTR_ERR(ci->ci); |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 100 | } |
| 101 | |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 102 | pci_set_drvdata(pdev, ci); |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 103 | |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 104 | return 0; |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /** |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 108 | * ci_hdrc_pci_remove: PCI remove |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 109 | * @pdev: USB Device Controller being removed |
| 110 | * |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 111 | * Reverses the effect of ci_hdrc_pci_probe(), |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 112 | * first invoking the udc_remove() and then releases |
| 113 | * all PCI resources allocated for this USB device controller |
| 114 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 115 | static void ci_hdrc_pci_remove(struct pci_dev *pdev) |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 116 | { |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 117 | struct ci_hdrc_pci *ci = pci_get_drvdata(pdev); |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 118 | |
Andy Shevchenko | ba1aff6 | 2015-02-11 12:45:00 +0800 | [diff] [blame] | 119 | ci_hdrc_remove_device(ci->ci); |
| 120 | usb_phy_generic_unregister(ci->phy); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 121 | } |
| 122 | |
Lee Jones | f2db5f2 | 2020-07-06 14:33:11 +0100 | [diff] [blame] | 123 | /* |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 124 | * PCI device table |
| 125 | * PCI device structure |
| 126 | * |
| 127 | * Check "pci.h" for details |
Andy Shevchenko | 518ca8d | 2015-02-03 18:08:39 +0200 | [diff] [blame] | 128 | * |
| 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 Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 131 | */ |
Jingoo Han | 4e065b8 | 2013-11-28 14:15:26 +0900 | [diff] [blame] | 132 | static const struct pci_device_id ci_hdrc_pci_id_table[] = { |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 133 | { |
| 134 | PCI_DEVICE(0x153F, 0x1004), |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 135 | .driver_data = (kernel_ulong_t)&pci_platdata, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 136 | }, |
| 137 | { |
| 138 | PCI_DEVICE(0x153F, 0x1006), |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 139 | .driver_data = (kernel_ulong_t)&pci_platdata, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 140 | }, |
| 141 | { |
Sergei Shtylyov | 46b95a1d | 2015-10-04 23:55:35 +0300 | [diff] [blame] | 142 | PCI_VDEVICE(INTEL, 0x0811), |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 143 | .driver_data = (kernel_ulong_t)&langwell_pci_platdata, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 144 | }, |
| 145 | { |
Sergei Shtylyov | 46b95a1d | 2015-10-04 23:55:35 +0300 | [diff] [blame] | 146 | PCI_VDEVICE(INTEL, 0x0829), |
Richard Zhao | 77c4400 | 2012-06-29 17:48:53 +0800 | [diff] [blame] | 147 | .driver_data = (kernel_ulong_t)&penwell_pci_platdata, |
Alexander Shishkin | 62bb84e | 2012-05-08 23:29:01 +0300 | [diff] [blame] | 148 | }, |
David Cohen | a214339 | 2013-10-01 14:32:58 -0700 | [diff] [blame] | 149 | { |
| 150 | /* Intel Clovertrail */ |
Sergei Shtylyov | 46b95a1d | 2015-10-04 23:55:35 +0300 | [diff] [blame] | 151 | PCI_VDEVICE(INTEL, 0xe006), |
David Cohen | a214339 | 2013-10-01 14:32:58 -0700 | [diff] [blame] | 152 | .driver_data = (kernel_ulong_t)&penwell_pci_platdata, |
| 153 | }, |
| 154 | { 0 } /* end: all zeroes */ |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 155 | }; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 156 | MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 157 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 158 | static struct pci_driver ci_hdrc_pci_driver = { |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 159 | .name = UDC_DRIVER_NAME, |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 160 | .id_table = ci_hdrc_pci_id_table, |
| 161 | .probe = ci_hdrc_pci_probe, |
| 162 | .remove = ci_hdrc_pci_remove, |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 163 | }; |
| 164 | |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 165 | module_pci_driver(ci_hdrc_pci_driver); |
Pavankumar Kondeti | 409a15d | 2010-12-07 17:53:59 +0530 | [diff] [blame] | 166 | |
| 167 | MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); |
| 168 | MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); |
| 169 | MODULE_LICENSE("GPL"); |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 170 | MODULE_ALIAS("platform:ci13xxx_pci"); |