Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 1 | /* |
| 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 Saini | f63ef49 | 2019-06-14 13:05:33 +0530 | [diff] [blame] | 18 | #include <mxs_nand.h> |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 19 | |
| 20 | struct mxs_nand_dt_data { |
| 21 | unsigned int max_ecc_strength_supported; |
| 22 | }; |
| 23 | |
Stefan Agner | 05413d6 | 2018-05-30 19:01:44 +0200 | [diff] [blame] | 24 | static const struct mxs_nand_dt_data mxs_nand_imx6q_data = { |
| 25 | .max_ecc_strength_supported = 40, |
| 26 | }; |
| 27 | |
Ye Li | 960b4ba | 2020-05-04 22:08:56 +0800 | [diff] [blame] | 28 | static const struct mxs_nand_dt_data mxs_nand_imx6sx_data = { |
| 29 | .max_ecc_strength_supported = 62, |
| 30 | }; |
| 31 | |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 32 | static const struct mxs_nand_dt_data mxs_nand_imx7d_data = { |
| 33 | .max_ecc_strength_supported = 62, |
| 34 | }; |
| 35 | |
Peng Fan | 128abf4 | 2020-05-04 22:09:00 +0800 | [diff] [blame^] | 36 | static const struct mxs_nand_dt_data mxs_nand_imx8qxp_data = { |
| 37 | .max_ecc_strength_supported = 62, |
| 38 | }; |
| 39 | |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 40 | static const struct udevice_id mxs_nand_dt_ids[] = { |
| 41 | { |
Stefan Agner | 05413d6 | 2018-05-30 19:01:44 +0200 | [diff] [blame] | 42 | .compatible = "fsl,imx6q-gpmi-nand", |
| 43 | .data = (unsigned long)&mxs_nand_imx6q_data, |
| 44 | }, |
| 45 | { |
Han Xu | a231b75 | 2020-05-04 22:08:57 +0800 | [diff] [blame] | 46 | .compatible = "fsl,imx6qp-gpmi-nand", |
| 47 | .data = (unsigned long)&mxs_nand_imx6q_data, |
| 48 | }, |
| 49 | { |
Ye Li | 960b4ba | 2020-05-04 22:08:56 +0800 | [diff] [blame] | 50 | .compatible = "fsl,imx6sx-gpmi-nand", |
| 51 | .data = (unsigned long)&mxs_nand_imx6sx_data, |
| 52 | }, |
| 53 | { |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 54 | .compatible = "fsl,imx7d-gpmi-nand", |
| 55 | .data = (unsigned long)&mxs_nand_imx7d_data, |
| 56 | }, |
Peng Fan | 128abf4 | 2020-05-04 22:09:00 +0800 | [diff] [blame^] | 57 | { |
| 58 | .compatible = "fsl,imx8qxp-gpmi-nand", |
| 59 | .data = (unsigned long)&mxs_nand_imx8qxp_data, |
| 60 | }, |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 61 | { /* sentinel */ } |
| 62 | }; |
| 63 | |
| 64 | static 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 Li | c673613 | 2020-05-04 22:08:51 +0800 | [diff] [blame] | 92 | info->legacy_bch_geometry = dev_read_bool(dev, "fsl,legacy-bch-geometry"); |
| 93 | |
Stefan Agner | 150ddbc | 2018-06-22 18:06:17 +0200 | [diff] [blame] | 94 | return mxs_nand_init_ctrl(info); |
| 95 | } |
| 96 | |
| 97 | U_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 | |
| 105 | void 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 | } |