xref: /openbmc/linux/drivers/mmc/host/dw_mmc-pci.c (revision 2874c5fd)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
262ca8034SShashidhar Hiremath /*
362ca8034SShashidhar Hiremath  * Synopsys DesignWare Multimedia Card PCI Interface driver
462ca8034SShashidhar Hiremath  *
562ca8034SShashidhar Hiremath  * Copyright (C) 2012 Vayavya Labs Pvt. Ltd.
662ca8034SShashidhar Hiremath  */
762ca8034SShashidhar Hiremath 
862ca8034SShashidhar Hiremath #include <linux/interrupt.h>
962ca8034SShashidhar Hiremath #include <linux/module.h>
1062ca8034SShashidhar Hiremath #include <linux/io.h>
1162ca8034SShashidhar Hiremath #include <linux/irq.h>
1262ca8034SShashidhar Hiremath #include <linux/pci.h>
1353b27288SShawn Lin #include <linux/pm_runtime.h>
1462ca8034SShashidhar Hiremath #include <linux/slab.h>
1562ca8034SShashidhar Hiremath #include <linux/mmc/host.h>
1662ca8034SShashidhar Hiremath #include <linux/mmc/mmc.h>
1762ca8034SShashidhar Hiremath #include "dw_mmc.h"
1862ca8034SShashidhar Hiremath 
1962ca8034SShashidhar Hiremath #define PCI_BAR_NO 2
2062ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_VENDOR_ID 0x700
2162ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
2262ca8034SShashidhar Hiremath /* Defining the Capabilities */
2362ca8034SShashidhar Hiremath #define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
2462ca8034SShashidhar Hiremath 				MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
2562ca8034SShashidhar Hiremath 				MMC_CAP_SDIO_IRQ)
2662ca8034SShashidhar Hiremath 
2762ca8034SShashidhar Hiremath static struct dw_mci_board pci_board_data = {
2862ca8034SShashidhar Hiremath 	.caps				= DW_MCI_CAPABILITIES,
2962ca8034SShashidhar Hiremath 	.bus_hz				= 33 * 1000 * 1000,
3062ca8034SShashidhar Hiremath 	.detect_delay_ms		= 200,
3162ca8034SShashidhar Hiremath 	.fifo_depth			= 32,
3262ca8034SShashidhar Hiremath };
3362ca8034SShashidhar Hiremath 
dw_mci_pci_probe(struct pci_dev * pdev,const struct pci_device_id * entries)34c3be1efdSBill Pemberton static int dw_mci_pci_probe(struct pci_dev *pdev,
3562ca8034SShashidhar Hiremath 			    const struct pci_device_id *entries)
3662ca8034SShashidhar Hiremath {
3762ca8034SShashidhar Hiremath 	struct dw_mci *host;
3862ca8034SShashidhar Hiremath 	int ret;
3962ca8034SShashidhar Hiremath 
4013959741SAndy Shevchenko 	ret = pcim_enable_device(pdev);
4162ca8034SShashidhar Hiremath 	if (ret)
4262ca8034SShashidhar Hiremath 		return ret;
4362ca8034SShashidhar Hiremath 
4413959741SAndy Shevchenko 	host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
4513959741SAndy Shevchenko 	if (!host)
4613959741SAndy Shevchenko 		return -ENOMEM;
4762ca8034SShashidhar Hiremath 
4862ca8034SShashidhar Hiremath 	host->irq = pdev->irq;
4962ca8034SShashidhar Hiremath 	host->irq_flags = IRQF_SHARED;
504a90920cSThomas Abraham 	host->dev = &pdev->dev;
5162ca8034SShashidhar Hiremath 	host->pdata = &pci_board_data;
5262ca8034SShashidhar Hiremath 
5313959741SAndy Shevchenko 	ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev));
5413959741SAndy Shevchenko 	if (ret)
5513959741SAndy Shevchenko 		return ret;
5662ca8034SShashidhar Hiremath 
57afeb52d6SAndy Shevchenko 	host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO];
5813959741SAndy Shevchenko 
59638585f6SAndy Shevchenko 	pci_set_master(pdev);
60638585f6SAndy Shevchenko 
6162ca8034SShashidhar Hiremath 	ret = dw_mci_probe(host);
6262ca8034SShashidhar Hiremath 	if (ret)
6362ca8034SShashidhar Hiremath 		return ret;
6462ca8034SShashidhar Hiremath 
6513959741SAndy Shevchenko 	pci_set_drvdata(pdev, host);
6613959741SAndy Shevchenko 
6713959741SAndy Shevchenko 	return 0;
6862ca8034SShashidhar Hiremath }
6962ca8034SShashidhar Hiremath 
dw_mci_pci_remove(struct pci_dev * pdev)706e0ee714SBill Pemberton static void dw_mci_pci_remove(struct pci_dev *pdev)
7162ca8034SShashidhar Hiremath {
7262ca8034SShashidhar Hiremath 	struct dw_mci *host = pci_get_drvdata(pdev);
7362ca8034SShashidhar Hiremath 
7462ca8034SShashidhar Hiremath 	dw_mci_remove(host);
7562ca8034SShashidhar Hiremath }
7662ca8034SShashidhar Hiremath 
7753b27288SShawn Lin static const struct dev_pm_ops dw_mci_pci_dev_pm_ops = {
7853b27288SShawn Lin 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
7953b27288SShawn Lin 				pm_runtime_force_resume)
8053b27288SShawn Lin 	SET_RUNTIME_PM_OPS(dw_mci_runtime_suspend,
8153b27288SShawn Lin 			   dw_mci_runtime_resume,
8253b27288SShawn Lin 			   NULL)
8353b27288SShawn Lin };
8462ca8034SShashidhar Hiremath 
859baa3c34SBenoit Taine static const struct pci_device_id dw_mci_pci_id[] = {
8662ca8034SShashidhar Hiremath 	{ PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
8762ca8034SShashidhar Hiremath 	{}
8862ca8034SShashidhar Hiremath };
8962ca8034SShashidhar Hiremath MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
9062ca8034SShashidhar Hiremath 
9162ca8034SShashidhar Hiremath static struct pci_driver dw_mci_pci_driver = {
9262ca8034SShashidhar Hiremath 	.name		= "dw_mmc_pci",
9362ca8034SShashidhar Hiremath 	.id_table	= dw_mci_pci_id,
9462ca8034SShashidhar Hiremath 	.probe		= dw_mci_pci_probe,
954e608e4eSGreg Kroah-Hartman 	.remove		= dw_mci_pci_remove,
9662ca8034SShashidhar Hiremath 	.driver		=	{
9753b27288SShawn Lin 		.pm =   &dw_mci_pci_dev_pm_ops,
9862ca8034SShashidhar Hiremath 	},
9962ca8034SShashidhar Hiremath };
10062ca8034SShashidhar Hiremath 
101350e3e00SSachin Kamat module_pci_driver(dw_mci_pci_driver);
10262ca8034SShashidhar Hiremath 
10362ca8034SShashidhar Hiremath MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
10462ca8034SShashidhar Hiremath MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
10562ca8034SShashidhar Hiremath MODULE_LICENSE("GPL v2");
106