1*5fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 28e22978cSAlexander Shishkin /* 38e22978cSAlexander Shishkin * ci_hdrc_pci.c - MIPS USB IP core family device controller 48e22978cSAlexander Shishkin * 58e22978cSAlexander Shishkin * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. 68e22978cSAlexander Shishkin * 78e22978cSAlexander Shishkin * Author: David Lopo 88e22978cSAlexander Shishkin * 98e22978cSAlexander Shishkin * This program is free software; you can redistribute it and/or modify 108e22978cSAlexander Shishkin * it under the terms of the GNU General Public License version 2 as 118e22978cSAlexander Shishkin * published by the Free Software Foundation. 128e22978cSAlexander Shishkin */ 138e22978cSAlexander Shishkin 148e22978cSAlexander Shishkin #include <linux/platform_device.h> 158e22978cSAlexander Shishkin #include <linux/module.h> 168e22978cSAlexander Shishkin #include <linux/pci.h> 178e22978cSAlexander Shishkin #include <linux/interrupt.h> 188e22978cSAlexander Shishkin #include <linux/usb/gadget.h> 198e22978cSAlexander Shishkin #include <linux/usb/chipidea.h> 20ba1aff67SAndy Shevchenko #include <linux/usb/usb_phy_generic.h> 218e22978cSAlexander Shishkin 228e22978cSAlexander Shishkin /* driver name */ 238e22978cSAlexander Shishkin #define UDC_DRIVER_NAME "ci_hdrc_pci" 248e22978cSAlexander Shishkin 25ba1aff67SAndy Shevchenko struct ci_hdrc_pci { 26ba1aff67SAndy Shevchenko struct platform_device *ci; 27ba1aff67SAndy Shevchenko struct platform_device *phy; 28ba1aff67SAndy Shevchenko }; 29ba1aff67SAndy Shevchenko 308e22978cSAlexander Shishkin /****************************************************************************** 318e22978cSAlexander Shishkin * PCI block 328e22978cSAlexander Shishkin *****************************************************************************/ 338e22978cSAlexander Shishkin static struct ci_hdrc_platform_data pci_platdata = { 348e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 358e22978cSAlexander Shishkin .capoffset = DEF_CAPOFFSET, 368e22978cSAlexander Shishkin }; 378e22978cSAlexander Shishkin 388e22978cSAlexander Shishkin static struct ci_hdrc_platform_data langwell_pci_platdata = { 398e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 408e22978cSAlexander Shishkin .capoffset = 0, 418e22978cSAlexander Shishkin }; 428e22978cSAlexander Shishkin 438e22978cSAlexander Shishkin static struct ci_hdrc_platform_data penwell_pci_platdata = { 448e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 458e22978cSAlexander Shishkin .capoffset = 0, 468e22978cSAlexander Shishkin .power_budget = 200, 478e22978cSAlexander Shishkin }; 488e22978cSAlexander Shishkin 498e22978cSAlexander Shishkin /** 508e22978cSAlexander Shishkin * ci_hdrc_pci_probe: PCI probe 518e22978cSAlexander Shishkin * @pdev: USB device controller being probed 528e22978cSAlexander Shishkin * @id: PCI hotplug ID connecting controller to UDC framework 538e22978cSAlexander Shishkin * 548e22978cSAlexander Shishkin * This function returns an error code 558e22978cSAlexander Shishkin * Allocates basic PCI resources for this USB device controller, and then 568e22978cSAlexander Shishkin * invokes the udc_probe() method to start the UDC associated with it 578e22978cSAlexander Shishkin */ 588e22978cSAlexander Shishkin static int ci_hdrc_pci_probe(struct pci_dev *pdev, 598e22978cSAlexander Shishkin const struct pci_device_id *id) 608e22978cSAlexander Shishkin { 618e22978cSAlexander Shishkin struct ci_hdrc_platform_data *platdata = (void *)id->driver_data; 62ba1aff67SAndy Shevchenko struct ci_hdrc_pci *ci; 638e22978cSAlexander Shishkin struct resource res[3]; 648e22978cSAlexander Shishkin int retval = 0, nres = 2; 658e22978cSAlexander Shishkin 668e22978cSAlexander Shishkin if (!platdata) { 678e22978cSAlexander Shishkin dev_err(&pdev->dev, "device doesn't provide driver data\n"); 688e22978cSAlexander Shishkin return -ENODEV; 698e22978cSAlexander Shishkin } 708e22978cSAlexander Shishkin 71ba1aff67SAndy Shevchenko ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL); 72ba1aff67SAndy Shevchenko if (!ci) 73ba1aff67SAndy Shevchenko return -ENOMEM; 74ba1aff67SAndy Shevchenko 758e22978cSAlexander Shishkin retval = pcim_enable_device(pdev); 768e22978cSAlexander Shishkin if (retval) 778e22978cSAlexander Shishkin return retval; 788e22978cSAlexander Shishkin 798e22978cSAlexander Shishkin if (!pdev->irq) { 808e22978cSAlexander Shishkin dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); 818e22978cSAlexander Shishkin return -ENODEV; 828e22978cSAlexander Shishkin } 838e22978cSAlexander Shishkin 848e22978cSAlexander Shishkin pci_set_master(pdev); 858e22978cSAlexander Shishkin pci_try_set_mwi(pdev); 868e22978cSAlexander Shishkin 87ba1aff67SAndy Shevchenko /* register a nop PHY */ 88ba1aff67SAndy Shevchenko ci->phy = usb_phy_generic_register(); 898c0614caSWei Yongjun if (IS_ERR(ci->phy)) 908c0614caSWei Yongjun return PTR_ERR(ci->phy); 91ba1aff67SAndy Shevchenko 928e22978cSAlexander Shishkin memset(res, 0, sizeof(res)); 938e22978cSAlexander Shishkin res[0].start = pci_resource_start(pdev, 0); 948e22978cSAlexander Shishkin res[0].end = pci_resource_end(pdev, 0); 958e22978cSAlexander Shishkin res[0].flags = IORESOURCE_MEM; 968e22978cSAlexander Shishkin res[1].start = pdev->irq; 978e22978cSAlexander Shishkin res[1].flags = IORESOURCE_IRQ; 988e22978cSAlexander Shishkin 99ba1aff67SAndy Shevchenko ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); 100ba1aff67SAndy Shevchenko if (IS_ERR(ci->ci)) { 1018e22978cSAlexander Shishkin dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); 102ba1aff67SAndy Shevchenko usb_phy_generic_unregister(ci->phy); 103ba1aff67SAndy Shevchenko return PTR_ERR(ci->ci); 1048e22978cSAlexander Shishkin } 1058e22978cSAlexander Shishkin 106ba1aff67SAndy Shevchenko pci_set_drvdata(pdev, ci); 1078e22978cSAlexander Shishkin 1088e22978cSAlexander Shishkin return 0; 1098e22978cSAlexander Shishkin } 1108e22978cSAlexander Shishkin 1118e22978cSAlexander Shishkin /** 1128e22978cSAlexander Shishkin * ci_hdrc_pci_remove: PCI remove 1138e22978cSAlexander Shishkin * @pdev: USB Device Controller being removed 1148e22978cSAlexander Shishkin * 1158e22978cSAlexander Shishkin * Reverses the effect of ci_hdrc_pci_probe(), 1168e22978cSAlexander Shishkin * first invoking the udc_remove() and then releases 1178e22978cSAlexander Shishkin * all PCI resources allocated for this USB device controller 1188e22978cSAlexander Shishkin */ 1198e22978cSAlexander Shishkin static void ci_hdrc_pci_remove(struct pci_dev *pdev) 1208e22978cSAlexander Shishkin { 121ba1aff67SAndy Shevchenko struct ci_hdrc_pci *ci = pci_get_drvdata(pdev); 1228e22978cSAlexander Shishkin 123ba1aff67SAndy Shevchenko ci_hdrc_remove_device(ci->ci); 124ba1aff67SAndy Shevchenko usb_phy_generic_unregister(ci->phy); 1258e22978cSAlexander Shishkin } 1268e22978cSAlexander Shishkin 1278e22978cSAlexander Shishkin /** 1288e22978cSAlexander Shishkin * PCI device table 1298e22978cSAlexander Shishkin * PCI device structure 1308e22978cSAlexander Shishkin * 1318e22978cSAlexander Shishkin * Check "pci.h" for details 132518ca8d9SAndy Shevchenko * 133518ca8d9SAndy Shevchenko * Note: ehci-pci driver may try to probe the device first. You have to add an 134518ca8d9SAndy Shevchenko * ID to the bypass_pci_id_table in ehci-pci driver to prevent this. 1358e22978cSAlexander Shishkin */ 1364e065b8bSJingoo Han static const struct pci_device_id ci_hdrc_pci_id_table[] = { 1378e22978cSAlexander Shishkin { 1388e22978cSAlexander Shishkin PCI_DEVICE(0x153F, 0x1004), 1398e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&pci_platdata, 1408e22978cSAlexander Shishkin }, 1418e22978cSAlexander Shishkin { 1428e22978cSAlexander Shishkin PCI_DEVICE(0x153F, 0x1006), 1438e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&pci_platdata, 1448e22978cSAlexander Shishkin }, 1458e22978cSAlexander Shishkin { 14646b95a1dSSergei Shtylyov PCI_VDEVICE(INTEL, 0x0811), 1478e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&langwell_pci_platdata, 1488e22978cSAlexander Shishkin }, 1498e22978cSAlexander Shishkin { 15046b95a1dSSergei Shtylyov PCI_VDEVICE(INTEL, 0x0829), 1518e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&penwell_pci_platdata, 1528e22978cSAlexander Shishkin }, 153a214339dSDavid Cohen { 154a214339dSDavid Cohen /* Intel Clovertrail */ 15546b95a1dSSergei Shtylyov PCI_VDEVICE(INTEL, 0xe006), 156a214339dSDavid Cohen .driver_data = (kernel_ulong_t)&penwell_pci_platdata, 157a214339dSDavid Cohen }, 158a214339dSDavid Cohen { 0 } /* end: all zeroes */ 1598e22978cSAlexander Shishkin }; 1608e22978cSAlexander Shishkin MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table); 1618e22978cSAlexander Shishkin 1628e22978cSAlexander Shishkin static struct pci_driver ci_hdrc_pci_driver = { 1638e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 1648e22978cSAlexander Shishkin .id_table = ci_hdrc_pci_id_table, 1658e22978cSAlexander Shishkin .probe = ci_hdrc_pci_probe, 1668e22978cSAlexander Shishkin .remove = ci_hdrc_pci_remove, 1678e22978cSAlexander Shishkin }; 1688e22978cSAlexander Shishkin 1698e22978cSAlexander Shishkin module_pci_driver(ci_hdrc_pci_driver); 1708e22978cSAlexander Shishkin 1718e22978cSAlexander Shishkin MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); 1728e22978cSAlexander Shishkin MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); 1738e22978cSAlexander Shishkin MODULE_LICENSE("GPL"); 1748e22978cSAlexander Shishkin MODULE_ALIAS("platform:ci13xxx_pci"); 175