blob: c4dc0bb1ddfe8d118690b84ed377d97259b3e265 [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
5 * Authors:
6 * Stefan Agner <stefan.agner@toradex.com>
7 *
8 * Based on denali_dt.c
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 */
12
13#include <dm.h>
14#include <linux/io.h>
15#include <linux/ioport.h>
16#include <linux/printk.h>
17
Shyam Sainif63ef492019-06-14 13:05:33 +053018#include <mxs_nand.h>
Stefan Agner150ddbc2018-06-22 18:06:17 +020019
20struct mxs_nand_dt_data {
21 unsigned int max_ecc_strength_supported;
22};
23
Stefan Agner05413d62018-05-30 19:01:44 +020024static const struct mxs_nand_dt_data mxs_nand_imx6q_data = {
25 .max_ecc_strength_supported = 40,
26};
27
Ye Li960b4ba2020-05-04 22:08:56 +080028static const struct mxs_nand_dt_data mxs_nand_imx6sx_data = {
29 .max_ecc_strength_supported = 62,
30};
31
Stefan Agner150ddbc2018-06-22 18:06:17 +020032static const struct mxs_nand_dt_data mxs_nand_imx7d_data = {
33 .max_ecc_strength_supported = 62,
34};
35
Peng Fan128abf42020-05-04 22:09:00 +080036static const struct mxs_nand_dt_data mxs_nand_imx8qxp_data = {
37 .max_ecc_strength_supported = 62,
38};
39
Stefan Agner150ddbc2018-06-22 18:06:17 +020040static const struct udevice_id mxs_nand_dt_ids[] = {
41 {
Stefan Agner05413d62018-05-30 19:01:44 +020042 .compatible = "fsl,imx6q-gpmi-nand",
43 .data = (unsigned long)&mxs_nand_imx6q_data,
44 },
45 {
Han Xua231b752020-05-04 22:08:57 +080046 .compatible = "fsl,imx6qp-gpmi-nand",
47 .data = (unsigned long)&mxs_nand_imx6q_data,
48 },
49 {
Ye Li960b4ba2020-05-04 22:08:56 +080050 .compatible = "fsl,imx6sx-gpmi-nand",
51 .data = (unsigned long)&mxs_nand_imx6sx_data,
52 },
53 {
Stefan Agner150ddbc2018-06-22 18:06:17 +020054 .compatible = "fsl,imx7d-gpmi-nand",
55 .data = (unsigned long)&mxs_nand_imx7d_data,
56 },
Peng Fan128abf42020-05-04 22:09:00 +080057 {
58 .compatible = "fsl,imx8qxp-gpmi-nand",
59 .data = (unsigned long)&mxs_nand_imx8qxp_data,
60 },
Stefan Agner150ddbc2018-06-22 18:06:17 +020061 { /* sentinel */ }
62};
63
64static int mxs_nand_dt_probe(struct udevice *dev)
65{
66 struct mxs_nand_info *info = dev_get_priv(dev);
67 const struct mxs_nand_dt_data *data;
68 struct resource res;
69 int ret;
70
71 data = (void *)dev_get_driver_data(dev);
72 if (data)
73 info->max_ecc_strength_supported = data->max_ecc_strength_supported;
74
75 info->dev = dev;
76
77 ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
78 if (ret)
79 return ret;
80
81 info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
82
83
84 ret = dev_read_resource_byname(dev, "bch", &res);
85 if (ret)
86 return ret;
87
88 info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
89
90 info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
91
Ye Lic6736132020-05-04 22:08:51 +080092 info->legacy_bch_geometry = dev_read_bool(dev, "fsl,legacy-bch-geometry");
93
Stefan Agner150ddbc2018-06-22 18:06:17 +020094 return mxs_nand_init_ctrl(info);
95}
96
97U_BOOT_DRIVER(mxs_nand_dt) = {
98 .name = "mxs-nand-dt",
99 .id = UCLASS_MTD,
100 .of_match = mxs_nand_dt_ids,
101 .probe = mxs_nand_dt_probe,
102 .priv_auto_alloc_size = sizeof(struct mxs_nand_info),
103};
104
105void board_nand_init(void)
106{
107 struct udevice *dev;
108 int ret;
109
110 ret = uclass_get_device_by_driver(UCLASS_MTD,
111 DM_GET_DRIVER(mxs_nand_dt),
112 &dev);
113 if (ret && ret != -ENODEV)
114 pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
115 ret);
116}