blob: ac843238b77e72f846c63d2eb9a8299a2d3aceb5 [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 */
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/pci.h>
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060017
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 */
Jingoo Han94f70392013-12-03 08:18:28 +090023static const struct pci_device_id denali_pci_ids[] = {
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060024 { PCI_VDEVICE(INTEL, 0x0701), INTEL_CE4100 },
25 { PCI_VDEVICE(INTEL, 0x0809), INTEL_MRST },
26 { /* end: all zeroes */ }
27};
28MODULE_DEVICE_TABLE(pci, denali_pci_ids);
29
30static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
31{
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030032 int ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060033 resource_size_t csr_base, mem_base;
34 unsigned long csr_len, mem_len;
35 struct denali_nand_info *denali;
36
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030037 denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060038 if (!denali)
39 return -ENOMEM;
40
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030041 ret = pcim_enable_device(dev);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060042 if (ret) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030043 dev_err(&dev->dev, "Spectra: pci_enable_device failed.\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030044 return ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060045 }
46
47 if (id->driver_data == INTEL_CE4100) {
48 denali->platform = 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 denali->platform = INTEL_MRST;
55 csr_base = pci_resource_start(dev, 0);
56 csr_len = pci_resource_len(dev, 0);
57 mem_base = pci_resource_start(dev, 1);
58 mem_len = pci_resource_len(dev, 1);
59 if (!mem_len) {
60 mem_base = csr_base + csr_len;
61 mem_len = csr_len;
62 }
63 }
64
65 pci_set_master(dev);
66 denali->dev = &dev->dev;
67 denali->irq = dev->irq;
68
69 ret = pci_request_regions(dev, DENALI_NAND_NAME);
70 if (ret) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030071 dev_err(&dev->dev, "Spectra: Unable to request memory regions\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030072 return ret;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060073 }
74
75 denali->flash_reg = ioremap_nocache(csr_base, csr_len);
76 if (!denali->flash_reg) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030077 dev_err(&dev->dev, "Spectra: Unable to remap memory region\n");
Andy Shevchenkoadd243d2015-08-06 16:04:23 +030078 return -ENOMEM;
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060079 }
80
81 denali->flash_mem = ioremap_nocache(mem_base, mem_len);
82 if (!denali->flash_mem) {
Andy Shevchenkoaf83a67c2015-08-06 16:04:24 +030083 dev_err(&dev->dev, "Spectra: ioremap_nocache failed!");
Dinh Nguyen2a0a2882012-09-27 10:58:05 -060084 ret = -ENOMEM;
85 goto failed_remap_reg;
86 }
87
88 ret = denali_init(denali);
89 if (ret)
90 goto failed_remap_mem;
91
92 pci_set_drvdata(dev, denali);
93
94 return 0;
95
96failed_remap_mem:
97 iounmap(denali->flash_mem);
98failed_remap_reg:
99 iounmap(denali->flash_reg);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600100 return ret;
101}
102
103/* driver exit point */
104static void denali_pci_remove(struct pci_dev *dev)
105{
106 struct denali_nand_info *denali = pci_get_drvdata(dev);
107
108 denali_remove(denali);
109 iounmap(denali->flash_reg);
110 iounmap(denali->flash_mem);
Dinh Nguyen2a0a2882012-09-27 10:58:05 -0600111}
112
113static struct pci_driver denali_pci_driver = {
114 .name = DENALI_NAND_NAME,
115 .id_table = denali_pci_ids,
116 .probe = denali_pci_probe,
117 .remove = denali_pci_remove,
118};
119
Andy Shevchenko2445d332015-08-06 16:04:22 +0300120module_pci_driver(denali_pci_driver);