blob: c90a45009b9b2fb87a3a5b33d659b8ec075ad050 [file] [log] [blame]
Feng Tange24c7452009-12-14 14:20:22 -08001/*
Grant Likelyca632f52011-06-06 01:16:30 -06002 * PCI interface driver for DW SPI Core
Feng Tange24c7452009-12-14 14:20:22 -08003 *
Andy Shevchenko5dc23c42014-08-29 12:41:43 +03004 * Copyright (c) 2009, 2014 Intel Corporation.
Feng Tange24c7452009-12-14 14:20:22 -08005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
Feng Tange24c7452009-12-14 14:20:22 -080014 */
15
16#include <linux/interrupt.h>
17#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Feng Tange24c7452009-12-14 14:20:22 -080019#include <linux/spi/spi.h>
Paul Gortmakerd7614de2011-07-03 15:44:29 -040020#include <linux/module.h>
Feng Tange24c7452009-12-14 14:20:22 -080021
Grant Likelyca632f52011-06-06 01:16:30 -060022#include "spi-dw.h"
Grant Likely568a60e2011-02-28 12:47:12 -070023
Feng Tange24c7452009-12-14 14:20:22 -080024#define DRIVER_NAME "dw_spi_pci"
25
26struct dw_spi_pci {
Feng Tang7063c0d2010-12-24 13:59:11 +080027 struct pci_dev *pdev;
28 struct dw_spi dws;
Feng Tange24c7452009-12-14 14:20:22 -080029};
30
Andy Shevchenkoc95791b2014-08-29 12:41:42 +030031struct spi_pci_desc {
32 int (*setup)(struct dw_spi *);
33};
34
35static struct spi_pci_desc spi_pci_mid_desc = {
36 .setup = dw_spi_mid_init,
37};
38
39static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Feng Tange24c7452009-12-14 14:20:22 -080040{
41 struct dw_spi_pci *dwpci;
42 struct dw_spi *dws;
Andy Shevchenkoc95791b2014-08-29 12:41:42 +030043 struct spi_pci_desc *desc = (struct spi_pci_desc *)ent->driver_data;
Feng Tange24c7452009-12-14 14:20:22 -080044 int pci_bar = 0;
45 int ret;
46
Baruch Siach04f421e2013-12-30 20:30:44 +020047 ret = pcim_enable_device(pdev);
Feng Tange24c7452009-12-14 14:20:22 -080048 if (ret)
49 return ret;
50
Baruch Siachfa4934a2014-01-06 09:21:33 +020051 dwpci = devm_kzalloc(&pdev->dev, sizeof(struct dw_spi_pci),
52 GFP_KERNEL);
Baruch Siach04f421e2013-12-30 20:30:44 +020053 if (!dwpci)
54 return -ENOMEM;
Feng Tange24c7452009-12-14 14:20:22 -080055
56 dwpci->pdev = pdev;
57 dws = &dwpci->dws;
58
59 /* Get basic io resource and map it */
60 dws->paddr = pci_resource_start(pdev, pci_bar);
Feng Tange24c7452009-12-14 14:20:22 -080061
Andy Shevchenkoceb86de2014-08-29 12:41:40 +030062 ret = pcim_iomap_regions(pdev, 1 << pci_bar, pci_name(pdev));
Feng Tange24c7452009-12-14 14:20:22 -080063 if (ret)
Baruch Siach04f421e2013-12-30 20:30:44 +020064 return ret;
Feng Tange24c7452009-12-14 14:20:22 -080065
Feng Tange24c7452009-12-14 14:20:22 -080066 dws->bus_num = 0;
67 dws->num_cs = 4;
Feng Tange24c7452009-12-14 14:20:22 -080068 dws->irq = pdev->irq;
Feng Tang7063c0d2010-12-24 13:59:11 +080069
70 /*
Andy Shevchenkoc95791b2014-08-29 12:41:42 +030071 * Specific handling for paltforms, like dma setup,
Feng Tang7063c0d2010-12-24 13:59:11 +080072 * clock rate, FIFO depth.
73 */
Andy Shevchenkoc95791b2014-08-29 12:41:42 +030074 if (desc && desc->setup) {
75 ret = desc->setup(dws);
Feng Tang7063c0d2010-12-24 13:59:11 +080076 if (ret)
Baruch Siach04f421e2013-12-30 20:30:44 +020077 return ret;
Feng Tang7063c0d2010-12-24 13:59:11 +080078 }
Feng Tange24c7452009-12-14 14:20:22 -080079
Baruch Siach04f421e2013-12-30 20:30:44 +020080 ret = dw_spi_add_host(&pdev->dev, dws);
Feng Tange24c7452009-12-14 14:20:22 -080081 if (ret)
Baruch Siach04f421e2013-12-30 20:30:44 +020082 return ret;
Feng Tange24c7452009-12-14 14:20:22 -080083
84 /* PCI hook and SPI hook use the same drv data */
85 pci_set_drvdata(pdev, dwpci);
Feng Tange24c7452009-12-14 14:20:22 -080086
Andy Shevchenkofcf0af42014-08-29 12:41:39 +030087 dev_info(&pdev->dev, "found PCI SPI controller(ID: %04x:%04x)\n",
88 pdev->vendor, pdev->device);
89
Baruch Siach04f421e2013-12-30 20:30:44 +020090 return 0;
Feng Tange24c7452009-12-14 14:20:22 -080091}
92
Grant Likelyfd4a3192012-12-07 16:57:14 +000093static void spi_pci_remove(struct pci_dev *pdev)
Feng Tange24c7452009-12-14 14:20:22 -080094{
95 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
96
Feng Tang51f921c2010-01-20 13:49:45 -070097 dw_spi_remove_host(&dwpci->dws);
Feng Tange24c7452009-12-14 14:20:22 -080098}
99
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300100#ifdef CONFIG_PM_SLEEP
101static int spi_suspend(struct device *dev)
Feng Tange24c7452009-12-14 14:20:22 -0800102{
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300103 struct pci_dev *pdev = to_pci_dev(dev);
Feng Tange24c7452009-12-14 14:20:22 -0800104 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
Feng Tange24c7452009-12-14 14:20:22 -0800105
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300106 return dw_spi_suspend_host(&dwpci->dws);
Feng Tange24c7452009-12-14 14:20:22 -0800107}
108
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300109static int spi_resume(struct device *dev)
Feng Tange24c7452009-12-14 14:20:22 -0800110{
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300111 struct pci_dev *pdev = to_pci_dev(dev);
Feng Tange24c7452009-12-14 14:20:22 -0800112 struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
Feng Tange24c7452009-12-14 14:20:22 -0800113
Feng Tange24c7452009-12-14 14:20:22 -0800114 return dw_spi_resume_host(&dwpci->dws);
115}
Feng Tange24c7452009-12-14 14:20:22 -0800116#endif
117
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300118static SIMPLE_DEV_PM_OPS(dw_spi_pm_ops, spi_suspend, spi_resume);
119
Jingoo Han9a21e472013-12-03 08:25:19 +0900120static const struct pci_device_id pci_ids[] = {
Feng Tang7063c0d2010-12-24 13:59:11 +0800121 /* Intel MID platform SPI controller 0 */
Andy Shevchenkoc95791b2014-08-29 12:41:42 +0300122 { PCI_VDEVICE(INTEL, 0x0800), (kernel_ulong_t)&spi_pci_mid_desc},
Feng Tange24c7452009-12-14 14:20:22 -0800123 {},
124};
125
126static struct pci_driver dw_spi_driver = {
127 .name = DRIVER_NAME,
128 .id_table = pci_ids,
129 .probe = spi_pci_probe,
Grant Likelyfd4a3192012-12-07 16:57:14 +0000130 .remove = spi_pci_remove,
Andy Shevchenko35f2d412014-08-29 12:41:41 +0300131 .driver = {
132 .pm = &dw_spi_pm_ops,
133 },
Feng Tange24c7452009-12-14 14:20:22 -0800134};
135
Axel Lin8ebb35f2012-04-04 22:29:32 +0800136module_pci_driver(dw_spi_driver);
Feng Tange24c7452009-12-14 14:20:22 -0800137
138MODULE_AUTHOR("Feng Tang <feng.tang@intel.com>");
139MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
140MODULE_LICENSE("GPL v2");