blob: 59fab90ee73113ea3e993a734eca6babae41233c [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>
Alexander Shishkine443b332012-05-11 17:25:46 +030018#include <linux/usb/chipidea.h>
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053019
20/* driver name */
21#define UDC_DRIVER_NAME "ci13xxx_pci"
22
23/******************************************************************************
24 * PCI block
25 *****************************************************************************/
Alexander Shishkinefccca42013-03-30 12:54:02 +020026static struct ci13xxx_platform_data pci_platdata = {
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053027 .name = UDC_DRIVER_NAME,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030028 .capoffset = DEF_CAPOFFSET,
29};
30
Alexander Shishkinefccca42013-03-30 12:54:02 +020031static struct ci13xxx_platform_data langwell_pci_platdata = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030032 .name = UDC_DRIVER_NAME,
33 .capoffset = 0,
Pavankumar Kondetif01ef572010-12-07 17:54:02 +053034};
35
Alexander Shishkinefccca42013-03-30 12:54:02 +020036static struct ci13xxx_platform_data penwell_pci_platdata = {
Alexander Shishkinbd841982012-05-11 17:25:55 +030037 .name = UDC_DRIVER_NAME,
38 .capoffset = 0,
39 .power_budget = 200,
40};
41
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053042/**
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 Pemberton41ac7b32012-11-19 13:21:48 -050051static int ci13xxx_pci_probe(struct pci_dev *pdev,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053052 const struct pci_device_id *id)
53{
Richard Zhao77c44002012-06-29 17:48:53 +080054 struct ci13xxx_platform_data *platdata = (void *)id->driver_data;
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030055 struct platform_device *plat_ci;
56 struct resource res[3];
57 int retval = 0, nres = 2;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053058
Richard Zhao77c44002012-06-29 17:48:53 +080059 if (!platdata) {
Alexander Shishkin1989b5c2012-05-11 17:25:40 +030060 dev_err(&pdev->dev, "device doesn't provide driver data\n");
61 return -ENODEV;
62 }
63
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053064 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
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053074 pci_set_master(pdev);
75 pci_try_set_mwi(pdev);
76
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030077 memset(res, 0, sizeof(res));
78 res[0].start = pci_resource_start(pdev, 0);
79 res[0].end = pci_resource_end(pdev, 0);
80 res[0].flags = IORESOURCE_MEM;
81 res[1].start = pdev->irq;
82 res[1].flags = IORESOURCE_IRQ;
83
Richard Zhaocbc6dc22012-07-07 22:56:41 +080084 plat_ci = ci13xxx_add_device(&pdev->dev, res, nres, platdata);
85 if (IS_ERR(plat_ci)) {
86 dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
87 retval = PTR_ERR(plat_ci);
88 goto disable_device;
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030089 }
90
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030091 pci_set_drvdata(pdev, plat_ci);
92
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053093 return 0;
94
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053095 disable_device:
96 pci_disable_device(pdev);
97 done:
98 return retval;
99}
100
101/**
102 * ci13xxx_pci_remove: PCI remove
103 * @pdev: USB Device Controller being removed
104 *
105 * Reverses the effect of ci13xxx_pci_probe(),
106 * first invoking the udc_remove() and then releases
107 * all PCI resources allocated for this USB device controller
108 */
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500109static void ci13xxx_pci_remove(struct pci_dev *pdev)
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530110{
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300111 struct platform_device *plat_ci = pci_get_drvdata(pdev);
112
Richard Zhaocbc6dc22012-07-07 22:56:41 +0800113 ci13xxx_remove_device(plat_ci);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530114 pci_disable_device(pdev);
115}
116
117/**
118 * PCI device table
119 * PCI device structure
120 *
121 * Check "pci.h" for details
122 */
123static DEFINE_PCI_DEVICE_TABLE(ci13xxx_pci_id_table) = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300124 {
125 PCI_DEVICE(0x153F, 0x1004),
Richard Zhao77c44002012-06-29 17:48:53 +0800126 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300127 },
128 {
129 PCI_DEVICE(0x153F, 0x1006),
Richard Zhao77c44002012-06-29 17:48:53 +0800130 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300131 },
132 {
133 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
Richard Zhao77c44002012-06-29 17:48:53 +0800134 .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300135 },
136 {
137 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
Richard Zhao77c44002012-06-29 17:48:53 +0800138 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300139 },
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530140 { 0, 0, 0, 0, 0, 0, 0 /* end: all zeroes */ }
141};
142MODULE_DEVICE_TABLE(pci, ci13xxx_pci_id_table);
143
144static struct pci_driver ci13xxx_pci_driver = {
145 .name = UDC_DRIVER_NAME,
146 .id_table = ci13xxx_pci_id_table,
147 .probe = ci13xxx_pci_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500148 .remove = ci13xxx_pci_remove,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530149};
150
Axel Lin3cdb7722012-04-04 22:14:58 +0800151module_pci_driver(ci13xxx_pci_driver);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530152
153MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
154MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
155MODULE_LICENSE("GPL");
156MODULE_VERSION("June 2008");