blob: a922a22b27302e0c71456183cdb4d10cdee5ad05 [file] [log] [blame]
Stefan Agner150ddbc2018-06-22 18:06:17 +02001/*
2 * NXP GPMI NAND flash driver (DT initialization)
3 *
4 * Copyright (C) 2018 Toradex
Ye Li30e5a502020-05-04 22:09:01 +08005 * Copyright 2019 NXP
6 *
Stefan Agner150ddbc2018-06-22 18:06:17 +02007 * Authors:
8 * Stefan Agner <stefan.agner@toradex.com>
9 *
10 * Based on denali_dt.c
11 *
12 * SPDX-License-Identifier: GPL-2.0+
13 */
14
15#include <dm.h>
16#include <linux/io.h>
17#include <linux/ioport.h>
18#include <linux/printk.h>
Ye Li30e5a502020-05-04 22:09:01 +080019#include <clk.h>
Stefan Agner150ddbc2018-06-22 18:06:17 +020020
Shyam Sainif63ef492019-06-14 13:05:33 +053021#include <mxs_nand.h>
Stefan Agner150ddbc2018-06-22 18:06:17 +020022
23struct mxs_nand_dt_data {
24 unsigned int max_ecc_strength_supported;
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020025 int max_chain_delay; /* See the async EDO mode */
Stefan Agner150ddbc2018-06-22 18:06:17 +020026};
27
Stefan Agner05413d62018-05-30 19:01:44 +020028static const struct mxs_nand_dt_data mxs_nand_imx6q_data = {
29 .max_ecc_strength_supported = 40,
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020030 .max_chain_delay = 12000,
Stefan Agner05413d62018-05-30 19:01:44 +020031};
32
Ye Li960b4ba2020-05-04 22:08:56 +080033static const struct mxs_nand_dt_data mxs_nand_imx6sx_data = {
34 .max_ecc_strength_supported = 62,
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020035 .max_chain_delay = 12000,
Ye Li960b4ba2020-05-04 22:08:56 +080036};
37
Stefan Agner150ddbc2018-06-22 18:06:17 +020038static const struct mxs_nand_dt_data mxs_nand_imx7d_data = {
39 .max_ecc_strength_supported = 62,
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020040 .max_chain_delay = 12000,
Stefan Agner150ddbc2018-06-22 18:06:17 +020041};
42
Peng Fan128abf42020-05-04 22:09:00 +080043static const struct mxs_nand_dt_data mxs_nand_imx8qxp_data = {
44 .max_ecc_strength_supported = 62,
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020045 .max_chain_delay = 12000,
Peng Fan128abf42020-05-04 22:09:00 +080046};
47
Stefan Agner150ddbc2018-06-22 18:06:17 +020048static const struct udevice_id mxs_nand_dt_ids[] = {
49 {
Stefan Agner05413d62018-05-30 19:01:44 +020050 .compatible = "fsl,imx6q-gpmi-nand",
51 .data = (unsigned long)&mxs_nand_imx6q_data,
52 },
53 {
Han Xua231b752020-05-04 22:08:57 +080054 .compatible = "fsl,imx6qp-gpmi-nand",
55 .data = (unsigned long)&mxs_nand_imx6q_data,
56 },
57 {
Ye Li960b4ba2020-05-04 22:08:56 +080058 .compatible = "fsl,imx6sx-gpmi-nand",
59 .data = (unsigned long)&mxs_nand_imx6sx_data,
60 },
61 {
Stefan Agner150ddbc2018-06-22 18:06:17 +020062 .compatible = "fsl,imx7d-gpmi-nand",
63 .data = (unsigned long)&mxs_nand_imx7d_data,
64 },
Peng Fan128abf42020-05-04 22:09:00 +080065 {
66 .compatible = "fsl,imx8qxp-gpmi-nand",
67 .data = (unsigned long)&mxs_nand_imx8qxp_data,
68 },
Stefan Agner150ddbc2018-06-22 18:06:17 +020069 { /* sentinel */ }
70};
71
72static int mxs_nand_dt_probe(struct udevice *dev)
73{
74 struct mxs_nand_info *info = dev_get_priv(dev);
75 const struct mxs_nand_dt_data *data;
76 struct resource res;
77 int ret;
78
79 data = (void *)dev_get_driver_data(dev);
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020080 if (data) {
Stefan Agner150ddbc2018-06-22 18:06:17 +020081 info->max_ecc_strength_supported = data->max_ecc_strength_supported;
Michael Trimarchifd6e13e2022-08-30 16:48:47 +020082 info->max_chain_delay = data->max_chain_delay;
83 }
Stefan Agner150ddbc2018-06-22 18:06:17 +020084
85 info->dev = dev;
86
87 ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
88 if (ret)
89 return ret;
90
91 info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
92
93
94 ret = dev_read_resource_byname(dev, "bch", &res);
95 if (ret)
96 return ret;
97
98 info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
99
100 info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
101
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200102 if (IS_ENABLED(CONFIG_CLK) &&
103 (IS_ENABLED(CONFIG_IMX8) || IS_ENABLED(CONFIG_IMX8M))) {
Ye Li30e5a502020-05-04 22:09:01 +0800104 /* Assigned clock already set clock */
105 struct clk gpmi_clk;
106
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200107 info->gpmi_clk = devm_clk_get(dev, "gpmi_io");
108
109 if (IS_ERR(info->gpmi_clk)) {
110 ret = PTR_ERR(info->gpmi_clk);
Ye Li30e5a502020-05-04 22:09:01 +0800111 debug("Can't get gpmi io clk: %d\n", ret);
112 return ret;
113 }
114
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200115 ret = clk_enable(info->gpmi_clk);
Ye Li30e5a502020-05-04 22:09:01 +0800116 if (ret < 0) {
117 debug("Can't enable gpmi io clk: %d\n", ret);
118 return ret;
119 }
120
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200121 if (IS_ENABLED(CONFIG_IMX8)) {
122 ret = clk_get_by_name(dev, "gpmi_apb", &gpmi_clk);
123 if (ret < 0) {
124 debug("Can't get gpmi_apb clk: %d\n", ret);
125 return ret;
126 }
Ye Li30e5a502020-05-04 22:09:01 +0800127
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200128 ret = clk_enable(&gpmi_clk);
129 if (ret < 0) {
130 debug("Can't enable gpmi_apb clk: %d\n", ret);
131 return ret;
132 }
Ye Li30e5a502020-05-04 22:09:01 +0800133
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200134 ret = clk_get_by_name(dev, "gpmi_bch", &gpmi_clk);
135 if (ret < 0) {
136 debug("Can't get gpmi_bch clk: %d\n", ret);
137 return ret;
138 }
Ye Li30e5a502020-05-04 22:09:01 +0800139
Michael Trimarchifd6e13e2022-08-30 16:48:47 +0200140 ret = clk_enable(&gpmi_clk);
141 if (ret < 0) {
142 debug("Can't enable gpmi_bch clk: %d\n", ret);
143 return ret;
144 }
Ye Li30e5a502020-05-04 22:09:01 +0800145 }
146
Dario Binacchi8a6bbc52022-09-27 11:56:33 +0200147 ret = clk_get_by_name(dev, "gpmi_bch_apb", &gpmi_clk);
Ye Li30e5a502020-05-04 22:09:01 +0800148 if (ret < 0) {
Dario Binacchi8a6bbc52022-09-27 11:56:33 +0200149 debug("Can't get gpmi_bch_apb clk: %d\n", ret);
Ye Li30e5a502020-05-04 22:09:01 +0800150 return ret;
151 }
152
153 ret = clk_enable(&gpmi_clk);
154 if (ret < 0) {
Dario Binacchi8a6bbc52022-09-27 11:56:33 +0200155 debug("Can't enable gpmi_bch_apb clk: %d\n", ret);
Ye Li30e5a502020-05-04 22:09:01 +0800156 return ret;
157 }
Ye Li30e5a502020-05-04 22:09:01 +0800158 }
159
Stefan Agner150ddbc2018-06-22 18:06:17 +0200160 return mxs_nand_init_ctrl(info);
161}
162
163U_BOOT_DRIVER(mxs_nand_dt) = {
164 .name = "mxs-nand-dt",
165 .id = UCLASS_MTD,
166 .of_match = mxs_nand_dt_ids,
167 .probe = mxs_nand_dt_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700168 .priv_auto = sizeof(struct mxs_nand_info),
Stefan Agner150ddbc2018-06-22 18:06:17 +0200169};
170
171void board_nand_init(void)
172{
173 struct udevice *dev;
174 int ret;
175
176 ret = uclass_get_device_by_driver(UCLASS_MTD,
Simon Glass65130cd2020-12-28 20:34:56 -0700177 DM_DRIVER_GET(mxs_nand_dt),
Stefan Agner150ddbc2018-06-22 18:06:17 +0200178 &dev);
179 if (ret && ret != -ENODEV)
180 pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
181 ret);
182}