forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/mtd/nand/raw/xway_nand.c
....@@ -1,7 +1,5 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
2
- * This program is free software; you can redistribute it and/or modify it
3
- * under the terms of the GNU General Public License version 2 as published
4
- * by the Free Software Foundation.
53 *
64 * Copyright © 2012 John Crispin <john@phrozen.org>
75 * Copyright © 2016 Hauke Mehrtens <hauke@hauke-m.de>
....@@ -64,6 +62,7 @@
6462 #define NAND_CON_NANDM 1
6563
6664 struct xway_nand_data {
65
+ struct nand_controller controller;
6766 struct nand_chip chip;
6867 unsigned long csflags;
6968 void __iomem *nandaddr;
....@@ -85,9 +84,8 @@
8584 writeb(value, data->nandaddr + op);
8685 }
8786
88
-static void xway_select_chip(struct mtd_info *mtd, int select)
87
+static void xway_select_chip(struct nand_chip *chip, int select)
8988 {
90
- struct nand_chip *chip = mtd_to_nand(mtd);
9189 struct xway_nand_data *data = nand_get_controller_data(chip);
9290
9391 switch (select) {
....@@ -106,8 +104,10 @@
106104 }
107105 }
108106
109
-static void xway_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
107
+static void xway_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl)
110108 {
109
+ struct mtd_info *mtd = nand_to_mtd(chip);
110
+
111111 if (cmd == NAND_CMD_NONE)
112112 return;
113113
....@@ -120,31 +120,44 @@
120120 ;
121121 }
122122
123
-static int xway_dev_ready(struct mtd_info *mtd)
123
+static int xway_dev_ready(struct nand_chip *chip)
124124 {
125125 return ltq_ebu_r32(EBU_NAND_WAIT) & NAND_WAIT_RD;
126126 }
127127
128
-static unsigned char xway_read_byte(struct mtd_info *mtd)
128
+static unsigned char xway_read_byte(struct nand_chip *chip)
129129 {
130
- return xway_readb(mtd, NAND_READ_DATA);
130
+ return xway_readb(nand_to_mtd(chip), NAND_READ_DATA);
131131 }
132132
133
-static void xway_read_buf(struct mtd_info *mtd, u_char *buf, int len)
133
+static void xway_read_buf(struct nand_chip *chip, u_char *buf, int len)
134134 {
135135 int i;
136136
137137 for (i = 0; i < len; i++)
138
- buf[i] = xway_readb(mtd, NAND_WRITE_DATA);
138
+ buf[i] = xway_readb(nand_to_mtd(chip), NAND_WRITE_DATA);
139139 }
140140
141
-static void xway_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
141
+static void xway_write_buf(struct nand_chip *chip, const u_char *buf, int len)
142142 {
143143 int i;
144144
145145 for (i = 0; i < len; i++)
146
- xway_writeb(mtd, NAND_WRITE_DATA, buf[i]);
146
+ xway_writeb(nand_to_mtd(chip), NAND_WRITE_DATA, buf[i]);
147147 }
148
+
149
+static int xway_attach_chip(struct nand_chip *chip)
150
+{
151
+ if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT &&
152
+ chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN)
153
+ chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
154
+
155
+ return 0;
156
+}
157
+
158
+static const struct nand_controller_ops xway_nand_ops = {
159
+ .attach_chip = xway_attach_chip,
160
+};
148161
149162 /*
150163 * Probe for the NAND device.
....@@ -173,16 +186,17 @@
173186 mtd = nand_to_mtd(&data->chip);
174187 mtd->dev.parent = &pdev->dev;
175188
176
- data->chip.cmd_ctrl = xway_cmd_ctrl;
177
- data->chip.dev_ready = xway_dev_ready;
178
- data->chip.select_chip = xway_select_chip;
179
- data->chip.write_buf = xway_write_buf;
180
- data->chip.read_buf = xway_read_buf;
181
- data->chip.read_byte = xway_read_byte;
182
- data->chip.chip_delay = 30;
189
+ data->chip.legacy.cmd_ctrl = xway_cmd_ctrl;
190
+ data->chip.legacy.dev_ready = xway_dev_ready;
191
+ data->chip.legacy.select_chip = xway_select_chip;
192
+ data->chip.legacy.write_buf = xway_write_buf;
193
+ data->chip.legacy.read_buf = xway_read_buf;
194
+ data->chip.legacy.read_byte = xway_read_byte;
195
+ data->chip.legacy.chip_delay = 30;
183196
184
- data->chip.ecc.mode = NAND_ECC_SOFT;
185
- data->chip.ecc.algo = NAND_ECC_HAMMING;
197
+ nand_controller_init(&data->controller);
198
+ data->controller.ops = &xway_nand_ops;
199
+ data->chip.controller = &data->controller;
186200
187201 platform_set_drvdata(pdev, data);
188202 nand_set_controller_data(&data->chip, data);
....@@ -204,6 +218,13 @@
204218 | NAND_CON_SE_P | NAND_CON_WP_P | NAND_CON_PRE_P
205219 | cs_flag, EBU_NAND_CON);
206220
221
+ /*
222
+ * This driver assumes that the default ECC engine should be TYPE_SOFT.
223
+ * Set ->engine_type before registering the NAND devices in order to
224
+ * provide a driver specific default value.
225
+ */
226
+ data->chip.ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
227
+
207228 /* Scan to find existence of the device */
208229 err = nand_scan(&data->chip, 1);
209230 if (err)
....@@ -222,8 +243,12 @@
222243 static int xway_nand_remove(struct platform_device *pdev)
223244 {
224245 struct xway_nand_data *data = platform_get_drvdata(pdev);
246
+ struct nand_chip *chip = &data->chip;
247
+ int ret;
225248
226
- nand_release(&data->chip);
249
+ ret = mtd_device_unregister(nand_to_mtd(chip));
250
+ WARN_ON(ret);
251
+ nand_cleanup(chip);
227252
228253 return 0;
229254 }