GNU Linux-libre 4.14.332-gnu1
[releases.git] / drivers / mtd / nand / denali_pci.c
1 /*
2  * NAND Flash Controller Device Driver
3  * Copyright © 2009-2010, Intel Corporation and its suppliers.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  */
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
17
18 #include "denali.h"
19
20 #define DENALI_NAND_NAME    "denali-nand-pci"
21
22 #define INTEL_CE4100    1
23 #define INTEL_MRST      2
24
25 /* List of platforms this NAND controller has be integrated into */
26 static const struct pci_device_id denali_pci_ids[] = {
27         { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
28         { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
29         { /* end: all zeroes */ }
30 };
31 MODULE_DEVICE_TABLE(pci, denali_pci_ids);
32
33 NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
34
35 static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
36 {
37         int ret;
38         resource_size_t csr_base, mem_base;
39         unsigned long csr_len, mem_len;
40         struct denali_nand_info *denali;
41
42         denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
43         if (!denali)
44                 return -ENOMEM;
45
46         ret = pcim_enable_device(dev);
47         if (ret) {
48                 dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
49                 return ret;
50         }
51
52         if (id->driver_data == INTEL_CE4100) {
53                 mem_base = pci_resource_start(dev, 0);
54                 mem_len = pci_resource_len(dev, 1);
55                 csr_base = pci_resource_start(dev, 1);
56                 csr_len = pci_resource_len(dev, 1);
57         } else {
58                 csr_base = pci_resource_start(dev, 0);
59                 csr_len = pci_resource_len(dev, 0);
60                 mem_base = pci_resource_start(dev, 1);
61                 mem_len = pci_resource_len(dev, 1);
62                 if (!mem_len) {
63                         mem_base = csr_base + csr_len;
64                         mem_len = csr_len;
65                 }
66         }
67
68         pci_set_master(dev);
69         denali->dev = &dev->dev;
70         denali->irq = dev->irq;
71         denali->ecc_caps = &denali_pci_ecc_caps;
72         denali->nand.ecc.options |= NAND_ECC_MAXIMIZE;
73         denali->clk_x_rate = 200000000;         /* 200 MHz */
74
75         ret = pci_request_regions(dev, DENALI_NAND_NAME);
76         if (ret) {
77                 dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
78                 return ret;
79         }
80
81         denali->reg = ioremap_nocache(csr_base, csr_len);
82         if (!denali->reg) {
83                 dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
84                 return -ENOMEM;
85         }
86
87         denali->host = ioremap_nocache(mem_base, mem_len);
88         if (!denali->host) {
89                 dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
90                 ret = -ENOMEM;
91                 goto failed_remap_reg;
92         }
93
94         ret = denali_init(denali);
95         if (ret)
96                 goto failed_remap_mem;
97
98         pci_set_drvdata(dev, denali);
99
100         return 0;
101
102 failed_remap_mem:
103         iounmap(denali->host);
104 failed_remap_reg:
105         iounmap(denali->reg);
106         return ret;
107 }
108
109 /* driver exit point */
110 static void denali_pci_remove(struct pci_dev *dev)
111 {
112         struct denali_nand_info *denali = pci_get_drvdata(dev);
113
114         denali_remove(denali);
115         iounmap(denali->reg);
116         iounmap(denali->host);
117 }
118
119 static struct pci_driver denali_pci_driver = {
120         .name = DENALI_NAND_NAME,
121         .id_table = denali_pci_ids,
122         .probe = denali_pci_probe,
123         .remove = denali_pci_remove,
124 };
125
126 module_pci_driver(denali_pci_driver);
127
128 MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
129 MODULE_AUTHOR("Intel Corporation and its suppliers");
130 MODULE_LICENSE("GPL v2");