Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: rawnand: r852: Move the ECC initialization to ->attach_chip()

The probe function is only supposed to initialize the controller
hardware but not the ECC engine. Indeed, we don't know anything about
the NAND chip(s) at this stage. Let's move the logic initializing the
ECC engine, even pretty simple, to the ->attach_chip() hook which gets
called during nand_scan() routine, after the NAND chip discovery. As
the previously mentioned logic is supposed to parse the DT for us, it
is likely that the chip->ecc.* entries be overwritten. So let's avoid
this by moving these lines to ->attach_chip().

Fixes: d7157ff49a5b ("mtd: rawnand: Use the ECC framework user input parsing bits")
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Maxim Levitsky <maximlevitsky@gmail.com>
Link: https://lore.kernel.org/linux-mtd/20201113123424.32233-18-miquel.raynal@bootlin.com

+28 -13
+27 -13
drivers/mtd/nand/raw/r852.c
··· 817 817 return ret; 818 818 } 819 819 820 + static int r852_attach_chip(struct nand_chip *chip) 821 + { 822 + if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) 823 + return 0; 824 + 825 + chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED; 826 + chip->ecc.size = R852_DMA_LEN; 827 + chip->ecc.bytes = SM_OOB_SIZE; 828 + chip->ecc.strength = 2; 829 + chip->ecc.hwctl = r852_ecc_hwctl; 830 + chip->ecc.calculate = r852_ecc_calculate; 831 + chip->ecc.correct = r852_ecc_correct; 832 + 833 + /* TODO: hack */ 834 + chip->ecc.read_oob = r852_read_oob; 835 + 836 + return 0; 837 + } 838 + 839 + static const struct nand_controller_ops r852_ops = { 840 + .attach_chip = r852_attach_chip, 841 + }; 842 + 820 843 static int r852_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) 821 844 { 822 845 int error; ··· 881 858 chip->legacy.read_buf = r852_read_buf; 882 859 chip->legacy.write_buf = r852_write_buf; 883 860 884 - /* ecc */ 885 - chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; 886 - chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED; 887 - chip->ecc.size = R852_DMA_LEN; 888 - chip->ecc.bytes = SM_OOB_SIZE; 889 - chip->ecc.strength = 2; 890 - chip->ecc.hwctl = r852_ecc_hwctl; 891 - chip->ecc.calculate = r852_ecc_calculate; 892 - chip->ecc.correct = r852_ecc_correct; 893 - 894 - /* TODO: hack */ 895 - chip->ecc.read_oob = r852_read_oob; 896 - 897 861 /* init our device structure */ 898 862 dev = kzalloc(sizeof(struct r852_device), GFP_KERNEL); 899 863 ··· 891 881 dev->chip = chip; 892 882 dev->pci_dev = pci_dev; 893 883 pci_set_drvdata(pci_dev, dev); 884 + 885 + nand_controller_init(&dev->controller); 886 + dev->controller.ops = &r852_ops; 887 + chip->controller = &dev->controller; 894 888 895 889 dev->bounce_buffer = dma_alloc_coherent(&pci_dev->dev, R852_DMA_LEN, 896 890 &dev->phys_bounce_buffer, GFP_KERNEL);
+1
drivers/mtd/nand/raw/r852.h
··· 104 104 #define DMA_MEMORY 1 105 105 106 106 struct r852_device { 107 + struct nand_controller controller; 107 108 void __iomem *mmio; /* mmio */ 108 109 struct nand_chip *chip; /* nand chip backpointer */ 109 110 struct pci_dev *pci_dev; /* pci backpointer */