blob: 49cb3e1f8bd0607044b52431a1504492f2b762f2 [file] [log] [blame]
Dinh Nguyen2a0a2882012-09-27 10:58:05 -06001/*
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 */
Masahiro Yamadada4734b2017-09-22 12:46:40 +090014
15#include <linux/errno.h>
16#include <linux/io.h>
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060017#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/pci.h>
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060020
21#include "denali.h"
22
23#define DENALI_NAND_NAME "denali-nand-pci"
24
Masahiro Yamada1bb88662017-06-13 22:45:37 +090025#define INTEL_CE4100 1
26#define INTEL_MRST 2
27
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060028/* List of platforms this NAND controller has be integrated into */
Jingoo Han94f70392013-12-03 08:18:28 +090029static const struct pci_device_id denali_pci_ids[] = {
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060030 { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
31 { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
32 { /* end: all zeroes */ }
33};
34MODULE_DEVICE_TABLE(pci, denali_pci_ids);
35
Masahiro Yamada7de117f2017-06-07 20:52:12 +090036NAND_ECC_CAPS_SINGLE(denali_pci_ecc_caps, denali_calc_ecc_bytes, 512, 8, 15);
37
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060038static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
39{
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030040 int ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060041 resource_size_t csr_base, mem_base;
42 unsigned long csr_len, mem_len;
43 struct denali_nand_info *denali;
44
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030045 denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060046 if (!denali)
47 return -ENOMEM;
48
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030049 ret = pcim_enable_device(dev);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060050 if (ret) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030051 dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030052 return ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060053 }
54
55 if (id->driver_data == INTEL_CE4100) {
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060056 mem_base = pci_resource_start(dev, 0);
57 mem_len = pci_resource_len(dev, 1);
58 csr_base = pci_resource_start(dev, 1);
59 csr_len = pci_resource_len(dev, 1);
60 } else {
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060061 csr_base = pci_resource_start(dev, 0);
62 csr_len = pci_resource_len(dev, 0);
63 mem_base = pci_resource_start(dev, 1);
64 mem_len = pci_resource_len(dev, 1);
65 if (!mem_len) {
66 mem_base = csr_base + csr_len;
67 mem_len = csr_len;
68 }
69 }
70
71 pci_set_master(dev);
72 denali->dev = &dev->dev;
73 denali->irq = dev->irq;
Masahiro Yamada7de117f2017-06-07 20:52:12 +090074 denali->ecc_caps = &denali_pci_ecc_caps;
75 denali->nand.ecc.options |= NAND_ECC_MAXIMIZE;
Masahiro Yamada1bb88662017-06-13 22:45:37 +090076 denali->clk_x_rate = 200000000; /* 200 MHz */
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060077
78 ret = pci_request_regions(dev, DENALI_NAND_NAME);
79 if (ret) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030080 dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030081 return ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060082 }
83
Masahiro Yamada0d3a9662017-06-16 14:36:39 +090084 denali->reg = ioremap_nocache(csr_base, csr_len);
85 if (!denali->reg) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030086 dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030087 return -ENOMEM;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060088 }
89
Masahiro Yamada0d3a9662017-06-16 14:36:39 +090090 denali->host = ioremap_nocache(mem_base, mem_len);
91 if (!denali->host) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030092 dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060093 ret = -ENOMEM;
94 goto failed_remap_reg;
95 }
96
97 ret = denali_init(denali);
98 if (ret)
99 goto failed_remap_mem;
100
101 pci_set_drvdata(dev, denali);
102
103 return 0;
104
105failed_remap_mem:
Masahiro Yamada0d3a9662017-06-16 14:36:39 +0900106 iounmap(denali->host);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600107failed_remap_reg:
Masahiro Yamada0d3a9662017-06-16 14:36:39 +0900108 iounmap(denali->reg);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600109 return ret;
110}
111
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600112static void denali_pci_remove(struct pci_dev *dev)
113{
114 struct denali_nand_info *denali = pci_get_drvdata(dev);
115
116 denali_remove(denali);
Masahiro Yamada0d3a9662017-06-16 14:36:39 +0900117 iounmap(denali->reg);
118 iounmap(denali->host);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600119}
120
121static struct pci_driver denali_pci_driver = {
122 .name = DENALI_NAND_NAME,
123 .id_table = denali_pci_ids,
124 .probe = denali_pci_probe,
125 .remove = denali_pci_remove,
126};
Andy Shevchenko2445d332015-08-06 16:04:22 +0300127module_pci_driver(denali_pci_driver);
Jesse Chand8224012017-11-20 12:57:13 -0800128
129MODULE_DESCRIPTION("PCI driver for Denali NAND controller");
130MODULE_AUTHOR("Intel Corporation and its suppliers");
131MODULE_LICENSE("GPL v2");