2 * NAND Flash Controller Device Driver
3 * Copyright © 2009-2010, Intel Corporation and its suppliers.
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.
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
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/pci.h>
17 #include <linux/slab.h>
21 #define DENALI_NAND_NAME "denali-nand-pci"
23 /* List of platforms this NAND controller has be integrated into */
24 static const struct pci_device_id denali_pci_ids
[] = {
25 { PCI_VDEVICE(INTEL
, 0x0701), INTEL_CE4100
},
26 { PCI_VDEVICE(INTEL
, 0x0809), INTEL_MRST
},
27 { /* end: all zeroes */ }
29 MODULE_DEVICE_TABLE(pci
, denali_pci_ids
);
31 static int denali_pci_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
34 resource_size_t csr_base
, mem_base
;
35 unsigned long csr_len
, mem_len
;
36 struct denali_nand_info
*denali
;
38 denali
= kzalloc(sizeof(*denali
), GFP_KERNEL
);
42 ret
= pci_enable_device(dev
);
44 pr_err("Spectra: pci_enable_device failed.\n");
45 goto failed_alloc_memery
;
48 if (id
->driver_data
== INTEL_CE4100
) {
49 denali
->platform
= INTEL_CE4100
;
50 mem_base
= pci_resource_start(dev
, 0);
51 mem_len
= pci_resource_len(dev
, 1);
52 csr_base
= pci_resource_start(dev
, 1);
53 csr_len
= pci_resource_len(dev
, 1);
55 denali
->platform
= INTEL_MRST
;
56 csr_base
= pci_resource_start(dev
, 0);
57 csr_len
= pci_resource_len(dev
, 0);
58 mem_base
= pci_resource_start(dev
, 1);
59 mem_len
= pci_resource_len(dev
, 1);
61 mem_base
= csr_base
+ csr_len
;
67 denali
->dev
= &dev
->dev
;
68 denali
->irq
= dev
->irq
;
70 ret
= pci_request_regions(dev
, DENALI_NAND_NAME
);
72 pr_err("Spectra: Unable to request memory regions\n");
73 goto failed_enable_dev
;
76 denali
->flash_reg
= ioremap_nocache(csr_base
, csr_len
);
77 if (!denali
->flash_reg
) {
78 pr_err("Spectra: Unable to remap memory region\n");
80 goto failed_req_regions
;
83 denali
->flash_mem
= ioremap_nocache(mem_base
, mem_len
);
84 if (!denali
->flash_mem
) {
85 pr_err("Spectra: ioremap_nocache failed!");
87 goto failed_remap_reg
;
90 ret
= denali_init(denali
);
92 goto failed_remap_mem
;
94 pci_set_drvdata(dev
, denali
);
99 iounmap(denali
->flash_mem
);
101 iounmap(denali
->flash_reg
);
103 pci_release_regions(dev
);
105 pci_disable_device(dev
);
112 /* driver exit point */
113 static void denali_pci_remove(struct pci_dev
*dev
)
115 struct denali_nand_info
*denali
= pci_get_drvdata(dev
);
117 denali_remove(denali
);
118 iounmap(denali
->flash_reg
);
119 iounmap(denali
->flash_mem
);
120 pci_release_regions(dev
);
121 pci_disable_device(dev
);
125 static struct pci_driver denali_pci_driver
= {
126 .name
= DENALI_NAND_NAME
,
127 .id_table
= denali_pci_ids
,
128 .probe
= denali_pci_probe
,
129 .remove
= denali_pci_remove
,
132 static int denali_init_pci(void)
134 return pci_register_driver(&denali_pci_driver
);
136 module_init(denali_init_pci
);
138 static void denali_exit_pci(void)
140 pci_unregister_driver(&denali_pci_driver
);
142 module_exit(denali_exit_pci
);