blob: 9577bfde960e9b553fd171e9328cb682cc449058 [file] [log] [blame]
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -06001/*
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>
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060024
25#include "denali.h"
26
27struct denali_dt {
28 struct denali_nand_info denali;
29 struct clk *clk;
30};
31
Masahiro Yamadabe72a4a2017-03-23 05:07:07 +090032struct denali_dt_data {
33 unsigned int caps;
34};
35
Masahiro Yamadaa56609c2017-03-30 15:45:53 +090036static const struct denali_dt_data denali_socfpga_data = {
37 .caps = DENALI_CAP_HW_ECC_FIXUP,
38};
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060039
Masahiro Yamadaa56609c2017-03-30 15:45:53 +090040static 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};
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060047MODULE_DEVICE_TABLE(of, denali_nand_dt_ids);
48
49static u64 denali_dma_mask;
50
Bill Pemberton06f25512012-11-19 13:23:07 -050051static int denali_dt_probe(struct platform_device *ofdev)
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060052{
53 struct resource *denali_reg, *nand_data;
54 struct denali_dt *dt;
Masahiro Yamadabe72a4a2017-03-23 05:07:07 +090055 const struct denali_dt_data *data;
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060056 struct denali_nand_info *denali;
57 int ret;
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060058
59 dt = devm_kzalloc(&ofdev->dev, sizeof(*dt), GFP_KERNEL);
60 if (!dt)
61 return -ENOMEM;
62 denali = &dt->denali;
63
Masahiro Yamadabe72a4a2017-03-23 05:07:07 +090064 data = of_device_get_match_data(&ofdev->dev);
65 if (data)
66 denali->caps = data->caps;
67
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060068 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");
Sachin Kamat2f2ff142013-03-18 15:11:13 +053073 return denali->irq;
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060074 }
75
Jingoo Han79952042014-02-12 11:29:42 +090076 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);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060080
Jingoo Han79952042014-02-12 11:29:42 +090081 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);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060085
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
Jingoo Han2281f7b62013-12-26 10:43:11 +090093 dt->clk = devm_clk_get(&ofdev->dev, NULL);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -060094 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
107out_disable_clk:
108 clk_disable_unprepare(dt->clk);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600109
110 return ret;
111}
112
Bill Pemberton810b7e02012-11-19 13:26:04 -0500113static int denali_dt_remove(struct platform_device *ofdev)
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600114{
115 struct denali_dt *dt = platform_get_drvdata(ofdev);
116
117 denali_remove(&dt->denali);
Masahiro Yamadaa1a26172016-11-03 02:21:04 +0900118 clk_disable_unprepare(dt->clk);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600119
120 return 0;
121}
122
123static struct platform_driver denali_dt_driver = {
124 .probe = denali_dt_probe,
Bill Pemberton5153b882012-11-19 13:21:24 -0500125 .remove = denali_dt_remove,
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600126 .driver = {
127 .name = "denali-nand-dt",
Sachin Kamatef54f872013-03-18 15:11:14 +0530128 .of_match_table = denali_nand_dt_ids,
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600129 },
130};
131
Sachin Kamat82fc8122013-03-18 15:11:12 +0530132module_platform_driver(denali_dt_driver);
Dinh Nguyen30f9f2f2012-09-27 10:58:06 -0600133
134MODULE_LICENSE("GPL");
135MODULE_AUTHOR("Jamie Iles");
136MODULE_DESCRIPTION("DT driver for Denali NAND controller");