Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mtd / nand / raw / denali_pci.c
blob20c085a30adcba8558b8c79aaaec7e8d6108f1c7
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * NAND Flash Controller Device Driver
4 * Copyright © 2009-2010, Intel Corporation and its suppliers.
5 */
7 #include <linux/errno.h>
8 #include <linux/io.h>
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/pci.h>
13 #include "denali.h"
15 #define DENALI_NAND_NAME "denali-nand-pci"
17 #define INTEL_CE4100 1
18 #define INTEL_MRST 2
20 /* List of platforms this NAND controller has be integrated into */
21 static const struct pci_device_id denali_pci_ids[] = {
22 { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
23 { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
24 { /* end: all zeroes */ }
26 MODULE_DEVICE_TABLE(pci, denali_pci_ids);
28 NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
30 static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
32 resource_size_t csr_base, mem_base;
33 unsigned long csr_len, mem_len;
34 struct denali_controller *denali;
35 struct denali_chip *dchip;
36 int nsels, ret, i;
38 denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
39 if (!denali)
40 return -ENOMEM;
42 ret = pcim_enable_device(dev);
43 if (ret) {
44 dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
45 return ret;
48 if (id->driver_data == INTEL_CE4100) {
49 mem_base = pci_resource_start(dev, 0);
50 mem_len = pci_resource_len(dev, 1);
51 csr_base = pci_resource_start(dev, 1);
52 csr_len = pci_resource_len(dev, 1);
53 } else {
54 csr_base = pci_resource_start(dev, 0);
55 csr_len = pci_resource_len(dev, 0);
56 mem_base = pci_resource_start(dev, 1);
57 mem_len = pci_resource_len(dev, 1);
58 if (!mem_len) {
59 mem_base = csr_base + csr_len;
60 mem_len = csr_len;
64 pci_set_master(dev);
65 denali->dev = &dev->dev;
66 denali->irq = dev->irq;
67 denali->ecc_caps = &denali_pci_ecc_caps;
68 denali->clk_rate = 50000000; /* 50 MHz */
69 denali->clk_x_rate = 200000000; /* 200 MHz */
71 ret = pci_request_regions(dev, DENALI_NAND_NAME);
72 if (ret) {
73 dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
74 return ret;
77 denali->reg = ioremap(csr_base, csr_len);
78 if (!denali->reg) {
79 dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
80 return -ENOMEM;
83 denali->host = ioremap(mem_base, mem_len);
84 if (!denali->host) {
85 dev_err(&dev->dev, "Spectra: ioremap failed!");
86 ret = -ENOMEM;
87 goto out_unmap_reg;
90 ret = denali_init(denali);
91 if (ret)
92 goto out_unmap_host;
94 nsels = denali->nbanks;
96 dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels),
97 GFP_KERNEL);
98 if (!dchip) {
99 ret = -ENOMEM;
100 goto out_remove_denali;
103 dchip->chip.base.ecc.user_conf.flags |= NAND_ECC_MAXIMIZE_STRENGTH;
105 dchip->nsels = nsels;
107 for (i = 0; i < nsels; i++)
108 dchip->sels[i].bank = i;
110 ret = denali_chip_init(denali, dchip);
111 if (ret)
112 goto out_remove_denali;
114 pci_set_drvdata(dev, denali);
116 return 0;
118 out_remove_denali:
119 denali_remove(denali);
120 out_unmap_host:
121 iounmap(denali->host);
122 out_unmap_reg:
123 iounmap(denali->reg);
124 return ret;
127 static void denali_pci_remove(struct pci_dev *dev)
129 struct denali_controller *denali = pci_get_drvdata(dev);
131 denali_remove(denali);
132 iounmap(denali->reg);
133 iounmap(denali->host);
136 static struct pci_driver denali_pci_driver = {
137 .name = DENALI_NAND_NAME,
138 .id_table = denali_pci_ids,
139 .probe = denali_pci_probe,
140 .remove = denali_pci_remove,
142 module_pci_driver(denali_pci_driver);
144 MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
145 MODULE_AUTHOR("Intel Corporation and its suppliers");
146 MODULE_LICENSE("GPL v2");