2018-06-22 16:06:17 +00:00
|
|
|
/*
|
|
|
|
* NXP GPMI NAND flash driver (DT initialization)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Toradex
|
2020-05-04 14:09:01 +00:00
|
|
|
* Copyright 2019 NXP
|
|
|
|
*
|
2018-06-22 16:06:17 +00:00
|
|
|
* Authors:
|
|
|
|
* Stefan Agner <stefan.agner@toradex.com>
|
|
|
|
*
|
|
|
|
* Based on denali_dt.c
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <dm.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/printk.h>
|
2020-05-04 14:09:01 +00:00
|
|
|
#include <clk.h>
|
2018-06-22 16:06:17 +00:00
|
|
|
|
2019-06-14 07:35:33 +00:00
|
|
|
#include <mxs_nand.h>
|
2018-06-22 16:06:17 +00:00
|
|
|
|
|
|
|
struct mxs_nand_dt_data {
|
|
|
|
unsigned int max_ecc_strength_supported;
|
2022-08-30 14:48:47 +00:00
|
|
|
int max_chain_delay; /* See the async EDO mode */
|
2018-06-22 16:06:17 +00:00
|
|
|
};
|
|
|
|
|
2018-05-30 17:01:44 +00:00
|
|
|
static const struct mxs_nand_dt_data mxs_nand_imx6q_data = {
|
|
|
|
.max_ecc_strength_supported = 40,
|
2022-08-30 14:48:47 +00:00
|
|
|
.max_chain_delay = 12000,
|
2018-05-30 17:01:44 +00:00
|
|
|
};
|
|
|
|
|
2020-05-04 14:08:56 +00:00
|
|
|
static const struct mxs_nand_dt_data mxs_nand_imx6sx_data = {
|
|
|
|
.max_ecc_strength_supported = 62,
|
2022-08-30 14:48:47 +00:00
|
|
|
.max_chain_delay = 12000,
|
2020-05-04 14:08:56 +00:00
|
|
|
};
|
|
|
|
|
2018-06-22 16:06:17 +00:00
|
|
|
static const struct mxs_nand_dt_data mxs_nand_imx7d_data = {
|
|
|
|
.max_ecc_strength_supported = 62,
|
2022-08-30 14:48:47 +00:00
|
|
|
.max_chain_delay = 12000,
|
2018-06-22 16:06:17 +00:00
|
|
|
};
|
|
|
|
|
2020-05-04 14:09:00 +00:00
|
|
|
static const struct mxs_nand_dt_data mxs_nand_imx8qxp_data = {
|
|
|
|
.max_ecc_strength_supported = 62,
|
2022-08-30 14:48:47 +00:00
|
|
|
.max_chain_delay = 12000,
|
2020-05-04 14:09:00 +00:00
|
|
|
};
|
|
|
|
|
2018-06-22 16:06:17 +00:00
|
|
|
static const struct udevice_id mxs_nand_dt_ids[] = {
|
2018-05-30 17:01:44 +00:00
|
|
|
{
|
|
|
|
.compatible = "fsl,imx6q-gpmi-nand",
|
|
|
|
.data = (unsigned long)&mxs_nand_imx6q_data,
|
|
|
|
},
|
2020-05-04 14:08:57 +00:00
|
|
|
{
|
|
|
|
.compatible = "fsl,imx6qp-gpmi-nand",
|
|
|
|
.data = (unsigned long)&mxs_nand_imx6q_data,
|
|
|
|
},
|
2020-05-04 14:08:56 +00:00
|
|
|
{
|
|
|
|
.compatible = "fsl,imx6sx-gpmi-nand",
|
|
|
|
.data = (unsigned long)&mxs_nand_imx6sx_data,
|
|
|
|
},
|
2018-06-22 16:06:17 +00:00
|
|
|
{
|
|
|
|
.compatible = "fsl,imx7d-gpmi-nand",
|
|
|
|
.data = (unsigned long)&mxs_nand_imx7d_data,
|
|
|
|
},
|
2020-05-04 14:09:00 +00:00
|
|
|
{
|
|
|
|
.compatible = "fsl,imx8qxp-gpmi-nand",
|
|
|
|
.data = (unsigned long)&mxs_nand_imx8qxp_data,
|
|
|
|
},
|
2018-06-22 16:06:17 +00:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mxs_nand_dt_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mxs_nand_info *info = dev_get_priv(dev);
|
|
|
|
const struct mxs_nand_dt_data *data;
|
|
|
|
struct resource res;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
data = (void *)dev_get_driver_data(dev);
|
2022-08-30 14:48:47 +00:00
|
|
|
if (data) {
|
2018-06-22 16:06:17 +00:00
|
|
|
info->max_ecc_strength_supported = data->max_ecc_strength_supported;
|
2022-08-30 14:48:47 +00:00
|
|
|
info->max_chain_delay = data->max_chain_delay;
|
|
|
|
}
|
2018-06-22 16:06:17 +00:00
|
|
|
|
|
|
|
info->dev = dev;
|
|
|
|
|
|
|
|
ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
|
|
|
|
|
|
|
|
|
|
|
|
ret = dev_read_resource_byname(dev, "bch", &res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
|
|
|
|
|
|
|
|
info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
|
|
|
|
|
2022-08-30 14:48:47 +00:00
|
|
|
if (IS_ENABLED(CONFIG_CLK) &&
|
|
|
|
(IS_ENABLED(CONFIG_IMX8) || IS_ENABLED(CONFIG_IMX8M))) {
|
2020-05-04 14:09:01 +00:00
|
|
|
/* Assigned clock already set clock */
|
|
|
|
struct clk gpmi_clk;
|
|
|
|
|
2022-08-30 14:48:47 +00:00
|
|
|
info->gpmi_clk = devm_clk_get(dev, "gpmi_io");
|
|
|
|
|
|
|
|
if (IS_ERR(info->gpmi_clk)) {
|
|
|
|
ret = PTR_ERR(info->gpmi_clk);
|
2020-05-04 14:09:01 +00:00
|
|
|
debug("Can't get gpmi io clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-30 14:48:47 +00:00
|
|
|
ret = clk_enable(info->gpmi_clk);
|
2020-05-04 14:09:01 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't enable gpmi io clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-08-30 14:48:47 +00:00
|
|
|
if (IS_ENABLED(CONFIG_IMX8)) {
|
|
|
|
ret = clk_get_by_name(dev, "gpmi_apb", &gpmi_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get gpmi_apb clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_enable(&gpmi_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't enable gpmi_apb clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "gpmi_bch", &gpmi_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't get gpmi_bch clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_enable(&gpmi_clk);
|
|
|
|
if (ret < 0) {
|
|
|
|
debug("Can't enable gpmi_bch clk: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-04 14:09:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 09:56:33 +00:00
|
|
|
ret = clk_get_by_name(dev, "gpmi_bch_apb", &gpmi_clk);
|
2020-05-04 14:09:01 +00:00
|
|
|
if (ret < 0) {
|
2022-09-27 09:56:33 +00:00
|
|
|
debug("Can't get gpmi_bch_apb clk: %d\n", ret);
|
2020-05-04 14:09:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = clk_enable(&gpmi_clk);
|
|
|
|
if (ret < 0) {
|
2022-09-27 09:56:33 +00:00
|
|
|
debug("Can't enable gpmi_bch_apb clk: %d\n", ret);
|
2020-05-04 14:09:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 16:06:17 +00:00
|
|
|
return mxs_nand_init_ctrl(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mxs_nand_dt) = {
|
|
|
|
.name = "mxs-nand-dt",
|
|
|
|
.id = UCLASS_MTD,
|
|
|
|
.of_match = mxs_nand_dt_ids,
|
|
|
|
.probe = mxs_nand_dt_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct mxs_nand_info),
|
2018-06-22 16:06:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void board_nand_init(void)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MTD,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(mxs_nand_dt),
|
2018-06-22 16:06:17 +00:00
|
|
|
&dev);
|
|
|
|
if (ret && ret != -ENODEV)
|
|
|
|
pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
|
|
|
|
ret);
|
|
|
|
}
|