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