blob: 65a7797f0f3819aace32ea4f8a8a8b5d504b5a62 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +09002/*
3 * Copyright (C) 2017 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +09005 */
6
Masahiro Yamadab1c72732017-10-14 02:21:18 +09007#include <clk.h>
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +09008#include <dm.h>
9#include <linux/io.h>
10#include <linux/ioport.h>
Masahiro Yamada2cf4eba2017-11-30 13:45:26 +090011#include <linux/printk.h>
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090012
13#include "denali.h"
14
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090015struct denali_dt_data {
16 unsigned int revision;
17 unsigned int caps;
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090018 const struct nand_ecc_caps *ecc_caps;
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090019};
20
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090021NAND_ECC_CAPS_SINGLE(denali_socfpga_ecc_caps, denali_calc_ecc_bytes,
22 512, 8, 15);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090023static const struct denali_dt_data denali_socfpga_data = {
24 .caps = DENALI_CAP_HW_ECC_FIXUP,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090025 .ecc_caps = &denali_socfpga_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090026};
27
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090028NAND_ECC_CAPS_SINGLE(denali_uniphier_v5a_ecc_caps, denali_calc_ecc_bytes,
29 1024, 8, 16, 24);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090030static const struct denali_dt_data denali_uniphier_v5a_data = {
31 .caps = DENALI_CAP_HW_ECC_FIXUP |
32 DENALI_CAP_DMA_64BIT,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090033 .ecc_caps = &denali_uniphier_v5a_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090034};
35
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090036NAND_ECC_CAPS_SINGLE(denali_uniphier_v5b_ecc_caps, denali_calc_ecc_bytes,
37 1024, 8, 16);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090038static const struct denali_dt_data denali_uniphier_v5b_data = {
39 .revision = 0x0501,
40 .caps = DENALI_CAP_HW_ECC_FIXUP |
41 DENALI_CAP_DMA_64BIT,
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090042 .ecc_caps = &denali_uniphier_v5b_ecc_caps,
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090043};
44
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090045static const struct udevice_id denali_nand_dt_ids[] = {
46 {
47 .compatible = "altr,socfpga-denali-nand",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090048 .data = (unsigned long)&denali_socfpga_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090049 },
50 {
51 .compatible = "socionext,uniphier-denali-nand-v5a",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090052 .data = (unsigned long)&denali_uniphier_v5a_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090053 },
54 {
55 .compatible = "socionext,uniphier-denali-nand-v5b",
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090056 .data = (unsigned long)&denali_uniphier_v5b_data,
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090057 },
58 { /* sentinel */ }
59};
60
61static int denali_dt_probe(struct udevice *dev)
62{
63 struct denali_nand_info *denali = dev_get_priv(dev);
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090064 const struct denali_dt_data *data;
Masahiro Yamadab1c72732017-10-14 02:21:18 +090065 struct clk clk;
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090066 struct resource res;
67 int ret;
68
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090069 data = (void *)dev_get_driver_data(dev);
70 if (data) {
71 denali->revision = data->revision;
72 denali->caps = data->caps;
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090073 denali->ecc_caps = data->ecc_caps;
Masahiro Yamada54fde8e2017-09-15 21:43:19 +090074 }
75
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090076 denali->dev = dev;
77
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090078 ret = dev_read_resource_byname(dev, "denali_reg", &res);
79 if (ret)
80 return ret;
81
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090082 denali->reg = devm_ioremap(dev, res.start, resource_size(&res));
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090083
84 ret = dev_read_resource_byname(dev, "nand_data", &res);
85 if (ret)
86 return ret;
87
Masahiro Yamada8b0c16f2017-11-22 02:38:32 +090088 denali->host = devm_ioremap(dev, res.start, resource_size(&res));
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +090089
Masahiro Yamadab1c72732017-10-14 02:21:18 +090090 ret = clk_get_by_index(dev, 0, &clk);
91 if (ret)
92 return ret;
93
94 ret = clk_enable(&clk);
95 if (ret)
96 return ret;
97
98 denali->clk_x_rate = clk_get_rate(&clk);
99
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +0900100 return denali_init(denali);
101}
102
103U_BOOT_DRIVER(denali_nand_dt) = {
104 .name = "denali-nand-dt",
105 .id = UCLASS_MISC,
106 .of_match = denali_nand_dt_ids,
107 .probe = denali_dt_probe,
108 .priv_auto_alloc_size = sizeof(struct denali_nand_info),
109};
110
111void board_nand_init(void)
112{
113 struct udevice *dev;
114 int ret;
115
116 ret = uclass_get_device_by_driver(UCLASS_MISC,
117 DM_GET_DRIVER(denali_nand_dt),
118 &dev);
119 if (ret && ret != -ENODEV)
Masahiro Yamada2cf4eba2017-11-30 13:45:26 +0900120 pr_err("Failed to initialize Denali NAND controller. (error %d)\n",
Masahiro Yamada9c5a5dd2017-08-26 01:12:31 +0900121 ret);
122}