ci_hdrc_pci.c 4.0 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 20

/* driver name */
21
#define UDC_DRIVER_NAME   "ci_hdrc_pci"
22 23 24 25

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

31
static struct ci_hdrc_platform_data langwell_pci_platdata = {
32
	.name		= UDC_DRIVER_NAME,
33
	.capoffset	= 0,
34 35
};

36
static struct ci_hdrc_platform_data penwell_pci_platdata = {
37 38 39 40 41
	.name		= UDC_DRIVER_NAME,
	.capoffset	= 0,
	.power_budget	= 200,
};

42
/**
43
 * ci_hdrc_pci_probe: PCI probe
44 45 46 47 48 49 50
 * @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
 */
51
static int ci_hdrc_pci_probe(struct pci_dev *pdev,
52 53
				       const struct pci_device_id *id)
{
54
	struct ci_hdrc_platform_data *platdata = (void *)id->driver_data;
55 56 57
	struct platform_device *plat_ci;
	struct resource res[3];
	int retval = 0, nres = 2;
58

59
	if (!platdata) {
60 61 62 63
		dev_err(&pdev->dev, "device doesn't provide driver data\n");
		return -ENODEV;
	}

64
	retval = pcim_enable_device(pdev);
65
	if (retval)
66
		return retval;
67 68 69

	if (!pdev->irq) {
		dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
70
		return -ENODEV;
71 72 73 74 75
	}

	pci_set_master(pdev);
	pci_try_set_mwi(pdev);

76 77 78 79 80 81 82
	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;

83
	plat_ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
84
	if (IS_ERR(plat_ci)) {
85
		dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
86
		return PTR_ERR(plat_ci);
87 88 89 90
	}

	pci_set_drvdata(pdev, plat_ci);

91 92 93 94
	return 0;
}

/**
95
 * ci_hdrc_pci_remove: PCI remove
96 97
 * @pdev: USB Device Controller being removed
 *
98
 * Reverses the effect of ci_hdrc_pci_probe(),
99 100 101
 * first invoking the udc_remove() and then releases
 * all PCI resources allocated for this USB device controller
 */
102
static void ci_hdrc_pci_remove(struct pci_dev *pdev)
103
{
104 105
	struct platform_device *plat_ci = pci_get_drvdata(pdev);

106
	ci_hdrc_remove_device(plat_ci);
107 108 109 110 111 112 113 114
}

/**
 * PCI device table
 * PCI device structure
 *
 * Check "pci.h" for details
 */
115
static const struct pci_device_id ci_hdrc_pci_id_table[] = {
116 117
	{
		PCI_DEVICE(0x153F, 0x1004),
118
		.driver_data = (kernel_ulong_t)&pci_platdata,
119 120 121
	},
	{
		PCI_DEVICE(0x153F, 0x1006),
122
		.driver_data = (kernel_ulong_t)&pci_platdata,
123 124 125
	},
	{
		PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
126
		.driver_data = (kernel_ulong_t)&langwell_pci_platdata,
127 128 129
	},
	{
		PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
130
		.driver_data = (kernel_ulong_t)&penwell_pci_platdata,
131
	},
132 133 134 135 136 137
	{
		/* Intel Clovertrail */
		PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xe006),
		.driver_data = (kernel_ulong_t)&penwell_pci_platdata,
	},
	{ 0 } /* end: all zeroes */
138
};
139
MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
140

141
static struct pci_driver ci_hdrc_pci_driver = {
142
	.name         =	UDC_DRIVER_NAME,
143 144 145
	.id_table     =	ci_hdrc_pci_id_table,
	.probe        =	ci_hdrc_pci_probe,
	.remove       =	ci_hdrc_pci_remove,
146 147
};

148
module_pci_driver(ci_hdrc_pci_driver);
149 150 151 152 153

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