]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mtd/nand/denali_pci.c
mtd: nand: denali: avoid hard-coding ECC step, strength, bytes
[karo-tx-linux.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 /* List of platforms this NAND controller has be integrated into */
23 static const struct pci_device_id denali_pci_ids[] = {
24         { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
25         { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
26         { /* end: all zeroes */ }
27 };
28 MODULE_DEVICE_TABLE(pci, denali_pci_ids);
29
30 NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
31
32 static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
33 {
34         int ret;
35         resource_size_t csr_base, mem_base;
36         unsigned long csr_len, mem_len;
37         struct denali_nand_info *denali;
38
39         denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
40         if (!denali)
41                 return -ENOMEM;
42
43         ret = pcim_enable_device(dev);
44         if (ret) {
45                 dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
46                 return ret;
47         }
48
49         if (id->driver_data == INTEL_CE4100) {
50                 denali->platform = INTEL_CE4100;
51                 mem_base = pci_resource_start(dev, 0);
52                 mem_len = pci_resource_len(dev, 1);
53                 csr_base = pci_resource_start(dev, 1);
54                 csr_len = pci_resource_len(dev, 1);
55         } else {
56                 denali->platform = INTEL_MRST;
57                 csr_base = pci_resource_start(dev, 0);
58                 csr_len = pci_resource_len(dev, 0);
59                 mem_base = pci_resource_start(dev, 1);
60                 mem_len = pci_resource_len(dev, 1);
61                 if (!mem_len) {
62                         mem_base = csr_base + csr_len;
63                         mem_len = csr_len;
64                 }
65         }
66
67         pci_set_master(dev);
68         denali->dev = &dev->dev;
69         denali->irq = dev->irq;
70         denali->ecc_caps = &denali_pci_ecc_caps;
71         denali->nand.ecc.options |= NAND_ECC_MAXIMIZE;
72
73         ret = pci_request_regions(dev, DENALI_NAND_NAME);
74         if (ret) {
75                 dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
76                 return ret;
77         }
78
79         denali->flash_reg = ioremap_nocache(csr_base, csr_len);
80         if (!denali->flash_reg) {
81                 dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
82                 return -ENOMEM;
83         }
84
85         denali->flash_mem = ioremap_nocache(mem_base, mem_len);
86         if (!denali->flash_mem) {
87                 dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
88                 ret = -ENOMEM;
89                 goto failed_remap_reg;
90         }
91
92         ret = denali_init(denali);
93         if (ret)
94                 goto failed_remap_mem;
95
96         pci_set_drvdata(dev, denali);
97
98         return 0;
99
100 failed_remap_mem:
101         iounmap(denali->flash_mem);
102 failed_remap_reg:
103         iounmap(denali->flash_reg);
104         return ret;
105 }
106
107 /* driver exit point */
108 static void denali_pci_remove(struct pci_dev *dev)
109 {
110         struct denali_nand_info *denali = pci_get_drvdata(dev);
111
112         denali_remove(denali);
113         iounmap(denali->flash_reg);
114         iounmap(denali->flash_mem);
115 }
116
117 static struct pci_driver denali_pci_driver = {
118         .name = DENALI_NAND_NAME,
119         .id_table = denali_pci_ids,
120         .probe = denali_pci_probe,
121         .remove = denali_pci_remove,
122 };
123
124 module_pci_driver(denali_pci_driver);