blob: 241ae3444fde92a2927e372493a2432cb066bc7a [file] [log] [blame]
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05301/*
Alexander Shishkin8e229782013-06-24 14:46:36 +03002 * ci_hdrc_pci.c - MIPS USB IP core family device controller
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +05303 *
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 */
Alexander Shishkin8e229782013-06-24 14:46:36 +030021#define UDC_DRIVER_NAME "ci_hdrc_pci"
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053022
23/******************************************************************************
24 * PCI block
25 *****************************************************************************/
Alexander Shishkin8e229782013-06-24 14:46:36 +030026static struct ci_hdrc_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 Shishkin8e229782013-06-24 14:46:36 +030031static struct ci_hdrc_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 Shishkin8e229782013-06-24 14:46:36 +030036static struct ci_hdrc_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/**
Alexander Shishkin8e229782013-06-24 14:46:36 +030043 * ci_hdrc_pci_probe: PCI probe
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053044 * @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 */
Alexander Shishkin8e229782013-06-24 14:46:36 +030051static int ci_hdrc_pci_probe(struct pci_dev *pdev,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053052 const struct pci_device_id *id)
53{
Alexander Shishkin8e229782013-06-24 14:46:36 +030054 struct ci_hdrc_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
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030064 retval = pcim_enable_device(pdev);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053065 if (retval)
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030066 return retval;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053067
68 if (!pdev->irq) {
69 dev_err(&pdev->dev, "No IRQ, check BIOS/PCI setup!");
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030070 return -ENODEV;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053071 }
72
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053073 pci_set_master(pdev);
74 pci_try_set_mwi(pdev);
75
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030076 memset(res, 0, sizeof(res));
77 res[0].start = pci_resource_start(pdev, 0);
78 res[0].end = pci_resource_end(pdev, 0);
79 res[0].flags = IORESOURCE_MEM;
80 res[1].start = pdev->irq;
81 res[1].flags = IORESOURCE_IRQ;
82
Alexander Shishkin8e229782013-06-24 14:46:36 +030083 plat_ci = ci_hdrc_add_device(&pdev->dev, res, nres, platdata);
Richard Zhaocbc6dc22012-07-07 22:56:41 +080084 if (IS_ERR(plat_ci)) {
Alexander Shishkin8e229782013-06-24 14:46:36 +030085 dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
Andy Shevchenko8b2379b2013-06-13 18:00:02 +030086 return PTR_ERR(plat_ci);
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030087 }
88
Alexander Shishkin62bb84e2012-05-08 23:29:01 +030089 pci_set_drvdata(pdev, plat_ci);
90
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053091 return 0;
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053092}
93
94/**
Alexander Shishkin8e229782013-06-24 14:46:36 +030095 * ci_hdrc_pci_remove: PCI remove
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053096 * @pdev: USB Device Controller being removed
97 *
Alexander Shishkin8e229782013-06-24 14:46:36 +030098 * Reverses the effect of ci_hdrc_pci_probe(),
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +053099 * first invoking the udc_remove() and then releases
100 * all PCI resources allocated for this USB device controller
101 */
Alexander Shishkin8e229782013-06-24 14:46:36 +0300102static void ci_hdrc_pci_remove(struct pci_dev *pdev)
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530103{
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300104 struct platform_device *plat_ci = pci_get_drvdata(pdev);
105
Alexander Shishkin8e229782013-06-24 14:46:36 +0300106 ci_hdrc_remove_device(plat_ci);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530107}
108
109/**
110 * PCI device table
111 * PCI device structure
112 *
113 * Check "pci.h" for details
114 */
Jingoo Han4e065b82013-11-28 14:15:26 +0900115static const struct pci_device_id ci_hdrc_pci_id_table[] = {
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300116 {
117 PCI_DEVICE(0x153F, 0x1004),
Richard Zhao77c44002012-06-29 17:48:53 +0800118 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300119 },
120 {
121 PCI_DEVICE(0x153F, 0x1006),
Richard Zhao77c44002012-06-29 17:48:53 +0800122 .driver_data = (kernel_ulong_t)&pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300123 },
124 {
125 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0811),
Richard Zhao77c44002012-06-29 17:48:53 +0800126 .driver_data = (kernel_ulong_t)&langwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300127 },
128 {
129 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0829),
Richard Zhao77c44002012-06-29 17:48:53 +0800130 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
Alexander Shishkin62bb84e2012-05-08 23:29:01 +0300131 },
David Cohena2143392013-10-01 14:32:58 -0700132 {
133 /* Intel Clovertrail */
134 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xe006),
135 .driver_data = (kernel_ulong_t)&penwell_pci_platdata,
136 },
137 { 0 } /* end: all zeroes */
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530138};
Alexander Shishkin8e229782013-06-24 14:46:36 +0300139MODULE_DEVICE_TABLE(pci, ci_hdrc_pci_id_table);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530140
Alexander Shishkin8e229782013-06-24 14:46:36 +0300141static struct pci_driver ci_hdrc_pci_driver = {
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530142 .name = UDC_DRIVER_NAME,
Alexander Shishkin8e229782013-06-24 14:46:36 +0300143 .id_table = ci_hdrc_pci_id_table,
144 .probe = ci_hdrc_pci_probe,
145 .remove = ci_hdrc_pci_remove,
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530146};
147
Alexander Shishkin8e229782013-06-24 14:46:36 +0300148module_pci_driver(ci_hdrc_pci_driver);
Pavankumar Kondeti409a15d2010-12-07 17:53:59 +0530149
150MODULE_AUTHOR("MIPS - David Lopo <dlopo@chipidea.mips.com>");
151MODULE_DESCRIPTION("MIPS CI13XXX USB Peripheral Controller");
152MODULE_LICENSE("GPL");
153MODULE_VERSION("June 2008");
Alexander Shishkin8e229782013-06-24 14:46:36 +0300154MODULE_ALIAS("platform:ci13xxx_pci");