]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mtd/nand/denali_dt.c
mtd: nand: denali_dt: enable HW_ECC_FIXUP for Altera SOCFPGA variant
[karo-tx-linux.git] / drivers / mtd / nand / denali_dt.c
1 /*
2  * NAND Flash Controller Device Driver for DT
3  *
4  * Copyright © 2011, Picochip.
5  *
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.
9  *
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
13  * more details.
14  */
15 #include <linux/clk.h>
16 #include <linux/err.h>
17 #include <linux/io.h>
18 #include <linux/ioport.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/of.h>
23 #include <linux/of_device.h>
24
25 #include "denali.h"
26
27 struct denali_dt {
28         struct denali_nand_info denali;
29         struct clk              *clk;
30 };
31
32 struct denali_dt_data {
33         unsigned int caps;
34 };
35
36 static const struct denali_dt_data denali_socfpga_data = {
37         .caps = DENALI_CAP_HW_ECC_FIXUP,
38 };
39
40 static const struct of_device_id denali_nand_dt_ids[] = {
41         {
42                 .compatible = "altr,socfpga-denali-nand",
43                 .data = &denali_socfpga_data,
44         },
45         { /* sentinel */ }
46 };
47 MODULE_DEVICE_TABLE(of, denali_nand_dt_ids);
48
49 static u64 denali_dma_mask;
50
51 static int denali_dt_probe(struct platform_device *ofdev)
52 {
53         struct resource *denali_reg, *nand_data;
54         struct denali_dt *dt;
55         const struct denali_dt_data *data;
56         struct denali_nand_info *denali;
57         int ret;
58
59         dt = devm_kzalloc(&ofdev->dev, sizeof(*dt), GFP_KERNEL);
60         if (!dt)
61                 return -ENOMEM;
62         denali = &dt->denali;
63
64         data = of_device_get_match_data(&ofdev->dev);
65         if (data)
66                 denali->caps = data->caps;
67
68         denali->platform = DT;
69         denali->dev = &ofdev->dev;
70         denali->irq = platform_get_irq(ofdev, 0);
71         if (denali->irq < 0) {
72                 dev_err(&ofdev->dev, "no irq defined\n");
73                 return denali->irq;
74         }
75
76         denali_reg = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "denali_reg");
77         denali->flash_reg = devm_ioremap_resource(&ofdev->dev, denali_reg);
78         if (IS_ERR(denali->flash_reg))
79                 return PTR_ERR(denali->flash_reg);
80
81         nand_data = platform_get_resource_byname(ofdev, IORESOURCE_MEM, "nand_data");
82         denali->flash_mem = devm_ioremap_resource(&ofdev->dev, nand_data);
83         if (IS_ERR(denali->flash_mem))
84                 return PTR_ERR(denali->flash_mem);
85
86         if (!of_property_read_u32(ofdev->dev.of_node,
87                 "dma-mask", (u32 *)&denali_dma_mask)) {
88                 denali->dev->dma_mask = &denali_dma_mask;
89         } else {
90                 denali->dev->dma_mask = NULL;
91         }
92
93         dt->clk = devm_clk_get(&ofdev->dev, NULL);
94         if (IS_ERR(dt->clk)) {
95                 dev_err(&ofdev->dev, "no clk available\n");
96                 return PTR_ERR(dt->clk);
97         }
98         clk_prepare_enable(dt->clk);
99
100         ret = denali_init(denali);
101         if (ret)
102                 goto out_disable_clk;
103
104         platform_set_drvdata(ofdev, dt);
105         return 0;
106
107 out_disable_clk:
108         clk_disable_unprepare(dt->clk);
109
110         return ret;
111 }
112
113 static int denali_dt_remove(struct platform_device *ofdev)
114 {
115         struct denali_dt *dt = platform_get_drvdata(ofdev);
116
117         denali_remove(&dt->denali);
118         clk_disable_unprepare(dt->clk);
119
120         return 0;
121 }
122
123 static struct platform_driver denali_dt_driver = {
124         .probe          = denali_dt_probe,
125         .remove         = denali_dt_remove,
126         .driver         = {
127                 .name   = "denali-nand-dt",
128                 .of_match_table = denali_nand_dt_ids,
129         },
130 };
131
132 module_platform_driver(denali_dt_driver);
133
134 MODULE_LICENSE("GPL");
135 MODULE_AUTHOR("Jamie Iles");
136 MODULE_DESCRIPTION("DT driver for Denali NAND controller");