xref: /openbmc/linux/drivers/mmc/host/dw_mmc-pci.c (revision 9baa3c34)
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>
1762ca8034SShashidhar Hiremath #include <linux/slab.h>
1862ca8034SShashidhar Hiremath #include <linux/mmc/host.h>
1962ca8034SShashidhar Hiremath #include <linux/mmc/mmc.h>
2062ca8034SShashidhar Hiremath #include <linux/mmc/dw_mmc.h>
2162ca8034SShashidhar Hiremath #include "dw_mmc.h"
2262ca8034SShashidhar Hiremath 
2362ca8034SShashidhar Hiremath #define PCI_BAR_NO 2
2462ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_VENDOR_ID 0x700
2562ca8034SShashidhar Hiremath #define SYNOPSYS_DW_MCI_DEVICE_ID 0x1107
2662ca8034SShashidhar Hiremath /* Defining the Capabilities */
2762ca8034SShashidhar Hiremath #define DW_MCI_CAPABILITIES (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED |\
2862ca8034SShashidhar Hiremath 				MMC_CAP_SD_HIGHSPEED | MMC_CAP_8_BIT_DATA |\
2962ca8034SShashidhar Hiremath 				MMC_CAP_SDIO_IRQ)
3062ca8034SShashidhar Hiremath 
3162ca8034SShashidhar Hiremath static struct dw_mci_board pci_board_data = {
3262ca8034SShashidhar Hiremath 	.num_slots			= 1,
3362ca8034SShashidhar Hiremath 	.caps				= DW_MCI_CAPABILITIES,
3462ca8034SShashidhar Hiremath 	.bus_hz				= 33 * 1000 * 1000,
3562ca8034SShashidhar Hiremath 	.detect_delay_ms		= 200,
3662ca8034SShashidhar Hiremath 	.fifo_depth			= 32,
3762ca8034SShashidhar Hiremath };
3862ca8034SShashidhar Hiremath 
39c3be1efdSBill Pemberton static int dw_mci_pci_probe(struct pci_dev *pdev,
4062ca8034SShashidhar Hiremath 			    const struct pci_device_id *entries)
4162ca8034SShashidhar Hiremath {
4262ca8034SShashidhar Hiremath 	struct dw_mci *host;
4362ca8034SShashidhar Hiremath 	int ret;
4462ca8034SShashidhar Hiremath 
4513959741SAndy Shevchenko 	ret = pcim_enable_device(pdev);
4662ca8034SShashidhar Hiremath 	if (ret)
4762ca8034SShashidhar Hiremath 		return ret;
4862ca8034SShashidhar Hiremath 
4913959741SAndy Shevchenko 	host = devm_kzalloc(&pdev->dev, sizeof(struct dw_mci), GFP_KERNEL);
5013959741SAndy Shevchenko 	if (!host)
5113959741SAndy Shevchenko 		return -ENOMEM;
5262ca8034SShashidhar Hiremath 
5362ca8034SShashidhar Hiremath 	host->irq = pdev->irq;
5462ca8034SShashidhar Hiremath 	host->irq_flags = IRQF_SHARED;
554a90920cSThomas Abraham 	host->dev = &pdev->dev;
5662ca8034SShashidhar Hiremath 	host->pdata = &pci_board_data;
5762ca8034SShashidhar Hiremath 
5813959741SAndy Shevchenko 	ret = pcim_iomap_regions(pdev, 1 << PCI_BAR_NO, pci_name(pdev));
5913959741SAndy Shevchenko 	if (ret)
6013959741SAndy Shevchenko 		return ret;
6162ca8034SShashidhar Hiremath 
62afeb52d6SAndy Shevchenko 	host->regs = pcim_iomap_table(pdev)[PCI_BAR_NO];
6313959741SAndy Shevchenko 
64638585f6SAndy Shevchenko 	pci_set_master(pdev);
65638585f6SAndy Shevchenko 
6662ca8034SShashidhar Hiremath 	ret = dw_mci_probe(host);
6762ca8034SShashidhar Hiremath 	if (ret)
6862ca8034SShashidhar Hiremath 		return ret;
6962ca8034SShashidhar Hiremath 
7013959741SAndy Shevchenko 	pci_set_drvdata(pdev, host);
7113959741SAndy Shevchenko 
7213959741SAndy Shevchenko 	return 0;
7362ca8034SShashidhar Hiremath }
7462ca8034SShashidhar Hiremath 
756e0ee714SBill Pemberton static void dw_mci_pci_remove(struct pci_dev *pdev)
7662ca8034SShashidhar Hiremath {
7762ca8034SShashidhar Hiremath 	struct dw_mci *host = pci_get_drvdata(pdev);
7862ca8034SShashidhar Hiremath 
7962ca8034SShashidhar Hiremath 	dw_mci_remove(host);
8062ca8034SShashidhar Hiremath }
8162ca8034SShashidhar Hiremath 
8262ca8034SShashidhar Hiremath #ifdef CONFIG_PM_SLEEP
8362ca8034SShashidhar Hiremath static int dw_mci_pci_suspend(struct device *dev)
8462ca8034SShashidhar Hiremath {
8562ca8034SShashidhar Hiremath 	struct pci_dev *pdev = to_pci_dev(dev);
8662ca8034SShashidhar Hiremath 	struct dw_mci *host = pci_get_drvdata(pdev);
8762ca8034SShashidhar Hiremath 
88dd369800SAndy Shevchenko 	return dw_mci_suspend(host);
8962ca8034SShashidhar Hiremath }
9062ca8034SShashidhar Hiremath 
9162ca8034SShashidhar Hiremath static int dw_mci_pci_resume(struct device *dev)
9262ca8034SShashidhar Hiremath {
9362ca8034SShashidhar Hiremath 	struct pci_dev *pdev = to_pci_dev(dev);
9462ca8034SShashidhar Hiremath 	struct dw_mci *host = pci_get_drvdata(pdev);
9562ca8034SShashidhar Hiremath 
96dd369800SAndy Shevchenko 	return dw_mci_resume(host);
9762ca8034SShashidhar Hiremath }
9862ca8034SShashidhar Hiremath #else
9962ca8034SShashidhar Hiremath #define dw_mci_pci_suspend	NULL
10062ca8034SShashidhar Hiremath #define dw_mci_pci_resume	NULL
10162ca8034SShashidhar Hiremath #endif /* CONFIG_PM_SLEEP */
10262ca8034SShashidhar Hiremath 
10362ca8034SShashidhar Hiremath static SIMPLE_DEV_PM_OPS(dw_mci_pci_pmops, dw_mci_pci_suspend, dw_mci_pci_resume);
10462ca8034SShashidhar Hiremath 
1059baa3c34SBenoit Taine static const struct pci_device_id dw_mci_pci_id[] = {
10662ca8034SShashidhar Hiremath 	{ PCI_DEVICE(SYNOPSYS_DW_MCI_VENDOR_ID, SYNOPSYS_DW_MCI_DEVICE_ID) },
10762ca8034SShashidhar Hiremath 	{}
10862ca8034SShashidhar Hiremath };
10962ca8034SShashidhar Hiremath MODULE_DEVICE_TABLE(pci, dw_mci_pci_id);
11062ca8034SShashidhar Hiremath 
11162ca8034SShashidhar Hiremath static struct pci_driver dw_mci_pci_driver = {
11262ca8034SShashidhar Hiremath 	.name		= "dw_mmc_pci",
11362ca8034SShashidhar Hiremath 	.id_table	= dw_mci_pci_id,
11462ca8034SShashidhar Hiremath 	.probe		= dw_mci_pci_probe,
1154e608e4eSGreg Kroah-Hartman 	.remove		= dw_mci_pci_remove,
11662ca8034SShashidhar Hiremath 	.driver		=	{
11762ca8034SShashidhar Hiremath 		.pm =   &dw_mci_pci_pmops
11862ca8034SShashidhar Hiremath 	},
11962ca8034SShashidhar Hiremath };
12062ca8034SShashidhar Hiremath 
121350e3e00SSachin Kamat module_pci_driver(dw_mci_pci_driver);
12262ca8034SShashidhar Hiremath 
12362ca8034SShashidhar Hiremath MODULE_DESCRIPTION("DW Multimedia Card PCI Interface driver");
12462ca8034SShashidhar Hiremath MODULE_AUTHOR("Shashidhar Hiremath <shashidharh@vayavyalabs.com>");
12562ca8034SShashidhar Hiremath MODULE_LICENSE("GPL v2");
126