blob: ab82796b01e2665eca6c82645f7938981f1b469a [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>
Shawn Lin53b27282016-10-12 10:56:34 +080017#include <linux/pm_runtime.h>
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053018#include <linux/slab.h>
19#include <linux/mmc/host.h>
20#include <linux/mmc/mmc.h>
21#include <linux/mmc/dw_mmc.h>
22#include "dw_mmc.h"
23
24#define PCI_BAR_NO 2
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053025#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,
Andy Shevchenko13959742013-06-05 12:24:12 +030041 const struct pci_device_id *entries)
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053042{
43 struct dw_mci *host;
44 int ret;
45
Andy Shevchenko13959742013-06-05 12:24:12 +030046 ret = pcim_enable_device(pdev);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053047 if (ret)
48 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053049
Andy Shevchenko13959742013-06-05 12:24:12 +030050 host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
51 if (!host)
52 return -ENOMEM;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053053
54 host->irq = pdev->irq;
55 host->irq_flags = IRQF_SHARED;
Thomas Abraham4a909202012-09-17 18:16:35 +000056 host->dev = &pdev->dev;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053057 host->pdata = &pci_board_data;
58
Andy Shevchenko13959742013-06-05 12:24:12 +030059 ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev));
60 if (ret)
61 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053062
Andy Shevchenkoafeb52d2013-08-08 13:44:57 +030063 host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO];
Andy Shevchenko13959742013-06-05 12:24:12 +030064
Andy Shevchenko638585f2013-08-08 13:44:58 +030065 pci_set_master(pdev);
66
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053067 ret = dw_mci_probe(host);
68 if (ret)
Andy Shevchenko13959742013-06-05 12:24:12 +030069 return ret;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053070
Andy Shevchenko13959742013-06-05 12:24:12 +030071 pci_set_drvdata(pdev, host);
72
73 return 0;
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053074}
75
Bill Pemberton6e0ee712012-11-19 13:26:03 -050076static void dw_mci_pci_remove(struct pci_dev *pdev)
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053077{
78 struct dw_mci *host = pci_get_drvdata(pdev);
79
80 dw_mci_remove(host);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053081}
82
Shawn Lin53b27282016-10-12 10:56:34 +080083static const struct dev_pm_ops dw_mci_pci_dev_pm_ops = {
84 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
85 pm_runtime_force_resume)
86 SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
87 dw_mci_runtime_resume,
88 NULL)
89};
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053090
Benoit Taine9baa3c32014-08-08 15:56:03 +020091static const struct pci_device_id dw_mci_pci_id[] = {
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053092 { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
93 {}
94};
95MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
96
97static struct pci_driver dw_mci_pci_driver = {
98 .name = "dw_mmc_pci",
99 .id_table = dw_mci_pci_id,
100 .probe = dw_mci_pci_probe,
Greg Kroah-Hartman4e608e42012-12-21 15:05:47 -0800101 .remove = dw_mci_pci_remove,
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530102 .driver = {
Shawn Lin53b27282016-10-12 10:56:34 +0800103 .pm = &dw_mci_pci_dev_pm_ops,
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530104 },
105};
106
Sachin Kamat350e3e02012-08-27 11:59:17 +0530107module_pci_driver(dw_mci_pci_driver);
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530108
109MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
110MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
111MODULE_LICENSE("GPL v2");