ci13xxx_pci.c 4.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * ci13xxx_pci.c - MIPS USB IP core family device controller
 *
 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
 *
 * Author: David Lopo
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

13
#include <linux/platform_device.h>
14 15
#include <linux/module.h>
#include <linux/pci.h>
16 17
#include <linux/interrupt.h>
#include <linux/usb/gadget.h>
18
#include <linux/usb/chipidea.h>
19 20 21 22 23 24 25

/* driver name */
#define UDC_DRIVER_NAME   "ci13xxx_pci"

/******************************************************************************
 * PCI block
 *****************************************************************************/
26 27 28 29
struct ci13xxx_udc_driver pci_driver = {
	.name		= UDC_DRIVER_NAME,
	.capoffset	= DEF_CAPOFFSET,
};
30

31
struct ci13xxx_udc_driver langwell_pci_driver = {
32
	.name		= UDC_DRIVER_NAME,
33
	.capoffset	= 0,
34 35
};

36 37 38 39 40 41 42 43 44 45 46 47
/**
 * ci13xxx_pci_probe: PCI probe
 * @pdev: USB device controller being probed
 * @id:   PCI hotplug ID connecting controller to UDC framework
 *
 * This function returns an error code
 * Allocates basic PCI resources for this USB device controller, and then
 * invokes the udc_probe() method to start the UDC associated with it
 */
static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
				       const struct pci_device_id *id)
{
48 49 50 51
	struct ci13xxx_udc_driver *driver = (void *)id->driver_data;
	struct platform_device *plat_ci;
	struct resource res[3];
	int retval = 0, nres = 2;
52

53 54 55 56 57
	if (!driver) {
		dev_err(&pdev->dev, "device doesn't provide driver data\n");
		return -ENODEV;
	}

58 59 60 61 62 63 64 65 66 67
	retval = pci_enable_device(pdev);
	if (retval)
		goto done;

	if (!pdev->irq) {
		dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
		retval = -ENODEV;
		goto disable_device;
	}

68
	pci_set_power_state(pdev, PCI_D0);
69 70 71
	pci_set_master(pdev);
	pci_try_set_mwi(pdev);

72
	plat_ci = platform_device_alloc("ci_hdrc", -1);
73
	if (!plat_ci) {
74
		dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n");
75 76 77
		retval = -ENOMEM;
		goto disable_device;
	}
78

79 80 81 82 83 84 85 86 87 88 89 90 91 92
	memset(res, 0, sizeof(res));
	res[0].start	= pci_resource_start(pdev, 0);
	res[0].end	= pci_resource_end(pdev, 0);
	res[0].flags	= IORESOURCE_MEM;
	res[1].start	= pdev->irq;
	res[1].flags	= IORESOURCE_IRQ;

	retval = platform_device_add_resources(plat_ci, res, nres);
	if (retval) {
		dev_err(&pdev->dev, "can't add resources to platform device\n");
		goto put_platform;
	}

	retval = platform_device_add_data(plat_ci, driver, sizeof(*driver));
93
	if (retval)
94
		goto put_platform;
95

96 97 98 99
	dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
	plat_ci->dev.dma_mask = pdev->dev.dma_mask;
	plat_ci->dev.dma_parms = pdev->dev.dma_parms;
	plat_ci->dev.parent = &pdev->dev;
100

101 102 103
	pci_set_drvdata(pdev, plat_ci);

	retval = platform_device_add(plat_ci);
104
	if (retval)
105
		goto put_platform;
106 107 108

	return 0;

109 110 111
 put_platform:
	pci_set_drvdata(pdev, NULL);
	platform_device_put(plat_ci);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
 disable_device:
	pci_disable_device(pdev);
 done:
	return retval;
}

/**
 * ci13xxx_pci_remove: PCI remove
 * @pdev: USB Device Controller being removed
 *
 * Reverses the effect of ci13xxx_pci_probe(),
 * first invoking the udc_remove() and then releases
 * all PCI resources allocated for this USB device controller
 */
static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
{
128 129 130 131
	struct platform_device *plat_ci = pci_get_drvdata(pdev);

	platform_device_unregister(plat_ci);
	pci_set_drvdata(pdev, NULL);
132 133 134 135 136 137 138 139 140 141
	pci_disable_device(pdev);
}

/**
 * PCI device table
 * PCI device structure
 *
 * Check "pci.h" for details
 */
static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
	{
		PCI_DEVICE(0x153F, 0x1004),
		.driver_data = (kernel_ulong_t)&pci_driver,
	},
	{
		PCI_DEVICE(0x153F, 0x1006),
		.driver_data = (kernel_ulong_t)&pci_driver,
	},
	{
		PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
		.driver_data = (kernel_ulong_t)&langwell_pci_driver,
	},
	{
		PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
		.driver_data = (kernel_ulong_t)&langwell_pci_driver,
	},
158 159 160 161 162 163 164 165 166 167 168
	{ 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
};
MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);

static struct pci_driver ci13xxx_pci_driver = {
	.name         =	UDC_DRIVER_NAME,
	.id_table     =	ci13xxx_pci_id_table,
	.probe        =	ci13xxx_pci_probe,
	.remove       =	__devexit_p(ci13xxx_pci_remove),
};

A
Axel Lin 已提交
169
module_pci_driver(ci13xxx_pci_driver);
170 171 172 173 174

MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
MODULE_LICENSE("GPL");
MODULE_VERSION("June 2008");