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