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