blob: c76844110e36f857cc321d97a9ffaff20a4c8f2e [file] [log] [blame]
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05301/*
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 Shishkin62bb84e2012-05-08 23:29:01 +030013#include <linux/platform_device.h>
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053014#include <linux/module.h>
15#include <linux/pci.h>
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030016#include <linux/interrupt.h>
17#include <linux/usb/gadget.h>
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053018
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030019#include "ci13xxx_udc.h"
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053020
21/* driver name */
22#define UDC_DRIVER_NAME "ci13xxx_pci"
23
24/******************************************************************************
25 * PCI block
26 *****************************************************************************/
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030027struct ci13xxx_udc_driver pci_driver = {
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053028 .name = UDC_DRIVER_NAME,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030029 .capoffset = DEF_CAPOFFSET,
30};
31
32struct ci13xxx_udc_driver langwell_pci_driver = {
33 .name = UDC_DRIVER_NAME,
34 .capoffset = 0,
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053035};
36
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053037/**
38 * ci13xxx_pci_probe: PCI probe
39 * @pdev: USB device controller being probed
40 * @id: PCI hotplug ID connecting controller to UDC framework
41 *
42 * This function returns an error code
43 * Allocates basic PCI resources for this USB device controller, and then
44 * invokes the udc_probe() method to start the UDC associated with it
45 */
46static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
47 const struct pci_device_id *id)
48{
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030049 struct ci13xxx_udc_driver *driver = (void *)id->driver_data;
50 struct platform_device *plat_ci;
51 struct resource res[3];
52 int retval = 0, nres = 2;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053053
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053054 retval = pci_enable_device(pdev);
55 if (retval)
56 goto done;
57
58 if (!pdev->irq) {
59 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
60 retval = -ENODEV;
61 goto disable_device;
62 }
63
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030064 pci_set_power_state(pdev, PCI_D0);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053065 pci_set_master(pdev);
66 pci_try_set_mwi(pdev);
67
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030068 plat_ci = platform_device_alloc("ci_udc", -1);
69 if (!plat_ci) {
70 dev_err(&pdev->dev, "can't allocate ci_udc platform device\n");
71 retval = -ENOMEM;
72 goto disable_device;
73 }
Alexander Shishkinf9df8392012-05-04 16:47:16 +030074
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030075 memset(res, 0, sizeof(res));
76 res[0].start = pci_resource_start(pdev, 0);
77 res[0].end = pci_resource_end(pdev, 0);
78 res[0].flags = IORESOURCE_MEM;
79 res[1].start = pdev->irq;
80 res[1].flags = IORESOURCE_IRQ;
81
82 retval = platform_device_add_resources(plat_ci, res, nres);
83 if (retval) {
84 dev_err(&pdev->dev, "can't add resources to platform device\n");
85 goto put_platform;
86 }
87
88 retval = platform_device_add_data(plat_ci, driver, sizeof(*driver));
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053089 if (retval)
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030090 goto put_platform;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053091
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030092 dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
93 plat_ci->dev.dma_mask = pdev->dev.dma_mask;
94 plat_ci->dev.dma_parms = pdev->dev.dma_parms;
95 plat_ci->dev.parent = &pdev->dev;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053096
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030097 pci_set_drvdata(pdev, plat_ci);
98
99 retval = platform_device_add(plat_ci);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530100 if (retval)
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300101 goto put_platform;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530102
103 return 0;
104
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300105 put_platform:
106 pci_set_drvdata(pdev, NULL);
107 platform_device_put(plat_ci);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530108 disable_device:
109 pci_disable_device(pdev);
110 done:
111 return retval;
112}
113
114/**
115 * ci13xxx_pci_remove: PCI remove
116 * @pdev: USB Device Controller being removed
117 *
118 * Reverses the effect of ci13xxx_pci_probe(),
119 * first invoking the udc_remove() and then releases
120 * all PCI resources allocated for this USB device controller
121 */
122static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
123{
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300124 struct platform_device *plat_ci = pci_get_drvdata(pdev);
125
126 platform_device_unregister(plat_ci);
127 pci_set_drvdata(pdev, NULL);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530128 pci_disable_device(pdev);
129}
130
131/**
132 * PCI device table
133 * PCI device structure
134 *
135 * Check "pci.h" for details
136 */
137static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300138 {
139 PCI_DEVICE(0x153F, 0x1004),
140 .driver_data = (kernel_ulong_t)&pci_driver,
141 },
142 {
143 PCI_DEVICE(0x153F, 0x1006),
144 .driver_data = (kernel_ulong_t)&pci_driver,
145 },
146 {
147 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
148 .driver_data = (kernel_ulong_t)&langwell_pci_driver,
149 },
150 {
151 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
152 .driver_data = (kernel_ulong_t)&langwell_pci_driver,
153 },
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530154 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
155};
156MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
157
158static struct pci_driver ci13xxx_pci_driver = {
159 .name = UDC_DRIVER_NAME,
160 .id_table = ci13xxx_pci_id_table,
161 .probe = ci13xxx_pci_probe,
162 .remove = __devexit_p(ci13xxx_pci_remove),
163};
164
Axel Lin3cdb7722012-04-04 22:14:58 +0800165module_pci_driver(ci13xxx_pci_driver);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530166
167MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
168MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
169MODULE_LICENSE("GPL");
170MODULE_VERSION("June 2008");