2 * NAND Flash Controller Device Driver for DT
4 * Copyright © 2011, Picochip.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/clk.h>
16 #include <linux/err.h>
18 #include <linux/ioport.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
23 #include <linux/of_device.h>
24 #include <linux/slab.h>
29 struct denali_nand_info denali
;
33 static void __iomem
*request_and_map(struct device
*dev
,
34 const struct resource
*res
)
38 if (!devm_request_mem_region(dev
, res
->start
, resource_size(res
),
40 dev_err(dev
, "unable to request %s\n", res
->name
);
44 ptr
= devm_ioremap_nocache(dev
, res
->start
, resource_size(res
));
46 dev_err(dev
, "ioremap_nocache of %s failed!", res
->name
);
51 static const struct of_device_id denali_nand_dt_ids
[] = {
52 { .compatible
= "denali,denali-nand-dt" },
56 MODULE_DEVICE_TABLE(of
, denali_nand_dt_ids
);
58 static u64 denali_dma_mask
;
60 static int denali_dt_probe(struct platform_device
*ofdev
)
62 struct resource
*denali_reg
, *nand_data
;
64 struct denali_nand_info
*denali
;
66 const struct of_device_id
*of_id
;
68 of_id
= of_match_device(denali_nand_dt_ids
, &ofdev
->dev
);
70 ofdev
->id_entry
= of_id
->data
;
72 pr_err("Failed to find the right device id.\n");
76 dt
= devm_kzalloc(&ofdev
->dev
, sizeof(*dt
), GFP_KERNEL
);
81 denali_reg
= platform_get_resource_byname(ofdev
, IORESOURCE_MEM
, "denali_reg");
82 nand_data
= platform_get_resource_byname(ofdev
, IORESOURCE_MEM
, "nand_data");
83 if (!denali_reg
|| !nand_data
) {
84 dev_err(&ofdev
->dev
, "resources not completely defined\n");
88 denali
->platform
= DT
;
89 denali
->dev
= &ofdev
->dev
;
90 denali
->irq
= platform_get_irq(ofdev
, 0);
91 if (denali
->irq
< 0) {
92 dev_err(&ofdev
->dev
, "no irq defined\n");
96 denali
->flash_reg
= request_and_map(&ofdev
->dev
, denali_reg
);
97 if (!denali
->flash_reg
)
100 denali
->flash_mem
= request_and_map(&ofdev
->dev
, nand_data
);
101 if (!denali
->flash_mem
)
104 if (!of_property_read_u32(ofdev
->dev
.of_node
,
105 "dma-mask", (u32
*)&denali_dma_mask
)) {
106 denali
->dev
->dma_mask
= &denali_dma_mask
;
108 denali
->dev
->dma_mask
= NULL
;
111 dt
->clk
= clk_get(&ofdev
->dev
, NULL
);
112 if (IS_ERR(dt
->clk
)) {
113 dev_err(&ofdev
->dev
, "no clk available\n");
114 return PTR_ERR(dt
->clk
);
116 clk_prepare_enable(dt
->clk
);
118 ret
= denali_init(denali
);
120 goto out_disable_clk
;
122 platform_set_drvdata(ofdev
, dt
);
126 clk_disable_unprepare(dt
->clk
);
132 static int denali_dt_remove(struct platform_device
*ofdev
)
134 struct denali_dt
*dt
= platform_get_drvdata(ofdev
);
136 denali_remove(&dt
->denali
);
137 clk_disable(dt
->clk
);
143 static struct platform_driver denali_dt_driver
= {
144 .probe
= denali_dt_probe
,
145 .remove
= denali_dt_remove
,
147 .name
= "denali-nand-dt",
148 .owner
= THIS_MODULE
,
149 .of_match_table
= denali_nand_dt_ids
,
153 module_platform_driver(denali_dt_driver
);
155 MODULE_LICENSE("GPL");
156 MODULE_AUTHOR("Jamie Iles");
157 MODULE_DESCRIPTION("DT driver for Denali NAND controller");