blob: bd429e0d6266a8c8f948852e9eff2cf34f41b8e7 [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
36static const struct udevice_id mxs_nand_dt_ids[] = {
37 {
Stefan Agner05413d62018-05-30 19:01:44 +020038 .compatible = "fsl,imx6q-gpmi-nand",
39 .data = (unsigned long)&mxs_nand_imx6q_data,
40 },
41 {
Han Xua231b752020-05-04 22:08:57 +080042 .compatible = "fsl,imx6qp-gpmi-nand",
43 .data = (unsigned long)&mxs_nand_imx6q_data,
44 },
45 {
Ye Li960b4ba2020-05-04 22:08:56 +080046 .compatible = "fsl,imx6sx-gpmi-nand",
47 .data = (unsigned long)&mxs_nand_imx6sx_data,
48 },
49 {
Stefan Agner150ddbc2018-06-22 18:06:17 +020050 .compatible = "fsl,imx7d-gpmi-nand",
51 .data = (unsigned long)&mxs_nand_imx7d_data,
52 },
53 { /* sentinel */ }
54};
55
56static int mxs_nand_dt_probe(struct udevice *dev)
57{
58 struct mxs_nand_info *info = dev_get_priv(dev);
59 const struct mxs_nand_dt_data *data;
60 struct resource res;
61 int ret;
62
63 data = (void *)dev_get_driver_data(dev);
64 if (data)
65 info->max_ecc_strength_supported = data->max_ecc_strength_supported;
66
67 info->dev = dev;
68
69 ret = dev_read_resource_byname(dev, "gpmi-nand", &res);
70 if (ret)
71 return ret;
72
73 info->gpmi_regs = devm_ioremap(dev, res.start, resource_size(&res));
74
75
76 ret = dev_read_resource_byname(dev, "bch", &res);
77 if (ret)
78 return ret;
79
80 info->bch_regs = devm_ioremap(dev, res.start, resource_size(&res));
81
82 info->use_minimum_ecc = dev_read_bool(dev, "fsl,use-minimum-ecc");
83
Ye Lic6736132020-05-04 22:08:51 +080084 info->legacy_bch_geometry = dev_read_bool(dev, "fsl,legacy-bch-geometry");
85
Stefan Agner150ddbc2018-06-22 18:06:17 +020086 return mxs_nand_init_ctrl(info);
87}
88
89U_BOOT_DRIVER(mxs_nand_dt) = {
90 .name = "mxs-nand-dt",
91 .id = UCLASS_MTD,
92 .of_match = mxs_nand_dt_ids,
93 .probe = mxs_nand_dt_probe,
94 .priv_auto_alloc_size = sizeof(struct mxs_nand_info),
95};
96
97void board_nand_init(void)
98{
99 struct udevice *dev;
100 int ret;
101
102 ret = uclass_get_device_by_driver(UCLASS_MTD,
103 DM_GET_DRIVER(mxs_nand_dt),
104 &dev);
105 if (ret && ret != -ENODEV)
106 pr_err("Failed to initialize MXS NAND controller. (error %d)\n",
107 ret);
108}