1*8e22978cSAlexander Shishkin /* 2*8e22978cSAlexander Shishkin * ci_hdrc_pci.c - MIPS USB IP core family device controller 3*8e22978cSAlexander Shishkin * 4*8e22978cSAlexander Shishkin * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved. 5*8e22978cSAlexander Shishkin * 6*8e22978cSAlexander Shishkin * Author: David Lopo 7*8e22978cSAlexander Shishkin * 8*8e22978cSAlexander Shishkin * This program is free software; you can redistribute it and/or modify 9*8e22978cSAlexander Shishkin * it under the terms of the GNU General Public License version 2 as 10*8e22978cSAlexander Shishkin * published by the Free Software Foundation. 11*8e22978cSAlexander Shishkin */ 12*8e22978cSAlexander Shishkin 13*8e22978cSAlexander Shishkin #include <linux/platform_device.h> 14*8e22978cSAlexander Shishkin #include <linux/module.h> 15*8e22978cSAlexander Shishkin #include <linux/pci.h> 16*8e22978cSAlexander Shishkin #include <linux/interrupt.h> 17*8e22978cSAlexander Shishkin #include <linux/usb/gadget.h> 18*8e22978cSAlexander Shishkin #include <linux/usb/chipidea.h> 19*8e22978cSAlexander Shishkin 20*8e22978cSAlexander Shishkin /* driver name */ 21*8e22978cSAlexander Shishkin #define UDC_DRIVER_NAME "ci_hdrc_pci" 22*8e22978cSAlexander Shishkin 23*8e22978cSAlexander Shishkin /****************************************************************************** 24*8e22978cSAlexander Shishkin * PCI block 25*8e22978cSAlexander Shishkin *****************************************************************************/ 26*8e22978cSAlexander Shishkin static struct ci_hdrc_platform_data pci_platdata = { 27*8e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 28*8e22978cSAlexander Shishkin .capoffset = DEF_CAPOFFSET, 29*8e22978cSAlexander Shishkin }; 30*8e22978cSAlexander Shishkin 31*8e22978cSAlexander Shishkin static struct ci_hdrc_platform_data langwell_pci_platdata = { 32*8e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 33*8e22978cSAlexander Shishkin .capoffset = 0, 34*8e22978cSAlexander Shishkin }; 35*8e22978cSAlexander Shishkin 36*8e22978cSAlexander Shishkin static struct ci_hdrc_platform_data penwell_pci_platdata = { 37*8e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 38*8e22978cSAlexander Shishkin .capoffset = 0, 39*8e22978cSAlexander Shishkin .power_budget = 200, 40*8e22978cSAlexander Shishkin }; 41*8e22978cSAlexander Shishkin 42*8e22978cSAlexander Shishkin /** 43*8e22978cSAlexander Shishkin * ci_hdrc_pci_probe: PCI probe 44*8e22978cSAlexander Shishkin * @pdev: USB device controller being probed 45*8e22978cSAlexander Shishkin * @id: PCI hotplug ID connecting controller to UDC framework 46*8e22978cSAlexander Shishkin * 47*8e22978cSAlexander Shishkin * This function returns an error code 48*8e22978cSAlexander Shishkin * Allocates basic PCI resources for this USB device controller, and then 49*8e22978cSAlexander Shishkin * invokes the udc_probe() method to start the UDC associated with it 50*8e22978cSAlexander Shishkin */ 51*8e22978cSAlexander Shishkin static int ci_hdrc_pci_probe(struct pci_dev *pdev, 52*8e22978cSAlexander Shishkin const struct pci_device_id *id) 53*8e22978cSAlexander Shishkin { 54*8e22978cSAlexander Shishkin struct ci_hdrc_platform_data *platdata = (void *)id->driver_data; 55*8e22978cSAlexander Shishkin struct platform_device *plat_ci; 56*8e22978cSAlexander Shishkin struct resource res[3]; 57*8e22978cSAlexander Shishkin int retval = 0, nres = 2; 58*8e22978cSAlexander Shishkin 59*8e22978cSAlexander Shishkin if (!platdata) { 60*8e22978cSAlexander Shishkin dev_err(&pdev->dev, "device doesn't provide driver data\n"); 61*8e22978cSAlexander Shishkin return -ENODEV; 62*8e22978cSAlexander Shishkin } 63*8e22978cSAlexander Shishkin 64*8e22978cSAlexander Shishkin retval = pcim_enable_device(pdev); 65*8e22978cSAlexander Shishkin if (retval) 66*8e22978cSAlexander Shishkin return retval; 67*8e22978cSAlexander Shishkin 68*8e22978cSAlexander Shishkin if (!pdev->irq) { 69*8e22978cSAlexander Shishkin dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!"); 70*8e22978cSAlexander Shishkin return -ENODEV; 71*8e22978cSAlexander Shishkin } 72*8e22978cSAlexander Shishkin 73*8e22978cSAlexander Shishkin pci_set_master(pdev); 74*8e22978cSAlexander Shishkin pci_try_set_mwi(pdev); 75*8e22978cSAlexander Shishkin 76*8e22978cSAlexander Shishkin memset(res, 0, sizeof(res)); 77*8e22978cSAlexander Shishkin res[0].start = pci_resource_start(pdev, 0); 78*8e22978cSAlexander Shishkin res[0].end = pci_resource_end(pdev, 0); 79*8e22978cSAlexander Shishkin res[0].flags = IORESOURCE_MEM; 80*8e22978cSAlexander Shishkin res[1].start = pdev->irq; 81*8e22978cSAlexander Shishkin res[1].flags = IORESOURCE_IRQ; 82*8e22978cSAlexander Shishkin 83*8e22978cSAlexander Shishkin plat_ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata); 84*8e22978cSAlexander Shishkin if (IS_ERR(plat_ci)) { 85*8e22978cSAlexander Shishkin dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n"); 86*8e22978cSAlexander Shishkin return PTR_ERR(plat_ci); 87*8e22978cSAlexander Shishkin } 88*8e22978cSAlexander Shishkin 89*8e22978cSAlexander Shishkin pci_set_drvdata(pdev, plat_ci); 90*8e22978cSAlexander Shishkin 91*8e22978cSAlexander Shishkin return 0; 92*8e22978cSAlexander Shishkin } 93*8e22978cSAlexander Shishkin 94*8e22978cSAlexander Shishkin /** 95*8e22978cSAlexander Shishkin * ci_hdrc_pci_remove: PCI remove 96*8e22978cSAlexander Shishkin * @pdev: USB Device Controller being removed 97*8e22978cSAlexander Shishkin * 98*8e22978cSAlexander Shishkin * Reverses the effect of ci_hdrc_pci_probe(), 99*8e22978cSAlexander Shishkin * first invoking the udc_remove() and then releases 100*8e22978cSAlexander Shishkin * all PCI resources allocated for this USB device controller 101*8e22978cSAlexander Shishkin */ 102*8e22978cSAlexander Shishkin static void ci_hdrc_pci_remove(struct pci_dev *pdev) 103*8e22978cSAlexander Shishkin { 104*8e22978cSAlexander Shishkin struct platform_device *plat_ci = pci_get_drvdata(pdev); 105*8e22978cSAlexander Shishkin 106*8e22978cSAlexander Shishkin ci_hdrc_remove_device(plat_ci); 107*8e22978cSAlexander Shishkin } 108*8e22978cSAlexander Shishkin 109*8e22978cSAlexander Shishkin /** 110*8e22978cSAlexander Shishkin * PCI device table 111*8e22978cSAlexander Shishkin * PCI device structure 112*8e22978cSAlexander Shishkin * 113*8e22978cSAlexander Shishkin * Check "pci.h" for details 114*8e22978cSAlexander Shishkin */ 115*8e22978cSAlexander Shishkin static DEFINE_PCI_DEVICE_TABLE(ci_hdrc_pci_id_table) = { 116*8e22978cSAlexander Shishkin { 117*8e22978cSAlexander Shishkin PCI_DEVICE(0x153F, 0x1004), 118*8e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&pci_platdata, 119*8e22978cSAlexander Shishkin }, 120*8e22978cSAlexander Shishkin { 121*8e22978cSAlexander Shishkin PCI_DEVICE(0x153F, 0x1006), 122*8e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&pci_platdata, 123*8e22978cSAlexander Shishkin }, 124*8e22978cSAlexander Shishkin { 125*8e22978cSAlexander Shishkin PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811), 126*8e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&langwell_pci_platdata, 127*8e22978cSAlexander Shishkin }, 128*8e22978cSAlexander Shishkin { 129*8e22978cSAlexander Shishkin PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829), 130*8e22978cSAlexander Shishkin .driver_data = (kernel_ulong_t)&penwell_pci_platdata, 131*8e22978cSAlexander Shishkin }, 132*8e22978cSAlexander Shishkin { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ } 133*8e22978cSAlexander Shishkin }; 134*8e22978cSAlexander Shishkin MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table); 135*8e22978cSAlexander Shishkin 136*8e22978cSAlexander Shishkin static struct pci_driver ci_hdrc_pci_driver = { 137*8e22978cSAlexander Shishkin .name = UDC_DRIVER_NAME, 138*8e22978cSAlexander Shishkin .id_table = ci_hdrc_pci_id_table, 139*8e22978cSAlexander Shishkin .probe = ci_hdrc_pci_probe, 140*8e22978cSAlexander Shishkin .remove = ci_hdrc_pci_remove, 141*8e22978cSAlexander Shishkin }; 142*8e22978cSAlexander Shishkin 143*8e22978cSAlexander Shishkin module_pci_driver(ci_hdrc_pci_driver); 144*8e22978cSAlexander Shishkin 145*8e22978cSAlexander Shishkin MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>"); 146*8e22978cSAlexander Shishkin MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller"); 147*8e22978cSAlexander Shishkin MODULE_LICENSE("GPL"); 148*8e22978cSAlexander Shishkin MODULE_VERSION("June 2008"); 149*8e22978cSAlexander Shishkin MODULE_ALIAS("platform:ci13xxx_pci"); 150