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