blob: 9d6cb09b42258a57534764a8aad31829c377cce3 [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;
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090019 const struct nand_ecc_caps *ecc_caps;
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090020};
21
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090022NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes,
23 512, 8, 15);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090024static const struct denali_dt_data denali_socfpga_data = {
25 .caps = DENALI_CAP_HW_ECC_FIXUP,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090026 .ecc_caps = &denali_socfpga_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090027};
28
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090029NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes,
30 1024, 8, 16, 24);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090031static const struct denali_dt_data denali_uniphier_v5a_data = {
32 .caps = DENALI_CAP_HW_ECC_FIXUP |
33 DENALI_CAP_DMA_64BIT,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090034 .ecc_caps = &denali_uniphier_v5a_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090035};
36
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090037NAND_ECC_CAPS_SINGLE(denali_uniphier_v5b_ecc_caps, denali_calc_ecc_bytes,
38 1024, 8, 16);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090039static const struct denali_dt_data denali_uniphier_v5b_data = {
40 .revision = 0x0501,
41 .caps = DENALI_CAP_HW_ECC_FIXUP |
42 DENALI_CAP_DMA_64BIT,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090043 .ecc_caps = &denali_uniphier_v5b_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090044};
45
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090046static const struct udevice_id denali_nand_dt_ids[] = {
47 {
48 .compatible = "altr,socfpga-denali-nand",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090049 .data = (unsigned long)&denali_socfpga_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090050 },
51 {
52 .compatible = "socionext,uniphier-denali-nand-v5a",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090053 .data = (unsigned long)&denali_uniphier_v5a_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090054 },
55 {
56 .compatible = "socionext,uniphier-denali-nand-v5b",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090057 .data = (unsigned long)&denali_uniphier_v5b_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090058 },
59 { /* sentinel */ }
60};
61
62static int denali_dt_probe(struct udevice *dev)
63{
64 struct denali_nand_info *denali = dev_get_priv(dev);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090065 const struct denali_dt_data *data;
Masahiro Yamadab1c72732017-10-14 02:21:18 +090066 struct clk clk;
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090067 struct resource res;
68 int ret;
69
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090070 data = (void *)dev_get_driver_data(dev);
71 if (data) {
72 denali->revision = data->revision;
73 denali->caps = data->caps;
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090074 denali->ecc_caps = data->ecc_caps;
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090075 }
76
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090077 denali->dev = dev;
78
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090079 ret = dev_read_resource_byname(dev, "denali_reg", &res);
80 if (ret)
81 return ret;
82
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090083 denali->reg = devm_ioremap(dev, res.start, resource_size(&res));
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090084
85 ret = dev_read_resource_byname(dev, "nand_data", &res);
86 if (ret)
87 return ret;
88
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090089 denali->host = devm_ioremap(dev, res.start, resource_size(&res));
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090090
Masahiro Yamadab1c72732017-10-14 02:21:18 +090091 ret = clk_get_by_index(dev, 0, &clk);
92 if (ret)
93 return ret;
94
95 ret = clk_enable(&clk);
96 if (ret)
97 return ret;
98
99 denali->clk_x_rate = clk_get_rate(&clk);
100
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +0900101 return denali_init(denali);
102}
103
104U_BOOT_DRIVER(denali_nand_dt) = {
105 .name = "denali-nand-dt",
106 .id = UCLASS_MISC,
107 .of_match = denali_nand_dt_ids,
108 .probe = denali_dt_probe,
109 .priv_auto_alloc_size = sizeof(struct denali_nand_info),
110};
111
112void board_nand_init(void)
113{
114 struct udevice *dev;
115 int ret;
116
117 ret = uclass_get_device_by_driver(UCLASS_MISC,
118 DM_GET_DRIVER(denali_nand_dt),
119 &dev);
120 if (ret && ret != -ENODEV)
121 printf("Failed to initialize Denali NAND controller. (error %d)\n",
122 ret);
123}