blob: 4c69fbd2981190734d4ef1ff9861df73c1ab5806 [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
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053024#define SYNOPSYS_DW_MCI_VENDOR_ID 0x700
25#define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
26/* Defining the Capabilities */
27#define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
28 MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
29 MMC_CAP_SDIO_IRQ)
30
31static struct dw_mci_board pci_board_data = {
32 .num_slots = 1,
33 .caps = DW_MCI_CAPABILITIES,
34 .bus_hz = 33 * 1000 * 1000,
35 .detect_delay_ms = 200,
36 .fifo_depth = 32,
37};
38
Bill Pembertonc3be1ef2012-11-19 13:23:06 -050039static int dw_mci_pci_probe(struct pci_dev *pdev,
Andy Shevchenko13959742013-06-05 12:24:12 +030040 const struct pci_device_id *entries)
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053041{
42 struct dw_mci *host;
43 int ret;
44
Andy Shevchenko13959742013-06-05 12:24:12 +030045 ret = pcim_enable_device(pdev);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053046 if (ret)
47 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053048
Andy Shevchenko13959742013-06-05 12:24:12 +030049 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
50 if (!host)
51 return -ENOMEM;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053052
53 host->irq = pdev->irq;
54 host->irq_flags = IRQF_SHARED;
Thomas Abraham4a909202012-09-17 18:16:35 +000055 host->dev = &pdev->dev;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053056 host->pdata = &pci_board_data;
57
Andy Shevchenko13959742013-06-05 12:24:12 +030058 ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev));
59 if (ret)
60 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053061
Andy Shevchenkoafeb52d2013-08-08 13:44:57 +030062 host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO];
Andy Shevchenko13959742013-06-05 12:24:12 +030063
Andy Shevchenko638585f2013-08-08 13:44:58 +030064 pci_set_master(pdev);
65
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053066 ret = dw_mci_probe(host);
67 if (ret)
Andy Shevchenko13959742013-06-05 12:24:12 +030068 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053069
Andy Shevchenko13959742013-06-05 12:24:12 +030070 pci_set_drvdata(pdev, host);
71
72 return 0;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053073}
74
Bill Pemberton6e0ee712012-11-19 13:26:03 -050075static void dw_mci_pci_remove(struct pci_dev *pdev)
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053076{
77 struct dw_mci *host = pci_get_drvdata(pdev);
78
79 dw_mci_remove(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053080}
81
82#ifdef CONFIG_PM_SLEEP
83static int dw_mci_pci_suspend(struct device *dev)
84{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053085 struct pci_dev *pdev = to_pci_dev(dev);
86 struct dw_mci *host = pci_get_drvdata(pdev);
87
Andy Shevchenkodd369802013-06-05 12:24:11 +030088 return dw_mci_suspend(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053089}
90
91static int dw_mci_pci_resume(struct device *dev)
92{
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053093 struct pci_dev *pdev = to_pci_dev(dev);
94 struct dw_mci *host = pci_get_drvdata(pdev);
95
Andy Shevchenkodd369802013-06-05 12:24:11 +030096 return dw_mci_resume(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053097}
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053098#endif /* CONFIG_PM_SLEEP */
99
100static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
101
Benoit Taine9baa3c32014-08-08 15:56:03 +0200102static const struct pci_device_id dw_mci_pci_id[] = {
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530103 { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
104 {}
105};
106MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
107
108static struct pci_driver dw_mci_pci_driver = {
109 .name = "dw_mmc_pci",
110 .id_table = dw_mci_pci_id,
111 .probe = dw_mci_pci_probe,
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800112 .remove = dw_mci_pci_remove,
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530113 .driver = {
114 .pm = &dw_mci_pci_pmops
115 },
116};
117
Sachin Kamat350e3e02012-08-27 11:59:17 +0530118module_pci_driver(dw_mci_pci_driver);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530119
120MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
121MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
122MODULE_LICENSE("GPL v2");