2 * NXP GPMI NAND flash driver (DT initialization)
4 * Copyright (C) 2018 Toradex
8 * Stefan Agner <stefan.agner@toradex.com>
10 * Based on denali_dt.c
12 * SPDX-License-Identifier: GPL-2.0+
17 #include <linux/ioport.h>
18 #include <linux/printk.h>
23 struct mxs_nand_dt_data {
24 unsigned int max_ecc_strength_supported;
27 static const struct mxs_nand_dt_data mxs_nand_imx6q_data = {
28 .max_ecc_strength_supported = 40,
31 static const struct mxs_nand_dt_data mxs_nand_imx6sx_data = {
32 .max_ecc_strength_supported = 62,
35 static const struct mxs_nand_dt_data mxs_nand_imx7d_data = {
36 .max_ecc_strength_supported = 62,
39 static const struct mxs_nand_dt_data mxs_nand_imx8qxp_data = {
40 .max_ecc_strength_supported = 62,
43 static const struct udevice_id mxs_nand_dt_ids[] = {
45 .compatible = "fsl,imx6q-gpmi-nand",
46 .data = (unsigned long)&mxs_nand_imx6q_data,
49 .compatible = "fsl,imx6qp-gpmi-nand",
50 .data = (unsigned long)&mxs_nand_imx6q_data,
53 .compatible = "fsl,imx6sx-gpmi-nand",
54 .data = (unsigned long)&mxs_nand_imx6sx_data,
57 .compatible = "fsl,imx7d-gpmi-nand",
58 .data = (unsigned long)&mxs_nand_imx7d_data,
61 .compatible = "fsl,imx8qxp-gpmi-nand",
62 .data = (unsigned long)&mxs_nand_imx8qxp_data,
67 static int mxs_nand_dt_probe(struct udevice *dev)
69 struct mxs_nand_info *info = dev_get_priv(dev);
70 const struct mxs_nand_dt_data *data;
74 data = (void *)dev_get_driver_data(dev);
76 info->max_ecc_strength_supported = data->max_ecc_strength_supported;
80 ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
84 info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
87 ret = dev_read_resource_byname(dev, "bch", &res);
91 info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
93 info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
95 info->legacy_bch_geometry = dev_read_bool(dev, "fsl,legacy-bch-geometry");
97 if (IS_ENABLED(CONFIG_CLK) && IS_ENABLED(CONFIG_IMX8)) {
98 /* Assigned clock already set clock */
101 ret = clk_get_by_name(dev, "gpmi_io", &gpmi_clk);
103 debug("Can't get gpmi io clk: %d\n", ret);
107 ret = clk_enable(&gpmi_clk);
109 debug("Can't enable gpmi io clk: %d\n", ret);
113 ret = clk_get_by_name(dev, "gpmi_apb", &gpmi_clk);
115 debug("Can't get gpmi_apb clk: %d\n", ret);
119 ret = clk_enable(&gpmi_clk);
121 debug("Can't enable gpmi_apb clk: %d\n", ret);
125 ret = clk_get_by_name(dev, "gpmi_bch", &gpmi_clk);
127 debug("Can't get gpmi_bch clk: %d\n", ret);
131 ret = clk_enable(&gpmi_clk);
133 debug("Can't enable gpmi_bch clk: %d\n", ret);
137 ret = clk_get_by_name(dev, "gpmi_apb_bch", &gpmi_clk);
139 debug("Can't get gpmi_apb_bch clk: %d\n", ret);
143 ret = clk_enable(&gpmi_clk);
145 debug("Can't enable gpmi_apb_bch clk: %d\n", ret);
149 /* this clock is used for apbh_dma, since the apbh dma does not support DM,
150 * we optionally enable it here
152 ret = clk_get_by_name(dev, "gpmi_apbh_dma", &gpmi_clk);
154 debug("Can't get gpmi_apbh_dma clk: %d\n", ret);
156 ret = clk_enable(&gpmi_clk);
158 debug("Can't enable gpmi_apbh_dma clk: %d\n", ret);
163 return mxs_nand_init_ctrl(info);
166 U_BOOT_DRIVER(mxs_nand_dt) = {
167 .name = "mxs-nand-dt",
169 .of_match = mxs_nand_dt_ids,
170 .probe = mxs_nand_dt_probe,
171 .priv_auto = sizeof(struct mxs_nand_info),
174 void board_nand_init(void)
179 ret = uclass_get_device_by_driver(UCLASS_MTD,
180 DM_DRIVER_GET(mxs_nand_dt),
182 if (ret && ret != -ENODEV)
183 pr_err("Failed to initialize MXS NAND controller. (error %d)\n",