]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mtd/nand/denali_dt.c
mtd: nand: denali: avoid hard-coding ECC step, strength, bytes
[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 revision;
34         unsigned int caps;
35         const struct nand_ecc_caps *ecc_caps;
36 };
37
38 NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes,
39                      512, 8, 15);
40 static const struct denali_dt_data denali_socfpga_data = {
41         .caps = DENALI_CAP_HW_ECC_FIXUP,
42         .ecc_caps = &denali_socfpga_ecc_caps,
43 };
44
45 static const struct of_device_id denali_nand_dt_ids[] = {
46         {
47                 .compatible = "altr,socfpga-denali-nand",
48                 .data = &denali_socfpga_data,
49         },
50         { /* sentinel */ }
51 };
52 MODULE_DEVICE_TABLE(of, denali_nand_dt_ids);
53
54 static int denali_dt_probe(struct platform_device *pdev)
55 {
56         struct resource *res;
57         struct denali_dt *dt;
58         const struct denali_dt_data *data;
59         struct denali_nand_info *denali;
60         int ret;
61
62         dt = devm_kzalloc(&pdev->dev, sizeof(*dt), GFP_KERNEL);
63         if (!dt)
64                 return -ENOMEM;
65         denali = &dt->denali;
66
67         data = of_device_get_match_data(&pdev->dev);
68         if (data) {
69                 denali->revision = data->revision;
70                 denali->caps = data->caps;
71                 denali->ecc_caps = data->ecc_caps;
72         }
73
74         denali->platform = DT;
75         denali->dev = &pdev->dev;
76         denali->irq = platform_get_irq(pdev, 0);
77         if (denali->irq < 0) {
78                 dev_err(&pdev->dev, "no irq defined\n");
79                 return denali->irq;
80         }
81
82         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "denali_reg");
83         denali->flash_reg = devm_ioremap_resource(&pdev->dev, res);
84         if (IS_ERR(denali->flash_reg))
85                 return PTR_ERR(denali->flash_reg);
86
87         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data");
88         denali->flash_mem = devm_ioremap_resource(&pdev->dev, res);
89         if (IS_ERR(denali->flash_mem))
90                 return PTR_ERR(denali->flash_mem);
91
92         dt->clk = devm_clk_get(&pdev->dev, NULL);
93         if (IS_ERR(dt->clk)) {
94                 dev_err(&pdev->dev, "no clk available\n");
95                 return PTR_ERR(dt->clk);
96         }
97         clk_prepare_enable(dt->clk);
98
99         ret = denali_init(denali);
100         if (ret)
101                 goto out_disable_clk;
102
103         platform_set_drvdata(pdev, dt);
104         return 0;
105
106 out_disable_clk:
107         clk_disable_unprepare(dt->clk);
108
109         return ret;
110 }
111
112 static int denali_dt_remove(struct platform_device *pdev)
113 {
114         struct denali_dt *dt = platform_get_drvdata(pdev);
115
116         denali_remove(&dt->denali);
117         clk_disable_unprepare(dt->clk);
118
119         return 0;
120 }
121
122 static struct platform_driver denali_dt_driver = {
123         .probe          = denali_dt_probe,
124         .remove         = denali_dt_remove,
125         .driver         = {
126                 .name   = "denali-nand-dt",
127                 .of_match_table = denali_nand_dt_ids,
128         },
129 };
130
131 module_platform_driver(denali_dt_driver);
132
133 MODULE_LICENSE("GPL");
134 MODULE_AUTHOR("Jamie Iles");
135 MODULE_DESCRIPTION("DT driver for Denali NAND controller");