162ca8034SShashidhar Hiremath /* 262ca8034SShashidhar Hiremath * Synopsys DesignWare Multimedia Card PCI Interface driver 362ca8034SShashidhar Hiremath * 462ca8034SShashidhar Hiremath * Copyright (C) 2012 Vayavya Labs Pvt. Ltd. 562ca8034SShashidhar Hiremath * 662ca8034SShashidhar Hiremath * This program is free software; you can redistribute it and/or modify 762ca8034SShashidhar Hiremath * it under the terms of the GNU General Public License as published by 862ca8034SShashidhar Hiremath * the Free Software Foundation; either version 2 of the License, or 962ca8034SShashidhar Hiremath * (at your option) any later version. 1062ca8034SShashidhar Hiremath */ 1162ca8034SShashidhar Hiremath 1262ca8034SShashidhar Hiremath #include <linux/interrupt.h> 1362ca8034SShashidhar Hiremath #include <linux/module.h> 1462ca8034SShashidhar Hiremath #include <linux/io.h> 1562ca8034SShashidhar Hiremath #include <linux/irq.h> 1662ca8034SShashidhar Hiremath #include <linux/pci.h> 1753b27288SShawn Lin #include <linux/pm_runtime.h> 1862ca8034SShashidhar Hiremath #include <linux/slab.h> 1962ca8034SShashidhar Hiremath #include <linux/mmc/host.h> 2062ca8034SShashidhar Hiremath #include <linux/mmc/mmc.h> 2162ca8034SShashidhar Hiremath #include <linux/mmc/dw_mmc.h> 2262ca8034SShashidhar Hiremath #include "dw_mmc.h" 2362ca8034SShashidhar Hiremath 2462ca8034SShashidhar Hiremath #define PCI_BAR_NO 2 2562ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_VENDOR_ID 0x700 2662ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107 2762ca8034SShashidhar Hiremath /* Defining the Capabilities */ 2862ca8034SShashidhar Hiremath #define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\ 2962ca8034SShashidhar Hiremath MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\ 3062ca8034SShashidhar Hiremath MMC_CAP_SDIO_IRQ) 3162ca8034SShashidhar Hiremath 3262ca8034SShashidhar Hiremath static struct dw_mci_board pci_board_data = { 3362ca8034SShashidhar Hiremath .num_slots = 1, 3462ca8034SShashidhar Hiremath .caps = DW_MCI_CAPABILITIES, 3562ca8034SShashidhar Hiremath .bus_hz = 33 * 1000 * 1000, 3662ca8034SShashidhar Hiremath .detect_delay_ms = 200, 3762ca8034SShashidhar Hiremath .fifo_depth = 32, 3862ca8034SShashidhar Hiremath }; 3962ca8034SShashidhar Hiremath 40c3be1efdSBill Pemberton static int dw_mci_pci_probe(struct pci_dev *pdev, 4162ca8034SShashidhar Hiremath const struct pci_device_id *entries) 4262ca8034SShashidhar Hiremath { 4362ca8034SShashidhar Hiremath struct dw_mci *host; 4462ca8034SShashidhar Hiremath int ret; 4562ca8034SShashidhar Hiremath 4613959741SAndy Shevchenko ret = pcim_enable_device(pdev); 4762ca8034SShashidhar Hiremath if (ret) 4862ca8034SShashidhar Hiremath return ret; 4962ca8034SShashidhar Hiremath 5013959741SAndy Shevchenko host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL); 5113959741SAndy Shevchenko if (!host) 5213959741SAndy Shevchenko return -ENOMEM; 5362ca8034SShashidhar Hiremath 5462ca8034SShashidhar Hiremath host->irq = pdev->irq; 5562ca8034SShashidhar Hiremath host->irq_flags = IRQF_SHARED; 564a90920cSThomas Abraham host->dev = &pdev->dev; 5762ca8034SShashidhar Hiremath host->pdata = &pci_board_data; 5862ca8034SShashidhar Hiremath 5913959741SAndy Shevchenko ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev)); 6013959741SAndy Shevchenko if (ret) 6113959741SAndy Shevchenko return ret; 6262ca8034SShashidhar Hiremath 63afeb52d6SAndy Shevchenko host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO]; 6413959741SAndy Shevchenko 65638585f6SAndy Shevchenko pci_set_master(pdev); 66638585f6SAndy Shevchenko 6762ca8034SShashidhar Hiremath ret = dw_mci_probe(host); 6862ca8034SShashidhar Hiremath if (ret) 6962ca8034SShashidhar Hiremath return ret; 7062ca8034SShashidhar Hiremath 7113959741SAndy Shevchenko pci_set_drvdata(pdev, host); 7213959741SAndy Shevchenko 7313959741SAndy Shevchenko return 0; 7462ca8034SShashidhar Hiremath } 7562ca8034SShashidhar Hiremath 766e0ee714SBill Pemberton static void dw_mci_pci_remove(struct pci_dev *pdev) 7762ca8034SShashidhar Hiremath { 7862ca8034SShashidhar Hiremath struct dw_mci *host = pci_get_drvdata(pdev); 7962ca8034SShashidhar Hiremath 8062ca8034SShashidhar Hiremath dw_mci_remove(host); 8162ca8034SShashidhar Hiremath } 8262ca8034SShashidhar Hiremath 8353b27288SShawn Lin static const struct dev_pm_ops dw_mci_pci_dev_pm_ops = { 8453b27288SShawn Lin SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, 8553b27288SShawn Lin pm_runtime_force_resume) 8653b27288SShawn Lin SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend, 8753b27288SShawn Lin dw_mci_runtime_resume, 8853b27288SShawn Lin NULL) 8953b27288SShawn Lin }; 9062ca8034SShashidhar Hiremath 919baa3c34SBenoit Taine static const struct pci_device_id dw_mci_pci_id[] = { 9262ca8034SShashidhar Hiremath { PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) }, 9362ca8034SShashidhar Hiremath {} 9462ca8034SShashidhar Hiremath }; 9562ca8034SShashidhar Hiremath MODULE_DEVICE_TABLE(pci, dw_mci_pci_id); 9662ca8034SShashidhar Hiremath 9762ca8034SShashidhar Hiremath static struct pci_driver dw_mci_pci_driver = { 9862ca8034SShashidhar Hiremath .name = "dw_mmc_pci", 9962ca8034SShashidhar Hiremath .id_table = dw_mci_pci_id, 10062ca8034SShashidhar Hiremath .probe = dw_mci_pci_probe, 1014e608e4eSGreg Kroah-Hartman .remove = dw_mci_pci_remove, 10262ca8034SShashidhar Hiremath .driver = { 10353b27288SShawn Lin .pm = &dw_mci_pci_dev_pm_ops, 10462ca8034SShashidhar Hiremath }, 10562ca8034SShashidhar Hiremath }; 10662ca8034SShashidhar Hiremath 107350e3e00SSachin Kamat module_pci_driver(dw_mci_pci_driver); 10862ca8034SShashidhar Hiremath 10962ca8034SShashidhar Hiremath MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver"); 11062ca8034SShashidhar Hiremath MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>"); 11162ca8034SShashidhar Hiremath MODULE_LICENSE("GPL v2"); 112