forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/mtd/nand/raw/ndfc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Overview:
34 * Platform independent driver for NDFC (NanD Flash Controller)
....@@ -14,12 +15,6 @@
1415 * Copyright 2006 IBM
1516 * Copyright 2008 PIKA Technologies
1617 * Sean MacLennan <smaclennan@pikatech.com>
17
- *
18
- * This program is free software; you can redistribute it and/or modify it
19
- * under the terms of the GNU General Public License as published by the
20
- * Free Software Foundation; either version 2 of the License, or (at your
21
- * option) any later version.
22
- *
2318 */
2419 #include <linux/module.h>
2520 #include <linux/mtd/rawnand.h>
....@@ -44,10 +39,9 @@
4439
4540 static struct ndfc_controller ndfc_ctrl[NDFC_MAX_CS];
4641
47
-static void ndfc_select_chip(struct mtd_info *mtd, int chip)
42
+static void ndfc_select_chip(struct nand_chip *nchip, int chip)
4843 {
4944 uint32_t ccr;
50
- struct nand_chip *nchip = mtd_to_nand(mtd);
5145 struct ndfc_controller *ndfc = nand_get_controller_data(nchip);
5246
5347 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
....@@ -59,9 +53,8 @@
5953 out_be32(ndfc->ndfcbase + NDFC_CCR, ccr);
6054 }
6155
62
-static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
56
+static void ndfc_hwcontrol(struct nand_chip *chip, int cmd, unsigned int ctrl)
6357 {
64
- struct nand_chip *chip = mtd_to_nand(mtd);
6558 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
6659
6760 if (cmd == NAND_CMD_NONE)
....@@ -73,18 +66,16 @@
7366 writel(cmd & 0xFF, ndfc->ndfcbase + NDFC_ALE);
7467 }
7568
76
-static int ndfc_ready(struct mtd_info *mtd)
69
+static int ndfc_ready(struct nand_chip *chip)
7770 {
78
- struct nand_chip *chip = mtd_to_nand(mtd);
7971 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
8072
8173 return in_be32(ndfc->ndfcbase + NDFC_STAT) & NDFC_STAT_IS_READY;
8274 }
8375
84
-static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode)
76
+static void ndfc_enable_hwecc(struct nand_chip *chip, int mode)
8577 {
8678 uint32_t ccr;
87
- struct nand_chip *chip = mtd_to_nand(mtd);
8879 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
8980
9081 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
....@@ -93,10 +84,9 @@
9384 wmb();
9485 }
9586
96
-static int ndfc_calculate_ecc(struct mtd_info *mtd,
87
+static int ndfc_calculate_ecc(struct nand_chip *chip,
9788 const u_char *dat, u_char *ecc_code)
9889 {
99
- struct nand_chip *chip = mtd_to_nand(mtd);
10090 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
10191 uint32_t ecc;
10292 uint8_t *p = (uint8_t *)&ecc;
....@@ -118,9 +108,8 @@
118108 * functions. No further checking, as nand_base will always read/write
119109 * page aligned.
120110 */
121
-static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
111
+static void ndfc_read_buf(struct nand_chip *chip, uint8_t *buf, int len)
122112 {
123
- struct nand_chip *chip = mtd_to_nand(mtd);
124113 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
125114 uint32_t *p = (uint32_t *) buf;
126115
....@@ -128,9 +117,8 @@
128117 *p++ = in_be32(ndfc->ndfcbase + NDFC_DATA);
129118 }
130119
131
-static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
120
+static void ndfc_write_buf(struct nand_chip *chip, const uint8_t *buf, int len)
132121 {
133
- struct nand_chip *chip = mtd_to_nand(mtd);
134122 struct ndfc_controller *ndfc = nand_get_controller_data(chip);
135123 uint32_t *p = (uint32_t *) buf;
136124
....@@ -149,19 +137,19 @@
149137 struct mtd_info *mtd = nand_to_mtd(chip);
150138 int ret;
151139
152
- chip->IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
153
- chip->IO_ADDR_W = ndfc->ndfcbase + NDFC_DATA;
154
- chip->cmd_ctrl = ndfc_hwcontrol;
155
- chip->dev_ready = ndfc_ready;
156
- chip->select_chip = ndfc_select_chip;
157
- chip->chip_delay = 50;
140
+ chip->legacy.IO_ADDR_R = ndfc->ndfcbase + NDFC_DATA;
141
+ chip->legacy.IO_ADDR_W = ndfc->ndfcbase + NDFC_DATA;
142
+ chip->legacy.cmd_ctrl = ndfc_hwcontrol;
143
+ chip->legacy.dev_ready = ndfc_ready;
144
+ chip->legacy.select_chip = ndfc_select_chip;
145
+ chip->legacy.chip_delay = 50;
158146 chip->controller = &ndfc->ndfc_control;
159
- chip->read_buf = ndfc_read_buf;
160
- chip->write_buf = ndfc_write_buf;
147
+ chip->legacy.read_buf = ndfc_read_buf;
148
+ chip->legacy.write_buf = ndfc_write_buf;
161149 chip->ecc.correct = nand_correct_data;
162150 chip->ecc.hwctl = ndfc_enable_hwecc;
163151 chip->ecc.calculate = ndfc_calculate_ecc;
164
- chip->ecc.mode = NAND_ECC_HW;
152
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
165153 chip->ecc.size = 256;
166154 chip->ecc.bytes = 3;
167155 chip->ecc.strength = 1;
....@@ -174,8 +162,8 @@
174162 return -ENODEV;
175163 nand_set_flash_node(chip, flash_np);
176164
177
- mtd->name = kasprintf(GFP_KERNEL, "%s.%s", dev_name(&ndfc->ofdev->dev),
178
- flash_np->name);
165
+ mtd->name = kasprintf(GFP_KERNEL, "%s.%pOFn", dev_name(&ndfc->ofdev->dev),
166
+ flash_np);
179167 if (!mtd->name) {
180168 ret = -ENOMEM;
181169 goto err;
....@@ -256,9 +244,13 @@
256244 static int ndfc_remove(struct platform_device *ofdev)
257245 {
258246 struct ndfc_controller *ndfc = dev_get_drvdata(&ofdev->dev);
259
- struct mtd_info *mtd = nand_to_mtd(&ndfc->chip);
247
+ struct nand_chip *chip = &ndfc->chip;
248
+ struct mtd_info *mtd = nand_to_mtd(chip);
249
+ int ret;
260250
261
- nand_release(&ndfc->chip);
251
+ ret = mtd_device_unregister(mtd);
252
+ WARN_ON(ret);
253
+ nand_cleanup(chip);
262254 kfree(mtd->name);
263255
264256 return 0;