ci_hdrc_pci.c 4.4 KB
Newer Older
1
/*
2
 * ci_hdrc_pci.c - MIPS USB IP core family device controller
3 4 5 6 7 8 9 10 11 12
 *
 * 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
#include <linux/usb/usb_phy_generic.h>
20 21

/* driver name */
22
#define UDC_DRIVER_NAME   "ci_hdrc_pci"
23

24 25 26 27 28
struct ci_hdrc_pci {
	struct platform_device	*ci;
	struct platform_device	*phy;
};

29 30 31
/******************************************************************************
 * PCI block
 *****************************************************************************/
32
static struct ci_hdrc_platform_data pci_platdata = {
33 34 35
	.name		= UDC_DRIVER_NAME,
	.capoffset	= DEF_CAPOFFSET,
};
36

37
static struct ci_hdrc_platform_data langwell_pci_platdata = {
38
	.name		= UDC_DRIVER_NAME,
39
	.capoffset	= 0,
40 41
};

42
static struct ci_hdrc_platform_data penwell_pci_platdata = {
43 44 45 46 47
	.name		= UDC_DRIVER_NAME,
	.capoffset	= 0,
	.power_budget	= 200,
};

48
/**
49
 * ci_hdrc_pci_probe: PCI probe
50 51 52 53 54 55 56
 * @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
 */
57
static int ci_hdrc_pci_probe(struct pci_dev *pdev,
58 59
				       const struct pci_device_id *id)
{
60
	struct ci_hdrc_platform_data *platdata = (void *)id->driver_data;
61
	struct ci_hdrc_pci *ci;
62 63
	struct resource res[3];
	int retval = 0, nres = 2;
64

65
	if (!platdata) {
66 67 68 69
		dev_err(&pdev->dev, "device doesn't provide driver data\n");
		return -ENODEV;
	}

70 71 72 73
	ci = devm_kzalloc(&pdev->dev, sizeof(*ci), GFP_KERNEL);
	if (!ci)
		return -ENOMEM;

74
	retval = pcim_enable_device(pdev);
75
	if (retval)
76
		return retval;
77 78 79

	if (!pdev->irq) {
		dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
80
		return -ENODEV;
81 82 83 84 85
	}

	pci_set_master(pdev);
	pci_try_set_mwi(pdev);

86 87
	/* register a nop PHY */
	ci->phy = usb_phy_generic_register();
88 89
	if (IS_ERR(ci->phy))
		return PTR_ERR(ci->phy);
90

91 92 93 94 95 96 97
	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;

98 99
	ci->ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
	if (IS_ERR(ci->ci)) {
100
		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
101 102
		usb_phy_generic_unregister(ci->phy);
		return PTR_ERR(ci->ci);
103 104
	}

105
	pci_set_drvdata(pdev, ci);
106

107 108 109 110
	return 0;
}

/**
111
 * ci_hdrc_pci_remove: PCI remove
112 113
 * @pdev: USB Device Controller being removed
 *
114
 * Reverses the effect of ci_hdrc_pci_probe(),
115 116 117
 * first invoking the udc_remove() and then releases
 * all PCI resources allocated for this USB device controller
 */
118
static void ci_hdrc_pci_remove(struct pci_dev *pdev)
119
{
120
	struct ci_hdrc_pci *ci = pci_get_drvdata(pdev);
121

122 123
	ci_hdrc_remove_device(ci->ci);
	usb_phy_generic_unregister(ci->phy);
124 125 126 127 128 129 130
}

/**
 * PCI device table
 * PCI device structure
 *
 * Check "pci.h" for details
131 132 133
 *
 * Note: ehci-pci driver may try to probe the device first. You have to add an
 * ID to the bypass_pci_id_table in ehci-pci driver to prevent this.
134
 */
135
static const struct pci_device_id ci_hdrc_pci_id_table[] = {
136 137
	{
		PCI_DEVICE(0x153F, 0x1004),
138
		.driver_data = (kernel_ulong_t)&pci_platdata,
139 140 141
	},
	{
		PCI_DEVICE(0x153F, 0x1006),
142
		.driver_data = (kernel_ulong_t)&pci_platdata,
143 144
	},
	{
145
		PCI_VDEVICE(INTEL, 0x0811),
146
		.driver_data = (kernel_ulong_t)&langwell_pci_platdata,
147 148
	},
	{
149
		PCI_VDEVICE(INTEL, 0x0829),
150
		.driver_data = (kernel_ulong_t)&penwell_pci_platdata,
151
	},
152 153
	{
		/* Intel Clovertrail */
154
		PCI_VDEVICE(INTEL, 0xe006),
155 156 157
		.driver_data = (kernel_ulong_t)&penwell_pci_platdata,
	},
	{ 0 } /* end: all zeroes */
158
};
159
MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
160

161
static struct pci_driver ci_hdrc_pci_driver = {
162
	.name         =	UDC_DRIVER_NAME,
163 164 165
	.id_table     =	ci_hdrc_pci_id_table,
	.probe        =	ci_hdrc_pci_probe,
	.remove       =	ci_hdrc_pci_remove,
166 167
};

168
module_pci_driver(ci_hdrc_pci_driver);
169 170 171 172 173

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