blob: c469ce624bb86283a589427afadc619460d3c660 [file] [log] [blame]
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +05301/*
2 * Synopsys DesignWare Multimedia Card PCI Interface driver
3 *
4 * Copyright (C) 2012 Vayavya Labs Pvt. Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/interrupt.h>
13#include <linux/module.h>
14#include <linux/io.h>
15#include <linux/irq.h>
16#include <linux/pci.h>
17#include <linux/slab.h>
18#include <linux/mmc/host.h>
19#include <linux/mmc/mmc.h>
20#include <linux/mmc/dw_mmc.h>
21#include "dw_mmc.h"
22
23#define PCI_BAR_NO 2
24#define COMPLETE_BAR 0
25#define SYNOPSYS_DW_MCI_VENDOR_ID 0x700
26#define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
27/* Defining the Capabilities */
28#define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
29 MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
30 MMC_CAP_SDIO_IRQ)
31
32static struct dw_mci_board pci_board_data = {
33 .num_slots = 1,
34 .caps = DW_MCI_CAPABILITIES,
35 .bus_hz = 33 * 1000 * 1000,
36 .detect_delay_ms = 200,
37 .fifo_depth = 32,
38};
39
Bill Pembertonc3be1ef2012-11-19 13:23:06 -050040static int dw_mci_pci_probe(struct pci_dev *pdev,
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053041 const struct pci_device_id *entries)
42{
43 struct dw_mci *host;
44 int ret;
45
46 ret = pci_enable_device(pdev);
47 if (ret)
48 return ret;
49 if (pci_request_regions(pdev, "dw_mmc_pci")) {
50 ret = -ENODEV;
51 goto err_disable_dev;
52 }
53
54 host = kzalloc(sizeof(struct dw_mci), GFP_KERNEL);
55 if (!host) {
56 ret = -ENOMEM;
57 goto err_release;
58 }
59
60 host->irq = pdev->irq;
61 host->irq_flags = IRQF_SHARED;
Thomas Abraham4a909202012-09-17 18:16:35 +000062 host->dev = &pdev->dev;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053063 host->pdata = &pci_board_data;
64
65 host->regs = pci_iomap(pdev, PCI_BAR_NO, COMPLETE_BAR);
66 if (!host->regs) {
67 ret = -EIO;
68 goto err_unmap;
69 }
70
71 pci_set_drvdata(pdev, host);
72 ret = dw_mci_probe(host);
73 if (ret)
74 goto err_probe_failed;
75 return ret;
76
77err_probe_failed:
78 pci_iounmap(pdev, host->regs);
79err_unmap:
80 kfree(host);
81err_release:
82 pci_release_regions(pdev);
83err_disable_dev:
84 pci_disable_device(pdev);
85 return ret;
86}
87
Bill Pemberton6e0ee712012-11-19 13:26:03 -050088static void dw_mci_pci_remove(struct pci_dev *pdev)
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053089{
90 struct dw_mci *host = pci_get_drvdata(pdev);
91
92 dw_mci_remove(host);
93 pci_set_drvdata(pdev, NULL);
94 pci_release_regions(pdev);
95 pci_iounmap(pdev, host->regs);
96 kfree(host);
97 pci_disable_device(pdev);
98}
99
100#ifdef CONFIG_PM_SLEEP
101static int dw_mci_pci_suspend(struct device *dev)
102{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530103 struct pci_dev *pdev = to_pci_dev(dev);
104 struct dw_mci *host = pci_get_drvdata(pdev);
105
Andy Shevchenkodd369802013-06-05 12:24:11 +0300106 return dw_mci_suspend(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530107}
108
109static int dw_mci_pci_resume(struct device *dev)
110{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530111 struct pci_dev *pdev = to_pci_dev(dev);
112 struct dw_mci *host = pci_get_drvdata(pdev);
113
Andy Shevchenkodd369802013-06-05 12:24:11 +0300114 return dw_mci_resume(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530115}
116#else
117#define dw_mci_pci_suspend NULL
118#define dw_mci_pci_resume NULL
119#endif /* CONFIG_PM_SLEEP */
120
121static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
122
123static DEFINE_PCI_DEVICE_TABLE(dw_mci_pci_id) = {
124 { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
125 {}
126};
127MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
128
129static struct pci_driver dw_mci_pci_driver = {
130 .name = "dw_mmc_pci",
131 .id_table = dw_mci_pci_id,
132 .probe = dw_mci_pci_probe,
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800133 .remove = dw_mci_pci_remove,
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530134 .driver = {
135 .pm = &dw_mci_pci_pmops
136 },
137};
138
Sachin Kamat350e3e02012-08-27 11:59:17 +0530139module_pci_driver(dw_mci_pci_driver);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530140
141MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
142MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
143MODULE_LICENSE("GPL v2");