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

Merge tag 'mtd/for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux

Pull MTD updates from Miquel Raynal:
"MTD changes:

- parsers: ofpart: add workaround for #size-cells 0

- dt-bindings: partitions: Fix partition node name pattern

- dataflash: remove duplicate SPI ID table

Raw NAND core changes:

- Check the data only read pattern only once

- Prepare the late addition of supported operation checks

- Support for sequential cache reads

- Fix nand_chip kdoc

Raw NAND driver changes:

- Fsl_elbc: Propagate HW ECC settings to HW

- Marvell: Add missing layouts

- Pasemi: Don't use static data to track per-device state

- Sunxi:
- Fix the size of the last OOB region
- Remove an unnecessary check
- Remove an unnecessary check
- Clean up chips after failed init
- Precompute the ECC_CTL register value
- Embed sunxi_nand_hw_ecc by value
- Update OOB layout to match hardware

- tmio_nand: Remove driver

- vf610_nfc: Use regular comments for functions

SPI-NAND driver changes:

- Add support for AllianceMemory AS5F34G04SND

- Macronix: use scratch buffer for DMA operation

NAND ECC changes:

- Mediatek:
- Add ECC support fot MT7986 IC
- Add compatible for MT7986
- dt-bindings: Split ECC engine with rawnand controller

SPI NOR changes:

- Misc core fixes

SPI NOR driver changes:

- Spansion: Minor fixes"

* tag 'mtd/for-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (33 commits)
mtd: parsers: ofpart: add workaround for #size-cells 0
mtd: rawnand: sunxi: Precompute the ECC_CTL register value
mtd: rawnand: sunxi: Embed sunxi_nand_hw_ecc by value
mtd: rawnand: sunxi: Update OOB layout to match hardware
mtd: spi-nor: Sort headers alphabetically
mtd: spi-nor: Fix shift-out-of-bounds in spi_nor_set_erase_type
mtd: nand: ecc-mtk: Add ECC support fot MT7986 IC
dt-bindings: mtd: mediatek,nand-ecc-engine: Add compatible for MT7986
dt-bindings: mtd: Split ECC engine with rawnand controller
mtd: rawnand: fsl_elbc: Propagate HW ECC settings to HW
mtd: spinand: Add support for AllianceMemory AS5F34G04SND
dt-bindings: mtd: partitions: Fix partition node name pattern
mtd: spi-nor: Create macros to define chip IDs and geometries
mtd: spi-nor: spansion: Make CFRx reg fields generic
mtd: spi-nor: spansion: Consider reserved bits in CFR5 register
mtd: spi-nor: core: fix implicit declaration warning
mtd: spinand: macronix: use scratch buffer for DMA operation
mtd: rawnand: Fix nand_chip kdoc
mtd: rawnand: vf610_nfc: use regular comments for functions
mtd: rawnand: Support for sequential cache reads
...

+783 -936
+155
Documentation/devicetree/bindings/mtd/mediatek,mtk-nfc.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/mediatek,mtk-nfc.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: MediaTek(MTK) SoCs raw NAND FLASH controller (NFC) 8 + 9 + maintainers: 10 + - Xiangsheng Hou <xiangsheng.hou@mediatek.com> 11 + 12 + properties: 13 + compatible: 14 + enum: 15 + - mediatek,mt2701-nfc 16 + - mediatek,mt2712-nfc 17 + - mediatek,mt7622-nfc 18 + 19 + reg: 20 + items: 21 + - description: Base physical address and size of NFI. 22 + 23 + interrupts: 24 + items: 25 + - description: NFI interrupt 26 + 27 + clocks: 28 + items: 29 + - description: clock used for the controller 30 + - description: clock used for the pad 31 + 32 + clock-names: 33 + items: 34 + - const: nfi_clk 35 + - const: pad_clk 36 + 37 + ecc-engine: 38 + description: device-tree node of the required ECC engine. 39 + $ref: /schemas/types.yaml#/definitions/phandle 40 + 41 + patternProperties: 42 + "^nand@[a-f0-9]$": 43 + $ref: nand-chip.yaml# 44 + unevaluatedProperties: false 45 + properties: 46 + reg: 47 + maximum: 1 48 + nand-on-flash-bbt: true 49 + nand-ecc-mode: 50 + const: hw 51 + 52 + allOf: 53 + - $ref: nand-controller.yaml# 54 + 55 + - if: 56 + properties: 57 + compatible: 58 + contains: 59 + const: mediatek,mt2701-nfc 60 + then: 61 + patternProperties: 62 + "^nand@[a-f0-9]$": 63 + properties: 64 + nand-ecc-step-size: 65 + enum: [ 512, 1024 ] 66 + nand-ecc-strength: 67 + enum: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 68 + 40, 44, 48, 52, 56, 60] 69 + 70 + - if: 71 + properties: 72 + compatible: 73 + contains: 74 + const: mediatek,mt2712-nfc 75 + then: 76 + patternProperties: 77 + "^nand@[a-f0-9]$": 78 + properties: 79 + nand-ecc-step-size: 80 + enum: [ 512, 1024 ] 81 + nand-ecc-strength: 82 + enum: [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 83 + 40, 44, 48, 52, 56, 60, 68, 72, 80] 84 + 85 + - if: 86 + properties: 87 + compatible: 88 + contains: 89 + const: mediatek,mt7622-nfc 90 + then: 91 + patternProperties: 92 + "^nand@[a-f0-9]$": 93 + properties: 94 + nand-ecc-step-size: 95 + const: 512 96 + nand-ecc-strength: 97 + enum: [4, 6, 8, 10, 12] 98 + 99 + required: 100 + - compatible 101 + - reg 102 + - interrupts 103 + - clocks 104 + - clock-names 105 + - ecc-engine 106 + 107 + unevaluatedProperties: false 108 + 109 + examples: 110 + - | 111 + #include <dt-bindings/clock/mt2701-clk.h> 112 + #include <dt-bindings/interrupt-controller/arm-gic.h> 113 + #include <dt-bindings/interrupt-controller/irq.h> 114 + 115 + soc { 116 + #address-cells = <2>; 117 + #size-cells = <2>; 118 + 119 + nand-controller@1100d000 { 120 + compatible = "mediatek,mt2701-nfc"; 121 + reg = <0 0x1100d000 0 0x1000>; 122 + interrupts = <GIC_SPI 56 IRQ_TYPE_LEVEL_LOW>; 123 + clocks = <&pericfg CLK_PERI_NFI>, 124 + <&pericfg CLK_PERI_NFI_PAD>; 125 + clock-names = "nfi_clk", "pad_clk"; 126 + ecc-engine = <&bch>; 127 + #address-cells = <1>; 128 + #size-cells = <0>; 129 + 130 + nand@0 { 131 + reg = <0>; 132 + 133 + nand-on-flash-bbt; 134 + nand-ecc-mode = "hw"; 135 + nand-ecc-step-size = <1024>; 136 + nand-ecc-strength = <24>; 137 + 138 + partitions { 139 + compatible = "fixed-partitions"; 140 + #address-cells = <1>; 141 + #size-cells = <1>; 142 + 143 + preloader@0 { 144 + label = "pl"; 145 + read-only; 146 + reg = <0x0 0x400000>; 147 + }; 148 + android@400000 { 149 + label = "android"; 150 + reg = <0x400000 0x12c00000>; 151 + }; 152 + }; 153 + }; 154 + }; 155 + };
+63
Documentation/devicetree/bindings/mtd/mediatek,nand-ecc-engine.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/mediatek,nand-ecc-engine.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: MediaTek(MTK) SoCs NAND ECC engine 8 + 9 + maintainers: 10 + - Xiangsheng Hou <xiangsheng.hou@mediatek.com> 11 + 12 + description: | 13 + MTK NAND ECC engine can cowork with MTK raw NAND and SPI NAND controller. 14 + 15 + properties: 16 + compatible: 17 + enum: 18 + - mediatek,mt2701-ecc 19 + - mediatek,mt2712-ecc 20 + - mediatek,mt7622-ecc 21 + - mediatek,mt7986-ecc 22 + 23 + reg: 24 + items: 25 + - description: Base physical address and size of ECC. 26 + 27 + interrupts: 28 + items: 29 + - description: ECC interrupt 30 + 31 + clocks: 32 + maxItems: 1 33 + 34 + clock-names: 35 + const: nfiecc_clk 36 + 37 + required: 38 + - compatible 39 + - reg 40 + - interrupts 41 + - clocks 42 + - clock-names 43 + 44 + additionalProperties: false 45 + 46 + examples: 47 + - | 48 + #include <dt-bindings/clock/mt2701-clk.h> 49 + #include <dt-bindings/interrupt-controller/arm-gic.h> 50 + #include <dt-bindings/interrupt-controller/irq.h> 51 + 52 + soc { 53 + #address-cells = <2>; 54 + #size-cells = <2>; 55 + 56 + bch: ecc@1100e000 { 57 + compatible = "mediatek,mt2701-ecc"; 58 + reg = <0 0x1100e000 0 0x1000>; 59 + interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_LOW>; 60 + clocks = <&pericfg CLK_PERI_NFI_ECC>; 61 + clock-names = "nfiecc_clk"; 62 + }; 63 + };
-176
Documentation/devicetree/bindings/mtd/mtk-nand.txt
··· 1 - MTK SoCs NAND FLASH controller (NFC) DT binding 2 - 3 - This file documents the device tree bindings for MTK SoCs NAND controllers. 4 - The functional split of the controller requires two drivers to operate: 5 - the nand controller interface driver and the ECC engine driver. 6 - 7 - The hardware description for both devices must be captured as device 8 - tree nodes. 9 - 10 - 1) NFC NAND Controller Interface (NFI): 11 - ======================================= 12 - 13 - The first part of NFC is NAND Controller Interface (NFI) HW. 14 - Required NFI properties: 15 - - compatible: Should be one of 16 - "mediatek,mt2701-nfc", 17 - "mediatek,mt2712-nfc", 18 - "mediatek,mt7622-nfc". 19 - - reg: Base physical address and size of NFI. 20 - - interrupts: Interrupts of NFI. 21 - - clocks: NFI required clocks. 22 - - clock-names: NFI clocks internal name. 23 - - ecc-engine: Required ECC Engine node. 24 - - #address-cells: NAND chip index, should be 1. 25 - - #size-cells: Should be 0. 26 - 27 - Example: 28 - 29 - nandc: nfi@1100d000 { 30 - compatible = "mediatek,mt2701-nfc"; 31 - reg = <0 0x1100d000 0 0x1000>; 32 - interrupts = <GIC_SPI 56 IRQ_TYPE_LEVEL_LOW>; 33 - clocks = <&pericfg CLK_PERI_NFI>, 34 - <&pericfg CLK_PERI_NFI_PAD>; 35 - clock-names = "nfi_clk", "pad_clk"; 36 - ecc-engine = <&bch>; 37 - #address-cells = <1>; 38 - #size-cells = <0>; 39 - }; 40 - 41 - Platform related properties, should be set in {platform_name}.dts: 42 - - children nodes: NAND chips. 43 - 44 - Children nodes properties: 45 - - reg: Chip Select Signal, default 0. 46 - Set as reg = <0>, <1> when need 2 CS. 47 - Optional: 48 - - nand-on-flash-bbt: Store BBT on NAND Flash. 49 - - nand-ecc-mode: the NAND ecc mode (check driver for supported modes) 50 - - nand-ecc-step-size: Number of data bytes covered by a single ECC step. 51 - valid values: 52 - 512 and 1024 on mt2701 and mt2712. 53 - 512 only on mt7622. 54 - 1024 is recommended for large page NANDs. 55 - - nand-ecc-strength: Number of bits to correct per ECC step. 56 - The valid values that each controller supports: 57 - mt2701: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 58 - 32, 36, 40, 44, 48, 52, 56, 60. 59 - mt2712: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 60 - 32, 36, 40, 44, 48, 52, 56, 60, 68, 72, 80. 61 - mt7622: 4, 6, 8, 10, 12, 14, 16. 62 - The strength should be calculated as follows: 63 - E = (S - F) * 8 / B 64 - S = O / (P / Q) 65 - E : nand-ecc-strength. 66 - S : spare size per sector. 67 - F : FDM size, should be in the range [1,8]. 68 - It is used to store free oob data. 69 - O : oob size. 70 - P : page size. 71 - Q : nand-ecc-step-size. 72 - B : number of parity bits needed to correct 73 - 1 bitflip. 74 - According to MTK NAND controller design, 75 - this number depends on max ecc step size 76 - that MTK NAND controller supports. 77 - If max ecc step size supported is 1024, 78 - then it should be always 14. And if max 79 - ecc step size is 512, then it should be 80 - always 13. 81 - If the result does not match any one of the listed 82 - choices above, please select the smaller valid value from 83 - the list. 84 - (otherwise the driver will do the adjustment at runtime) 85 - - pinctrl-names: Default NAND pin GPIO setting name. 86 - - pinctrl-0: GPIO setting node. 87 - 88 - Example: 89 - &pio { 90 - nand_pins_default: nanddefault { 91 - pins_dat { 92 - pinmux = <MT2701_PIN_111_MSDC0_DAT7__FUNC_NLD7>, 93 - <MT2701_PIN_112_MSDC0_DAT6__FUNC_NLD6>, 94 - <MT2701_PIN_114_MSDC0_DAT4__FUNC_NLD4>, 95 - <MT2701_PIN_118_MSDC0_DAT3__FUNC_NLD3>, 96 - <MT2701_PIN_121_MSDC0_DAT0__FUNC_NLD0>, 97 - <MT2701_PIN_120_MSDC0_DAT1__FUNC_NLD1>, 98 - <MT2701_PIN_113_MSDC0_DAT5__FUNC_NLD5>, 99 - <MT2701_PIN_115_MSDC0_RSTB__FUNC_NLD8>, 100 - <MT2701_PIN_119_MSDC0_DAT2__FUNC_NLD2>; 101 - input-enable; 102 - drive-strength = <MTK_DRIVE_8mA>; 103 - bias-pull-up; 104 - }; 105 - 106 - pins_we { 107 - pinmux = <MT2701_PIN_117_MSDC0_CLK__FUNC_NWEB>; 108 - drive-strength = <MTK_DRIVE_8mA>; 109 - bias-pull-up = <MTK_PUPD_SET_R1R0_10>; 110 - }; 111 - 112 - pins_ale { 113 - pinmux = <MT2701_PIN_116_MSDC0_CMD__FUNC_NALE>; 114 - drive-strength = <MTK_DRIVE_8mA>; 115 - bias-pull-down = <MTK_PUPD_SET_R1R0_10>; 116 - }; 117 - }; 118 - }; 119 - 120 - &nandc { 121 - status = "okay"; 122 - pinctrl-names = "default"; 123 - pinctrl-0 = <&nand_pins_default>; 124 - nand@0 { 125 - reg = <0>; 126 - nand-on-flash-bbt; 127 - nand-ecc-mode = "hw"; 128 - nand-ecc-strength = <24>; 129 - nand-ecc-step-size = <1024>; 130 - }; 131 - }; 132 - 133 - NAND chip optional subnodes: 134 - - Partitions, see Documentation/devicetree/bindings/mtd/mtd.yaml 135 - 136 - Example: 137 - nand@0 { 138 - partitions { 139 - compatible = "fixed-partitions"; 140 - #address-cells = <1>; 141 - #size-cells = <1>; 142 - 143 - preloader@0 { 144 - label = "pl"; 145 - read-only; 146 - reg = <0x00000000 0x00400000>; 147 - }; 148 - android@00400000 { 149 - label = "android"; 150 - reg = <0x00400000 0x12c00000>; 151 - }; 152 - }; 153 - }; 154 - 155 - 2) ECC Engine: 156 - ============== 157 - 158 - Required BCH properties: 159 - - compatible: Should be one of 160 - "mediatek,mt2701-ecc", 161 - "mediatek,mt2712-ecc", 162 - "mediatek,mt7622-ecc". 163 - - reg: Base physical address and size of ECC. 164 - - interrupts: Interrupts of ECC. 165 - - clocks: ECC required clocks. 166 - - clock-names: ECC clocks internal name. 167 - 168 - Example: 169 - 170 - bch: ecc@1100e000 { 171 - compatible = "mediatek,mt2701-ecc"; 172 - reg = <0 0x1100e000 0 0x1000>; 173 - interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_LOW>; 174 - clocks = <&pericfg CLK_PERI_NFI_ECC>; 175 - clock-names = "nfiecc_clk"; 176 - };
+1 -1
Documentation/devicetree/bindings/mtd/partitions/partitions.yaml
··· 32 32 enum: [1, 2] 33 33 34 34 patternProperties: 35 - "partition(-.+|@[0-9a-f]+)": 35 + "^partition(-.+|@[0-9a-f]+)$": 36 36 $ref: partition.yaml 37 37 38 38 required:
+1 -1
MAINTAINERS
··· 13139 13139 MEDIATEK NAND CONTROLLER DRIVER 13140 13140 L: linux-mtd@lists.infradead.org 13141 13141 S: Orphan 13142 - F: Documentation/devicetree/bindings/mtd/mtk-nand.txt 13142 + F: Documentation/devicetree/bindings/mtd/mediatek,mtk-nfc.yaml 13143 13143 F: drivers/mtd/nand/raw/mtk_* 13144 13144 13145 13145 MEDIATEK PMIC LED DRIVER
-9
drivers/mtd/devices/mtd_dataflash.c
··· 96 96 struct mtd_info mtd; 97 97 }; 98 98 99 - static const struct spi_device_id dataflash_dev_ids[] = { 100 - { "at45" }, 101 - { "dataflash" }, 102 - { }, 103 - }; 104 - MODULE_DEVICE_TABLE(spi, dataflash_dev_ids); 105 - 106 99 #ifdef CONFIG_OF 107 100 static const struct of_device_id dataflash_dt_ids[] = { 108 101 { .compatible = "atmel,at45", }, ··· 932 939 .name = "mtd_dataflash", 933 940 .of_match_table = of_match_ptr(dataflash_dt_ids), 934 941 }, 935 - .id_table = dataflash_dev_ids, 936 - 937 942 .probe = dataflash_probe, 938 943 .remove = dataflash_remove, 939 944 .id_table = dataflash_spi_ids,
+25 -3
drivers/mtd/nand/ecc-mtk.c
··· 40 40 #define ECC_IDLE_REG(op) ((op) == ECC_ENCODE ? ECC_ENCIDLE : ECC_DECIDLE) 41 41 #define ECC_CTL_REG(op) ((op) == ECC_ENCODE ? ECC_ENCCON : ECC_DECCON) 42 42 43 + #define ECC_ERRMASK_MT7622 GENMASK(4, 0) 44 + #define ECC_ERRMASK_MT2701 GENMASK(5, 0) 45 + #define ECC_ERRMASK_MT2712 GENMASK(6, 0) 46 + 43 47 struct mtk_ecc_caps { 44 48 u32 err_mask; 45 49 u32 err_shift; ··· 81 77 82 78 static const u8 ecc_strength_mt7622[] = { 83 79 4, 6, 8, 10, 12 80 + }; 81 + 82 + static const u8 ecc_strength_mt7986[] = { 83 + 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 84 84 }; 85 85 86 86 enum mtk_ecc_regs { ··· 459 451 EXPORT_SYMBOL(mtk_ecc_get_parity_bits); 460 452 461 453 static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = { 462 - .err_mask = 0x3f, 454 + .err_mask = ECC_ERRMASK_MT2701, 463 455 .err_shift = 8, 464 456 .ecc_strength = ecc_strength_mt2701, 465 457 .ecc_regs = mt2701_ecc_regs, ··· 470 462 }; 471 463 472 464 static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = { 473 - .err_mask = 0x7f, 465 + .err_mask = ECC_ERRMASK_MT2712, 474 466 .err_shift = 8, 475 467 .ecc_strength = ecc_strength_mt2712, 476 468 .ecc_regs = mt2712_ecc_regs, ··· 481 473 }; 482 474 483 475 static const struct mtk_ecc_caps mtk_ecc_caps_mt7622 = { 484 - .err_mask = 0x1f, 476 + .err_mask = ECC_ERRMASK_MT7622, 485 477 .err_shift = 5, 486 478 .ecc_strength = ecc_strength_mt7622, 487 479 .ecc_regs = mt7622_ecc_regs, ··· 489 481 .ecc_mode_shift = 4, 490 482 .parity_bits = 13, 491 483 .pg_irq_sel = 0, 484 + }; 485 + 486 + static const struct mtk_ecc_caps mtk_ecc_caps_mt7986 = { 487 + .err_mask = ECC_ERRMASK_MT7622, 488 + .err_shift = 8, 489 + .ecc_strength = ecc_strength_mt7986, 490 + .ecc_regs = mt2712_ecc_regs, 491 + .num_ecc_strength = 11, 492 + .ecc_mode_shift = 5, 493 + .parity_bits = 14, 494 + .pg_irq_sel = 1, 492 495 }; 493 496 494 497 static const struct of_device_id mtk_ecc_dt_match[] = { ··· 512 493 }, { 513 494 .compatible = "mediatek,mt7622-ecc", 514 495 .data = &mtk_ecc_caps_mt7622, 496 + }, { 497 + .compatible = "mediatek,mt7986-ecc", 498 + .data = &mtk_ecc_caps_mt7986, 515 499 }, 516 500 {}, 517 501 };
-7
drivers/mtd/nand/raw/Kconfig
··· 193 193 Enables support for NAND Flash interface on PA Semi PWRficient 194 194 based boards 195 195 196 - config MTD_NAND_TMIO 197 - tristate "Toshiba Mobile IO NAND controller" 198 - depends on MFD_TMIO 199 - help 200 - Support for NAND flash connected to a Toshiba Mobile IO 201 - Controller in some PDAs, including the Sharp SL6000x. 202 - 203 196 source "drivers/mtd/nand/raw/brcmnand/Kconfig" 204 197 205 198 config MTD_NAND_BCM47XXNFLASH
-1
drivers/mtd/nand/raw/Makefile
··· 23 23 obj-$(CONFIG_MTD_NAND_OMAP2) += omap2_nand.o 24 24 obj-$(CONFIG_MTD_NAND_OMAP_BCH_BUILD) += omap_elm.o 25 25 obj-$(CONFIG_MTD_NAND_MARVELL) += marvell_nand.o 26 - obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o 27 26 obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 28 27 obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 29 28 obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
+8
drivers/mtd/nand/raw/fsl_elbc_nand.c
··· 725 725 struct fsl_lbc_ctrl *ctrl = priv->ctrl; 726 726 struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 727 727 unsigned int al; 728 + u32 br; 728 729 729 730 /* 730 731 * if ECC was not chosen in DT, decide whether to use HW or SW ECC from ··· 764 763 default: 765 764 return -EINVAL; 766 765 } 766 + 767 + /* enable/disable HW ECC checking and generating based on if HW ECC was chosen */ 768 + br = in_be32(&lbc->bank[priv->bank].br) & ~BR_DECC; 769 + if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) 770 + out_be32(&lbc->bank[priv->bank].br, br | BR_DECC_CHK_GEN); 771 + else 772 + out_be32(&lbc->bank[priv->bank].br, br | BR_DECC_OFF); 767 773 768 774 /* calculate FMR Address Length field */ 769 775 al = 0;
+7
drivers/mtd/nand/raw/marvell_nand.c
··· 288 288 MARVELL_LAYOUT( 2048, 512, 1, 1, 1, 2048, 40, 24, 0, 0, 0), 289 289 MARVELL_LAYOUT( 2048, 512, 4, 1, 1, 2048, 32, 30, 0, 0, 0), 290 290 MARVELL_LAYOUT( 2048, 512, 8, 2, 1, 1024, 0, 30,1024,32, 30), 291 + MARVELL_LAYOUT( 2048, 512, 8, 2, 1, 1024, 0, 30,1024,64, 30), 292 + MARVELL_LAYOUT( 2048, 512, 12, 3, 2, 704, 0, 30,640, 0, 30), 293 + MARVELL_LAYOUT( 2048, 512, 16, 5, 4, 512, 0, 30, 0, 32, 30), 291 294 MARVELL_LAYOUT( 4096, 512, 4, 2, 2, 2048, 32, 30, 0, 0, 0), 292 295 MARVELL_LAYOUT( 4096, 512, 8, 5, 4, 1024, 0, 30, 0, 64, 30), 296 + MARVELL_LAYOUT( 4096, 512, 12, 6, 5, 704, 0, 30,576, 32, 30), 297 + MARVELL_LAYOUT( 4096, 512, 16, 9, 8, 512, 0, 30, 0, 32, 30), 293 298 MARVELL_LAYOUT( 8192, 512, 4, 4, 4, 2048, 0, 30, 0, 0, 0), 294 299 MARVELL_LAYOUT( 8192, 512, 8, 9, 8, 1024, 0, 30, 0, 160, 30), 300 + MARVELL_LAYOUT( 8192, 512, 12, 12, 11, 704, 0, 30,448, 64, 30), 301 + MARVELL_LAYOUT( 8192, 512, 16, 17, 16, 512, 0, 30, 0, 32, 30), 295 302 }; 296 303 297 304 /**
+145 -4
drivers/mtd/nand/raw/nand_base.c
··· 1208 1208 return nand_exec_op(chip, &op); 1209 1209 } 1210 1210 1211 + static int nand_lp_exec_cont_read_page_op(struct nand_chip *chip, unsigned int page, 1212 + unsigned int offset_in_page, void *buf, 1213 + unsigned int len, bool check_only) 1214 + { 1215 + const struct nand_interface_config *conf = 1216 + nand_get_interface_config(chip); 1217 + u8 addrs[5]; 1218 + struct nand_op_instr start_instrs[] = { 1219 + NAND_OP_CMD(NAND_CMD_READ0, 0), 1220 + NAND_OP_ADDR(4, addrs, 0), 1221 + NAND_OP_CMD(NAND_CMD_READSTART, NAND_COMMON_TIMING_NS(conf, tWB_max)), 1222 + NAND_OP_WAIT_RDY(NAND_COMMON_TIMING_MS(conf, tR_max), 0), 1223 + NAND_OP_CMD(NAND_CMD_READCACHESEQ, NAND_COMMON_TIMING_NS(conf, tWB_max)), 1224 + NAND_OP_WAIT_RDY(NAND_COMMON_TIMING_MS(conf, tR_max), 1225 + NAND_COMMON_TIMING_NS(conf, tRR_min)), 1226 + NAND_OP_DATA_IN(len, buf, 0), 1227 + }; 1228 + struct nand_op_instr cont_instrs[] = { 1229 + NAND_OP_CMD(page == chip->cont_read.last_page ? 1230 + NAND_CMD_READCACHEEND : NAND_CMD_READCACHESEQ, 1231 + NAND_COMMON_TIMING_NS(conf, tWB_max)), 1232 + NAND_OP_WAIT_RDY(NAND_COMMON_TIMING_MS(conf, tR_max), 1233 + NAND_COMMON_TIMING_NS(conf, tRR_min)), 1234 + NAND_OP_DATA_IN(len, buf, 0), 1235 + }; 1236 + struct nand_operation start_op = NAND_OPERATION(chip->cur_cs, start_instrs); 1237 + struct nand_operation cont_op = NAND_OPERATION(chip->cur_cs, cont_instrs); 1238 + int ret; 1239 + 1240 + if (!len) { 1241 + start_op.ninstrs--; 1242 + cont_op.ninstrs--; 1243 + } 1244 + 1245 + ret = nand_fill_column_cycles(chip, addrs, offset_in_page); 1246 + if (ret < 0) 1247 + return ret; 1248 + 1249 + addrs[2] = page; 1250 + addrs[3] = page >> 8; 1251 + 1252 + if (chip->options & NAND_ROW_ADDR_3) { 1253 + addrs[4] = page >> 16; 1254 + start_instrs[1].ctx.addr.naddrs++; 1255 + } 1256 + 1257 + /* Check if cache reads are supported */ 1258 + if (check_only) { 1259 + if (nand_check_op(chip, &start_op) || nand_check_op(chip, &cont_op)) 1260 + return -EOPNOTSUPP; 1261 + 1262 + return 0; 1263 + } 1264 + 1265 + if (page == chip->cont_read.first_page) 1266 + return nand_exec_op(chip, &start_op); 1267 + else 1268 + return nand_exec_op(chip, &cont_op); 1269 + } 1270 + 1271 + static bool rawnand_cont_read_ongoing(struct nand_chip *chip, unsigned int page) 1272 + { 1273 + return chip->cont_read.ongoing && 1274 + page >= chip->cont_read.first_page && 1275 + page <= chip->cont_read.last_page; 1276 + } 1277 + 1211 1278 /** 1212 1279 * nand_read_page_op - Do a READ PAGE operation 1213 1280 * @chip: The NAND chip ··· 1300 1233 return -EINVAL; 1301 1234 1302 1235 if (nand_has_exec_op(chip)) { 1303 - if (mtd->writesize > 512) 1304 - return nand_lp_exec_read_page_op(chip, page, 1305 - offset_in_page, buf, 1306 - len); 1236 + if (mtd->writesize > 512) { 1237 + if (rawnand_cont_read_ongoing(chip, page)) 1238 + return nand_lp_exec_cont_read_page_op(chip, page, 1239 + offset_in_page, 1240 + buf, len, false); 1241 + else 1242 + return nand_lp_exec_read_page_op(chip, page, 1243 + offset_in_page, buf, 1244 + len); 1245 + } 1307 1246 1308 1247 return nand_sp_exec_read_page_op(chip, page, offset_in_page, 1309 1248 buf, len); ··· 3426 3353 return NULL; 3427 3354 } 3428 3355 3356 + static void rawnand_enable_cont_reads(struct nand_chip *chip, unsigned int page, 3357 + u32 readlen, int col) 3358 + { 3359 + struct mtd_info *mtd = nand_to_mtd(chip); 3360 + 3361 + if (!chip->controller->supported_op.cont_read) 3362 + return; 3363 + 3364 + if ((col && col + readlen < (3 * mtd->writesize)) || 3365 + (!col && readlen < (2 * mtd->writesize))) { 3366 + chip->cont_read.ongoing = false; 3367 + return; 3368 + } 3369 + 3370 + chip->cont_read.ongoing = true; 3371 + chip->cont_read.first_page = page; 3372 + if (col) 3373 + chip->cont_read.first_page++; 3374 + chip->cont_read.last_page = page + ((readlen >> chip->page_shift) & chip->pagemask); 3375 + } 3376 + 3429 3377 /** 3430 3378 * nand_setup_read_retry - [INTERN] Set the READ RETRY mode 3431 3379 * @chip: NAND chip object ··· 3519 3425 buf = ops->datbuf; 3520 3426 oob = ops->oobbuf; 3521 3427 oob_required = oob ? 1 : 0; 3428 + 3429 + rawnand_enable_cont_reads(chip, page, readlen, col); 3522 3430 3523 3431 while (1) { 3524 3432 struct mtd_ecc_stats ecc_stats = mtd->ecc_stats; ··· 5087 4991 return manufacturer_desc ? manufacturer_desc->name : "Unknown"; 5088 4992 } 5089 4993 4994 + static void rawnand_check_data_only_read_support(struct nand_chip *chip) 4995 + { 4996 + /* Use an arbitrary size for the check */ 4997 + if (!nand_read_data_op(chip, NULL, SZ_512, true, true)) 4998 + chip->controller->supported_op.data_only_read = 1; 4999 + } 5000 + 5001 + static void rawnand_early_check_supported_ops(struct nand_chip *chip) 5002 + { 5003 + /* The supported_op fields should not be set by individual drivers */ 5004 + WARN_ON_ONCE(chip->controller->supported_op.data_only_read); 5005 + 5006 + if (!nand_has_exec_op(chip)) 5007 + return; 5008 + 5009 + rawnand_check_data_only_read_support(chip); 5010 + } 5011 + 5012 + static void rawnand_check_cont_read_support(struct nand_chip *chip) 5013 + { 5014 + struct mtd_info *mtd = nand_to_mtd(chip); 5015 + 5016 + if (chip->read_retries) 5017 + return; 5018 + 5019 + if (!nand_lp_exec_cont_read_page_op(chip, 0, 0, NULL, 5020 + mtd->writesize, true)) 5021 + chip->controller->supported_op.cont_read = 1; 5022 + } 5023 + 5024 + static void rawnand_late_check_supported_ops(struct nand_chip *chip) 5025 + { 5026 + /* The supported_op fields should not be set by individual drivers */ 5027 + WARN_ON_ONCE(chip->controller->supported_op.cont_read); 5028 + 5029 + if (!nand_has_exec_op(chip)) 5030 + return; 5031 + 5032 + rawnand_check_cont_read_support(chip); 5033 + } 5034 + 5090 5035 /* 5091 5036 * Get the flash and manufacturer id and lookup if the type is supported. 5092 5037 */ ··· 5159 5022 5160 5023 /* Select the device */ 5161 5024 nand_select_target(chip, 0); 5025 + 5026 + rawnand_early_check_supported_ops(chip); 5162 5027 5163 5028 /* Send the command for reading device ID */ 5164 5029 ret = nand_readid_op(chip, 0, id_data, 2); ··· 6463 6324 if (ret) 6464 6325 goto err_free_interface_config; 6465 6326 } 6327 + 6328 + rawnand_late_check_supported_ops(chip); 6466 6329 6467 6330 /* 6468 6331 * Look for secure regions in the NAND chip. These regions are supposed
+1 -2
drivers/mtd/nand/raw/nand_jedec.c
··· 46 46 if (!p) 47 47 return -ENOMEM; 48 48 49 - if (!nand_has_exec_op(chip) || 50 - !nand_read_data_op(chip, p, sizeof(*p), true, true)) 49 + if (!nand_has_exec_op(chip) || chip->controller->supported_op.data_only_read) 51 50 use_datain = true; 52 51 53 52 for (i = 0; i < JEDEC_PARAM_PAGES; i++) {
+1 -2
drivers/mtd/nand/raw/nand_onfi.c
··· 166 166 if (!pbuf) 167 167 return -ENOMEM; 168 168 169 - if (!nand_has_exec_op(chip) || 170 - !nand_read_data_op(chip, &pbuf[0], sizeof(*pbuf), true, true)) 169 + if (!nand_has_exec_op(chip) || chip->controller->supported_op.data_only_read) 171 170 use_datain = true; 172 171 173 172 for (i = 0; i < ONFI_PARAM_PAGES; i++) {
+35 -28
drivers/mtd/nand/raw/pasemi_nand.c
··· 26 26 #define CLE_PIN_CTL 15 27 27 #define ALE_PIN_CTL 14 28 28 29 - static unsigned int lpcctl; 30 - static struct mtd_info *pasemi_nand_mtd; 31 - static struct nand_controller controller; 29 + struct pasemi_ddata { 30 + struct nand_chip chip; 31 + unsigned int lpcctl; 32 + struct nand_controller controller; 33 + }; 34 + 32 35 static const char driver_name[] = "pasemi-nand"; 33 36 34 37 static void pasemi_read_buf(struct nand_chip *chip, u_char *buf, int len) ··· 58 55 static void pasemi_hwcontrol(struct nand_chip *chip, int cmd, 59 56 unsigned int ctrl) 60 57 { 58 + struct pasemi_ddata *ddata = container_of(chip, struct pasemi_ddata, chip); 59 + 61 60 if (cmd == NAND_CMD_NONE) 62 61 return; 63 62 ··· 70 65 71 66 /* Push out posted writes */ 72 67 eieio(); 73 - inl(lpcctl); 68 + inl(ddata->lpcctl); 74 69 } 75 70 76 71 static int pasemi_device_ready(struct nand_chip *chip) 77 72 { 78 - return !!(inl(lpcctl) & LBICTRL_LPCCTL_NR); 73 + struct pasemi_ddata *ddata = container_of(chip, struct pasemi_ddata, chip); 74 + 75 + return !!(inl(ddata->lpcctl) & LBICTRL_LPCCTL_NR); 79 76 } 80 77 81 78 static int pasemi_attach_chip(struct nand_chip *chip) ··· 100 93 struct device_node *np = dev->of_node; 101 94 struct resource res; 102 95 struct nand_chip *chip; 96 + struct nand_controller *controller; 103 97 int err = 0; 98 + struct pasemi_ddata *ddata; 99 + struct mtd_info *pasemi_nand_mtd; 104 100 105 101 err = of_address_to_resource(np, 0, &res); 106 102 107 103 if (err) 108 104 return -EINVAL; 109 105 110 - /* We only support one device at the moment */ 111 - if (pasemi_nand_mtd) 112 - return -ENODEV; 113 - 114 106 dev_dbg(dev, "pasemi_nand at %pR\n", &res); 115 107 116 108 /* Allocate memory for MTD device structure and private data */ 117 - chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL); 118 - if (!chip) { 109 + ddata = kzalloc(sizeof(*ddata), GFP_KERNEL); 110 + if (!ddata) { 119 111 err = -ENOMEM; 120 112 goto out; 121 113 } 114 + platform_set_drvdata(ofdev, ddata); 115 + chip = &ddata->chip; 116 + controller = &ddata->controller; 122 117 123 - controller.ops = &pasemi_ops; 124 - nand_controller_init(&controller); 125 - chip->controller = &controller; 118 + controller->ops = &pasemi_ops; 119 + nand_controller_init(controller); 120 + chip->controller = controller; 126 121 127 122 pasemi_nand_mtd = nand_to_mtd(chip); 128 123 ··· 145 136 goto out_ior; 146 137 } 147 138 148 - lpcctl = pci_resource_start(pdev, 0); 139 + ddata->lpcctl = pci_resource_start(pdev, 0); 149 140 pci_dev_put(pdev); 150 141 151 - if (!request_region(lpcctl, 4, driver_name)) { 142 + if (!request_region(ddata->lpcctl, 4, driver_name)) { 152 143 err = -EBUSY; 153 144 goto out_ior; 154 145 } ··· 181 172 } 182 173 183 174 dev_info(dev, "PA Semi NAND flash at %pR, control at I/O %x\n", &res, 184 - lpcctl); 175 + ddata->lpcctl); 185 176 186 177 return 0; 187 178 188 179 out_cleanup_nand: 189 180 nand_cleanup(chip); 190 181 out_lpc: 191 - release_region(lpcctl, 4); 182 + release_region(ddata->lpcctl, 4); 192 183 out_ior: 193 184 iounmap(chip->legacy.IO_ADDR_R); 194 185 out_mtd: 195 - kfree(chip); 186 + kfree(ddata); 196 187 out: 197 188 return err; 198 189 } 199 190 200 191 static int pasemi_nand_remove(struct platform_device *ofdev) 201 192 { 202 - struct nand_chip *chip; 193 + struct pasemi_ddata *ddata = platform_get_drvdata(ofdev); 194 + struct mtd_info *pasemi_nand_mtd; 203 195 int ret; 196 + struct nand_chip *chip; 204 197 205 - if (!pasemi_nand_mtd) 206 - return 0; 207 - 208 - chip = mtd_to_nand(pasemi_nand_mtd); 198 + chip = &ddata->chip; 199 + pasemi_nand_mtd = nand_to_mtd(chip); 209 200 210 201 /* Release resources, unregister device */ 211 202 ret = mtd_device_unregister(pasemi_nand_mtd); 212 203 WARN_ON(ret); 213 204 nand_cleanup(chip); 214 205 215 - release_region(lpcctl, 4); 206 + release_region(ddata->lpcctl, 4); 216 207 217 208 iounmap(chip->legacy.IO_ADDR_R); 218 209 219 210 /* Free the MTD device structure */ 220 - kfree(chip); 221 - 222 - pasemi_nand_mtd = NULL; 211 + kfree(ddata); 223 212 224 213 return 0; 225 214 }
+42 -80
drivers/mtd/nand/raw/sunxi_nand.c
··· 172 172 /** 173 173 * struct sunxi_nand_hw_ecc - stores information related to HW ECC support 174 174 * 175 - * @mode: the sunxi ECC mode field deduced from ECC requirements 175 + * @ecc_ctl: ECC_CTL register value for this NAND chip 176 176 */ 177 177 struct sunxi_nand_hw_ecc { 178 - int mode; 178 + u32 ecc_ctl; 179 179 }; 180 180 181 181 /** ··· 193 193 struct sunxi_nand_chip { 194 194 struct list_head node; 195 195 struct nand_chip nand; 196 - struct sunxi_nand_hw_ecc *ecc; 196 + struct sunxi_nand_hw_ecc ecc; 197 197 unsigned long clk_rate; 198 198 u32 timing_cfg; 199 199 u32 timing_ctl; ··· 421 421 struct sunxi_nand_chip_sel *sel; 422 422 u32 ctl; 423 423 424 - if (cs > 0 && cs >= sunxi_nand->nsels) 424 + if (cs >= sunxi_nand->nsels) 425 425 return; 426 426 427 427 ctl = readl(nfc->regs + NFC_REG_CTL) & ··· 689 689 { 690 690 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 691 691 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 692 - u32 ecc_ctl; 693 692 694 - ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); 695 - ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE | 696 - NFC_ECC_BLOCK_SIZE_MSK); 697 - ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc->mode) | 698 - NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE; 699 - 700 - if (nand->ecc.size == 512) 701 - ecc_ctl |= NFC_ECC_BLOCK_512; 702 - 703 - writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); 693 + writel(sunxi_nand->ecc.ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); 704 694 } 705 695 706 696 static void sunxi_nfc_hw_ecc_disable(struct nand_chip *nand) 707 697 { 708 698 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); 709 699 710 - writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN, 711 - nfc->regs + NFC_REG_ECC_CTL); 700 + writel(0, nfc->regs + NFC_REG_ECC_CTL); 712 701 } 713 702 714 703 static inline void sunxi_nfc_user_data_to_buf(u32 user_data, u8 *buf) ··· 1593 1604 return 0; 1594 1605 } 1595 1606 1607 + /* 1608 + * The controller does not provide access to OOB bytes 1609 + * past the end of the ECC data. 1610 + */ 1611 + if (section == ecc->steps && ecc->engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) 1612 + return -ERANGE; 1613 + 1596 1614 oobregion->offset = section * (ecc->bytes + 4); 1597 1615 1598 1616 if (section < ecc->steps) 1599 1617 oobregion->length = 4; 1600 1618 else 1601 - oobregion->offset = mtd->oobsize - oobregion->offset; 1619 + oobregion->length = mtd->oobsize - oobregion->offset; 1602 1620 1603 1621 return 0; 1604 1622 } ··· 1614 1618 .ecc = sunxi_nand_ooblayout_ecc, 1615 1619 .free = sunxi_nand_ooblayout_free, 1616 1620 }; 1617 - 1618 - static void sunxi_nand_hw_ecc_ctrl_cleanup(struct sunxi_nand_chip *sunxi_nand) 1619 - { 1620 - kfree(sunxi_nand->ecc); 1621 - } 1622 1621 1623 1622 static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand, 1624 1623 struct nand_ecc_ctrl *ecc, ··· 1625 1634 struct mtd_info *mtd = nand_to_mtd(nand); 1626 1635 struct nand_device *nanddev = mtd_to_nanddev(mtd); 1627 1636 int nsectors; 1628 - int ret; 1629 1637 int i; 1630 1638 1631 1639 if (nanddev->ecc.user_conf.flags & NAND_ECC_MAXIMIZE_STRENGTH) { ··· 1659 1669 if (ecc->size != 512 && ecc->size != 1024) 1660 1670 return -EINVAL; 1661 1671 1662 - sunxi_nand->ecc = kzalloc(sizeof(*sunxi_nand->ecc), GFP_KERNEL); 1663 - if (!sunxi_nand->ecc) 1664 - return -ENOMEM; 1665 - 1666 1672 /* Prefer 1k ECC chunk over 512 ones */ 1667 1673 if (ecc->size == 512 && mtd->writesize > 512) { 1668 1674 ecc->size = 1024; ··· 1679 1693 1680 1694 if (i >= ARRAY_SIZE(strengths)) { 1681 1695 dev_err(nfc->dev, "unsupported strength\n"); 1682 - ret = -ENOTSUPP; 1683 - goto err; 1696 + return -ENOTSUPP; 1684 1697 } 1685 - 1686 - sunxi_nand->ecc->mode = i; 1687 1698 1688 1699 /* HW ECC always request ECC bytes for 1024 bytes blocks */ 1689 1700 ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * 1024), 8); ··· 1690 1707 1691 1708 nsectors = mtd->writesize / ecc->size; 1692 1709 1693 - if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) { 1694 - ret = -EINVAL; 1695 - goto err; 1696 - } 1710 + if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) 1711 + return -EINVAL; 1697 1712 1698 1713 ecc->read_oob = sunxi_nfc_hw_ecc_read_oob; 1699 1714 ecc->write_oob = sunxi_nfc_hw_ecc_write_oob; ··· 1713 1732 ecc->read_oob_raw = nand_read_oob_std; 1714 1733 ecc->write_oob_raw = nand_write_oob_std; 1715 1734 1735 + sunxi_nand->ecc.ecc_ctl = NFC_ECC_MODE(i) | NFC_ECC_EXCEPTION | 1736 + NFC_ECC_PIPELINE | NFC_ECC_EN; 1737 + 1738 + if (ecc->size == 512) 1739 + sunxi_nand->ecc.ecc_ctl |= NFC_ECC_BLOCK_512; 1740 + 1716 1741 return 0; 1717 - 1718 - err: 1719 - kfree(sunxi_nand->ecc); 1720 - 1721 - return ret; 1722 - } 1723 - 1724 - static void sunxi_nand_ecc_cleanup(struct sunxi_nand_chip *sunxi_nand) 1725 - { 1726 - struct nand_ecc_ctrl *ecc = &sunxi_nand->nand.ecc; 1727 - 1728 - switch (ecc->engine_type) { 1729 - case NAND_ECC_ENGINE_TYPE_ON_HOST: 1730 - sunxi_nand_hw_ecc_ctrl_cleanup(sunxi_nand); 1731 - break; 1732 - case NAND_ECC_ENGINE_TYPE_NONE: 1733 - default: 1734 - break; 1735 - } 1736 1742 } 1737 1743 1738 1744 static int sunxi_nand_attach_chip(struct nand_chip *nand) ··· 1918 1950 .exec_op = sunxi_nfc_exec_op, 1919 1951 }; 1920 1952 1953 + static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) 1954 + { 1955 + struct sunxi_nand_chip *sunxi_nand; 1956 + struct nand_chip *chip; 1957 + int ret; 1958 + 1959 + while (!list_empty(&nfc->chips)) { 1960 + sunxi_nand = list_first_entry(&nfc->chips, 1961 + struct sunxi_nand_chip, 1962 + node); 1963 + chip = &sunxi_nand->nand; 1964 + ret = mtd_device_unregister(nand_to_mtd(chip)); 1965 + WARN_ON(ret); 1966 + nand_cleanup(chip); 1967 + list_del(&sunxi_nand->node); 1968 + } 1969 + } 1970 + 1921 1971 static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, 1922 1972 struct device_node *np) 1923 1973 { ··· 2027 2041 { 2028 2042 struct device_node *np = dev->of_node; 2029 2043 struct device_node *nand_np; 2030 - int nchips = of_get_child_count(np); 2031 2044 int ret; 2032 - 2033 - if (nchips > 8) { 2034 - dev_err(dev, "too many NAND chips: %d (max = 8)\n", nchips); 2035 - return -EINVAL; 2036 - } 2037 2045 2038 2046 for_each_child_of_node(np, nand_np) { 2039 2047 ret = sunxi_nand_chip_init(dev, nfc, nand_np); 2040 2048 if (ret) { 2041 2049 of_node_put(nand_np); 2050 + sunxi_nand_chips_cleanup(nfc); 2042 2051 return ret; 2043 2052 } 2044 2053 } 2045 2054 2046 2055 return 0; 2047 - } 2048 - 2049 - static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) 2050 - { 2051 - struct sunxi_nand_chip *sunxi_nand; 2052 - struct nand_chip *chip; 2053 - int ret; 2054 - 2055 - while (!list_empty(&nfc->chips)) { 2056 - sunxi_nand = list_first_entry(&nfc->chips, 2057 - struct sunxi_nand_chip, 2058 - node); 2059 - chip = &sunxi_nand->nand; 2060 - ret = mtd_device_unregister(nand_to_mtd(chip)); 2061 - WARN_ON(ret); 2062 - nand_cleanup(chip); 2063 - sunxi_nand_ecc_cleanup(sunxi_nand); 2064 - list_del(&sunxi_nand->node); 2065 - } 2066 2056 } 2067 2057 2068 2058 static int sunxi_nfc_dma_init(struct sunxi_nfc *nfc, struct resource *r)
-533
drivers/mtd/nand/raw/tmio_nand.c
··· 1 - /* 2 - * Toshiba TMIO NAND flash controller driver 3 - * 4 - * Slightly murky pre-git history of the driver: 5 - * 6 - * Copyright (c) Ian Molton 2004, 2005, 2008 7 - * Original work, independent of sharps code. Included hardware ECC support. 8 - * Hard ECC did not work for writes in the early revisions. 9 - * Copyright (c) Dirk Opfer 2005. 10 - * Modifications developed from sharps code but 11 - * NOT containing any, ported onto Ians base. 12 - * Copyright (c) Chris Humbert 2005 13 - * Copyright (c) Dmitry Baryshkov 2008 14 - * Minor fixes 15 - * 16 - * Parts copyright Sebastian Carlier 17 - * 18 - * This file is licensed under 19 - * the terms of the GNU General Public License version 2. This program 20 - * is licensed "as is" without any warranty of any kind, whether express 21 - * or implied. 22 - * 23 - */ 24 - 25 - 26 - #include <linux/kernel.h> 27 - #include <linux/module.h> 28 - #include <linux/platform_device.h> 29 - #include <linux/mfd/core.h> 30 - #include <linux/mfd/tmio.h> 31 - #include <linux/delay.h> 32 - #include <linux/io.h> 33 - #include <linux/irq.h> 34 - #include <linux/interrupt.h> 35 - #include <linux/ioport.h> 36 - #include <linux/mtd/mtd.h> 37 - #include <linux/mtd/rawnand.h> 38 - #include <linux/mtd/partitions.h> 39 - #include <linux/slab.h> 40 - 41 - /*--------------------------------------------------------------------------*/ 42 - 43 - /* 44 - * NAND Flash Host Controller Configuration Register 45 - */ 46 - #define CCR_COMMAND 0x04 /* w Command */ 47 - #define CCR_BASE 0x10 /* l NAND Flash Control Reg Base Addr */ 48 - #define CCR_INTP 0x3d /* b Interrupt Pin */ 49 - #define CCR_INTE 0x48 /* b Interrupt Enable */ 50 - #define CCR_EC 0x4a /* b Event Control */ 51 - #define CCR_ICC 0x4c /* b Internal Clock Control */ 52 - #define CCR_ECCC 0x5b /* b ECC Control */ 53 - #define CCR_NFTC 0x60 /* b NAND Flash Transaction Control */ 54 - #define CCR_NFM 0x61 /* b NAND Flash Monitor */ 55 - #define CCR_NFPSC 0x62 /* b NAND Flash Power Supply Control */ 56 - #define CCR_NFDC 0x63 /* b NAND Flash Detect Control */ 57 - 58 - /* 59 - * NAND Flash Control Register 60 - */ 61 - #define FCR_DATA 0x00 /* bwl Data Register */ 62 - #define FCR_MODE 0x04 /* b Mode Register */ 63 - #define FCR_STATUS 0x05 /* b Status Register */ 64 - #define FCR_ISR 0x06 /* b Interrupt Status Register */ 65 - #define FCR_IMR 0x07 /* b Interrupt Mask Register */ 66 - 67 - /* FCR_MODE Register Command List */ 68 - #define FCR_MODE_DATA 0x94 /* Data Data_Mode */ 69 - #define FCR_MODE_COMMAND 0x95 /* Data Command_Mode */ 70 - #define FCR_MODE_ADDRESS 0x96 /* Data Address_Mode */ 71 - 72 - #define FCR_MODE_HWECC_CALC 0xB4 /* HW-ECC Data */ 73 - #define FCR_MODE_HWECC_RESULT 0xD4 /* HW-ECC Calc result Read_Mode */ 74 - #define FCR_MODE_HWECC_RESET 0xF4 /* HW-ECC Reset */ 75 - 76 - #define FCR_MODE_POWER_ON 0x0C /* Power Supply ON to SSFDC card */ 77 - #define FCR_MODE_POWER_OFF 0x08 /* Power Supply OFF to SSFDC card */ 78 - 79 - #define FCR_MODE_LED_OFF 0x00 /* LED OFF */ 80 - #define FCR_MODE_LED_ON 0x04 /* LED ON */ 81 - 82 - #define FCR_MODE_EJECT_ON 0x68 /* Ejection events active */ 83 - #define FCR_MODE_EJECT_OFF 0x08 /* Ejection events ignored */ 84 - 85 - #define FCR_MODE_LOCK 0x6C /* Lock_Mode. Eject Switch Invalid */ 86 - #define FCR_MODE_UNLOCK 0x0C /* UnLock_Mode. Eject Switch is valid */ 87 - 88 - #define FCR_MODE_CONTROLLER_ID 0x40 /* Controller ID Read */ 89 - #define FCR_MODE_STANDBY 0x00 /* SSFDC card Changes Standby State */ 90 - 91 - #define FCR_MODE_WE 0x80 92 - #define FCR_MODE_ECC1 0x40 93 - #define FCR_MODE_ECC0 0x20 94 - #define FCR_MODE_CE 0x10 95 - #define FCR_MODE_PCNT1 0x08 96 - #define FCR_MODE_PCNT0 0x04 97 - #define FCR_MODE_ALE 0x02 98 - #define FCR_MODE_CLE 0x01 99 - 100 - #define FCR_STATUS_BUSY 0x80 101 - 102 - /*--------------------------------------------------------------------------*/ 103 - 104 - struct tmio_nand { 105 - struct nand_controller controller; 106 - struct nand_chip chip; 107 - struct completion comp; 108 - 109 - struct platform_device *dev; 110 - 111 - void __iomem *ccr; 112 - void __iomem *fcr; 113 - unsigned long fcr_base; 114 - 115 - unsigned int irq; 116 - 117 - /* for tmio_nand_read_byte */ 118 - u8 read; 119 - unsigned read_good:1; 120 - }; 121 - 122 - static inline struct tmio_nand *mtd_to_tmio(struct mtd_info *mtd) 123 - { 124 - return container_of(mtd_to_nand(mtd), struct tmio_nand, chip); 125 - } 126 - 127 - 128 - /*--------------------------------------------------------------------------*/ 129 - 130 - static void tmio_nand_hwcontrol(struct nand_chip *chip, int cmd, 131 - unsigned int ctrl) 132 - { 133 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 134 - 135 - if (ctrl & NAND_CTRL_CHANGE) { 136 - u8 mode; 137 - 138 - if (ctrl & NAND_NCE) { 139 - mode = FCR_MODE_DATA; 140 - 141 - if (ctrl & NAND_CLE) 142 - mode |= FCR_MODE_CLE; 143 - else 144 - mode &= ~FCR_MODE_CLE; 145 - 146 - if (ctrl & NAND_ALE) 147 - mode |= FCR_MODE_ALE; 148 - else 149 - mode &= ~FCR_MODE_ALE; 150 - } else { 151 - mode = FCR_MODE_STANDBY; 152 - } 153 - 154 - tmio_iowrite8(mode, tmio->fcr + FCR_MODE); 155 - tmio->read_good = 0; 156 - } 157 - 158 - if (cmd != NAND_CMD_NONE) 159 - tmio_iowrite8(cmd, chip->legacy.IO_ADDR_W); 160 - } 161 - 162 - static int tmio_nand_dev_ready(struct nand_chip *chip) 163 - { 164 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 165 - 166 - return !(tmio_ioread8(tmio->fcr + FCR_STATUS) & FCR_STATUS_BUSY); 167 - } 168 - 169 - static irqreturn_t tmio_irq(int irq, void *__tmio) 170 - { 171 - struct tmio_nand *tmio = __tmio; 172 - 173 - /* disable RDYREQ interrupt */ 174 - tmio_iowrite8(0x00, tmio->fcr + FCR_IMR); 175 - complete(&tmio->comp); 176 - 177 - return IRQ_HANDLED; 178 - } 179 - 180 - /* 181 - *The TMIO core has a RDYREQ interrupt on the posedge of #SMRB. 182 - *This interrupt is normally disabled, but for long operations like 183 - *erase and write, we enable it to wake us up. The irq handler 184 - *disables the interrupt. 185 - */ 186 - static int tmio_nand_wait(struct nand_chip *nand_chip) 187 - { 188 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(nand_chip)); 189 - long timeout; 190 - u8 status; 191 - 192 - /* enable RDYREQ interrupt */ 193 - 194 - tmio_iowrite8(0x0f, tmio->fcr + FCR_ISR); 195 - reinit_completion(&tmio->comp); 196 - tmio_iowrite8(0x81, tmio->fcr + FCR_IMR); 197 - 198 - timeout = 400; 199 - timeout = wait_for_completion_timeout(&tmio->comp, 200 - msecs_to_jiffies(timeout)); 201 - 202 - if (unlikely(!tmio_nand_dev_ready(nand_chip))) { 203 - tmio_iowrite8(0x00, tmio->fcr + FCR_IMR); 204 - dev_warn(&tmio->dev->dev, "still busy after 400 ms\n"); 205 - 206 - } else if (unlikely(!timeout)) { 207 - tmio_iowrite8(0x00, tmio->fcr + FCR_IMR); 208 - dev_warn(&tmio->dev->dev, "timeout waiting for interrupt\n"); 209 - } 210 - 211 - nand_status_op(nand_chip, &status); 212 - return status; 213 - } 214 - 215 - /* 216 - *The TMIO controller combines two 8-bit data bytes into one 16-bit 217 - *word. This function separates them so nand_base.c works as expected, 218 - *especially its NAND_CMD_READID routines. 219 - * 220 - *To prevent stale data from being read, tmio_nand_hwcontrol() clears 221 - *tmio->read_good. 222 - */ 223 - static u_char tmio_nand_read_byte(struct nand_chip *chip) 224 - { 225 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 226 - unsigned int data; 227 - 228 - if (tmio->read_good--) 229 - return tmio->read; 230 - 231 - data = tmio_ioread16(tmio->fcr + FCR_DATA); 232 - tmio->read = data >> 8; 233 - return data; 234 - } 235 - 236 - /* 237 - *The TMIO controller converts an 8-bit NAND interface to a 16-bit 238 - *bus interface, so all data reads and writes must be 16-bit wide. 239 - *Thus, we implement 16-bit versions of the read, write, and verify 240 - *buffer functions. 241 - */ 242 - static void 243 - tmio_nand_write_buf(struct nand_chip *chip, const u_char *buf, int len) 244 - { 245 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 246 - 247 - tmio_iowrite16_rep(tmio->fcr + FCR_DATA, buf, len >> 1); 248 - } 249 - 250 - static void tmio_nand_read_buf(struct nand_chip *chip, u_char *buf, int len) 251 - { 252 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 253 - 254 - tmio_ioread16_rep(tmio->fcr + FCR_DATA, buf, len >> 1); 255 - } 256 - 257 - static void tmio_nand_enable_hwecc(struct nand_chip *chip, int mode) 258 - { 259 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 260 - 261 - tmio_iowrite8(FCR_MODE_HWECC_RESET, tmio->fcr + FCR_MODE); 262 - tmio_ioread8(tmio->fcr + FCR_DATA); /* dummy read */ 263 - tmio_iowrite8(FCR_MODE_HWECC_CALC, tmio->fcr + FCR_MODE); 264 - } 265 - 266 - static int tmio_nand_calculate_ecc(struct nand_chip *chip, const u_char *dat, 267 - u_char *ecc_code) 268 - { 269 - struct tmio_nand *tmio = mtd_to_tmio(nand_to_mtd(chip)); 270 - unsigned int ecc; 271 - 272 - tmio_iowrite8(FCR_MODE_HWECC_RESULT, tmio->fcr + FCR_MODE); 273 - 274 - ecc = tmio_ioread16(tmio->fcr + FCR_DATA); 275 - ecc_code[1] = ecc; /* 000-255 LP7-0 */ 276 - ecc_code[0] = ecc >> 8; /* 000-255 LP15-8 */ 277 - ecc = tmio_ioread16(tmio->fcr + FCR_DATA); 278 - ecc_code[2] = ecc; /* 000-255 CP5-0,11b */ 279 - ecc_code[4] = ecc >> 8; /* 256-511 LP7-0 */ 280 - ecc = tmio_ioread16(tmio->fcr + FCR_DATA); 281 - ecc_code[3] = ecc; /* 256-511 LP15-8 */ 282 - ecc_code[5] = ecc >> 8; /* 256-511 CP5-0,11b */ 283 - 284 - tmio_iowrite8(FCR_MODE_DATA, tmio->fcr + FCR_MODE); 285 - return 0; 286 - } 287 - 288 - static int tmio_nand_correct_data(struct nand_chip *chip, unsigned char *buf, 289 - unsigned char *read_ecc, 290 - unsigned char *calc_ecc) 291 - { 292 - int r0, r1; 293 - 294 - /* assume ecc.size = 512 and ecc.bytes = 6 */ 295 - r0 = rawnand_sw_hamming_correct(chip, buf, read_ecc, calc_ecc); 296 - if (r0 < 0) 297 - return r0; 298 - r1 = rawnand_sw_hamming_correct(chip, buf + 256, read_ecc + 3, 299 - calc_ecc + 3); 300 - if (r1 < 0) 301 - return r1; 302 - return r0 + r1; 303 - } 304 - 305 - static int tmio_hw_init(struct platform_device *dev, struct tmio_nand *tmio) 306 - { 307 - const struct mfd_cell *cell = mfd_get_cell(dev); 308 - int ret; 309 - 310 - if (cell->enable) { 311 - ret = cell->enable(dev); 312 - if (ret) 313 - return ret; 314 - } 315 - 316 - /* (4Ch) CLKRUN Enable 1st spcrunc */ 317 - tmio_iowrite8(0x81, tmio->ccr + CCR_ICC); 318 - 319 - /* (10h)BaseAddress 0x1000 spba.spba2 */ 320 - tmio_iowrite16(tmio->fcr_base, tmio->ccr + CCR_BASE); 321 - tmio_iowrite16(tmio->fcr_base >> 16, tmio->ccr + CCR_BASE + 2); 322 - 323 - /* (04h)Command Register I/O spcmd */ 324 - tmio_iowrite8(0x02, tmio->ccr + CCR_COMMAND); 325 - 326 - /* (62h) Power Supply Control ssmpwc */ 327 - /* HardPowerOFF - SuspendOFF - PowerSupplyWait_4MS */ 328 - tmio_iowrite8(0x02, tmio->ccr + CCR_NFPSC); 329 - 330 - /* (63h) Detect Control ssmdtc */ 331 - tmio_iowrite8(0x02, tmio->ccr + CCR_NFDC); 332 - 333 - /* Interrupt status register clear sintst */ 334 - tmio_iowrite8(0x0f, tmio->fcr + FCR_ISR); 335 - 336 - /* After power supply, Media are reset smode */ 337 - tmio_iowrite8(FCR_MODE_POWER_ON, tmio->fcr + FCR_MODE); 338 - tmio_iowrite8(FCR_MODE_COMMAND, tmio->fcr + FCR_MODE); 339 - tmio_iowrite8(NAND_CMD_RESET, tmio->fcr + FCR_DATA); 340 - 341 - /* Standby Mode smode */ 342 - tmio_iowrite8(FCR_MODE_STANDBY, tmio->fcr + FCR_MODE); 343 - 344 - mdelay(5); 345 - 346 - return 0; 347 - } 348 - 349 - static void tmio_hw_stop(struct platform_device *dev, struct tmio_nand *tmio) 350 - { 351 - const struct mfd_cell *cell = mfd_get_cell(dev); 352 - 353 - tmio_iowrite8(FCR_MODE_POWER_OFF, tmio->fcr + FCR_MODE); 354 - if (cell->disable) 355 - cell->disable(dev); 356 - } 357 - 358 - static int tmio_attach_chip(struct nand_chip *chip) 359 - { 360 - if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST) 361 - return 0; 362 - 363 - chip->ecc.size = 512; 364 - chip->ecc.bytes = 6; 365 - chip->ecc.strength = 2; 366 - chip->ecc.hwctl = tmio_nand_enable_hwecc; 367 - chip->ecc.calculate = tmio_nand_calculate_ecc; 368 - chip->ecc.correct = tmio_nand_correct_data; 369 - 370 - return 0; 371 - } 372 - 373 - static const struct nand_controller_ops tmio_ops = { 374 - .attach_chip = tmio_attach_chip, 375 - }; 376 - 377 - static int tmio_probe(struct platform_device *dev) 378 - { 379 - struct tmio_nand_data *data = dev_get_platdata(&dev->dev); 380 - struct resource *fcr = platform_get_resource(dev, 381 - IORESOURCE_MEM, 0); 382 - struct resource *ccr = platform_get_resource(dev, 383 - IORESOURCE_MEM, 1); 384 - int irq = platform_get_irq(dev, 0); 385 - struct tmio_nand *tmio; 386 - struct mtd_info *mtd; 387 - struct nand_chip *nand_chip; 388 - int retval; 389 - 390 - if (data == NULL) 391 - dev_warn(&dev->dev, "NULL platform data!\n"); 392 - 393 - if (!ccr || !fcr) 394 - return -EINVAL; 395 - 396 - tmio = devm_kzalloc(&dev->dev, sizeof(*tmio), GFP_KERNEL); 397 - if (!tmio) 398 - return -ENOMEM; 399 - 400 - init_completion(&tmio->comp); 401 - 402 - tmio->dev = dev; 403 - 404 - platform_set_drvdata(dev, tmio); 405 - nand_chip = &tmio->chip; 406 - mtd = nand_to_mtd(nand_chip); 407 - mtd->name = "tmio-nand"; 408 - mtd->dev.parent = &dev->dev; 409 - 410 - nand_controller_init(&tmio->controller); 411 - tmio->controller.ops = &tmio_ops; 412 - nand_chip->controller = &tmio->controller; 413 - 414 - tmio->ccr = devm_ioremap(&dev->dev, ccr->start, resource_size(ccr)); 415 - if (!tmio->ccr) 416 - return -EIO; 417 - 418 - tmio->fcr_base = fcr->start & 0xfffff; 419 - tmio->fcr = devm_ioremap(&dev->dev, fcr->start, resource_size(fcr)); 420 - if (!tmio->fcr) 421 - return -EIO; 422 - 423 - retval = tmio_hw_init(dev, tmio); 424 - if (retval) 425 - return retval; 426 - 427 - /* Set address of NAND IO lines */ 428 - nand_chip->legacy.IO_ADDR_R = tmio->fcr; 429 - nand_chip->legacy.IO_ADDR_W = tmio->fcr; 430 - 431 - /* Set address of hardware control function */ 432 - nand_chip->legacy.cmd_ctrl = tmio_nand_hwcontrol; 433 - nand_chip->legacy.dev_ready = tmio_nand_dev_ready; 434 - nand_chip->legacy.read_byte = tmio_nand_read_byte; 435 - nand_chip->legacy.write_buf = tmio_nand_write_buf; 436 - nand_chip->legacy.read_buf = tmio_nand_read_buf; 437 - 438 - if (data) 439 - nand_chip->badblock_pattern = data->badblock_pattern; 440 - 441 - /* 15 us command delay time */ 442 - nand_chip->legacy.chip_delay = 15; 443 - 444 - retval = devm_request_irq(&dev->dev, irq, &tmio_irq, 0, 445 - dev_name(&dev->dev), tmio); 446 - if (retval) { 447 - dev_err(&dev->dev, "request_irq error %d\n", retval); 448 - goto err_irq; 449 - } 450 - 451 - tmio->irq = irq; 452 - nand_chip->legacy.waitfunc = tmio_nand_wait; 453 - 454 - /* Scan to find existence of the device */ 455 - retval = nand_scan(nand_chip, 1); 456 - if (retval) 457 - goto err_irq; 458 - 459 - /* Register the partitions */ 460 - retval = mtd_device_parse_register(mtd, 461 - data ? data->part_parsers : NULL, 462 - NULL, 463 - data ? data->partition : NULL, 464 - data ? data->num_partitions : 0); 465 - if (!retval) 466 - return retval; 467 - 468 - nand_cleanup(nand_chip); 469 - 470 - err_irq: 471 - tmio_hw_stop(dev, tmio); 472 - return retval; 473 - } 474 - 475 - static int tmio_remove(struct platform_device *dev) 476 - { 477 - struct tmio_nand *tmio = platform_get_drvdata(dev); 478 - struct nand_chip *chip = &tmio->chip; 479 - int ret; 480 - 481 - ret = mtd_device_unregister(nand_to_mtd(chip)); 482 - WARN_ON(ret); 483 - nand_cleanup(chip); 484 - tmio_hw_stop(dev, tmio); 485 - return 0; 486 - } 487 - 488 - #ifdef CONFIG_PM 489 - static int tmio_suspend(struct platform_device *dev, pm_message_t state) 490 - { 491 - const struct mfd_cell *cell = mfd_get_cell(dev); 492 - 493 - if (cell->suspend) 494 - cell->suspend(dev); 495 - 496 - tmio_hw_stop(dev, platform_get_drvdata(dev)); 497 - return 0; 498 - } 499 - 500 - static int tmio_resume(struct platform_device *dev) 501 - { 502 - const struct mfd_cell *cell = mfd_get_cell(dev); 503 - 504 - /* FIXME - is this required or merely another attack of the broken 505 - * SHARP platform? Looks suspicious. 506 - */ 507 - tmio_hw_init(dev, platform_get_drvdata(dev)); 508 - 509 - if (cell->resume) 510 - cell->resume(dev); 511 - 512 - return 0; 513 - } 514 - #else 515 - #define tmio_suspend NULL 516 - #define tmio_resume NULL 517 - #endif 518 - 519 - static struct platform_driver tmio_driver = { 520 - .driver.name = "tmio-nand", 521 - .driver.owner = THIS_MODULE, 522 - .probe = tmio_probe, 523 - .remove = tmio_remove, 524 - .suspend = tmio_suspend, 525 - .resume = tmio_resume, 526 - }; 527 - 528 - module_platform_driver(tmio_driver); 529 - 530 - MODULE_LICENSE("GPL v2"); 531 - MODULE_AUTHOR("Ian Molton, Dirk Opfer, Chris Humbert, Dmitry Baryshkov"); 532 - MODULE_DESCRIPTION("NAND flash driver on Toshiba Mobile IO controller"); 533 - MODULE_ALIAS("platform:tmio-nand");
+2 -2
drivers/mtd/nand/raw/vf610_nfc.c
··· 206 206 #endif 207 207 } 208 208 209 - /** 209 + /* 210 210 * Read accessor for internal SRAM buffer 211 211 * @dst: destination address in regular memory 212 212 * @src: source address in SRAM buffer ··· 241 241 } 242 242 } 243 243 244 - /** 244 + /* 245 245 * Write accessor for internal SRAM buffer 246 246 * @dst: destination address in SRAM buffer 247 247 * @src: source address in regular memory
+1 -1
drivers/mtd/nand/spi/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - spinand-objs := core.o ato.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o 2 + spinand-objs := core.o alliancememory.o ato.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o 3 3 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
+153
drivers/mtd/nand/spi/alliancememory.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Author: Mario Kicherer <dev@kicherer.org> 4 + */ 5 + 6 + #include <linux/device.h> 7 + #include <linux/kernel.h> 8 + #include <linux/mtd/spinand.h> 9 + 10 + #define SPINAND_MFR_ALLIANCEMEMORY 0x52 11 + 12 + #define AM_STATUS_ECC_BITMASK (3 << 4) 13 + 14 + #define AM_STATUS_ECC_NONE_DETECTED (0 << 4) 15 + #define AM_STATUS_ECC_CORRECTED (1 << 4) 16 + #define AM_STATUS_ECC_ERRORED (2 << 4) 17 + #define AM_STATUS_ECC_MAX_CORRECTED (3 << 4) 18 + 19 + static SPINAND_OP_VARIANTS(read_cache_variants, 20 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0), 21 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), 22 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), 23 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), 24 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), 25 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); 26 + 27 + static SPINAND_OP_VARIANTS(write_cache_variants, 28 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), 29 + SPINAND_PROG_LOAD(true, 0, NULL, 0)); 30 + 31 + static SPINAND_OP_VARIANTS(update_cache_variants, 32 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), 33 + SPINAND_PROG_LOAD(false, 0, NULL, 0)); 34 + 35 + static int am_get_eccsize(struct mtd_info *mtd) 36 + { 37 + if (mtd->oobsize == 64) 38 + return 0x20; 39 + else if (mtd->oobsize == 128) 40 + return 0x38; 41 + else if (mtd->oobsize == 256) 42 + return 0x70; 43 + else 44 + return -EINVAL; 45 + } 46 + 47 + static int am_ooblayout_ecc(struct mtd_info *mtd, int section, 48 + struct mtd_oob_region *region) 49 + { 50 + int ecc_bytes; 51 + 52 + ecc_bytes = am_get_eccsize(mtd); 53 + if (ecc_bytes < 0) 54 + return ecc_bytes; 55 + 56 + region->offset = mtd->oobsize - ecc_bytes; 57 + region->length = ecc_bytes; 58 + 59 + return 0; 60 + } 61 + 62 + static int am_ooblayout_free(struct mtd_info *mtd, int section, 63 + struct mtd_oob_region *region) 64 + { 65 + int ecc_bytes; 66 + 67 + if (section) 68 + return -ERANGE; 69 + 70 + ecc_bytes = am_get_eccsize(mtd); 71 + if (ecc_bytes < 0) 72 + return ecc_bytes; 73 + 74 + /* 75 + * It is unclear how many bytes are used for the bad block marker. We 76 + * reserve the common two bytes here. 77 + * 78 + * The free area in this kind of flash is divided into chunks where the 79 + * first 4 bytes of each chunk are unprotected. The number of chunks 80 + * depends on the specific model. The models with 4096+256 bytes pages 81 + * have 8 chunks, the others 4 chunks. 82 + */ 83 + 84 + region->offset = 2; 85 + region->length = mtd->oobsize - 2 - ecc_bytes; 86 + 87 + return 0; 88 + } 89 + 90 + static const struct mtd_ooblayout_ops am_ooblayout = { 91 + .ecc = am_ooblayout_ecc, 92 + .free = am_ooblayout_free, 93 + }; 94 + 95 + static int am_ecc_get_status(struct spinand_device *spinand, u8 status) 96 + { 97 + switch (status & AM_STATUS_ECC_BITMASK) { 98 + case AM_STATUS_ECC_NONE_DETECTED: 99 + return 0; 100 + 101 + case AM_STATUS_ECC_CORRECTED: 102 + /* 103 + * use oobsize to determine the flash model and the maximum of 104 + * correctable errors and return maximum - 1 by convention 105 + */ 106 + if (spinand->base.mtd.oobsize == 64) 107 + return 3; 108 + else 109 + return 7; 110 + 111 + case AM_STATUS_ECC_ERRORED: 112 + return -EBADMSG; 113 + 114 + case AM_STATUS_ECC_MAX_CORRECTED: 115 + /* 116 + * use oobsize to determine the flash model and the maximum of 117 + * correctable errors 118 + */ 119 + if (spinand->base.mtd.oobsize == 64) 120 + return 4; 121 + else 122 + return 8; 123 + 124 + default: 125 + break; 126 + } 127 + 128 + return -EINVAL; 129 + } 130 + 131 + static const struct spinand_info alliancememory_spinand_table[] = { 132 + SPINAND_INFO("AS5F34G04SND", 133 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x2f), 134 + NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 1, 1), 135 + NAND_ECCREQ(4, 512), 136 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 137 + &write_cache_variants, 138 + &update_cache_variants), 139 + SPINAND_HAS_QE_BIT, 140 + SPINAND_ECCINFO(&am_ooblayout, 141 + am_ecc_get_status)), 142 + }; 143 + 144 + static const struct spinand_manufacturer_ops alliancememory_spinand_manuf_ops = { 145 + }; 146 + 147 + const struct spinand_manufacturer alliancememory_spinand_manufacturer = { 148 + .id = SPINAND_MFR_ALLIANCEMEMORY, 149 + .name = "AllianceMemory", 150 + .chips = alliancememory_spinand_table, 151 + .nchips = ARRAY_SIZE(alliancememory_spinand_table), 152 + .ops = &alliancememory_spinand_manuf_ops, 153 + };
+1
drivers/mtd/nand/spi/core.c
··· 937 937 }; 938 938 939 939 static const struct spinand_manufacturer *spinand_manufacturers[] = { 940 + &alliancememory_spinand_manufacturer, 940 941 &ato_spinand_manufacturer, 941 942 &gigadevice_spinand_manufacturer, 942 943 &macronix_spinand_manufacturer,
+2 -1
drivers/mtd/nand/spi/macronix.c
··· 83 83 * in order to avoid forcing the wear-leveling layer to move 84 84 * data around if it's not necessary. 85 85 */ 86 - if (mx35lf1ge4ab_get_eccsr(spinand, &eccsr)) 86 + if (mx35lf1ge4ab_get_eccsr(spinand, spinand->scratchbuf)) 87 87 return nanddev_get_ecc_conf(nand)->strength; 88 88 89 + eccsr = *spinand->scratchbuf; 89 90 if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength || 90 91 !eccsr)) 91 92 return nanddev_get_ecc_conf(nand)->strength;
+19
drivers/mtd/parsers/ofpart_core.c
··· 122 122 123 123 a_cells = of_n_addr_cells(pp); 124 124 s_cells = of_n_size_cells(pp); 125 + if (!dedicated && s_cells == 0) { 126 + /* 127 + * This is a ugly workaround to not create 128 + * regression on devices that are still creating 129 + * partitions as direct children of the nand controller. 130 + * This can happen in case the nand controller node has 131 + * #size-cells equal to 0 and the firmware (e.g. 132 + * U-Boot) just add the partitions there assuming 133 + * 32-bit addressing. 134 + * 135 + * If you get this warning your firmware and/or DTS 136 + * should be really fixed. 137 + * 138 + * This is working only for devices smaller than 4GiB. 139 + */ 140 + pr_warn("%s: ofpart partition %pOF (%pOF) #size-cells is wrongly set to <0>, assuming <1> for parsing partitions.\n", 141 + master->name, pp, mtd_node); 142 + s_cells = 1; 143 + } 125 144 if (len / 4 != a_cells + s_cells) { 126 145 pr_debug("%s: ofpart partition %pOF (%pOF) error parsing reg property.\n", 127 146 master->name, pp,
+14 -6
drivers/mtd/spi-nor/core.c
··· 9 9 10 10 #include <linux/err.h> 11 11 #include <linux/errno.h> 12 - #include <linux/module.h> 13 12 #include <linux/delay.h> 14 13 #include <linux/device.h> 15 - #include <linux/mutex.h> 16 14 #include <linux/math64.h> 17 - #include <linux/sizes.h> 18 - #include <linux/slab.h> 19 - 15 + #include <linux/module.h> 20 16 #include <linux/mtd/mtd.h> 17 + #include <linux/mtd/spi-nor.h> 18 + #include <linux/mutex.h> 21 19 #include <linux/of_platform.h> 22 20 #include <linux/sched/task_stack.h> 21 + #include <linux/sizes.h> 22 + #include <linux/slab.h> 23 23 #include <linux/spi/flash.h> 24 - #include <linux/mtd/spi-nor.h> 25 24 26 25 #include "core.h" 27 26 ··· 2023 2024 /* JEDEC JESD216B Standard imposes erase sizes to be power of 2. */ 2024 2025 erase->size_shift = ffs(erase->size) - 1; 2025 2026 erase->size_mask = (1 << erase->size_shift) - 1; 2027 + } 2028 + 2029 + /** 2030 + * spi_nor_mask_erase_type() - mask out a SPI NOR erase type 2031 + * @erase: pointer to a structure that describes a SPI NOR erase type 2032 + */ 2033 + void spi_nor_mask_erase_type(struct spi_nor_erase_type *erase) 2034 + { 2035 + erase->size = 0; 2026 2036 } 2027 2037 2028 2038 /**
+21 -23
drivers/mtd/spi-nor/core.h
··· 529 529 const struct spi_nor_fixups *fixups; 530 530 }; 531 531 532 + #define SPI_NOR_ID_2ITEMS(_id) ((_id) >> 8) & 0xff, (_id) & 0xff 533 + #define SPI_NOR_ID_3ITEMS(_id) ((_id) >> 16) & 0xff, SPI_NOR_ID_2ITEMS(_id) 534 + 535 + #define SPI_NOR_ID(_jedec_id, _ext_id) \ 536 + .id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_2ITEMS(_ext_id) }, \ 537 + .id_len = !(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0)) 538 + 539 + #define SPI_NOR_ID6(_jedec_id, _ext_id) \ 540 + .id = { SPI_NOR_ID_3ITEMS(_jedec_id), SPI_NOR_ID_3ITEMS(_ext_id) }, \ 541 + .id_len = 6 542 + 543 + #define SPI_NOR_GEOMETRY(_sector_size, _n_sectors) \ 544 + .sector_size = (_sector_size), \ 545 + .n_sectors = (_n_sectors), \ 546 + .page_size = 256 547 + 532 548 /* Used when the "_ext_id" is two bytes at most */ 533 549 #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors) \ 534 - .id = { \ 535 - ((_jedec_id) >> 16) & 0xff, \ 536 - ((_jedec_id) >> 8) & 0xff, \ 537 - (_jedec_id) & 0xff, \ 538 - ((_ext_id) >> 8) & 0xff, \ 539 - (_ext_id) & 0xff, \ 540 - }, \ 541 - .id_len = (!(_jedec_id) ? 0 : (3 + ((_ext_id) ? 2 : 0))), \ 542 - .sector_size = (_sector_size), \ 543 - .n_sectors = (_n_sectors), \ 544 - .page_size = 256, \ 550 + SPI_NOR_ID((_jedec_id), (_ext_id)), \ 551 + SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)), 545 552 546 553 #define INFO6(_jedec_id, _ext_id, _sector_size, _n_sectors) \ 547 - .id = { \ 548 - ((_jedec_id) >> 16) & 0xff, \ 549 - ((_jedec_id) >> 8) & 0xff, \ 550 - (_jedec_id) & 0xff, \ 551 - ((_ext_id) >> 16) & 0xff, \ 552 - ((_ext_id) >> 8) & 0xff, \ 553 - (_ext_id) & 0xff, \ 554 - }, \ 555 - .id_len = 6, \ 556 - .sector_size = (_sector_size), \ 557 - .n_sectors = (_n_sectors), \ 558 - .page_size = 256, \ 554 + SPI_NOR_ID6((_jedec_id), (_ext_id)), \ 555 + SPI_NOR_GEOMETRY((_sector_size), (_n_sectors)), 559 556 560 557 #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_nbytes) \ 561 558 .sector_size = (_sector_size), \ ··· 681 684 682 685 void spi_nor_set_erase_type(struct spi_nor_erase_type *erase, u32 size, 683 686 u8 opcode); 687 + void spi_nor_mask_erase_type(struct spi_nor_erase_type *erase); 684 688 struct spi_nor_erase_region * 685 689 spi_nor_region_next(struct spi_nor_erase_region *region); 686 690 void spi_nor_init_uniform_erase_map(struct spi_nor_erase_map *map,
+1 -1
drivers/mtd/spi-nor/debugfs.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 + #include <linux/debugfs.h> 3 4 #include <linux/mtd/spi-nor.h> 4 5 #include <linux/spi/spi.h> 5 6 #include <linux/spi/spi-mem.h> 6 - #include <linux/debugfs.h> 7 7 8 8 #include "core.h" 9 9
+1 -1
drivers/mtd/spi-nor/issi.c
··· 18 18 * BFPT_DWORD1_ADDRESS_BYTES_3_ONLY. 19 19 * Overwrite the number of address bytes advertised by the BFPT. 20 20 */ 21 - if ((bfpt->dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) == 21 + if ((bfpt->dwords[SFDP_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) == 22 22 BFPT_DWORD1_ADDRESS_BYTES_3_ONLY) 23 23 nor->params->addr_nbytes = 4; 24 24
+1 -1
drivers/mtd/spi-nor/macronix.c
··· 22 22 * seems that the F version advertises support for Fast Read 4-4-4 in 23 23 * its BFPT table. 24 24 */ 25 - if (bfpt->dwords[BFPT_DWORD(5)] & BFPT_DWORD5_FAST_READ_4_4_4) 25 + if (bfpt->dwords[SFDP_DWORD(5)] & BFPT_DWORD5_FAST_READ_4_4_4) 26 26 nor->flags |= SNOR_F_4B_OPCODES; 27 27 28 28 return 0;
+41 -37
drivers/mtd/spi-nor/sfdp.c
··· 5 5 */ 6 6 7 7 #include <linux/bitfield.h> 8 + #include <linux/mtd/spi-nor.h> 8 9 #include <linux/slab.h> 9 10 #include <linux/sort.h> 10 - #include <linux/mtd/spi-nor.h> 11 11 12 12 #include "core.h" 13 13 ··· 242 242 /* Fast Read 1-1-2 */ 243 243 { 244 244 SNOR_HWCAPS_READ_1_1_2, 245 - BFPT_DWORD(1), BIT(16), /* Supported bit */ 246 - BFPT_DWORD(4), 0, /* Settings */ 245 + SFDP_DWORD(1), BIT(16), /* Supported bit */ 246 + SFDP_DWORD(4), 0, /* Settings */ 247 247 SNOR_PROTO_1_1_2, 248 248 }, 249 249 250 250 /* Fast Read 1-2-2 */ 251 251 { 252 252 SNOR_HWCAPS_READ_1_2_2, 253 - BFPT_DWORD(1), BIT(20), /* Supported bit */ 254 - BFPT_DWORD(4), 16, /* Settings */ 253 + SFDP_DWORD(1), BIT(20), /* Supported bit */ 254 + SFDP_DWORD(4), 16, /* Settings */ 255 255 SNOR_PROTO_1_2_2, 256 256 }, 257 257 258 258 /* Fast Read 2-2-2 */ 259 259 { 260 260 SNOR_HWCAPS_READ_2_2_2, 261 - BFPT_DWORD(5), BIT(0), /* Supported bit */ 262 - BFPT_DWORD(6), 16, /* Settings */ 261 + SFDP_DWORD(5), BIT(0), /* Supported bit */ 262 + SFDP_DWORD(6), 16, /* Settings */ 263 263 SNOR_PROTO_2_2_2, 264 264 }, 265 265 266 266 /* Fast Read 1-1-4 */ 267 267 { 268 268 SNOR_HWCAPS_READ_1_1_4, 269 - BFPT_DWORD(1), BIT(22), /* Supported bit */ 270 - BFPT_DWORD(3), 16, /* Settings */ 269 + SFDP_DWORD(1), BIT(22), /* Supported bit */ 270 + SFDP_DWORD(3), 16, /* Settings */ 271 271 SNOR_PROTO_1_1_4, 272 272 }, 273 273 274 274 /* Fast Read 1-4-4 */ 275 275 { 276 276 SNOR_HWCAPS_READ_1_4_4, 277 - BFPT_DWORD(1), BIT(21), /* Supported bit */ 278 - BFPT_DWORD(3), 0, /* Settings */ 277 + SFDP_DWORD(1), BIT(21), /* Supported bit */ 278 + SFDP_DWORD(3), 0, /* Settings */ 279 279 SNOR_PROTO_1_4_4, 280 280 }, 281 281 282 282 /* Fast Read 4-4-4 */ 283 283 { 284 284 SNOR_HWCAPS_READ_4_4_4, 285 - BFPT_DWORD(5), BIT(4), /* Supported bit */ 286 - BFPT_DWORD(7), 16, /* Settings */ 285 + SFDP_DWORD(5), BIT(4), /* Supported bit */ 286 + SFDP_DWORD(7), 16, /* Settings */ 287 287 SNOR_PROTO_4_4_4, 288 288 }, 289 289 }; 290 290 291 291 static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = { 292 292 /* Erase Type 1 in DWORD8 bits[15:0] */ 293 - {BFPT_DWORD(8), 0}, 293 + {SFDP_DWORD(8), 0}, 294 294 295 295 /* Erase Type 2 in DWORD8 bits[31:16] */ 296 - {BFPT_DWORD(8), 16}, 296 + {SFDP_DWORD(8), 16}, 297 297 298 298 /* Erase Type 3 in DWORD9 bits[15:0] */ 299 - {BFPT_DWORD(9), 0}, 299 + {SFDP_DWORD(9), 0}, 300 300 301 301 /* Erase Type 4 in DWORD9 bits[31:16] */ 302 - {BFPT_DWORD(9), 16}, 302 + {SFDP_DWORD(9), 16}, 303 303 }; 304 304 305 305 /** ··· 458 458 le32_to_cpu_array(bfpt.dwords, BFPT_DWORD_MAX); 459 459 460 460 /* Number of address bytes. */ 461 - switch (bfpt.dwords[BFPT_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) { 461 + switch (bfpt.dwords[SFDP_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) { 462 462 case BFPT_DWORD1_ADDRESS_BYTES_3_ONLY: 463 463 case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4: 464 464 params->addr_nbytes = 3; ··· 475 475 } 476 476 477 477 /* Flash Memory Density (in bits). */ 478 - val = bfpt.dwords[BFPT_DWORD(2)]; 478 + val = bfpt.dwords[SFDP_DWORD(2)]; 479 479 if (val & BIT(31)) { 480 480 val &= ~BIT(31); 481 481 ··· 555 555 return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); 556 556 557 557 /* Page size: this field specifies 'N' so the page size = 2^N bytes. */ 558 - val = bfpt.dwords[BFPT_DWORD(11)]; 558 + val = bfpt.dwords[SFDP_DWORD(11)]; 559 559 val &= BFPT_DWORD11_PAGE_SIZE_MASK; 560 560 val >>= BFPT_DWORD11_PAGE_SIZE_SHIFT; 561 561 params->page_size = 1U << val; 562 562 563 563 /* Quad Enable Requirements. */ 564 - switch (bfpt.dwords[BFPT_DWORD(15)] & BFPT_DWORD15_QER_MASK) { 564 + switch (bfpt.dwords[SFDP_DWORD(15)] & BFPT_DWORD15_QER_MASK) { 565 565 case BFPT_DWORD15_QER_NONE: 566 566 params->quad_enable = NULL; 567 567 break; ··· 608 608 } 609 609 610 610 /* Soft Reset support. */ 611 - if (bfpt.dwords[BFPT_DWORD(16)] & BFPT_DWORD16_SWRST_EN_RST) 611 + if (bfpt.dwords[SFDP_DWORD(16)] & BFPT_DWORD16_SWRST_EN_RST) 612 612 nor->flags |= SNOR_F_SOFT_RESET; 613 613 614 614 /* Stop here if not JESD216 rev C or later. */ ··· 616 616 return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt); 617 617 618 618 /* 8D-8D-8D command extension. */ 619 - switch (bfpt.dwords[BFPT_DWORD(18)] & BFPT_DWORD18_CMD_EXT_MASK) { 619 + switch (bfpt.dwords[SFDP_DWORD(18)] & BFPT_DWORD18_CMD_EXT_MASK) { 620 620 case BFPT_DWORD18_CMD_EXT_REP: 621 621 nor->cmd_ext_type = SPI_NOR_EXT_REPEAT; 622 622 break; ··· 875 875 */ 876 876 for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) 877 877 if (!(regions_erase_type & BIT(erase[i].idx))) 878 - spi_nor_set_erase_type(&erase[i], 0, 0xFF); 878 + spi_nor_mask_erase_type(&erase[i]); 879 879 880 880 return 0; 881 881 } ··· 1004 1004 1005 1005 discard_hwcaps |= read->hwcaps; 1006 1006 if ((params->hwcaps.mask & read->hwcaps) && 1007 - (dwords[0] & read->supported_bit)) 1007 + (dwords[SFDP_DWORD(1)] & read->supported_bit)) 1008 1008 read_hwcaps |= read->hwcaps; 1009 1009 } 1010 1010 ··· 1023 1023 * authority for specifying Page Program support. 1024 1024 */ 1025 1025 discard_hwcaps |= program->hwcaps; 1026 - if (dwords[0] & program->supported_bit) 1026 + if (dwords[SFDP_DWORD(1)] & program->supported_bit) 1027 1027 pp_hwcaps |= program->hwcaps; 1028 1028 } 1029 1029 ··· 1035 1035 for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) { 1036 1036 const struct sfdp_4bait *erase = &erases[i]; 1037 1037 1038 - if (dwords[0] & erase->supported_bit) 1038 + if (dwords[SFDP_DWORD(1)] & erase->supported_bit) 1039 1039 erase_mask |= BIT(i); 1040 1040 } 1041 1041 ··· 1086 1086 1087 1087 for (i = 0; i < SNOR_ERASE_TYPE_MAX; i++) { 1088 1088 if (erase_mask & BIT(i)) 1089 - erase_type[i].opcode = (dwords[1] >> 1089 + erase_type[i].opcode = (dwords[SFDP_DWORD(2)] >> 1090 1090 erase_type[i].idx * 8) & 0xFF; 1091 1091 else 1092 - spi_nor_set_erase_type(&erase_type[i], 0u, 0xFF); 1092 + spi_nor_mask_erase_type(&erase_type[i]); 1093 1093 } 1094 1094 1095 1095 /* ··· 1145 1145 le32_to_cpu_array(dwords, profile1_header->length); 1146 1146 1147 1147 /* Get 8D-8D-8D fast read opcode and dummy cycles. */ 1148 - opcode = FIELD_GET(PROFILE1_DWORD1_RD_FAST_CMD, dwords[0]); 1148 + opcode = FIELD_GET(PROFILE1_DWORD1_RD_FAST_CMD, dwords[SFDP_DWORD(1)]); 1149 1149 1150 1150 /* Set the Read Status Register dummy cycles and dummy address bytes. */ 1151 - if (dwords[0] & PROFILE1_DWORD1_RDSR_DUMMY) 1151 + if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_DUMMY) 1152 1152 nor->params->rdsr_dummy = 8; 1153 1153 else 1154 1154 nor->params->rdsr_dummy = 4; 1155 1155 1156 - if (dwords[0] & PROFILE1_DWORD1_RDSR_ADDR_BYTES) 1156 + if (dwords[SFDP_DWORD(1)] & PROFILE1_DWORD1_RDSR_ADDR_BYTES) 1157 1157 nor->params->rdsr_addr_nbytes = 4; 1158 1158 else 1159 1159 nor->params->rdsr_addr_nbytes = 0; ··· 1167 1167 * Default to PROFILE1_DUMMY_DEFAULT if we don't find anything, and let 1168 1168 * flashes set the correct value if needed in their fixup hooks. 1169 1169 */ 1170 - dummy = FIELD_GET(PROFILE1_DWORD4_DUMMY_200MHZ, dwords[3]); 1170 + dummy = FIELD_GET(PROFILE1_DWORD4_DUMMY_200MHZ, dwords[SFDP_DWORD(4)]); 1171 1171 if (!dummy) 1172 - dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_166MHZ, dwords[4]); 1172 + dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_166MHZ, 1173 + dwords[SFDP_DWORD(5)]); 1173 1174 if (!dummy) 1174 - dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_133MHZ, dwords[4]); 1175 + dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_133MHZ, 1176 + dwords[SFDP_DWORD(5)]); 1175 1177 if (!dummy) 1176 - dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_100MHZ, dwords[4]); 1178 + dummy = FIELD_GET(PROFILE1_DWORD5_DUMMY_100MHZ, 1179 + dwords[SFDP_DWORD(5)]); 1177 1180 if (!dummy) 1178 1181 dev_dbg(nor->dev, 1179 1182 "Can't find dummy cycles from Profile 1.0 table\n"); ··· 1231 1228 1232 1229 le32_to_cpu_array(dwords, sccr_header->length); 1233 1230 1234 - if (FIELD_GET(SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE, dwords[22])) 1231 + if (FIELD_GET(SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE, 1232 + dwords[SFDP_DWORD(22)])) 1235 1233 nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE; 1236 1234 1237 1235 out:
+4 -5
drivers/mtd/spi-nor/sfdp.h
··· 13 13 #define SFDP_JESD216A_MINOR 5 14 14 #define SFDP_JESD216B_MINOR 6 15 15 16 + /* SFDP DWORDS are indexed from 1 but C arrays are indexed from 0. */ 17 + #define SFDP_DWORD(i) ((i) - 1) 18 + 16 19 /* Basic Flash Parameter Table */ 17 20 18 - /* 19 - * JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs. 20 - * They are indexed from 1 but C arrays are indexed from 0. 21 - */ 22 - #define BFPT_DWORD(i) ((i) - 1) 21 + /* JESD216 rev D defines a Basic Flash Parameter Table of 20 DWORDs. */ 23 22 #define BFPT_DWORD_MAX 20 24 23 25 24 struct sfdp_bfpt {
+16 -11
drivers/mtd/spi-nor/spansion.c
··· 15 15 #define SPINOR_OP_RD_ANY_REG 0x65 /* Read any register */ 16 16 #define SPINOR_OP_WR_ANY_REG 0x71 /* Write any register */ 17 17 #define SPINOR_REG_CYPRESS_CFR1V 0x00800002 18 - #define SPINOR_REG_CYPRESS_CFR1V_QUAD_EN BIT(1) /* Quad Enable */ 18 + #define SPINOR_REG_CYPRESS_CFR1_QUAD_EN BIT(1) /* Quad Enable */ 19 19 #define SPINOR_REG_CYPRESS_CFR2V 0x00800003 20 - #define SPINOR_REG_CYPRESS_CFR2V_MEMLAT_11_24 0xb 20 + #define SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24 0xb 21 21 #define SPINOR_REG_CYPRESS_CFR3V 0x00800004 22 - #define SPINOR_REG_CYPRESS_CFR3V_PGSZ BIT(4) /* Page size. */ 22 + #define SPINOR_REG_CYPRESS_CFR3_PGSZ BIT(4) /* Page size. */ 23 23 #define SPINOR_REG_CYPRESS_CFR5V 0x00800006 24 - #define SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_EN 0x3 25 - #define SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_DS 0 24 + #define SPINOR_REG_CYPRESS_CFR5_BIT6 BIT(6) 25 + #define SPINOR_REG_CYPRESS_CFR5_DDR BIT(1) 26 + #define SPINOR_REG_CYPRESS_CFR5_OPI BIT(0) 27 + #define SPINOR_REG_CYPRESS_CFR5_OCT_DTR_EN \ 28 + (SPINOR_REG_CYPRESS_CFR5_BIT6 | SPINOR_REG_CYPRESS_CFR5_DDR | \ 29 + SPINOR_REG_CYPRESS_CFR5_OPI) 30 + #define SPINOR_REG_CYPRESS_CFR5_OCT_DTR_DS SPINOR_REG_CYPRESS_CFR5_BIT6 26 31 #define SPINOR_OP_CYPRESS_RD_FAST 0xee 27 32 28 33 /* Cypress SPI NOR flash operations. */ ··· 57 52 u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; 58 53 59 54 /* Use 24 dummy cycles for memory array reads. */ 60 - *buf = SPINOR_REG_CYPRESS_CFR2V_MEMLAT_11_24; 55 + *buf = SPINOR_REG_CYPRESS_CFR2_MEMLAT_11_24; 61 56 op = (struct spi_mem_op) 62 57 CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes, 63 58 SPINOR_REG_CYPRESS_CFR2V, 1, buf); ··· 69 64 nor->read_dummy = 24; 70 65 71 66 /* Set the octal and DTR enable bits. */ 72 - buf[0] = SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_EN; 67 + buf[0] = SPINOR_REG_CYPRESS_CFR5_OCT_DTR_EN; 73 68 op = (struct spi_mem_op) 74 69 CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes, 75 70 SPINOR_REG_CYPRESS_CFR5V, 1, buf); ··· 103 98 * in 8D-8D-8D mode. Since there is no register at the next location, 104 99 * just initialize the value to 0 and let the transaction go on. 105 100 */ 106 - buf[0] = SPINOR_REG_CYPRESS_CFR5V_OCT_DTR_DS; 101 + buf[0] = SPINOR_REG_CYPRESS_CFR5_OCT_DTR_DS; 107 102 buf[1] = 0; 108 103 op = (struct spi_mem_op) 109 104 CYPRESS_NOR_WR_ANY_REG_OP(nor->addr_nbytes, ··· 155 150 if (ret) 156 151 return ret; 157 152 158 - if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR1V_QUAD_EN) 153 + if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR1_QUAD_EN) 159 154 return 0; 160 155 161 156 /* Update the Quad Enable bit. */ 162 - nor->bouncebuf[0] |= SPINOR_REG_CYPRESS_CFR1V_QUAD_EN; 157 + nor->bouncebuf[0] |= SPINOR_REG_CYPRESS_CFR1_QUAD_EN; 163 158 op = (struct spi_mem_op) 164 159 CYPRESS_NOR_WR_ANY_REG_OP(addr_mode_nbytes, 165 160 SPINOR_REG_CYPRESS_CFR1V, 1, ··· 210 205 if (ret) 211 206 return ret; 212 207 213 - if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3V_PGSZ) 208 + if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3_PGSZ) 214 209 nor->params->page_size = 512; 215 210 else 216 211 nor->params->page_size = 256;
+21
include/linux/mtd/rawnand.h
··· 67 67 68 68 /* Extended commands for large page devices */ 69 69 #define NAND_CMD_READSTART 0x30 70 + #define NAND_CMD_READCACHESEQ 0x31 71 + #define NAND_CMD_READCACHEEND 0x3f 70 72 #define NAND_CMD_RNDOUTSTART 0xE0 71 73 #define NAND_CMD_CACHEDPROG 0x15 72 74 ··· 1096 1094 * 1097 1095 * @lock: lock used to serialize accesses to the NAND controller 1098 1096 * @ops: NAND controller operations. 1097 + * @supported_op: NAND controller known-to-be-supported operations, 1098 + * only writable by the core after initial checking. 1099 + * @supported_op.data_only_read: The controller supports reading more data from 1100 + * the bus without restarting an entire read operation nor 1101 + * changing the column. 1102 + * @supported_op.cont_read: The controller supports sequential cache reads. 1099 1103 */ 1100 1104 struct nand_controller { 1101 1105 struct mutex lock; 1102 1106 const struct nand_controller_ops *ops; 1107 + struct { 1108 + unsigned int data_only_read: 1; 1109 + unsigned int cont_read: 1; 1110 + } supported_op; 1103 1111 }; 1104 1112 1105 1113 static inline void nand_controller_init(struct nand_controller *nfc) ··· 1260 1248 * @read_retries: The number of read retry modes supported 1261 1249 * @secure_regions: Structure containing the secure regions info 1262 1250 * @nr_secure_regions: Number of secure regions 1251 + * @cont_read: Sequential page read internals 1252 + * @cont_read.ongoing: Whether a continuous read is ongoing or not 1253 + * @cont_read.first_page: Start of the continuous read operation 1254 + * @cont_read.last_page: End of the continuous read operation 1263 1255 * @controller: The hardware controller structure which is shared among multiple 1264 1256 * independent devices 1265 1257 * @ecc: The ECC controller structure ··· 1316 1300 int read_retries; 1317 1301 struct nand_secure_region *secure_regions; 1318 1302 u8 nr_secure_regions; 1303 + struct { 1304 + bool ongoing; 1305 + unsigned int first_page; 1306 + unsigned int last_page; 1307 + } cont_read; 1319 1308 1320 1309 /* Externals */ 1321 1310 struct nand_controller *controller;
+1
include/linux/mtd/spinand.h
··· 260 260 }; 261 261 262 262 /* SPI NAND manufacturers */ 263 + extern const struct spinand_manufacturer alliancememory_spinand_manufacturer; 263 264 extern const struct spinand_manufacturer ato_spinand_manufacturer; 264 265 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer; 265 266 extern const struct spinand_manufacturer macronix_spinand_manufacturer;