blob: 805c066b40569574346341e71876748da07ea4cf [file] [log] [blame]
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +09001/*
2 * Copyright (C) 2017 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Masahiro Yamadab1c72732017-10-14 02:21:18 +09009#include <clk.h>
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090010#include <dm.h>
11#include <linux/io.h>
12#include <linux/ioport.h>
13
14#include "denali.h"
15
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090016struct denali_dt_data {
17 unsigned int revision;
18 unsigned int caps;
19};
20
21static const struct denali_dt_data denali_socfpga_data = {
22 .caps = DENALI_CAP_HW_ECC_FIXUP,
23};
24
25static const struct denali_dt_data denali_uniphier_v5a_data = {
26 .caps = DENALI_CAP_HW_ECC_FIXUP |
27 DENALI_CAP_DMA_64BIT,
28};
29
30static const struct denali_dt_data denali_uniphier_v5b_data = {
31 .revision = 0x0501,
32 .caps = DENALI_CAP_HW_ECC_FIXUP |
33 DENALI_CAP_DMA_64BIT,
34};
35
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090036static const struct udevice_id denali_nand_dt_ids[] = {
37 {
38 .compatible = "altr,socfpga-denali-nand",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090039 .data = (unsigned long)&denali_socfpga_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090040 },
41 {
42 .compatible = "socionext,uniphier-denali-nand-v5a",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090043 .data = (unsigned long)&denali_uniphier_v5a_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090044 },
45 {
46 .compatible = "socionext,uniphier-denali-nand-v5b",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090047 .data = (unsigned long)&denali_uniphier_v5b_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090048 },
49 { /* sentinel */ }
50};
51
52static int denali_dt_probe(struct udevice *dev)
53{
54 struct denali_nand_info *denali = dev_get_priv(dev);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090055 const struct denali_dt_data *data;
Masahiro Yamadab1c72732017-10-14 02:21:18 +090056 struct clk clk;
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090057 struct resource res;
58 int ret;
59
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090060 data = (void *)dev_get_driver_data(dev);
61 if (data) {
62 denali->revision = data->revision;
63 denali->caps = data->caps;
64 }
65
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090066 ret = dev_read_resource_byname(dev, "denali_reg", &res);
67 if (ret)
68 return ret;
69
70 denali->flash_reg = devm_ioremap(dev, res.start, resource_size(&res));
71
72 ret = dev_read_resource_byname(dev, "nand_data", &res);
73 if (ret)
74 return ret;
75
76 denali->flash_mem = devm_ioremap(dev, res.start, resource_size(&res));
77
Masahiro Yamadab1c72732017-10-14 02:21:18 +090078 ret = clk_get_by_index(dev, 0, &clk);
79 if (ret)
80 return ret;
81
82 ret = clk_enable(&clk);
83 if (ret)
84 return ret;
85
86 denali->clk_x_rate = clk_get_rate(&clk);
87
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090088 return denali_init(denali);
89}
90
91U_BOOT_DRIVER(denali_nand_dt) = {
92 .name = "denali-nand-dt",
93 .id = UCLASS_MISC,
94 .of_match = denali_nand_dt_ids,
95 .probe = denali_dt_probe,
96 .priv_auto_alloc_size = sizeof(struct denali_nand_info),
97};
98
99void board_nand_init(void)
100{
101 struct udevice *dev;
102 int ret;
103
104 ret = uclass_get_device_by_driver(UCLASS_MISC,
105 DM_GET_DRIVER(denali_nand_dt),
106 &dev);
107 if (ret && ret != -ENODEV)
108 printf("Failed to initialize Denali NAND controller. (error %d)\n",
109 ret);
110}