hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/mtd/nand/raw/mpc5121_nfc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright 2004-2008 Freescale Semiconductor, Inc.
34 * Copyright 2009 Semihalf.
....@@ -8,20 +9,6 @@
89 * Based on original driver from Freescale Semiconductor
910 * written by John Rigby <jrigby@freescale.com> on basis of mxc_nand.c.
1011 * Reworked and extended by Piotr Ziecik <kosmo@semihalf.com>.
11
- *
12
- * This program is free software; you can redistribute it and/or
13
- * modify it under the terms of the GNU General Public License
14
- * as published by the Free Software Foundation; either version 2
15
- * of the License, or (at your option) any later version.
16
- * This program is distributed in the hope that it will be useful,
17
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
- * GNU General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU General Public License
22
- * along with this program; if not, write to the Free Software
23
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24
- * MA 02110-1301, USA.
2512 */
2613
2714 #include <linux/module.h>
....@@ -117,6 +104,7 @@
117104 #define NFC_TIMEOUT (HZ / 10) /* 1/10 s */
118105
119106 struct mpc5121_nfc_prv {
107
+ struct nand_controller controller;
120108 struct nand_chip chip;
121109 int irq;
122110 void __iomem *regs;
....@@ -263,8 +251,10 @@
263251 }
264252
265253 /* Control chip select signals */
266
-static void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
254
+static void mpc5121_nfc_select_chip(struct nand_chip *nand, int chip)
267255 {
256
+ struct mtd_info *mtd = nand_to_mtd(nand);
257
+
268258 if (chip < 0) {
269259 nfc_clear(mtd, NFC_CONFIG1, NFC_CE);
270260 return;
....@@ -299,9 +289,8 @@
299289 }
300290
301291 /* Control chips select signal on ADS5121 board */
302
-static void ads5121_select_chip(struct mtd_info *mtd, int chip)
292
+static void ads5121_select_chip(struct nand_chip *nand, int chip)
303293 {
304
- struct nand_chip *nand = mtd_to_nand(mtd);
305294 struct mpc5121_nfc_prv *prv = nand_get_controller_data(nand);
306295 u8 v;
307296
....@@ -309,16 +298,16 @@
309298 v |= 0x0F;
310299
311300 if (chip >= 0) {
312
- mpc5121_nfc_select_chip(mtd, 0);
301
+ mpc5121_nfc_select_chip(nand, 0);
313302 v &= ~(1 << chip);
314303 } else
315
- mpc5121_nfc_select_chip(mtd, -1);
304
+ mpc5121_nfc_select_chip(nand, -1);
316305
317306 out_8(prv->csreg, v);
318307 }
319308
320309 /* Read NAND Ready/Busy signal */
321
-static int mpc5121_nfc_dev_ready(struct mtd_info *mtd)
310
+static int mpc5121_nfc_dev_ready(struct nand_chip *nand)
322311 {
323312 /*
324313 * NFC handles ready/busy signal internally. Therefore, this function
....@@ -328,10 +317,10 @@
328317 }
329318
330319 /* Write command to NAND flash */
331
-static void mpc5121_nfc_command(struct mtd_info *mtd, unsigned command,
332
- int column, int page)
320
+static void mpc5121_nfc_command(struct nand_chip *chip, unsigned command,
321
+ int column, int page)
333322 {
334
- struct nand_chip *chip = mtd_to_nand(mtd);
323
+ struct mtd_info *mtd = nand_to_mtd(chip);
335324 struct mpc5121_nfc_prv *prv = nand_get_controller_data(chip);
336325
337326 prv->column = (column >= 0) ? column : 0;
....@@ -362,7 +351,7 @@
362351 break;
363352
364353 case NAND_CMD_SEQIN:
365
- mpc5121_nfc_command(mtd, NAND_CMD_READ0, column, page);
354
+ mpc5121_nfc_command(chip, NAND_CMD_READ0, column, page);
366355 column = 0;
367356 break;
368357
....@@ -449,7 +438,7 @@
449438 buffer += blksize;
450439 offset += blksize;
451440 size -= blksize;
452
- };
441
+ }
453442 }
454443
455444 /* Copy data from/to NFC main and spare buffers */
....@@ -493,34 +482,24 @@
493482 }
494483
495484 /* Read data from NFC buffers */
496
-static void mpc5121_nfc_read_buf(struct mtd_info *mtd, u_char *buf, int len)
485
+static void mpc5121_nfc_read_buf(struct nand_chip *chip, u_char *buf, int len)
497486 {
498
- mpc5121_nfc_buf_copy(mtd, buf, len, 0);
487
+ mpc5121_nfc_buf_copy(nand_to_mtd(chip), buf, len, 0);
499488 }
500489
501490 /* Write data to NFC buffers */
502
-static void mpc5121_nfc_write_buf(struct mtd_info *mtd,
503
- const u_char *buf, int len)
491
+static void mpc5121_nfc_write_buf(struct nand_chip *chip, const u_char *buf,
492
+ int len)
504493 {
505
- mpc5121_nfc_buf_copy(mtd, (u_char *)buf, len, 1);
494
+ mpc5121_nfc_buf_copy(nand_to_mtd(chip), (u_char *)buf, len, 1);
506495 }
507496
508497 /* Read byte from NFC buffers */
509
-static u8 mpc5121_nfc_read_byte(struct mtd_info *mtd)
498
+static u8 mpc5121_nfc_read_byte(struct nand_chip *chip)
510499 {
511500 u8 tmp;
512501
513
- mpc5121_nfc_read_buf(mtd, &tmp, sizeof(tmp));
514
-
515
- return tmp;
516
-}
517
-
518
-/* Read word from NFC buffers */
519
-static u16 mpc5121_nfc_read_word(struct mtd_info *mtd)
520
-{
521
- u16 tmp;
522
-
523
- mpc5121_nfc_read_buf(mtd, (u_char *)&tmp, sizeof(tmp));
502
+ mpc5121_nfc_read_buf(chip, &tmp, sizeof(tmp));
524503
525504 return tmp;
526505 }
....@@ -623,6 +602,19 @@
623602 iounmap(prv->csreg);
624603 }
625604
605
+static int mpc5121_nfc_attach_chip(struct nand_chip *chip)
606
+{
607
+ if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT &&
608
+ chip->ecc.algo == NAND_ECC_ALGO_UNKNOWN)
609
+ chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
610
+
611
+ return 0;
612
+}
613
+
614
+static const struct nand_controller_ops mpc5121_nfc_ops = {
615
+ .attach_chip = mpc5121_nfc_attach_chip,
616
+};
617
+
626618 static int mpc5121_nfc_probe(struct platform_device *op)
627619 {
628620 struct device_node *dn = op->dev.of_node;
....@@ -654,6 +646,10 @@
654646
655647 chip = &prv->chip;
656648 mtd = nand_to_mtd(chip);
649
+
650
+ nand_controller_init(&prv->controller);
651
+ prv->controller.ops = &mpc5121_nfc_ops;
652
+ chip->controller = &prv->controller;
657653
658654 mtd->dev.parent = dev;
659655 nand_set_controller_data(chip, prv);
....@@ -700,18 +696,15 @@
700696 }
701697
702698 mtd->name = "MPC5121 NAND";
703
- chip->dev_ready = mpc5121_nfc_dev_ready;
704
- chip->cmdfunc = mpc5121_nfc_command;
705
- chip->read_byte = mpc5121_nfc_read_byte;
706
- chip->read_word = mpc5121_nfc_read_word;
707
- chip->read_buf = mpc5121_nfc_read_buf;
708
- chip->write_buf = mpc5121_nfc_write_buf;
709
- chip->select_chip = mpc5121_nfc_select_chip;
710
- chip->set_features = nand_get_set_features_notsupp;
711
- chip->get_features = nand_get_set_features_notsupp;
699
+ chip->legacy.dev_ready = mpc5121_nfc_dev_ready;
700
+ chip->legacy.cmdfunc = mpc5121_nfc_command;
701
+ chip->legacy.read_byte = mpc5121_nfc_read_byte;
702
+ chip->legacy.read_buf = mpc5121_nfc_read_buf;
703
+ chip->legacy.write_buf = mpc5121_nfc_write_buf;
704
+ chip->legacy.select_chip = mpc5121_nfc_select_chip;
705
+ chip->legacy.set_features = nand_get_set_features_notsupp;
706
+ chip->legacy.get_features = nand_get_set_features_notsupp;
712707 chip->bbt_options = NAND_BBT_USE_FLASH;
713
- chip->ecc.mode = NAND_ECC_SOFT;
714
- chip->ecc.algo = NAND_ECC_HAMMING;
715708
716709 /* Support external chip-select logic on ADS5121 board */
717710 if (of_machine_is_compatible("fsl,mpc5121ads")) {
....@@ -721,7 +714,7 @@
721714 return retval;
722715 }
723716
724
- chip->select_chip = ads5121_select_chip;
717
+ chip->legacy.select_chip = ads5121_select_chip;
725718 }
726719
727720 /* Enable NFC clock */
....@@ -777,6 +770,13 @@
777770 goto error;
778771 }
779772
773
+ /*
774
+ * This driver assumes that the default ECC engine should be TYPE_SOFT.
775
+ * Set ->engine_type before registering the NAND devices in order to
776
+ * provide a driver specific default value.
777
+ */
778
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
779
+
780780 /* Detect NAND chips */
781781 retval = nand_scan(chip, be32_to_cpup(chips_no));
782782 if (retval) {
....@@ -827,8 +827,11 @@
827827 {
828828 struct device *dev = &op->dev;
829829 struct mtd_info *mtd = dev_get_drvdata(dev);
830
+ int ret;
830831
831
- nand_release(mtd_to_nand(mtd));
832
+ ret = mtd_device_unregister(mtd);
833
+ WARN_ON(ret);
834
+ nand_cleanup(mtd_to_nand(mtd));
832835 mpc5121_nfc_free(dev, mtd);
833836
834837 return 0;