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

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

Pull MTD updates from Richard Weinberger:
"MTD core changes:
- New AFS partition parser
- Update MAINTAINERS entry
- Use of fall-throughs markers

NAND core changes:
- Support having the bad block markers in either the first, second or
last page of a block. The combination of all three location is now
possible.
- Constification of NAND_OP_PARSER(_PATTERN) elements.
- Generic NAND DT bindings changed to yaml format (can be used to
check the proposed bindings. First platform to be fully supported:
sunxi.
- Stopped using several legacy hooks.
- Preparation to use the generic NAND layer with the addition of
several helpers and the removal of the struct nand_chip from
generic functions.
- Kconfig cleanup to prepare the introduction of external ECC engines
support.
- Fallthrough comments.
- Introduction of the SPI-mem dirmap API for SPI-NAND devices.

Raw NAND controller drivers changes:
- nandsim:
- Switch to ->exec-op().
- meson:
- Misc cleanups and fixes.
- New OOB layout.
- Sunxi:
- A23/A33 NAND DMA support.
- Ingenic:
- Full reorganization and cleanup.
- Clear separation between NAND controller and ECC engine.
- Support JZ4740 an JZ4725B.
- Denali:
- Clear controller/chip separation.
- ->exec_op() migration.
- Various cleanups.
- fsl_elbc:
- Enable software ECC support.
- Atmel:
- Sam9x60 support.
- GPMI:
- Introduce the GPMI_IS_MXS() macro.
- Various trivial/spelling/coding style fixes.

SPI NOR core changes:
- Print all JEDEC ID bytes on error
- Fix comment of spi_nor_find_best_erase_type()
- Add region locking flags for s25fl512s

SPI NOR controller drivers changes:
- intel-spi:
- Avoid crossing 4K address boundary on read/write
- Add support for Intel Comet Lake SPI serial flash"

* tag 'mtd/for-5.2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (120 commits)
mtd: part: fix incorrect format specifier for an unsigned long long
mtd: lpddr_cmds: Mark expected switch fall-through
mtd: phram: Mark expected switch fall-throughs
mtd: cfi_cmdset_0002: Mark expected switch fall-throughs
mtd: cfi_util: mark expected switch fall-throughs
MAINTAINERS: MTD Git repository is hosted on kernel.org
MAINTAINERS: Update jffs2 entry
mtd: afs: add v2 partition parsing
mtd: afs: factor the IIS read into partition parser
mtd: afs: factor footer parsing into the v1 part parsing
mtd: factor out v1 partition parsing
mtd: afs: simplify partition detection
mtd: afs: simplify partition parsing
mtd: partitions: Add OF support to AFS partitions
mtd: partitions: Add AFS partitions DT bindings
mtd: afs: Move AFS partition parser to parsers subdir
mtd: maps: Make uclinux_ram_map static
mtd: maps: Allow MTD_PHYSMAP with MTD_RAM
MAINTAINERS: Add myself as MTD maintainer
MAINTAINERS: Remove my name from the MTD and NAND entries
...

+4976 -3075
+1
Documentation/devicetree/bindings/memory-controllers/atmel,ebi.txt
··· 15 15 "atmel,at91sam9g45-ebi" 16 16 "atmel,at91sam9x5-ebi" 17 17 "atmel,sama5d3-ebi" 18 + "microchip,sam9x60-ebi" 18 19 19 20 - reg: Contains offset/length value for EBI memory mapping. 20 21 This property might contain several entries if the EBI
+97
Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/allwinner,sun4i-a10-nand.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Allwinner A10 NAND Controller Device Tree Bindings 8 + 9 + allOf: 10 + - $ref: "nand-controller.yaml" 11 + 12 + maintainers: 13 + - Chen-Yu Tsai <wens@csie.org> 14 + - Maxime Ripard <maxime.ripard@bootlin.com> 15 + 16 + properties: 17 + "#address-cells": true 18 + "#size-cells": true 19 + 20 + compatible: 21 + enum: 22 + - allwinner,sun4i-a10-nand 23 + - allwinner,sun8i-a23-nand-controller 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + clocks: 31 + items: 32 + - description: Bus Clock 33 + - description: Module Clock 34 + 35 + clock-names: 36 + items: 37 + - const: ahb 38 + - const: mod 39 + 40 + resets: 41 + maxItems: 1 42 + 43 + reset-names: 44 + const: ahb 45 + 46 + dmas: 47 + maxItems: 1 48 + 49 + dma-names: 50 + const: rxtx 51 + 52 + pinctrl-names: true 53 + 54 + patternProperties: 55 + "^pinctrl-[0-9]+$": true 56 + 57 + "^nand@[a-f0-9]+$": 58 + properties: 59 + reg: 60 + maxItems: 1 61 + minimum: 0 62 + maximum: 7 63 + 64 + nand-ecc-mode: true 65 + 66 + nand-ecc-algo: 67 + const: bch 68 + 69 + nand-ecc-step-size: 70 + enum: [ 512, 1024 ] 71 + 72 + nand-ecc-strength: 73 + maximum: 80 74 + 75 + allwinner,rb: 76 + description: 77 + Contains the native Ready/Busy IDs. 78 + allOf: 79 + - $ref: /schemas/types.yaml#/definitions/uint32-array 80 + - minItems: 1 81 + maxItems: 2 82 + items: 83 + minimum: 0 84 + maximum: 1 85 + 86 + additionalProperties: false 87 + 88 + required: 89 + - compatible 90 + - reg 91 + - interrupts 92 + - clocks 93 + - clock-names 94 + 95 + additionalProperties: false 96 + 97 + ...
+1
Documentation/devicetree/bindings/mtd/atmel-nand.txt
··· 14 14 "atmel,at91sam9261-nand-controller" 15 15 "atmel,at91sam9g45-nand-controller" 16 16 "atmel,sama5d3-nand-controller" 17 + "microchip,sam9x60-nand-controller" 17 18 - ranges: empty ranges property to forward EBI ranges definitions. 18 19 - #address-cells: should be set to 2. 19 20 - #size-cells: should be set to 1.
+26 -12
Documentation/devicetree/bindings/mtd/denali-nand.txt
··· 7 7 "socionext,uniphier-denali-nand-v5b" - for Socionext UniPhier (v5b) 8 8 - reg : should contain registers location and length for data and reg. 9 9 - reg-names: Should contain the reg names "nand_data" and "denali_reg" 10 + - #address-cells: should be 1. The cell encodes the chip select connection. 11 + - #size-cells : should be 0. 10 12 - interrupts : The interrupt number. 11 13 - clocks: should contain phandle of the controller core clock, the bus 12 14 interface clock, and the ECC circuit clock. 13 15 - clock-names: should contain "nand", "nand_x", "ecc" 14 16 15 - Optional properties: 16 - - nand-ecc-step-size: see nand.txt for details. If present, the value must be 17 - 512 for "altr,socfpga-denali-nand" 18 - 1024 for "socionext,uniphier-denali-nand-v5a" 19 - 1024 for "socionext,uniphier-denali-nand-v5b" 20 - - nand-ecc-strength: see nand.txt for details. Valid values are: 21 - 8, 15 for "altr,socfpga-denali-nand" 22 - 8, 16, 24 for "socionext,uniphier-denali-nand-v5a" 23 - 8, 16 for "socionext,uniphier-denali-nand-v5b" 24 - - nand-ecc-maximize: see nand.txt for details 17 + Sub-nodes: 18 + Sub-nodes represent available NAND chips. 25 19 26 - The device tree may optionally contain sub-nodes describing partitions of the 20 + Required properties: 21 + - reg: should contain the bank ID of the controller to which each chip 22 + select is connected. 23 + 24 + Optional properties: 25 + - nand-ecc-step-size: see nand.txt for details. 26 + If present, the value must be 27 + 512 for "altr,socfpga-denali-nand" 28 + 1024 for "socionext,uniphier-denali-nand-v5a" 29 + 1024 for "socionext,uniphier-denali-nand-v5b" 30 + - nand-ecc-strength: see nand.txt for details. Valid values are: 31 + 8, 15 for "altr,socfpga-denali-nand" 32 + 8, 16, 24 for "socionext,uniphier-denali-nand-v5a" 33 + 8, 16 for "socionext,uniphier-denali-nand-v5b" 34 + - nand-ecc-maximize: see nand.txt for details 35 + 36 + The chip nodes may optionally contain sub-nodes describing partitions of the 27 37 address space. See partition.txt for more detail. 28 38 29 39 Examples: 30 40 31 41 nand: nand@ff900000 { 32 42 #address-cells = <1>; 33 - #size-cells = <1>; 43 + #size-cells = <0>; 34 44 compatible = "altr,socfpga-denali-nand"; 35 45 reg = <0xff900000 0x20>, <0xffb80000 0x1000>; 36 46 reg-names = "nand_data", "denali_reg"; 37 47 clocks = <&nand_clk>, <&nand_x_clk>, <&nand_ecc_clk>; 38 48 clock-names = "nand", "nand_x", "ecc"; 39 49 interrupts = <0 144 4>; 50 + 51 + nand@0 { 52 + reg = <0>; 53 + } 40 54 };
+18 -12
Documentation/devicetree/bindings/mtd/ingenic,jz4780-nand.txt
··· 1 - * Ingenic JZ4780 NAND/BCH 1 + * Ingenic JZ4780 NAND/ECC 2 2 3 3 This file documents the device tree bindings for NAND flash devices on the 4 4 JZ4780. NAND devices are connected to the NEMC controller (described in ··· 6 6 be children of the NEMC node. 7 7 8 8 Required NAND controller device properties: 9 - - compatible: Should be set to "ingenic,jz4780-nand". 9 + - compatible: Should be one of: 10 + * ingenic,jz4740-nand 11 + * ingenic,jz4725b-nand 12 + * ingenic,jz4780-nand 10 13 - reg: For each bank with a NAND chip attached, should specify a bank number, 11 14 an offset of 0 and a size of 0x1000000 (i.e. the whole NEMC bank). 12 15 13 16 Optional NAND controller device properties: 14 - - ingenic,bch-controller: To make use of the hardware BCH controller, this 15 - property must contain a phandle for the BCH controller node. The required 17 + - ecc-engine: To make use of the hardware ECC controller, this 18 + property must contain a phandle for the ECC controller node. The required 16 19 properties for this node are described below. If this is not specified, 17 - software BCH will be used instead. 20 + software ECC will be used instead. 18 21 19 22 Optional children nodes: 20 23 - Individual NAND chips are children of the NAND controller node. ··· 48 45 #address-cells = <1>; 49 46 #size-cells = <0>; 50 47 51 - ingenic,bch-controller = <&bch>; 48 + ecc-engine = <&bch>; 52 49 53 50 nand@1 { 54 51 reg = <1>; ··· 70 67 }; 71 68 }; 72 69 73 - The BCH controller is a separate SoC component used for error correction on 70 + The ECC controller is a separate SoC component used for error correction on 74 71 NAND devices. The following is a description of the device properties for a 75 - BCH controller. 72 + ECC controller. 76 73 77 - Required BCH properties: 78 - - compatible: Should be set to "ingenic,jz4780-bch". 79 - - reg: Should specify the BCH controller registers location and length. 80 - - clocks: Clock for the BCH controller. 74 + Required ECC properties: 75 + - compatible: Should be one of: 76 + * ingenic,jz4740-ecc 77 + * ingenic,jz4725b-bch 78 + * ingenic,jz4780-bch 79 + - reg: Should specify the ECC controller registers location and length. 80 + - clocks: Clock for the ECC controller. 81 81 82 82 Example: 83 83
+16
Documentation/devicetree/bindings/mtd/mtd-physmap.txt
··· 96 96 bank-width = <2>; 97 97 }; 98 98 99 + An example using gpio-addrs 100 + 101 + flash@20000000 { 102 + #address-cells = <1>; 103 + #size-cells = <1>; 104 + compatible = "cfi-flash", "jedec-flash"; 105 + reg = <0x20000000 0x02000000>; 106 + ranges = <0 0x00000000 0x02000000 107 + 1 0x02000000 0x02000000>; 108 + bank-width = <2>; 109 + addr-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; 110 + partition@0 { 111 + label = "test-part1"; 112 + reg = <0 0x04000000>; 113 + }; 114 + };
+143
Documentation/devicetree/bindings/mtd/nand-controller.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/mtd/nand-controller.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NAND Chip and NAND Controller Generic Binding 8 + 9 + maintainers: 10 + - Miquel Raynal <miquel.raynal@bootlin.com> 11 + - Richard Weinberger <richard@nod.at> 12 + 13 + description: | 14 + The NAND controller should be represented with its own DT node, and 15 + all NAND chips attached to this controller should be defined as 16 + children nodes of the NAND controller. This representation should be 17 + enforced even for simple controllers supporting only one chip. 18 + 19 + The ECC strength and ECC step size properties define the user 20 + desires in terms of correction capability of a controller. Together, 21 + they request the ECC engine to correct {strength} bit errors per 22 + {size} bytes. 23 + 24 + The interpretation of these parameters is implementation-defined, so 25 + not all implementations must support all possible 26 + combinations. However, implementations are encouraged to further 27 + specify the value(s) they support. 28 + 29 + properties: 30 + $nodename: 31 + pattern: "^nand-controller(@.*)?" 32 + 33 + "#address-cells": 34 + const: 1 35 + 36 + "#size-cells": 37 + const: 0 38 + 39 + ranges: true 40 + 41 + patternProperties: 42 + "^nand@[a-f0-9]$": 43 + properties: 44 + reg: 45 + description: 46 + Contains the native Ready/Busy IDs. 47 + 48 + nand-ecc-mode: 49 + allOf: 50 + - $ref: /schemas/types.yaml#/definitions/string 51 + - enum: [ none, soft, hw, hw_syndrome, hw_oob_first, on-die ] 52 + description: 53 + Desired ECC engine, either hardware (most of the time 54 + embedded in the NAND controller) or software correction 55 + (Linux will handle the calculations). soft_bch is deprecated 56 + and should be replaced by soft and nand-ecc-algo. 57 + 58 + nand-ecc-algo: 59 + allOf: 60 + - $ref: /schemas/types.yaml#/definitions/string 61 + - enum: [ hamming, bch, rs ] 62 + description: 63 + Desired ECC algorithm. 64 + 65 + nand-bus-width: 66 + allOf: 67 + - $ref: /schemas/types.yaml#/definitions/uint32 68 + - enum: [ 8, 16 ] 69 + - default: 8 70 + description: 71 + Bus width to the NAND chip 72 + 73 + nand-on-flash-bbt: 74 + $ref: /schemas/types.yaml#/definitions/flag 75 + description: 76 + With this property, the OS will search the device for a Bad 77 + Block Table (BBT). If not found, it will create one, reserve 78 + a few blocks at the end of the device to store it and update 79 + it as the device ages. Otherwise, the out-of-band area of a 80 + few pages of all the blocks will be scanned at boot time to 81 + find Bad Block Markers (BBM). These markers will help to 82 + build a volatile BBT in RAM. 83 + 84 + nand-ecc-strength: 85 + allOf: 86 + - $ref: /schemas/types.yaml#/definitions/uint32 87 + - minimum: 1 88 + description: 89 + Maximum number of bits that can be corrected per ECC step. 90 + 91 + nand-ecc-step-size: 92 + allOf: 93 + - $ref: /schemas/types.yaml#/definitions/uint32 94 + - minimum: 1 95 + description: 96 + Number of data bytes covered by a single ECC step. 97 + 98 + nand-ecc-maximize: 99 + $ref: /schemas/types.yaml#/definitions/flag 100 + description: 101 + Whether or not the ECC strength should be maximized. The 102 + maximum ECC strength is both controller and chip 103 + dependent. The ECC engine has to select the ECC config 104 + providing the best strength and taking the OOB area size 105 + constraint into account. This is particularly useful when 106 + only the in-band area is used by the upper layers, and you 107 + want to make your NAND as reliable as possible. 108 + 109 + nand-is-boot-medium: 110 + $ref: /schemas/types.yaml#/definitions/flag 111 + description: 112 + Whether or not the NAND chip is a boot medium. Drivers might 113 + use this information to select ECC algorithms supported by 114 + the boot ROM or similar restrictions. 115 + 116 + nand-rb: 117 + $ref: /schemas/types.yaml#/definitions/uint32-array 118 + description: 119 + Contains the native Ready/Busy IDs. 120 + 121 + required: 122 + - reg 123 + 124 + required: 125 + - "#address-cells" 126 + - "#size-cells" 127 + 128 + examples: 129 + - | 130 + nand-controller { 131 + #address-cells = <1>; 132 + #size-cells = <0>; 133 + 134 + /* controller specific properties */ 135 + 136 + nand@0 { 137 + reg = <0>; 138 + nand-ecc-mode = "soft"; 139 + nand-ecc-algo = "bch"; 140 + 141 + /* controller specific properties */ 142 + }; 143 + };
-75
Documentation/devicetree/bindings/mtd/nand.txt
··· 1 - * NAND chip and NAND controller generic binding 2 - 3 - NAND controller/NAND chip representation: 4 - 5 - The NAND controller should be represented with its own DT node, and all 6 - NAND chips attached to this controller should be defined as children nodes 7 - of the NAND controller. This representation should be enforced even for 8 - simple controllers supporting only one chip. 9 - 10 - Mandatory NAND controller properties: 11 - - #address-cells: depends on your controller. Should at least be 1 to 12 - encode the CS line id. 13 - - #size-cells: depends on your controller. Put zero unless you need a 14 - mapping between CS lines and dedicated memory regions 15 - 16 - Optional NAND controller properties 17 - - ranges: only needed if you need to define a mapping between CS lines and 18 - memory regions 19 - 20 - Optional NAND chip properties: 21 - 22 - - nand-ecc-mode : String, operation mode of the NAND ecc mode. 23 - Supported values are: "none", "soft", "hw", "hw_syndrome", 24 - "hw_oob_first", "on-die". 25 - Deprecated values: 26 - "soft_bch": use "soft" and nand-ecc-algo instead 27 - - nand-ecc-algo: string, algorithm of NAND ECC. 28 - Valid values are: "hamming", "bch", "rs". 29 - - nand-bus-width : 8 or 16 bus width if not present 8 30 - - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false 31 - 32 - - nand-ecc-strength: integer representing the number of bits to correct 33 - per ECC step. 34 - 35 - - nand-ecc-step-size: integer representing the number of data bytes 36 - that are covered by a single ECC step. 37 - 38 - - nand-ecc-maximize: boolean used to specify that you want to maximize ECC 39 - strength. The maximum ECC strength is both controller and 40 - chip dependent. The controller side has to select the ECC 41 - config providing the best strength and taking the OOB area 42 - size constraint into account. 43 - This is particularly useful when only the in-band area is 44 - used by the upper layers, and you want to make your NAND 45 - as reliable as possible. 46 - - nand-is-boot-medium: Whether the NAND chip is a boot medium. Drivers might use 47 - this information to select ECC algorithms supported by 48 - the boot ROM or similar restrictions. 49 - 50 - - nand-rb: shall contain the native Ready/Busy ids. 51 - 52 - The ECC strength and ECC step size properties define the correction capability 53 - of a controller. Together, they say a controller can correct "{strength} bit 54 - errors per {size} bytes". 55 - 56 - The interpretation of these parameters is implementation-defined, so not all 57 - implementations must support all possible combinations. However, implementations 58 - are encouraged to further specify the value(s) they support. 59 - 60 - Example: 61 - 62 - nand-controller { 63 - #address-cells = <1>; 64 - #size-cells = <0>; 65 - 66 - /* controller specific properties */ 67 - 68 - nand@0 { 69 - reg = <0>; 70 - nand-ecc-mode = "soft"; 71 - nand-ecc-algo = "bch"; 72 - 73 - /* controller specific properties */ 74 - }; 75 - };
+17
Documentation/devicetree/bindings/mtd/partitions/arm,arm-firmware-suite.txt
··· 1 + ARM AFS - ARM Firmware Suite Partitions 2 + ======================================= 3 + 4 + The ARM Firmware Suite is a flash partitioning system found on the 5 + ARM reference designs: Integrator AP, Integrator CP, Versatile AB, 6 + Versatile PB, the RealView family, Versatile Express and Juno. 7 + 8 + Required properties: 9 + - compatible : (required) must be "arm,arm-firmware-suite" 10 + 11 + Example: 12 + 13 + flash@0 { 14 + partitions { 15 + compatible = "arm,arm-firmware-suite"; 16 + }; 17 + };
+24
Documentation/devicetree/bindings/mtd/partitions/brcm,bcm963xx-cfe-nor-partitions.txt
··· 1 + Broadcom BCM963XX CFE Loader NOR Flash Partitions 2 + ================================================= 3 + 4 + Most Broadcom BCM63XX SoC based devices follow the Broadcom reference layout for 5 + NOR. The first erase block used for the CFE bootloader, the last for an 6 + NVRAM partition, and the remainder in-between for one to two firmware partitions 7 + at fixed offsets. A valid firmware partition is identified by the ImageTag 8 + header found at beginning of the second erase block, containing the rootfs and 9 + kernel offsets and sizes within the firmware partition. 10 + 11 + Required properties: 12 + - compatible : must be "brcm,bcm963xx-cfe-nor-partitions" 13 + 14 + Example: 15 + 16 + flash@1fc00000 { 17 + compatible = "cfi-flash"; 18 + reg = <0x1fc00000 0x400000>; 19 + bank-width = <2>; 20 + 21 + partitions { 22 + compatible = "brcm,bcm963xx-cfe-nor-partitions"; 23 + }; 24 + };
+45
Documentation/devicetree/bindings/mtd/partitions/brcm,bcm963xx-imagetag.txt
··· 1 + Broadcom BCM963XX ImageTag Partition Container 2 + ============================================== 3 + 4 + Some Broadcom BCM63XX SoC based devices contain additional, non discoverable 5 + partitions or non standard bootloader partition sizes. For these a mixed layout 6 + needs to be used with an explicit firmware partition. 7 + 8 + The BCM963XX ImageTag is a simple firmware header describing the offsets and 9 + sizes of the rootfs and kernel parts contained in the firmware. 10 + 11 + Required properties: 12 + - compatible : must be "brcm,bcm963xx-imagetag" 13 + 14 + Example: 15 + 16 + flash@1e000000 { 17 + compatible = "cfi-flash"; 18 + reg = <0x1e000000 0x2000000>; 19 + bank-width = <2>; 20 + 21 + partitions { 22 + compatible = "fixed-partitions"; 23 + #address-cells = <1>; 24 + #size-cells = <1>; 25 + 26 + cfe@0 { 27 + reg = <0x0 0x10000>; 28 + read-only; 29 + }; 30 + 31 + firmware@10000 { 32 + reg = <0x10000 0x7d0000>; 33 + compatible = "brcm,bcm963xx-imagetag"; 34 + }; 35 + 36 + caldata@7e0000 { 37 + reg = <0x7e0000 0x10000>; 38 + read-only; 39 + }; 40 + 41 + nvram@7f0000 { 42 + reg = <0x7f0000 0x10000>; 43 + }; 44 + }; 45 + };
-48
Documentation/devicetree/bindings/mtd/sunxi-nand.txt
··· 1 - Allwinner NAND Flash Controller (NFC) 2 - 3 - Required properties: 4 - - compatible : "allwinner,sun4i-a10-nand". 5 - - reg : shall contain registers location and length for data and reg. 6 - - interrupts : shall define the nand controller interrupt. 7 - - #address-cells: shall be set to 1. Encode the nand CS. 8 - - #size-cells : shall be set to 0. 9 - - clocks : shall reference nand controller clocks. 10 - - clock-names : nand controller internal clock names. Shall contain : 11 - * "ahb" : AHB gating clock 12 - * "mod" : nand controller clock 13 - 14 - Optional properties: 15 - - dmas : shall reference DMA channel associated to the NAND controller. 16 - - dma-names : shall be "rxtx". 17 - 18 - Optional children nodes: 19 - Children nodes represent the available nand chips. 20 - 21 - Optional properties: 22 - - reset : phandle + reset specifier pair 23 - - reset-names : must contain "ahb" 24 - - allwinner,rb : shall contain the native Ready/Busy ids. 25 - - nand-ecc-mode : one of the supported ECC modes ("hw", "soft", "soft_bch" or 26 - "none") 27 - 28 - see Documentation/devicetree/bindings/mtd/nand.txt for generic bindings. 29 - 30 - 31 - Examples: 32 - nfc: nand@1c03000 { 33 - compatible = "allwinner,sun4i-a10-nand"; 34 - reg = <0x01c03000 0x1000>; 35 - interrupts = <0 37 1>; 36 - clocks = <&ahb_gates 13>, <&nand_clk>; 37 - clock-names = "ahb", "mod"; 38 - #address-cells = <1>; 39 - #size-cells = <0>; 40 - pinctrl-names = "default"; 41 - pinctrl-0 = <&nand_pins_a &nand_cs0_pins_a &nand_rb0_pins_a>; 42 - 43 - nand@0 { 44 - reg = <0>; 45 - allwinner,rb = <0>; 46 - nand-ecc-mode = "soft_bch"; 47 - }; 48 - };
+9 -9
MAINTAINERS
··· 8418 8418 8419 8419 JOURNALLING FLASH FILE SYSTEM V2 (JFFS2) 8420 8420 M: David Woodhouse <dwmw2@infradead.org> 8421 + M: Richard Weinberger <richard@nod.at> 8421 8422 L: linux-mtd@lists.infradead.org 8422 8423 W: http://www.linux-mtd.infradead.org/doc/jffs2.html 8423 - S: Maintained 8424 + T: git git://git.infradead.org/ubifs-2.6.git 8425 + S: Odd Fixes 8424 8426 F: fs/jffs2/ 8425 8427 F: include/uapi/linux/jffs2.h 8426 8428 ··· 10116 10114 MEMORY TECHNOLOGY DEVICES (MTD) 10117 10115 M: David Woodhouse <dwmw2@infradead.org> 10118 10116 M: Brian Norris <computersforpeace@gmail.com> 10119 - M: Boris Brezillon <bbrezillon@kernel.org> 10120 10117 M: Marek Vasut <marek.vasut@gmail.com> 10118 + M: Miquel Raynal <miquel.raynal@bootlin.com> 10121 10119 M: Richard Weinberger <richard@nod.at> 10120 + M: Vignesh Raghavendra <vigneshr@ti.com> 10122 10121 L: linux-mtd@lists.infradead.org 10123 10122 W: http://www.linux-mtd.infradead.org/ 10124 10123 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/ 10125 - T: git git://git.infradead.org/linux-mtd.git master 10126 - T: git git://git.infradead.org/linux-mtd.git mtd/next 10124 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes 10125 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next 10127 10126 S: Maintained 10128 10127 F: Documentation/devicetree/bindings/mtd/ 10129 10128 F: drivers/mtd/ ··· 10733 10730 F: drivers/net/ethernet/myricom/myri10ge/ 10734 10731 10735 10732 NAND FLASH SUBSYSTEM 10736 - M: Boris Brezillon <bbrezillon@kernel.org> 10737 10733 M: Miquel Raynal <miquel.raynal@bootlin.com> 10738 10734 R: Richard Weinberger <richard@nod.at> 10739 10735 L: linux-mtd@lists.infradead.org 10740 10736 W: http://www.linux-mtd.infradead.org/ 10741 10737 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/ 10742 - T: git git://git.infradead.org/linux-mtd.git nand/fixes 10743 - T: git git://git.infradead.org/linux-mtd.git nand/next 10738 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next 10744 10739 S: Maintained 10745 10740 F: drivers/mtd/nand/ 10746 10741 F: include/linux/mtd/*nand*.h ··· 14752 14751 L: linux-mtd@lists.infradead.org 14753 14752 W: http://www.linux-mtd.infradead.org/ 14754 14753 Q: http://patchwork.ozlabs.org/project/linux-mtd/list/ 14755 - T: git git://git.infradead.org/linux-mtd.git spi-nor/fixes 14756 - T: git git://git.infradead.org/linux-mtd.git spi-nor/next 14754 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-nor/next 14757 14755 S: Maintained 14758 14756 F: drivers/mtd/spi-nor/ 14759 14757 F: include/linux/mtd/spi-nor.h
+1 -1
arch/arm/configs/at91_dt_defconfig
··· 55 55 CONFIG_MTD_CMDLINE_PARTS=y 56 56 CONFIG_MTD_BLOCK=y 57 57 CONFIG_MTD_DATAFLASH=y 58 - CONFIG_MTD_NAND=y 58 + CONFIG_MTD_RAW_NAND=y 59 59 CONFIG_MTD_NAND_ATMEL=y 60 60 CONFIG_MTD_UBI=y 61 61 CONFIG_MTD_UBI_GLUEBI=y
+1 -1
arch/arm/configs/clps711x_defconfig
··· 35 35 CONFIG_MTD_CFI_AMDSTD=y 36 36 CONFIG_MTD_CFI_STAA=y 37 37 CONFIG_MTD_PLATRAM=y 38 - CONFIG_MTD_NAND=y 38 + CONFIG_MTD_RAW_NAND=y 39 39 CONFIG_MTD_NAND_GPIO=y 40 40 CONFIG_NETDEVICES=y 41 41 # CONFIG_NET_CADENCE is not set
+1 -1
arch/arm/configs/cm_x2xx_defconfig
··· 58 58 CONFIG_MTD_CFI_STAA=y 59 59 CONFIG_MTD_PHYSMAP=y 60 60 CONFIG_MTD_PXA2XX=y 61 - CONFIG_MTD_NAND=y 61 + CONFIG_MTD_RAW_NAND=y 62 62 CONFIG_MTD_NAND_GPIO=m 63 63 CONFIG_MTD_NAND_CM_X270=y 64 64 CONFIG_MTD_NAND_PLATFORM=y
+1 -1
arch/arm/configs/cm_x300_defconfig
··· 48 48 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 49 49 CONFIG_MTD=y 50 50 CONFIG_MTD_BLOCK=y 51 - CONFIG_MTD_NAND=y 51 + CONFIG_MTD_RAW_NAND=y 52 52 CONFIG_MTD_NAND_MARVELL=y 53 53 CONFIG_MTD_UBI=y 54 54 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/arm/configs/colibri_pxa270_defconfig
··· 64 64 CONFIG_MTD_PHYSMAP=y 65 65 CONFIG_MTD_PXA2XX=y 66 66 CONFIG_MTD_BLOCK2MTD=y 67 - CONFIG_MTD_NAND=y 67 + CONFIG_MTD_RAW_NAND=y 68 68 CONFIG_MTD_NAND_DISKONCHIP=y 69 69 CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED=y 70 70 CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS=0x4000000
+1 -1
arch/arm/configs/corgi_defconfig
··· 87 87 CONFIG_MTD_BLOCK=y 88 88 CONFIG_MTD_ROM=y 89 89 CONFIG_MTD_COMPLEX_MAPPINGS=y 90 - CONFIG_MTD_NAND=y 90 + CONFIG_MTD_RAW_NAND=y 91 91 CONFIG_MTD_NAND_SHARPSL=y 92 92 CONFIG_BLK_DEV_LOOP=y 93 93 CONFIG_BLK_DEV_SD=y
+1 -1
arch/arm/configs/davinci_all_defconfig
··· 74 74 CONFIG_MTD_CFI_AMDSTD=m 75 75 CONFIG_MTD_PHYSMAP=m 76 76 CONFIG_MTD_M25P80=m 77 - CONFIG_MTD_NAND=m 77 + CONFIG_MTD_RAW_NAND=m 78 78 CONFIG_MTD_NAND_DAVINCI=m 79 79 CONFIG_MTD_SPI_NOR=m 80 80 CONFIG_MTD_UBI=m
+1 -1
arch/arm/configs/em_x270_defconfig
··· 54 54 CONFIG_MTD_CFI_STAA=y 55 55 CONFIG_MTD_PHYSMAP=y 56 56 CONFIG_MTD_PXA2XX=y 57 - CONFIG_MTD_NAND=y 57 + CONFIG_MTD_RAW_NAND=y 58 58 CONFIG_MTD_NAND_PLATFORM=y 59 59 CONFIG_BLK_DEV_LOOP=y 60 60 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/arm/configs/ep93xx_defconfig
··· 63 63 CONFIG_MTD_CFI_STAA=y 64 64 CONFIG_MTD_ROM=y 65 65 CONFIG_MTD_PHYSMAP=y 66 - CONFIG_MTD_NAND=y 66 + CONFIG_MTD_RAW_NAND=y 67 67 CONFIG_BLK_DEV_NBD=y 68 68 CONFIG_EEPROM_LEGACY=y 69 69 CONFIG_SCSI=y
+1 -1
arch/arm/configs/eseries_pxa_defconfig
··· 43 43 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 44 44 # CONFIG_STANDALONE is not set 45 45 CONFIG_MTD=m 46 - CONFIG_MTD_NAND=m 46 + CONFIG_MTD_RAW_NAND=m 47 47 CONFIG_MTD_NAND_TMIO=m 48 48 CONFIG_BLK_DEV_LOOP=m 49 49 # CONFIG_SCSI_PROC_FS is not set
+1 -1
arch/arm/configs/imx_v4_v5_defconfig
··· 61 61 # CONFIG_MTD_CFI_I2 is not set 62 62 CONFIG_MTD_CFI_INTELEXT=y 63 63 CONFIG_MTD_PHYSMAP=y 64 - CONFIG_MTD_NAND=y 64 + CONFIG_MTD_RAW_NAND=y 65 65 CONFIG_MTD_NAND_MXC=y 66 66 CONFIG_MTD_UBI=y 67 67 CONFIG_EEPROM_AT24=y
+1 -1
arch/arm/configs/imx_v6_v7_defconfig
··· 110 110 CONFIG_MTD_DATAFLASH=y 111 111 CONFIG_MTD_M25P80=y 112 112 CONFIG_MTD_SST25L=y 113 - CONFIG_MTD_NAND=y 113 + CONFIG_MTD_RAW_NAND=y 114 114 CONFIG_MTD_NAND_GPMI_NAND=y 115 115 CONFIG_MTD_NAND_VF610_NFC=y 116 116 CONFIG_MTD_NAND_MXC=y
+1 -1
arch/arm/configs/ixp4xx_defconfig
··· 112 112 CONFIG_MTD_CFI_INTELEXT=y 113 113 CONFIG_MTD_COMPLEX_MAPPINGS=y 114 114 CONFIG_MTD_IXP4XX=y 115 - CONFIG_MTD_NAND=m 115 + CONFIG_MTD_RAW_NAND=m 116 116 CONFIG_BLK_DEV_LOOP=y 117 117 CONFIG_BLK_DEV_RAM=y 118 118 CONFIG_BLK_DEV_RAM_SIZE=8192
+1 -1
arch/arm/configs/keystone_defconfig
··· 124 124 CONFIG_MTD_BLOCK=y 125 125 CONFIG_MTD_PLATRAM=y 126 126 CONFIG_MTD_M25P80=y 127 - CONFIG_MTD_NAND=y 127 + CONFIG_MTD_RAW_NAND=y 128 128 CONFIG_MTD_NAND_DAVINCI=y 129 129 CONFIG_MTD_SPI_NOR=y 130 130 CONFIG_MTD_UBI=y
+1 -1
arch/arm/configs/lpc32xx_defconfig
··· 47 47 CONFIG_MTD=y 48 48 CONFIG_MTD_CMDLINE_PARTS=y 49 49 CONFIG_MTD_BLOCK=y 50 - CONFIG_MTD_NAND=y 50 + CONFIG_MTD_RAW_NAND=y 51 51 CONFIG_MTD_NAND_SLC_LPC32XX=y 52 52 CONFIG_MTD_NAND_MLC_LPC32XX=y 53 53 CONFIG_MTD_UBI=y
+1 -1
arch/arm/configs/mini2440_defconfig
··· 92 92 CONFIG_MTD_CFI_STAA=y 93 93 CONFIG_MTD_RAM=y 94 94 CONFIG_MTD_ROM=y 95 - CONFIG_MTD_NAND=y 95 + CONFIG_MTD_RAW_NAND=y 96 96 CONFIG_MTD_NAND_S3C2410=y 97 97 CONFIG_MTD_NAND_PLATFORM=y 98 98 CONFIG_MTD_LPDDR=y
+1 -1
arch/arm/configs/mmp2_defconfig
··· 28 28 CONFIG_MTD=y 29 29 CONFIG_MTD_CMDLINE_PARTS=y 30 30 CONFIG_MTD_BLOCK=y 31 - CONFIG_MTD_NAND=y 31 + CONFIG_MTD_RAW_NAND=y 32 32 CONFIG_MTD_ONENAND=y 33 33 CONFIG_MTD_ONENAND_GENERIC=y 34 34 # CONFIG_BLK_DEV is not set
+1 -1
arch/arm/configs/multi_v4t_defconfig
··· 38 38 CONFIG_MTD_CFI_AMDSTD=y 39 39 CONFIG_MTD_CFI_STAA=y 40 40 CONFIG_MTD_PLATRAM=y 41 - CONFIG_MTD_NAND=y 41 + CONFIG_MTD_RAW_NAND=y 42 42 CONFIG_MTD_NAND_GPIO=y 43 43 # CONFIG_INPUT is not set 44 44 # CONFIG_SERIO is not set
+1 -1
arch/arm/configs/multi_v5_defconfig
··· 87 87 CONFIG_MTD_CFI_INTELEXT=y 88 88 CONFIG_MTD_CFI_STAA=y 89 89 CONFIG_MTD_PHYSMAP=y 90 - CONFIG_MTD_NAND=y 90 + CONFIG_MTD_RAW_NAND=y 91 91 CONFIG_MTD_NAND_ATMEL=y 92 92 CONFIG_MTD_NAND_ORION=y 93 93 CONFIG_MTD_SPI_NOR=y
+1 -1
arch/arm/configs/multi_v7_defconfig
··· 184 184 CONFIG_MTD_CMDLINE_PARTS=y 185 185 CONFIG_MTD_BLOCK=y 186 186 CONFIG_MTD_M25P80=y 187 - CONFIG_MTD_NAND=y 187 + CONFIG_MTD_RAW_NAND=y 188 188 CONFIG_MTD_NAND_DENALI_DT=y 189 189 CONFIG_MTD_NAND_OMAP2=y 190 190 CONFIG_MTD_NAND_OMAP_BCH=y
+1 -1
arch/arm/configs/mv78xx0_defconfig
··· 47 47 CONFIG_MTD_CFI_INTELEXT=y 48 48 CONFIG_MTD_CFI_AMDSTD=y 49 49 CONFIG_MTD_PHYSMAP=y 50 - CONFIG_MTD_NAND=y 50 + CONFIG_MTD_RAW_NAND=y 51 51 CONFIG_MTD_NAND_ORION=y 52 52 CONFIG_BLK_DEV_LOOP=y 53 53 # CONFIG_SCSI_PROC_FS is not set
+1 -1
arch/arm/configs/mvebu_v5_defconfig
··· 77 77 CONFIG_MTD_CFI_STAA=y 78 78 CONFIG_MTD_PHYSMAP=y 79 79 CONFIG_MTD_M25P80=y 80 - CONFIG_MTD_NAND=y 80 + CONFIG_MTD_RAW_NAND=y 81 81 CONFIG_MTD_NAND_ORION=y 82 82 CONFIG_MTD_SPI_NOR=y 83 83 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/arm/configs/mvebu_v7_defconfig
··· 52 52 CONFIG_MTD_CFI_STAA=y 53 53 CONFIG_MTD_PHYSMAP_OF=y 54 54 CONFIG_MTD_M25P80=y 55 - CONFIG_MTD_NAND=y 55 + CONFIG_MTD_RAW_NAND=y 56 56 CONFIG_MTD_NAND_MARVELL=y 57 57 CONFIG_MTD_SPI_NOR=y 58 58 CONFIG_MTD_UBI=y
+1 -1
arch/arm/configs/mxs_defconfig
··· 50 50 CONFIG_MTD_DATAFLASH=y 51 51 CONFIG_MTD_M25P80=y 52 52 CONFIG_MTD_SST25L=y 53 - CONFIG_MTD_NAND=y 53 + CONFIG_MTD_RAW_NAND=y 54 54 CONFIG_MTD_NAND_GPMI_NAND=y 55 55 CONFIG_MTD_SPI_NOR=y 56 56 CONFIG_MTD_UBI=y
+2 -2
arch/arm/configs/nhk8815_defconfig
··· 53 53 CONFIG_MTD_ONENAND=y 54 54 CONFIG_MTD_ONENAND_VERIFY_WRITE=y 55 55 CONFIG_MTD_ONENAND_GENERIC=y 56 - CONFIG_MTD_NAND_ECC_SMC=y 57 - CONFIG_MTD_NAND=y 56 + CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC=y 57 + CONFIG_MTD_RAW_NAND=y 58 58 CONFIG_MTD_NAND_FSMC=y 59 59 CONFIG_BLK_DEV_LOOP=y 60 60 CONFIG_BLK_DEV_CRYPTOLOOP=y
+1 -1
arch/arm/configs/omap1_defconfig
··· 89 89 CONFIG_MTD_BLOCK=y 90 90 CONFIG_MTD_CFI=y 91 91 CONFIG_MTD_CFI_INTELEXT=y 92 - CONFIG_MTD_NAND=y 92 + CONFIG_MTD_RAW_NAND=y 93 93 CONFIG_BLK_DEV_LOOP=y 94 94 CONFIG_BLK_DEV_RAM=y 95 95 CONFIG_BLK_DEV_RAM_COUNT=2
+2 -2
arch/arm/configs/omap2plus_defconfig
··· 143 143 CONFIG_MTD_ONENAND=y 144 144 CONFIG_MTD_ONENAND_VERIFY_WRITE=y 145 145 CONFIG_MTD_ONENAND_OMAP2=y 146 - CONFIG_MTD_NAND=y 147 - CONFIG_MTD_NAND_ECC_BCH=y 146 + CONFIG_MTD_RAW_NAND=y 147 + CONFIG_MTD_NAND_ECC_SW_BCH=y 148 148 CONFIG_MTD_NAND_OMAP2=y 149 149 CONFIG_MTD_NAND_OMAP_BCH=y 150 150 CONFIG_MTD_SPI_NOR=m
+1 -1
arch/arm/configs/orion5x_defconfig
··· 70 70 CONFIG_MTD_CFI_INTELEXT=y 71 71 CONFIG_MTD_CFI_AMDSTD=y 72 72 CONFIG_MTD_PHYSMAP=y 73 - CONFIG_MTD_NAND=y 73 + CONFIG_MTD_RAW_NAND=y 74 74 CONFIG_MTD_NAND_PLATFORM=y 75 75 CONFIG_MTD_NAND_ORION=y 76 76 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/arm/configs/oxnas_v6_defconfig
··· 50 50 CONFIG_MTD=y 51 51 CONFIG_MTD_CMDLINE_PARTS=y 52 52 CONFIG_MTD_BLOCK=y 53 - CONFIG_MTD_NAND=y 53 + CONFIG_MTD_RAW_NAND=y 54 54 CONFIG_MTD_NAND_OXNAS=y 55 55 CONFIG_MTD_UBI=y 56 56 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/arm/configs/pxa3xx_defconfig
··· 31 31 # CONFIG_PREVENT_FIRMWARE_BUILD is not set 32 32 CONFIG_MTD=y 33 33 CONFIG_MTD_BLOCK=y 34 - CONFIG_MTD_NAND=y 34 + CONFIG_MTD_RAW_NAND=y 35 35 CONFIG_MTD_NAND_MARVELL=y 36 36 CONFIG_MTD_ONENAND=y 37 37 CONFIG_MTD_ONENAND_VERIFY_WRITE=y
+2 -2
arch/arm/configs/pxa_defconfig
··· 185 185 CONFIG_MTD_M25P80=m 186 186 CONFIG_MTD_BLOCK2MTD=y 187 187 CONFIG_MTD_DOCG3=m 188 - CONFIG_MTD_NAND=m 189 - CONFIG_MTD_NAND_ECC_BCH=y 188 + CONFIG_MTD_RAW_NAND=m 189 + CONFIG_MTD_NAND_ECC_SW_BCH=y 190 190 CONFIG_MTD_NAND_GPIO=m 191 191 CONFIG_MTD_NAND_DISKONCHIP=m 192 192 CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED=y
+1 -1
arch/arm/configs/qcom_defconfig
··· 57 57 CONFIG_MTD=y 58 58 CONFIG_MTD_BLOCK=y 59 59 CONFIG_MTD_M25P80=y 60 - CONFIG_MTD_NAND=y 60 + CONFIG_MTD_RAW_NAND=y 61 61 CONFIG_MTD_NAND_QCOM=y 62 62 CONFIG_MTD_SPI_NOR=y 63 63 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/arm/configs/s3c2410_defconfig
··· 192 192 CONFIG_MTD_CFI_INTELEXT=y 193 193 CONFIG_MTD_CFI_AMDSTD=y 194 194 CONFIG_MTD_ROM=y 195 - CONFIG_MTD_NAND=y 195 + CONFIG_MTD_RAW_NAND=y 196 196 CONFIG_MTD_NAND_S3C2410=y 197 197 CONFIG_PARPORT=y 198 198 CONFIG_PARPORT_PC=m
+1 -1
arch/arm/configs/s3c6400_defconfig
··· 23 23 CONFIG_VFP=y 24 24 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 25 25 CONFIG_MTD=y 26 - CONFIG_MTD_NAND=y 26 + CONFIG_MTD_RAW_NAND=y 27 27 CONFIG_MTD_NAND_S3C2410=y 28 28 CONFIG_BLK_DEV_LOOP=y 29 29 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/arm/configs/sama5_defconfig
··· 66 66 CONFIG_MTD_BLOCK=y 67 67 CONFIG_MTD_CFI=y 68 68 CONFIG_MTD_M25P80=y 69 - CONFIG_MTD_NAND=y 69 + CONFIG_MTD_RAW_NAND=y 70 70 CONFIG_MTD_NAND_ATMEL=y 71 71 CONFIG_MTD_SPI_NOR=y 72 72 CONFIG_MTD_UBI=y
+1 -1
arch/arm/configs/socfpga_defconfig
··· 51 51 CONFIG_MTD=y 52 52 CONFIG_MTD_BLOCK=y 53 53 CONFIG_MTD_M25P80=y 54 - CONFIG_MTD_NAND=y 54 + CONFIG_MTD_RAW_NAND=y 55 55 CONFIG_MTD_NAND_DENALI_DT=y 56 56 CONFIG_MTD_SPI_NOR=y 57 57 # CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is not set
+1 -1
arch/arm/configs/spear13xx_defconfig
··· 32 32 CONFIG_MTD=y 33 33 CONFIG_MTD_OF_PARTS=y 34 34 CONFIG_MTD_BLOCK=y 35 - CONFIG_MTD_NAND=y 35 + CONFIG_MTD_RAW_NAND=y 36 36 CONFIG_MTD_NAND_FSMC=y 37 37 CONFIG_BLK_DEV_RAM=y 38 38 CONFIG_BLK_DEV_RAM_SIZE=16384
+1 -1
arch/arm/configs/spear3xx_defconfig
··· 17 17 CONFIG_MTD=y 18 18 CONFIG_MTD_OF_PARTS=y 19 19 CONFIG_MTD_BLOCK=y 20 - CONFIG_MTD_NAND=y 20 + CONFIG_MTD_RAW_NAND=y 21 21 CONFIG_MTD_NAND_FSMC=y 22 22 CONFIG_BLK_DEV_RAM=y 23 23 CONFIG_BLK_DEV_RAM_SIZE=16384
+1 -1
arch/arm/configs/spear6xx_defconfig
··· 14 14 CONFIG_MTD=y 15 15 CONFIG_MTD_OF_PARTS=y 16 16 CONFIG_MTD_BLOCK=y 17 - CONFIG_MTD_NAND=y 17 + CONFIG_MTD_RAW_NAND=y 18 18 CONFIG_MTD_NAND_FSMC=y 19 19 CONFIG_BLK_DEV_RAM=y 20 20 CONFIG_BLK_DEV_RAM_SIZE=16384
+1 -1
arch/arm/configs/spitz_defconfig
··· 84 84 CONFIG_MTD_BLOCK=y 85 85 CONFIG_MTD_ROM=y 86 86 CONFIG_MTD_COMPLEX_MAPPINGS=y 87 - CONFIG_MTD_NAND=y 87 + CONFIG_MTD_RAW_NAND=y 88 88 CONFIG_MTD_NAND_SHARPSL=y 89 89 CONFIG_BLK_DEV_LOOP=y 90 90 CONFIG_BLK_DEV_SD=y
+1 -1
arch/arm/configs/tango4_defconfig
··· 39 39 CONFIG_MTD=y 40 40 CONFIG_MTD_TESTS=m 41 41 CONFIG_MTD_CMDLINE_PARTS=y 42 - CONFIG_MTD_NAND=y 42 + CONFIG_MTD_RAW_NAND=y 43 43 CONFIG_MTD_NAND_TANGO=y 44 44 CONFIG_BLK_DEV_LOOP=y 45 45 CONFIG_SCSI=y
+1 -1
arch/arm/configs/trizeps4_defconfig
··· 76 76 CONFIG_MTD_DOCPROBE_ADVANCED=y 77 77 CONFIG_MTD_DOCPROBE_ADDRESS=0x4000000 78 78 CONFIG_MTD_DOCPROBE_HIGH=y 79 - CONFIG_MTD_NAND=y 79 + CONFIG_MTD_RAW_NAND=y 80 80 CONFIG_MTD_NAND_DISKONCHIP=y 81 81 CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED=y 82 82 CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS=0x4000000
+1 -1
arch/arm/configs/u300_defconfig
··· 26 26 # CONFIG_PREVENT_FIRMWARE_BUILD is not set 27 27 CONFIG_MTD=y 28 28 CONFIG_MTD_CMDLINE_PARTS=y 29 - CONFIG_MTD_NAND=y 29 + CONFIG_MTD_RAW_NAND=y 30 30 CONFIG_MTD_NAND_FSMC=y 31 31 # CONFIG_INPUT_MOUSEDEV is not set 32 32 CONFIG_INPUT_EVDEV=y
+1 -1
arch/arm64/configs/defconfig
··· 206 206 CONFIG_MTD=y 207 207 CONFIG_MTD_BLOCK=y 208 208 CONFIG_MTD_M25P80=y 209 - CONFIG_MTD_NAND=y 209 + CONFIG_MTD_RAW_NAND=y 210 210 CONFIG_MTD_NAND_DENALI_DT=y 211 211 CONFIG_MTD_NAND_MARVELL=y 212 212 CONFIG_MTD_NAND_QCOM=y
+1 -1
arch/mips/configs/bcm47xx_defconfig
··· 41 41 CONFIG_MTD_COMPLEX_MAPPINGS=y 42 42 CONFIG_MTD_PHYSMAP=y 43 43 CONFIG_MTD_BCM47XXSFLASH=y 44 - CONFIG_MTD_NAND=y 44 + CONFIG_MTD_RAW_NAND=y 45 45 CONFIG_MTD_NAND_BCM47XXNFLASH=y 46 46 CONFIG_NETDEVICES=y 47 47 CONFIG_B44=y
+1 -1
arch/mips/configs/ci20_defconfig
··· 51 51 CONFIG_DMA_CMA=y 52 52 CONFIG_CMA_SIZE_MBYTES=32 53 53 CONFIG_MTD=y 54 - CONFIG_MTD_NAND=y 54 + CONFIG_MTD_RAW_NAND=y 55 55 CONFIG_MTD_NAND_JZ4780=y 56 56 CONFIG_MTD_UBI=y 57 57 CONFIG_MTD_UBI_FASTMAP=y
+2 -2
arch/mips/configs/db1xxx_defconfig
··· 95 95 CONFIG_MTD_PHYSMAP=y 96 96 CONFIG_MTD_M25P80=y 97 97 CONFIG_MTD_SST25L=y 98 - CONFIG_MTD_NAND=y 99 - CONFIG_MTD_NAND_ECC_BCH=y 98 + CONFIG_MTD_RAW_NAND=y 99 + CONFIG_MTD_NAND_ECC_SW_BCH=y 100 100 CONFIG_MTD_NAND_AU1550=y 101 101 CONFIG_MTD_NAND_PLATFORM=y 102 102 CONFIG_MTD_SPI_NOR=y
+3 -3
arch/mips/configs/generic/board-ni169445.config
··· 15 15 CONFIG_MTD_BLOCK=y 16 16 CONFIG_MTD_CMDLINE_PARTS=y 17 17 18 - CONFIG_MTD_NAND_ECC=y 19 - CONFIG_MTD_NAND_ECC_BCH=y 20 - CONFIG_MTD_NAND=y 18 + CONFIG_MTD_NAND_ECC_SW_HAMMING=y 19 + CONFIG_MTD_NAND_ECC_SW_BCH=y 20 + CONFIG_MTD_RAW_NAND=y 21 21 CONFIG_MTD_NAND_GPIO=y 22 22 CONFIG_MTD_NAND_IDS=y 23 23
+1 -1
arch/mips/configs/generic/board-ocelot.config
··· 10 10 CONFIG_MTD_CMDLINE_PARTS=y 11 11 CONFIG_MTD_BLOCK=y 12 12 CONFIG_MTD_M25P80=y 13 - CONFIG_MTD_NAND=y 13 + CONFIG_MTD_RAW_NAND=y 14 14 CONFIG_MTD_NAND_PLATFORM=y 15 15 CONFIG_MTD_SPI_NOR=y 16 16 CONFIG_MTD_UBI=y
+1 -1
arch/mips/configs/loongson1b_defconfig
··· 41 41 CONFIG_MTD=y 42 42 CONFIG_MTD_CMDLINE_PARTS=y 43 43 CONFIG_MTD_BLOCK=y 44 - CONFIG_MTD_NAND=y 44 + CONFIG_MTD_RAW_NAND=y 45 45 CONFIG_MTD_UBI=y 46 46 CONFIG_BLK_DEV_LOOP=y 47 47 CONFIG_SCSI=m
+1 -1
arch/mips/configs/loongson1c_defconfig
··· 42 42 CONFIG_MTD=y 43 43 CONFIG_MTD_CMDLINE_PARTS=y 44 44 CONFIG_MTD_BLOCK=y 45 - CONFIG_MTD_NAND=y 45 + CONFIG_MTD_RAW_NAND=y 46 46 CONFIG_MTD_UBI=y 47 47 CONFIG_BLK_DEV_LOOP=y 48 48 CONFIG_SCSI=m
+1 -1
arch/mips/configs/qi_lb60_defconfig
··· 44 44 CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 45 45 CONFIG_MTD=y 46 46 CONFIG_MTD_BLOCK=y 47 - CONFIG_MTD_NAND=y 47 + CONFIG_MTD_RAW_NAND=y 48 48 CONFIG_MTD_NAND_JZ4740=y 49 49 CONFIG_MTD_UBI=y 50 50 CONFIG_NETDEVICES=y
+1 -1
arch/mips/configs/rb532_defconfig
··· 109 109 CONFIG_MTD=y 110 110 CONFIG_MTD_BLOCK=y 111 111 CONFIG_MTD_BLOCK2MTD=y 112 - CONFIG_MTD_NAND=y 112 + CONFIG_MTD_RAW_NAND=y 113 113 CONFIG_MTD_NAND_PLATFORM=y 114 114 CONFIG_ATA=y 115 115 # CONFIG_ATA_VERBOSE_ERROR is not set
+1 -1
arch/mips/configs/rbtx49xx_defconfig
··· 39 39 CONFIG_MTD_COMPLEX_MAPPINGS=y 40 40 CONFIG_MTD_PHYSMAP=y 41 41 CONFIG_MTD_RBTX4939=y 42 - CONFIG_MTD_NAND=m 42 + CONFIG_MTD_RAW_NAND=m 43 43 CONFIG_MTD_NAND_TXX9NDFMC=m 44 44 CONFIG_BLK_DEV_LOOP=y 45 45 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/mips/configs/xway_defconfig
··· 81 81 CONFIG_MTD_PHYSMAP=y 82 82 CONFIG_MTD_PHYSMAP_OF=y 83 83 CONFIG_MTD_LANTIQ=y 84 - CONFIG_MTD_NAND=y 84 + CONFIG_MTD_RAW_NAND=y 85 85 CONFIG_MTD_NAND_XWAY=y 86 86 CONFIG_EEPROM_93CX6=m 87 87 CONFIG_SCSI=y
+1 -1
arch/powerpc/configs/40x/kilauea_defconfig
··· 33 33 CONFIG_MTD_JEDECPROBE=y 34 34 CONFIG_MTD_CFI_AMDSTD=y 35 35 CONFIG_MTD_PHYSMAP_OF=y 36 - CONFIG_MTD_NAND=y 36 + CONFIG_MTD_RAW_NAND=y 37 37 CONFIG_MTD_NAND_NDFC=y 38 38 CONFIG_BLK_DEV_RAM=y 39 39 CONFIG_BLK_DEV_RAM_SIZE=35000
+1 -1
arch/powerpc/configs/40x/obs600_defconfig
··· 33 33 CONFIG_MTD_JEDECPROBE=y 34 34 CONFIG_MTD_CFI_AMDSTD=y 35 35 CONFIG_MTD_PHYSMAP_OF=y 36 - CONFIG_MTD_NAND=y 36 + CONFIG_MTD_RAW_NAND=y 37 37 CONFIG_MTD_NAND_NDFC=y 38 38 CONFIG_BLK_DEV_RAM=y 39 39 CONFIG_BLK_DEV_RAM_SIZE=35000
+1 -1
arch/powerpc/configs/44x/canyonlands_defconfig
··· 32 32 CONFIG_MTD_CFI=y 33 33 CONFIG_MTD_CFI_AMDSTD=y 34 34 CONFIG_MTD_PHYSMAP_OF=y 35 - CONFIG_MTD_NAND=y 35 + CONFIG_MTD_RAW_NAND=y 36 36 CONFIG_MTD_NAND_NDFC=y 37 37 CONFIG_BLK_DEV_RAM=y 38 38 CONFIG_BLK_DEV_RAM_SIZE=35000
+1 -1
arch/powerpc/configs/44x/eiger_defconfig
··· 33 33 CONFIG_MTD_CFI=y 34 34 CONFIG_MTD_CFI_AMDSTD=y 35 35 CONFIG_MTD_PHYSMAP_OF=y 36 - CONFIG_MTD_NAND=y 36 + CONFIG_MTD_RAW_NAND=y 37 37 CONFIG_MTD_NAND_NDFC=y 38 38 CONFIG_BLK_DEV_RAM=y 39 39 CONFIG_BLK_DEV_RAM_SIZE=35000
+1 -1
arch/powerpc/configs/44x/sequoia_defconfig
··· 33 33 CONFIG_MTD_CFI_INTELEXT=y 34 34 CONFIG_MTD_CFI_AMDSTD=y 35 35 CONFIG_MTD_PHYSMAP_OF=y 36 - CONFIG_MTD_NAND=y 36 + CONFIG_MTD_RAW_NAND=y 37 37 CONFIG_MTD_NAND_NDFC=y 38 38 CONFIG_BLK_DEV_RAM=y 39 39 CONFIG_BLK_DEV_RAM_SIZE=35000
+1 -1
arch/powerpc/configs/44x/warp_defconfig
··· 34 34 CONFIG_MTD_CFI=y 35 35 CONFIG_MTD_CFI_AMDSTD=y 36 36 CONFIG_MTD_PHYSMAP_OF=y 37 - CONFIG_MTD_NAND=y 37 + CONFIG_MTD_RAW_NAND=y 38 38 CONFIG_MTD_NAND_NDFC=y 39 39 CONFIG_MTD_UBI=y 40 40 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/83xx/mpc8313_rdb_defconfig
··· 31 31 CONFIG_MTD_CFI=y 32 32 CONFIG_MTD_CFI_AMDSTD=y 33 33 CONFIG_MTD_PHYSMAP_OF=y 34 - CONFIG_MTD_NAND=y 34 + CONFIG_MTD_RAW_NAND=y 35 35 CONFIG_MTD_NAND_FSL_ELBC=y 36 36 CONFIG_BLK_DEV_LOOP=y 37 37 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/83xx/mpc8315_rdb_defconfig
··· 31 31 CONFIG_MTD_CFI=y 32 32 CONFIG_MTD_CFI_AMDSTD=y 33 33 CONFIG_MTD_PHYSMAP_OF=y 34 - CONFIG_MTD_NAND=y 34 + CONFIG_MTD_RAW_NAND=y 35 35 CONFIG_BLK_DEV_LOOP=y 36 36 CONFIG_BLK_DEV_RAM=y 37 37 CONFIG_BLK_DEV_RAM_SIZE=32768
+1 -1
arch/powerpc/configs/85xx-hw.config
··· 71 71 CONFIG_MTD_M25P80=y 72 72 CONFIG_MTD_NAND_FSL_ELBC=y 73 73 CONFIG_MTD_NAND_FSL_IFC=y 74 - CONFIG_MTD_NAND=y 74 + CONFIG_MTD_RAW_NAND=y 75 75 CONFIG_MTD_PHYSMAP_OF=y 76 76 CONFIG_MTD_PHYSMAP=y 77 77 CONFIG_MTD_PLATRAM=y
+1 -1
arch/powerpc/configs/85xx/ge_imp3a_defconfig
··· 73 73 CONFIG_MTD_CFI_INTELEXT=y 74 74 CONFIG_MTD_CFI_AMDSTD=y 75 75 CONFIG_MTD_PHYSMAP_OF=y 76 - CONFIG_MTD_NAND=y 76 + CONFIG_MTD_RAW_NAND=y 77 77 CONFIG_MTD_NAND_FSL_ELBC=y 78 78 CONFIG_BLK_DEV_LOOP=m 79 79 CONFIG_BLK_DEV_CRYPTOLOOP=m
+1 -1
arch/powerpc/configs/85xx/socrates_defconfig
··· 31 31 CONFIG_MTD_JEDECPROBE=y 32 32 CONFIG_MTD_CFI_AMDSTD=y 33 33 CONFIG_MTD_PHYSMAP_OF=y 34 - CONFIG_MTD_NAND=y 34 + CONFIG_MTD_RAW_NAND=y 35 35 CONFIG_MTD_NAND_SOCRATES=y 36 36 CONFIG_BLK_DEV_LOOP=y 37 37 CONFIG_BLK_DEV_RAM=y
+2 -2
arch/powerpc/configs/85xx/tqm8548_defconfig
··· 35 35 CONFIG_MTD_CFI=y 36 36 CONFIG_MTD_CFI_AMDSTD=y 37 37 CONFIG_MTD_PHYSMAP_OF=y 38 - CONFIG_MTD_NAND_ECC_SMC=y 39 - CONFIG_MTD_NAND=y 38 + CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC=y 39 + CONFIG_MTD_RAW_NAND=y 40 40 CONFIG_MTD_NAND_FSL_UPM=y 41 41 CONFIG_BLK_DEV_LOOP=y 42 42 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/85xx/xes_mpc85xx_defconfig
··· 65 65 CONFIG_MTD_CFI_AMDSTD=y 66 66 CONFIG_MTD_CFI_STAA=y 67 67 CONFIG_MTD_PHYSMAP_OF=y 68 - CONFIG_MTD_NAND=y 68 + CONFIG_MTD_RAW_NAND=y 69 69 CONFIG_MTD_NAND_FSL_ELBC=y 70 70 CONFIG_MTD_NAND_FSL_UPM=y 71 71 CONFIG_BLK_DEV_LOOP=y
+1 -1
arch/powerpc/configs/86xx-hw.config
··· 47 47 CONFIG_MTD_CMDLINE_PARTS=y 48 48 CONFIG_MTD_JEDECPROBE=y 49 49 CONFIG_MTD_NAND_FSL_ELBC=y 50 - CONFIG_MTD_NAND=y 50 + CONFIG_MTD_RAW_NAND=y 51 51 CONFIG_MTD_PHYSMAP_OF=y 52 52 CONFIG_NETDEVICES=y 53 53 CONFIG_NET_TULIP=y
+1 -1
arch/powerpc/configs/mpc512x_defconfig
··· 46 46 CONFIG_MTD_CFI_AMDSTD=y 47 47 CONFIG_MTD_ROM=y 48 48 CONFIG_MTD_PHYSMAP_OF=y 49 - CONFIG_MTD_NAND=y 49 + CONFIG_MTD_RAW_NAND=y 50 50 CONFIG_MTD_NAND_MPC5121_NFC=y 51 51 CONFIG_MTD_UBI=y 52 52 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/mpc83xx_defconfig
··· 46 46 CONFIG_MTD_CFI=y 47 47 CONFIG_MTD_CFI_AMDSTD=y 48 48 CONFIG_MTD_PHYSMAP_OF=y 49 - CONFIG_MTD_NAND=y 49 + CONFIG_MTD_RAW_NAND=y 50 50 CONFIG_MTD_NAND_FSL_ELBC=y 51 51 CONFIG_BLK_DEV_LOOP=y 52 52 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/pasemi_defconfig
··· 51 51 CONFIG_MTD_BLOCK=y 52 52 CONFIG_MTD_SLRAM=y 53 53 CONFIG_MTD_PHRAM=y 54 - CONFIG_MTD_NAND=y 54 + CONFIG_MTD_RAW_NAND=y 55 55 CONFIG_MTD_NAND_PASEMI=y 56 56 CONFIG_BLK_DEV_LOOP=y 57 57 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/powerpc/configs/ppc44x_defconfig
··· 44 44 CONFIG_MTD_JEDECPROBE=y 45 45 CONFIG_MTD_CFI_AMDSTD=y 46 46 CONFIG_MTD_PHYSMAP_OF=y 47 - CONFIG_MTD_NAND=m 47 + CONFIG_MTD_RAW_NAND=m 48 48 CONFIG_MTD_NAND_NDFC=m 49 49 CONFIG_MTD_UBI=m 50 50 CONFIG_MTD_UBI_GLUEBI=m
+1 -1
arch/sh/configs/ap325rxa_defconfig
··· 35 35 CONFIG_MTD_CFI=y 36 36 CONFIG_MTD_CFI_AMDSTD=y 37 37 CONFIG_MTD_PHYSMAP=y 38 - CONFIG_MTD_NAND=y 38 + CONFIG_MTD_RAW_NAND=y 39 39 CONFIG_MTD_NAND_SH_FLCTL=y 40 40 CONFIG_MTD_UBI=y 41 41 CONFIG_BLK_DEV_RAM=y
+1 -1
arch/sh/configs/ecovec24_defconfig
··· 38 38 CONFIG_MTD_CFI=y 39 39 CONFIG_MTD_CFI_AMDSTD=y 40 40 CONFIG_MTD_PHYSMAP=y 41 - CONFIG_MTD_NAND=y 41 + CONFIG_MTD_RAW_NAND=y 42 42 CONFIG_MTD_UBI=y 43 43 CONFIG_BLK_DEV_RAM=y 44 44 CONFIG_BLK_DEV_RAM_COUNT=4
+1 -1
arch/sh/configs/migor_defconfig
··· 34 34 CONFIG_MTD_CFI=y 35 35 CONFIG_MTD_CFI_AMDSTD=y 36 36 CONFIG_MTD_PHYSMAP=y 37 - CONFIG_MTD_NAND=y 37 + CONFIG_MTD_RAW_NAND=y 38 38 CONFIG_MTD_NAND_PLATFORM=y 39 39 CONFIG_BLK_DEV_RAM=y 40 40 CONFIG_SCSI=y
+1 -1
arch/sh/configs/sdk7786_defconfig
··· 108 108 CONFIG_MTD_ABSENT=m 109 109 CONFIG_MTD_PLATRAM=y 110 110 CONFIG_MTD_PHRAM=y 111 - CONFIG_MTD_NAND=y 111 + CONFIG_MTD_RAW_NAND=y 112 112 CONFIG_MTD_NAND_PLATFORM=y 113 113 CONFIG_MTD_NAND_SH_FLCTL=m 114 114 CONFIG_MTD_UBI=y
+1 -1
arch/sh/configs/se7724_defconfig
··· 37 37 CONFIG_MTD_CFI=y 38 38 CONFIG_MTD_CFI_AMDSTD=y 39 39 CONFIG_MTD_PHYSMAP=y 40 - CONFIG_MTD_NAND=y 40 + CONFIG_MTD_RAW_NAND=y 41 41 CONFIG_MTD_UBI=y 42 42 CONFIG_BLK_DEV_RAM=y 43 43 CONFIG_BLK_DEV_RAM_COUNT=4
+1 -1
arch/sh/configs/titan_defconfig
··· 155 155 CONFIG_RFD_FTL=m 156 156 CONFIG_MTD_CFI=m 157 157 CONFIG_MTD_JEDECPROBE=m 158 - CONFIG_MTD_NAND=m 158 + CONFIG_MTD_RAW_NAND=m 159 159 CONFIG_BLK_DEV_LOOP=m 160 160 CONFIG_BLK_DEV_CRYPTOLOOP=m 161 161 CONFIG_BLK_DEV_RAM=y
+30 -7
drivers/memory/atmel-ebi.c
··· 17 17 #include <linux/init.h> 18 18 #include <linux/of_device.h> 19 19 #include <linux/regmap.h> 20 + #include <soc/at91/atmel-sfr.h> 20 21 21 22 struct atmel_ebi_dev_config { 22 23 int cs; ··· 37 36 struct atmel_ebi_caps { 38 37 unsigned int available_cs; 39 38 unsigned int ebi_csa_offs; 39 + const char *regmap_name; 40 40 void (*get_config)(struct atmel_ebi_dev *ebid, 41 41 struct atmel_ebi_dev_config *conf); 42 42 int (*xlate_config)(struct atmel_ebi_dev *ebid, ··· 49 47 50 48 struct atmel_ebi { 51 49 struct clk *clk; 52 - struct regmap *matrix; 50 + struct regmap *regmap; 53 51 struct { 54 52 struct regmap *regmap; 55 53 struct clk *clk; ··· 359 357 * one "atmel,smc-" property is present. 360 358 */ 361 359 if (ebi->caps->ebi_csa_offs && apply) 362 - regmap_update_bits(ebi->matrix, 360 + regmap_update_bits(ebi->regmap, 363 361 ebi->caps->ebi_csa_offs, 364 362 BIT(cs), 0); 365 363 ··· 374 372 static const struct atmel_ebi_caps at91sam9260_ebi_caps = { 375 373 .available_cs = 0xff, 376 374 .ebi_csa_offs = AT91SAM9260_MATRIX_EBICSA, 375 + .regmap_name = "atmel,matrix", 377 376 .get_config = at91sam9_ebi_get_config, 378 377 .xlate_config = atmel_ebi_xslate_smc_config, 379 378 .apply_config = at91sam9_ebi_apply_config, ··· 383 380 static const struct atmel_ebi_caps at91sam9261_ebi_caps = { 384 381 .available_cs = 0xff, 385 382 .ebi_csa_offs = AT91SAM9261_MATRIX_EBICSA, 383 + .regmap_name = "atmel,matrix", 386 384 .get_config = at91sam9_ebi_get_config, 387 385 .xlate_config = atmel_ebi_xslate_smc_config, 388 386 .apply_config = at91sam9_ebi_apply_config, ··· 392 388 static const struct atmel_ebi_caps at91sam9263_ebi0_caps = { 393 389 .available_cs = 0x3f, 394 390 .ebi_csa_offs = AT91SAM9263_MATRIX_EBI0CSA, 391 + .regmap_name = "atmel,matrix", 395 392 .get_config = at91sam9_ebi_get_config, 396 393 .xlate_config = atmel_ebi_xslate_smc_config, 397 394 .apply_config = at91sam9_ebi_apply_config, ··· 401 396 static const struct atmel_ebi_caps at91sam9263_ebi1_caps = { 402 397 .available_cs = 0x7, 403 398 .ebi_csa_offs = AT91SAM9263_MATRIX_EBI1CSA, 399 + .regmap_name = "atmel,matrix", 404 400 .get_config = at91sam9_ebi_get_config, 405 401 .xlate_config = atmel_ebi_xslate_smc_config, 406 402 .apply_config = at91sam9_ebi_apply_config, ··· 410 404 static const struct atmel_ebi_caps at91sam9rl_ebi_caps = { 411 405 .available_cs = 0x3f, 412 406 .ebi_csa_offs = AT91SAM9RL_MATRIX_EBICSA, 407 + .regmap_name = "atmel,matrix", 413 408 .get_config = at91sam9_ebi_get_config, 414 409 .xlate_config = atmel_ebi_xslate_smc_config, 415 410 .apply_config = at91sam9_ebi_apply_config, ··· 419 412 static const struct atmel_ebi_caps at91sam9g45_ebi_caps = { 420 413 .available_cs = 0x3f, 421 414 .ebi_csa_offs = AT91SAM9G45_MATRIX_EBICSA, 415 + .regmap_name = "atmel,matrix", 422 416 .get_config = at91sam9_ebi_get_config, 423 417 .xlate_config = atmel_ebi_xslate_smc_config, 424 418 .apply_config = at91sam9_ebi_apply_config, ··· 428 420 static const struct atmel_ebi_caps at91sam9x5_ebi_caps = { 429 421 .available_cs = 0x3f, 430 422 .ebi_csa_offs = AT91SAM9X5_MATRIX_EBICSA, 423 + .regmap_name = "atmel,matrix", 431 424 .get_config = at91sam9_ebi_get_config, 432 425 .xlate_config = atmel_ebi_xslate_smc_config, 433 426 .apply_config = at91sam9_ebi_apply_config, ··· 439 430 .get_config = sama5_ebi_get_config, 440 431 .xlate_config = atmel_ebi_xslate_smc_config, 441 432 .apply_config = sama5_ebi_apply_config, 433 + }; 434 + 435 + static const struct atmel_ebi_caps sam9x60_ebi_caps = { 436 + .available_cs = 0x3f, 437 + .ebi_csa_offs = AT91_SFR_CCFG_EBICSA, 438 + .regmap_name = "microchip,sfr", 439 + .get_config = at91sam9_ebi_get_config, 440 + .xlate_config = atmel_ebi_xslate_smc_config, 441 + .apply_config = at91sam9_ebi_apply_config, 442 442 }; 443 443 444 444 static const struct of_device_id atmel_ebi_id_table[] = { ··· 482 464 { 483 465 .compatible = "atmel,sama5d3-ebi", 484 466 .data = &sama5d3_ebi_caps, 467 + }, 468 + { 469 + .compatible = "microchip,sam9x60-ebi", 470 + .data = &sam9x60_ebi_caps, 485 471 }, 486 472 { /* sentinel */ } 487 473 }; ··· 565 543 566 544 /* 567 545 * The sama5d3 does not provide an EBICSA register and thus does need 568 - * to access the matrix registers. 546 + * to access it. 569 547 */ 570 548 if (ebi->caps->ebi_csa_offs) { 571 - ebi->matrix = 572 - syscon_regmap_lookup_by_phandle(np, "atmel,matrix"); 573 - if (IS_ERR(ebi->matrix)) 574 - return PTR_ERR(ebi->matrix); 549 + ebi->regmap = 550 + syscon_regmap_lookup_by_phandle(np, 551 + ebi->caps->regmap_name); 552 + if (IS_ERR(ebi->regmap)) 553 + return PTR_ERR(ebi->regmap); 575 554 } 576 555 577 556 ret = of_property_read_u32(np, "#address-cells", &val);
+2 -18
drivers/mtd/Kconfig
··· 60 60 61 61 If unsure, say 'N'. 62 62 63 - config MTD_AFS_PARTS 64 - tristate "ARM Firmware Suite partition parsing" 65 - depends on (ARM || ARM64) 66 - help 67 - The ARM Firmware Suite allows the user to divide flash devices into 68 - multiple 'images'. Each such image has a header containing its name 69 - and offset/size etc. 70 - 71 - If you need code which can detect and parse these tables, and 72 - register MTD 'partitions' corresponding to each image detected, 73 - enable this option. 74 - 75 - You will still need the parsing functions to be called by the driver 76 - for your particular device. It won't happen automatically. The 77 - 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example. 78 - 79 63 config MTD_OF_PARTS 80 64 tristate "OpenFirmware partitioning information support" 81 65 default y ··· 78 94 tristate "BCM63XX CFE partitioning support" 79 95 depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST 80 96 select CRC32 97 + select MTD_PARSER_IMAGETAG 81 98 help 82 99 This provides partition parsing for BCM63xx devices with CFE 83 100 bootloaders. ··· 215 230 This enables read only access to SmartMedia formatted NAND 216 231 flash. You can mount it with FAT file system. 217 232 218 - 219 233 config SM_FTL 220 234 tristate "SmartMedia/xD new translation layer" 221 235 depends on BLOCK 222 236 select MTD_BLKDEVS 223 - select MTD_NAND_ECC 237 + select MTD_NAND_ECC_SW_HAMMING 224 238 help 225 239 This enables EXPERIMENTAL R/W support for SmartMedia/xD 226 240 FTL (Flash translation layer).
-1
drivers/mtd/Makefile
··· 9 9 10 10 obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o 11 11 obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o 12 - obj-$(CONFIG_MTD_AFS_PARTS) += afs.o 13 12 obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o 14 13 obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o 15 14 obj-$(CONFIG_MTD_BCM47XX_PARTS) += bcm47xxpart.o
-266
drivers/mtd/afs.c
··· 1 - /*====================================================================== 2 - 3 - drivers/mtd/afs.c: ARM Flash Layout/Partitioning 4 - 5 - Copyright © 2000 ARM Limited 6 - 7 - This program is free software; you can redistribute it and/or modify 8 - it under the terms of the GNU General Public License as published by 9 - the Free Software Foundation; either version 2 of the License, or 10 - (at your option) any later version. 11 - 12 - This program is distributed in the hope that it will be useful, 13 - but WITHOUT ANY WARRANTY; without even the implied warranty of 14 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 - GNU General Public License for more details. 16 - 17 - You should have received a copy of the GNU General Public License 18 - along with this program; if not, write to the Free Software 19 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 - 21 - This is access code for flashes using ARM's flash partitioning 22 - standards. 23 - 24 - ======================================================================*/ 25 - 26 - #include <linux/module.h> 27 - #include <linux/types.h> 28 - #include <linux/kernel.h> 29 - #include <linux/slab.h> 30 - #include <linux/string.h> 31 - #include <linux/init.h> 32 - 33 - #include <linux/mtd/mtd.h> 34 - #include <linux/mtd/map.h> 35 - #include <linux/mtd/partitions.h> 36 - 37 - #define AFSV1_FOOTER_MAGIC 0xA0FFFF9F 38 - 39 - struct footer_v1 { 40 - u32 image_info_base; /* Address of first word of ImageFooter */ 41 - u32 image_start; /* Start of area reserved by this footer */ 42 - u32 signature; /* 'Magic' number proves it's a footer */ 43 - u32 type; /* Area type: ARM Image, SIB, customer */ 44 - u32 checksum; /* Just this structure */ 45 - }; 46 - 47 - struct image_info_v1 { 48 - u32 bootFlags; /* Boot flags, compression etc. */ 49 - u32 imageNumber; /* Unique number, selects for boot etc. */ 50 - u32 loadAddress; /* Address program should be loaded to */ 51 - u32 length; /* Actual size of image */ 52 - u32 address; /* Image is executed from here */ 53 - char name[16]; /* Null terminated */ 54 - u32 headerBase; /* Flash Address of any stripped header */ 55 - u32 header_length; /* Length of header in memory */ 56 - u32 headerType; /* AIF, RLF, s-record etc. */ 57 - u32 checksum; /* Image checksum (inc. this struct) */ 58 - }; 59 - 60 - static u32 word_sum(void *words, int num) 61 - { 62 - u32 *p = words; 63 - u32 sum = 0; 64 - 65 - while (num--) 66 - sum += *p++; 67 - 68 - return sum; 69 - } 70 - 71 - static int 72 - afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, 73 - u_int off, u_int mask) 74 - { 75 - struct footer_v1 fs; 76 - u_int ptr = off + mtd->erasesize - sizeof(fs); 77 - size_t sz; 78 - int ret; 79 - 80 - ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); 81 - if (ret >= 0 && sz != sizeof(fs)) 82 - ret = -EINVAL; 83 - 84 - if (ret < 0) { 85 - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 86 - ptr, ret); 87 - return ret; 88 - } 89 - 90 - /* 91 - * Does it contain the magic number? 92 - */ 93 - if (fs.signature != AFSV1_FOOTER_MAGIC) 94 - return 0; 95 - 96 - /* 97 - * Check the checksum. 98 - */ 99 - if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) 100 - return 0; 101 - 102 - /* 103 - * Don't touch the SIB. 104 - */ 105 - if (fs.type == 2) 106 - return 0; 107 - 108 - *iis_start = fs.image_info_base & mask; 109 - *img_start = fs.image_start & mask; 110 - 111 - /* 112 - * Check the image info base. This can not 113 - * be located after the footer structure. 114 - */ 115 - if (*iis_start >= ptr) 116 - return 0; 117 - 118 - /* 119 - * Check the start of this image. The image 120 - * data can not be located after this block. 121 - */ 122 - if (*img_start > off) 123 - return 0; 124 - 125 - return 1; 126 - } 127 - 128 - static int 129 - afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr) 130 - { 131 - size_t sz; 132 - int ret, i; 133 - 134 - memset(iis, 0, sizeof(*iis)); 135 - ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis); 136 - if (ret < 0) 137 - goto failed; 138 - 139 - if (sz != sizeof(*iis)) { 140 - ret = -EINVAL; 141 - goto failed; 142 - } 143 - 144 - ret = 0; 145 - 146 - /* 147 - * Validate the name - it must be NUL terminated. 148 - */ 149 - for (i = 0; i < sizeof(iis->name); i++) 150 - if (iis->name[i] == '\0') 151 - break; 152 - 153 - if (i < sizeof(iis->name)) 154 - ret = 1; 155 - 156 - return ret; 157 - 158 - failed: 159 - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 160 - ptr, ret); 161 - return ret; 162 - } 163 - 164 - static int parse_afs_partitions(struct mtd_info *mtd, 165 - const struct mtd_partition **pparts, 166 - struct mtd_part_parser_data *data) 167 - { 168 - struct mtd_partition *parts; 169 - u_int mask, off, idx, sz; 170 - int ret = 0; 171 - char *str; 172 - 173 - /* 174 - * This is the address mask; we use this to mask off out of 175 - * range address bits. 176 - */ 177 - mask = mtd->size - 1; 178 - 179 - /* 180 - * First, calculate the size of the array we need for the 181 - * partition information. We include in this the size of 182 - * the strings. 183 - */ 184 - for (idx = off = sz = 0; off < mtd->size; off += mtd->erasesize) { 185 - struct image_info_v1 iis; 186 - u_int iis_ptr, img_ptr; 187 - 188 - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 189 - if (ret < 0) 190 - break; 191 - if (ret) { 192 - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 193 - if (ret < 0) 194 - break; 195 - if (ret == 0) 196 - continue; 197 - 198 - sz += sizeof(struct mtd_partition); 199 - sz += strlen(iis.name) + 1; 200 - idx += 1; 201 - } 202 - } 203 - 204 - if (!sz) 205 - return ret; 206 - 207 - parts = kzalloc(sz, GFP_KERNEL); 208 - if (!parts) 209 - return -ENOMEM; 210 - 211 - str = (char *)(parts + idx); 212 - 213 - /* 214 - * Identify the partitions 215 - */ 216 - for (idx = off = 0; off < mtd->size; off += mtd->erasesize) { 217 - struct image_info_v1 iis; 218 - u_int iis_ptr, img_ptr; 219 - 220 - /* Read the footer. */ 221 - ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask); 222 - if (ret < 0) 223 - break; 224 - if (ret == 0) 225 - continue; 226 - 227 - /* Read the image info block */ 228 - ret = afs_read_iis_v1(mtd, &iis, iis_ptr); 229 - if (ret < 0) 230 - break; 231 - if (ret == 0) 232 - continue; 233 - 234 - strcpy(str, iis.name); 235 - 236 - parts[idx].name = str; 237 - parts[idx].size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); 238 - parts[idx].offset = img_ptr; 239 - parts[idx].mask_flags = 0; 240 - 241 - printk(" mtd%d: at 0x%08x, %5lluKiB, %8u, %s\n", 242 - idx, img_ptr, parts[idx].size / 1024, 243 - iis.imageNumber, str); 244 - 245 - idx += 1; 246 - str = str + strlen(iis.name) + 1; 247 - } 248 - 249 - if (!idx) { 250 - kfree(parts); 251 - parts = NULL; 252 - } 253 - 254 - *pparts = parts; 255 - return idx ? idx : ret; 256 - } 257 - 258 - static struct mtd_part_parser afs_parser = { 259 - .parse_fn = parse_afs_partitions, 260 - .name = "afs", 261 - }; 262 - module_mtd_part_parser(afs_parser); 263 - 264 - MODULE_AUTHOR("ARM Ltd"); 265 - MODULE_DESCRIPTION("ARM Firmware Suite partition parser"); 266 - MODULE_LICENSE("GPL");
+16 -147
drivers/mtd/bcm63xxpart.c
··· 34 34 #include <linux/vmalloc.h> 35 35 #include <linux/mtd/mtd.h> 36 36 #include <linux/mtd/partitions.h> 37 + #include <linux/of.h> 37 38 38 39 #define BCM963XX_CFE_BLOCK_SIZE SZ_64K /* always at least 64KiB */ 39 40 ··· 94 93 return 0; 95 94 } 96 95 97 - static int bcm63xx_read_image_tag(struct mtd_info *master, const char *name, 98 - loff_t tag_offset, struct bcm_tag *buf) 99 - { 100 - int ret; 101 - size_t retlen; 102 - u32 computed_crc; 103 - 104 - ret = mtd_read(master, tag_offset, sizeof(*buf), &retlen, (void *)buf); 105 - if (ret) 106 - return ret; 107 - 108 - if (retlen != sizeof(*buf)) 109 - return -EIO; 110 - 111 - computed_crc = crc32_le(IMAGETAG_CRC_START, (u8 *)buf, 112 - offsetof(struct bcm_tag, header_crc)); 113 - if (computed_crc == buf->header_crc) { 114 - STR_NULL_TERMINATE(buf->board_id); 115 - STR_NULL_TERMINATE(buf->tag_version); 116 - 117 - pr_info("%s: CFE image tag found at 0x%llx with version %s, board type %s\n", 118 - name, tag_offset, buf->tag_version, buf->board_id); 119 - 120 - return 0; 121 - } 122 - 123 - pr_warn("%s: CFE image tag at 0x%llx CRC invalid (expected %08x, actual %08x)\n", 124 - name, tag_offset, buf->header_crc, computed_crc); 125 - return 1; 126 - } 96 + static const char * const bcm63xx_cfe_part_types[] = { 97 + "bcm963xx-imagetag", 98 + NULL, 99 + }; 127 100 128 101 static int bcm63xx_parse_cfe_nor_partitions(struct mtd_info *master, 129 102 const struct mtd_partition **pparts, struct bcm963xx_nvram *nvram) 130 103 { 131 - /* CFE, NVRAM and global Linux are always present */ 132 - int nrparts = 3, curpart = 0; 133 - struct bcm_tag *buf = NULL; 134 104 struct mtd_partition *parts; 135 - int ret; 136 - unsigned int rootfsaddr, kerneladdr, spareaddr; 137 - unsigned int rootfslen, kernellen, sparelen, totallen; 105 + int nrparts = 3, curpart = 0; 138 106 unsigned int cfelen, nvramlen; 139 107 unsigned int cfe_erasesize; 140 108 int i; 141 - bool rootfs_first = false; 142 109 143 110 cfe_erasesize = max_t(uint32_t, master->erasesize, 144 111 BCM963XX_CFE_BLOCK_SIZE); ··· 115 146 nvramlen = nvram->psi_size * SZ_1K; 116 147 nvramlen = roundup(nvramlen, cfe_erasesize); 117 148 118 - buf = vmalloc(sizeof(struct bcm_tag)); 119 - if (!buf) 120 - return -ENOMEM; 121 - 122 - /* Get the tag */ 123 - ret = bcm63xx_read_image_tag(master, "rootfs", cfelen, buf); 124 - if (!ret) { 125 - STR_NULL_TERMINATE(buf->flash_image_start); 126 - if (kstrtouint(buf->flash_image_start, 10, &rootfsaddr) || 127 - rootfsaddr < BCM963XX_EXTENDED_SIZE) { 128 - pr_err("invalid rootfs address: %*ph\n", 129 - (int)sizeof(buf->flash_image_start), 130 - buf->flash_image_start); 131 - goto invalid_tag; 132 - } 133 - 134 - STR_NULL_TERMINATE(buf->kernel_address); 135 - if (kstrtouint(buf->kernel_address, 10, &kerneladdr) || 136 - kerneladdr < BCM963XX_EXTENDED_SIZE) { 137 - pr_err("invalid kernel address: %*ph\n", 138 - (int)sizeof(buf->kernel_address), 139 - buf->kernel_address); 140 - goto invalid_tag; 141 - } 142 - 143 - STR_NULL_TERMINATE(buf->kernel_length); 144 - if (kstrtouint(buf->kernel_length, 10, &kernellen)) { 145 - pr_err("invalid kernel length: %*ph\n", 146 - (int)sizeof(buf->kernel_length), 147 - buf->kernel_length); 148 - goto invalid_tag; 149 - } 150 - 151 - STR_NULL_TERMINATE(buf->total_length); 152 - if (kstrtouint(buf->total_length, 10, &totallen)) { 153 - pr_err("invalid total length: %*ph\n", 154 - (int)sizeof(buf->total_length), 155 - buf->total_length); 156 - goto invalid_tag; 157 - } 158 - 159 - kerneladdr = kerneladdr - BCM963XX_EXTENDED_SIZE; 160 - rootfsaddr = rootfsaddr - BCM963XX_EXTENDED_SIZE; 161 - spareaddr = roundup(totallen, master->erasesize) + cfelen; 162 - 163 - if (rootfsaddr < kerneladdr) { 164 - /* default Broadcom layout */ 165 - rootfslen = kerneladdr - rootfsaddr; 166 - rootfs_first = true; 167 - } else { 168 - /* OpenWrt layout */ 169 - rootfsaddr = kerneladdr + kernellen; 170 - rootfslen = spareaddr - rootfsaddr; 171 - } 172 - } else if (ret > 0) { 173 - invalid_tag: 174 - kernellen = 0; 175 - rootfslen = 0; 176 - rootfsaddr = 0; 177 - spareaddr = cfelen; 178 - } else { 179 - goto out; 180 - } 181 - sparelen = master->size - spareaddr - nvramlen; 182 - 183 - /* Determine number of partitions */ 184 - if (rootfslen > 0) 185 - nrparts++; 186 - 187 - if (kernellen > 0) 188 - nrparts++; 189 - 190 149 parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); 191 - if (!parts) { 192 - ret = -ENOMEM; 193 - goto out; 194 - } 150 + if (!parts) 151 + return -ENOMEM; 195 152 196 153 /* Start building partition list */ 197 154 parts[curpart].name = "CFE"; 198 155 parts[curpart].offset = 0; 199 156 parts[curpart].size = cfelen; 200 157 curpart++; 201 - 202 - if (kernellen > 0) { 203 - int kernelpart = curpart; 204 - 205 - if (rootfslen > 0 && rootfs_first) 206 - kernelpart++; 207 - parts[kernelpart].name = "kernel"; 208 - parts[kernelpart].offset = kerneladdr; 209 - parts[kernelpart].size = kernellen; 210 - curpart++; 211 - } 212 - 213 - if (rootfslen > 0) { 214 - int rootfspart = curpart; 215 - 216 - if (kernellen > 0 && rootfs_first) 217 - rootfspart--; 218 - parts[rootfspart].name = "rootfs"; 219 - parts[rootfspart].offset = rootfsaddr; 220 - parts[rootfspart].size = rootfslen; 221 - if (sparelen > 0 && !rootfs_first) 222 - parts[rootfspart].size += sparelen; 223 - curpart++; 224 - } 225 158 226 159 parts[curpart].name = "nvram"; 227 160 parts[curpart].offset = master->size - nvramlen; ··· 134 263 parts[curpart].name = "linux"; 135 264 parts[curpart].offset = cfelen; 136 265 parts[curpart].size = master->size - cfelen - nvramlen; 266 + parts[curpart].types = bcm63xx_cfe_part_types; 137 267 138 268 for (i = 0; i < nrparts; i++) 139 269 pr_info("Partition %d is %s offset %llx and length %llx\n", i, 140 270 parts[i].name, parts[i].offset, parts[i].size); 141 271 142 - pr_info("Spare partition is offset %x and length %x\n", spareaddr, 143 - sparelen); 144 - 145 272 *pparts = parts; 146 - ret = 0; 147 - 148 - out: 149 - vfree(buf); 150 - 151 - if (ret) 152 - return ret; 153 273 154 274 return nrparts; 155 275 } ··· 173 311 return ret; 174 312 }; 175 313 314 + static const struct of_device_id parse_bcm63xx_cfe_match_table[] = { 315 + { .compatible = "brcm,bcm963xx-cfe-nor-partitions" }, 316 + {}, 317 + }; 318 + MODULE_DEVICE_TABLE(of, parse_bcm63xx_cfe_match_table); 319 + 176 320 static struct mtd_part_parser bcm63xx_cfe_parser = { 177 321 .parse_fn = bcm63xx_parse_cfe_partitions, 178 322 .name = "bcm63xxpart", 323 + .of_match_table = parse_bcm63xx_cfe_match_table, 179 324 }; 180 325 module_mtd_part_parser(bcm63xx_cfe_parser); 181 326
+2
drivers/mtd/chips/cfi_cmdset_0002.c
··· 869 869 /* Only if there's no operation suspended... */ 870 870 if (mode == FL_READY && chip->oldstate == FL_READY) 871 871 return 0; 872 + /* fall through */ 872 873 873 874 default: 874 875 sleep: ··· 2752 2751 * as the whole point is that nobody can do anything 2753 2752 * with the chip now anyway. 2754 2753 */ 2754 + /* fall through */ 2755 2755 case FL_SYNCING: 2756 2756 mutex_unlock(&chip->mutex); 2757 2757 break;
+6
drivers/mtd/chips/cfi_util.c
··· 109 109 case 8: 110 110 onecmd |= (onecmd << (chip_mode * 32)); 111 111 #endif 112 + /* fall through */ 112 113 case 4: 113 114 onecmd |= (onecmd << (chip_mode * 16)); 115 + /* fall through */ 114 116 case 2: 115 117 onecmd |= (onecmd << (chip_mode * 8)); 118 + /* fall through */ 116 119 case 1: 117 120 ; 118 121 } ··· 165 162 case 8: 166 163 res |= (onestat >> (chip_mode * 32)); 167 164 #endif 165 + /* fall through */ 168 166 case 4: 169 167 res |= (onestat >> (chip_mode * 16)); 168 + /* fall through */ 170 169 case 2: 171 170 res |= (onestat >> (chip_mode * 8)); 171 + /* fall through */ 172 172 case 1: 173 173 ; 174 174 }
+1 -1
drivers/mtd/devices/Kconfig
··· 207 207 config MTD_DOCG3 208 208 tristate "M-Systems Disk-On-Chip G3" 209 209 select BCH 210 - select BCH_CONST_PARAMS if !MTD_NAND_BCH 210 + select BCH_CONST_PARAMS if !MTD_NAND_ECC_SW_BCH 211 211 select BITREVERSE 212 212 help 213 213 This provides an MTD device driver for the M-Systems DiskOnChip
+2
drivers/mtd/devices/phram.c
··· 147 147 switch (token[len - 2]) { 148 148 case 'G': 149 149 shift += 10; 150 + /* fall through */ 150 151 case 'M': 151 152 shift += 10; 153 + /* fall through */ 152 154 case 'k': 153 155 shift += 10; 154 156 token[len - 2] = 0;
+1
drivers/mtd/lpddr/lpddr_cmds.c
··· 318 318 /* Only if there's no operation suspended... */ 319 319 if (mode == FL_READY && chip->oldstate == FL_READY) 320 320 return 0; 321 + /* fall through */ 321 322 322 323 default: 323 324 sleep:
+1 -1
drivers/mtd/maps/Kconfig
··· 10 10 11 11 config MTD_PHYSMAP 12 12 tristate "Flash device in physical memory map" 13 - depends on MTD_CFI || MTD_JEDECPROBE || MTD_ROM || MTD_LPDDR 13 + depends on MTD_CFI || MTD_JEDECPROBE || MTD_ROM || MTD_RAM || MTD_LPDDR 14 14 help 15 15 This provides a 'mapping' driver which allows the NOR Flash and 16 16 ROM driver code to communicate with chips which are mapped
+2
drivers/mtd/maps/physmap-core.c
··· 132 132 133 133 gpiod_set_value(info->gpios->desc[i], !!(BIT(i) & ofs)); 134 134 } 135 + 136 + info->gpio_values = ofs; 135 137 } 136 138 137 139 #define win_mask(order) (BIT(order) - 1)
+1 -1
drivers/mtd/maps/physmap-gemini.c
··· 86 86 static map_word __xipram gemini_flash_map_read(struct map_info *map, 87 87 unsigned long ofs) 88 88 { 89 - map_word __xipram ret; 89 + map_word ret; 90 90 91 91 gemini_flash_enable_pins(); 92 92 ret = inline_map_read(map, ofs);
+1 -7
drivers/mtd/maps/uclinux.c
··· 31 31 #define MAP_NAME "ram" 32 32 #endif 33 33 34 - /* 35 - * Blackfin uses uclinux_ram_map during startup, so it must not be static. 36 - * Provide a dummy declaration to make sparse happy. 37 - */ 38 - extern struct map_info uclinux_ram_map; 39 - 40 - struct map_info uclinux_ram_map = { 34 + static struct map_info uclinux_ram_map = { 41 35 .name = MAP_NAME, 42 36 .size = 0, 43 37 };
+1 -1
drivers/mtd/mtdpart.c
··· 572 572 { 573 573 struct mtd_info *mtd = dev_get_drvdata(dev); 574 574 struct mtd_part *part = mtd_to_part(mtd); 575 - return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset); 575 + return snprintf(buf, PAGE_SIZE, "%llu\n", part->offset); 576 576 } 577 577 578 578 static DEVICE_ATTR(offset, S_IRUGO, mtd_partition_offset_show, NULL);
-1
drivers/mtd/nand/Kconfig
··· 2 2 tristate 3 3 4 4 source "drivers/mtd/nand/onenand/Kconfig" 5 - 6 5 source "drivers/mtd/nand/raw/Kconfig" 7 6 source "drivers/mtd/nand/spi/Kconfig"
+34
drivers/mtd/nand/core.c
··· 174 174 EXPORT_SYMBOL_GPL(nanddev_mtd_erase); 175 175 176 176 /** 177 + * nanddev_mtd_max_bad_blocks() - Get the maximum number of bad eraseblock on 178 + * a specific region of the NAND device 179 + * @mtd: MTD device 180 + * @offs: offset of the NAND region 181 + * @len: length of the NAND region 182 + * 183 + * Default implementation for mtd->_max_bad_blocks(). Only works if 184 + * nand->memorg.max_bad_eraseblocks_per_lun is > 0. 185 + * 186 + * Return: a positive number encoding the maximum number of eraseblocks on a 187 + * portion of memory, a negative error code otherwise. 188 + */ 189 + int nanddev_mtd_max_bad_blocks(struct mtd_info *mtd, loff_t offs, size_t len) 190 + { 191 + struct nand_device *nand = mtd_to_nanddev(mtd); 192 + struct nand_pos pos, end; 193 + unsigned int max_bb = 0; 194 + 195 + if (!nand->memorg.max_bad_eraseblocks_per_lun) 196 + return -ENOTSUPP; 197 + 198 + nanddev_offs_to_pos(nand, offs, &pos); 199 + nanddev_offs_to_pos(nand, offs + len, &end); 200 + 201 + for (nanddev_offs_to_pos(nand, offs, &pos); 202 + nanddev_pos_cmp(&pos, &end) < 0; 203 + nanddev_pos_next_lun(nand, &pos)) 204 + max_bb += nand->memorg.max_bad_eraseblocks_per_lun; 205 + 206 + return max_bb; 207 + } 208 + EXPORT_SYMBOL_GPL(nanddev_mtd_max_bad_blocks); 209 + 210 + /** 177 211 * nanddev_init() - Initialize a NAND device 178 212 * @nand: NAND device 179 213 * @ops: NAND device operations
+4 -1
drivers/mtd/nand/onenand/onenand_base.c
··· 2458 2458 bbm->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 2459 2459 2460 2460 /* We write two bytes, so we don't have to mess with 16-bit access */ 2461 - ofs += mtd->oobsize + (bbm->badblockpos & ~0x01); 2461 + ofs += mtd->oobsize + (this->badblockpos & ~0x01); 2462 2462 /* FIXME : What to do when marking SLC block in partition 2463 2463 * with MLC erasesize? For now, it is not advisable to 2464 2464 * create partitions containing both SLC and MLC regions. ··· 3966 3966 /* Unlock whole block */ 3967 3967 if (!(this->options & ONENAND_SKIP_INITIAL_UNLOCKING)) 3968 3968 this->unlock_all(mtd); 3969 + 3970 + /* Set the bad block marker position */ 3971 + this->badblockpos = ONENAND_BADBLOCK_POS; 3969 3972 3970 3973 ret = this->scan_bbt(mtd); 3971 3974 if ((!FLEXONENAND(this)) || ret)
-3
drivers/mtd/nand/onenand/onenand_bbt.c
··· 190 190 if (!bbm->bbt) 191 191 return -ENOMEM; 192 192 193 - /* Set the bad block position */ 194 - bbm->badblockpos = ONENAND_BADBLOCK_POS; 195 - 196 193 /* Set erase shift */ 197 194 bbm->bbt_erase_shift = this->erase_shift; 198 195
+371 -384
drivers/mtd/nand/raw/Kconfig
··· 1 - config MTD_NAND_ECC 1 + config MTD_NAND_ECC_SW_HAMMING 2 2 tristate 3 3 4 - config MTD_NAND_ECC_SMC 4 + config MTD_NAND_ECC_SW_HAMMING_SMC 5 5 bool "NAND ECC Smart Media byte order" 6 - depends on MTD_NAND_ECC 6 + depends on MTD_NAND_ECC_SW_HAMMING 7 7 default n 8 8 help 9 9 Software ECC according to the Smart Media Specification. 10 10 The original Linux implementation had byte 0 and 1 swapped. 11 11 12 - 13 - menuconfig MTD_NAND 12 + menuconfig MTD_RAW_NAND 14 13 tristate "Raw/Parallel NAND Device Support" 15 14 depends on MTD 16 - select MTD_NAND_ECC 15 + select MTD_NAND_CORE 16 + select MTD_NAND_ECC_SW_HAMMING 17 17 help 18 18 This enables support for accessing all type of raw/parallel 19 19 NAND flash devices. For further information see 20 20 <http://www.linux-mtd.infradead.org/doc/nand.html>. 21 21 22 - if MTD_NAND 22 + if MTD_RAW_NAND 23 23 24 - config MTD_NAND_BCH 25 - tristate 26 - select BCH 27 - depends on MTD_NAND_ECC_BCH 28 - default MTD_NAND 29 - 30 - config MTD_NAND_ECC_BCH 24 + config MTD_NAND_ECC_SW_BCH 31 25 bool "Support software BCH ECC" 26 + select BCH 32 27 default n 33 28 help 34 29 This enables support for software BCH error correction. Binary BCH ··· 31 36 ECC codes. They are used with NAND devices requiring more than 1 bit 32 37 of error correction. 33 38 34 - config MTD_SM_COMMON 35 - tristate 36 - default n 39 + comment "Raw/parallel NAND flash controllers" 37 40 38 41 config MTD_NAND_DENALI 39 42 tristate 40 43 41 44 config MTD_NAND_DENALI_PCI 42 - tristate "Support Denali NAND controller on Intel Moorestown" 45 + tristate "Denali NAND controller on Intel Moorestown" 43 46 select MTD_NAND_DENALI 44 47 depends on PCI 45 48 help ··· 45 52 Denali NAND controller core. 46 53 47 54 config MTD_NAND_DENALI_DT 48 - tristate "Support Denali NAND controller as a DT device" 55 + tristate "Denali NAND controller as a DT device" 49 56 select MTD_NAND_DENALI 50 57 depends on HAS_DMA && HAVE_CLK && OF 51 58 help 52 59 Enable the driver for NAND flash on platforms using a Denali NAND 53 60 controller as a DT device. 54 61 55 - config MTD_NAND_GPIO 56 - tristate "GPIO assisted NAND Flash driver" 57 - depends on GPIOLIB || COMPILE_TEST 58 - depends on HAS_IOMEM 59 - help 60 - This enables a NAND flash driver where control signals are 61 - connected to GPIO pins, and commands and data are communicated 62 - via a memory mapped interface. 63 - 64 62 config MTD_NAND_AMS_DELTA 65 - tristate "NAND Flash device on Amstrad E3" 63 + tristate "Amstrad E3 NAND controller" 66 64 depends on MACH_AMS_DELTA || COMPILE_TEST 67 65 default y 68 66 help 69 67 Support for NAND flash on Amstrad E3 (Delta). 70 68 71 69 config MTD_NAND_OMAP2 72 - tristate "NAND Flash device on OMAP2, OMAP3, OMAP4 and Keystone" 70 + tristate "OMAP2, OMAP3, OMAP4 and Keystone NAND controller" 73 71 depends on ARCH_OMAP2PLUS || ARCH_KEYSTONE || COMPILE_TEST 74 72 depends on HAS_IOMEM 75 73 help ··· 82 98 config MTD_NAND_OMAP_BCH_BUILD 83 99 def_tristate MTD_NAND_OMAP2 && MTD_NAND_OMAP_BCH 84 100 85 - config MTD_NAND_RICOH 86 - tristate "Ricoh xD card reader" 87 - default n 88 - depends on PCI 89 - select MTD_SM_COMMON 90 - help 91 - Enable support for Ricoh R5C852 xD card reader 92 - You also need to enable ether 93 - NAND SSFDC (SmartMedia) read only translation layer' or new 94 - expermental, readwrite 95 - 'SmartMedia/xD new translation layer' 96 - 97 101 config MTD_NAND_AU1550 98 102 tristate "Au1550/1200 NAND support" 99 103 depends on MIPS_ALCHEMY ··· 89 117 This enables the driver for the NAND flash controller on the 90 118 AMD/Alchemy 1550 SOC. 91 119 120 + config MTD_NAND_NDFC 121 + tristate "IBM/MCC 4xx NAND controller" 122 + depends on 4xx 123 + select MTD_NAND_ECC_SW_HAMMING_SMC 124 + help 125 + NDFC Nand Flash Controllers are integrated in IBM/AMCC's 4xx SoCs 126 + 92 127 config MTD_NAND_S3C2410 93 - tristate "NAND Flash support for Samsung S3C SoCs" 128 + tristate "Samsung S3C NAND controller" 94 129 depends on ARCH_S3C24XX || ARCH_S3C64XX 95 130 help 96 131 This enables the NAND flash controller on the S3C24xx and S3C64xx ··· 107 128 must advertise a platform_device for the driver to attach. 108 129 109 130 config MTD_NAND_S3C2410_DEBUG 110 - bool "Samsung S3C NAND driver debug" 131 + bool "Samsung S3C NAND controller debug" 111 132 depends on MTD_NAND_S3C2410 112 133 help 113 134 Enable debugging of the S3C NAND driver 114 - 115 - config MTD_NAND_NDFC 116 - tristate "NDFC NanD Flash Controller" 117 - depends on 4xx 118 - select MTD_NAND_ECC_SMC 119 - help 120 - NDFC Nand Flash Controllers are integrated in IBM/AMCC's 4xx SoCs 121 135 122 136 config MTD_NAND_S3C2410_CLKSTOP 123 137 bool "Samsung S3C NAND IDLE clock stop" ··· 123 151 approximately 5mA of power when there is nothing happening. 124 152 125 153 config MTD_NAND_TANGO 126 - tristate "NAND Flash support for Tango chips" 154 + tristate "Tango NAND controller" 127 155 depends on ARCH_TANGO || COMPILE_TEST 128 156 depends on HAS_IOMEM 129 157 help 130 158 Enables the NAND Flash controller on Tango chips. 159 + 160 + config MTD_NAND_SHARPSL 161 + tristate "Sharp SL Series (C7xx + others) NAND controller" 162 + depends on ARCH_PXA || COMPILE_TEST 163 + depends on HAS_IOMEM 164 + 165 + config MTD_NAND_CAFE 166 + tristate "OLPC CAFÉ NAND controller" 167 + depends on PCI 168 + select REED_SOLOMON 169 + select REED_SOLOMON_DEC16 170 + help 171 + Use NAND flash attached to the CAFÉ chip designed for the OLPC 172 + laptop. 173 + 174 + config MTD_NAND_CS553X 175 + tristate "CS5535/CS5536 (AMD Geode companion) NAND controller" 176 + depends on X86_32 177 + depends on !UML && HAS_IOMEM 178 + help 179 + The CS553x companion chips for the AMD Geode processor 180 + include NAND flash controllers with built-in hardware ECC 181 + capabilities; enabling this option will allow you to use 182 + these. The driver will check the MSRs to verify that the 183 + controller is enabled for NAND, and currently requires that 184 + the controller be in MMIO mode. 185 + 186 + If you say "m", the module will be called cs553x_nand. 187 + 188 + config MTD_NAND_ATMEL 189 + tristate "Atmel AT91 NAND Flash/SmartMedia NAND controller" 190 + depends on ARCH_AT91 || COMPILE_TEST 191 + depends on HAS_IOMEM 192 + select GENERIC_ALLOCATOR 193 + select MFD_ATMEL_SMC 194 + help 195 + Enables support for NAND Flash / Smart Media Card interface 196 + on Atmel AT91 processors. 197 + 198 + config MTD_NAND_ORION 199 + tristate "Marvell Orion NAND controller" 200 + depends on PLAT_ORION 201 + help 202 + This enables the NAND flash controller on Orion machines. 203 + 204 + No board specific support is done by this driver, each board 205 + must advertise a platform_device for the driver to attach. 206 + 207 + config MTD_NAND_MARVELL 208 + tristate "Marvell EBU NAND controller" 209 + depends on PXA3xx || ARCH_MMP || PLAT_ORION || ARCH_MVEBU || \ 210 + COMPILE_TEST 211 + depends on HAS_IOMEM 212 + help 213 + This enables the NAND flash controller driver for Marvell boards, 214 + including: 215 + - PXA3xx processors (NFCv1) 216 + - 32-bit Armada platforms (XP, 37x, 38x, 39x) (NFCv2) 217 + - 64-bit Aramda platforms (7k, 8k) (NFCv2) 218 + 219 + config MTD_NAND_SLC_LPC32XX 220 + tristate "NXP LPC32xx SLC NAND controller" 221 + depends on ARCH_LPC32XX || COMPILE_TEST 222 + depends on HAS_IOMEM 223 + help 224 + Enables support for NXP's LPC32XX SLC (i.e. for Single Level Cell 225 + chips) NAND controller. This is the default for the PHYTEC 3250 226 + reference board which contains a NAND256R3A2CZA6 chip. 227 + 228 + Please check the actual NAND chip connected and its support 229 + by the SLC NAND controller. 230 + 231 + config MTD_NAND_MLC_LPC32XX 232 + tristate "NXP LPC32xx MLC NAND controller" 233 + depends on ARCH_LPC32XX || COMPILE_TEST 234 + depends on HAS_IOMEM 235 + help 236 + Uses the LPC32XX MLC (i.e. for Multi Level Cell chips) NAND 237 + controller. This is the default for the WORK92105 controller 238 + board. 239 + 240 + Please check the actual NAND chip connected and its support 241 + by the MLC NAND controller. 242 + 243 + config MTD_NAND_CM_X270 244 + tristate "CM-X270 modules NAND controller" 245 + depends on MACH_ARMCORE 246 + 247 + config MTD_NAND_PASEMI 248 + tristate "PA Semi PWRficient NAND controller" 249 + depends on PPC_PASEMI 250 + help 251 + Enables support for NAND Flash interface on PA Semi PWRficient 252 + based boards 253 + 254 + config MTD_NAND_TMIO 255 + tristate "Toshiba Mobile IO NAND controller" 256 + depends on MFD_TMIO 257 + help 258 + Support for NAND flash connected to a Toshiba Mobile IO 259 + Controller in some PDAs, including the Sharp SL6000x. 260 + 261 + config MTD_NAND_BRCMNAND 262 + tristate "Broadcom STB NAND controller" 263 + depends on ARM || ARM64 || MIPS || COMPILE_TEST 264 + depends on HAS_IOMEM 265 + help 266 + Enables the Broadcom NAND controller driver. The controller was 267 + originally designed for Set-Top Box but is used on various BCM7xxx, 268 + BCM3xxx, BCM63xxx, iProc/Cygnus and more. 269 + 270 + config MTD_NAND_BCM47XXNFLASH 271 + tristate "BCM4706 BCMA NAND controller" 272 + depends on BCMA_NFLASH 273 + depends on BCMA 274 + help 275 + BCMA bus can have various flash memories attached, they are 276 + registered by bcma as platform devices. This enables driver for 277 + NAND flash memories. For now only BCM4706 is supported. 278 + 279 + config MTD_NAND_OXNAS 280 + tristate "Oxford Semiconductor NAND controller" 281 + depends on ARCH_OXNAS || COMPILE_TEST 282 + depends on HAS_IOMEM 283 + help 284 + This enables the NAND flash controller on Oxford Semiconductor SoCs. 285 + 286 + config MTD_NAND_MPC5121_NFC 287 + tristate "MPC5121 NAND controller" 288 + depends on PPC_MPC512x 289 + help 290 + This enables the driver for the NAND flash controller on the 291 + MPC5121 SoC. 292 + 293 + config MTD_NAND_GPMI_NAND 294 + tristate "Freescale GPMI NAND controller" 295 + depends on MXS_DMA 296 + help 297 + Enables NAND Flash support for IMX23, IMX28 or IMX6. 298 + The GPMI controller is very powerful, with the help of BCH 299 + module, it can do the hardware ECC. The GPMI supports several 300 + NAND flashs at the same time. 301 + 302 + config MTD_NAND_FSL_ELBC 303 + tristate "Freescale eLBC NAND controller" 304 + depends on FSL_SOC 305 + select FSL_LBC 306 + help 307 + Various Freescale chips, including the 8313, include a NAND Flash 308 + Controller Module with built-in hardware ECC capabilities. 309 + Enabling this option will enable you to use this to control 310 + external NAND devices. 311 + 312 + config MTD_NAND_FSL_IFC 313 + tristate "Freescale IFC NAND controller" 314 + depends on FSL_SOC || ARCH_LAYERSCAPE || SOC_LS1021A || COMPILE_TEST 315 + depends on HAS_IOMEM 316 + select FSL_IFC 317 + select MEMORY 318 + help 319 + Various Freescale chips e.g P1010, include a NAND Flash machine 320 + with built-in hardware ECC capabilities. 321 + Enabling this option will enable you to use this to control 322 + external NAND devices. 323 + 324 + config MTD_NAND_FSL_UPM 325 + tristate "Freescale UPM NAND controller" 326 + depends on PPC_83xx || PPC_85xx 327 + select FSL_LBC 328 + help 329 + Enables support for NAND Flash chips wired onto Freescale PowerPC 330 + processor localbus with User-Programmable Machine support. 331 + 332 + config MTD_NAND_VF610_NFC 333 + tristate "Freescale VF610/MPC5125 NAND controller" 334 + depends on (SOC_VF610 || COMPILE_TEST) 335 + depends on HAS_IOMEM 336 + help 337 + Enables support for NAND Flash Controller on some Freescale 338 + processors like the VF610, MPC5125, MCF54418 or Kinetis K70. 339 + The driver supports a maximum 2k page size. With 2k pages and 340 + 64 bytes or more of OOB, hardware ECC with up to 32-bit error 341 + correction is supported. Hardware ECC is only enabled through 342 + device tree. 343 + 344 + config MTD_NAND_MXC 345 + tristate "Freescale MXC NAND controller" 346 + depends on ARCH_MXC || COMPILE_TEST 347 + depends on HAS_IOMEM 348 + help 349 + This enables the driver for the NAND flash controller on the 350 + MXC processors. 351 + 352 + config MTD_NAND_SH_FLCTL 353 + tristate "Renesas SuperH FLCTL NAND controller" 354 + depends on SUPERH || COMPILE_TEST 355 + depends on HAS_IOMEM 356 + help 357 + Several Renesas SuperH CPU has FLCTL. This option enables support 358 + for NAND Flash using FLCTL. 359 + 360 + config MTD_NAND_DAVINCI 361 + tristate "DaVinci/Keystone NAND controller" 362 + depends on ARCH_DAVINCI || (ARCH_KEYSTONE && TI_AEMIF) || COMPILE_TEST 363 + depends on HAS_IOMEM 364 + help 365 + Enable the driver for NAND flash chips on Texas Instruments 366 + DaVinci/Keystone processors. 367 + 368 + config MTD_NAND_TXX9NDFMC 369 + tristate "TXx9 NAND controller" 370 + depends on SOC_TX4938 || SOC_TX4939 || COMPILE_TEST 371 + depends on HAS_IOMEM 372 + help 373 + This enables the NAND flash controller on the TXx9 SoCs. 374 + 375 + config MTD_NAND_SOCRATES 376 + tristate "Socrates NAND controller" 377 + depends on SOCRATES 378 + help 379 + Enables support for NAND Flash chips wired onto Socrates board. 380 + 381 + config MTD_NAND_NUC900 382 + tristate "Nuvoton NUC9xx/w90p910 NAND controller" 383 + depends on ARCH_W90X900 || COMPILE_TEST 384 + depends on HAS_IOMEM 385 + help 386 + This enables the driver for the NAND Flash on evaluation board based 387 + on w90p910 / NUC9xx. 388 + 389 + source "drivers/mtd/nand/raw/ingenic/Kconfig" 390 + 391 + config MTD_NAND_FSMC 392 + tristate "ST Micros FSMC NAND controller" 393 + depends on OF && HAS_IOMEM 394 + depends on PLAT_SPEAR || ARCH_NOMADIK || ARCH_U8500 || MACH_U300 || \ 395 + COMPILE_TEST 396 + help 397 + Enables support for NAND Flash chips on the ST Microelectronics 398 + Flexible Static Memory Controller (FSMC) 399 + 400 + config MTD_NAND_XWAY 401 + bool "Lantiq XWAY NAND controller" 402 + depends on LANTIQ && SOC_TYPE_XWAY 403 + help 404 + Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached 405 + to the External Bus Unit (EBU). 406 + 407 + config MTD_NAND_SUNXI 408 + tristate "Allwinner NAND controller" 409 + depends on ARCH_SUNXI || COMPILE_TEST 410 + depends on HAS_IOMEM 411 + help 412 + Enables support for NAND Flash chips on Allwinner SoCs. 413 + 414 + config MTD_NAND_HISI504 415 + tristate "Hisilicon Hip04 NAND controller" 416 + depends on ARCH_HISI || COMPILE_TEST 417 + depends on HAS_IOMEM 418 + help 419 + Enables support for NAND controller on Hisilicon SoC Hip04. 420 + 421 + config MTD_NAND_QCOM 422 + tristate "QCOM NAND controller" 423 + depends on ARCH_QCOM || COMPILE_TEST 424 + depends on HAS_IOMEM 425 + help 426 + Enables support for NAND flash chips on SoCs containing the EBI2 NAND 427 + controller. This controller is found on IPQ806x SoC. 428 + 429 + config MTD_NAND_MTK 430 + tristate "MTK NAND controller" 431 + depends on ARCH_MEDIATEK || COMPILE_TEST 432 + depends on HAS_IOMEM 433 + help 434 + Enables support for NAND controller on MTK SoCs. 435 + This controller is found on mt27xx, mt81xx, mt65xx SoCs. 436 + 437 + config MTD_NAND_TEGRA 438 + tristate "NVIDIA Tegra NAND controller" 439 + depends on ARCH_TEGRA || COMPILE_TEST 440 + depends on HAS_IOMEM 441 + help 442 + Enables support for NAND flash controller on NVIDIA Tegra SoC. 443 + The driver has been developed and tested on a Tegra 2 SoC. DMA 444 + support, raw read/write page as well as HW ECC read/write page 445 + is supported. Extra OOB bytes when using HW ECC are currently 446 + not supported. 447 + 448 + config MTD_NAND_STM32_FMC2 449 + tristate "Support for NAND controller on STM32MP SoCs" 450 + depends on MACH_STM32MP157 || COMPILE_TEST 451 + help 452 + Enables support for NAND Flash chips on SoCs containing the FMC2 453 + NAND controller. This controller is found on STM32MP SoCs. 454 + The controller supports a maximum 8k page size and supports 455 + a maximum 8-bit correction error per sector of 512 bytes. 456 + 457 + config MTD_NAND_MESON 458 + tristate "Support for NAND controller on Amlogic's Meson SoCs" 459 + depends on ARCH_MESON || COMPILE_TEST 460 + select MFD_SYSCON 461 + help 462 + Enables support for NAND controller on Amlogic's Meson SoCs. 463 + This controller is found on Meson SoCs. 464 + 465 + config MTD_NAND_GPIO 466 + tristate "GPIO assisted NAND controller" 467 + depends on GPIOLIB || COMPILE_TEST 468 + depends on HAS_IOMEM 469 + help 470 + This enables a NAND flash driver where control signals are 471 + connected to GPIO pins, and commands and data are communicated 472 + via a memory mapped interface. 473 + 474 + config MTD_NAND_PLATFORM 475 + tristate "Generic NAND controller" 476 + depends on HAS_IOMEM 477 + help 478 + This implements a generic NAND driver for on-SOC platform 479 + devices. You will need to provide platform-specific functions 480 + via platform_data. 481 + 482 + comment "Misc" 483 + 484 + config MTD_SM_COMMON 485 + tristate 486 + default n 487 + 488 + config MTD_NAND_NANDSIM 489 + tristate "Support for NAND Flash Simulator" 490 + help 491 + The simulator may simulate various NAND flash chips for the 492 + MTD nand layer. 493 + 494 + config MTD_NAND_RICOH 495 + tristate "Ricoh xD card reader" 496 + default n 497 + depends on PCI 498 + select MTD_SM_COMMON 499 + help 500 + Enable support for Ricoh R5C852 xD card reader 501 + You also need to enable ether 502 + NAND SSFDC (SmartMedia) read only translation layer' or new 503 + expermental, readwrite 504 + 'SmartMedia/xD new translation layer' 131 505 132 506 config MTD_NAND_DISKONCHIP 133 507 tristate "DiskOnChip 2000, Millennium and Millennium Plus (NAND reimplementation)" ··· 545 227 load time (assuming you build diskonchip as a module) with the module 546 228 parameter "inftl_bbt_write=1". 547 229 548 - config MTD_NAND_SHARPSL 549 - tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" 550 - depends on ARCH_PXA || COMPILE_TEST 551 - depends on HAS_IOMEM 552 - 553 - config MTD_NAND_CAFE 554 - tristate "NAND support for OLPC CAFÉ chip" 555 - depends on PCI 556 - select REED_SOLOMON 557 - select REED_SOLOMON_DEC16 558 - help 559 - Use NAND flash attached to the CAFÉ chip designed for the OLPC 560 - laptop. 561 - 562 - config MTD_NAND_CS553X 563 - tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)" 564 - depends on X86_32 565 - depends on !UML && HAS_IOMEM 566 - help 567 - The CS553x companion chips for the AMD Geode processor 568 - include NAND flash controllers with built-in hardware ECC 569 - capabilities; enabling this option will allow you to use 570 - these. The driver will check the MSRs to verify that the 571 - controller is enabled for NAND, and currently requires that 572 - the controller be in MMIO mode. 573 - 574 - If you say "m", the module will be called cs553x_nand. 575 - 576 - config MTD_NAND_ATMEL 577 - tristate "Support for NAND Flash / SmartMedia on AT91" 578 - depends on ARCH_AT91 || COMPILE_TEST 579 - depends on HAS_IOMEM 580 - select GENERIC_ALLOCATOR 581 - select MFD_ATMEL_SMC 582 - help 583 - Enables support for NAND Flash / Smart Media Card interface 584 - on Atmel AT91 processors. 585 - 586 - config MTD_NAND_MARVELL 587 - tristate "NAND controller support on Marvell boards" 588 - depends on PXA3xx || ARCH_MMP || PLAT_ORION || ARCH_MVEBU || \ 589 - COMPILE_TEST 590 - depends on HAS_IOMEM 591 - help 592 - This enables the NAND flash controller driver for Marvell boards, 593 - including: 594 - - PXA3xx processors (NFCv1) 595 - - 32-bit Armada platforms (XP, 37x, 38x, 39x) (NFCv2) 596 - - 64-bit Aramda platforms (7k, 8k) (NFCv2) 597 - 598 - config MTD_NAND_SLC_LPC32XX 599 - tristate "NXP LPC32xx SLC Controller" 600 - depends on ARCH_LPC32XX || COMPILE_TEST 601 - depends on HAS_IOMEM 602 - help 603 - Enables support for NXP's LPC32XX SLC (i.e. for Single Level Cell 604 - chips) NAND controller. This is the default for the PHYTEC 3250 605 - reference board which contains a NAND256R3A2CZA6 chip. 606 - 607 - Please check the actual NAND chip connected and its support 608 - by the SLC NAND controller. 609 - 610 - config MTD_NAND_MLC_LPC32XX 611 - tristate "NXP LPC32xx MLC Controller" 612 - depends on ARCH_LPC32XX || COMPILE_TEST 613 - depends on HAS_IOMEM 614 - help 615 - Uses the LPC32XX MLC (i.e. for Multi Level Cell chips) NAND 616 - controller. This is the default for the WORK92105 controller 617 - board. 618 - 619 - Please check the actual NAND chip connected and its support 620 - by the MLC NAND controller. 621 - 622 - config MTD_NAND_CM_X270 623 - tristate "Support for NAND Flash on CM-X270 modules" 624 - depends on MACH_ARMCORE 625 - 626 - config MTD_NAND_PASEMI 627 - tristate "NAND support for PA Semi PWRficient" 628 - depends on PPC_PASEMI 629 - help 630 - Enables support for NAND Flash interface on PA Semi PWRficient 631 - based boards 632 - 633 - config MTD_NAND_TMIO 634 - tristate "NAND Flash device on Toshiba Mobile IO Controller" 635 - depends on MFD_TMIO 636 - help 637 - Support for NAND flash connected to a Toshiba Mobile IO 638 - Controller in some PDAs, including the Sharp SL6000x. 639 - 640 - config MTD_NAND_NANDSIM 641 - tristate "Support for NAND Flash Simulator" 642 - help 643 - The simulator may simulate various NAND flash chips for the 644 - MTD nand layer. 645 - 646 - config MTD_NAND_GPMI_NAND 647 - tristate "GPMI NAND Flash Controller driver" 648 - depends on MXS_DMA 649 - help 650 - Enables NAND Flash support for IMX23, IMX28 or IMX6. 651 - The GPMI controller is very powerful, with the help of BCH 652 - module, it can do the hardware ECC. The GPMI supports several 653 - NAND flashs at the same time. 654 - 655 - config MTD_NAND_BRCMNAND 656 - tristate "Broadcom STB NAND controller" 657 - depends on ARM || ARM64 || MIPS || COMPILE_TEST 658 - depends on HAS_IOMEM 659 - help 660 - Enables the Broadcom NAND controller driver. The controller was 661 - originally designed for Set-Top Box but is used on various BCM7xxx, 662 - BCM3xxx, BCM63xxx, iProc/Cygnus and more. 663 - 664 - config MTD_NAND_BCM47XXNFLASH 665 - tristate "Support for NAND flash on BCM4706 BCMA bus" 666 - depends on BCMA_NFLASH 667 - depends on BCMA 668 - help 669 - BCMA bus can have various flash memories attached, they are 670 - registered by bcma as platform devices. This enables driver for 671 - NAND flash memories. For now only BCM4706 is supported. 672 - 673 - config MTD_NAND_PLATFORM 674 - tristate "Support for generic platform NAND driver" 675 - depends on HAS_IOMEM 676 - help 677 - This implements a generic NAND driver for on-SOC platform 678 - devices. You will need to provide platform-specific functions 679 - via platform_data. 680 - 681 - config MTD_NAND_ORION 682 - tristate "NAND Flash support for Marvell Orion SoC" 683 - depends on PLAT_ORION 684 - help 685 - This enables the NAND flash controller on Orion machines. 686 - 687 - No board specific support is done by this driver, each board 688 - must advertise a platform_device for the driver to attach. 689 - 690 - config MTD_NAND_OXNAS 691 - tristate "NAND Flash support for Oxford Semiconductor SoC" 692 - depends on ARCH_OXNAS || COMPILE_TEST 693 - depends on HAS_IOMEM 694 - help 695 - This enables the NAND flash controller on Oxford Semiconductor SoCs. 696 - 697 - config MTD_NAND_FSL_ELBC 698 - tristate "NAND support for Freescale eLBC controllers" 699 - depends on FSL_SOC 700 - select FSL_LBC 701 - help 702 - Various Freescale chips, including the 8313, include a NAND Flash 703 - Controller Module with built-in hardware ECC capabilities. 704 - Enabling this option will enable you to use this to control 705 - external NAND devices. 706 - 707 - config MTD_NAND_FSL_IFC 708 - tristate "NAND support for Freescale IFC controller" 709 - depends on FSL_SOC || ARCH_LAYERSCAPE || SOC_LS1021A || COMPILE_TEST 710 - depends on HAS_IOMEM 711 - select FSL_IFC 712 - select MEMORY 713 - help 714 - Various Freescale chips e.g P1010, include a NAND Flash machine 715 - with built-in hardware ECC capabilities. 716 - Enabling this option will enable you to use this to control 717 - external NAND devices. 718 - 719 - config MTD_NAND_FSL_UPM 720 - tristate "Support for NAND on Freescale UPM" 721 - depends on PPC_83xx || PPC_85xx 722 - select FSL_LBC 723 - help 724 - Enables support for NAND Flash chips wired onto Freescale PowerPC 725 - processor localbus with User-Programmable Machine support. 726 - 727 - config MTD_NAND_MPC5121_NFC 728 - tristate "MPC5121 built-in NAND Flash Controller support" 729 - depends on PPC_MPC512x 730 - help 731 - This enables the driver for the NAND flash controller on the 732 - MPC5121 SoC. 733 - 734 - config MTD_NAND_VF610_NFC 735 - tristate "Support for Freescale NFC for VF610/MPC5125" 736 - depends on (SOC_VF610 || COMPILE_TEST) 737 - depends on HAS_IOMEM 738 - help 739 - Enables support for NAND Flash Controller on some Freescale 740 - processors like the VF610, MPC5125, MCF54418 or Kinetis K70. 741 - The driver supports a maximum 2k page size. With 2k pages and 742 - 64 bytes or more of OOB, hardware ECC with up to 32-bit error 743 - correction is supported. Hardware ECC is only enabled through 744 - device tree. 745 - 746 - config MTD_NAND_MXC 747 - tristate "MXC NAND support" 748 - depends on ARCH_MXC || COMPILE_TEST 749 - depends on HAS_IOMEM 750 - help 751 - This enables the driver for the NAND flash controller on the 752 - MXC processors. 753 - 754 - config MTD_NAND_SH_FLCTL 755 - tristate "Support for NAND on Renesas SuperH FLCTL" 756 - depends on SUPERH || COMPILE_TEST 757 - depends on HAS_IOMEM 758 - help 759 - Several Renesas SuperH CPU has FLCTL. This option enables support 760 - for NAND Flash using FLCTL. 761 - 762 - config MTD_NAND_DAVINCI 763 - tristate "Support NAND on DaVinci/Keystone SoC" 764 - depends on ARCH_DAVINCI || (ARCH_KEYSTONE && TI_AEMIF) || COMPILE_TEST 765 - depends on HAS_IOMEM 766 - help 767 - Enable the driver for NAND flash chips on Texas Instruments 768 - DaVinci/Keystone processors. 769 - 770 - config MTD_NAND_TXX9NDFMC 771 - tristate "NAND Flash support for TXx9 SoC" 772 - depends on SOC_TX4938 || SOC_TX4939 || COMPILE_TEST 773 - depends on HAS_IOMEM 774 - help 775 - This enables the NAND flash controller on the TXx9 SoCs. 776 - 777 - config MTD_NAND_SOCRATES 778 - tristate "Support for NAND on Socrates board" 779 - depends on SOCRATES 780 - help 781 - Enables support for NAND Flash chips wired onto Socrates board. 782 - 783 - config MTD_NAND_NUC900 784 - tristate "Support for NAND on Nuvoton NUC9xx/w90p910 evaluation boards." 785 - depends on ARCH_W90X900 || COMPILE_TEST 786 - depends on HAS_IOMEM 787 - help 788 - This enables the driver for the NAND Flash on evaluation board based 789 - on w90p910 / NUC9xx. 790 - 791 - config MTD_NAND_JZ4740 792 - tristate "Support for JZ4740 SoC NAND controller" 793 - depends on MACH_JZ4740 || COMPILE_TEST 794 - depends on HAS_IOMEM 795 - help 796 - Enables support for NAND Flash on JZ4740 SoC based boards. 797 - 798 - config MTD_NAND_JZ4780 799 - tristate "Support for NAND on JZ4780 SoC" 800 - depends on JZ4780_NEMC 801 - help 802 - Enables support for NAND Flash connected to the NEMC on JZ4780 SoC 803 - based boards, using the BCH controller for hardware error correction. 804 - 805 - config MTD_NAND_FSMC 806 - tristate "Support for NAND on ST Micros FSMC" 807 - depends on OF && HAS_IOMEM 808 - depends on PLAT_SPEAR || ARCH_NOMADIK || ARCH_U8500 || MACH_U300 || \ 809 - COMPILE_TEST 810 - help 811 - Enables support for NAND Flash chips on the ST Microelectronics 812 - Flexible Static Memory Controller (FSMC) 813 - 814 - config MTD_NAND_XWAY 815 - bool "Support for NAND on Lantiq XWAY SoC" 816 - depends on LANTIQ && SOC_TYPE_XWAY 817 - help 818 - Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached 819 - to the External Bus Unit (EBU). 820 - 821 - config MTD_NAND_SUNXI 822 - tristate "Support for NAND on Allwinner SoCs" 823 - depends on ARCH_SUNXI || COMPILE_TEST 824 - depends on HAS_IOMEM 825 - help 826 - Enables support for NAND Flash chips on Allwinner SoCs. 827 - 828 - config MTD_NAND_HISI504 829 - tristate "Support for NAND controller on Hisilicon SoC Hip04" 830 - depends on ARCH_HISI || COMPILE_TEST 831 - depends on HAS_IOMEM 832 - help 833 - Enables support for NAND controller on Hisilicon SoC Hip04. 834 - 835 - config MTD_NAND_QCOM 836 - tristate "Support for NAND on QCOM SoCs" 837 - depends on ARCH_QCOM || COMPILE_TEST 838 - depends on HAS_IOMEM 839 - help 840 - Enables support for NAND flash chips on SoCs containing the EBI2 NAND 841 - controller. This controller is found on IPQ806x SoC. 842 - 843 - config MTD_NAND_MTK 844 - tristate "Support for NAND controller on MTK SoCs" 845 - depends on ARCH_MEDIATEK || COMPILE_TEST 846 - depends on HAS_IOMEM 847 - help 848 - Enables support for NAND controller on MTK SoCs. 849 - This controller is found on mt27xx, mt81xx, mt65xx SoCs. 850 - 851 - config MTD_NAND_TEGRA 852 - tristate "Support for NAND controller on NVIDIA Tegra" 853 - depends on ARCH_TEGRA || COMPILE_TEST 854 - depends on HAS_IOMEM 855 - help 856 - Enables support for NAND flash controller on NVIDIA Tegra SoC. 857 - The driver has been developed and tested on a Tegra 2 SoC. DMA 858 - support, raw read/write page as well as HW ECC read/write page 859 - is supported. Extra OOB bytes when using HW ECC are currently 860 - not supported. 861 - 862 - config MTD_NAND_STM32_FMC2 863 - tristate "Support for NAND controller on STM32MP SoCs" 864 - depends on MACH_STM32MP157 || COMPILE_TEST 865 - help 866 - Enables support for NAND Flash chips on SoCs containing the FMC2 867 - NAND controller. This controller is found on STM32MP SoCs. 868 - The controller supports a maximum 8k page size and supports 869 - a maximum 8-bit correction error per sector of 512 bytes. 870 - 871 - config MTD_NAND_MESON 872 - tristate "Support for NAND controller on Amlogic's Meson SoCs" 873 - depends on ARCH_MESON || COMPILE_TEST 874 - select MFD_SYSCON 875 - help 876 - Enables support for NAND controller on Amlogic's Meson SoCs. 877 - This controller is found on Meson SoCs. 878 - 879 - endif # MTD_NAND 230 + endif # MTD_RAW_NAND
+4 -5
drivers/mtd/nand/raw/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - obj-$(CONFIG_MTD_NAND) += nand.o 4 - obj-$(CONFIG_MTD_NAND_ECC) += nand_ecc.o 5 - obj-$(CONFIG_MTD_NAND_BCH) += nand_bch.o 3 + obj-$(CONFIG_MTD_RAW_NAND) += nand.o 4 + obj-$(CONFIG_MTD_NAND_ECC_SW_HAMMING) += nand_ecc.o 5 + nand-$(CONFIG_MTD_NAND_ECC_SW_BCH) += nand_bch.o 6 6 obj-$(CONFIG_MTD_SM_COMMON) += sm_common.o 7 7 8 8 obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o ··· 45 45 obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mpc5121_nfc.o 46 46 obj-$(CONFIG_MTD_NAND_VF610_NFC) += vf610_nfc.o 47 47 obj-$(CONFIG_MTD_NAND_RICOH) += r852.o 48 - obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o 49 - obj-$(CONFIG_MTD_NAND_JZ4780) += jz4780_nand.o jz4780_bch.o 48 + obj-y += ingenic/ 50 49 obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/ 51 50 obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o 52 51 obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/
+96 -31
drivers/mtd/nand/raw/atmel/nand-controller.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Copyright 2017 ATMEL 3 4 * Copyright 2017 Free Electrons ··· 29 28 * 30 29 * Add Nand Flash Controller support for SAMA5 SoC 31 30 * Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com) 32 - * 33 - * This program is free software; you can redistribute it and/or modify 34 - * it under the terms of the GNU General Public License version 2 as 35 - * published by the Free Software Foundation. 36 31 * 37 32 * A few words about the naming convention in this file. This convention 38 33 * applies to structure and function names. ··· 62 65 #include <linux/iopoll.h> 63 66 #include <linux/platform_device.h> 64 67 #include <linux/regmap.h> 68 + #include <soc/at91/atmel-sfr.h> 65 69 66 70 #include "pmecc.h" 67 71 ··· 209 211 bool legacy_of_bindings; 210 212 u32 ale_offs; 211 213 u32 cle_offs; 214 + const char *ebi_csa_regmap_name; 212 215 const struct atmel_nand_controller_ops *ops; 213 216 }; 214 217 ··· 230 231 return container_of(ctl, struct atmel_nand_controller, base); 231 232 } 232 233 234 + struct atmel_smc_nand_ebi_csa_cfg { 235 + u32 offs; 236 + u32 nfd0_on_d16; 237 + }; 238 + 233 239 struct atmel_smc_nand_controller { 234 240 struct atmel_nand_controller base; 235 - struct regmap *matrix; 236 - unsigned int ebi_csa_offs; 241 + struct regmap *ebi_csa_regmap; 242 + struct atmel_smc_nand_ebi_csa_cfg *ebi_csa; 237 243 }; 238 244 239 245 static inline struct atmel_smc_nand_controller * ··· 1072 1068 req.ecc.strength = ATMEL_PMECC_MAXIMIZE_ECC_STRENGTH; 1073 1069 else if (chip->ecc.strength) 1074 1070 req.ecc.strength = chip->ecc.strength; 1075 - else if (chip->ecc_strength_ds) 1076 - req.ecc.strength = chip->ecc_strength_ds; 1071 + else if (chip->base.eccreq.strength) 1072 + req.ecc.strength = chip->base.eccreq.strength; 1077 1073 else 1078 1074 req.ecc.strength = ATMEL_PMECC_MAXIMIZE_ECC_STRENGTH; 1079 1075 1080 1076 if (chip->ecc.size) 1081 1077 req.ecc.sectorsize = chip->ecc.size; 1082 - else if (chip->ecc_step_ds) 1083 - req.ecc.sectorsize = chip->ecc_step_ds; 1078 + else if (chip->base.eccreq.step_size) 1079 + req.ecc.sectorsize = chip->base.eccreq.step_size; 1084 1080 else 1085 1081 req.ecc.sectorsize = ATMEL_PMECC_SECTOR_SIZE_AUTO; 1086 1082 ··· 1511 1507 atmel_nand_init(nc, nand); 1512 1508 1513 1509 smc_nc = to_smc_nand_controller(chip->controller); 1514 - if (!smc_nc->matrix) 1510 + if (!smc_nc->ebi_csa_regmap) 1515 1511 return; 1516 1512 1517 1513 /* Attach the CS to the NAND Flash logic. */ 1518 1514 for (i = 0; i < nand->numcs; i++) 1519 - regmap_update_bits(smc_nc->matrix, smc_nc->ebi_csa_offs, 1515 + regmap_update_bits(smc_nc->ebi_csa_regmap, 1516 + smc_nc->ebi_csa->offs, 1520 1517 BIT(nand->cs[i].id), BIT(nand->cs[i].id)); 1518 + 1519 + if (smc_nc->ebi_csa->nfd0_on_d16) 1520 + regmap_update_bits(smc_nc->ebi_csa_regmap, 1521 + smc_nc->ebi_csa->offs, 1522 + smc_nc->ebi_csa->nfd0_on_d16, 1523 + smc_nc->ebi_csa->nfd0_on_d16); 1521 1524 } 1522 1525 1523 1526 static void atmel_hsmc_nand_init(struct atmel_nand_controller *nc, ··· 1808 1797 1809 1798 ret = of_property_read_u32(np, "#size-cells", &val); 1810 1799 if (ret) { 1811 - dev_err(dev, "missing #address-cells property\n"); 1800 + dev_err(dev, "missing #size-cells property\n"); 1812 1801 return ret; 1813 1802 } 1814 1803 ··· 1844 1833 clk_put(nc->mck); 1845 1834 } 1846 1835 1847 - static const struct of_device_id atmel_matrix_of_ids[] = { 1836 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9260_ebi_csa = { 1837 + .offs = AT91SAM9260_MATRIX_EBICSA, 1838 + }; 1839 + 1840 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9261_ebi_csa = { 1841 + .offs = AT91SAM9261_MATRIX_EBICSA, 1842 + }; 1843 + 1844 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9263_ebi_csa = { 1845 + .offs = AT91SAM9263_MATRIX_EBI0CSA, 1846 + }; 1847 + 1848 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9rl_ebi_csa = { 1849 + .offs = AT91SAM9RL_MATRIX_EBICSA, 1850 + }; 1851 + 1852 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9g45_ebi_csa = { 1853 + .offs = AT91SAM9G45_MATRIX_EBICSA, 1854 + }; 1855 + 1856 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9n12_ebi_csa = { 1857 + .offs = AT91SAM9N12_MATRIX_EBICSA, 1858 + }; 1859 + 1860 + static const struct atmel_smc_nand_ebi_csa_cfg at91sam9x5_ebi_csa = { 1861 + .offs = AT91SAM9X5_MATRIX_EBICSA, 1862 + }; 1863 + 1864 + static const struct atmel_smc_nand_ebi_csa_cfg sam9x60_ebi_csa = { 1865 + .offs = AT91_SFR_CCFG_EBICSA, 1866 + .nfd0_on_d16 = AT91_SFR_CCFG_NFD0_ON_D16, 1867 + }; 1868 + 1869 + static const struct of_device_id atmel_ebi_csa_regmap_of_ids[] = { 1848 1870 { 1849 1871 .compatible = "atmel,at91sam9260-matrix", 1850 - .data = (void *)AT91SAM9260_MATRIX_EBICSA, 1872 + .data = &at91sam9260_ebi_csa, 1851 1873 }, 1852 1874 { 1853 1875 .compatible = "atmel,at91sam9261-matrix", 1854 - .data = (void *)AT91SAM9261_MATRIX_EBICSA, 1876 + .data = &at91sam9261_ebi_csa, 1855 1877 }, 1856 1878 { 1857 1879 .compatible = "atmel,at91sam9263-matrix", 1858 - .data = (void *)AT91SAM9263_MATRIX_EBI0CSA, 1880 + .data = &at91sam9263_ebi_csa, 1859 1881 }, 1860 1882 { 1861 1883 .compatible = "atmel,at91sam9rl-matrix", 1862 - .data = (void *)AT91SAM9RL_MATRIX_EBICSA, 1884 + .data = &at91sam9rl_ebi_csa, 1863 1885 }, 1864 1886 { 1865 1887 .compatible = "atmel,at91sam9g45-matrix", 1866 - .data = (void *)AT91SAM9G45_MATRIX_EBICSA, 1888 + .data = &at91sam9g45_ebi_csa, 1867 1889 }, 1868 1890 { 1869 1891 .compatible = "atmel,at91sam9n12-matrix", 1870 - .data = (void *)AT91SAM9N12_MATRIX_EBICSA, 1892 + .data = &at91sam9n12_ebi_csa, 1871 1893 }, 1872 1894 { 1873 1895 .compatible = "atmel,at91sam9x5-matrix", 1874 - .data = (void *)AT91SAM9X5_MATRIX_EBICSA, 1896 + .data = &at91sam9x5_ebi_csa, 1897 + }, 1898 + { 1899 + .compatible = "microchip,sam9x60-sfr", 1900 + .data = &sam9x60_ebi_csa, 1875 1901 }, 1876 1902 { /* sentinel */ }, 1877 1903 }; ··· 2030 1982 struct device_node *np; 2031 1983 int ret; 2032 1984 2033 - /* We do not retrieve the matrix syscon when parsing old DTs. */ 1985 + /* We do not retrieve the EBICSA regmap when parsing old DTs. */ 2034 1986 if (nc->base.caps->legacy_of_bindings) 2035 1987 return 0; 2036 1988 2037 - np = of_parse_phandle(dev->parent->of_node, "atmel,matrix", 0); 1989 + np = of_parse_phandle(dev->parent->of_node, 1990 + nc->base.caps->ebi_csa_regmap_name, 0); 2038 1991 if (!np) 2039 1992 return 0; 2040 1993 2041 - match = of_match_node(atmel_matrix_of_ids, np); 1994 + match = of_match_node(atmel_ebi_csa_regmap_of_ids, np); 2042 1995 if (!match) { 2043 1996 of_node_put(np); 2044 1997 return 0; 2045 1998 } 2046 1999 2047 - nc->matrix = syscon_node_to_regmap(np); 2000 + nc->ebi_csa_regmap = syscon_node_to_regmap(np); 2048 2001 of_node_put(np); 2049 - if (IS_ERR(nc->matrix)) { 2050 - ret = PTR_ERR(nc->matrix); 2051 - dev_err(dev, "Could not get Matrix regmap (err = %d)\n", ret); 2002 + if (IS_ERR(nc->ebi_csa_regmap)) { 2003 + ret = PTR_ERR(nc->ebi_csa_regmap); 2004 + dev_err(dev, "Could not get EBICSA regmap (err = %d)\n", ret); 2052 2005 return ret; 2053 2006 } 2054 2007 2055 - nc->ebi_csa_offs = (uintptr_t)match->data; 2008 + nc->ebi_csa = (struct atmel_smc_nand_ebi_csa_cfg *)match->data; 2056 2009 2057 2010 /* 2058 2011 * The at91sam9263 has 2 EBIs, if the NAND controller is under EBI1 2059 - * add 4 to ->ebi_csa_offs. 2012 + * add 4 to ->ebi_csa->offs. 2060 2013 */ 2061 2014 if (of_device_is_compatible(dev->parent->of_node, 2062 2015 "atmel,at91sam9263-ebi1")) 2063 - nc->ebi_csa_offs += 4; 2016 + nc->ebi_csa->offs += 4; 2064 2017 2065 2018 return 0; 2066 2019 } ··· 2390 2341 static const struct atmel_nand_controller_caps atmel_rm9200_nc_caps = { 2391 2342 .ale_offs = BIT(21), 2392 2343 .cle_offs = BIT(22), 2344 + .ebi_csa_regmap_name = "atmel,matrix", 2393 2345 .ops = &at91rm9200_nc_ops, 2394 2346 }; 2395 2347 ··· 2405 2355 static const struct atmel_nand_controller_caps atmel_sam9260_nc_caps = { 2406 2356 .ale_offs = BIT(21), 2407 2357 .cle_offs = BIT(22), 2358 + .ebi_csa_regmap_name = "atmel,matrix", 2408 2359 .ops = &atmel_smc_nc_ops, 2409 2360 }; 2410 2361 2411 2362 static const struct atmel_nand_controller_caps atmel_sam9261_nc_caps = { 2412 2363 .ale_offs = BIT(22), 2413 2364 .cle_offs = BIT(21), 2365 + .ebi_csa_regmap_name = "atmel,matrix", 2414 2366 .ops = &atmel_smc_nc_ops, 2415 2367 }; 2416 2368 ··· 2420 2368 .has_dma = true, 2421 2369 .ale_offs = BIT(21), 2422 2370 .cle_offs = BIT(22), 2371 + .ebi_csa_regmap_name = "atmel,matrix", 2372 + .ops = &atmel_smc_nc_ops, 2373 + }; 2374 + 2375 + static const struct atmel_nand_controller_caps microchip_sam9x60_nc_caps = { 2376 + .has_dma = true, 2377 + .ale_offs = BIT(21), 2378 + .cle_offs = BIT(22), 2379 + .ebi_csa_regmap_name = "microchip,sfr", 2423 2380 .ops = &atmel_smc_nc_ops, 2424 2381 }; 2425 2382 ··· 2475 2414 { 2476 2415 .compatible = "atmel,sama5d3-nand-controller", 2477 2416 .data = &atmel_sama5_nc_caps, 2417 + }, 2418 + { 2419 + .compatible = "microchip,sam9x60-nand-controller", 2420 + .data = &microchip_sam9x60_nc_caps, 2478 2421 }, 2479 2422 /* Support for old/deprecated bindings: */ 2480 2423 {
+1 -4
drivers/mtd/nand/raw/atmel/pmecc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 3 * Copyright 2017 ATMEL 3 4 * Copyright 2017 Free Electrons ··· 28 27 * 29 28 * Add Nand Flash Controller support for SAMA5 SoC 30 29 * Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com) 31 - * 32 - * This program is free software; you can redistribute it and/or modify 33 - * it under the terms of the GNU General Public License version 2 as 34 - * published by the Free Software Foundation. 35 30 * 36 31 * The PMECC is an hardware assisted BCH engine, which means part of the 37 32 * ECC algorithm is left to the software. The hardware/software repartition
+1 -5
drivers/mtd/nand/raw/atmel/pmecc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 2 3 * © Copyright 2016 ATMEL 3 4 * © Copyright 2016 Free Electrons ··· 29 28 * 30 29 * Add Nand Flash Controller support for SAMA5 SoC 31 30 * © Copyright 2013 ATMEL, Josh Wu (josh.wu@atmel.com) 32 - * 33 - * This program is free software; you can redistribute it and/or modify 34 - * it under the terms of the GNU General Public License version 2 as 35 - * published by the Free Software Foundation. 36 - * 37 31 */ 38 32 39 33 #ifndef ATMEL_PMECC_H
+1 -1
drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c
··· 428 428 } 429 429 430 430 /* Configure FLASH */ 431 - chipsize = b47n->nand_chip.chipsize >> 20; 431 + chipsize = nanddev_target_size(&b47n->nand_chip.base) >> 20; 432 432 tbits = ffs(chipsize); /* find first bit set */ 433 433 if (!tbits || tbits != fls(chipsize)) { 434 434 pr_err("Invalid flash size: 0x%lX\n", chipsize);
+2 -5
drivers/mtd/nand/raw/brcmnand/brcmnand.c
··· 1676 1676 int page = addr >> chip->page_shift; 1677 1677 int ret; 1678 1678 1679 - if (!buf) { 1680 - buf = chip->data_buf; 1681 - /* Invalidate page cache */ 1682 - chip->pagebuf = -1; 1683 - } 1679 + if (!buf) 1680 + buf = nand_get_data_buf(chip); 1684 1681 1685 1682 sas = mtd->oobsize / chip->ecc.steps; 1686 1683
+618 -604
drivers/mtd/nand/raw/denali.c
··· 3 3 * NAND Flash Controller Device Driver 4 4 * Copyright © 2009-2010, Intel Corporation and its suppliers. 5 5 * 6 - * Copyright (c) 2017 Socionext Inc. 6 + * Copyright (c) 2017-2019 Socionext Inc. 7 7 * Reworked by Masahiro Yamada <yamada.masahiro@socionext.com> 8 8 */ 9 9 ··· 40 40 #define DENALI_BANK(denali) ((denali)->active_bank << 24) 41 41 42 42 #define DENALI_INVALID_BANK -1 43 - #define DENALI_NR_BANKS 4 44 43 45 - static inline struct denali_nand_info *mtd_to_denali(struct mtd_info *mtd) 44 + static struct denali_chip *to_denali_chip(struct nand_chip *chip) 46 45 { 47 - return container_of(mtd_to_nand(mtd), struct denali_nand_info, nand); 46 + return container_of(chip, struct denali_chip, chip); 47 + } 48 + 49 + static struct denali_controller *to_denali_controller(struct nand_chip *chip) 50 + { 51 + return container_of(chip->controller, struct denali_controller, 52 + controller); 48 53 } 49 54 50 55 /* ··· 57 52 * type, bank, block, and page address). The slave data is the actual data to 58 53 * be transferred. This mode requires 28 bits of address region allocated. 59 54 */ 60 - static u32 denali_direct_read(struct denali_nand_info *denali, u32 addr) 55 + static u32 denali_direct_read(struct denali_controller *denali, u32 addr) 61 56 { 62 57 return ioread32(denali->host + addr); 63 58 } 64 59 65 - static void denali_direct_write(struct denali_nand_info *denali, u32 addr, 60 + static void denali_direct_write(struct denali_controller *denali, u32 addr, 66 61 u32 data) 67 62 { 68 63 iowrite32(data, denali->host + addr); ··· 74 69 * control information and transferred data are latched by the registers in 75 70 * the translation module. 76 71 */ 77 - static u32 denali_indexed_read(struct denali_nand_info *denali, u32 addr) 72 + static u32 denali_indexed_read(struct denali_controller *denali, u32 addr) 78 73 { 79 74 iowrite32(addr, denali->host + DENALI_INDEXED_CTRL); 80 75 return ioread32(denali->host + DENALI_INDEXED_DATA); 81 76 } 82 77 83 - static void denali_indexed_write(struct denali_nand_info *denali, u32 addr, 78 + static void denali_indexed_write(struct denali_controller *denali, u32 addr, 84 79 u32 data) 85 80 { 86 81 iowrite32(addr, denali->host + DENALI_INDEXED_CTRL); 87 82 iowrite32(data, denali->host + DENALI_INDEXED_DATA); 88 83 } 89 84 90 - /* 91 - * Use the configuration feature register to determine the maximum number of 92 - * banks that the hardware supports. 93 - */ 94 - static void denali_detect_max_banks(struct denali_nand_info *denali) 95 - { 96 - uint32_t features = ioread32(denali->reg + FEATURES); 97 - 98 - denali->max_banks = 1 << FIELD_GET(FEATURES__N_BANKS, features); 99 - 100 - /* the encoding changed from rev 5.0 to 5.1 */ 101 - if (denali->revision < 0x0501) 102 - denali->max_banks <<= 1; 103 - } 104 - 105 - static void denali_enable_irq(struct denali_nand_info *denali) 85 + static void denali_enable_irq(struct denali_controller *denali) 106 86 { 107 87 int i; 108 88 109 - for (i = 0; i < DENALI_NR_BANKS; i++) 89 + for (i = 0; i < denali->nbanks; i++) 110 90 iowrite32(U32_MAX, denali->reg + INTR_EN(i)); 111 91 iowrite32(GLOBAL_INT_EN_FLAG, denali->reg + GLOBAL_INT_ENABLE); 112 92 } 113 93 114 - static void denali_disable_irq(struct denali_nand_info *denali) 94 + static void denali_disable_irq(struct denali_controller *denali) 115 95 { 116 96 int i; 117 97 118 - for (i = 0; i < DENALI_NR_BANKS; i++) 98 + for (i = 0; i < denali->nbanks; i++) 119 99 iowrite32(0, denali->reg + INTR_EN(i)); 120 100 iowrite32(0, denali->reg + GLOBAL_INT_ENABLE); 121 101 } 122 102 123 - static void denali_clear_irq(struct denali_nand_info *denali, 124 - int bank, uint32_t irq_status) 103 + static void denali_clear_irq(struct denali_controller *denali, 104 + int bank, u32 irq_status) 125 105 { 126 106 /* write one to clear bits */ 127 107 iowrite32(irq_status, denali->reg + INTR_STATUS(bank)); 128 108 } 129 109 130 - static void denali_clear_irq_all(struct denali_nand_info *denali) 110 + static void denali_clear_irq_all(struct denali_controller *denali) 131 111 { 132 112 int i; 133 113 134 - for (i = 0; i < DENALI_NR_BANKS; i++) 114 + for (i = 0; i < denali->nbanks; i++) 135 115 denali_clear_irq(denali, i, U32_MAX); 136 116 } 137 117 138 118 static irqreturn_t denali_isr(int irq, void *dev_id) 139 119 { 140 - struct denali_nand_info *denali = dev_id; 120 + struct denali_controller *denali = dev_id; 141 121 irqreturn_t ret = IRQ_NONE; 142 - uint32_t irq_status; 122 + u32 irq_status; 143 123 int i; 144 124 145 125 spin_lock(&denali->irq_lock); 146 126 147 - for (i = 0; i < DENALI_NR_BANKS; i++) { 127 + for (i = 0; i < denali->nbanks; i++) { 148 128 irq_status = ioread32(denali->reg + INTR_STATUS(i)); 149 129 if (irq_status) 150 130 ret = IRQ_HANDLED; ··· 150 160 return ret; 151 161 } 152 162 153 - static void denali_reset_irq(struct denali_nand_info *denali) 163 + static void denali_reset_irq(struct denali_controller *denali) 154 164 { 155 165 unsigned long flags; 156 166 ··· 160 170 spin_unlock_irqrestore(&denali->irq_lock, flags); 161 171 } 162 172 163 - static uint32_t denali_wait_for_irq(struct denali_nand_info *denali, 164 - uint32_t irq_mask) 173 + static u32 denali_wait_for_irq(struct denali_controller *denali, u32 irq_mask) 165 174 { 166 175 unsigned long time_left, flags; 167 - uint32_t irq_status; 176 + u32 irq_status; 168 177 169 178 spin_lock_irqsave(&denali->irq_lock, flags); 170 179 ··· 190 201 return denali->irq_status; 191 202 } 192 203 193 - static void denali_read_buf(struct nand_chip *chip, uint8_t *buf, int len) 204 + static void denali_select_target(struct nand_chip *chip, int cs) 194 205 { 206 + struct denali_controller *denali = to_denali_controller(chip); 207 + struct denali_chip_sel *sel = &to_denali_chip(chip)->sels[cs]; 195 208 struct mtd_info *mtd = nand_to_mtd(chip); 196 - struct denali_nand_info *denali = mtd_to_denali(mtd); 197 - u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali); 198 - int i; 199 209 200 - for (i = 0; i < len; i++) 201 - buf[i] = denali->host_read(denali, addr); 202 - } 210 + denali->active_bank = sel->bank; 203 211 204 - static void denali_write_buf(struct nand_chip *chip, const uint8_t *buf, 205 - int len) 206 - { 207 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 208 - u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali); 209 - int i; 212 + iowrite32(1 << (chip->phys_erase_shift - chip->page_shift), 213 + denali->reg + PAGES_PER_BLOCK); 214 + iowrite32(chip->options & NAND_BUSWIDTH_16 ? 1 : 0, 215 + denali->reg + DEVICE_WIDTH); 216 + iowrite32(mtd->writesize, denali->reg + DEVICE_MAIN_AREA_SIZE); 217 + iowrite32(mtd->oobsize, denali->reg + DEVICE_SPARE_AREA_SIZE); 218 + iowrite32(chip->options & NAND_ROW_ADDR_3 ? 219 + 0 : TWO_ROW_ADDR_CYCLES__FLAG, 220 + denali->reg + TWO_ROW_ADDR_CYCLES); 221 + iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) | 222 + FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength), 223 + denali->reg + ECC_CORRECTION); 224 + iowrite32(chip->ecc.size, denali->reg + CFG_DATA_BLOCK_SIZE); 225 + iowrite32(chip->ecc.size, denali->reg + CFG_LAST_DATA_BLOCK_SIZE); 226 + iowrite32(chip->ecc.steps, denali->reg + CFG_NUM_DATA_BLOCKS); 210 227 211 - for (i = 0; i < len; i++) 212 - denali->host_write(denali, addr, buf[i]); 213 - } 214 - 215 - static void denali_read_buf16(struct nand_chip *chip, uint8_t *buf, int len) 216 - { 217 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 218 - u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali); 219 - uint16_t *buf16 = (uint16_t *)buf; 220 - int i; 221 - 222 - for (i = 0; i < len / 2; i++) 223 - buf16[i] = denali->host_read(denali, addr); 224 - } 225 - 226 - static void denali_write_buf16(struct nand_chip *chip, const uint8_t *buf, 227 - int len) 228 - { 229 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 230 - u32 addr = DENALI_MAP11_DATA | DENALI_BANK(denali); 231 - const uint16_t *buf16 = (const uint16_t *)buf; 232 - int i; 233 - 234 - for (i = 0; i < len / 2; i++) 235 - denali->host_write(denali, addr, buf16[i]); 236 - } 237 - 238 - static uint8_t denali_read_byte(struct nand_chip *chip) 239 - { 240 - uint8_t byte; 241 - 242 - denali_read_buf(chip, &byte, 1); 243 - 244 - return byte; 245 - } 246 - 247 - static void denali_write_byte(struct nand_chip *chip, uint8_t byte) 248 - { 249 - denali_write_buf(chip, &byte, 1); 250 - } 251 - 252 - static void denali_cmd_ctrl(struct nand_chip *chip, int dat, unsigned int ctrl) 253 - { 254 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 255 - uint32_t type; 256 - 257 - if (ctrl & NAND_CLE) 258 - type = DENALI_MAP11_CMD; 259 - else if (ctrl & NAND_ALE) 260 - type = DENALI_MAP11_ADDR; 261 - else 228 + if (chip->options & NAND_KEEP_TIMINGS) 262 229 return; 263 230 264 - /* 265 - * Some commands are followed by chip->legacy.waitfunc. 266 - * irq_status must be cleared here to catch the R/B# interrupt later. 267 - */ 268 - if (ctrl & NAND_CTRL_CHANGE) 269 - denali_reset_irq(denali); 270 - 271 - denali->host_write(denali, DENALI_BANK(denali) | type, dat); 231 + /* update timing registers unless NAND_KEEP_TIMINGS is set */ 232 + iowrite32(sel->hwhr2_and_we_2_re, denali->reg + TWHR2_AND_WE_2_RE); 233 + iowrite32(sel->tcwaw_and_addr_2_data, 234 + denali->reg + TCWAW_AND_ADDR_2_DATA); 235 + iowrite32(sel->re_2_we, denali->reg + RE_2_WE); 236 + iowrite32(sel->acc_clks, denali->reg + ACC_CLKS); 237 + iowrite32(sel->rdwr_en_lo_cnt, denali->reg + RDWR_EN_LO_CNT); 238 + iowrite32(sel->rdwr_en_hi_cnt, denali->reg + RDWR_EN_HI_CNT); 239 + iowrite32(sel->cs_setup_cnt, denali->reg + CS_SETUP_CNT); 240 + iowrite32(sel->re_2_re, denali->reg + RE_2_RE); 272 241 } 273 242 274 - static int denali_check_erased_page(struct mtd_info *mtd, 275 - struct nand_chip *chip, uint8_t *buf, 243 + static int denali_change_column(struct nand_chip *chip, unsigned int offset, 244 + void *buf, unsigned int len, bool write) 245 + { 246 + if (write) 247 + return nand_change_write_column_op(chip, offset, buf, len, 248 + false); 249 + else 250 + return nand_change_read_column_op(chip, offset, buf, len, 251 + false); 252 + } 253 + 254 + static int denali_payload_xfer(struct nand_chip *chip, void *buf, bool write) 255 + { 256 + struct denali_controller *denali = to_denali_controller(chip); 257 + struct mtd_info *mtd = nand_to_mtd(chip); 258 + struct nand_ecc_ctrl *ecc = &chip->ecc; 259 + int writesize = mtd->writesize; 260 + int oob_skip = denali->oob_skip_bytes; 261 + int ret, i, pos, len; 262 + 263 + for (i = 0; i < ecc->steps; i++) { 264 + pos = i * (ecc->size + ecc->bytes); 265 + len = ecc->size; 266 + 267 + if (pos >= writesize) { 268 + pos += oob_skip; 269 + } else if (pos + len > writesize) { 270 + /* This chunk overwraps the BBM area. Must be split */ 271 + ret = denali_change_column(chip, pos, buf, 272 + writesize - pos, write); 273 + if (ret) 274 + return ret; 275 + 276 + buf += writesize - pos; 277 + len -= writesize - pos; 278 + pos = writesize + oob_skip; 279 + } 280 + 281 + ret = denali_change_column(chip, pos, buf, len, write); 282 + if (ret) 283 + return ret; 284 + 285 + buf += len; 286 + } 287 + 288 + return 0; 289 + } 290 + 291 + static int denali_oob_xfer(struct nand_chip *chip, void *buf, bool write) 292 + { 293 + struct denali_controller *denali = to_denali_controller(chip); 294 + struct mtd_info *mtd = nand_to_mtd(chip); 295 + struct nand_ecc_ctrl *ecc = &chip->ecc; 296 + int writesize = mtd->writesize; 297 + int oobsize = mtd->oobsize; 298 + int oob_skip = denali->oob_skip_bytes; 299 + int ret, i, pos, len; 300 + 301 + /* BBM at the beginning of the OOB area */ 302 + ret = denali_change_column(chip, writesize, buf, oob_skip, write); 303 + if (ret) 304 + return ret; 305 + 306 + buf += oob_skip; 307 + 308 + for (i = 0; i < ecc->steps; i++) { 309 + pos = ecc->size + i * (ecc->size + ecc->bytes); 310 + 311 + if (i == ecc->steps - 1) 312 + /* The last chunk includes OOB free */ 313 + len = writesize + oobsize - pos - oob_skip; 314 + else 315 + len = ecc->bytes; 316 + 317 + if (pos >= writesize) { 318 + pos += oob_skip; 319 + } else if (pos + len > writesize) { 320 + /* This chunk overwraps the BBM area. Must be split */ 321 + ret = denali_change_column(chip, pos, buf, 322 + writesize - pos, write); 323 + if (ret) 324 + return ret; 325 + 326 + buf += writesize - pos; 327 + len -= writesize - pos; 328 + pos = writesize + oob_skip; 329 + } 330 + 331 + ret = denali_change_column(chip, pos, buf, len, write); 332 + if (ret) 333 + return ret; 334 + 335 + buf += len; 336 + } 337 + 338 + return 0; 339 + } 340 + 341 + static int denali_read_raw(struct nand_chip *chip, void *buf, void *oob_buf, 342 + int page) 343 + { 344 + int ret; 345 + 346 + if (!buf && !oob_buf) 347 + return -EINVAL; 348 + 349 + ret = nand_read_page_op(chip, page, 0, NULL, 0); 350 + if (ret) 351 + return ret; 352 + 353 + if (buf) { 354 + ret = denali_payload_xfer(chip, buf, false); 355 + if (ret) 356 + return ret; 357 + } 358 + 359 + if (oob_buf) { 360 + ret = denali_oob_xfer(chip, oob_buf, false); 361 + if (ret) 362 + return ret; 363 + } 364 + 365 + return 0; 366 + } 367 + 368 + static int denali_write_raw(struct nand_chip *chip, const void *buf, 369 + const void *oob_buf, int page) 370 + { 371 + int ret; 372 + 373 + if (!buf && !oob_buf) 374 + return -EINVAL; 375 + 376 + ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0); 377 + if (ret) 378 + return ret; 379 + 380 + if (buf) { 381 + ret = denali_payload_xfer(chip, (void *)buf, true); 382 + if (ret) 383 + return ret; 384 + } 385 + 386 + if (oob_buf) { 387 + ret = denali_oob_xfer(chip, (void *)oob_buf, true); 388 + if (ret) 389 + return ret; 390 + } 391 + 392 + return nand_prog_page_end_op(chip); 393 + } 394 + 395 + static int denali_read_page_raw(struct nand_chip *chip, u8 *buf, 396 + int oob_required, int page) 397 + { 398 + return denali_read_raw(chip, buf, oob_required ? chip->oob_poi : NULL, 399 + page); 400 + } 401 + 402 + static int denali_write_page_raw(struct nand_chip *chip, const u8 *buf, 403 + int oob_required, int page) 404 + { 405 + return denali_write_raw(chip, buf, oob_required ? chip->oob_poi : NULL, 406 + page); 407 + } 408 + 409 + static int denali_read_oob(struct nand_chip *chip, int page) 410 + { 411 + return denali_read_raw(chip, NULL, chip->oob_poi, page); 412 + } 413 + 414 + static int denali_write_oob(struct nand_chip *chip, int page) 415 + { 416 + return denali_write_raw(chip, NULL, chip->oob_poi, page); 417 + } 418 + 419 + static int denali_check_erased_page(struct nand_chip *chip, u8 *buf, 276 420 unsigned long uncor_ecc_flags, 277 421 unsigned int max_bitflips) 278 422 { 279 - struct denali_nand_info *denali = mtd_to_denali(mtd); 280 - uint8_t *ecc_code = chip->oob_poi + denali->oob_skip_bytes; 281 - int ecc_steps = chip->ecc.steps; 282 - int ecc_size = chip->ecc.size; 283 - int ecc_bytes = chip->ecc.bytes; 423 + struct denali_controller *denali = to_denali_controller(chip); 424 + struct mtd_ecc_stats *ecc_stats = &nand_to_mtd(chip)->ecc_stats; 425 + struct nand_ecc_ctrl *ecc = &chip->ecc; 426 + u8 *ecc_code = chip->oob_poi + denali->oob_skip_bytes; 284 427 int i, stat; 285 428 286 - for (i = 0; i < ecc_steps; i++) { 429 + for (i = 0; i < ecc->steps; i++) { 287 430 if (!(uncor_ecc_flags & BIT(i))) 288 431 continue; 289 432 290 - stat = nand_check_erased_ecc_chunk(buf, ecc_size, 291 - ecc_code, ecc_bytes, 292 - NULL, 0, 293 - chip->ecc.strength); 433 + stat = nand_check_erased_ecc_chunk(buf, ecc->size, ecc_code, 434 + ecc->bytes, NULL, 0, 435 + ecc->strength); 294 436 if (stat < 0) { 295 - mtd->ecc_stats.failed++; 437 + ecc_stats->failed++; 296 438 } else { 297 - mtd->ecc_stats.corrected += stat; 439 + ecc_stats->corrected += stat; 298 440 max_bitflips = max_t(unsigned int, max_bitflips, stat); 299 441 } 300 442 301 - buf += ecc_size; 302 - ecc_code += ecc_bytes; 443 + buf += ecc->size; 444 + ecc_code += ecc->bytes; 303 445 } 304 446 305 447 return max_bitflips; 306 448 } 307 449 308 - static int denali_hw_ecc_fixup(struct mtd_info *mtd, 309 - struct denali_nand_info *denali, 450 + static int denali_hw_ecc_fixup(struct nand_chip *chip, 310 451 unsigned long *uncor_ecc_flags) 311 452 { 312 - struct nand_chip *chip = mtd_to_nand(mtd); 453 + struct denali_controller *denali = to_denali_controller(chip); 454 + struct mtd_ecc_stats *ecc_stats = &nand_to_mtd(chip)->ecc_stats; 313 455 int bank = denali->active_bank; 314 - uint32_t ecc_cor; 456 + u32 ecc_cor; 315 457 unsigned int max_bitflips; 316 458 317 459 ecc_cor = ioread32(denali->reg + ECC_COR_INFO(bank)); ··· 466 346 * Unfortunately, we can not know the total number of corrected bits in 467 347 * the page. Increase the stats by max_bitflips. (compromised solution) 468 348 */ 469 - mtd->ecc_stats.corrected += max_bitflips; 349 + ecc_stats->corrected += max_bitflips; 470 350 471 351 return max_bitflips; 472 352 } 473 353 474 - static int denali_sw_ecc_fixup(struct mtd_info *mtd, 475 - struct denali_nand_info *denali, 476 - unsigned long *uncor_ecc_flags, uint8_t *buf) 354 + static int denali_sw_ecc_fixup(struct nand_chip *chip, 355 + unsigned long *uncor_ecc_flags, u8 *buf) 477 356 { 478 - unsigned int ecc_size = denali->nand.ecc.size; 357 + struct denali_controller *denali = to_denali_controller(chip); 358 + struct mtd_ecc_stats *ecc_stats = &nand_to_mtd(chip)->ecc_stats; 359 + unsigned int ecc_size = chip->ecc.size; 479 360 unsigned int bitflips = 0; 480 361 unsigned int max_bitflips = 0; 481 - uint32_t err_addr, err_cor_info; 362 + u32 err_addr, err_cor_info; 482 363 unsigned int err_byte, err_sector, err_device; 483 - uint8_t err_cor_value; 364 + u8 err_cor_value; 484 365 unsigned int prev_sector = 0; 485 - uint32_t irq_status; 366 + u32 irq_status; 486 367 487 368 denali_reset_irq(denali); 488 369 ··· 525 404 /* correct the ECC error */ 526 405 flips_in_byte = hweight8(buf[offset] ^ err_cor_value); 527 406 buf[offset] ^= err_cor_value; 528 - mtd->ecc_stats.corrected += flips_in_byte; 407 + ecc_stats->corrected += flips_in_byte; 529 408 bitflips += flips_in_byte; 530 409 531 410 max_bitflips = max(max_bitflips, bitflips); ··· 545 424 return max_bitflips; 546 425 } 547 426 548 - static void denali_setup_dma64(struct denali_nand_info *denali, 549 - dma_addr_t dma_addr, int page, int write) 427 + static void denali_setup_dma64(struct denali_controller *denali, 428 + dma_addr_t dma_addr, int page, bool write) 550 429 { 551 - uint32_t mode; 430 + u32 mode; 552 431 const int page_count = 1; 553 432 554 433 mode = DENALI_MAP10 | DENALI_BANK(denali) | page; ··· 560 439 * burst len = 64 bytes, the number of pages 561 440 */ 562 441 denali->host_write(denali, mode, 563 - 0x01002000 | (64 << 16) | (write << 8) | page_count); 442 + 0x01002000 | (64 << 16) | 443 + (write ? BIT(8) : 0) | page_count); 564 444 565 445 /* 2. set memory low address */ 566 446 denali->host_write(denali, mode, lower_32_bits(dma_addr)); ··· 570 448 denali->host_write(denali, mode, upper_32_bits(dma_addr)); 571 449 } 572 450 573 - static void denali_setup_dma32(struct denali_nand_info *denali, 574 - dma_addr_t dma_addr, int page, int write) 451 + static void denali_setup_dma32(struct denali_controller *denali, 452 + dma_addr_t dma_addr, int page, bool write) 575 453 { 576 - uint32_t mode; 454 + u32 mode; 577 455 const int page_count = 1; 578 456 579 457 mode = DENALI_MAP10 | DENALI_BANK(denali); ··· 582 460 583 461 /* 1. setup transfer type and # of pages */ 584 462 denali->host_write(denali, mode | page, 585 - 0x2000 | (write << 8) | page_count); 463 + 0x2000 | (write ? BIT(8) : 0) | page_count); 586 464 587 465 /* 2. set memory high address bits 23:8 */ 588 466 denali->host_write(denali, mode | ((dma_addr >> 16) << 8), 0x2200); ··· 594 472 denali->host_write(denali, mode | 0x14000, 0x2400); 595 473 } 596 474 597 - static int denali_pio_read(struct denali_nand_info *denali, void *buf, 475 + static int denali_pio_read(struct denali_controller *denali, u32 *buf, 598 476 size_t size, int page) 599 477 { 600 478 u32 addr = DENALI_MAP01 | DENALI_BANK(denali) | page; 601 - uint32_t *buf32 = (uint32_t *)buf; 602 - uint32_t irq_status, ecc_err_mask; 479 + u32 irq_status, ecc_err_mask; 603 480 int i; 604 481 605 482 if (denali->caps & DENALI_CAP_HW_ECC_FIXUP) ··· 609 488 denali_reset_irq(denali); 610 489 611 490 for (i = 0; i < size / 4; i++) 612 - *buf32++ = denali->host_read(denali, addr); 491 + buf[i] = denali->host_read(denali, addr); 613 492 614 493 irq_status = denali_wait_for_irq(denali, INTR__PAGE_XFER_INC); 615 494 if (!(irq_status & INTR__PAGE_XFER_INC)) ··· 621 500 return irq_status & ecc_err_mask ? -EBADMSG : 0; 622 501 } 623 502 624 - static int denali_pio_write(struct denali_nand_info *denali, 625 - const void *buf, size_t size, int page) 503 + static int denali_pio_write(struct denali_controller *denali, const u32 *buf, 504 + size_t size, int page) 626 505 { 627 506 u32 addr = DENALI_MAP01 | DENALI_BANK(denali) | page; 628 - const uint32_t *buf32 = (uint32_t *)buf; 629 - uint32_t irq_status; 507 + u32 irq_status; 630 508 int i; 631 509 632 510 denali_reset_irq(denali); 633 511 634 512 for (i = 0; i < size / 4; i++) 635 - denali->host_write(denali, addr, *buf32++); 513 + denali->host_write(denali, addr, buf[i]); 636 514 637 515 irq_status = denali_wait_for_irq(denali, 638 - INTR__PROGRAM_COMP | INTR__PROGRAM_FAIL); 516 + INTR__PROGRAM_COMP | 517 + INTR__PROGRAM_FAIL); 639 518 if (!(irq_status & INTR__PROGRAM_COMP)) 640 519 return -EIO; 641 520 642 521 return 0; 643 522 } 644 523 645 - static int denali_pio_xfer(struct denali_nand_info *denali, void *buf, 646 - size_t size, int page, int write) 524 + static int denali_pio_xfer(struct denali_controller *denali, void *buf, 525 + size_t size, int page, bool write) 647 526 { 648 527 if (write) 649 528 return denali_pio_write(denali, buf, size, page); ··· 651 530 return denali_pio_read(denali, buf, size, page); 652 531 } 653 532 654 - static int denali_dma_xfer(struct denali_nand_info *denali, void *buf, 655 - size_t size, int page, int write) 533 + static int denali_dma_xfer(struct denali_controller *denali, void *buf, 534 + size_t size, int page, bool write) 656 535 { 657 536 dma_addr_t dma_addr; 658 - uint32_t irq_mask, irq_status, ecc_err_mask; 537 + u32 irq_mask, irq_status, ecc_err_mask; 659 538 enum dma_data_direction dir = write ? DMA_TO_DEVICE : DMA_FROM_DEVICE; 660 539 int ret = 0; 661 540 ··· 708 587 return ret; 709 588 } 710 589 711 - static int denali_data_xfer(struct denali_nand_info *denali, void *buf, 712 - size_t size, int page, int raw, int write) 590 + static int denali_page_xfer(struct nand_chip *chip, void *buf, size_t size, 591 + int page, bool write) 713 592 { 714 - iowrite32(raw ? 0 : ECC_ENABLE__FLAG, denali->reg + ECC_ENABLE); 715 - iowrite32(raw ? TRANSFER_SPARE_REG__FLAG : 0, 716 - denali->reg + TRANSFER_SPARE_REG); 593 + struct denali_controller *denali = to_denali_controller(chip); 594 + 595 + denali_select_target(chip, chip->cur_cs); 717 596 718 597 if (denali->dma_avail) 719 598 return denali_dma_xfer(denali, buf, size, page, write); ··· 721 600 return denali_pio_xfer(denali, buf, size, page, write); 722 601 } 723 602 724 - static void denali_oob_xfer(struct mtd_info *mtd, struct nand_chip *chip, 725 - int page, int write) 726 - { 727 - struct denali_nand_info *denali = mtd_to_denali(mtd); 728 - int writesize = mtd->writesize; 729 - int oobsize = mtd->oobsize; 730 - uint8_t *bufpoi = chip->oob_poi; 731 - int ecc_steps = chip->ecc.steps; 732 - int ecc_size = chip->ecc.size; 733 - int ecc_bytes = chip->ecc.bytes; 734 - int oob_skip = denali->oob_skip_bytes; 735 - size_t size = writesize + oobsize; 736 - int i, pos, len; 737 - 738 - /* BBM at the beginning of the OOB area */ 739 - if (write) 740 - nand_prog_page_begin_op(chip, page, writesize, bufpoi, 741 - oob_skip); 742 - else 743 - nand_read_page_op(chip, page, writesize, bufpoi, oob_skip); 744 - bufpoi += oob_skip; 745 - 746 - /* OOB ECC */ 747 - for (i = 0; i < ecc_steps; i++) { 748 - pos = ecc_size + i * (ecc_size + ecc_bytes); 749 - len = ecc_bytes; 750 - 751 - if (pos >= writesize) 752 - pos += oob_skip; 753 - else if (pos + len > writesize) 754 - len = writesize - pos; 755 - 756 - if (write) 757 - nand_change_write_column_op(chip, pos, bufpoi, len, 758 - false); 759 - else 760 - nand_change_read_column_op(chip, pos, bufpoi, len, 761 - false); 762 - bufpoi += len; 763 - if (len < ecc_bytes) { 764 - len = ecc_bytes - len; 765 - if (write) 766 - nand_change_write_column_op(chip, writesize + 767 - oob_skip, bufpoi, 768 - len, false); 769 - else 770 - nand_change_read_column_op(chip, writesize + 771 - oob_skip, bufpoi, 772 - len, false); 773 - bufpoi += len; 774 - } 775 - } 776 - 777 - /* OOB free */ 778 - len = oobsize - (bufpoi - chip->oob_poi); 779 - if (write) 780 - nand_change_write_column_op(chip, size - len, bufpoi, len, 781 - false); 782 - else 783 - nand_change_read_column_op(chip, size - len, bufpoi, len, 784 - false); 785 - } 786 - 787 - static int denali_read_page_raw(struct nand_chip *chip, uint8_t *buf, 788 - int oob_required, int page) 789 - { 790 - struct mtd_info *mtd = nand_to_mtd(chip); 791 - struct denali_nand_info *denali = mtd_to_denali(mtd); 792 - int writesize = mtd->writesize; 793 - int oobsize = mtd->oobsize; 794 - int ecc_steps = chip->ecc.steps; 795 - int ecc_size = chip->ecc.size; 796 - int ecc_bytes = chip->ecc.bytes; 797 - void *tmp_buf = denali->buf; 798 - int oob_skip = denali->oob_skip_bytes; 799 - size_t size = writesize + oobsize; 800 - int ret, i, pos, len; 801 - 802 - ret = denali_data_xfer(denali, tmp_buf, size, page, 1, 0); 803 - if (ret) 804 - return ret; 805 - 806 - /* Arrange the buffer for syndrome payload/ecc layout */ 807 - if (buf) { 808 - for (i = 0; i < ecc_steps; i++) { 809 - pos = i * (ecc_size + ecc_bytes); 810 - len = ecc_size; 811 - 812 - if (pos >= writesize) 813 - pos += oob_skip; 814 - else if (pos + len > writesize) 815 - len = writesize - pos; 816 - 817 - memcpy(buf, tmp_buf + pos, len); 818 - buf += len; 819 - if (len < ecc_size) { 820 - len = ecc_size - len; 821 - memcpy(buf, tmp_buf + writesize + oob_skip, 822 - len); 823 - buf += len; 824 - } 825 - } 826 - } 827 - 828 - if (oob_required) { 829 - uint8_t *oob = chip->oob_poi; 830 - 831 - /* BBM at the beginning of the OOB area */ 832 - memcpy(oob, tmp_buf + writesize, oob_skip); 833 - oob += oob_skip; 834 - 835 - /* OOB ECC */ 836 - for (i = 0; i < ecc_steps; i++) { 837 - pos = ecc_size + i * (ecc_size + ecc_bytes); 838 - len = ecc_bytes; 839 - 840 - if (pos >= writesize) 841 - pos += oob_skip; 842 - else if (pos + len > writesize) 843 - len = writesize - pos; 844 - 845 - memcpy(oob, tmp_buf + pos, len); 846 - oob += len; 847 - if (len < ecc_bytes) { 848 - len = ecc_bytes - len; 849 - memcpy(oob, tmp_buf + writesize + oob_skip, 850 - len); 851 - oob += len; 852 - } 853 - } 854 - 855 - /* OOB free */ 856 - len = oobsize - (oob - chip->oob_poi); 857 - memcpy(oob, tmp_buf + size - len, len); 858 - } 859 - 860 - return 0; 861 - } 862 - 863 - static int denali_read_oob(struct nand_chip *chip, int page) 864 - { 865 - struct mtd_info *mtd = nand_to_mtd(chip); 866 - 867 - denali_oob_xfer(mtd, chip, page, 0); 868 - 869 - return 0; 870 - } 871 - 872 - static int denali_write_oob(struct nand_chip *chip, int page) 873 - { 874 - struct mtd_info *mtd = nand_to_mtd(chip); 875 - 876 - denali_oob_xfer(mtd, chip, page, 1); 877 - 878 - return nand_prog_page_end_op(chip); 879 - } 880 - 881 - static int denali_read_page(struct nand_chip *chip, uint8_t *buf, 603 + static int denali_read_page(struct nand_chip *chip, u8 *buf, 882 604 int oob_required, int page) 883 605 { 606 + struct denali_controller *denali = to_denali_controller(chip); 884 607 struct mtd_info *mtd = nand_to_mtd(chip); 885 - struct denali_nand_info *denali = mtd_to_denali(mtd); 886 608 unsigned long uncor_ecc_flags = 0; 887 609 int stat = 0; 888 610 int ret; 889 611 890 - ret = denali_data_xfer(denali, buf, mtd->writesize, page, 0, 0); 612 + ret = denali_page_xfer(chip, buf, mtd->writesize, page, false); 891 613 if (ret && ret != -EBADMSG) 892 614 return ret; 893 615 894 616 if (denali->caps & DENALI_CAP_HW_ECC_FIXUP) 895 - stat = denali_hw_ecc_fixup(mtd, denali, &uncor_ecc_flags); 617 + stat = denali_hw_ecc_fixup(chip, &uncor_ecc_flags); 896 618 else if (ret == -EBADMSG) 897 - stat = denali_sw_ecc_fixup(mtd, denali, &uncor_ecc_flags, buf); 619 + stat = denali_sw_ecc_fixup(chip, &uncor_ecc_flags, buf); 898 620 899 621 if (stat < 0) 900 622 return stat; ··· 747 783 if (ret) 748 784 return ret; 749 785 750 - stat = denali_check_erased_page(mtd, chip, buf, 786 + stat = denali_check_erased_page(chip, buf, 751 787 uncor_ecc_flags, stat); 752 788 } 753 789 754 790 return stat; 755 791 } 756 792 757 - static int denali_write_page_raw(struct nand_chip *chip, const uint8_t *buf, 758 - int oob_required, int page) 759 - { 760 - struct mtd_info *mtd = nand_to_mtd(chip); 761 - struct denali_nand_info *denali = mtd_to_denali(mtd); 762 - int writesize = mtd->writesize; 763 - int oobsize = mtd->oobsize; 764 - int ecc_steps = chip->ecc.steps; 765 - int ecc_size = chip->ecc.size; 766 - int ecc_bytes = chip->ecc.bytes; 767 - void *tmp_buf = denali->buf; 768 - int oob_skip = denali->oob_skip_bytes; 769 - size_t size = writesize + oobsize; 770 - int i, pos, len; 771 - 772 - /* 773 - * Fill the buffer with 0xff first except the full page transfer. 774 - * This simplifies the logic. 775 - */ 776 - if (!buf || !oob_required) 777 - memset(tmp_buf, 0xff, size); 778 - 779 - /* Arrange the buffer for syndrome payload/ecc layout */ 780 - if (buf) { 781 - for (i = 0; i < ecc_steps; i++) { 782 - pos = i * (ecc_size + ecc_bytes); 783 - len = ecc_size; 784 - 785 - if (pos >= writesize) 786 - pos += oob_skip; 787 - else if (pos + len > writesize) 788 - len = writesize - pos; 789 - 790 - memcpy(tmp_buf + pos, buf, len); 791 - buf += len; 792 - if (len < ecc_size) { 793 - len = ecc_size - len; 794 - memcpy(tmp_buf + writesize + oob_skip, buf, 795 - len); 796 - buf += len; 797 - } 798 - } 799 - } 800 - 801 - if (oob_required) { 802 - const uint8_t *oob = chip->oob_poi; 803 - 804 - /* BBM at the beginning of the OOB area */ 805 - memcpy(tmp_buf + writesize, oob, oob_skip); 806 - oob += oob_skip; 807 - 808 - /* OOB ECC */ 809 - for (i = 0; i < ecc_steps; i++) { 810 - pos = ecc_size + i * (ecc_size + ecc_bytes); 811 - len = ecc_bytes; 812 - 813 - if (pos >= writesize) 814 - pos += oob_skip; 815 - else if (pos + len > writesize) 816 - len = writesize - pos; 817 - 818 - memcpy(tmp_buf + pos, oob, len); 819 - oob += len; 820 - if (len < ecc_bytes) { 821 - len = ecc_bytes - len; 822 - memcpy(tmp_buf + writesize + oob_skip, oob, 823 - len); 824 - oob += len; 825 - } 826 - } 827 - 828 - /* OOB free */ 829 - len = oobsize - (oob - chip->oob_poi); 830 - memcpy(tmp_buf + size - len, oob, len); 831 - } 832 - 833 - return denali_data_xfer(denali, tmp_buf, size, page, 1, 1); 834 - } 835 - 836 - static int denali_write_page(struct nand_chip *chip, const uint8_t *buf, 793 + static int denali_write_page(struct nand_chip *chip, const u8 *buf, 837 794 int oob_required, int page) 838 795 { 839 796 struct mtd_info *mtd = nand_to_mtd(chip); 840 - struct denali_nand_info *denali = mtd_to_denali(mtd); 841 797 842 - return denali_data_xfer(denali, (void *)buf, mtd->writesize, 843 - page, 0, 1); 844 - } 845 - 846 - static void denali_select_chip(struct nand_chip *chip, int cs) 847 - { 848 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 849 - 850 - denali->active_bank = cs; 851 - } 852 - 853 - static int denali_waitfunc(struct nand_chip *chip) 854 - { 855 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 856 - uint32_t irq_status; 857 - 858 - /* R/B# pin transitioned from low to high? */ 859 - irq_status = denali_wait_for_irq(denali, INTR__INT_ACT); 860 - 861 - return irq_status & INTR__INT_ACT ? 0 : NAND_STATUS_FAIL; 798 + return denali_page_xfer(chip, (void *)buf, mtd->writesize, page, true); 862 799 } 863 800 864 801 static int denali_setup_data_interface(struct nand_chip *chip, int chipnr, 865 802 const struct nand_data_interface *conf) 866 803 { 867 - struct denali_nand_info *denali = mtd_to_denali(nand_to_mtd(chip)); 804 + struct denali_controller *denali = to_denali_controller(chip); 805 + struct denali_chip_sel *sel; 868 806 const struct nand_sdr_timings *timings; 869 807 unsigned long t_x, mult_x; 870 808 int acc_clks, re_2_we, re_2_re, we_2_re, addr_2_data; 871 809 int rdwr_en_lo, rdwr_en_hi, rdwr_en_lo_hi, cs_setup; 872 810 int addr_2_data_mask; 873 - uint32_t tmp; 811 + u32 tmp; 874 812 875 813 timings = nand_get_sdr_timings(conf); 876 814 if (IS_ERR(timings)) ··· 795 929 if (chipnr == NAND_DATA_IFACE_CHECK_ONLY) 796 930 return 0; 797 931 932 + sel = &to_denali_chip(chip)->sels[chipnr]; 933 + 798 934 /* tREA -> ACC_CLKS */ 799 935 acc_clks = DIV_ROUND_UP(timings->tREA_max, t_x); 800 936 acc_clks = min_t(int, acc_clks, ACC_CLKS__VALUE); ··· 804 936 tmp = ioread32(denali->reg + ACC_CLKS); 805 937 tmp &= ~ACC_CLKS__VALUE; 806 938 tmp |= FIELD_PREP(ACC_CLKS__VALUE, acc_clks); 807 - iowrite32(tmp, denali->reg + ACC_CLKS); 939 + sel->acc_clks = tmp; 808 940 809 941 /* tRWH -> RE_2_WE */ 810 942 re_2_we = DIV_ROUND_UP(timings->tRHW_min, t_x); ··· 813 945 tmp = ioread32(denali->reg + RE_2_WE); 814 946 tmp &= ~RE_2_WE__VALUE; 815 947 tmp |= FIELD_PREP(RE_2_WE__VALUE, re_2_we); 816 - iowrite32(tmp, denali->reg + RE_2_WE); 948 + sel->re_2_we = tmp; 817 949 818 950 /* tRHZ -> RE_2_RE */ 819 951 re_2_re = DIV_ROUND_UP(timings->tRHZ_max, t_x); ··· 822 954 tmp = ioread32(denali->reg + RE_2_RE); 823 955 tmp &= ~RE_2_RE__VALUE; 824 956 tmp |= FIELD_PREP(RE_2_RE__VALUE, re_2_re); 825 - iowrite32(tmp, denali->reg + RE_2_RE); 957 + sel->re_2_re = tmp; 826 958 827 959 /* 828 960 * tCCS, tWHR -> WE_2_RE ··· 836 968 tmp = ioread32(denali->reg + TWHR2_AND_WE_2_RE); 837 969 tmp &= ~TWHR2_AND_WE_2_RE__WE_2_RE; 838 970 tmp |= FIELD_PREP(TWHR2_AND_WE_2_RE__WE_2_RE, we_2_re); 839 - iowrite32(tmp, denali->reg + TWHR2_AND_WE_2_RE); 971 + sel->hwhr2_and_we_2_re = tmp; 840 972 841 973 /* tADL -> ADDR_2_DATA */ 842 974 ··· 851 983 tmp = ioread32(denali->reg + TCWAW_AND_ADDR_2_DATA); 852 984 tmp &= ~TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA; 853 985 tmp |= FIELD_PREP(TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA, addr_2_data); 854 - iowrite32(tmp, denali->reg + TCWAW_AND_ADDR_2_DATA); 986 + sel->tcwaw_and_addr_2_data = tmp; 855 987 856 988 /* tREH, tWH -> RDWR_EN_HI_CNT */ 857 989 rdwr_en_hi = DIV_ROUND_UP(max(timings->tREH_min, timings->tWH_min), ··· 861 993 tmp = ioread32(denali->reg + RDWR_EN_HI_CNT); 862 994 tmp &= ~RDWR_EN_HI_CNT__VALUE; 863 995 tmp |= FIELD_PREP(RDWR_EN_HI_CNT__VALUE, rdwr_en_hi); 864 - iowrite32(tmp, denali->reg + RDWR_EN_HI_CNT); 996 + sel->rdwr_en_hi_cnt = tmp; 865 997 866 998 /* tRP, tWP -> RDWR_EN_LO_CNT */ 867 999 rdwr_en_lo = DIV_ROUND_UP(max(timings->tRP_min, timings->tWP_min), t_x); ··· 874 1006 tmp = ioread32(denali->reg + RDWR_EN_LO_CNT); 875 1007 tmp &= ~RDWR_EN_LO_CNT__VALUE; 876 1008 tmp |= FIELD_PREP(RDWR_EN_LO_CNT__VALUE, rdwr_en_lo); 877 - iowrite32(tmp, denali->reg + RDWR_EN_LO_CNT); 1009 + sel->rdwr_en_lo_cnt = tmp; 878 1010 879 1011 /* tCS, tCEA -> CS_SETUP_CNT */ 880 1012 cs_setup = max3((int)DIV_ROUND_UP(timings->tCS_min, t_x) - rdwr_en_lo, ··· 885 1017 tmp = ioread32(denali->reg + CS_SETUP_CNT); 886 1018 tmp &= ~CS_SETUP_CNT__VALUE; 887 1019 tmp |= FIELD_PREP(CS_SETUP_CNT__VALUE, cs_setup); 888 - iowrite32(tmp, denali->reg + CS_SETUP_CNT); 1020 + sel->cs_setup_cnt = tmp; 889 1021 890 1022 return 0; 891 - } 892 - 893 - static void denali_hw_init(struct denali_nand_info *denali) 894 - { 895 - /* 896 - * The REVISION register may not be reliable. Platforms are allowed to 897 - * override it. 898 - */ 899 - if (!denali->revision) 900 - denali->revision = swab16(ioread32(denali->reg + REVISION)); 901 - 902 - /* 903 - * Set how many bytes should be skipped before writing data in OOB. 904 - * If a non-zero value has already been set (by firmware or something), 905 - * just use it. Otherwise, set the driver default. 906 - */ 907 - denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); 908 - if (!denali->oob_skip_bytes) { 909 - denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; 910 - iowrite32(denali->oob_skip_bytes, 911 - denali->reg + SPARE_AREA_SKIP_BYTES); 912 - } 913 - 914 - denali_detect_max_banks(denali); 915 - iowrite32(0x0F, denali->reg + RB_PIN_ENABLED); 916 - iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE); 917 - 918 - iowrite32(0xffff, denali->reg + SPARE_AREA_MARKER); 919 1023 } 920 1024 921 1025 int denali_calc_ecc_bytes(int step_size, int strength) ··· 900 1060 static int denali_ooblayout_ecc(struct mtd_info *mtd, int section, 901 1061 struct mtd_oob_region *oobregion) 902 1062 { 903 - struct denali_nand_info *denali = mtd_to_denali(mtd); 904 1063 struct nand_chip *chip = mtd_to_nand(mtd); 1064 + struct denali_controller *denali = to_denali_controller(chip); 905 1065 906 - if (section) 1066 + if (section > 0) 907 1067 return -ERANGE; 908 1068 909 1069 oobregion->offset = denali->oob_skip_bytes; ··· 915 1075 static int denali_ooblayout_free(struct mtd_info *mtd, int section, 916 1076 struct mtd_oob_region *oobregion) 917 1077 { 918 - struct denali_nand_info *denali = mtd_to_denali(mtd); 919 1078 struct nand_chip *chip = mtd_to_nand(mtd); 1079 + struct denali_controller *denali = to_denali_controller(chip); 920 1080 921 - if (section) 1081 + if (section > 0) 922 1082 return -ERANGE; 923 1083 924 1084 oobregion->offset = chip->ecc.total + denali->oob_skip_bytes; ··· 932 1092 .free = denali_ooblayout_free, 933 1093 }; 934 1094 935 - static int denali_multidev_fixup(struct denali_nand_info *denali) 1095 + static int denali_multidev_fixup(struct nand_chip *chip) 936 1096 { 937 - struct nand_chip *chip = &denali->nand; 1097 + struct denali_controller *denali = to_denali_controller(chip); 938 1098 struct mtd_info *mtd = nand_to_mtd(chip); 1099 + struct nand_memory_organization *memorg; 1100 + 1101 + memorg = nanddev_get_memorg(&chip->base); 939 1102 940 1103 /* 941 1104 * Support for multi device: ··· 968 1125 } 969 1126 970 1127 /* 2 chips in parallel */ 1128 + memorg->pagesize <<= 1; 1129 + memorg->oobsize <<= 1; 971 1130 mtd->size <<= 1; 972 1131 mtd->erasesize <<= 1; 973 1132 mtd->writesize <<= 1; 974 1133 mtd->oobsize <<= 1; 975 - chip->chipsize <<= 1; 976 1134 chip->page_shift += 1; 977 1135 chip->phys_erase_shift += 1; 978 1136 chip->bbt_erase_shift += 1; ··· 989 1145 990 1146 static int denali_attach_chip(struct nand_chip *chip) 991 1147 { 1148 + struct denali_controller *denali = to_denali_controller(chip); 992 1149 struct mtd_info *mtd = nand_to_mtd(chip); 993 - struct denali_nand_info *denali = mtd_to_denali(mtd); 994 1150 int ret; 995 - 996 - if (ioread32(denali->reg + FEATURES) & FEATURES__DMA) 997 - denali->dma_avail = 1; 998 - 999 - if (denali->dma_avail) { 1000 - int dma_bit = denali->caps & DENALI_CAP_DMA_64BIT ? 64 : 32; 1001 - 1002 - ret = dma_set_mask(denali->dev, DMA_BIT_MASK(dma_bit)); 1003 - if (ret) { 1004 - dev_info(denali->dev, 1005 - "Failed to set DMA mask. Disabling DMA.\n"); 1006 - denali->dma_avail = 0; 1007 - } 1008 - } 1009 - 1010 - if (denali->dma_avail) { 1011 - chip->options |= NAND_USE_BOUNCE_BUFFER; 1012 - chip->buf_align = 16; 1013 - if (denali->caps & DENALI_CAP_DMA_64BIT) 1014 - denali->setup_dma = denali_setup_dma64; 1015 - else 1016 - denali->setup_dma = denali_setup_dma32; 1017 - } 1018 - 1019 - chip->bbt_options |= NAND_BBT_USE_FLASH; 1020 - chip->bbt_options |= NAND_BBT_NO_OOB; 1021 - chip->ecc.mode = NAND_ECC_HW_SYNDROME; 1022 - chip->options |= NAND_NO_SUBPAGE_WRITE; 1023 1151 1024 1152 ret = nand_ecc_choose_conf(chip, denali->ecc_caps, 1025 1153 mtd->oobsize - denali->oob_skip_bytes); ··· 1004 1188 "chosen ECC settings: step=%d, strength=%d, bytes=%d\n", 1005 1189 chip->ecc.size, chip->ecc.strength, chip->ecc.bytes); 1006 1190 1007 - iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD, 1) | 1008 - FIELD_PREP(ECC_CORRECTION__VALUE, chip->ecc.strength), 1009 - denali->reg + ECC_CORRECTION); 1010 - iowrite32(mtd->erasesize / mtd->writesize, 1011 - denali->reg + PAGES_PER_BLOCK); 1012 - iowrite32(chip->options & NAND_BUSWIDTH_16 ? 1 : 0, 1013 - denali->reg + DEVICE_WIDTH); 1014 - iowrite32(chip->options & NAND_ROW_ADDR_3 ? 0 : TWO_ROW_ADDR_CYCLES__FLAG, 1015 - denali->reg + TWO_ROW_ADDR_CYCLES); 1016 - iowrite32(mtd->writesize, denali->reg + DEVICE_MAIN_AREA_SIZE); 1017 - iowrite32(mtd->oobsize, denali->reg + DEVICE_SPARE_AREA_SIZE); 1018 - 1019 - iowrite32(chip->ecc.size, denali->reg + CFG_DATA_BLOCK_SIZE); 1020 - iowrite32(chip->ecc.size, denali->reg + CFG_LAST_DATA_BLOCK_SIZE); 1021 - /* chip->ecc.steps is set by nand_scan_tail(); not available here */ 1022 - iowrite32(mtd->writesize / chip->ecc.size, 1023 - denali->reg + CFG_NUM_DATA_BLOCKS); 1024 - 1025 - mtd_set_ooblayout(mtd, &denali_ooblayout_ops); 1026 - 1027 - if (chip->options & NAND_BUSWIDTH_16) { 1028 - chip->legacy.read_buf = denali_read_buf16; 1029 - chip->legacy.write_buf = denali_write_buf16; 1030 - } else { 1031 - chip->legacy.read_buf = denali_read_buf; 1032 - chip->legacy.write_buf = denali_write_buf; 1033 - } 1034 - chip->ecc.read_page = denali_read_page; 1035 - chip->ecc.read_page_raw = denali_read_page_raw; 1036 - chip->ecc.write_page = denali_write_page; 1037 - chip->ecc.write_page_raw = denali_write_page_raw; 1038 - chip->ecc.read_oob = denali_read_oob; 1039 - chip->ecc.write_oob = denali_write_oob; 1040 - 1041 - ret = denali_multidev_fixup(denali); 1191 + ret = denali_multidev_fixup(chip); 1042 1192 if (ret) 1043 1193 return ret; 1044 - 1045 - /* 1046 - * This buffer is DMA-mapped by denali_{read,write}_page_raw. Do not 1047 - * use devm_kmalloc() because the memory allocated by devm_ does not 1048 - * guarantee DMA-safe alignment. 1049 - */ 1050 - denali->buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); 1051 - if (!denali->buf) 1052 - return -ENOMEM; 1053 1194 1054 1195 return 0; 1055 1196 } 1056 1197 1057 - static void denali_detach_chip(struct nand_chip *chip) 1198 + static void denali_exec_in8(struct denali_controller *denali, u32 type, 1199 + u8 *buf, unsigned int len) 1058 1200 { 1059 - struct mtd_info *mtd = nand_to_mtd(chip); 1060 - struct denali_nand_info *denali = mtd_to_denali(mtd); 1201 + int i; 1061 1202 1062 - kfree(denali->buf); 1203 + for (i = 0; i < len; i++) 1204 + buf[i] = denali->host_read(denali, type | DENALI_BANK(denali)); 1205 + } 1206 + 1207 + static void denali_exec_in16(struct denali_controller *denali, u32 type, 1208 + u8 *buf, unsigned int len) 1209 + { 1210 + u32 data; 1211 + int i; 1212 + 1213 + for (i = 0; i < len; i += 2) { 1214 + data = denali->host_read(denali, type | DENALI_BANK(denali)); 1215 + /* bit 31:24 and 15:8 are used for DDR */ 1216 + buf[i] = data; 1217 + buf[i + 1] = data >> 16; 1218 + } 1219 + } 1220 + 1221 + static void denali_exec_in(struct denali_controller *denali, u32 type, 1222 + u8 *buf, unsigned int len, bool width16) 1223 + { 1224 + if (width16) 1225 + denali_exec_in16(denali, type, buf, len); 1226 + else 1227 + denali_exec_in8(denali, type, buf, len); 1228 + } 1229 + 1230 + static void denali_exec_out8(struct denali_controller *denali, u32 type, 1231 + const u8 *buf, unsigned int len) 1232 + { 1233 + int i; 1234 + 1235 + for (i = 0; i < len; i++) 1236 + denali->host_write(denali, type | DENALI_BANK(denali), buf[i]); 1237 + } 1238 + 1239 + static void denali_exec_out16(struct denali_controller *denali, u32 type, 1240 + const u8 *buf, unsigned int len) 1241 + { 1242 + int i; 1243 + 1244 + for (i = 0; i < len; i += 2) 1245 + denali->host_write(denali, type | DENALI_BANK(denali), 1246 + buf[i + 1] << 16 | buf[i]); 1247 + } 1248 + 1249 + static void denali_exec_out(struct denali_controller *denali, u32 type, 1250 + const u8 *buf, unsigned int len, bool width16) 1251 + { 1252 + if (width16) 1253 + denali_exec_out16(denali, type, buf, len); 1254 + else 1255 + denali_exec_out8(denali, type, buf, len); 1256 + } 1257 + 1258 + static int denali_exec_waitrdy(struct denali_controller *denali) 1259 + { 1260 + u32 irq_stat; 1261 + 1262 + /* R/B# pin transitioned from low to high? */ 1263 + irq_stat = denali_wait_for_irq(denali, INTR__INT_ACT); 1264 + 1265 + /* Just in case nand_operation has multiple NAND_OP_WAITRDY_INSTR. */ 1266 + denali_reset_irq(denali); 1267 + 1268 + return irq_stat & INTR__INT_ACT ? 0 : -EIO; 1269 + } 1270 + 1271 + static int denali_exec_instr(struct nand_chip *chip, 1272 + const struct nand_op_instr *instr) 1273 + { 1274 + struct denali_controller *denali = to_denali_controller(chip); 1275 + 1276 + switch (instr->type) { 1277 + case NAND_OP_CMD_INSTR: 1278 + denali_exec_out8(denali, DENALI_MAP11_CMD, 1279 + &instr->ctx.cmd.opcode, 1); 1280 + return 0; 1281 + case NAND_OP_ADDR_INSTR: 1282 + denali_exec_out8(denali, DENALI_MAP11_ADDR, 1283 + instr->ctx.addr.addrs, 1284 + instr->ctx.addr.naddrs); 1285 + return 0; 1286 + case NAND_OP_DATA_IN_INSTR: 1287 + denali_exec_in(denali, DENALI_MAP11_DATA, 1288 + instr->ctx.data.buf.in, 1289 + instr->ctx.data.len, 1290 + !instr->ctx.data.force_8bit && 1291 + chip->options & NAND_BUSWIDTH_16); 1292 + return 0; 1293 + case NAND_OP_DATA_OUT_INSTR: 1294 + denali_exec_out(denali, DENALI_MAP11_DATA, 1295 + instr->ctx.data.buf.out, 1296 + instr->ctx.data.len, 1297 + !instr->ctx.data.force_8bit && 1298 + chip->options & NAND_BUSWIDTH_16); 1299 + return 0; 1300 + case NAND_OP_WAITRDY_INSTR: 1301 + return denali_exec_waitrdy(denali); 1302 + default: 1303 + WARN_ONCE(1, "unsupported NAND instruction type: %d\n", 1304 + instr->type); 1305 + 1306 + return -EINVAL; 1307 + } 1308 + } 1309 + 1310 + static int denali_exec_op(struct nand_chip *chip, 1311 + const struct nand_operation *op, bool check_only) 1312 + { 1313 + int i, ret; 1314 + 1315 + if (check_only) 1316 + return 0; 1317 + 1318 + denali_select_target(chip, op->cs); 1319 + 1320 + /* 1321 + * Some commands contain NAND_OP_WAITRDY_INSTR. 1322 + * irq must be cleared here to catch the R/B# interrupt there. 1323 + */ 1324 + denali_reset_irq(to_denali_controller(chip)); 1325 + 1326 + for (i = 0; i < op->ninstrs; i++) { 1327 + ret = denali_exec_instr(chip, &op->instrs[i]); 1328 + if (ret) 1329 + return ret; 1330 + } 1331 + 1332 + return 0; 1063 1333 } 1064 1334 1065 1335 static const struct nand_controller_ops denali_controller_ops = { 1066 1336 .attach_chip = denali_attach_chip, 1067 - .detach_chip = denali_detach_chip, 1337 + .exec_op = denali_exec_op, 1068 1338 .setup_data_interface = denali_setup_data_interface, 1069 1339 }; 1070 1340 1071 - int denali_init(struct denali_nand_info *denali) 1341 + int denali_chip_init(struct denali_controller *denali, 1342 + struct denali_chip *dchip) 1072 1343 { 1073 - struct nand_chip *chip = &denali->nand; 1344 + struct nand_chip *chip = &dchip->chip; 1074 1345 struct mtd_info *mtd = nand_to_mtd(chip); 1346 + struct denali_chip *dchip2; 1347 + int i, j, ret; 1348 + 1349 + chip->controller = &denali->controller; 1350 + 1351 + /* sanity checks for bank numbers */ 1352 + for (i = 0; i < dchip->nsels; i++) { 1353 + unsigned int bank = dchip->sels[i].bank; 1354 + 1355 + if (bank >= denali->nbanks) { 1356 + dev_err(denali->dev, "unsupported bank %d\n", bank); 1357 + return -EINVAL; 1358 + } 1359 + 1360 + for (j = 0; j < i; j++) { 1361 + if (bank == dchip->sels[j].bank) { 1362 + dev_err(denali->dev, 1363 + "bank %d is assigned twice in the same chip\n", 1364 + bank); 1365 + return -EINVAL; 1366 + } 1367 + } 1368 + 1369 + list_for_each_entry(dchip2, &denali->chips, node) { 1370 + for (j = 0; j < dchip2->nsels; j++) { 1371 + if (bank == dchip2->sels[j].bank) { 1372 + dev_err(denali->dev, 1373 + "bank %d is already used\n", 1374 + bank); 1375 + return -EINVAL; 1376 + } 1377 + } 1378 + } 1379 + } 1380 + 1381 + mtd->dev.parent = denali->dev; 1382 + 1383 + /* 1384 + * Fallback to the default name if DT did not give "label" property. 1385 + * Use "label" property if multiple chips are connected. 1386 + */ 1387 + if (!mtd->name && list_empty(&denali->chips)) 1388 + mtd->name = "denali-nand"; 1389 + 1390 + if (denali->dma_avail) { 1391 + chip->options |= NAND_USE_BOUNCE_BUFFER; 1392 + chip->buf_align = 16; 1393 + } 1394 + 1395 + /* clk rate info is needed for setup_data_interface */ 1396 + if (!denali->clk_rate || !denali->clk_x_rate) 1397 + chip->options |= NAND_KEEP_TIMINGS; 1398 + 1399 + chip->bbt_options |= NAND_BBT_USE_FLASH; 1400 + chip->bbt_options |= NAND_BBT_NO_OOB; 1401 + chip->options |= NAND_NO_SUBPAGE_WRITE; 1402 + chip->ecc.mode = NAND_ECC_HW_SYNDROME; 1403 + chip->ecc.read_page = denali_read_page; 1404 + chip->ecc.write_page = denali_write_page; 1405 + chip->ecc.read_page_raw = denali_read_page_raw; 1406 + chip->ecc.write_page_raw = denali_write_page_raw; 1407 + chip->ecc.read_oob = denali_read_oob; 1408 + chip->ecc.write_oob = denali_write_oob; 1409 + 1410 + mtd_set_ooblayout(mtd, &denali_ooblayout_ops); 1411 + 1412 + ret = nand_scan(chip, dchip->nsels); 1413 + if (ret) 1414 + return ret; 1415 + 1416 + ret = mtd_device_register(mtd, NULL, 0); 1417 + if (ret) { 1418 + dev_err(denali->dev, "Failed to register MTD: %d\n", ret); 1419 + goto cleanup_nand; 1420 + } 1421 + 1422 + list_add_tail(&dchip->node, &denali->chips); 1423 + 1424 + return 0; 1425 + 1426 + cleanup_nand: 1427 + nand_cleanup(chip); 1428 + 1429 + return ret; 1430 + } 1431 + EXPORT_SYMBOL_GPL(denali_chip_init); 1432 + 1433 + int denali_init(struct denali_controller *denali) 1434 + { 1075 1435 u32 features = ioread32(denali->reg + FEATURES); 1076 1436 int ret; 1077 1437 1078 - mtd->dev.parent = denali->dev; 1079 - denali_hw_init(denali); 1080 - 1438 + nand_controller_init(&denali->controller); 1439 + denali->controller.ops = &denali_controller_ops; 1081 1440 init_completion(&denali->complete); 1082 1441 spin_lock_init(&denali->irq_lock); 1442 + INIT_LIST_HEAD(&denali->chips); 1443 + denali->active_bank = DENALI_INVALID_BANK; 1444 + 1445 + /* 1446 + * The REVISION register may not be reliable. Platforms are allowed to 1447 + * override it. 1448 + */ 1449 + if (!denali->revision) 1450 + denali->revision = swab16(ioread32(denali->reg + REVISION)); 1451 + 1452 + denali->nbanks = 1 << FIELD_GET(FEATURES__N_BANKS, features); 1453 + 1454 + /* the encoding changed from rev 5.0 to 5.1 */ 1455 + if (denali->revision < 0x0501) 1456 + denali->nbanks <<= 1; 1457 + 1458 + if (features & FEATURES__DMA) 1459 + denali->dma_avail = true; 1460 + 1461 + if (denali->dma_avail) { 1462 + int dma_bit = denali->caps & DENALI_CAP_DMA_64BIT ? 64 : 32; 1463 + 1464 + ret = dma_set_mask(denali->dev, DMA_BIT_MASK(dma_bit)); 1465 + if (ret) { 1466 + dev_info(denali->dev, 1467 + "Failed to set DMA mask. Disabling DMA.\n"); 1468 + denali->dma_avail = false; 1469 + } 1470 + } 1471 + 1472 + if (denali->dma_avail) { 1473 + if (denali->caps & DENALI_CAP_DMA_64BIT) 1474 + denali->setup_dma = denali_setup_dma64; 1475 + else 1476 + denali->setup_dma = denali_setup_dma32; 1477 + } 1478 + 1479 + if (features & FEATURES__INDEX_ADDR) { 1480 + denali->host_read = denali_indexed_read; 1481 + denali->host_write = denali_indexed_write; 1482 + } else { 1483 + denali->host_read = denali_direct_read; 1484 + denali->host_write = denali_direct_write; 1485 + } 1486 + 1487 + /* 1488 + * Set how many bytes should be skipped before writing data in OOB. 1489 + * If a non-zero value has already been set (by firmware or something), 1490 + * just use it. Otherwise, set the driver's default. 1491 + */ 1492 + denali->oob_skip_bytes = ioread32(denali->reg + SPARE_AREA_SKIP_BYTES); 1493 + if (!denali->oob_skip_bytes) { 1494 + denali->oob_skip_bytes = DENALI_DEFAULT_OOB_SKIP_BYTES; 1495 + iowrite32(denali->oob_skip_bytes, 1496 + denali->reg + SPARE_AREA_SKIP_BYTES); 1497 + } 1498 + 1499 + iowrite32(0, denali->reg + TRANSFER_SPARE_REG); 1500 + iowrite32(GENMASK(denali->nbanks - 1, 0), denali->reg + RB_PIN_ENABLED); 1501 + iowrite32(CHIP_EN_DONT_CARE__FLAG, denali->reg + CHIP_ENABLE_DONT_CARE); 1502 + iowrite32(ECC_ENABLE__FLAG, denali->reg + ECC_ENABLE); 1503 + iowrite32(0xffff, denali->reg + SPARE_AREA_MARKER); 1083 1504 1084 1505 denali_clear_irq_all(denali); 1085 1506 ··· 1329 1276 1330 1277 denali_enable_irq(denali); 1331 1278 1332 - denali->active_bank = DENALI_INVALID_BANK; 1333 - 1334 - nand_set_flash_node(chip, denali->dev->of_node); 1335 - /* Fallback to the default name if DT did not give "label" property */ 1336 - if (!mtd->name) 1337 - mtd->name = "denali-nand"; 1338 - 1339 - chip->legacy.select_chip = denali_select_chip; 1340 - chip->legacy.read_byte = denali_read_byte; 1341 - chip->legacy.write_byte = denali_write_byte; 1342 - chip->legacy.cmd_ctrl = denali_cmd_ctrl; 1343 - chip->legacy.waitfunc = denali_waitfunc; 1344 - 1345 - if (features & FEATURES__INDEX_ADDR) { 1346 - denali->host_read = denali_indexed_read; 1347 - denali->host_write = denali_indexed_write; 1348 - } else { 1349 - denali->host_read = denali_direct_read; 1350 - denali->host_write = denali_direct_write; 1351 - } 1352 - 1353 - /* clk rate info is needed for setup_data_interface */ 1354 - if (!denali->clk_rate || !denali->clk_x_rate) 1355 - chip->options |= NAND_KEEP_TIMINGS; 1356 - 1357 - chip->legacy.dummy_controller.ops = &denali_controller_ops; 1358 - ret = nand_scan(chip, denali->max_banks); 1359 - if (ret) 1360 - goto disable_irq; 1361 - 1362 - ret = mtd_device_register(mtd, NULL, 0); 1363 - if (ret) { 1364 - dev_err(denali->dev, "Failed to register MTD: %d\n", ret); 1365 - goto cleanup_nand; 1366 - } 1367 - 1368 1279 return 0; 1369 - 1370 - cleanup_nand: 1371 - nand_cleanup(chip); 1372 - disable_irq: 1373 - denali_disable_irq(denali); 1374 - 1375 - return ret; 1376 1280 } 1377 1281 EXPORT_SYMBOL(denali_init); 1378 1282 1379 - void denali_remove(struct denali_nand_info *denali) 1283 + void denali_remove(struct denali_controller *denali) 1380 1284 { 1381 - nand_release(&denali->nand); 1285 + struct denali_chip *dchip; 1286 + 1287 + list_for_each_entry(dchip, &denali->chips, node) 1288 + nand_release(&dchip->chip); 1289 + 1382 1290 denali_disable_irq(denali); 1383 1291 } 1384 1292 EXPORT_SYMBOL(denali_remove);
+94 -23
drivers/mtd/nand/raw/denali.h
··· 9 9 10 10 #include <linux/bits.h> 11 11 #include <linux/completion.h> 12 + #include <linux/list.h> 12 13 #include <linux/mtd/rawnand.h> 13 14 #include <linux/spinlock_types.h> 14 15 #include <linux/types.h> ··· 291 290 #define CHNL_ACTIVE__CHANNEL2 BIT(2) 292 291 #define CHNL_ACTIVE__CHANNEL3 BIT(3) 293 292 294 - struct denali_nand_info { 295 - struct nand_chip nand; 296 - unsigned long clk_rate; /* core clock rate */ 297 - unsigned long clk_x_rate; /* bus interface clock rate */ 298 - int active_bank; /* currently selected bank */ 293 + /** 294 + * struct denali_chip_sel - per-CS data of Denali NAND 295 + * 296 + * @bank: bank id of the controller this CS is connected to 297 + * @hwhr2_and_we_2_re: value of timing register HWHR2_AND_WE_2_RE 298 + * @tcwaw_and_addr_2_data: value of timing register TCWAW_AND_ADDR_2_DATA 299 + * @re_2_we: value of timing register RE_2_WE 300 + * @acc_clks: value of timing register ACC_CLKS 301 + * @rdwr_en_lo_cnt: value of timing register RDWR_EN_LO_CNT 302 + * @rdwr_en_hi_cnt: value of timing register RDWR_EN_HI_CNT 303 + * @cs_setup_cnt: value of timing register CS_SETUP_CNT 304 + * @re_2_re: value of timing register RE_2_RE 305 + */ 306 + struct denali_chip_sel { 307 + int bank; 308 + u32 hwhr2_and_we_2_re; 309 + u32 tcwaw_and_addr_2_data; 310 + u32 re_2_we; 311 + u32 acc_clks; 312 + u32 rdwr_en_lo_cnt; 313 + u32 rdwr_en_hi_cnt; 314 + u32 cs_setup_cnt; 315 + u32 re_2_re; 316 + }; 317 + 318 + /** 319 + * struct denali_chip - per-chip data of Denali NAND 320 + * 321 + * @chip: base NAND chip structure 322 + * @node: node to be used to associate this chip with the controller 323 + * @nsels: the number of CS lines of this chip 324 + * @sels: the array of per-cs data 325 + */ 326 + struct denali_chip { 327 + struct nand_chip chip; 328 + struct list_head node; 329 + unsigned int nsels; 330 + struct denali_chip_sel sels[0]; 331 + }; 332 + 333 + /** 334 + * struct denali_controller - Denali NAND controller data 335 + * 336 + * @controller: base NAND controller structure 337 + * @dev: device 338 + * @chips: the list of chips attached to this controller 339 + * @clk_rate: frequency of core clock 340 + * @clk_x_rate: frequency of bus interface clock 341 + * @reg: base of Register Interface 342 + * @host: base of Host Data/Command interface 343 + * @complete: completion used to wait for interrupts 344 + * @irq: interrupt number 345 + * @irq_mask: interrupt bits the controller is waiting for 346 + * @irq_status: interrupt bits of events that have happened 347 + * @irq_lock: lock to protect @irq_mask and @irq_status 348 + * @dma_avail: set if DMA engine is available 349 + * @devs_per_cs: number of devices connected in parallel 350 + * @oob_skip_bytes: number of bytes in OOB skipped by the ECC engine 351 + * @active_bank: active bank id 352 + * @nbanks: the number of banks supported by this controller 353 + * @revision: IP revision 354 + * @caps: controller capabilities that cannot be detected run-time 355 + * @ecc_caps: ECC engine capabilities 356 + * @host_read: callback for read access of Host Data/Command Interface 357 + * @host_write: callback for write access of Host Data/Command Interface 358 + * @setup_dma: callback for setup of the Data DMA 359 + */ 360 + struct denali_controller { 361 + struct nand_controller controller; 299 362 struct device *dev; 300 - void __iomem *reg; /* Register Interface */ 301 - void __iomem *host; /* Host Data/Command Interface */ 363 + struct list_head chips; 364 + unsigned long clk_rate; 365 + unsigned long clk_x_rate; 366 + void __iomem *reg; 367 + void __iomem *host; 302 368 struct completion complete; 303 - spinlock_t irq_lock; /* protect irq_mask and irq_status */ 304 - u32 irq_mask; /* interrupts we are waiting for */ 305 - u32 irq_status; /* interrupts that have happened */ 306 369 int irq; 307 - void *buf; /* for syndrome layout conversion */ 308 - int dma_avail; /* can support DMA? */ 309 - int devs_per_cs; /* devices connected in parallel */ 310 - int oob_skip_bytes; /* number of bytes reserved for BBM */ 311 - int max_banks; 312 - unsigned int revision; /* IP revision */ 313 - unsigned int caps; /* IP capability (or quirk) */ 370 + u32 irq_mask; 371 + u32 irq_status; 372 + spinlock_t irq_lock; 373 + bool dma_avail; 374 + int devs_per_cs; 375 + int oob_skip_bytes; 376 + int active_bank; 377 + int nbanks; 378 + unsigned int revision; 379 + unsigned int caps; 314 380 const struct nand_ecc_caps *ecc_caps; 315 - u32 (*host_read)(struct denali_nand_info *denali, u32 addr); 316 - void (*host_write)(struct denali_nand_info *denali, u32 addr, u32 data); 317 - void (*setup_dma)(struct denali_nand_info *denali, dma_addr_t dma_addr, 318 - int page, int write); 381 + u32 (*host_read)(struct denali_controller *denali, u32 addr); 382 + void (*host_write)(struct denali_controller *denali, u32 addr, 383 + u32 data); 384 + void (*setup_dma)(struct denali_controller *denali, dma_addr_t dma_addr, 385 + int page, bool write); 319 386 }; 320 387 321 388 #define DENALI_CAP_HW_ECC_FIXUP BIT(0) 322 389 #define DENALI_CAP_DMA_64BIT BIT(1) 323 390 324 391 int denali_calc_ecc_bytes(int step_size, int strength); 325 - int denali_init(struct denali_nand_info *denali); 326 - void denali_remove(struct denali_nand_info *denali); 392 + int denali_chip_init(struct denali_controller *denali, 393 + struct denali_chip *dchip); 394 + int denali_init(struct denali_controller *denali); 395 + void denali_remove(struct denali_controller *denali); 327 396 328 397 #endif /* __DENALI_H__ */
+94 -4
drivers/mtd/nand/raw/denali_dt.c
··· 18 18 #include "denali.h" 19 19 20 20 struct denali_dt { 21 - struct denali_nand_info denali; 21 + struct denali_controller controller; 22 22 struct clk *clk; /* core clock */ 23 23 struct clk *clk_x; /* bus interface clock */ 24 24 struct clk *clk_ecc; /* ECC circuit clock */ ··· 71 71 }; 72 72 MODULE_DEVICE_TABLE(of, denali_nand_dt_ids); 73 73 74 + static int denali_dt_chip_init(struct denali_controller *denali, 75 + struct device_node *chip_np) 76 + { 77 + struct denali_chip *dchip; 78 + u32 bank; 79 + int nsels, i, ret; 80 + 81 + nsels = of_property_count_u32_elems(chip_np, "reg"); 82 + if (nsels < 0) 83 + return nsels; 84 + 85 + dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels), 86 + GFP_KERNEL); 87 + if (!dchip) 88 + return -ENOMEM; 89 + 90 + dchip->nsels = nsels; 91 + 92 + for (i = 0; i < nsels; i++) { 93 + ret = of_property_read_u32_index(chip_np, "reg", i, &bank); 94 + if (ret) 95 + return ret; 96 + 97 + dchip->sels[i].bank = bank; 98 + 99 + nand_set_flash_node(&dchip->chip, chip_np); 100 + } 101 + 102 + return denali_chip_init(denali, dchip); 103 + } 104 + 105 + /* Backward compatibility for old platforms */ 106 + static int denali_dt_legacy_chip_init(struct denali_controller *denali) 107 + { 108 + struct denali_chip *dchip; 109 + int nsels, i; 110 + 111 + nsels = denali->nbanks; 112 + 113 + dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels), 114 + GFP_KERNEL); 115 + if (!dchip) 116 + return -ENOMEM; 117 + 118 + dchip->nsels = nsels; 119 + 120 + for (i = 0; i < nsels; i++) 121 + dchip->sels[i].bank = i; 122 + 123 + nand_set_flash_node(&dchip->chip, denali->dev->of_node); 124 + 125 + return denali_chip_init(denali, dchip); 126 + } 127 + 128 + /* 129 + * Check the DT binding. 130 + * The new binding expects chip subnodes in the controller node. 131 + * So, #address-cells = <1>; #size-cells = <0>; are required. 132 + * Check the #size-cells to distinguish the binding. 133 + */ 134 + static bool denali_dt_is_legacy_binding(struct device_node *np) 135 + { 136 + u32 cells; 137 + int ret; 138 + 139 + ret = of_property_read_u32(np, "#size-cells", &cells); 140 + if (ret) 141 + return true; 142 + 143 + return cells != 0; 144 + } 145 + 74 146 static int denali_dt_probe(struct platform_device *pdev) 75 147 { 76 148 struct device *dev = &pdev->dev; 77 149 struct resource *res; 78 150 struct denali_dt *dt; 79 151 const struct denali_dt_data *data; 80 - struct denali_nand_info *denali; 152 + struct denali_controller *denali; 153 + struct device_node *np; 81 154 int ret; 82 155 83 156 dt = devm_kzalloc(dev, sizeof(*dt), GFP_KERNEL); 84 157 if (!dt) 85 158 return -ENOMEM; 86 - denali = &dt->denali; 159 + denali = &dt->controller; 87 160 88 161 data = of_device_get_match_data(dev); 89 162 if (data) { ··· 213 140 if (ret) 214 141 goto out_disable_clk_ecc; 215 142 143 + if (denali_dt_is_legacy_binding(dev->of_node)) { 144 + ret = denali_dt_legacy_chip_init(denali); 145 + if (ret) 146 + goto out_remove_denali; 147 + } else { 148 + for_each_child_of_node(dev->of_node, np) { 149 + ret = denali_dt_chip_init(denali, np); 150 + if (ret) { 151 + of_node_put(np); 152 + goto out_remove_denali; 153 + } 154 + } 155 + } 156 + 216 157 platform_set_drvdata(pdev, dt); 158 + 217 159 return 0; 218 160 161 + out_remove_denali: 162 + denali_remove(denali); 219 163 out_disable_clk_ecc: 220 164 clk_disable_unprepare(dt->clk_ecc); 221 165 out_disable_clk_x: ··· 247 157 { 248 158 struct denali_dt *dt = platform_get_drvdata(pdev); 249 159 250 - denali_remove(&dt->denali); 160 + denali_remove(&dt->controller); 251 161 clk_disable_unprepare(dt->clk_ecc); 252 162 clk_disable_unprepare(dt->clk_x); 253 163 clk_disable_unprepare(dt->clk);
+30 -8
drivers/mtd/nand/raw/denali_pci.c
··· 29 29 30 30 static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) 31 31 { 32 - int ret; 33 32 resource_size_t csr_base, mem_base; 34 33 unsigned long csr_len, mem_len; 35 - struct denali_nand_info *denali; 34 + struct denali_controller *denali; 35 + struct denali_chip *dchip; 36 + int nsels, ret, i; 36 37 37 38 denali = devm_kzalloc(&dev->dev, sizeof(*denali), GFP_KERNEL); 38 39 if (!denali) ··· 65 64 denali->dev = &dev->dev; 66 65 denali->irq = dev->irq; 67 66 denali->ecc_caps = &denali_pci_ecc_caps; 68 - denali->nand.ecc.options |= NAND_ECC_MAXIMIZE; 69 67 denali->clk_rate = 50000000; /* 50 MHz */ 70 68 denali->clk_x_rate = 200000000; /* 200 MHz */ 71 69 ··· 84 84 if (!denali->host) { 85 85 dev_err(&dev->dev, "Spectra: ioremap_nocache failed!"); 86 86 ret = -ENOMEM; 87 - goto failed_remap_reg; 87 + goto out_unmap_reg; 88 88 } 89 89 90 90 ret = denali_init(denali); 91 91 if (ret) 92 - goto failed_remap_mem; 92 + goto out_unmap_host; 93 + 94 + nsels = denali->nbanks; 95 + 96 + dchip = devm_kzalloc(denali->dev, struct_size(dchip, sels, nsels), 97 + GFP_KERNEL); 98 + if (!dchip) { 99 + ret = -ENOMEM; 100 + goto out_remove_denali; 101 + } 102 + 103 + dchip->chip.ecc.options |= NAND_ECC_MAXIMIZE; 104 + 105 + dchip->nsels = nsels; 106 + 107 + for (i = 0; i < nsels; i++) 108 + dchip->sels[i].bank = i; 109 + 110 + ret = denali_chip_init(denali, dchip); 111 + if (ret) 112 + goto out_remove_denali; 93 113 94 114 pci_set_drvdata(dev, denali); 95 115 96 116 return 0; 97 117 98 - failed_remap_mem: 118 + out_remove_denali: 119 + denali_remove(denali); 120 + out_unmap_host: 99 121 iounmap(denali->host); 100 - failed_remap_reg: 122 + out_unmap_reg: 101 123 iounmap(denali->reg); 102 124 return ret; 103 125 } 104 126 105 127 static void denali_pci_remove(struct pci_dev *dev) 106 128 { 107 - struct denali_nand_info *denali = pci_get_drvdata(dev); 129 + struct denali_controller *denali = pci_get_drvdata(dev); 108 130 109 131 denali_remove(denali); 110 132 iounmap(denali->reg);
+6 -1
drivers/mtd/nand/raw/diskonchip.c
··· 1028 1028 { 1029 1029 struct nand_chip *this = mtd_to_nand(mtd); 1030 1030 struct doc_priv *doc = nand_get_controller_data(this); 1031 + struct nand_memory_organization *memorg; 1031 1032 int ret = 0; 1032 1033 u_char *buf; 1033 1034 struct NFTLMediaHeader *mh; ··· 1036 1035 int numparts = 0; 1037 1036 unsigned blocks, maxblocks; 1038 1037 int offs, numheaders; 1038 + 1039 + memorg = nanddev_get_memorg(&this->base); 1039 1040 1040 1041 buf = kmalloc(mtd->writesize, GFP_KERNEL); 1041 1042 if (!buf) { ··· 1085 1082 implementation of the NAND layer. */ 1086 1083 if (mh->UnitSizeFactor != 0xff) { 1087 1084 this->bbt_erase_shift += (0xff - mh->UnitSizeFactor); 1085 + memorg->pages_per_eraseblock <<= (0xff - mh->UnitSizeFactor); 1088 1086 mtd->erasesize <<= (0xff - mh->UnitSizeFactor); 1089 1087 pr_info("Setting virtual erase size to %d\n", mtd->erasesize); 1090 1088 blocks = mtd->size >> this->bbt_erase_shift; ··· 1291 1287 struct doc_priv *doc = nand_get_controller_data(this); 1292 1288 struct mtd_partition parts[5]; 1293 1289 1294 - if (this->numchips > doc->chips_per_floor) { 1290 + if (nanddev_ntargets(&this->base) > doc->chips_per_floor) { 1295 1291 pr_err("Multi-floor INFTL devices not yet supported.\n"); 1296 1292 return -EIO; 1297 1293 } ··· 1481 1477 break; 1482 1478 case DOC_ChipID_DocMilPlus32: 1483 1479 pr_err("DiskOnChip Millennium Plus 32MB is not supported, ignoring.\n"); 1480 + /* fall through */ 1484 1481 default: 1485 1482 ret = -ENODEV; 1486 1483 goto notfound;
+112 -87
drivers/mtd/nand/raw/fsl_elbc_nand.c
··· 355 355 fsl_elbc_run_command(mtd); 356 356 return; 357 357 358 + /* RNDOUT moves the pointer inside the page */ 359 + case NAND_CMD_RNDOUT: 360 + dev_dbg(priv->dev, 361 + "fsl_elbc_cmdfunc: NAND_CMD_RNDOUT, column: 0x%x.\n", 362 + column); 363 + 364 + elbc_fcm_ctrl->index = column; 365 + return; 366 + 358 367 /* READOOB reads only the OOB because no ECC is performed. */ 359 368 case NAND_CMD_READOOB: 360 369 dev_vdbg(priv->dev, ··· 644 635 return (elbc_fcm_ctrl->mdr & 0xff) | NAND_STATUS_WP; 645 636 } 646 637 647 - static int fsl_elbc_attach_chip(struct nand_chip *chip) 648 - { 649 - struct mtd_info *mtd = nand_to_mtd(chip); 650 - struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 651 - struct fsl_lbc_ctrl *ctrl = priv->ctrl; 652 - struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 653 - unsigned int al; 654 - 655 - /* calculate FMR Address Length field */ 656 - al = 0; 657 - if (chip->pagemask & 0xffff0000) 658 - al++; 659 - if (chip->pagemask & 0xff000000) 660 - al++; 661 - 662 - priv->fmr |= al << FMR_AL_SHIFT; 663 - 664 - dev_dbg(priv->dev, "fsl_elbc_init: nand->numchips = %d\n", 665 - chip->numchips); 666 - dev_dbg(priv->dev, "fsl_elbc_init: nand->chipsize = %lld\n", 667 - chip->chipsize); 668 - dev_dbg(priv->dev, "fsl_elbc_init: nand->pagemask = %8x\n", 669 - chip->pagemask); 670 - dev_dbg(priv->dev, "fsl_elbc_init: nand->legacy.chip_delay = %d\n", 671 - chip->legacy.chip_delay); 672 - dev_dbg(priv->dev, "fsl_elbc_init: nand->badblockpos = %d\n", 673 - chip->badblockpos); 674 - dev_dbg(priv->dev, "fsl_elbc_init: nand->chip_shift = %d\n", 675 - chip->chip_shift); 676 - dev_dbg(priv->dev, "fsl_elbc_init: nand->page_shift = %d\n", 677 - chip->page_shift); 678 - dev_dbg(priv->dev, "fsl_elbc_init: nand->phys_erase_shift = %d\n", 679 - chip->phys_erase_shift); 680 - dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.mode = %d\n", 681 - chip->ecc.mode); 682 - dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.steps = %d\n", 683 - chip->ecc.steps); 684 - dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.bytes = %d\n", 685 - chip->ecc.bytes); 686 - dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.total = %d\n", 687 - chip->ecc.total); 688 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->ooblayout = %p\n", 689 - mtd->ooblayout); 690 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->flags = %08x\n", mtd->flags); 691 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->size = %lld\n", mtd->size); 692 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->erasesize = %d\n", 693 - mtd->erasesize); 694 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->writesize = %d\n", 695 - mtd->writesize); 696 - dev_dbg(priv->dev, "fsl_elbc_init: mtd->oobsize = %d\n", 697 - mtd->oobsize); 698 - 699 - /* adjust Option Register and ECC to match Flash page size */ 700 - if (mtd->writesize == 512) { 701 - priv->page_size = 0; 702 - clrbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 703 - } else if (mtd->writesize == 2048) { 704 - priv->page_size = 1; 705 - setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 706 - } else { 707 - dev_err(priv->dev, 708 - "fsl_elbc_init: page size %d is not supported\n", 709 - mtd->writesize); 710 - return -ENOTSUPP; 711 - } 712 - 713 - return 0; 714 - } 715 - 716 - static const struct nand_controller_ops fsl_elbc_controller_ops = { 717 - .attach_chip = fsl_elbc_attach_chip, 718 - }; 719 - 720 638 static int fsl_elbc_read_page(struct nand_chip *chip, uint8_t *buf, 721 639 int oob_required, int page) 722 640 { ··· 730 794 chip->controller = &elbc_fcm_ctrl->controller; 731 795 nand_set_controller_data(chip, priv); 732 796 733 - chip->ecc.read_page = fsl_elbc_read_page; 734 - chip->ecc.write_page = fsl_elbc_write_page; 735 - chip->ecc.write_subpage = fsl_elbc_write_subpage; 797 + return 0; 798 + } 736 799 737 - /* If CS Base Register selects full hardware ECC then use it */ 738 - if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) == 739 - BR_DECC_CHK_GEN) { 740 - chip->ecc.mode = NAND_ECC_HW; 741 - mtd_set_ooblayout(mtd, &fsl_elbc_ooblayout_ops); 742 - chip->ecc.size = 512; 743 - chip->ecc.bytes = 3; 744 - chip->ecc.strength = 1; 800 + static int fsl_elbc_attach_chip(struct nand_chip *chip) 801 + { 802 + struct mtd_info *mtd = nand_to_mtd(chip); 803 + struct fsl_elbc_mtd *priv = nand_get_controller_data(chip); 804 + struct fsl_lbc_ctrl *ctrl = priv->ctrl; 805 + struct fsl_lbc_regs __iomem *lbc = ctrl->regs; 806 + unsigned int al; 807 + 808 + switch (chip->ecc.mode) { 809 + /* 810 + * if ECC was not chosen in DT, decide whether to use HW or SW ECC from 811 + * CS Base Register 812 + */ 813 + case NAND_ECC_NONE: 814 + /* If CS Base Register selects full hardware ECC then use it */ 815 + if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) == 816 + BR_DECC_CHK_GEN) { 817 + chip->ecc.read_page = fsl_elbc_read_page; 818 + chip->ecc.write_page = fsl_elbc_write_page; 819 + chip->ecc.write_subpage = fsl_elbc_write_subpage; 820 + 821 + chip->ecc.mode = NAND_ECC_HW; 822 + mtd_set_ooblayout(mtd, &fsl_elbc_ooblayout_ops); 823 + chip->ecc.size = 512; 824 + chip->ecc.bytes = 3; 825 + chip->ecc.strength = 1; 826 + } else { 827 + /* otherwise fall back to default software ECC */ 828 + chip->ecc.mode = NAND_ECC_SOFT; 829 + chip->ecc.algo = NAND_ECC_HAMMING; 830 + } 831 + break; 832 + 833 + /* if SW ECC was chosen in DT, we do not need to set anything here */ 834 + case NAND_ECC_SOFT: 835 + break; 836 + 837 + /* should we also implement NAND_ECC_HW to do as the code above? */ 838 + default: 839 + return -EINVAL; 840 + } 841 + 842 + /* calculate FMR Address Length field */ 843 + al = 0; 844 + if (chip->pagemask & 0xffff0000) 845 + al++; 846 + if (chip->pagemask & 0xff000000) 847 + al++; 848 + 849 + priv->fmr |= al << FMR_AL_SHIFT; 850 + 851 + dev_dbg(priv->dev, "fsl_elbc_init: nand->numchips = %d\n", 852 + nanddev_ntargets(&chip->base)); 853 + dev_dbg(priv->dev, "fsl_elbc_init: nand->chipsize = %lld\n", 854 + nanddev_target_size(&chip->base)); 855 + dev_dbg(priv->dev, "fsl_elbc_init: nand->pagemask = %8x\n", 856 + chip->pagemask); 857 + dev_dbg(priv->dev, "fsl_elbc_init: nand->legacy.chip_delay = %d\n", 858 + chip->legacy.chip_delay); 859 + dev_dbg(priv->dev, "fsl_elbc_init: nand->badblockpos = %d\n", 860 + chip->badblockpos); 861 + dev_dbg(priv->dev, "fsl_elbc_init: nand->chip_shift = %d\n", 862 + chip->chip_shift); 863 + dev_dbg(priv->dev, "fsl_elbc_init: nand->page_shift = %d\n", 864 + chip->page_shift); 865 + dev_dbg(priv->dev, "fsl_elbc_init: nand->phys_erase_shift = %d\n", 866 + chip->phys_erase_shift); 867 + dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.mode = %d\n", 868 + chip->ecc.mode); 869 + dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.steps = %d\n", 870 + chip->ecc.steps); 871 + dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.bytes = %d\n", 872 + chip->ecc.bytes); 873 + dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.total = %d\n", 874 + chip->ecc.total); 875 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->ooblayout = %p\n", 876 + mtd->ooblayout); 877 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->flags = %08x\n", mtd->flags); 878 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->size = %lld\n", mtd->size); 879 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->erasesize = %d\n", 880 + mtd->erasesize); 881 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->writesize = %d\n", 882 + mtd->writesize); 883 + dev_dbg(priv->dev, "fsl_elbc_init: mtd->oobsize = %d\n", 884 + mtd->oobsize); 885 + 886 + /* adjust Option Register and ECC to match Flash page size */ 887 + if (mtd->writesize == 512) { 888 + priv->page_size = 0; 889 + clrbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 890 + } else if (mtd->writesize == 2048) { 891 + priv->page_size = 1; 892 + setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 745 893 } else { 746 - /* otherwise fall back to default software ECC */ 747 - chip->ecc.mode = NAND_ECC_SOFT; 748 - chip->ecc.algo = NAND_ECC_HAMMING; 894 + dev_err(priv->dev, 895 + "fsl_elbc_init: page size %d is not supported\n", 896 + mtd->writesize); 897 + return -ENOTSUPP; 749 898 } 750 899 751 900 return 0; 752 901 } 902 + 903 + static const struct nand_controller_ops fsl_elbc_controller_ops = { 904 + .attach_chip = fsl_elbc_attach_chip, 905 + }; 753 906 754 907 static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv) 755 908 {
+2 -2
drivers/mtd/nand/raw/fsl_ifc_nand.c
··· 722 722 struct fsl_ifc_mtd *priv = nand_get_controller_data(chip); 723 723 724 724 dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__, 725 - chip->numchips); 725 + nanddev_ntargets(&chip->base)); 726 726 dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__, 727 - chip->chipsize); 727 + nanddev_target_size(&chip->base)); 728 728 dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__, 729 729 chip->pagemask); 730 730 dev_dbg(priv->dev, "%s: nand->legacy.chip_delay = %d\n", __func__,
+2 -4
drivers/mtd/nand/raw/gpmi-nand/gpmi-lib.c
··· 157 157 * Reset BCH here, too. We got failures otherwise :( 158 158 * See later BCH reset for explanation of MX23 and MX28 handling 159 159 */ 160 - ret = gpmi_reset_block(r->bch_regs, 161 - GPMI_IS_MX23(this) || GPMI_IS_MX28(this)); 160 + ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); 162 161 if (ret) 163 162 goto err_out; 164 163 ··· 265 266 * chip, otherwise it will lock up. So we skip resetting BCH on the MX23. 266 267 * and MX28. 267 268 */ 268 - ret = gpmi_reset_block(r->bch_regs, 269 - GPMI_IS_MX23(this) || GPMI_IS_MX28(this)); 269 + ret = gpmi_reset_block(r->bch_regs, GPMI_IS_MXS(this)); 270 270 if (ret) 271 271 goto err_out; 272 272
+11 -8
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
··· 171 171 struct bch_geometry *geo = &this->bch_geometry; 172 172 173 173 /* Do the sanity check. */ 174 - if (GPMI_IS_MX23(this) || GPMI_IS_MX28(this)) { 174 + if (GPMI_IS_MXS(this)) { 175 175 /* The mx23/mx28 only support the GF13. */ 176 176 if (geo->gf_len == 14) 177 177 return false; ··· 204 204 default: 205 205 dev_err(this->dev, 206 206 "unsupported nand chip. ecc bits : %d, ecc size : %d\n", 207 - chip->ecc_strength_ds, chip->ecc_step_ds); 207 + chip->base.eccreq.strength, 208 + chip->base.eccreq.step_size); 208 209 return -EINVAL; 209 210 } 210 211 geo->ecc_chunk_size = ecc_step; ··· 418 417 419 418 if ((of_property_read_bool(this->dev->of_node, "fsl,use-minimum-ecc")) 420 419 || legacy_set_geometry(this)) { 421 - if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) 420 + if (!(chip->base.eccreq.strength > 0 && 421 + chip->base.eccreq.step_size > 0)) 422 422 return -EINVAL; 423 423 424 - return set_geometry_by_ecc_info(this, chip->ecc_strength_ds, 425 - chip->ecc_step_ds); 424 + return set_geometry_by_ecc_info(this, 425 + chip->base.eccreq.strength, 426 + chip->base.eccreq.step_size); 426 427 } 427 428 428 429 return 0; ··· 1605 1602 unsigned int search_area_size_in_strides; 1606 1603 unsigned int stride; 1607 1604 unsigned int page; 1608 - uint8_t *buffer = chip->data_buf; 1605 + u8 *buffer = nand_get_data_buf(chip); 1609 1606 int saved_chip_number; 1610 1607 int found_an_ncb_fingerprint = false; 1611 1608 ··· 1667 1664 unsigned int block; 1668 1665 unsigned int stride; 1669 1666 unsigned int page; 1670 - uint8_t *buffer = chip->data_buf; 1667 + u8 *buffer = nand_get_data_buf(chip); 1671 1668 int saved_chip_number; 1672 1669 int status; 1673 1670 ··· 1756 1753 dev_dbg(dev, "Transcribing bad block marks...\n"); 1757 1754 1758 1755 /* Compute the number of blocks in the entire medium. */ 1759 - block_count = chip->chipsize >> chip->phys_erase_shift; 1756 + block_count = nanddev_eraseblocks_per_target(&chip->base); 1760 1757 1761 1758 /* 1762 1759 * Loop over all the blocks in the medium, transcribing block marks as
+1
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h
··· 207 207 208 208 #define GPMI_IS_MX6(x) (GPMI_IS_MX6Q(x) || GPMI_IS_MX6SX(x) || \ 209 209 GPMI_IS_MX7D(x)) 210 + #define GPMI_IS_MXS(x) (GPMI_IS_MX23(x) || GPMI_IS_MX28(x)) 210 211 #endif
+1 -1
drivers/mtd/nand/raw/hisi504_nand.c
··· 849 849 struct hinfc_host *host = dev_get_drvdata(dev); 850 850 struct nand_chip *chip = &host->chip; 851 851 852 - for (cs = 0; cs < chip->numchips; cs++) 852 + for (cs = 0; cs < nanddev_ntargets(&chip->base); cs++) 853 853 hisi_nfc_send_cmd_reset(host, cs); 854 854 hinfc_write(host, SET_HINFC504_PWIDTH(HINFC504_W_LATCH, 855 855 HINFC504_R_LATCH, HINFC504_RW_LATCH), HINFC504_PWIDTH);
+50
drivers/mtd/nand/raw/ingenic/Kconfig
··· 1 + config MTD_NAND_JZ4740 2 + tristate "JZ4740 NAND controller" 3 + depends on MACH_JZ4740 || COMPILE_TEST 4 + depends on HAS_IOMEM 5 + help 6 + Enables support for NAND Flash on JZ4740 SoC based boards. 7 + 8 + config MTD_NAND_JZ4780 9 + tristate "JZ4780 NAND controller" 10 + depends on JZ4780_NEMC 11 + help 12 + Enables support for NAND Flash connected to the NEMC on JZ4780 SoC 13 + based boards, using the BCH controller for hardware error correction. 14 + 15 + if MTD_NAND_JZ4780 16 + 17 + config MTD_NAND_INGENIC_ECC 18 + tristate 19 + 20 + config MTD_NAND_JZ4740_ECC 21 + tristate "Hardware BCH support for JZ4740 SoC" 22 + select MTD_NAND_INGENIC_ECC 23 + help 24 + Enable this driver to support the Reed-Solomon error-correction 25 + hardware present on the JZ4740 SoC from Ingenic. 26 + 27 + This driver can also be built as a module. If so, the module 28 + will be called jz4740-ecc. 29 + 30 + config MTD_NAND_JZ4725B_BCH 31 + tristate "Hardware BCH support for JZ4725B SoC" 32 + select MTD_NAND_INGENIC_ECC 33 + help 34 + Enable this driver to support the BCH error-correction hardware 35 + present on the JZ4725B SoC from Ingenic. 36 + 37 + This driver can also be built as a module. If so, the module 38 + will be called jz4725b-bch. 39 + 40 + config MTD_NAND_JZ4780_BCH 41 + tristate "Hardware BCH support for JZ4780 SoC" 42 + select MTD_NAND_INGENIC_ECC 43 + help 44 + Enable this driver to support the BCH error-correction hardware 45 + present on the JZ4780 SoC from Ingenic. 46 + 47 + This driver can also be built as a module. If so, the module 48 + will be called jz4780-bch. 49 + 50 + endif # MTD_NAND_JZ4780
+7
drivers/mtd/nand/raw/ingenic/Makefile
··· 1 + obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o 2 + obj-$(CONFIG_MTD_NAND_JZ4780) += ingenic_nand.o 3 + 4 + obj-$(CONFIG_MTD_NAND_INGENIC_ECC) += ingenic_ecc.o 5 + obj-$(CONFIG_MTD_NAND_JZ4740_ECC) += jz4740_ecc.o 6 + obj-$(CONFIG_MTD_NAND_JZ4725B_BCH) += jz4725b_bch.o 7 + obj-$(CONFIG_MTD_NAND_JZ4780_BCH) += jz4780_bch.o
+166
drivers/mtd/nand/raw/ingenic/ingenic_ecc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * JZ47xx ECC common code 4 + * 5 + * Copyright (c) 2015 Imagination Technologies 6 + * Author: Alex Smith <alex.smith@imgtec.com> 7 + */ 8 + 9 + #include <linux/clk.h> 10 + #include <linux/init.h> 11 + #include <linux/module.h> 12 + #include <linux/of_platform.h> 13 + #include <linux/platform_device.h> 14 + 15 + #include "ingenic_ecc.h" 16 + 17 + /** 18 + * ingenic_ecc_calculate() - calculate ECC for a data buffer 19 + * @ecc: ECC device. 20 + * @params: ECC parameters. 21 + * @buf: input buffer with raw data. 22 + * @ecc_code: output buffer with ECC. 23 + * 24 + * Return: 0 on success, -ETIMEDOUT if timed out while waiting for ECC 25 + * controller. 26 + */ 27 + int ingenic_ecc_calculate(struct ingenic_ecc *ecc, 28 + struct ingenic_ecc_params *params, 29 + const u8 *buf, u8 *ecc_code) 30 + { 31 + return ecc->ops->calculate(ecc, params, buf, ecc_code); 32 + } 33 + EXPORT_SYMBOL(ingenic_ecc_calculate); 34 + 35 + /** 36 + * ingenic_ecc_correct() - detect and correct bit errors 37 + * @ecc: ECC device. 38 + * @params: ECC parameters. 39 + * @buf: raw data read from the chip. 40 + * @ecc_code: ECC read from the chip. 41 + * 42 + * Given the raw data and the ECC read from the NAND device, detects and 43 + * corrects errors in the data. 44 + * 45 + * Return: the number of bit errors corrected, -EBADMSG if there are too many 46 + * errors to correct or -ETIMEDOUT if we timed out waiting for the controller. 47 + */ 48 + int ingenic_ecc_correct(struct ingenic_ecc *ecc, 49 + struct ingenic_ecc_params *params, 50 + u8 *buf, u8 *ecc_code) 51 + { 52 + return ecc->ops->correct(ecc, params, buf, ecc_code); 53 + } 54 + EXPORT_SYMBOL(ingenic_ecc_correct); 55 + 56 + /** 57 + * ingenic_ecc_get() - get the ECC controller device 58 + * @np: ECC device tree node. 59 + * 60 + * Gets the ECC controller device from the specified device tree node. The 61 + * device must be released with ingenic_ecc_release() when it is no longer being 62 + * used. 63 + * 64 + * Return: a pointer to ingenic_ecc, errors are encoded into the pointer. 65 + * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 66 + */ 67 + static struct ingenic_ecc *ingenic_ecc_get(struct device_node *np) 68 + { 69 + struct platform_device *pdev; 70 + struct ingenic_ecc *ecc; 71 + 72 + pdev = of_find_device_by_node(np); 73 + if (!pdev || !platform_get_drvdata(pdev)) 74 + return ERR_PTR(-EPROBE_DEFER); 75 + 76 + get_device(&pdev->dev); 77 + 78 + ecc = platform_get_drvdata(pdev); 79 + clk_prepare_enable(ecc->clk); 80 + 81 + return ecc; 82 + } 83 + 84 + /** 85 + * of_ingenic_ecc_get() - get the ECC controller from a DT node 86 + * @of_node: the node that contains an ecc-engine property. 87 + * 88 + * Get the ecc-engine property from the given device tree 89 + * node and pass it to ingenic_ecc_get to do the work. 90 + * 91 + * Return: a pointer to ingenic_ecc, errors are encoded into the pointer. 92 + * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 93 + */ 94 + struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *of_node) 95 + { 96 + struct ingenic_ecc *ecc = NULL; 97 + struct device_node *np; 98 + 99 + np = of_parse_phandle(of_node, "ecc-engine", 0); 100 + 101 + /* 102 + * If the ecc-engine property is not found, check for the deprecated 103 + * ingenic,bch-controller property 104 + */ 105 + if (!np) 106 + np = of_parse_phandle(of_node, "ingenic,bch-controller", 0); 107 + 108 + if (np) { 109 + ecc = ingenic_ecc_get(np); 110 + of_node_put(np); 111 + } 112 + return ecc; 113 + } 114 + EXPORT_SYMBOL(of_ingenic_ecc_get); 115 + 116 + /** 117 + * ingenic_ecc_release() - release the ECC controller device 118 + * @ecc: ECC device. 119 + */ 120 + void ingenic_ecc_release(struct ingenic_ecc *ecc) 121 + { 122 + clk_disable_unprepare(ecc->clk); 123 + put_device(ecc->dev); 124 + } 125 + EXPORT_SYMBOL(ingenic_ecc_release); 126 + 127 + int ingenic_ecc_probe(struct platform_device *pdev) 128 + { 129 + struct device *dev = &pdev->dev; 130 + struct ingenic_ecc *ecc; 131 + struct resource *res; 132 + 133 + ecc = devm_kzalloc(dev, sizeof(*ecc), GFP_KERNEL); 134 + if (!ecc) 135 + return -ENOMEM; 136 + 137 + ecc->ops = device_get_match_data(dev); 138 + if (!ecc->ops) 139 + return -EINVAL; 140 + 141 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 142 + ecc->base = devm_ioremap_resource(dev, res); 143 + if (IS_ERR(ecc->base)) 144 + return PTR_ERR(ecc->base); 145 + 146 + ecc->ops->disable(ecc); 147 + 148 + ecc->clk = devm_clk_get(dev, NULL); 149 + if (IS_ERR(ecc->clk)) { 150 + dev_err(dev, "failed to get clock: %ld\n", PTR_ERR(ecc->clk)); 151 + return PTR_ERR(ecc->clk); 152 + } 153 + 154 + mutex_init(&ecc->lock); 155 + 156 + ecc->dev = dev; 157 + platform_set_drvdata(pdev, ecc); 158 + 159 + return 0; 160 + } 161 + EXPORT_SYMBOL(ingenic_ecc_probe); 162 + 163 + MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); 164 + MODULE_AUTHOR("Harvey Hunt <harveyhuntnexus@gmail.com>"); 165 + MODULE_DESCRIPTION("Ingenic ECC common driver"); 166 + MODULE_LICENSE("GPL v2");
+83
drivers/mtd/nand/raw/ingenic/ingenic_ecc.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__ 3 + #define __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__ 4 + 5 + #include <linux/compiler_types.h> 6 + #include <linux/err.h> 7 + #include <linux/mutex.h> 8 + #include <linux/types.h> 9 + #include <uapi/asm-generic/errno-base.h> 10 + 11 + struct clk; 12 + struct device; 13 + struct ingenic_ecc; 14 + struct platform_device; 15 + 16 + /** 17 + * struct ingenic_ecc_params - ECC parameters 18 + * @size: data bytes per ECC step. 19 + * @bytes: ECC bytes per step. 20 + * @strength: number of correctable bits per ECC step. 21 + */ 22 + struct ingenic_ecc_params { 23 + int size; 24 + int bytes; 25 + int strength; 26 + }; 27 + 28 + #if IS_ENABLED(CONFIG_MTD_NAND_INGENIC_ECC) 29 + int ingenic_ecc_calculate(struct ingenic_ecc *ecc, 30 + struct ingenic_ecc_params *params, 31 + const u8 *buf, u8 *ecc_code); 32 + int ingenic_ecc_correct(struct ingenic_ecc *ecc, 33 + struct ingenic_ecc_params *params, u8 *buf, 34 + u8 *ecc_code); 35 + 36 + void ingenic_ecc_release(struct ingenic_ecc *ecc); 37 + struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *np); 38 + #else /* CONFIG_MTD_NAND_INGENIC_ECC */ 39 + int ingenic_ecc_calculate(struct ingenic_ecc *ecc, 40 + struct ingenic_ecc_params *params, 41 + const u8 *buf, u8 *ecc_code) 42 + { 43 + return -ENODEV; 44 + } 45 + 46 + int ingenic_ecc_correct(struct ingenic_ecc *ecc, 47 + struct ingenic_ecc_params *params, u8 *buf, 48 + u8 *ecc_code) 49 + { 50 + return -ENODEV; 51 + } 52 + 53 + void ingenic_ecc_release(struct ingenic_ecc *ecc) 54 + { 55 + } 56 + 57 + struct ingenic_ecc *of_ingenic_ecc_get(struct device_node *np) 58 + { 59 + return ERR_PTR(-ENODEV); 60 + } 61 + #endif /* CONFIG_MTD_NAND_INGENIC_ECC */ 62 + 63 + struct ingenic_ecc_ops { 64 + void (*disable)(struct ingenic_ecc *ecc); 65 + int (*calculate)(struct ingenic_ecc *ecc, 66 + struct ingenic_ecc_params *params, 67 + const u8 *buf, u8 *ecc_code); 68 + int (*correct)(struct ingenic_ecc *ecc, 69 + struct ingenic_ecc_params *params, 70 + u8 *buf, u8 *ecc_code); 71 + }; 72 + 73 + struct ingenic_ecc { 74 + struct device *dev; 75 + const struct ingenic_ecc_ops *ops; 76 + void __iomem *base; 77 + struct clk *clk; 78 + struct mutex lock; 79 + }; 80 + 81 + int ingenic_ecc_probe(struct platform_device *pdev); 82 + 83 + #endif /* __DRIVERS_MTD_NAND_INGENIC_ECC_INTERNAL_H__ */
+530
drivers/mtd/nand/raw/ingenic/ingenic_nand.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Ingenic JZ47xx NAND driver 4 + * 5 + * Copyright (c) 2015 Imagination Technologies 6 + * Author: Alex Smith <alex.smith@imgtec.com> 7 + */ 8 + 9 + #include <linux/delay.h> 10 + #include <linux/init.h> 11 + #include <linux/io.h> 12 + #include <linux/list.h> 13 + #include <linux/module.h> 14 + #include <linux/of.h> 15 + #include <linux/of_address.h> 16 + #include <linux/of_device.h> 17 + #include <linux/gpio/consumer.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/slab.h> 20 + #include <linux/mtd/mtd.h> 21 + #include <linux/mtd/rawnand.h> 22 + #include <linux/mtd/partitions.h> 23 + 24 + #include <linux/jz4780-nemc.h> 25 + 26 + #include "ingenic_ecc.h" 27 + 28 + #define DRV_NAME "ingenic-nand" 29 + 30 + /* Command delay when there is no R/B pin. */ 31 + #define RB_DELAY_US 100 32 + 33 + struct jz_soc_info { 34 + unsigned long data_offset; 35 + unsigned long addr_offset; 36 + unsigned long cmd_offset; 37 + const struct mtd_ooblayout_ops *oob_layout; 38 + }; 39 + 40 + struct ingenic_nand_cs { 41 + unsigned int bank; 42 + void __iomem *base; 43 + }; 44 + 45 + struct ingenic_nfc { 46 + struct device *dev; 47 + struct ingenic_ecc *ecc; 48 + const struct jz_soc_info *soc_info; 49 + struct nand_controller controller; 50 + unsigned int num_banks; 51 + struct list_head chips; 52 + int selected; 53 + struct ingenic_nand_cs cs[]; 54 + }; 55 + 56 + struct ingenic_nand { 57 + struct nand_chip chip; 58 + struct list_head chip_list; 59 + 60 + struct gpio_desc *busy_gpio; 61 + struct gpio_desc *wp_gpio; 62 + unsigned int reading: 1; 63 + }; 64 + 65 + static inline struct ingenic_nand *to_ingenic_nand(struct mtd_info *mtd) 66 + { 67 + return container_of(mtd_to_nand(mtd), struct ingenic_nand, chip); 68 + } 69 + 70 + static inline struct ingenic_nfc *to_ingenic_nfc(struct nand_controller *ctrl) 71 + { 72 + return container_of(ctrl, struct ingenic_nfc, controller); 73 + } 74 + 75 + static int qi_lb60_ooblayout_ecc(struct mtd_info *mtd, int section, 76 + struct mtd_oob_region *oobregion) 77 + { 78 + struct nand_chip *chip = mtd_to_nand(mtd); 79 + struct nand_ecc_ctrl *ecc = &chip->ecc; 80 + 81 + if (section || !ecc->total) 82 + return -ERANGE; 83 + 84 + oobregion->length = ecc->total; 85 + oobregion->offset = 12; 86 + 87 + return 0; 88 + } 89 + 90 + static int qi_lb60_ooblayout_free(struct mtd_info *mtd, int section, 91 + struct mtd_oob_region *oobregion) 92 + { 93 + struct nand_chip *chip = mtd_to_nand(mtd); 94 + struct nand_ecc_ctrl *ecc = &chip->ecc; 95 + 96 + if (section) 97 + return -ERANGE; 98 + 99 + oobregion->length = mtd->oobsize - ecc->total - 12; 100 + oobregion->offset = 12 + ecc->total; 101 + 102 + return 0; 103 + } 104 + 105 + const struct mtd_ooblayout_ops qi_lb60_ooblayout_ops = { 106 + .ecc = qi_lb60_ooblayout_ecc, 107 + .free = qi_lb60_ooblayout_free, 108 + }; 109 + 110 + static int jz4725b_ooblayout_ecc(struct mtd_info *mtd, int section, 111 + struct mtd_oob_region *oobregion) 112 + { 113 + struct nand_chip *chip = mtd_to_nand(mtd); 114 + struct nand_ecc_ctrl *ecc = &chip->ecc; 115 + 116 + if (section || !ecc->total) 117 + return -ERANGE; 118 + 119 + oobregion->length = ecc->total; 120 + oobregion->offset = 3; 121 + 122 + return 0; 123 + } 124 + 125 + static int jz4725b_ooblayout_free(struct mtd_info *mtd, int section, 126 + struct mtd_oob_region *oobregion) 127 + { 128 + struct nand_chip *chip = mtd_to_nand(mtd); 129 + struct nand_ecc_ctrl *ecc = &chip->ecc; 130 + 131 + if (section) 132 + return -ERANGE; 133 + 134 + oobregion->length = mtd->oobsize - ecc->total - 3; 135 + oobregion->offset = 3 + ecc->total; 136 + 137 + return 0; 138 + } 139 + 140 + static const struct mtd_ooblayout_ops jz4725b_ooblayout_ops = { 141 + .ecc = jz4725b_ooblayout_ecc, 142 + .free = jz4725b_ooblayout_free, 143 + }; 144 + 145 + static void ingenic_nand_select_chip(struct nand_chip *chip, int chipnr) 146 + { 147 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 148 + struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller); 149 + struct ingenic_nand_cs *cs; 150 + 151 + /* Ensure the currently selected chip is deasserted. */ 152 + if (chipnr == -1 && nfc->selected >= 0) { 153 + cs = &nfc->cs[nfc->selected]; 154 + jz4780_nemc_assert(nfc->dev, cs->bank, false); 155 + } 156 + 157 + nfc->selected = chipnr; 158 + } 159 + 160 + static void ingenic_nand_cmd_ctrl(struct nand_chip *chip, int cmd, 161 + unsigned int ctrl) 162 + { 163 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 164 + struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller); 165 + struct ingenic_nand_cs *cs; 166 + 167 + if (WARN_ON(nfc->selected < 0)) 168 + return; 169 + 170 + cs = &nfc->cs[nfc->selected]; 171 + 172 + jz4780_nemc_assert(nfc->dev, cs->bank, ctrl & NAND_NCE); 173 + 174 + if (cmd == NAND_CMD_NONE) 175 + return; 176 + 177 + if (ctrl & NAND_ALE) 178 + writeb(cmd, cs->base + nfc->soc_info->addr_offset); 179 + else if (ctrl & NAND_CLE) 180 + writeb(cmd, cs->base + nfc->soc_info->cmd_offset); 181 + } 182 + 183 + static int ingenic_nand_dev_ready(struct nand_chip *chip) 184 + { 185 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 186 + 187 + return !gpiod_get_value_cansleep(nand->busy_gpio); 188 + } 189 + 190 + static void ingenic_nand_ecc_hwctl(struct nand_chip *chip, int mode) 191 + { 192 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 193 + 194 + nand->reading = (mode == NAND_ECC_READ); 195 + } 196 + 197 + static int ingenic_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat, 198 + u8 *ecc_code) 199 + { 200 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 201 + struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller); 202 + struct ingenic_ecc_params params; 203 + 204 + /* 205 + * Don't need to generate the ECC when reading, the ECC engine does it 206 + * for us as part of decoding/correction. 207 + */ 208 + if (nand->reading) 209 + return 0; 210 + 211 + params.size = nand->chip.ecc.size; 212 + params.bytes = nand->chip.ecc.bytes; 213 + params.strength = nand->chip.ecc.strength; 214 + 215 + return ingenic_ecc_calculate(nfc->ecc, &params, dat, ecc_code); 216 + } 217 + 218 + static int ingenic_nand_ecc_correct(struct nand_chip *chip, u8 *dat, 219 + u8 *read_ecc, u8 *calc_ecc) 220 + { 221 + struct ingenic_nand *nand = to_ingenic_nand(nand_to_mtd(chip)); 222 + struct ingenic_nfc *nfc = to_ingenic_nfc(nand->chip.controller); 223 + struct ingenic_ecc_params params; 224 + 225 + params.size = nand->chip.ecc.size; 226 + params.bytes = nand->chip.ecc.bytes; 227 + params.strength = nand->chip.ecc.strength; 228 + 229 + return ingenic_ecc_correct(nfc->ecc, &params, dat, read_ecc); 230 + } 231 + 232 + static int ingenic_nand_attach_chip(struct nand_chip *chip) 233 + { 234 + struct mtd_info *mtd = nand_to_mtd(chip); 235 + struct ingenic_nfc *nfc = to_ingenic_nfc(chip->controller); 236 + int eccbytes; 237 + 238 + if (chip->ecc.strength == 4) { 239 + /* JZ4740 uses 9 bytes of ECC to correct maximum 4 errors */ 240 + chip->ecc.bytes = 9; 241 + } else { 242 + chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) * 243 + (chip->ecc.strength / 8); 244 + } 245 + 246 + switch (chip->ecc.mode) { 247 + case NAND_ECC_HW: 248 + if (!nfc->ecc) { 249 + dev_err(nfc->dev, "HW ECC selected, but ECC controller not found\n"); 250 + return -ENODEV; 251 + } 252 + 253 + chip->ecc.hwctl = ingenic_nand_ecc_hwctl; 254 + chip->ecc.calculate = ingenic_nand_ecc_calculate; 255 + chip->ecc.correct = ingenic_nand_ecc_correct; 256 + /* fall through */ 257 + case NAND_ECC_SOFT: 258 + dev_info(nfc->dev, "using %s (strength %d, size %d, bytes %d)\n", 259 + (nfc->ecc) ? "hardware ECC" : "software ECC", 260 + chip->ecc.strength, chip->ecc.size, chip->ecc.bytes); 261 + break; 262 + case NAND_ECC_NONE: 263 + dev_info(nfc->dev, "not using ECC\n"); 264 + break; 265 + default: 266 + dev_err(nfc->dev, "ECC mode %d not supported\n", 267 + chip->ecc.mode); 268 + return -EINVAL; 269 + } 270 + 271 + /* The NAND core will generate the ECC layout for SW ECC */ 272 + if (chip->ecc.mode != NAND_ECC_HW) 273 + return 0; 274 + 275 + /* Generate ECC layout. ECC codes are right aligned in the OOB area. */ 276 + eccbytes = mtd->writesize / chip->ecc.size * chip->ecc.bytes; 277 + 278 + if (eccbytes > mtd->oobsize - 2) { 279 + dev_err(nfc->dev, 280 + "invalid ECC config: required %d ECC bytes, but only %d are available", 281 + eccbytes, mtd->oobsize - 2); 282 + return -EINVAL; 283 + } 284 + 285 + /* 286 + * The generic layout for BBT markers will most likely overlap with our 287 + * ECC bytes in the OOB, so move the BBT markers outside the OOB area. 288 + */ 289 + if (chip->bbt_options & NAND_BBT_USE_FLASH) 290 + chip->bbt_options |= NAND_BBT_NO_OOB; 291 + 292 + /* For legacy reasons we use a different layout on the qi,lb60 board. */ 293 + if (of_machine_is_compatible("qi,lb60")) 294 + mtd_set_ooblayout(mtd, &qi_lb60_ooblayout_ops); 295 + else 296 + mtd_set_ooblayout(mtd, nfc->soc_info->oob_layout); 297 + 298 + return 0; 299 + } 300 + 301 + static const struct nand_controller_ops ingenic_nand_controller_ops = { 302 + .attach_chip = ingenic_nand_attach_chip, 303 + }; 304 + 305 + static int ingenic_nand_init_chip(struct platform_device *pdev, 306 + struct ingenic_nfc *nfc, 307 + struct device_node *np, 308 + unsigned int chipnr) 309 + { 310 + struct device *dev = &pdev->dev; 311 + struct ingenic_nand *nand; 312 + struct ingenic_nand_cs *cs; 313 + struct resource *res; 314 + struct nand_chip *chip; 315 + struct mtd_info *mtd; 316 + const __be32 *reg; 317 + int ret = 0; 318 + 319 + cs = &nfc->cs[chipnr]; 320 + 321 + reg = of_get_property(np, "reg", NULL); 322 + if (!reg) 323 + return -EINVAL; 324 + 325 + cs->bank = be32_to_cpu(*reg); 326 + 327 + jz4780_nemc_set_type(nfc->dev, cs->bank, JZ4780_NEMC_BANK_NAND); 328 + 329 + res = platform_get_resource(pdev, IORESOURCE_MEM, chipnr); 330 + cs->base = devm_ioremap_resource(dev, res); 331 + if (IS_ERR(cs->base)) 332 + return PTR_ERR(cs->base); 333 + 334 + nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL); 335 + if (!nand) 336 + return -ENOMEM; 337 + 338 + nand->busy_gpio = devm_gpiod_get_optional(dev, "rb", GPIOD_IN); 339 + 340 + if (IS_ERR(nand->busy_gpio)) { 341 + ret = PTR_ERR(nand->busy_gpio); 342 + dev_err(dev, "failed to request busy GPIO: %d\n", ret); 343 + return ret; 344 + } else if (nand->busy_gpio) { 345 + nand->chip.legacy.dev_ready = ingenic_nand_dev_ready; 346 + } 347 + 348 + nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW); 349 + 350 + if (IS_ERR(nand->wp_gpio)) { 351 + ret = PTR_ERR(nand->wp_gpio); 352 + dev_err(dev, "failed to request WP GPIO: %d\n", ret); 353 + return ret; 354 + } 355 + 356 + chip = &nand->chip; 357 + mtd = nand_to_mtd(chip); 358 + mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev), 359 + cs->bank); 360 + if (!mtd->name) 361 + return -ENOMEM; 362 + mtd->dev.parent = dev; 363 + 364 + chip->legacy.IO_ADDR_R = cs->base + nfc->soc_info->data_offset; 365 + chip->legacy.IO_ADDR_W = cs->base + nfc->soc_info->data_offset; 366 + chip->legacy.chip_delay = RB_DELAY_US; 367 + chip->options = NAND_NO_SUBPAGE_WRITE; 368 + chip->legacy.select_chip = ingenic_nand_select_chip; 369 + chip->legacy.cmd_ctrl = ingenic_nand_cmd_ctrl; 370 + chip->ecc.mode = NAND_ECC_HW; 371 + chip->controller = &nfc->controller; 372 + nand_set_flash_node(chip, np); 373 + 374 + chip->controller->ops = &ingenic_nand_controller_ops; 375 + ret = nand_scan(chip, 1); 376 + if (ret) 377 + return ret; 378 + 379 + ret = mtd_device_register(mtd, NULL, 0); 380 + if (ret) { 381 + nand_release(chip); 382 + return ret; 383 + } 384 + 385 + list_add_tail(&nand->chip_list, &nfc->chips); 386 + 387 + return 0; 388 + } 389 + 390 + static void ingenic_nand_cleanup_chips(struct ingenic_nfc *nfc) 391 + { 392 + struct ingenic_nand *chip; 393 + 394 + while (!list_empty(&nfc->chips)) { 395 + chip = list_first_entry(&nfc->chips, 396 + struct ingenic_nand, chip_list); 397 + nand_release(&chip->chip); 398 + list_del(&chip->chip_list); 399 + } 400 + } 401 + 402 + static int ingenic_nand_init_chips(struct ingenic_nfc *nfc, 403 + struct platform_device *pdev) 404 + { 405 + struct device *dev = &pdev->dev; 406 + struct device_node *np; 407 + int i = 0; 408 + int ret; 409 + int num_chips = of_get_child_count(dev->of_node); 410 + 411 + if (num_chips > nfc->num_banks) { 412 + dev_err(dev, "found %d chips but only %d banks\n", 413 + num_chips, nfc->num_banks); 414 + return -EINVAL; 415 + } 416 + 417 + for_each_child_of_node(dev->of_node, np) { 418 + ret = ingenic_nand_init_chip(pdev, nfc, np, i); 419 + if (ret) { 420 + ingenic_nand_cleanup_chips(nfc); 421 + return ret; 422 + } 423 + 424 + i++; 425 + } 426 + 427 + return 0; 428 + } 429 + 430 + static int ingenic_nand_probe(struct platform_device *pdev) 431 + { 432 + struct device *dev = &pdev->dev; 433 + unsigned int num_banks; 434 + struct ingenic_nfc *nfc; 435 + int ret; 436 + 437 + num_banks = jz4780_nemc_num_banks(dev); 438 + if (num_banks == 0) { 439 + dev_err(dev, "no banks found\n"); 440 + return -ENODEV; 441 + } 442 + 443 + nfc = devm_kzalloc(dev, struct_size(nfc, cs, num_banks), GFP_KERNEL); 444 + if (!nfc) 445 + return -ENOMEM; 446 + 447 + nfc->soc_info = device_get_match_data(dev); 448 + if (!nfc->soc_info) 449 + return -EINVAL; 450 + 451 + /* 452 + * Check for ECC HW before we call nand_scan_ident, to prevent us from 453 + * having to call it again if the ECC driver returns -EPROBE_DEFER. 454 + */ 455 + nfc->ecc = of_ingenic_ecc_get(dev->of_node); 456 + if (IS_ERR(nfc->ecc)) 457 + return PTR_ERR(nfc->ecc); 458 + 459 + nfc->dev = dev; 460 + nfc->num_banks = num_banks; 461 + 462 + nand_controller_init(&nfc->controller); 463 + INIT_LIST_HEAD(&nfc->chips); 464 + 465 + ret = ingenic_nand_init_chips(nfc, pdev); 466 + if (ret) { 467 + if (nfc->ecc) 468 + ingenic_ecc_release(nfc->ecc); 469 + return ret; 470 + } 471 + 472 + platform_set_drvdata(pdev, nfc); 473 + return 0; 474 + } 475 + 476 + static int ingenic_nand_remove(struct platform_device *pdev) 477 + { 478 + struct ingenic_nfc *nfc = platform_get_drvdata(pdev); 479 + 480 + if (nfc->ecc) 481 + ingenic_ecc_release(nfc->ecc); 482 + 483 + ingenic_nand_cleanup_chips(nfc); 484 + 485 + return 0; 486 + } 487 + 488 + static const struct jz_soc_info jz4740_soc_info = { 489 + .data_offset = 0x00000000, 490 + .cmd_offset = 0x00008000, 491 + .addr_offset = 0x00010000, 492 + .oob_layout = &nand_ooblayout_lp_ops, 493 + }; 494 + 495 + static const struct jz_soc_info jz4725b_soc_info = { 496 + .data_offset = 0x00000000, 497 + .cmd_offset = 0x00008000, 498 + .addr_offset = 0x00010000, 499 + .oob_layout = &jz4725b_ooblayout_ops, 500 + }; 501 + 502 + static const struct jz_soc_info jz4780_soc_info = { 503 + .data_offset = 0x00000000, 504 + .cmd_offset = 0x00400000, 505 + .addr_offset = 0x00800000, 506 + .oob_layout = &nand_ooblayout_lp_ops, 507 + }; 508 + 509 + static const struct of_device_id ingenic_nand_dt_match[] = { 510 + { .compatible = "ingenic,jz4740-nand", .data = &jz4740_soc_info }, 511 + { .compatible = "ingenic,jz4725b-nand", .data = &jz4725b_soc_info }, 512 + { .compatible = "ingenic,jz4780-nand", .data = &jz4780_soc_info }, 513 + {}, 514 + }; 515 + MODULE_DEVICE_TABLE(of, ingenic_nand_dt_match); 516 + 517 + static struct platform_driver ingenic_nand_driver = { 518 + .probe = ingenic_nand_probe, 519 + .remove = ingenic_nand_remove, 520 + .driver = { 521 + .name = DRV_NAME, 522 + .of_match_table = of_match_ptr(ingenic_nand_dt_match), 523 + }, 524 + }; 525 + module_platform_driver(ingenic_nand_driver); 526 + 527 + MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); 528 + MODULE_AUTHOR("Harvey Hunt <harveyhuntnexus@gmail.com>"); 529 + MODULE_DESCRIPTION("Ingenic JZ47xx NAND driver"); 530 + MODULE_LICENSE("GPL v2");
+295
drivers/mtd/nand/raw/ingenic/jz4725b_bch.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * JZ4725B BCH controller driver 4 + * 5 + * Copyright (C) 2019 Paul Cercueil <paul@crapouillou.net> 6 + * 7 + * Based on jz4780_bch.c 8 + */ 9 + 10 + #include <linux/bitops.h> 11 + #include <linux/device.h> 12 + #include <linux/io.h> 13 + #include <linux/iopoll.h> 14 + #include <linux/module.h> 15 + #include <linux/mutex.h> 16 + #include <linux/of_platform.h> 17 + #include <linux/platform_device.h> 18 + 19 + #include "ingenic_ecc.h" 20 + 21 + #define BCH_BHCR 0x0 22 + #define BCH_BHCSR 0x4 23 + #define BCH_BHCCR 0x8 24 + #define BCH_BHCNT 0xc 25 + #define BCH_BHDR 0x10 26 + #define BCH_BHPAR0 0x14 27 + #define BCH_BHERR0 0x28 28 + #define BCH_BHINT 0x24 29 + #define BCH_BHINTES 0x3c 30 + #define BCH_BHINTEC 0x40 31 + #define BCH_BHINTE 0x38 32 + 33 + #define BCH_BHCR_ENCE BIT(3) 34 + #define BCH_BHCR_BSEL BIT(2) 35 + #define BCH_BHCR_INIT BIT(1) 36 + #define BCH_BHCR_BCHE BIT(0) 37 + 38 + #define BCH_BHCNT_DEC_COUNT_SHIFT 16 39 + #define BCH_BHCNT_DEC_COUNT_MASK (0x3ff << BCH_BHCNT_DEC_COUNT_SHIFT) 40 + #define BCH_BHCNT_ENC_COUNT_SHIFT 0 41 + #define BCH_BHCNT_ENC_COUNT_MASK (0x3ff << BCH_BHCNT_ENC_COUNT_SHIFT) 42 + 43 + #define BCH_BHERR_INDEX0_SHIFT 0 44 + #define BCH_BHERR_INDEX0_MASK (0x1fff << BCH_BHERR_INDEX0_SHIFT) 45 + #define BCH_BHERR_INDEX1_SHIFT 16 46 + #define BCH_BHERR_INDEX1_MASK (0x1fff << BCH_BHERR_INDEX1_SHIFT) 47 + 48 + #define BCH_BHINT_ERRC_SHIFT 28 49 + #define BCH_BHINT_ERRC_MASK (0xf << BCH_BHINT_ERRC_SHIFT) 50 + #define BCH_BHINT_TERRC_SHIFT 16 51 + #define BCH_BHINT_TERRC_MASK (0x7f << BCH_BHINT_TERRC_SHIFT) 52 + #define BCH_BHINT_ALL_0 BIT(5) 53 + #define BCH_BHINT_ALL_F BIT(4) 54 + #define BCH_BHINT_DECF BIT(3) 55 + #define BCH_BHINT_ENCF BIT(2) 56 + #define BCH_BHINT_UNCOR BIT(1) 57 + #define BCH_BHINT_ERR BIT(0) 58 + 59 + /* Timeout for BCH calculation/correction. */ 60 + #define BCH_TIMEOUT_US 100000 61 + 62 + static inline void jz4725b_bch_config_set(struct ingenic_ecc *bch, u32 cfg) 63 + { 64 + writel(cfg, bch->base + BCH_BHCSR); 65 + } 66 + 67 + static inline void jz4725b_bch_config_clear(struct ingenic_ecc *bch, u32 cfg) 68 + { 69 + writel(cfg, bch->base + BCH_BHCCR); 70 + } 71 + 72 + static int jz4725b_bch_reset(struct ingenic_ecc *bch, 73 + struct ingenic_ecc_params *params, bool calc_ecc) 74 + { 75 + u32 reg, max_value; 76 + 77 + /* Clear interrupt status. */ 78 + writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); 79 + 80 + /* Initialise and enable BCH. */ 81 + jz4725b_bch_config_clear(bch, 0x1f); 82 + jz4725b_bch_config_set(bch, BCH_BHCR_BCHE); 83 + 84 + if (params->strength == 8) 85 + jz4725b_bch_config_set(bch, BCH_BHCR_BSEL); 86 + else 87 + jz4725b_bch_config_clear(bch, BCH_BHCR_BSEL); 88 + 89 + if (calc_ecc) /* calculate ECC from data */ 90 + jz4725b_bch_config_set(bch, BCH_BHCR_ENCE); 91 + else /* correct data from ECC */ 92 + jz4725b_bch_config_clear(bch, BCH_BHCR_ENCE); 93 + 94 + jz4725b_bch_config_set(bch, BCH_BHCR_INIT); 95 + 96 + max_value = BCH_BHCNT_ENC_COUNT_MASK >> BCH_BHCNT_ENC_COUNT_SHIFT; 97 + if (params->size > max_value) 98 + return -EINVAL; 99 + 100 + max_value = BCH_BHCNT_DEC_COUNT_MASK >> BCH_BHCNT_DEC_COUNT_SHIFT; 101 + if (params->size + params->bytes > max_value) 102 + return -EINVAL; 103 + 104 + /* Set up BCH count register. */ 105 + reg = params->size << BCH_BHCNT_ENC_COUNT_SHIFT; 106 + reg |= (params->size + params->bytes) << BCH_BHCNT_DEC_COUNT_SHIFT; 107 + writel(reg, bch->base + BCH_BHCNT); 108 + 109 + return 0; 110 + } 111 + 112 + static void jz4725b_bch_disable(struct ingenic_ecc *bch) 113 + { 114 + /* Clear interrupts */ 115 + writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); 116 + 117 + /* Disable the hardware */ 118 + jz4725b_bch_config_clear(bch, BCH_BHCR_BCHE); 119 + } 120 + 121 + static void jz4725b_bch_write_data(struct ingenic_ecc *bch, const u8 *buf, 122 + size_t size) 123 + { 124 + while (size--) 125 + writeb(*buf++, bch->base + BCH_BHDR); 126 + } 127 + 128 + static void jz4725b_bch_read_parity(struct ingenic_ecc *bch, u8 *buf, 129 + size_t size) 130 + { 131 + size_t size32 = size / sizeof(u32); 132 + size_t size8 = size % sizeof(u32); 133 + u32 *dest32; 134 + u8 *dest8; 135 + u32 val, offset = 0; 136 + 137 + dest32 = (u32 *)buf; 138 + while (size32--) { 139 + *dest32++ = readl_relaxed(bch->base + BCH_BHPAR0 + offset); 140 + offset += sizeof(u32); 141 + } 142 + 143 + dest8 = (u8 *)dest32; 144 + val = readl_relaxed(bch->base + BCH_BHPAR0 + offset); 145 + switch (size8) { 146 + case 3: 147 + dest8[2] = (val >> 16) & 0xff; 148 + /* fall-through */ 149 + case 2: 150 + dest8[1] = (val >> 8) & 0xff; 151 + /* fall-through */ 152 + case 1: 153 + dest8[0] = val & 0xff; 154 + break; 155 + } 156 + } 157 + 158 + static int jz4725b_bch_wait_complete(struct ingenic_ecc *bch, unsigned int irq, 159 + u32 *status) 160 + { 161 + u32 reg; 162 + int ret; 163 + 164 + /* 165 + * While we could use interrupts here and sleep until the operation 166 + * completes, the controller works fairly quickly (usually a few 167 + * microseconds) and so the overhead of sleeping until we get an 168 + * interrupt quite noticeably decreases performance. 169 + */ 170 + ret = readl_relaxed_poll_timeout(bch->base + BCH_BHINT, reg, 171 + reg & irq, 0, BCH_TIMEOUT_US); 172 + if (ret) 173 + return ret; 174 + 175 + if (status) 176 + *status = reg; 177 + 178 + writel(reg, bch->base + BCH_BHINT); 179 + 180 + return 0; 181 + } 182 + 183 + static int jz4725b_calculate(struct ingenic_ecc *bch, 184 + struct ingenic_ecc_params *params, 185 + const u8 *buf, u8 *ecc_code) 186 + { 187 + int ret; 188 + 189 + mutex_lock(&bch->lock); 190 + 191 + ret = jz4725b_bch_reset(bch, params, true); 192 + if (ret) { 193 + dev_err(bch->dev, "Unable to init BCH with given parameters\n"); 194 + goto out_disable; 195 + } 196 + 197 + jz4725b_bch_write_data(bch, buf, params->size); 198 + 199 + ret = jz4725b_bch_wait_complete(bch, BCH_BHINT_ENCF, NULL); 200 + if (ret) { 201 + dev_err(bch->dev, "timed out while calculating ECC\n"); 202 + goto out_disable; 203 + } 204 + 205 + jz4725b_bch_read_parity(bch, ecc_code, params->bytes); 206 + 207 + out_disable: 208 + jz4725b_bch_disable(bch); 209 + mutex_unlock(&bch->lock); 210 + 211 + return ret; 212 + } 213 + 214 + static int jz4725b_correct(struct ingenic_ecc *bch, 215 + struct ingenic_ecc_params *params, 216 + u8 *buf, u8 *ecc_code) 217 + { 218 + u32 reg, errors, bit; 219 + unsigned int i; 220 + int ret; 221 + 222 + mutex_lock(&bch->lock); 223 + 224 + ret = jz4725b_bch_reset(bch, params, false); 225 + if (ret) { 226 + dev_err(bch->dev, "Unable to init BCH with given parameters\n"); 227 + goto out; 228 + } 229 + 230 + jz4725b_bch_write_data(bch, buf, params->size); 231 + jz4725b_bch_write_data(bch, ecc_code, params->bytes); 232 + 233 + ret = jz4725b_bch_wait_complete(bch, BCH_BHINT_DECF, &reg); 234 + if (ret) { 235 + dev_err(bch->dev, "timed out while correcting data\n"); 236 + goto out; 237 + } 238 + 239 + if (reg & (BCH_BHINT_ALL_F | BCH_BHINT_ALL_0)) { 240 + /* Data and ECC is all 0xff or 0x00 - nothing to correct */ 241 + ret = 0; 242 + goto out; 243 + } 244 + 245 + if (reg & BCH_BHINT_UNCOR) { 246 + /* Uncorrectable ECC error */ 247 + ret = -EBADMSG; 248 + goto out; 249 + } 250 + 251 + errors = (reg & BCH_BHINT_ERRC_MASK) >> BCH_BHINT_ERRC_SHIFT; 252 + 253 + /* Correct any detected errors. */ 254 + for (i = 0; i < errors; i++) { 255 + if (i & 1) { 256 + bit = (reg & BCH_BHERR_INDEX1_MASK) >> BCH_BHERR_INDEX1_SHIFT; 257 + } else { 258 + reg = readl(bch->base + BCH_BHERR0 + (i * 4)); 259 + bit = (reg & BCH_BHERR_INDEX0_MASK) >> BCH_BHERR_INDEX0_SHIFT; 260 + } 261 + 262 + buf[(bit >> 3)] ^= BIT(bit & 0x7); 263 + } 264 + 265 + out: 266 + jz4725b_bch_disable(bch); 267 + mutex_unlock(&bch->lock); 268 + 269 + return ret; 270 + } 271 + 272 + static const struct ingenic_ecc_ops jz4725b_bch_ops = { 273 + .disable = jz4725b_bch_disable, 274 + .calculate = jz4725b_calculate, 275 + .correct = jz4725b_correct, 276 + }; 277 + 278 + static const struct of_device_id jz4725b_bch_dt_match[] = { 279 + { .compatible = "ingenic,jz4725b-bch", .data = &jz4725b_bch_ops }, 280 + {}, 281 + }; 282 + MODULE_DEVICE_TABLE(of, jz4725b_bch_dt_match); 283 + 284 + static struct platform_driver jz4725b_bch_driver = { 285 + .probe = ingenic_ecc_probe, 286 + .driver = { 287 + .name = "jz4725b-bch", 288 + .of_match_table = jz4725b_bch_dt_match, 289 + }, 290 + }; 291 + module_platform_driver(jz4725b_bch_driver); 292 + 293 + MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>"); 294 + MODULE_DESCRIPTION("Ingenic JZ4725B BCH controller driver"); 295 + MODULE_LICENSE("GPL v2");
+197
drivers/mtd/nand/raw/ingenic/jz4740_ecc.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * JZ4740 ECC controller driver 4 + * 5 + * Copyright (c) 2019 Paul Cercueil <paul@crapouillou.net> 6 + * 7 + * based on jz4740-nand.c 8 + */ 9 + 10 + #include <linux/bitops.h> 11 + #include <linux/device.h> 12 + #include <linux/io.h> 13 + #include <linux/module.h> 14 + #include <linux/of_platform.h> 15 + #include <linux/platform_device.h> 16 + 17 + #include "ingenic_ecc.h" 18 + 19 + #define JZ_REG_NAND_ECC_CTRL 0x00 20 + #define JZ_REG_NAND_DATA 0x04 21 + #define JZ_REG_NAND_PAR0 0x08 22 + #define JZ_REG_NAND_PAR1 0x0C 23 + #define JZ_REG_NAND_PAR2 0x10 24 + #define JZ_REG_NAND_IRQ_STAT 0x14 25 + #define JZ_REG_NAND_IRQ_CTRL 0x18 26 + #define JZ_REG_NAND_ERR(x) (0x1C + ((x) << 2)) 27 + 28 + #define JZ_NAND_ECC_CTRL_PAR_READY BIT(4) 29 + #define JZ_NAND_ECC_CTRL_ENCODING BIT(3) 30 + #define JZ_NAND_ECC_CTRL_RS BIT(2) 31 + #define JZ_NAND_ECC_CTRL_RESET BIT(1) 32 + #define JZ_NAND_ECC_CTRL_ENABLE BIT(0) 33 + 34 + #define JZ_NAND_STATUS_ERR_COUNT (BIT(31) | BIT(30) | BIT(29)) 35 + #define JZ_NAND_STATUS_PAD_FINISH BIT(4) 36 + #define JZ_NAND_STATUS_DEC_FINISH BIT(3) 37 + #define JZ_NAND_STATUS_ENC_FINISH BIT(2) 38 + #define JZ_NAND_STATUS_UNCOR_ERROR BIT(1) 39 + #define JZ_NAND_STATUS_ERROR BIT(0) 40 + 41 + static const uint8_t empty_block_ecc[] = { 42 + 0xcd, 0x9d, 0x90, 0x58, 0xf4, 0x8b, 0xff, 0xb7, 0x6f 43 + }; 44 + 45 + static void jz4740_ecc_reset(struct ingenic_ecc *ecc, bool calc_ecc) 46 + { 47 + uint32_t reg; 48 + 49 + /* Clear interrupt status */ 50 + writel(0, ecc->base + JZ_REG_NAND_IRQ_STAT); 51 + 52 + /* Initialize and enable ECC hardware */ 53 + reg = readl(ecc->base + JZ_REG_NAND_ECC_CTRL); 54 + reg |= JZ_NAND_ECC_CTRL_RESET; 55 + reg |= JZ_NAND_ECC_CTRL_ENABLE; 56 + reg |= JZ_NAND_ECC_CTRL_RS; 57 + if (calc_ecc) /* calculate ECC from data */ 58 + reg |= JZ_NAND_ECC_CTRL_ENCODING; 59 + else /* correct data from ECC */ 60 + reg &= ~JZ_NAND_ECC_CTRL_ENCODING; 61 + 62 + writel(reg, ecc->base + JZ_REG_NAND_ECC_CTRL); 63 + } 64 + 65 + static int jz4740_ecc_calculate(struct ingenic_ecc *ecc, 66 + struct ingenic_ecc_params *params, 67 + const u8 *buf, u8 *ecc_code) 68 + { 69 + uint32_t reg, status; 70 + unsigned int timeout = 1000; 71 + int i; 72 + 73 + jz4740_ecc_reset(ecc, true); 74 + 75 + do { 76 + status = readl(ecc->base + JZ_REG_NAND_IRQ_STAT); 77 + } while (!(status & JZ_NAND_STATUS_ENC_FINISH) && --timeout); 78 + 79 + if (timeout == 0) 80 + return -ETIMEDOUT; 81 + 82 + reg = readl(ecc->base + JZ_REG_NAND_ECC_CTRL); 83 + reg &= ~JZ_NAND_ECC_CTRL_ENABLE; 84 + writel(reg, ecc->base + JZ_REG_NAND_ECC_CTRL); 85 + 86 + for (i = 0; i < params->bytes; ++i) 87 + ecc_code[i] = readb(ecc->base + JZ_REG_NAND_PAR0 + i); 88 + 89 + /* 90 + * If the written data is completely 0xff, we also want to write 0xff as 91 + * ECC, otherwise we will get in trouble when doing subpage writes. 92 + */ 93 + if (memcmp(ecc_code, empty_block_ecc, ARRAY_SIZE(empty_block_ecc)) == 0) 94 + memset(ecc_code, 0xff, ARRAY_SIZE(empty_block_ecc)); 95 + 96 + return 0; 97 + } 98 + 99 + static void jz_nand_correct_data(uint8_t *buf, int index, int mask) 100 + { 101 + int offset = index & 0x7; 102 + uint16_t data; 103 + 104 + index += (index >> 3); 105 + 106 + data = buf[index]; 107 + data |= buf[index + 1] << 8; 108 + 109 + mask ^= (data >> offset) & 0x1ff; 110 + data &= ~(0x1ff << offset); 111 + data |= (mask << offset); 112 + 113 + buf[index] = data & 0xff; 114 + buf[index + 1] = (data >> 8) & 0xff; 115 + } 116 + 117 + static int jz4740_ecc_correct(struct ingenic_ecc *ecc, 118 + struct ingenic_ecc_params *params, 119 + u8 *buf, u8 *ecc_code) 120 + { 121 + int i, error_count, index; 122 + uint32_t reg, status, error; 123 + unsigned int timeout = 1000; 124 + 125 + jz4740_ecc_reset(ecc, false); 126 + 127 + for (i = 0; i < params->bytes; ++i) 128 + writeb(ecc_code[i], ecc->base + JZ_REG_NAND_PAR0 + i); 129 + 130 + reg = readl(ecc->base + JZ_REG_NAND_ECC_CTRL); 131 + reg |= JZ_NAND_ECC_CTRL_PAR_READY; 132 + writel(reg, ecc->base + JZ_REG_NAND_ECC_CTRL); 133 + 134 + do { 135 + status = readl(ecc->base + JZ_REG_NAND_IRQ_STAT); 136 + } while (!(status & JZ_NAND_STATUS_DEC_FINISH) && --timeout); 137 + 138 + if (timeout == 0) 139 + return -ETIMEDOUT; 140 + 141 + reg = readl(ecc->base + JZ_REG_NAND_ECC_CTRL); 142 + reg &= ~JZ_NAND_ECC_CTRL_ENABLE; 143 + writel(reg, ecc->base + JZ_REG_NAND_ECC_CTRL); 144 + 145 + if (status & JZ_NAND_STATUS_ERROR) { 146 + if (status & JZ_NAND_STATUS_UNCOR_ERROR) 147 + return -EBADMSG; 148 + 149 + error_count = (status & JZ_NAND_STATUS_ERR_COUNT) >> 29; 150 + 151 + for (i = 0; i < error_count; ++i) { 152 + error = readl(ecc->base + JZ_REG_NAND_ERR(i)); 153 + index = ((error >> 16) & 0x1ff) - 1; 154 + if (index >= 0 && index < params->size) 155 + jz_nand_correct_data(buf, index, error & 0x1ff); 156 + } 157 + 158 + return error_count; 159 + } 160 + 161 + return 0; 162 + } 163 + 164 + static void jz4740_ecc_disable(struct ingenic_ecc *ecc) 165 + { 166 + u32 reg; 167 + 168 + writel(0, ecc->base + JZ_REG_NAND_IRQ_STAT); 169 + reg = readl(ecc->base + JZ_REG_NAND_ECC_CTRL); 170 + reg &= ~JZ_NAND_ECC_CTRL_ENABLE; 171 + writel(reg, ecc->base + JZ_REG_NAND_ECC_CTRL); 172 + } 173 + 174 + static const struct ingenic_ecc_ops jz4740_ecc_ops = { 175 + .disable = jz4740_ecc_disable, 176 + .calculate = jz4740_ecc_calculate, 177 + .correct = jz4740_ecc_correct, 178 + }; 179 + 180 + static const struct of_device_id jz4740_ecc_dt_match[] = { 181 + { .compatible = "ingenic,jz4740-ecc", .data = &jz4740_ecc_ops }, 182 + {}, 183 + }; 184 + MODULE_DEVICE_TABLE(of, jz4740_ecc_dt_match); 185 + 186 + static struct platform_driver jz4740_ecc_driver = { 187 + .probe = ingenic_ecc_probe, 188 + .driver = { 189 + .name = "jz4740-ecc", 190 + .of_match_table = jz4740_ecc_dt_match, 191 + }, 192 + }; 193 + module_platform_driver(jz4740_ecc_driver); 194 + 195 + MODULE_AUTHOR("Paul Cercueil <paul@crapouillou.net>"); 196 + MODULE_DESCRIPTION("Ingenic JZ4740 ECC controller driver"); 197 + MODULE_LICENSE("GPL v2");
+2 -1
drivers/mtd/nand/raw/internals.h
··· 76 76 77 77 /* Core functions */ 78 78 const struct nand_manufacturer *nand_get_manufacturer(u8 id); 79 + int nand_bbm_get_next_page(struct nand_chip *chip, int page); 79 80 int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs); 80 81 int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, 81 82 int allowbbt); ··· 111 110 if (!nand_has_exec_op(chip)) 112 111 return -ENOTSUPP; 113 112 114 - if (WARN_ON(op->cs >= chip->numchips)) 113 + if (WARN_ON(op->cs >= nanddev_ntargets(&chip->base))) 115 114 return -EINVAL; 116 115 117 116 return chip->controller->ops->exec_op(chip, op, false);
+5 -2
drivers/mtd/nand/raw/jz4740_nand.c drivers/mtd/nand/raw/ingenic/jz4740_nand.c
··· 313 313 uint32_t ctrl; 314 314 struct nand_chip *chip = &nand->chip; 315 315 struct mtd_info *mtd = nand_to_mtd(chip); 316 + struct nand_memory_organization *memorg; 316 317 u8 id[2]; 318 + 319 + memorg = nanddev_get_memorg(&chip->base); 317 320 318 321 /* Request I/O resource. */ 319 322 sprintf(res_name, "bank%d", bank); ··· 354 351 } 355 352 356 353 /* Update size of the MTD. */ 357 - chip->numchips++; 358 - mtd->size += chip->chipsize; 354 + memorg->ntargets++; 355 + mtd->size += nanddev_target_size(&chip->base); 359 356 } 360 357 361 358 dev_info(&pdev->dev, "Found chip %zu on bank %i\n", chipnr, bank);
+33 -147
drivers/mtd/nand/raw/jz4780_bch.c drivers/mtd/nand/raw/ingenic/jz4780_bch.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 1 2 /* 2 - * JZ4780 BCH controller 3 + * JZ4780 BCH controller driver 3 4 * 4 5 * Copyright (c) 2015 Imagination Technologies 5 6 * Author: Alex Smith <alex.smith@imgtec.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify it 8 - * under the terms of the GNU General Public License version 2 as published 9 - * by the Free Software Foundation. 10 7 */ 11 8 12 9 #include <linux/bitops.h> 13 10 #include <linux/clk.h> 14 - #include <linux/delay.h> 15 - #include <linux/init.h> 11 + #include <linux/device.h> 12 + #include <linux/io.h> 16 13 #include <linux/iopoll.h> 17 14 #include <linux/module.h> 18 15 #include <linux/mutex.h> 19 - #include <linux/of.h> 20 16 #include <linux/of_platform.h> 21 17 #include <linux/platform_device.h> 22 - #include <linux/sched.h> 23 - #include <linux/slab.h> 24 18 25 - #include "jz4780_bch.h" 19 + #include "ingenic_ecc.h" 26 20 27 21 #define BCH_BHCR 0x0 28 22 #define BCH_BHCCR 0x8 ··· 59 65 /* Timeout for BCH calculation/correction. */ 60 66 #define BCH_TIMEOUT_US 100000 61 67 62 - struct jz4780_bch { 63 - struct device *dev; 64 - void __iomem *base; 65 - struct clk *clk; 66 - struct mutex lock; 67 - }; 68 - 69 - static void jz4780_bch_init(struct jz4780_bch *bch, 70 - struct jz4780_bch_params *params, bool encode) 68 + static void jz4780_bch_reset(struct ingenic_ecc *bch, 69 + struct ingenic_ecc_params *params, bool encode) 71 70 { 72 71 u32 reg; 73 72 ··· 80 93 writel(reg, bch->base + BCH_BHCR); 81 94 } 82 95 83 - static void jz4780_bch_disable(struct jz4780_bch *bch) 96 + static void jz4780_bch_disable(struct ingenic_ecc *bch) 84 97 { 85 98 writel(readl(bch->base + BCH_BHINT), bch->base + BCH_BHINT); 86 99 writel(BCH_BHCR_BCHE, bch->base + BCH_BHCCR); 87 100 } 88 101 89 - static void jz4780_bch_write_data(struct jz4780_bch *bch, const void *buf, 102 + static void jz4780_bch_write_data(struct ingenic_ecc *bch, const void *buf, 90 103 size_t size) 91 104 { 92 105 size_t size32 = size / sizeof(u32); ··· 103 116 writeb(*src8++, bch->base + BCH_BHDR); 104 117 } 105 118 106 - static void jz4780_bch_read_parity(struct jz4780_bch *bch, void *buf, 119 + static void jz4780_bch_read_parity(struct ingenic_ecc *bch, void *buf, 107 120 size_t size) 108 121 { 109 122 size_t size32 = size / sizeof(u32); ··· 133 146 } 134 147 } 135 148 136 - static bool jz4780_bch_wait_complete(struct jz4780_bch *bch, unsigned int irq, 149 + static bool jz4780_bch_wait_complete(struct ingenic_ecc *bch, unsigned int irq, 137 150 u32 *status) 138 151 { 139 152 u32 reg; ··· 157 170 return true; 158 171 } 159 172 160 - /** 161 - * jz4780_bch_calculate() - calculate ECC for a data buffer 162 - * @bch: BCH device. 163 - * @params: BCH parameters. 164 - * @buf: input buffer with raw data. 165 - * @ecc_code: output buffer with ECC. 166 - * 167 - * Return: 0 on success, -ETIMEDOUT if timed out while waiting for BCH 168 - * controller. 169 - */ 170 - int jz4780_bch_calculate(struct jz4780_bch *bch, struct jz4780_bch_params *params, 171 - const u8 *buf, u8 *ecc_code) 173 + static int jz4780_calculate(struct ingenic_ecc *bch, 174 + struct ingenic_ecc_params *params, 175 + const u8 *buf, u8 *ecc_code) 172 176 { 173 177 int ret = 0; 174 178 175 179 mutex_lock(&bch->lock); 176 - jz4780_bch_init(bch, params, true); 180 + 181 + jz4780_bch_reset(bch, params, true); 177 182 jz4780_bch_write_data(bch, buf, params->size); 178 183 179 184 if (jz4780_bch_wait_complete(bch, BCH_BHINT_ENCF, NULL)) { ··· 179 200 mutex_unlock(&bch->lock); 180 201 return ret; 181 202 } 182 - EXPORT_SYMBOL(jz4780_bch_calculate); 183 203 184 - /** 185 - * jz4780_bch_correct() - detect and correct bit errors 186 - * @bch: BCH device. 187 - * @params: BCH parameters. 188 - * @buf: raw data read from the chip. 189 - * @ecc_code: ECC read from the chip. 190 - * 191 - * Given the raw data and the ECC read from the NAND device, detects and 192 - * corrects errors in the data. 193 - * 194 - * Return: the number of bit errors corrected, -EBADMSG if there are too many 195 - * errors to correct or -ETIMEDOUT if we timed out waiting for the controller. 196 - */ 197 - int jz4780_bch_correct(struct jz4780_bch *bch, struct jz4780_bch_params *params, 198 - u8 *buf, u8 *ecc_code) 204 + static int jz4780_correct(struct ingenic_ecc *bch, 205 + struct ingenic_ecc_params *params, 206 + u8 *buf, u8 *ecc_code) 199 207 { 200 208 u32 reg, mask, index; 201 209 int i, ret, count; 202 210 203 211 mutex_lock(&bch->lock); 204 212 205 - jz4780_bch_init(bch, params, false); 213 + jz4780_bch_reset(bch, params, false); 206 214 jz4780_bch_write_data(bch, buf, params->size); 207 215 jz4780_bch_write_data(bch, ecc_code, params->bytes); 208 216 ··· 228 262 mutex_unlock(&bch->lock); 229 263 return ret; 230 264 } 231 - EXPORT_SYMBOL(jz4780_bch_correct); 232 - 233 - /** 234 - * jz4780_bch_get() - get the BCH controller device 235 - * @np: BCH device tree node. 236 - * 237 - * Gets the BCH controller device from the specified device tree node. The 238 - * device must be released with jz4780_bch_release() when it is no longer being 239 - * used. 240 - * 241 - * Return: a pointer to jz4780_bch, errors are encoded into the pointer. 242 - * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 243 - */ 244 - static struct jz4780_bch *jz4780_bch_get(struct device_node *np) 245 - { 246 - struct platform_device *pdev; 247 - struct jz4780_bch *bch; 248 - 249 - pdev = of_find_device_by_node(np); 250 - if (!pdev) 251 - return ERR_PTR(-EPROBE_DEFER); 252 - 253 - bch = platform_get_drvdata(pdev); 254 - if (!bch) { 255 - put_device(&pdev->dev); 256 - return ERR_PTR(-EPROBE_DEFER); 257 - } 258 - 259 - clk_prepare_enable(bch->clk); 260 - 261 - return bch; 262 - } 263 - 264 - /** 265 - * of_jz4780_bch_get() - get the BCH controller from a DT node 266 - * @of_node: the node that contains a bch-controller property. 267 - * 268 - * Get the bch-controller property from the given device tree 269 - * node and pass it to jz4780_bch_get to do the work. 270 - * 271 - * Return: a pointer to jz4780_bch, errors are encoded into the pointer. 272 - * PTR_ERR(-EPROBE_DEFER) if the device hasn't been initialised yet. 273 - */ 274 - struct jz4780_bch *of_jz4780_bch_get(struct device_node *of_node) 275 - { 276 - struct jz4780_bch *bch = NULL; 277 - struct device_node *np; 278 - 279 - np = of_parse_phandle(of_node, "ingenic,bch-controller", 0); 280 - 281 - if (np) { 282 - bch = jz4780_bch_get(np); 283 - of_node_put(np); 284 - } 285 - return bch; 286 - } 287 - EXPORT_SYMBOL(of_jz4780_bch_get); 288 - 289 - /** 290 - * jz4780_bch_release() - release the BCH controller device 291 - * @bch: BCH device. 292 - */ 293 - void jz4780_bch_release(struct jz4780_bch *bch) 294 - { 295 - clk_disable_unprepare(bch->clk); 296 - put_device(bch->dev); 297 - } 298 - EXPORT_SYMBOL(jz4780_bch_release); 299 265 300 266 static int jz4780_bch_probe(struct platform_device *pdev) 301 267 { 302 - struct device *dev = &pdev->dev; 303 - struct jz4780_bch *bch; 304 - struct resource *res; 268 + struct ingenic_ecc *bch; 269 + int ret; 305 270 306 - bch = devm_kzalloc(dev, sizeof(*bch), GFP_KERNEL); 307 - if (!bch) 308 - return -ENOMEM; 271 + ret = ingenic_ecc_probe(pdev); 272 + if (ret) 273 + return ret; 309 274 310 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 311 - bch->base = devm_ioremap_resource(dev, res); 312 - if (IS_ERR(bch->base)) 313 - return PTR_ERR(bch->base); 314 - 315 - jz4780_bch_disable(bch); 316 - 317 - bch->clk = devm_clk_get(dev, NULL); 318 - if (IS_ERR(bch->clk)) { 319 - dev_err(dev, "failed to get clock: %ld\n", PTR_ERR(bch->clk)); 320 - return PTR_ERR(bch->clk); 321 - } 322 - 275 + bch = platform_get_drvdata(pdev); 323 276 clk_set_rate(bch->clk, BCH_CLK_RATE); 324 - 325 - mutex_init(&bch->lock); 326 - 327 - bch->dev = dev; 328 - platform_set_drvdata(pdev, bch); 329 277 330 278 return 0; 331 279 } 332 280 281 + static const struct ingenic_ecc_ops jz4780_bch_ops = { 282 + .disable = jz4780_bch_disable, 283 + .calculate = jz4780_calculate, 284 + .correct = jz4780_correct, 285 + }; 286 + 333 287 static const struct of_device_id jz4780_bch_dt_match[] = { 334 - { .compatible = "ingenic,jz4780-bch" }, 288 + { .compatible = "ingenic,jz4780-bch", .data = &jz4780_bch_ops }, 335 289 {}, 336 290 }; 337 291 MODULE_DEVICE_TABLE(of, jz4780_bch_dt_match);
-43
drivers/mtd/nand/raw/jz4780_bch.h
··· 1 - /* 2 - * JZ4780 BCH controller 3 - * 4 - * Copyright (c) 2015 Imagination Technologies 5 - * Author: Alex Smith <alex.smith@imgtec.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify it 8 - * under the terms of the GNU General Public License version 2 as published 9 - * by the Free Software Foundation. 10 - */ 11 - 12 - #ifndef __DRIVERS_MTD_NAND_JZ4780_BCH_H__ 13 - #define __DRIVERS_MTD_NAND_JZ4780_BCH_H__ 14 - 15 - #include <linux/types.h> 16 - 17 - struct device; 18 - struct device_node; 19 - struct jz4780_bch; 20 - 21 - /** 22 - * struct jz4780_bch_params - BCH parameters 23 - * @size: data bytes per ECC step. 24 - * @bytes: ECC bytes per step. 25 - * @strength: number of correctable bits per ECC step. 26 - */ 27 - struct jz4780_bch_params { 28 - int size; 29 - int bytes; 30 - int strength; 31 - }; 32 - 33 - int jz4780_bch_calculate(struct jz4780_bch *bch, 34 - struct jz4780_bch_params *params, 35 - const u8 *buf, u8 *ecc_code); 36 - int jz4780_bch_correct(struct jz4780_bch *bch, 37 - struct jz4780_bch_params *params, u8 *buf, 38 - u8 *ecc_code); 39 - 40 - void jz4780_bch_release(struct jz4780_bch *bch); 41 - struct jz4780_bch *of_jz4780_bch_get(struct device_node *np); 42 - 43 - #endif /* __DRIVERS_MTD_NAND_JZ4780_BCH_H__ */
-415
drivers/mtd/nand/raw/jz4780_nand.c
··· 1 - /* 2 - * JZ4780 NAND driver 3 - * 4 - * Copyright (c) 2015 Imagination Technologies 5 - * Author: Alex Smith <alex.smith@imgtec.com> 6 - * 7 - * This program is free software; you can redistribute it and/or modify it 8 - * under the terms of the GNU General Public License version 2 as published 9 - * by the Free Software Foundation. 10 - */ 11 - 12 - #include <linux/delay.h> 13 - #include <linux/init.h> 14 - #include <linux/io.h> 15 - #include <linux/list.h> 16 - #include <linux/module.h> 17 - #include <linux/of.h> 18 - #include <linux/of_address.h> 19 - #include <linux/gpio/consumer.h> 20 - #include <linux/platform_device.h> 21 - #include <linux/slab.h> 22 - #include <linux/mtd/mtd.h> 23 - #include <linux/mtd/rawnand.h> 24 - #include <linux/mtd/partitions.h> 25 - 26 - #include <linux/jz4780-nemc.h> 27 - 28 - #include "jz4780_bch.h" 29 - 30 - #define DRV_NAME "jz4780-nand" 31 - 32 - #define OFFSET_DATA 0x00000000 33 - #define OFFSET_CMD 0x00400000 34 - #define OFFSET_ADDR 0x00800000 35 - 36 - /* Command delay when there is no R/B pin. */ 37 - #define RB_DELAY_US 100 38 - 39 - struct jz4780_nand_cs { 40 - unsigned int bank; 41 - void __iomem *base; 42 - }; 43 - 44 - struct jz4780_nand_controller { 45 - struct device *dev; 46 - struct jz4780_bch *bch; 47 - struct nand_controller controller; 48 - unsigned int num_banks; 49 - struct list_head chips; 50 - int selected; 51 - struct jz4780_nand_cs cs[]; 52 - }; 53 - 54 - struct jz4780_nand_chip { 55 - struct nand_chip chip; 56 - struct list_head chip_list; 57 - 58 - struct gpio_desc *busy_gpio; 59 - struct gpio_desc *wp_gpio; 60 - unsigned int reading: 1; 61 - }; 62 - 63 - static inline struct jz4780_nand_chip *to_jz4780_nand_chip(struct mtd_info *mtd) 64 - { 65 - return container_of(mtd_to_nand(mtd), struct jz4780_nand_chip, chip); 66 - } 67 - 68 - static inline struct jz4780_nand_controller 69 - *to_jz4780_nand_controller(struct nand_controller *ctrl) 70 - { 71 - return container_of(ctrl, struct jz4780_nand_controller, controller); 72 - } 73 - 74 - static void jz4780_nand_select_chip(struct nand_chip *chip, int chipnr) 75 - { 76 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 77 - struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 78 - struct jz4780_nand_cs *cs; 79 - 80 - /* Ensure the currently selected chip is deasserted. */ 81 - if (chipnr == -1 && nfc->selected >= 0) { 82 - cs = &nfc->cs[nfc->selected]; 83 - jz4780_nemc_assert(nfc->dev, cs->bank, false); 84 - } 85 - 86 - nfc->selected = chipnr; 87 - } 88 - 89 - static void jz4780_nand_cmd_ctrl(struct nand_chip *chip, int cmd, 90 - unsigned int ctrl) 91 - { 92 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 93 - struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 94 - struct jz4780_nand_cs *cs; 95 - 96 - if (WARN_ON(nfc->selected < 0)) 97 - return; 98 - 99 - cs = &nfc->cs[nfc->selected]; 100 - 101 - jz4780_nemc_assert(nfc->dev, cs->bank, ctrl & NAND_NCE); 102 - 103 - if (cmd == NAND_CMD_NONE) 104 - return; 105 - 106 - if (ctrl & NAND_ALE) 107 - writeb(cmd, cs->base + OFFSET_ADDR); 108 - else if (ctrl & NAND_CLE) 109 - writeb(cmd, cs->base + OFFSET_CMD); 110 - } 111 - 112 - static int jz4780_nand_dev_ready(struct nand_chip *chip) 113 - { 114 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 115 - 116 - return !gpiod_get_value_cansleep(nand->busy_gpio); 117 - } 118 - 119 - static void jz4780_nand_ecc_hwctl(struct nand_chip *chip, int mode) 120 - { 121 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 122 - 123 - nand->reading = (mode == NAND_ECC_READ); 124 - } 125 - 126 - static int jz4780_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat, 127 - u8 *ecc_code) 128 - { 129 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 130 - struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 131 - struct jz4780_bch_params params; 132 - 133 - /* 134 - * Don't need to generate the ECC when reading, BCH does it for us as 135 - * part of decoding/correction. 136 - */ 137 - if (nand->reading) 138 - return 0; 139 - 140 - params.size = nand->chip.ecc.size; 141 - params.bytes = nand->chip.ecc.bytes; 142 - params.strength = nand->chip.ecc.strength; 143 - 144 - return jz4780_bch_calculate(nfc->bch, &params, dat, ecc_code); 145 - } 146 - 147 - static int jz4780_nand_ecc_correct(struct nand_chip *chip, u8 *dat, 148 - u8 *read_ecc, u8 *calc_ecc) 149 - { 150 - struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip)); 151 - struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller); 152 - struct jz4780_bch_params params; 153 - 154 - params.size = nand->chip.ecc.size; 155 - params.bytes = nand->chip.ecc.bytes; 156 - params.strength = nand->chip.ecc.strength; 157 - 158 - return jz4780_bch_correct(nfc->bch, &params, dat, read_ecc); 159 - } 160 - 161 - static int jz4780_nand_attach_chip(struct nand_chip *chip) 162 - { 163 - struct mtd_info *mtd = nand_to_mtd(chip); 164 - struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(chip->controller); 165 - int eccbytes; 166 - 167 - chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) * 168 - (chip->ecc.strength / 8); 169 - 170 - switch (chip->ecc.mode) { 171 - case NAND_ECC_HW: 172 - if (!nfc->bch) { 173 - dev_err(nfc->dev, 174 - "HW BCH selected, but BCH controller not found\n"); 175 - return -ENODEV; 176 - } 177 - 178 - chip->ecc.hwctl = jz4780_nand_ecc_hwctl; 179 - chip->ecc.calculate = jz4780_nand_ecc_calculate; 180 - chip->ecc.correct = jz4780_nand_ecc_correct; 181 - /* fall through */ 182 - case NAND_ECC_SOFT: 183 - dev_info(nfc->dev, "using %s (strength %d, size %d, bytes %d)\n", 184 - (nfc->bch) ? "hardware BCH" : "software ECC", 185 - chip->ecc.strength, chip->ecc.size, chip->ecc.bytes); 186 - break; 187 - case NAND_ECC_NONE: 188 - dev_info(nfc->dev, "not using ECC\n"); 189 - break; 190 - default: 191 - dev_err(nfc->dev, "ECC mode %d not supported\n", 192 - chip->ecc.mode); 193 - return -EINVAL; 194 - } 195 - 196 - /* The NAND core will generate the ECC layout for SW ECC */ 197 - if (chip->ecc.mode != NAND_ECC_HW) 198 - return 0; 199 - 200 - /* Generate ECC layout. ECC codes are right aligned in the OOB area. */ 201 - eccbytes = mtd->writesize / chip->ecc.size * chip->ecc.bytes; 202 - 203 - if (eccbytes > mtd->oobsize - 2) { 204 - dev_err(nfc->dev, 205 - "invalid ECC config: required %d ECC bytes, but only %d are available", 206 - eccbytes, mtd->oobsize - 2); 207 - return -EINVAL; 208 - } 209 - 210 - mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops); 211 - 212 - return 0; 213 - } 214 - 215 - static const struct nand_controller_ops jz4780_nand_controller_ops = { 216 - .attach_chip = jz4780_nand_attach_chip, 217 - }; 218 - 219 - static int jz4780_nand_init_chip(struct platform_device *pdev, 220 - struct jz4780_nand_controller *nfc, 221 - struct device_node *np, 222 - unsigned int chipnr) 223 - { 224 - struct device *dev = &pdev->dev; 225 - struct jz4780_nand_chip *nand; 226 - struct jz4780_nand_cs *cs; 227 - struct resource *res; 228 - struct nand_chip *chip; 229 - struct mtd_info *mtd; 230 - const __be32 *reg; 231 - int ret = 0; 232 - 233 - cs = &nfc->cs[chipnr]; 234 - 235 - reg = of_get_property(np, "reg", NULL); 236 - if (!reg) 237 - return -EINVAL; 238 - 239 - cs->bank = be32_to_cpu(*reg); 240 - 241 - jz4780_nemc_set_type(nfc->dev, cs->bank, JZ4780_NEMC_BANK_NAND); 242 - 243 - res = platform_get_resource(pdev, IORESOURCE_MEM, chipnr); 244 - cs->base = devm_ioremap_resource(dev, res); 245 - if (IS_ERR(cs->base)) 246 - return PTR_ERR(cs->base); 247 - 248 - nand = devm_kzalloc(dev, sizeof(*nand), GFP_KERNEL); 249 - if (!nand) 250 - return -ENOMEM; 251 - 252 - nand->busy_gpio = devm_gpiod_get_optional(dev, "rb", GPIOD_IN); 253 - 254 - if (IS_ERR(nand->busy_gpio)) { 255 - ret = PTR_ERR(nand->busy_gpio); 256 - dev_err(dev, "failed to request busy GPIO: %d\n", ret); 257 - return ret; 258 - } else if (nand->busy_gpio) { 259 - nand->chip.legacy.dev_ready = jz4780_nand_dev_ready; 260 - } 261 - 262 - nand->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_LOW); 263 - 264 - if (IS_ERR(nand->wp_gpio)) { 265 - ret = PTR_ERR(nand->wp_gpio); 266 - dev_err(dev, "failed to request WP GPIO: %d\n", ret); 267 - return ret; 268 - } 269 - 270 - chip = &nand->chip; 271 - mtd = nand_to_mtd(chip); 272 - mtd->name = devm_kasprintf(dev, GFP_KERNEL, "%s.%d", dev_name(dev), 273 - cs->bank); 274 - if (!mtd->name) 275 - return -ENOMEM; 276 - mtd->dev.parent = dev; 277 - 278 - chip->legacy.IO_ADDR_R = cs->base + OFFSET_DATA; 279 - chip->legacy.IO_ADDR_W = cs->base + OFFSET_DATA; 280 - chip->legacy.chip_delay = RB_DELAY_US; 281 - chip->options = NAND_NO_SUBPAGE_WRITE; 282 - chip->legacy.select_chip = jz4780_nand_select_chip; 283 - chip->legacy.cmd_ctrl = jz4780_nand_cmd_ctrl; 284 - chip->ecc.mode = NAND_ECC_HW; 285 - chip->controller = &nfc->controller; 286 - nand_set_flash_node(chip, np); 287 - 288 - chip->controller->ops = &jz4780_nand_controller_ops; 289 - ret = nand_scan(chip, 1); 290 - if (ret) 291 - return ret; 292 - 293 - ret = mtd_device_register(mtd, NULL, 0); 294 - if (ret) { 295 - nand_release(chip); 296 - return ret; 297 - } 298 - 299 - list_add_tail(&nand->chip_list, &nfc->chips); 300 - 301 - return 0; 302 - } 303 - 304 - static void jz4780_nand_cleanup_chips(struct jz4780_nand_controller *nfc) 305 - { 306 - struct jz4780_nand_chip *chip; 307 - 308 - while (!list_empty(&nfc->chips)) { 309 - chip = list_first_entry(&nfc->chips, struct jz4780_nand_chip, chip_list); 310 - nand_release(&chip->chip); 311 - list_del(&chip->chip_list); 312 - } 313 - } 314 - 315 - static int jz4780_nand_init_chips(struct jz4780_nand_controller *nfc, 316 - struct platform_device *pdev) 317 - { 318 - struct device *dev = &pdev->dev; 319 - struct device_node *np; 320 - int i = 0; 321 - int ret; 322 - int num_chips = of_get_child_count(dev->of_node); 323 - 324 - if (num_chips > nfc->num_banks) { 325 - dev_err(dev, "found %d chips but only %d banks\n", num_chips, nfc->num_banks); 326 - return -EINVAL; 327 - } 328 - 329 - for_each_child_of_node(dev->of_node, np) { 330 - ret = jz4780_nand_init_chip(pdev, nfc, np, i); 331 - if (ret) { 332 - jz4780_nand_cleanup_chips(nfc); 333 - return ret; 334 - } 335 - 336 - i++; 337 - } 338 - 339 - return 0; 340 - } 341 - 342 - static int jz4780_nand_probe(struct platform_device *pdev) 343 - { 344 - struct device *dev = &pdev->dev; 345 - unsigned int num_banks; 346 - struct jz4780_nand_controller *nfc; 347 - int ret; 348 - 349 - num_banks = jz4780_nemc_num_banks(dev); 350 - if (num_banks == 0) { 351 - dev_err(dev, "no banks found\n"); 352 - return -ENODEV; 353 - } 354 - 355 - nfc = devm_kzalloc(dev, struct_size(nfc, cs, num_banks), GFP_KERNEL); 356 - if (!nfc) 357 - return -ENOMEM; 358 - 359 - /* 360 - * Check for BCH HW before we call nand_scan_ident, to prevent us from 361 - * having to call it again if the BCH driver returns -EPROBE_DEFER. 362 - */ 363 - nfc->bch = of_jz4780_bch_get(dev->of_node); 364 - if (IS_ERR(nfc->bch)) 365 - return PTR_ERR(nfc->bch); 366 - 367 - nfc->dev = dev; 368 - nfc->num_banks = num_banks; 369 - 370 - nand_controller_init(&nfc->controller); 371 - INIT_LIST_HEAD(&nfc->chips); 372 - 373 - ret = jz4780_nand_init_chips(nfc, pdev); 374 - if (ret) { 375 - if (nfc->bch) 376 - jz4780_bch_release(nfc->bch); 377 - return ret; 378 - } 379 - 380 - platform_set_drvdata(pdev, nfc); 381 - return 0; 382 - } 383 - 384 - static int jz4780_nand_remove(struct platform_device *pdev) 385 - { 386 - struct jz4780_nand_controller *nfc = platform_get_drvdata(pdev); 387 - 388 - if (nfc->bch) 389 - jz4780_bch_release(nfc->bch); 390 - 391 - jz4780_nand_cleanup_chips(nfc); 392 - 393 - return 0; 394 - } 395 - 396 - static const struct of_device_id jz4780_nand_dt_match[] = { 397 - { .compatible = "ingenic,jz4780-nand" }, 398 - {}, 399 - }; 400 - MODULE_DEVICE_TABLE(of, jz4780_nand_dt_match); 401 - 402 - static struct platform_driver jz4780_nand_driver = { 403 - .probe = jz4780_nand_probe, 404 - .remove = jz4780_nand_remove, 405 - .driver = { 406 - .name = DRV_NAME, 407 - .of_match_table = of_match_ptr(jz4780_nand_dt_match), 408 - }, 409 - }; 410 - module_platform_driver(jz4780_nand_driver); 411 - 412 - MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); 413 - MODULE_AUTHOR("Harvey Hunt <harveyhuntnexus@gmail.com>"); 414 - MODULE_DESCRIPTION("Ingenic JZ4780 NAND driver"); 415 - MODULE_LICENSE("GPL v2");
+21 -30
drivers/mtd/nand/raw/marvell_nand.c
··· 1083 1083 */ 1084 1084 static int marvell_nfc_hw_ecc_hmg_read_oob_raw(struct nand_chip *chip, int page) 1085 1085 { 1086 - /* Invalidate page cache */ 1087 - chip->pagebuf = -1; 1086 + u8 *buf = nand_get_data_buf(chip); 1088 1087 1089 1088 marvell_nfc_select_target(chip, chip->cur_cs); 1090 - return marvell_nfc_hw_ecc_hmg_do_read_page(chip, chip->data_buf, 1091 - chip->oob_poi, true, page); 1089 + return marvell_nfc_hw_ecc_hmg_do_read_page(chip, buf, chip->oob_poi, 1090 + true, page); 1092 1091 } 1093 1092 1094 1093 /* Hamming write helpers */ ··· 1178 1179 int page) 1179 1180 { 1180 1181 struct mtd_info *mtd = nand_to_mtd(chip); 1182 + u8 *buf = nand_get_data_buf(chip); 1181 1183 1182 - /* Invalidate page cache */ 1183 - chip->pagebuf = -1; 1184 - 1185 - memset(chip->data_buf, 0xFF, mtd->writesize); 1184 + memset(buf, 0xFF, mtd->writesize); 1186 1185 1187 1186 marvell_nfc_select_target(chip, chip->cur_cs); 1188 - return marvell_nfc_hw_ecc_hmg_do_write_page(chip, chip->data_buf, 1189 - chip->oob_poi, true, page); 1187 + return marvell_nfc_hw_ecc_hmg_do_write_page(chip, buf, chip->oob_poi, 1188 + true, page); 1190 1189 } 1191 1190 1192 1191 /* BCH read helpers */ ··· 1431 1434 1432 1435 static int marvell_nfc_hw_ecc_bch_read_oob_raw(struct nand_chip *chip, int page) 1433 1436 { 1434 - /* Invalidate page cache */ 1435 - chip->pagebuf = -1; 1437 + u8 *buf = nand_get_data_buf(chip); 1436 1438 1437 - return chip->ecc.read_page_raw(chip, chip->data_buf, true, page); 1439 + return chip->ecc.read_page_raw(chip, buf, true, page); 1438 1440 } 1439 1441 1440 1442 static int marvell_nfc_hw_ecc_bch_read_oob(struct nand_chip *chip, int page) 1441 1443 { 1442 - /* Invalidate page cache */ 1443 - chip->pagebuf = -1; 1444 + u8 *buf = nand_get_data_buf(chip); 1444 1445 1445 - return chip->ecc.read_page(chip, chip->data_buf, true, page); 1446 + return chip->ecc.read_page(chip, buf, true, page); 1446 1447 } 1447 1448 1448 1449 /* BCH write helpers */ ··· 1614 1619 int page) 1615 1620 { 1616 1621 struct mtd_info *mtd = nand_to_mtd(chip); 1622 + u8 *buf = nand_get_data_buf(chip); 1617 1623 1618 - /* Invalidate page cache */ 1619 - chip->pagebuf = -1; 1624 + memset(buf, 0xFF, mtd->writesize); 1620 1625 1621 - memset(chip->data_buf, 0xFF, mtd->writesize); 1622 - 1623 - return chip->ecc.write_page_raw(chip, chip->data_buf, true, page); 1626 + return chip->ecc.write_page_raw(chip, buf, true, page); 1624 1627 } 1625 1628 1626 1629 static int marvell_nfc_hw_ecc_bch_write_oob(struct nand_chip *chip, int page) 1627 1630 { 1628 1631 struct mtd_info *mtd = nand_to_mtd(chip); 1632 + u8 *buf = nand_get_data_buf(chip); 1629 1633 1630 - /* Invalidate page cache */ 1631 - chip->pagebuf = -1; 1634 + memset(buf, 0xFF, mtd->writesize); 1632 1635 1633 - memset(chip->data_buf, 0xFF, mtd->writesize); 1634 - 1635 - return chip->ecc.write_page(chip, chip->data_buf, true, page); 1636 + return chip->ecc.write_page(chip, buf, true, page); 1636 1637 } 1637 1638 1638 1639 /* NAND framework ->exec_op() hooks and related helpers */ ··· 2248 2257 int ret; 2249 2258 2250 2259 if (ecc->mode != NAND_ECC_NONE && (!ecc->size || !ecc->strength)) { 2251 - if (chip->ecc_step_ds && chip->ecc_strength_ds) { 2252 - ecc->size = chip->ecc_step_ds; 2253 - ecc->strength = chip->ecc_strength_ds; 2260 + if (chip->base.eccreq.step_size && chip->base.eccreq.strength) { 2261 + ecc->size = chip->base.eccreq.step_size; 2262 + ecc->strength = chip->base.eccreq.strength; 2254 2263 } else { 2255 2264 dev_info(nfc->dev, 2256 2265 "No minimum ECC strength, using 1b/512B\n"); ··· 2980 2989 2981 2990 /* 2982 2991 * Reset nfc->selected_chip so the next command will cause the timing 2983 - * registers to be restored in marvell_nfc_select_chip(). 2992 + * registers to be restored in marvell_nfc_select_target(). 2984 2993 */ 2985 2994 nfc->selected_chip = NULL; 2986 2995
+17 -13
drivers/mtd/nand/raw/meson_nand.c
··· 400 400 cfg |= NFC_RB_IRQ_EN; 401 401 writel(cfg, nfc->reg_base + NFC_REG_CFG); 402 402 403 - init_completion(&nfc->completion); 403 + reinit_completion(&nfc->completion); 404 404 405 405 /* use the max erase time as the maximum clock for waiting R/B */ 406 406 cmd = NFC_CMD_RB | NFC_CMD_RB_INT ··· 470 470 return ret; 471 471 } 472 472 473 - static int meson_nfc_dma_buffer_setup(struct nand_chip *nand, u8 *databuf, 474 - int datalen, u8 *infobuf, int infolen, 473 + static int meson_nfc_dma_buffer_setup(struct nand_chip *nand, void *databuf, 474 + int datalen, void *infobuf, int infolen, 475 475 enum dma_data_direction dir) 476 476 { 477 477 struct meson_nfc *nfc = nand_get_controller_data(nand); 478 478 u32 cmd; 479 479 int ret = 0; 480 480 481 - nfc->daddr = dma_map_single(nfc->dev, (void *)databuf, datalen, dir); 481 + nfc->daddr = dma_map_single(nfc->dev, databuf, datalen, dir); 482 482 ret = dma_mapping_error(nfc->dev, nfc->daddr); 483 483 if (ret) { 484 484 dev_err(nfc->dev, "DMA mapping error\n"); ··· 528 528 u8 *info; 529 529 530 530 info = kzalloc(PER_INFO_BYTE, GFP_KERNEL); 531 + if (!info) 532 + return -ENOMEM; 533 + 531 534 ret = meson_nfc_dma_buffer_setup(nand, buf, len, info, 532 535 PER_INFO_BYTE, DMA_FROM_DEVICE); 533 536 if (ret) 534 - return ret; 537 + goto out; 535 538 536 539 cmd = NFC_CMD_N2M | (len & GENMASK(5, 0)); 537 540 writel(cmd, nfc->reg_base + NFC_REG_CMD); ··· 542 539 meson_nfc_drain_cmd(nfc); 543 540 meson_nfc_wait_cmd_finish(nfc, 1000); 544 541 meson_nfc_dma_buffer_release(nand, len, PER_INFO_BYTE, DMA_FROM_DEVICE); 542 + 543 + out: 545 544 kfree(info); 546 545 547 546 return ret; ··· 645 640 return ret; 646 641 647 642 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, 648 - data_len, (u8 *)meson_chip->info_buf, 643 + data_len, meson_chip->info_buf, 649 644 info_len, DMA_TO_DEVICE); 650 645 if (ret) 651 646 return ret; ··· 729 724 return ret; 730 725 731 726 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, 732 - data_len, (u8 *)meson_chip->info_buf, 727 + data_len, meson_chip->info_buf, 733 728 info_len, DMA_FROM_DEVICE); 734 729 if (ret) 735 730 return ret; ··· 1188 1183 return -EINVAL; 1189 1184 } 1190 1185 1186 + mtd_set_ooblayout(mtd, &meson_ooblayout_ops); 1187 + 1191 1188 ret = meson_nand_bch_mode(nand); 1192 1189 if (ret) 1193 1190 return -EINVAL; ··· 1233 1226 int ret, i; 1234 1227 u32 tmp, nsels; 1235 1228 1236 - if (!of_get_property(np, "reg", &nsels)) 1237 - return -EINVAL; 1238 - 1239 - nsels /= sizeof(u32); 1229 + nsels = of_property_count_elems_of_size(np, "reg", sizeof(u32)); 1240 1230 if (!nsels || nsels > MAX_CE_NUM) { 1241 1231 dev_err(dev, "invalid register property size\n"); 1242 1232 return -EINVAL; 1243 1233 } 1244 1234 1245 - meson_chip = devm_kzalloc(dev, 1246 - sizeof(*meson_chip) + (nsels * sizeof(u8)), 1235 + meson_chip = devm_kzalloc(dev, struct_size(meson_chip, sels, nsels), 1247 1236 GFP_KERNEL); 1248 1237 if (!meson_chip) 1249 1238 return -ENOMEM; ··· 1380 1377 1381 1378 nand_controller_init(&nfc->controller); 1382 1379 INIT_LIST_HEAD(&nfc->chips); 1380 + init_completion(&nfc->completion); 1383 1381 1384 1382 nfc->dev = dev; 1385 1383
+2 -2
drivers/mtd/nand/raw/mtk_nand.c
··· 1197 1197 /* if optional dt settings not present */ 1198 1198 if (!nand->ecc.size || !nand->ecc.strength) { 1199 1199 /* use datasheet requirements */ 1200 - nand->ecc.strength = nand->ecc_strength_ds; 1201 - nand->ecc.size = nand->ecc_step_ds; 1200 + nand->ecc.strength = nand->base.eccreq.strength; 1201 + nand->ecc.size = nand->base.eccreq.step_size; 1202 1202 1203 1203 /* 1204 1204 * align eccstrength and eccsize
+15 -4
drivers/mtd/nand/raw/nand_amd.c
··· 20 20 static void amd_nand_decode_id(struct nand_chip *chip) 21 21 { 22 22 struct mtd_info *mtd = nand_to_mtd(chip); 23 + struct nand_memory_organization *memorg; 24 + 25 + memorg = nanddev_get_memorg(&chip->base); 23 26 24 27 nand_decode_ext_id(chip); 25 28 ··· 34 31 */ 35 32 if (chip->id.data[4] != 0x00 && chip->id.data[5] == 0x00 && 36 33 chip->id.data[6] == 0x00 && chip->id.data[7] == 0x00 && 37 - mtd->writesize == 512) { 38 - mtd->erasesize = 128 * 1024; 39 - mtd->erasesize <<= ((chip->id.data[3] & 0x03) << 1); 34 + memorg->pagesize == 512) { 35 + memorg->pages_per_eraseblock = 256; 36 + memorg->pages_per_eraseblock <<= ((chip->id.data[3] & 0x03) << 1); 37 + mtd->erasesize = memorg->pages_per_eraseblock * 38 + memorg->pagesize; 40 39 } 41 40 } 42 41 43 42 static int amd_nand_init(struct nand_chip *chip) 44 43 { 45 44 if (nand_is_slc(chip)) 46 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 45 + /* 46 + * According to the datasheet of some Cypress SLC NANDs, 47 + * the bad block markers can be in the first, second or last 48 + * page of a block. So let's check all three locations. 49 + */ 50 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE | 51 + NAND_BBM_LASTPAGE; 47 52 48 53 return 0; 49 54 }
+203 -123
drivers/mtd/nand/raw/nand_base.c
··· 240 240 void nand_select_target(struct nand_chip *chip, unsigned int cs) 241 241 { 242 242 /* 243 - * cs should always lie between 0 and chip->numchips, when that's not 244 - * the case it's a bug and the caller should be fixed. 243 + * cs should always lie between 0 and nanddev_ntargets(), when that's 244 + * not the case it's a bug and the caller should be fixed. 245 245 */ 246 - if (WARN_ON(cs > chip->numchips)) 246 + if (WARN_ON(cs > nanddev_ntargets(&chip->base))) 247 247 return; 248 248 249 249 chip->cur_cs = cs; ··· 283 283 } 284 284 285 285 /** 286 + * nand_bbm_get_next_page - Get the next page for bad block markers 287 + * @chip: NAND chip object 288 + * @page: First page to start checking for bad block marker usage 289 + * 290 + * Returns an integer that corresponds to the page offset within a block, for 291 + * a page that is used to store bad block markers. If no more pages are 292 + * available, -EINVAL is returned. 293 + */ 294 + int nand_bbm_get_next_page(struct nand_chip *chip, int page) 295 + { 296 + struct mtd_info *mtd = nand_to_mtd(chip); 297 + int last_page = ((mtd->erasesize - mtd->writesize) >> 298 + chip->page_shift) & chip->pagemask; 299 + 300 + if (page == 0 && chip->options & NAND_BBM_FIRSTPAGE) 301 + return 0; 302 + else if (page <= 1 && chip->options & NAND_BBM_SECONDPAGE) 303 + return 1; 304 + else if (page <= last_page && chip->options & NAND_BBM_LASTPAGE) 305 + return last_page; 306 + 307 + return -EINVAL; 308 + } 309 + 310 + /** 286 311 * nand_block_bad - [DEFAULT] Read bad block marker from the chip 287 312 * @chip: NAND chip object 288 313 * @ofs: offset from device start ··· 316 291 */ 317 292 static int nand_block_bad(struct nand_chip *chip, loff_t ofs) 318 293 { 319 - struct mtd_info *mtd = nand_to_mtd(chip); 320 - int page, page_end, res; 294 + int first_page, page_offset; 295 + int res; 321 296 u8 bad; 322 297 323 - if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) 324 - ofs += mtd->erasesize - mtd->writesize; 298 + first_page = (int)(ofs >> chip->page_shift) & chip->pagemask; 299 + page_offset = nand_bbm_get_next_page(chip, 0); 325 300 326 - page = (int)(ofs >> chip->page_shift) & chip->pagemask; 327 - page_end = page + (chip->bbt_options & NAND_BBT_SCAN2NDPAGE ? 2 : 1); 328 - 329 - for (; page < page_end; page++) { 330 - res = chip->ecc.read_oob(chip, page); 301 + while (page_offset >= 0) { 302 + res = chip->ecc.read_oob(chip, first_page + page_offset); 331 303 if (res < 0) 332 304 return res; 333 305 ··· 336 314 res = hweight8(bad) < chip->badblockbits; 337 315 if (res) 338 316 return res; 317 + 318 + page_offset = nand_bbm_get_next_page(chip, page_offset + 1); 339 319 } 340 320 341 321 return 0; ··· 483 459 } 484 460 485 461 /* Invalidate the page cache, if we write to the cached page */ 486 - if (page == chip->pagebuf) 487 - chip->pagebuf = -1; 462 + if (page == chip->pagecache.page) 463 + chip->pagecache.page = -1; 488 464 489 465 nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); 490 466 ··· 517 493 struct mtd_info *mtd = nand_to_mtd(chip); 518 494 struct mtd_oob_ops ops; 519 495 uint8_t buf[2] = { 0, 0 }; 520 - int ret = 0, res, i = 0; 496 + int ret = 0, res, page_offset; 521 497 522 498 memset(&ops, 0, sizeof(ops)); 523 499 ops.oobbuf = buf; ··· 530 506 } 531 507 ops.mode = MTD_OPS_PLACE_OOB; 532 508 533 - /* Write to first/last page(s) if necessary */ 534 - if (chip->bbt_options & NAND_BBT_SCANLASTPAGE) 535 - ofs += mtd->erasesize - mtd->writesize; 536 - do { 537 - res = nand_do_write_oob(chip, ofs, &ops); 509 + page_offset = nand_bbm_get_next_page(chip, 0); 510 + 511 + while (page_offset >= 0) { 512 + res = nand_do_write_oob(chip, 513 + ofs + (page_offset * mtd->writesize), 514 + &ops); 515 + 538 516 if (!ret) 539 517 ret = res; 540 518 541 - i++; 542 - ofs += mtd->writesize; 543 - } while ((chip->bbt_options & NAND_BBT_SCAN2NDPAGE) && i < 2); 519 + page_offset = nand_bbm_get_next_page(chip, page_offset + 1); 520 + } 544 521 545 522 return ret; 546 523 } ··· 3198 3173 use_bufpoi = 0; 3199 3174 3200 3175 /* Is the current page in the buffer? */ 3201 - if (realpage != chip->pagebuf || oob) { 3176 + if (realpage != chip->pagecache.page || oob) { 3202 3177 bufpoi = use_bufpoi ? chip->data_buf : buf; 3203 3178 3204 3179 if (use_bufpoi && aligned) ··· 3224 3199 if (ret < 0) { 3225 3200 if (use_bufpoi) 3226 3201 /* Invalidate page cache */ 3227 - chip->pagebuf = -1; 3202 + chip->pagecache.page = -1; 3228 3203 break; 3229 3204 } 3230 3205 ··· 3233 3208 if (!NAND_HAS_SUBPAGE_READ(chip) && !oob && 3234 3209 !(mtd->ecc_stats.failed - ecc_failures) && 3235 3210 (ops->mode != MTD_OPS_RAW)) { 3236 - chip->pagebuf = realpage; 3237 - chip->pagebuf_bitflips = ret; 3211 + chip->pagecache.page = realpage; 3212 + chip->pagecache.bitflips = ret; 3238 3213 } else { 3239 3214 /* Invalidate page cache */ 3240 - chip->pagebuf = -1; 3215 + chip->pagecache.page = -1; 3241 3216 } 3242 3217 memcpy(buf, chip->data_buf + col, bytes); 3243 3218 } ··· 3277 3252 memcpy(buf, chip->data_buf + col, bytes); 3278 3253 buf += bytes; 3279 3254 max_bitflips = max_t(unsigned int, max_bitflips, 3280 - chip->pagebuf_bitflips); 3255 + chip->pagecache.bitflips); 3281 3256 } 3282 3257 3283 3258 readlen -= bytes; ··· 3998 3973 page = realpage & chip->pagemask; 3999 3974 4000 3975 /* Invalidate the page cache, when we write to the cached page */ 4001 - if (to <= ((loff_t)chip->pagebuf << chip->page_shift) && 4002 - ((loff_t)chip->pagebuf << chip->page_shift) < (to + ops->len)) 4003 - chip->pagebuf = -1; 3976 + if (to <= ((loff_t)chip->pagecache.page << chip->page_shift) && 3977 + ((loff_t)chip->pagecache.page << chip->page_shift) < (to + ops->len)) 3978 + chip->pagecache.page = -1; 4004 3979 4005 3980 /* Don't allow multipage oob writes with offset */ 4006 3981 if (oob && ops->ooboffs && (ops->ooboffs + ops->ooblen > oobmaxlen)) { ··· 4029 4004 __func__, buf); 4030 4005 if (part_pagewr) 4031 4006 bytes = min_t(int, bytes - column, writelen); 4032 - chip->pagebuf = -1; 4033 - memset(chip->data_buf, 0xff, mtd->writesize); 4034 - memcpy(&chip->data_buf[column], buf, bytes); 4035 - wbuf = chip->data_buf; 4007 + wbuf = nand_get_data_buf(chip); 4008 + memset(wbuf, 0xff, mtd->writesize); 4009 + memcpy(&wbuf[column], buf, bytes); 4036 4010 } 4037 4011 4038 4012 if (unlikely(oob)) { ··· 4221 4197 * Invalidate the page cache, if we erase the block which 4222 4198 * contains the current cached page. 4223 4199 */ 4224 - if (page <= chip->pagebuf && chip->pagebuf < 4200 + if (page <= chip->pagecache.page && chip->pagecache.page < 4225 4201 (page + pages_per_block)) 4226 - chip->pagebuf = -1; 4202 + chip->pagecache.page = -1; 4227 4203 4228 4204 ret = nand_erase_op(chip, (page & chip->pagemask) >> 4229 4205 (chip->phys_erase_shift - chip->page_shift)); ··· 4320 4296 } 4321 4297 4322 4298 return nand_block_markbad_lowlevel(mtd_to_nand(mtd), ofs); 4323 - } 4324 - 4325 - /** 4326 - * nand_max_bad_blocks - [MTD Interface] Max number of bad blocks for an mtd 4327 - * @mtd: MTD device structure 4328 - * @ofs: offset relative to mtd start 4329 - * @len: length of mtd 4330 - */ 4331 - static int nand_max_bad_blocks(struct mtd_info *mtd, loff_t ofs, size_t len) 4332 - { 4333 - struct nand_chip *chip = mtd_to_nand(mtd); 4334 - u32 part_start_block; 4335 - u32 part_end_block; 4336 - u32 part_start_die; 4337 - u32 part_end_die; 4338 - 4339 - /* 4340 - * max_bb_per_die and blocks_per_die used to determine 4341 - * the maximum bad block count. 4342 - */ 4343 - if (!chip->max_bb_per_die || !chip->blocks_per_die) 4344 - return -ENOTSUPP; 4345 - 4346 - /* Get the start and end of the partition in erase blocks. */ 4347 - part_start_block = mtd_div_by_eb(ofs, mtd); 4348 - part_end_block = mtd_div_by_eb(len, mtd) + part_start_block - 1; 4349 - 4350 - /* Get the start and end LUNs of the partition. */ 4351 - part_start_die = part_start_block / chip->blocks_per_die; 4352 - part_end_die = part_end_block / chip->blocks_per_die; 4353 - 4354 - /* 4355 - * Look up the bad blocks per unit and multiply by the number of units 4356 - * that the partition spans. 4357 - */ 4358 - return chip->max_bb_per_die * (part_end_die - part_start_die + 1); 4359 4299 } 4360 4300 4361 4301 /** ··· 4473 4485 */ 4474 4486 void nand_decode_ext_id(struct nand_chip *chip) 4475 4487 { 4488 + struct nand_memory_organization *memorg; 4476 4489 struct mtd_info *mtd = nand_to_mtd(chip); 4477 4490 int extid; 4478 4491 u8 *id_data = chip->id.data; 4492 + 4493 + memorg = nanddev_get_memorg(&chip->base); 4494 + 4479 4495 /* The 3rd id byte holds MLC / multichip data */ 4480 - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); 4496 + memorg->bits_per_cell = nand_get_bits_per_cell(id_data[2]); 4481 4497 /* The 4th id byte is the important one */ 4482 4498 extid = id_data[3]; 4483 4499 4484 4500 /* Calc pagesize */ 4485 - mtd->writesize = 1024 << (extid & 0x03); 4501 + memorg->pagesize = 1024 << (extid & 0x03); 4502 + mtd->writesize = memorg->pagesize; 4486 4503 extid >>= 2; 4487 4504 /* Calc oobsize */ 4488 - mtd->oobsize = (8 << (extid & 0x01)) * (mtd->writesize >> 9); 4505 + memorg->oobsize = (8 << (extid & 0x01)) * (mtd->writesize >> 9); 4506 + mtd->oobsize = memorg->oobsize; 4489 4507 extid >>= 2; 4490 4508 /* Calc blocksize. Blocksize is multiples of 64KiB */ 4509 + memorg->pages_per_eraseblock = ((64 * 1024) << (extid & 0x03)) / 4510 + memorg->pagesize; 4491 4511 mtd->erasesize = (64 * 1024) << (extid & 0x03); 4492 4512 extid >>= 2; 4493 4513 /* Get buswidth information */ ··· 4512 4516 static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) 4513 4517 { 4514 4518 struct mtd_info *mtd = nand_to_mtd(chip); 4519 + struct nand_memory_organization *memorg; 4515 4520 4521 + memorg = nanddev_get_memorg(&chip->base); 4522 + 4523 + memorg->pages_per_eraseblock = type->erasesize / type->pagesize; 4516 4524 mtd->erasesize = type->erasesize; 4517 - mtd->writesize = type->pagesize; 4518 - mtd->oobsize = mtd->writesize / 32; 4525 + memorg->pagesize = type->pagesize; 4526 + mtd->writesize = memorg->pagesize; 4527 + memorg->oobsize = memorg->pagesize / 32; 4528 + mtd->oobsize = memorg->oobsize; 4519 4529 4520 4530 /* All legacy ID NAND are small-page, SLC */ 4521 - chip->bits_per_cell = 1; 4531 + memorg->bits_per_cell = 1; 4522 4532 } 4523 4533 4524 4534 /* ··· 4538 4536 4539 4537 /* Set the bad block position */ 4540 4538 if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) 4541 - chip->badblockpos = NAND_LARGE_BADBLOCK_POS; 4539 + chip->badblockpos = NAND_BBM_POS_LARGE; 4542 4540 else 4543 - chip->badblockpos = NAND_SMALL_BADBLOCK_POS; 4541 + chip->badblockpos = NAND_BBM_POS_SMALL; 4544 4542 } 4545 4543 4546 4544 static inline bool is_full_id_nand(struct nand_flash_dev *type) ··· 4552 4550 struct nand_flash_dev *type) 4553 4551 { 4554 4552 struct mtd_info *mtd = nand_to_mtd(chip); 4553 + struct nand_memory_organization *memorg; 4555 4554 u8 *id_data = chip->id.data; 4556 4555 4557 - if (!strncmp(type->id, id_data, type->id_len)) { 4558 - mtd->writesize = type->pagesize; 4559 - mtd->erasesize = type->erasesize; 4560 - mtd->oobsize = type->oobsize; 4556 + memorg = nanddev_get_memorg(&chip->base); 4561 4557 4562 - chip->bits_per_cell = nand_get_bits_per_cell(id_data[2]); 4563 - chip->chipsize = (uint64_t)type->chipsize << 20; 4558 + if (!strncmp(type->id, id_data, type->id_len)) { 4559 + memorg->pagesize = type->pagesize; 4560 + mtd->writesize = memorg->pagesize; 4561 + memorg->pages_per_eraseblock = type->erasesize / 4562 + type->pagesize; 4563 + mtd->erasesize = type->erasesize; 4564 + memorg->oobsize = type->oobsize; 4565 + mtd->oobsize = memorg->oobsize; 4566 + 4567 + memorg->bits_per_cell = nand_get_bits_per_cell(id_data[2]); 4568 + memorg->eraseblocks_per_lun = 4569 + DIV_ROUND_DOWN_ULL((u64)type->chipsize << 20, 4570 + memorg->pagesize * 4571 + memorg->pages_per_eraseblock); 4564 4572 chip->options |= type->options; 4565 - chip->ecc_strength_ds = NAND_ECC_STRENGTH(type); 4566 - chip->ecc_step_ds = NAND_ECC_STEP(type); 4573 + chip->base.eccreq.strength = NAND_ECC_STRENGTH(type); 4574 + chip->base.eccreq.step_size = NAND_ECC_STEP(type); 4567 4575 chip->onfi_timing_mode_default = 4568 4576 type->onfi_timing_mode_default; 4569 4577 ··· 4599 4587 */ 4600 4588 if (chip->manufacturer.desc && chip->manufacturer.desc->ops && 4601 4589 chip->manufacturer.desc->ops->detect) { 4590 + struct nand_memory_organization *memorg; 4591 + 4592 + memorg = nanddev_get_memorg(&chip->base); 4593 + 4602 4594 /* The 3rd id byte holds MLC / multichip data */ 4603 - chip->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); 4595 + memorg->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); 4604 4596 chip->manufacturer.desc->ops->detect(chip); 4605 4597 } else { 4606 4598 nand_decode_ext_id(chip); ··· 4653 4637 { 4654 4638 const struct nand_manufacturer *manufacturer; 4655 4639 struct mtd_info *mtd = nand_to_mtd(chip); 4640 + struct nand_memory_organization *memorg; 4656 4641 int busw, ret; 4657 4642 u8 *id_data = chip->id.data; 4658 4643 u8 maf_id, dev_id; 4644 + u64 targetsize; 4645 + 4646 + /* 4647 + * Let's start by initializing memorg fields that might be left 4648 + * unassigned by the ID-based detection logic. 4649 + */ 4650 + memorg = nanddev_get_memorg(&chip->base); 4651 + memorg->planes_per_lun = 1; 4652 + memorg->luns_per_target = 1; 4653 + memorg->ntargets = 1; 4659 4654 4660 4655 /* 4661 4656 * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) ··· 4762 4735 if (!chip->parameters.model) 4763 4736 return -ENOMEM; 4764 4737 4765 - chip->chipsize = (uint64_t)type->chipsize << 20; 4766 - 4767 4738 if (!type->pagesize) 4768 4739 nand_manufacturer_detect(chip); 4769 4740 else ··· 4769 4744 4770 4745 /* Get chip options */ 4771 4746 chip->options |= type->options; 4747 + 4748 + memorg->eraseblocks_per_lun = 4749 + DIV_ROUND_DOWN_ULL((u64)type->chipsize << 20, 4750 + memorg->pagesize * 4751 + memorg->pages_per_eraseblock); 4772 4752 4773 4753 ident_done: 4774 4754 if (!mtd->name) ··· 4803 4773 /* Calculate the address shift from the page size */ 4804 4774 chip->page_shift = ffs(mtd->writesize) - 1; 4805 4775 /* Convert chipsize to number of pages per chip -1 */ 4806 - chip->pagemask = (chip->chipsize >> chip->page_shift) - 1; 4776 + targetsize = nanddev_target_size(&chip->base); 4777 + chip->pagemask = (targetsize >> chip->page_shift) - 1; 4807 4778 4808 4779 chip->bbt_erase_shift = chip->phys_erase_shift = 4809 4780 ffs(mtd->erasesize) - 1; 4810 - if (chip->chipsize & 0xffffffff) 4811 - chip->chip_shift = ffs((unsigned)chip->chipsize) - 1; 4781 + if (targetsize & 0xffffffff) 4782 + chip->chip_shift = ffs((unsigned)targetsize) - 1; 4812 4783 else { 4813 - chip->chip_shift = ffs((unsigned)(chip->chipsize >> 32)); 4784 + chip->chip_shift = ffs((unsigned)(targetsize >> 32)); 4814 4785 chip->chip_shift += 32 - 1; 4815 4786 } 4816 4787 ··· 4827 4796 pr_info("%s %s\n", nand_manufacturer_name(manufacturer), 4828 4797 chip->parameters.model); 4829 4798 pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n", 4830 - (int)(chip->chipsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", 4799 + (int)(targetsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", 4831 4800 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); 4832 4801 return 0; 4833 4802 ··· 5002 4971 struct nand_flash_dev *table) 5003 4972 { 5004 4973 struct mtd_info *mtd = nand_to_mtd(chip); 4974 + struct nand_memory_organization *memorg; 5005 4975 int nand_maf_id, nand_dev_id; 5006 4976 unsigned int i; 5007 4977 int ret; 4978 + 4979 + memorg = nanddev_get_memorg(&chip->base); 5008 4980 5009 4981 /* Assume all dies are deselected when we enter nand_scan_ident(). */ 5010 4982 chip->cur_cs = -1; ··· 5023 4989 5024 4990 if (!mtd->name && mtd->dev.parent) 5025 4991 mtd->name = dev_name(mtd->dev.parent); 5026 - 5027 - /* 5028 - * Start with chips->numchips = maxchips to let nand_select_target() do 5029 - * its job. chip->numchips will be adjusted after. 5030 - */ 5031 - chip->numchips = maxchips; 5032 4992 5033 4993 /* Set the default functions */ 5034 4994 nand_set_defaults(chip); ··· 5070 5042 pr_info("%d chips detected\n", i); 5071 5043 5072 5044 /* Store the number of chips and calc total size for mtd */ 5073 - chip->numchips = i; 5074 - mtd->size = i * chip->chipsize; 5045 + memorg->ntargets = i; 5046 + mtd->size = i * nanddev_target_size(&chip->base); 5075 5047 5076 5048 return 0; 5077 5049 } ··· 5106 5078 ecc->bytes = 3; 5107 5079 ecc->strength = 1; 5108 5080 5109 - if (IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)) 5081 + if (IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) 5110 5082 ecc->options |= NAND_ECC_SOFT_HAMMING_SM_ORDER; 5111 5083 5112 5084 return 0; 5113 5085 case NAND_ECC_BCH: 5114 5086 if (!mtd_nand_has_bch()) { 5115 - WARN(1, "CONFIG_MTD_NAND_ECC_BCH not enabled\n"); 5087 + WARN(1, "CONFIG_MTD_NAND_ECC_SW_BCH not enabled\n"); 5116 5088 return -EINVAL; 5117 5089 } 5118 5090 ecc->calculate = nand_bch_calculate_ecc; ··· 5252 5224 { 5253 5225 struct mtd_info *mtd = nand_to_mtd(chip); 5254 5226 const struct nand_ecc_step_info *stepinfo; 5255 - int req_step = chip->ecc_step_ds; 5256 - int req_strength = chip->ecc_strength_ds; 5227 + int req_step = chip->base.eccreq.step_size; 5228 + int req_strength = chip->base.eccreq.strength; 5257 5229 int req_corr, step_size, strength, nsteps, ecc_bytes, ecc_bytes_total; 5258 5230 int best_step, best_strength, best_ecc_bytes; 5259 5231 int best_ecc_bytes_total = INT_MAX; ··· 5446 5418 struct nand_ecc_ctrl *ecc = &chip->ecc; 5447 5419 int corr, ds_corr; 5448 5420 5449 - if (ecc->size == 0 || chip->ecc_step_ds == 0) 5421 + if (ecc->size == 0 || chip->base.eccreq.step_size == 0) 5450 5422 /* Not enough information */ 5451 5423 return true; 5452 5424 ··· 5455 5427 * the correction density. 5456 5428 */ 5457 5429 corr = (mtd->writesize * ecc->strength) / ecc->size; 5458 - ds_corr = (mtd->writesize * chip->ecc_strength_ds) / chip->ecc_step_ds; 5430 + ds_corr = (mtd->writesize * chip->base.eccreq.strength) / 5431 + chip->base.eccreq.step_size; 5459 5432 5460 - return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds; 5433 + return corr >= ds_corr && ecc->strength >= chip->base.eccreq.strength; 5461 5434 } 5435 + 5436 + static int rawnand_erase(struct nand_device *nand, const struct nand_pos *pos) 5437 + { 5438 + struct nand_chip *chip = container_of(nand, struct nand_chip, 5439 + base); 5440 + unsigned int eb = nanddev_pos_to_row(nand, pos); 5441 + int ret; 5442 + 5443 + eb >>= nand->rowconv.eraseblock_addr_shift; 5444 + 5445 + nand_select_target(chip, pos->target); 5446 + ret = nand_erase_op(chip, eb); 5447 + nand_deselect_target(chip); 5448 + 5449 + return ret; 5450 + } 5451 + 5452 + static int rawnand_markbad(struct nand_device *nand, 5453 + const struct nand_pos *pos) 5454 + { 5455 + struct nand_chip *chip = container_of(nand, struct nand_chip, 5456 + base); 5457 + 5458 + return nand_markbad_bbm(chip, nanddev_pos_to_offs(nand, pos)); 5459 + } 5460 + 5461 + static bool rawnand_isbad(struct nand_device *nand, const struct nand_pos *pos) 5462 + { 5463 + struct nand_chip *chip = container_of(nand, struct nand_chip, 5464 + base); 5465 + int ret; 5466 + 5467 + nand_select_target(chip, pos->target); 5468 + ret = nand_isbad_bbm(chip, nanddev_pos_to_offs(nand, pos)); 5469 + nand_deselect_target(chip); 5470 + 5471 + return ret; 5472 + } 5473 + 5474 + static const struct nand_ops rawnand_ops = { 5475 + .erase = rawnand_erase, 5476 + .markbad = rawnand_markbad, 5477 + .isbad = rawnand_isbad, 5478 + }; 5462 5479 5463 5480 /** 5464 5481 * nand_scan_tail - Scan for the NAND device ··· 5760 5687 chip->subpagesize = mtd->writesize >> mtd->subpage_sft; 5761 5688 5762 5689 /* Invalidate the pagebuffer reference */ 5763 - chip->pagebuf = -1; 5690 + chip->pagecache.page = -1; 5764 5691 5765 5692 /* Large page NAND with SOFT_ECC should support subpage reads */ 5766 5693 switch (ecc->mode) { ··· 5773 5700 break; 5774 5701 } 5775 5702 5703 + ret = nanddev_init(&chip->base, &rawnand_ops, mtd->owner); 5704 + if (ret) 5705 + goto err_nand_manuf_cleanup; 5706 + 5707 + /* Adjust the MTD_CAP_ flags when NAND_ROM is set. */ 5708 + if (chip->options & NAND_ROM) 5709 + mtd->flags = MTD_CAP_ROM; 5710 + 5776 5711 /* Fill in remaining MTD driver data */ 5777 - mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; 5778 - mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : 5779 - MTD_CAP_NANDFLASH; 5780 5712 mtd->_erase = nand_erase; 5781 5713 mtd->_point = NULL; 5782 5714 mtd->_unpoint = NULL; ··· 5797 5719 mtd->_block_isreserved = nand_block_isreserved; 5798 5720 mtd->_block_isbad = nand_block_isbad; 5799 5721 mtd->_block_markbad = nand_block_markbad; 5800 - mtd->_max_bad_blocks = nand_max_bad_blocks; 5801 - mtd->writebufsize = mtd->writesize; 5722 + mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks; 5802 5723 5803 5724 /* 5804 5725 * Initialize bitflip_threshold to its default prior scan_bbt() call. ··· 5810 5733 /* Initialize the ->data_interface field. */ 5811 5734 ret = nand_init_data_interface(chip); 5812 5735 if (ret) 5813 - goto err_nand_manuf_cleanup; 5736 + goto err_nanddev_cleanup; 5814 5737 5815 5738 /* Enter fastest possible mode on all dies. */ 5816 - for (i = 0; i < chip->numchips; i++) { 5739 + for (i = 0; i < nanddev_ntargets(&chip->base); i++) { 5817 5740 ret = nand_setup_data_interface(chip, i); 5818 5741 if (ret) 5819 - goto err_nand_manuf_cleanup; 5742 + goto err_nanddev_cleanup; 5820 5743 } 5821 5744 5822 5745 /* Check, if we should skip the bad block table scan */ ··· 5826 5749 /* Build bad block table */ 5827 5750 ret = nand_create_bbt(chip); 5828 5751 if (ret) 5829 - goto err_nand_manuf_cleanup; 5752 + goto err_nanddev_cleanup; 5830 5753 5831 5754 return 0; 5832 5755 5756 + 5757 + err_nanddev_cleanup: 5758 + nanddev_cleanup(&chip->base); 5833 5759 5834 5760 err_nand_manuf_cleanup: 5835 5761 nand_manufacturer_cleanup(chip);
+39 -34
drivers/mtd/nand/raw/nand_bbt.c
··· 264 264 struct nand_bbt_descr *td, int chip) 265 265 { 266 266 struct mtd_info *mtd = nand_to_mtd(this); 267 + u64 targetsize = nanddev_target_size(&this->base); 267 268 int res = 0, i; 268 269 269 270 if (td->options & NAND_BBT_PERCHIP) { 270 271 int offs = 0; 271 - for (i = 0; i < this->numchips; i++) { 272 + for (i = 0; i < nanddev_ntargets(&this->base); i++) { 272 273 if (chip == -1 || chip == i) 273 274 res = read_bbt(this, buf, td->pages[i], 274 - this->chipsize >> this->bbt_erase_shift, 275 + targetsize >> this->bbt_erase_shift, 275 276 td, offs); 276 277 if (res) 277 278 return res; 278 - offs += this->chipsize >> this->bbt_erase_shift; 279 + offs += targetsize >> this->bbt_erase_shift; 279 280 } 280 281 } else { 281 282 res = read_bbt(this, buf, td->pages[0], ··· 416 415 417 416 /* Scan a given block partially */ 418 417 static int scan_block_fast(struct nand_chip *this, struct nand_bbt_descr *bd, 419 - loff_t offs, uint8_t *buf, int numpages) 418 + loff_t offs, uint8_t *buf) 420 419 { 421 420 struct mtd_info *mtd = nand_to_mtd(this); 421 + 422 422 struct mtd_oob_ops ops; 423 - int j, ret; 423 + int ret, page_offset; 424 424 425 425 ops.ooblen = mtd->oobsize; 426 426 ops.oobbuf = buf; ··· 429 427 ops.datbuf = NULL; 430 428 ops.mode = MTD_OPS_PLACE_OOB; 431 429 432 - for (j = 0; j < numpages; j++) { 430 + page_offset = nand_bbm_get_next_page(this, 0); 431 + 432 + while (page_offset >= 0) { 433 433 /* 434 434 * Read the full oob until read_oob is fixed to handle single 435 435 * byte reads for 16 bit buswidth. 436 436 */ 437 - ret = mtd_read_oob(mtd, offs, &ops); 437 + ret = mtd_read_oob(mtd, offs + (page_offset * mtd->writesize), 438 + &ops); 438 439 /* Ignore ECC errors when checking for BBM */ 439 440 if (ret && !mtd_is_bitflip_or_eccerr(ret)) 440 441 return ret; ··· 445 440 if (check_short_pattern(buf, bd)) 446 441 return 1; 447 442 448 - offs += mtd->writesize; 443 + page_offset = nand_bbm_get_next_page(this, page_offset + 1); 449 444 } 445 + 450 446 return 0; 451 447 } 452 448 ··· 465 459 static int create_bbt(struct nand_chip *this, uint8_t *buf, 466 460 struct nand_bbt_descr *bd, int chip) 467 461 { 462 + u64 targetsize = nanddev_target_size(&this->base); 468 463 struct mtd_info *mtd = nand_to_mtd(this); 469 - int i, numblocks, numpages; 470 - int startblock; 464 + int i, numblocks, startblock; 471 465 loff_t from; 472 466 473 467 pr_info("Scanning device for bad blocks\n"); 474 - 475 - if (bd->options & NAND_BBT_SCAN2NDPAGE) 476 - numpages = 2; 477 - else 478 - numpages = 1; 479 468 480 469 if (chip == -1) { 481 470 numblocks = mtd->size >> this->bbt_erase_shift; 482 471 startblock = 0; 483 472 from = 0; 484 473 } else { 485 - if (chip >= this->numchips) { 474 + if (chip >= nanddev_ntargets(&this->base)) { 486 475 pr_warn("create_bbt(): chipnr (%d) > available chips (%d)\n", 487 - chip + 1, this->numchips); 476 + chip + 1, nanddev_ntargets(&this->base)); 488 477 return -EINVAL; 489 478 } 490 - numblocks = this->chipsize >> this->bbt_erase_shift; 479 + numblocks = targetsize >> this->bbt_erase_shift; 491 480 startblock = chip * numblocks; 492 481 numblocks += startblock; 493 482 from = (loff_t)startblock << this->bbt_erase_shift; 494 483 } 495 - 496 - if (this->bbt_options & NAND_BBT_SCANLASTPAGE) 497 - from += mtd->erasesize - (mtd->writesize * numpages); 498 484 499 485 for (i = startblock; i < numblocks; i++) { 500 486 int ret; 501 487 502 488 BUG_ON(bd->options & NAND_BBT_NO_OOB); 503 489 504 - ret = scan_block_fast(this, bd, from, buf, numpages); 490 + ret = scan_block_fast(this, bd, from, buf); 505 491 if (ret < 0) 506 492 return ret; 507 493 ··· 527 529 static int search_bbt(struct nand_chip *this, uint8_t *buf, 528 530 struct nand_bbt_descr *td) 529 531 { 532 + u64 targetsize = nanddev_target_size(&this->base); 530 533 struct mtd_info *mtd = nand_to_mtd(this); 531 534 int i, chips; 532 535 int startblock, block, dir; ··· 546 547 547 548 /* Do we have a bbt per chip? */ 548 549 if (td->options & NAND_BBT_PERCHIP) { 549 - chips = this->numchips; 550 - bbtblocks = this->chipsize >> this->bbt_erase_shift; 550 + chips = nanddev_ntargets(&this->base); 551 + bbtblocks = targetsize >> this->bbt_erase_shift; 551 552 startblock &= bbtblocks - 1; 552 553 } else { 553 554 chips = 1; ··· 575 576 break; 576 577 } 577 578 } 578 - startblock += this->chipsize >> this->bbt_erase_shift; 579 + startblock += targetsize >> this->bbt_erase_shift; 579 580 } 580 581 /* Check, if we found a bbt for each requested chip */ 581 582 for (i = 0; i < chips; i++) { ··· 625 626 static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td, 626 627 struct nand_bbt_descr *md, int chip) 627 628 { 629 + u64 targetsize = nanddev_target_size(&this->base); 628 630 int startblock, dir, page, numblocks, i; 629 631 630 632 /* ··· 637 637 return td->pages[chip] >> 638 638 (this->bbt_erase_shift - this->page_shift); 639 639 640 - numblocks = (int)(this->chipsize >> this->bbt_erase_shift); 640 + numblocks = (int)(targetsize >> this->bbt_erase_shift); 641 641 if (!(td->options & NAND_BBT_PERCHIP)) 642 - numblocks *= this->numchips; 642 + numblocks *= nanddev_ntargets(&this->base); 643 643 644 644 /* 645 645 * Automatic placement of the bad block table. Search direction ··· 717 717 struct nand_bbt_descr *td, struct nand_bbt_descr *md, 718 718 int chipsel) 719 719 { 720 + u64 targetsize = nanddev_target_size(&this->base); 720 721 struct mtd_info *mtd = nand_to_mtd(this); 721 722 struct erase_info einfo; 722 723 int i, res, chip = 0; ··· 738 737 rcode = 0xff; 739 738 /* Write bad block table per chip rather than per device? */ 740 739 if (td->options & NAND_BBT_PERCHIP) { 741 - numblocks = (int)(this->chipsize >> this->bbt_erase_shift); 740 + numblocks = (int)(targetsize >> this->bbt_erase_shift); 742 741 /* Full device write or specific chip? */ 743 742 if (chipsel == -1) { 744 - nrchips = this->numchips; 743 + nrchips = nanddev_ntargets(&this->base); 745 744 } else { 746 745 nrchips = chipsel + 1; 747 746 chip = chipsel; ··· 902 901 static inline int nand_memory_bbt(struct nand_chip *this, 903 902 struct nand_bbt_descr *bd) 904 903 { 905 - return create_bbt(this, this->data_buf, bd, -1); 904 + u8 *pagebuf = nand_get_data_buf(this); 905 + 906 + return create_bbt(this, pagebuf, bd, -1); 906 907 } 907 908 908 909 /** ··· 928 925 929 926 /* Do we have a bbt per chip? */ 930 927 if (td->options & NAND_BBT_PERCHIP) 931 - chips = this->numchips; 928 + chips = nanddev_ntargets(&this->base); 932 929 else 933 930 chips = 1; 934 931 ··· 1100 1097 */ 1101 1098 static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td) 1102 1099 { 1100 + u64 targetsize = nanddev_target_size(&this->base); 1103 1101 struct mtd_info *mtd = nand_to_mtd(this); 1104 1102 int i, j, chips, block, nrblocks, update; 1105 1103 uint8_t oldval; 1106 1104 1107 1105 /* Do we have a bbt per chip? */ 1108 1106 if (td->options & NAND_BBT_PERCHIP) { 1109 - chips = this->numchips; 1110 - nrblocks = (int)(this->chipsize >> this->bbt_erase_shift); 1107 + chips = nanddev_ntargets(&this->base); 1108 + nrblocks = (int)(targetsize >> this->bbt_erase_shift); 1111 1109 } else { 1112 1110 chips = 1; 1113 1111 nrblocks = (int)(mtd->size >> this->bbt_erase_shift); ··· 1161 1157 */ 1162 1158 static void verify_bbt_descr(struct nand_chip *this, struct nand_bbt_descr *bd) 1163 1159 { 1160 + u64 targetsize = nanddev_target_size(&this->base); 1164 1161 struct mtd_info *mtd = nand_to_mtd(this); 1165 1162 u32 pattern_len; 1166 1163 u32 bits; ··· 1190 1185 } 1191 1186 1192 1187 if (bd->options & NAND_BBT_PERCHIP) 1193 - table_size = this->chipsize >> this->bbt_erase_shift; 1188 + table_size = targetsize >> this->bbt_erase_shift; 1194 1189 else 1195 1190 table_size = mtd->size >> this->bbt_erase_shift; 1196 1191 table_size >>= 3;
+13 -6
drivers/mtd/nand/raw/nand_esmt.c
··· 14 14 15 15 /* Extract ECC requirements from 5th id byte. */ 16 16 if (chip->id.len >= 5 && nand_is_slc(chip)) { 17 - chip->ecc_step_ds = 512; 17 + chip->base.eccreq.step_size = 512; 18 18 switch (chip->id.data[4] & 0x3) { 19 19 case 0x0: 20 - chip->ecc_strength_ds = 4; 20 + chip->base.eccreq.strength = 4; 21 21 break; 22 22 case 0x1: 23 - chip->ecc_strength_ds = 2; 23 + chip->base.eccreq.strength = 2; 24 24 break; 25 25 case 0x2: 26 - chip->ecc_strength_ds = 1; 26 + chip->base.eccreq.strength = 1; 27 27 break; 28 28 default: 29 29 WARN(1, "Could not get ECC info"); 30 - chip->ecc_step_ds = 0; 30 + chip->base.eccreq.step_size = 0; 31 31 break; 32 32 } 33 33 } ··· 36 36 static int esmt_nand_init(struct nand_chip *chip) 37 37 { 38 38 if (nand_is_slc(chip)) 39 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 39 + /* 40 + * It is known that some ESMT SLC NANDs have been shipped 41 + * with the factory bad block markers in the first or last page 42 + * of the block, instead of the first or second page. To be on 43 + * the safe side, let's check all three locations. 44 + */ 45 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE | 46 + NAND_BBM_LASTPAGE; 40 47 41 48 return 0; 42 49 }
+55 -39
drivers/mtd/nand/raw/nand_hynix.c
··· 418 418 bool valid_jedecid) 419 419 { 420 420 struct mtd_info *mtd = nand_to_mtd(chip); 421 + struct nand_memory_organization *memorg; 421 422 u8 oobsize; 423 + 424 + memorg = nanddev_get_memorg(&chip->base); 422 425 423 426 oobsize = ((chip->id.data[3] >> 2) & 0x3) | 424 427 ((chip->id.data[3] >> 4) & 0x4); ··· 429 426 if (valid_jedecid) { 430 427 switch (oobsize) { 431 428 case 0: 432 - mtd->oobsize = 2048; 429 + memorg->oobsize = 2048; 433 430 break; 434 431 case 1: 435 - mtd->oobsize = 1664; 432 + memorg->oobsize = 1664; 436 433 break; 437 434 case 2: 438 - mtd->oobsize = 1024; 435 + memorg->oobsize = 1024; 439 436 break; 440 437 case 3: 441 - mtd->oobsize = 640; 438 + memorg->oobsize = 640; 442 439 break; 443 440 default: 444 441 /* ··· 453 450 } else { 454 451 switch (oobsize) { 455 452 case 0: 456 - mtd->oobsize = 128; 453 + memorg->oobsize = 128; 457 454 break; 458 455 case 1: 459 - mtd->oobsize = 224; 456 + memorg->oobsize = 224; 460 457 break; 461 458 case 2: 462 - mtd->oobsize = 448; 459 + memorg->oobsize = 448; 463 460 break; 464 461 case 3: 465 - mtd->oobsize = 64; 462 + memorg->oobsize = 64; 466 463 break; 467 464 case 4: 468 - mtd->oobsize = 32; 465 + memorg->oobsize = 32; 469 466 break; 470 467 case 5: 471 - mtd->oobsize = 16; 468 + memorg->oobsize = 16; 472 469 break; 473 470 case 6: 474 - mtd->oobsize = 640; 471 + memorg->oobsize = 640; 475 472 break; 476 473 default: 477 474 /* ··· 495 492 * the actual OOB size for this chip is: 640 * 16k / 8k). 496 493 */ 497 494 if (chip->id.data[1] == 0xde) 498 - mtd->oobsize *= mtd->writesize / SZ_8K; 495 + memorg->oobsize *= memorg->pagesize / SZ_8K; 499 496 } 497 + 498 + mtd->oobsize = memorg->oobsize; 500 499 } 501 500 502 501 static void hynix_nand_extract_ecc_requirements(struct nand_chip *chip, ··· 508 503 509 504 if (valid_jedecid) { 510 505 /* Reference: H27UCG8T2E datasheet */ 511 - chip->ecc_step_ds = 1024; 506 + chip->base.eccreq.step_size = 1024; 512 507 513 508 switch (ecc_level) { 514 509 case 0: 515 - chip->ecc_step_ds = 0; 516 - chip->ecc_strength_ds = 0; 510 + chip->base.eccreq.step_size = 0; 511 + chip->base.eccreq.strength = 0; 517 512 break; 518 513 case 1: 519 - chip->ecc_strength_ds = 4; 514 + chip->base.eccreq.strength = 4; 520 515 break; 521 516 case 2: 522 - chip->ecc_strength_ds = 24; 517 + chip->base.eccreq.strength = 24; 523 518 break; 524 519 case 3: 525 - chip->ecc_strength_ds = 32; 520 + chip->base.eccreq.strength = 32; 526 521 break; 527 522 case 4: 528 - chip->ecc_strength_ds = 40; 523 + chip->base.eccreq.strength = 40; 529 524 break; 530 525 case 5: 531 - chip->ecc_strength_ds = 50; 526 + chip->base.eccreq.strength = 50; 532 527 break; 533 528 case 6: 534 - chip->ecc_strength_ds = 60; 529 + chip->base.eccreq.strength = 60; 535 530 break; 536 531 default: 537 532 /* ··· 552 547 if (nand_tech < 3) { 553 548 /* > 26nm, reference: H27UBG8T2A datasheet */ 554 549 if (ecc_level < 5) { 555 - chip->ecc_step_ds = 512; 556 - chip->ecc_strength_ds = 1 << ecc_level; 550 + chip->base.eccreq.step_size = 512; 551 + chip->base.eccreq.strength = 1 << ecc_level; 557 552 } else if (ecc_level < 7) { 558 553 if (ecc_level == 5) 559 - chip->ecc_step_ds = 2048; 554 + chip->base.eccreq.step_size = 2048; 560 555 else 561 - chip->ecc_step_ds = 1024; 562 - chip->ecc_strength_ds = 24; 556 + chip->base.eccreq.step_size = 1024; 557 + chip->base.eccreq.strength = 24; 563 558 } else { 564 559 /* 565 560 * We should never reach this case, but if that ··· 572 567 } else { 573 568 /* <= 26nm, reference: H27UBG8T2B datasheet */ 574 569 if (!ecc_level) { 575 - chip->ecc_step_ds = 0; 576 - chip->ecc_strength_ds = 0; 570 + chip->base.eccreq.step_size = 0; 571 + chip->base.eccreq.strength = 0; 577 572 } else if (ecc_level < 5) { 578 - chip->ecc_step_ds = 512; 579 - chip->ecc_strength_ds = 1 << (ecc_level - 1); 573 + chip->base.eccreq.step_size = 512; 574 + chip->base.eccreq.strength = 1 << (ecc_level - 1); 580 575 } else { 581 - chip->ecc_step_ds = 1024; 582 - chip->ecc_strength_ds = 24 + 576 + chip->base.eccreq.step_size = 1024; 577 + chip->base.eccreq.strength = 24 + 583 578 (8 * (ecc_level - 5)); 584 579 } 585 580 } ··· 592 587 u8 nand_tech; 593 588 594 589 /* We need scrambling on all TLC NANDs*/ 595 - if (chip->bits_per_cell > 2) 590 + if (nanddev_bits_per_cell(&chip->base) > 2) 596 591 chip->options |= NAND_NEED_SCRAMBLING; 597 592 598 593 /* And on MLC NANDs with sub-3xnm process */ ··· 614 609 static void hynix_nand_decode_id(struct nand_chip *chip) 615 610 { 616 611 struct mtd_info *mtd = nand_to_mtd(chip); 612 + struct nand_memory_organization *memorg; 617 613 bool valid_jedecid; 618 614 u8 tmp; 615 + 616 + memorg = nanddev_get_memorg(&chip->base); 619 617 620 618 /* 621 619 * Exclude all SLC NANDs from this advanced detection scheme. ··· 633 625 } 634 626 635 627 /* Extract pagesize */ 636 - mtd->writesize = 2048 << (chip->id.data[3] & 0x03); 628 + memorg->pagesize = 2048 << (chip->id.data[3] & 0x03); 629 + mtd->writesize = memorg->pagesize; 637 630 638 631 tmp = (chip->id.data[3] >> 4) & 0x3; 639 632 /* ··· 644 635 * The only exception is when ID[3][4:5] == 3 and ID[3][7] == 0, in 645 636 * this case the erasesize is set to 768KiB. 646 637 */ 647 - if (chip->id.data[3] & 0x80) 638 + if (chip->id.data[3] & 0x80) { 639 + memorg->pages_per_eraseblock = (SZ_1M << tmp) / 640 + memorg->pagesize; 648 641 mtd->erasesize = SZ_1M << tmp; 649 - else if (tmp == 3) 642 + } else if (tmp == 3) { 643 + memorg->pages_per_eraseblock = (SZ_512K + SZ_256K) / 644 + memorg->pagesize; 650 645 mtd->erasesize = SZ_512K + SZ_256K; 651 - else 646 + } else { 647 + memorg->pages_per_eraseblock = (SZ_128K << tmp) / 648 + memorg->pagesize; 652 649 mtd->erasesize = SZ_128K << tmp; 650 + } 653 651 654 652 /* 655 653 * Modern Toggle DDR NANDs have a valid JEDECID even though they are ··· 688 672 int ret; 689 673 690 674 if (!nand_is_slc(chip)) 691 - chip->bbt_options |= NAND_BBT_SCANLASTPAGE; 675 + chip->options |= NAND_BBM_LASTPAGE; 692 676 else 693 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 677 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 694 678 695 679 hynix = kzalloc(sizeof(*hynix), GFP_KERNEL); 696 680 if (!hynix)
+18 -9
drivers/mtd/nand/raw/nand_jedec.c
··· 22 22 int nand_jedec_detect(struct nand_chip *chip) 23 23 { 24 24 struct mtd_info *mtd = nand_to_mtd(chip); 25 + struct nand_memory_organization *memorg; 25 26 struct nand_jedec_params *p; 26 27 struct jedec_ecc_info *ecc; 27 28 int jedec_version = 0; 28 29 char id[5]; 29 30 int i, val, ret; 31 + 32 + memorg = nanddev_get_memorg(&chip->base); 30 33 31 34 /* Try JEDEC for unknown chip or LP */ 32 35 ret = nand_readid_op(chip, 0x40, id, sizeof(id)); ··· 84 81 goto free_jedec_param_page; 85 82 } 86 83 87 - mtd->writesize = le32_to_cpu(p->byte_per_page); 84 + memorg->pagesize = le32_to_cpu(p->byte_per_page); 85 + mtd->writesize = memorg->pagesize; 88 86 89 87 /* Please reference to the comment for nand_flash_detect_onfi. */ 90 - mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); 91 - mtd->erasesize *= mtd->writesize; 88 + memorg->pages_per_eraseblock = 89 + 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); 90 + mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; 92 91 93 - mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); 92 + memorg->oobsize = le16_to_cpu(p->spare_bytes_per_page); 93 + mtd->oobsize = memorg->oobsize; 94 + 95 + memorg->luns_per_target = p->lun_count; 96 + memorg->planes_per_lun = 1 << p->multi_plane_addr; 94 97 95 98 /* Please reference to the comment for nand_flash_detect_onfi. */ 96 - chip->chipsize = 1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1); 97 - chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; 98 - chip->bits_per_cell = p->bits_per_cell; 99 + memorg->eraseblocks_per_lun = 100 + 1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1); 101 + memorg->bits_per_cell = p->bits_per_cell; 99 102 100 103 if (le16_to_cpu(p->features) & JEDEC_FEATURE_16_BIT_BUS) 101 104 chip->options |= NAND_BUSWIDTH_16; ··· 110 101 ecc = &p->ecc_info[0]; 111 102 112 103 if (ecc->codeword_size >= 9) { 113 - chip->ecc_strength_ds = ecc->ecc_bits; 114 - chip->ecc_step_ds = 1 << ecc->codeword_size; 104 + chip->base.eccreq.strength = ecc->ecc_bits; 105 + chip->base.eccreq.step_size = 1 << ecc->codeword_size; 115 106 } else { 116 107 pr_warn("Invalid codeword size\n"); 117 108 }
+1 -1
drivers/mtd/nand/raw/nand_macronix.c
··· 62 62 static int macronix_nand_init(struct nand_chip *chip) 63 63 { 64 64 if (nand_is_slc(chip)) 65 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 65 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 66 66 67 67 macronix_nand_fix_broken_get_timings(chip); 68 68
+8 -8
drivers/mtd/nand/raw/nand_micron.c
··· 385 385 if (!chip->parameters.onfi) 386 386 return MICRON_ON_DIE_UNSUPPORTED; 387 387 388 - if (chip->bits_per_cell != 1) 388 + if (nanddev_bits_per_cell(&chip->base) != 1) 389 389 return MICRON_ON_DIE_UNSUPPORTED; 390 390 391 391 /* 392 392 * We only support on-die ECC of 4/512 or 8/512 393 393 */ 394 - if (chip->ecc_strength_ds != 4 && chip->ecc_strength_ds != 8) 394 + if (chip->base.eccreq.strength != 4 && chip->base.eccreq.strength != 8) 395 395 return MICRON_ON_DIE_UNSUPPORTED; 396 396 397 397 /* 0x2 means on-die ECC is available. */ ··· 424 424 /* 425 425 * We only support on-die ECC of 4/512 or 8/512 426 426 */ 427 - if (chip->ecc_strength_ds != 4 && chip->ecc_strength_ds != 8) 427 + if (chip->base.eccreq.strength != 4 && chip->base.eccreq.strength != 8) 428 428 return MICRON_ON_DIE_UNSUPPORTED; 429 429 430 430 return MICRON_ON_DIE_SUPPORTED; ··· 448 448 goto err_free_manuf_data; 449 449 450 450 if (mtd->writesize == 2048) 451 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 451 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 452 452 453 453 ondie = micron_supports_on_die_ecc(chip); 454 454 ··· 479 479 * That's not needed for 8-bit ECC, because the status expose 480 480 * a better approximation of the number of bitflips in a page. 481 481 */ 482 - if (chip->ecc_strength_ds == 4) { 482 + if (chip->base.eccreq.strength == 4) { 483 483 micron->ecc.rawbuf = kmalloc(mtd->writesize + 484 484 mtd->oobsize, 485 485 GFP_KERNEL); ··· 489 489 } 490 490 } 491 491 492 - if (chip->ecc_strength_ds == 4) 492 + if (chip->base.eccreq.strength == 4) 493 493 mtd_set_ooblayout(mtd, 494 494 &micron_nand_on_die_4_ooblayout_ops); 495 495 else 496 496 mtd_set_ooblayout(mtd, 497 497 &micron_nand_on_die_8_ooblayout_ops); 498 498 499 - chip->ecc.bytes = chip->ecc_strength_ds * 2; 499 + chip->ecc.bytes = chip->base.eccreq.strength * 2; 500 500 chip->ecc.size = 512; 501 - chip->ecc.strength = chip->ecc_strength_ds; 501 + chip->ecc.strength = chip->base.eccreq.strength; 502 502 chip->ecc.algo = NAND_ECC_BCH; 503 503 chip->ecc.read_page = micron_nand_read_page_on_die_ecc; 504 504 chip->ecc.write_page = micron_nand_write_page_on_die_ecc;
+21 -14
drivers/mtd/nand/raw/nand_onfi.c
··· 94 94 goto ext_out; 95 95 } 96 96 97 - chip->ecc_strength_ds = ecc->ecc_bits; 98 - chip->ecc_step_ds = 1 << ecc->codeword_size; 97 + chip->base.eccreq.strength = ecc->ecc_bits; 98 + chip->base.eccreq.step_size = 1 << ecc->codeword_size; 99 99 ret = 0; 100 100 101 101 ext_out: ··· 140 140 int nand_onfi_detect(struct nand_chip *chip) 141 141 { 142 142 struct mtd_info *mtd = nand_to_mtd(chip); 143 + struct nand_memory_organization *memorg; 143 144 struct nand_onfi_params *p; 144 145 struct onfi_params *onfi; 145 146 int onfi_version = 0; 146 147 char id[4]; 147 148 int i, ret, val; 149 + 150 + memorg = nanddev_get_memorg(&chip->base); 148 151 149 152 /* Try ONFI for unknown chip or LP */ 150 153 ret = nand_readid_op(chip, 0x20, id, sizeof(id)); ··· 224 221 goto free_onfi_param_page; 225 222 } 226 223 227 - mtd->writesize = le32_to_cpu(p->byte_per_page); 224 + memorg->pagesize = le32_to_cpu(p->byte_per_page); 225 + mtd->writesize = memorg->pagesize; 228 226 229 227 /* 230 228 * pages_per_block and blocks_per_lun may not be a power-of-2 size 231 229 * (don't ask me who thought of this...). MTD assumes that these 232 230 * dimensions will be power-of-2, so just truncate the remaining area. 233 231 */ 234 - mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); 235 - mtd->erasesize *= mtd->writesize; 232 + memorg->pages_per_eraseblock = 233 + 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); 234 + mtd->erasesize = memorg->pages_per_eraseblock * memorg->pagesize; 236 235 237 - mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); 236 + memorg->oobsize = le16_to_cpu(p->spare_bytes_per_page); 237 + mtd->oobsize = memorg->oobsize; 238 + 239 + memorg->luns_per_target = p->lun_count; 240 + memorg->planes_per_lun = 1 << p->interleaved_bits; 238 241 239 242 /* See erasesize comment */ 240 - chip->chipsize = 1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1); 241 - chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; 242 - chip->bits_per_cell = p->bits_per_cell; 243 - 244 - chip->max_bb_per_die = le16_to_cpu(p->bb_per_lun); 245 - chip->blocks_per_die = le32_to_cpu(p->blocks_per_lun); 243 + memorg->eraseblocks_per_lun = 244 + 1 << (fls(le32_to_cpu(p->blocks_per_lun)) - 1); 245 + memorg->max_bad_eraseblocks_per_lun = le32_to_cpu(p->blocks_per_lun); 246 + memorg->bits_per_cell = p->bits_per_cell; 246 247 247 248 if (le16_to_cpu(p->features) & ONFI_FEATURE_16_BIT_BUS) 248 249 chip->options |= NAND_BUSWIDTH_16; 249 250 250 251 if (p->ecc_bits != 0xff) { 251 - chip->ecc_strength_ds = p->ecc_bits; 252 - chip->ecc_step_ds = 512; 252 + chip->base.eccreq.strength = p->ecc_bits; 253 + chip->base.eccreq.step_size = 512; 253 254 } else if (onfi_version >= 21 && 254 255 (le16_to_cpu(p->features) & ONFI_FEATURE_EXT_PARAM_PAGE)) { 255 256
+28 -18
drivers/mtd/nand/raw/nand_samsung.c
··· 20 20 static void samsung_nand_decode_id(struct nand_chip *chip) 21 21 { 22 22 struct mtd_info *mtd = nand_to_mtd(chip); 23 + struct nand_memory_organization *memorg; 24 + 25 + memorg = nanddev_get_memorg(&chip->base); 23 26 24 27 /* New Samsung (6 byte ID): Samsung K9GAG08U0F (p.44) */ 25 28 if (chip->id.len == 6 && !nand_is_slc(chip) && ··· 30 27 u8 extid = chip->id.data[3]; 31 28 32 29 /* Get pagesize */ 33 - mtd->writesize = 2048 << (extid & 0x03); 30 + memorg->pagesize = 2048 << (extid & 0x03); 31 + mtd->writesize = memorg->pagesize; 34 32 35 33 extid >>= 2; 36 34 37 35 /* Get oobsize */ 38 36 switch (((extid >> 2) & 0x4) | (extid & 0x3)) { 39 37 case 1: 40 - mtd->oobsize = 128; 38 + memorg->oobsize = 128; 41 39 break; 42 40 case 2: 43 - mtd->oobsize = 218; 41 + memorg->oobsize = 218; 44 42 break; 45 43 case 3: 46 - mtd->oobsize = 400; 44 + memorg->oobsize = 400; 47 45 break; 48 46 case 4: 49 - mtd->oobsize = 436; 47 + memorg->oobsize = 436; 50 48 break; 51 49 case 5: 52 - mtd->oobsize = 512; 50 + memorg->oobsize = 512; 53 51 break; 54 52 case 6: 55 - mtd->oobsize = 640; 53 + memorg->oobsize = 640; 56 54 break; 57 55 default: 58 56 /* ··· 66 62 break; 67 63 } 68 64 65 + mtd->oobsize = memorg->oobsize; 66 + 69 67 /* Get blocksize */ 70 68 extid >>= 2; 69 + memorg->pages_per_eraseblock = (128 * 1024) << 70 + (((extid >> 1) & 0x04) | 71 + (extid & 0x03)) / 72 + memorg->pagesize; 71 73 mtd->erasesize = (128 * 1024) << 72 74 (((extid >> 1) & 0x04) | (extid & 0x03)); 73 75 74 76 /* Extract ECC requirements from 5th id byte*/ 75 77 extid = (chip->id.data[4] >> 4) & 0x07; 76 78 if (extid < 5) { 77 - chip->ecc_step_ds = 512; 78 - chip->ecc_strength_ds = 1 << extid; 79 + chip->base.eccreq.step_size = 512; 80 + chip->base.eccreq.strength = 1 << extid; 79 81 } else { 80 - chip->ecc_step_ds = 1024; 82 + chip->base.eccreq.step_size = 1024; 81 83 switch (extid) { 82 84 case 5: 83 - chip->ecc_strength_ds = 24; 85 + chip->base.eccreq.strength = 24; 84 86 break; 85 87 case 6: 86 - chip->ecc_strength_ds = 40; 88 + chip->base.eccreq.strength = 40; 87 89 break; 88 90 case 7: 89 - chip->ecc_strength_ds = 60; 91 + chip->base.eccreq.strength = 60; 90 92 break; 91 93 default: 92 94 WARN(1, "Could not decode ECC info"); 93 - chip->ecc_step_ds = 0; 95 + chip->base.eccreq.step_size = 0; 94 96 } 95 97 } 96 98 } else { ··· 106 96 switch (chip->id.data[1]) { 107 97 /* K9F4G08U0D-S[I|C]B0(T00) */ 108 98 case 0xDC: 109 - chip->ecc_step_ds = 512; 110 - chip->ecc_strength_ds = 1; 99 + chip->base.eccreq.step_size = 512; 100 + chip->base.eccreq.strength = 1; 111 101 break; 112 102 113 103 /* K9F1G08U0E 21nm chips do not support subpage write */ ··· 131 121 chip->options |= NAND_SAMSUNG_LP_OPTIONS; 132 122 133 123 if (!nand_is_slc(chip)) 134 - chip->bbt_options |= NAND_BBT_SCANLASTPAGE; 124 + chip->options |= NAND_BBM_LASTPAGE; 135 125 else 136 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 126 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 137 127 138 128 return 0; 139 129 }
+13 -8
drivers/mtd/nand/raw/nand_toshiba.c
··· 101 101 static void toshiba_nand_decode_id(struct nand_chip *chip) 102 102 { 103 103 struct mtd_info *mtd = nand_to_mtd(chip); 104 + struct nand_memory_organization *memorg; 105 + 106 + memorg = nanddev_get_memorg(&chip->base); 104 107 105 108 nand_decode_ext_id(chip); 106 109 ··· 117 114 */ 118 115 if (chip->id.len >= 6 && nand_is_slc(chip) && 119 116 (chip->id.data[5] & 0x7) == 0x6 /* 24nm */ && 120 - !(chip->id.data[4] & 0x80) /* !BENAND */) 121 - mtd->oobsize = 32 * mtd->writesize >> 9; 117 + !(chip->id.data[4] & 0x80) /* !BENAND */) { 118 + memorg->oobsize = 32 * memorg->pagesize >> 9; 119 + mtd->oobsize = memorg->oobsize; 120 + } 122 121 123 122 /* 124 123 * Extract ECC requirements from 6th id byte. ··· 130 125 * - 24nm: 8 bit ECC for each 512Byte is required. 131 126 */ 132 127 if (chip->id.len >= 6 && nand_is_slc(chip)) { 133 - chip->ecc_step_ds = 512; 128 + chip->base.eccreq.step_size = 512; 134 129 switch (chip->id.data[5] & 0x7) { 135 130 case 0x4: 136 - chip->ecc_strength_ds = 1; 131 + chip->base.eccreq.strength = 1; 137 132 break; 138 133 case 0x5: 139 - chip->ecc_strength_ds = 4; 134 + chip->base.eccreq.strength = 4; 140 135 break; 141 136 case 0x6: 142 - chip->ecc_strength_ds = 8; 137 + chip->base.eccreq.strength = 8; 143 138 break; 144 139 default: 145 140 WARN(1, "Could not get ECC info"); 146 - chip->ecc_step_ds = 0; 141 + chip->base.eccreq.step_size = 0; 147 142 break; 148 143 } 149 144 } ··· 152 147 static int toshiba_nand_init(struct nand_chip *chip) 153 148 { 154 149 if (nand_is_slc(chip)) 155 - chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; 150 + chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 156 151 157 152 /* Check that chip is BENAND and ECC mode is on-die */ 158 153 if (nand_is_slc(chip) && chip->ecc.mode == NAND_ECC_ON_DIE &&
+84 -60
drivers/mtd/nand/raw/nandsim.c
··· 298 298 * The structure which describes all the internal simulator data. 299 299 */ 300 300 struct nandsim { 301 + struct nand_chip chip; 302 + struct nand_controller base; 301 303 struct mtd_partition partitions[CONFIG_NANDSIM_MAX_PARTS]; 302 304 unsigned int nbparts; 303 305 ··· 645 643 NS_ERR("init_nandsim: nandsim is already initialized\n"); 646 644 return -EIO; 647 645 } 648 - 649 - /* Force mtd to not do delays */ 650 - chip->legacy.chip_delay = 0; 651 646 652 647 /* Initialize the NAND flash parameters */ 653 648 ns->busw = chip->options & NAND_BUSWIDTH_16 ? 16 : 8; ··· 2075 2076 return; 2076 2077 } 2077 2078 2078 - static void ns_hwcontrol(struct nand_chip *chip, int cmd, unsigned int bitmask) 2079 - { 2080 - struct nandsim *ns = nand_get_controller_data(chip); 2081 - 2082 - ns->lines.cle = bitmask & NAND_CLE ? 1 : 0; 2083 - ns->lines.ale = bitmask & NAND_ALE ? 1 : 0; 2084 - ns->lines.ce = bitmask & NAND_NCE ? 1 : 0; 2085 - 2086 - if (cmd != NAND_CMD_NONE) 2087 - ns_nand_write_byte(chip, cmd); 2088 - } 2089 - 2090 - static int ns_device_ready(struct nand_chip *chip) 2091 - { 2092 - NS_DBG("device_ready\n"); 2093 - return 1; 2094 - } 2095 - 2096 2079 static void ns_nand_write_buf(struct nand_chip *chip, const u_char *buf, 2097 2080 int len) 2098 2081 { ··· 2126 2145 int i; 2127 2146 2128 2147 for (i = 0; i < len; i++) 2129 - buf[i] = chip->legacy.read_byte(chip); 2148 + buf[i] = ns_nand_read_byte(chip); 2130 2149 2131 2150 return; 2132 2151 } ··· 2147 2166 } 2148 2167 2149 2168 return; 2169 + } 2170 + 2171 + static int ns_exec_op(struct nand_chip *chip, const struct nand_operation *op, 2172 + bool check_only) 2173 + { 2174 + int i; 2175 + unsigned int op_id; 2176 + const struct nand_op_instr *instr = NULL; 2177 + struct nandsim *ns = nand_get_controller_data(chip); 2178 + 2179 + ns->lines.ce = 1; 2180 + 2181 + for (op_id = 0; op_id < op->ninstrs; op_id++) { 2182 + instr = &op->instrs[op_id]; 2183 + ns->lines.cle = 0; 2184 + ns->lines.ale = 0; 2185 + 2186 + switch (instr->type) { 2187 + case NAND_OP_CMD_INSTR: 2188 + ns->lines.cle = 1; 2189 + ns_nand_write_byte(chip, instr->ctx.cmd.opcode); 2190 + break; 2191 + case NAND_OP_ADDR_INSTR: 2192 + ns->lines.ale = 1; 2193 + for (i = 0; i < instr->ctx.addr.naddrs; i++) 2194 + ns_nand_write_byte(chip, instr->ctx.addr.addrs[i]); 2195 + break; 2196 + case NAND_OP_DATA_IN_INSTR: 2197 + ns_nand_read_buf(chip, instr->ctx.data.buf.in, instr->ctx.data.len); 2198 + break; 2199 + case NAND_OP_DATA_OUT_INSTR: 2200 + ns_nand_write_buf(chip, instr->ctx.data.buf.out, instr->ctx.data.len); 2201 + break; 2202 + case NAND_OP_WAITRDY_INSTR: 2203 + /* we are always ready */ 2204 + break; 2205 + } 2206 + } 2207 + 2208 + return 0; 2150 2209 } 2151 2210 2152 2211 static int ns_attach_chip(struct nand_chip *chip) ··· 2229 2208 2230 2209 static const struct nand_controller_ops ns_controller_ops = { 2231 2210 .attach_chip = ns_attach_chip, 2211 + .exec_op = ns_exec_op, 2232 2212 }; 2233 2213 2234 2214 /* ··· 2238 2216 static int __init ns_init_module(void) 2239 2217 { 2240 2218 struct nand_chip *chip; 2241 - struct nandsim *nand; 2219 + struct nandsim *ns; 2242 2220 int retval = -ENOMEM, i; 2243 2221 2244 2222 if (bus_width != 8 && bus_width != 16) { ··· 2246 2224 return -EINVAL; 2247 2225 } 2248 2226 2249 - /* Allocate and initialize mtd_info, nand_chip and nandsim structures */ 2250 - chip = kzalloc(sizeof(struct nand_chip) + sizeof(struct nandsim), 2251 - GFP_KERNEL); 2252 - if (!chip) { 2227 + ns = kzalloc(sizeof(struct nandsim), GFP_KERNEL); 2228 + if (!ns) { 2253 2229 NS_ERR("unable to allocate core structures.\n"); 2254 2230 return -ENOMEM; 2255 2231 } 2232 + chip = &ns->chip; 2256 2233 nsmtd = nand_to_mtd(chip); 2257 - nand = (struct nandsim *)(chip + 1); 2258 - nand_set_controller_data(chip, (void *)nand); 2234 + nand_set_controller_data(chip, (void *)ns); 2259 2235 2260 - /* 2261 - * Register simulator's callbacks. 2262 - */ 2263 - chip->legacy.cmd_ctrl = ns_hwcontrol; 2264 - chip->legacy.read_byte = ns_nand_read_byte; 2265 - chip->legacy.dev_ready = ns_device_ready; 2266 - chip->legacy.write_buf = ns_nand_write_buf; 2267 - chip->legacy.read_buf = ns_nand_read_buf; 2268 2236 chip->ecc.mode = NAND_ECC_SOFT; 2269 2237 chip->ecc.algo = NAND_ECC_HAMMING; 2270 2238 /* The NAND_SKIP_BBTSCAN option is necessary for 'overridesize' */ ··· 2263 2251 2264 2252 switch (bbt) { 2265 2253 case 2: 2266 - chip->bbt_options |= NAND_BBT_NO_OOB; 2254 + chip->bbt_options |= NAND_BBT_NO_OOB; 2255 + /* fall through */ 2267 2256 case 1: 2268 - chip->bbt_options |= NAND_BBT_USE_FLASH; 2257 + chip->bbt_options |= NAND_BBT_USE_FLASH; 2258 + /* fall through */ 2269 2259 case 0: 2270 2260 break; 2271 2261 default: ··· 2280 2266 * the initial ID read command correctly 2281 2267 */ 2282 2268 if (id_bytes[6] != 0xFF || id_bytes[7] != 0xFF) 2283 - nand->geom.idbytes = 8; 2269 + ns->geom.idbytes = 8; 2284 2270 else if (id_bytes[4] != 0xFF || id_bytes[5] != 0xFF) 2285 - nand->geom.idbytes = 6; 2271 + ns->geom.idbytes = 6; 2286 2272 else if (id_bytes[2] != 0xFF || id_bytes[3] != 0xFF) 2287 - nand->geom.idbytes = 4; 2273 + ns->geom.idbytes = 4; 2288 2274 else 2289 - nand->geom.idbytes = 2; 2290 - nand->regs.status = NS_STATUS_OK(nand); 2291 - nand->nxstate = STATE_UNKNOWN; 2292 - nand->options |= OPT_PAGE512; /* temporary value */ 2293 - memcpy(nand->ids, id_bytes, sizeof(nand->ids)); 2275 + ns->geom.idbytes = 2; 2276 + ns->regs.status = NS_STATUS_OK(ns); 2277 + ns->nxstate = STATE_UNKNOWN; 2278 + ns->options |= OPT_PAGE512; /* temporary value */ 2279 + memcpy(ns->ids, id_bytes, sizeof(ns->ids)); 2294 2280 if (bus_width == 16) { 2295 - nand->busw = 16; 2281 + ns->busw = 16; 2296 2282 chip->options |= NAND_BUSWIDTH_16; 2297 2283 } 2298 2284 ··· 2307 2293 if ((retval = parse_gravepages()) != 0) 2308 2294 goto error; 2309 2295 2310 - chip->legacy.dummy_controller.ops = &ns_controller_ops; 2296 + nand_controller_init(&ns->base); 2297 + ns->base.ops = &ns_controller_ops; 2298 + chip->controller = &ns->base; 2299 + 2311 2300 retval = nand_scan(chip, 1); 2312 2301 if (retval) { 2313 2302 NS_ERR("Could not scan NAND Simulator device\n"); ··· 2319 2302 2320 2303 if (overridesize) { 2321 2304 uint64_t new_size = (uint64_t)nsmtd->erasesize << overridesize; 2305 + struct nand_memory_organization *memorg; 2306 + u64 targetsize; 2307 + 2308 + memorg = nanddev_get_memorg(&chip->base); 2309 + 2322 2310 if (new_size >> overridesize != nsmtd->erasesize) { 2323 2311 NS_ERR("overridesize is too big\n"); 2324 2312 retval = -EINVAL; 2325 2313 goto err_exit; 2326 2314 } 2315 + 2327 2316 /* N.B. This relies on nand_scan not doing anything with the size before we change it */ 2328 2317 nsmtd->size = new_size; 2329 - chip->chipsize = new_size; 2318 + memorg->eraseblocks_per_lun = 1 << overridesize; 2319 + targetsize = nanddev_target_size(&chip->base); 2330 2320 chip->chip_shift = ffs(nsmtd->erasesize) + overridesize - 1; 2331 - chip->pagemask = (chip->chipsize >> chip->page_shift) - 1; 2321 + chip->pagemask = (targetsize >> chip->page_shift) - 1; 2332 2322 } 2333 2323 2334 2324 if ((retval = setup_wear_reporting(nsmtd)) != 0) ··· 2347 2323 if ((retval = nand_create_bbt(chip)) != 0) 2348 2324 goto err_exit; 2349 2325 2350 - if ((retval = parse_badblocks(nand, nsmtd)) != 0) 2326 + if ((retval = parse_badblocks(ns, nsmtd)) != 0) 2351 2327 goto err_exit; 2352 2328 2353 2329 /* Register NAND partitions */ 2354 - retval = mtd_device_register(nsmtd, &nand->partitions[0], 2355 - nand->nbparts); 2330 + retval = mtd_device_register(nsmtd, &ns->partitions[0], 2331 + ns->nbparts); 2356 2332 if (retval != 0) 2357 2333 goto err_exit; 2358 2334 2359 - if ((retval = nandsim_debugfs_create(nand)) != 0) 2335 + if ((retval = nandsim_debugfs_create(ns)) != 0) 2360 2336 goto err_exit; 2361 2337 2362 2338 return 0; 2363 2339 2364 2340 err_exit: 2365 - free_nandsim(nand); 2341 + free_nandsim(ns); 2366 2342 nand_release(chip); 2367 - for (i = 0;i < ARRAY_SIZE(nand->partitions); ++i) 2368 - kfree(nand->partitions[i].name); 2343 + for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) 2344 + kfree(ns->partitions[i].name); 2369 2345 error: 2370 - kfree(chip); 2346 + kfree(ns); 2371 2347 free_lists(); 2372 2348 2373 2349 return retval; ··· 2388 2364 nand_release(chip); /* Unregister driver */ 2389 2365 for (i = 0;i < ARRAY_SIZE(ns->partitions); ++i) 2390 2366 kfree(ns->partitions[i].name); 2391 - kfree(mtd_to_nand(nsmtd)); /* Free other structures */ 2367 + kfree(ns); /* Free other structures */ 2392 2368 free_lists(); 2393 2369 } 2394 2370
+2 -1
drivers/mtd/nand/raw/nuc900_nand.c
··· 192 192 return; 193 193 194 194 case NAND_CMD_READ0: 195 - 196 195 write_cmd_reg(nand, NAND_CMD_READSTART); 196 + /* fall through */ 197 + 197 198 default: 198 199 199 200 if (!chip->legacy.dev_ready) {
+2 -2
drivers/mtd/nand/raw/omap2.c
··· 1725 1725 break; 1726 1726 } 1727 1727 1728 - if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_BCH)) { 1728 + if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)) { 1729 1729 dev_err(&info->pdev->dev, 1730 - "CONFIG_MTD_NAND_ECC_BCH not enabled\n"); 1730 + "CONFIG_MTD_NAND_ECC_SW_BCH not enabled\n"); 1731 1731 return false; 1732 1732 } 1733 1733 if (ecc_needs_omap_bch && !IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH)) {
+4
drivers/mtd/nand/raw/omap_elm.c
··· 465 465 ELM_SYNDROME_FRAGMENT_5 + offset); 466 466 regs->elm_syndrome_fragment_4[i] = elm_read_reg(info, 467 467 ELM_SYNDROME_FRAGMENT_4 + offset); 468 + /* fall through */ 468 469 case BCH8_ECC: 469 470 regs->elm_syndrome_fragment_3[i] = elm_read_reg(info, 470 471 ELM_SYNDROME_FRAGMENT_3 + offset); 471 472 regs->elm_syndrome_fragment_2[i] = elm_read_reg(info, 472 473 ELM_SYNDROME_FRAGMENT_2 + offset); 474 + /* fall through */ 473 475 case BCH4_ECC: 474 476 regs->elm_syndrome_fragment_1[i] = elm_read_reg(info, 475 477 ELM_SYNDROME_FRAGMENT_1 + offset); ··· 513 511 regs->elm_syndrome_fragment_5[i]); 514 512 elm_write_reg(info, ELM_SYNDROME_FRAGMENT_4 + offset, 515 513 regs->elm_syndrome_fragment_4[i]); 514 + /* fall through */ 516 515 case BCH8_ECC: 517 516 elm_write_reg(info, ELM_SYNDROME_FRAGMENT_3 + offset, 518 517 regs->elm_syndrome_fragment_3[i]); 519 518 elm_write_reg(info, ELM_SYNDROME_FRAGMENT_2 + offset, 520 519 regs->elm_syndrome_fragment_2[i]); 520 + /* fall through */ 521 521 case BCH4_ECC: 522 522 elm_write_reg(info, ELM_SYNDROME_FRAGMENT_1 + offset, 523 523 regs->elm_syndrome_fragment_1[i]);
+3 -5
drivers/mtd/nand/raw/qcom_nandc.c
··· 1680 1680 u8 *cw_data_buf, *cw_oob_buf; 1681 1681 int cw, data_size, oob_size, ret = 0; 1682 1682 1683 - if (!data_buf) { 1684 - data_buf = chip->data_buf; 1685 - chip->pagebuf = -1; 1686 - } 1683 + if (!data_buf) 1684 + data_buf = nand_get_data_buf(chip); 1687 1685 1688 1686 if (!oob_buf) { 1687 + nand_get_data_buf(chip); 1689 1688 oob_buf = chip->oob_poi; 1690 - chip->pagebuf = -1; 1691 1689 } 1692 1690 1693 1691 for_each_set_bit(cw, &uncorrectable_cws, ecc->steps) {
+7 -6
drivers/mtd/nand/raw/sh_flctl.c
··· 101 101 static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 102 102 103 103 static struct nand_bbt_descr flctl_4secc_smallpage = { 104 - .options = NAND_BBT_SCAN2NDPAGE, 105 104 .offs = 11, 106 105 .len = 1, 107 106 .pattern = scan_ff_pattern, 108 107 }; 109 108 110 109 static struct nand_bbt_descr flctl_4secc_largepage = { 111 - .options = NAND_BBT_SCAN2NDPAGE, 112 110 .offs = 0, 113 111 .len = 2, 114 112 .pattern = scan_ff_pattern, ··· 984 986 985 987 static int flctl_chip_attach_chip(struct nand_chip *chip) 986 988 { 989 + u64 targetsize = nanddev_target_size(&chip->base); 987 990 struct mtd_info *mtd = nand_to_mtd(chip); 988 991 struct sh_flctl *flctl = mtd_to_flctl(mtd); 989 992 ··· 997 998 998 999 if (mtd->writesize == 512) { 999 1000 flctl->page_size = 0; 1000 - if (chip->chipsize > (32 << 20)) { 1001 + if (targetsize > (32 << 20)) { 1001 1002 /* big than 32MB */ 1002 1003 flctl->rw_ADRCNT = ADRCNT_4; 1003 1004 flctl->erase_ADRCNT = ADRCNT_3; 1004 - } else if (chip->chipsize > (2 << 16)) { 1005 + } else if (targetsize > (2 << 16)) { 1005 1006 /* big than 128KB */ 1006 1007 flctl->rw_ADRCNT = ADRCNT_3; 1007 1008 flctl->erase_ADRCNT = ADRCNT_2; ··· 1011 1012 } 1012 1013 } else { 1013 1014 flctl->page_size = 1; 1014 - if (chip->chipsize > (128 << 20)) { 1015 + if (targetsize > (128 << 20)) { 1015 1016 /* big than 128MB */ 1016 1017 flctl->rw_ADRCNT = ADRCNT2_E; 1017 1018 flctl->erase_ADRCNT = ADRCNT_3; 1018 - } else if (chip->chipsize > (8 << 16)) { 1019 + } else if (targetsize > (8 << 16)) { 1019 1020 /* big than 512KB */ 1020 1021 flctl->rw_ADRCNT = ADRCNT_4; 1021 1022 flctl->erase_ADRCNT = ADRCNT_2; ··· 1176 1177 1177 1178 if (pdata->flcmncr_val & SEL_16BIT) 1178 1179 nand->options |= NAND_BUSWIDTH_16; 1180 + 1181 + nand->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; 1179 1182 1180 1183 pm_runtime_enable(&pdev->dev); 1181 1184 pm_runtime_resume(&pdev->dev);
+75 -15
drivers/mtd/nand/raw/sunxi_nand.c
··· 42 42 #define NFC_REG_CMD 0x0024 43 43 #define NFC_REG_RCMD_SET 0x0028 44 44 #define NFC_REG_WCMD_SET 0x002C 45 - #define NFC_REG_IO_DATA 0x0030 45 + #define NFC_REG_A10_IO_DATA 0x0030 46 + #define NFC_REG_A23_IO_DATA 0x0300 46 47 #define NFC_REG_ECC_CTL 0x0034 47 48 #define NFC_REG_ECC_ST 0x0038 48 49 #define NFC_REG_DEBUG 0x003C ··· 201 200 return container_of(nand, struct sunxi_nand_chip, nand); 202 201 } 203 202 203 + /* 204 + * NAND Controller capabilities structure: stores NAND controller capabilities 205 + * for distinction between compatible strings. 206 + * 207 + * @sram_through_ahb: On A23, we choose to access the internal RAM through AHB 208 + * instead of MBUS (less configuration). A10, A10s, A13 and 209 + * A20 use the MBUS but no extra configuration is needed. 210 + * @reg_io_data: I/O data register 211 + * @dma_maxburst: DMA maxburst 212 + */ 213 + struct sunxi_nfc_caps { 214 + bool sram_through_ahb; 215 + unsigned int reg_io_data; 216 + unsigned int dma_maxburst; 217 + }; 218 + 204 219 /** 205 220 * struct sunxi_nfc - stores sunxi NAND controller information 206 221 * ··· 245 228 struct list_head chips; 246 229 struct completion complete; 247 230 struct dma_chan *dmac; 231 + const struct sunxi_nfc_caps *caps; 248 232 }; 249 233 250 234 static inline struct sunxi_nfc *to_sunxi_nfc(struct nand_controller *ctrl) ··· 368 350 goto err_unmap_buf; 369 351 } 370 352 371 - writel(readl(nfc->regs + NFC_REG_CTL) | NFC_RAM_METHOD, 372 - nfc->regs + NFC_REG_CTL); 353 + /* 354 + * On A23, we suppose the "internal RAM" (p.12 of the NFC user manual) 355 + * refers to the NAND controller's internal SRAM. This memory is mapped 356 + * and so is accessible from the AHB. It seems that it can also be 357 + * accessed by the MBUS. MBUS accesses are mandatory when using the 358 + * internal DMA instead of the external DMA engine. 359 + * 360 + * During DMA I/O operation, either we access this memory from the AHB 361 + * by clearing the NFC_RAM_METHOD bit, or we set the bit and use the 362 + * MBUS. In this case, we should also configure the MBUS DMA length 363 + * NFC_REG_MDMA_CNT(0xC4) to be chunksize * nchunks. NAND I/O over MBUS 364 + * are also limited to 32kiB pages. 365 + */ 366 + if (nfc->caps->sram_through_ahb) 367 + writel(readl(nfc->regs + NFC_REG_CTL) & ~NFC_RAM_METHOD, 368 + nfc->regs + NFC_REG_CTL); 369 + else 370 + writel(readl(nfc->regs + NFC_REG_CTL) | NFC_RAM_METHOD, 371 + nfc->regs + NFC_REG_CTL); 372 + 373 373 writel(nchunks, nfc->regs + NFC_REG_SECTOR_NUM); 374 374 writel(chunksize, nfc->regs + NFC_REG_CNT); 375 + 375 376 dmat = dmaengine_submit(dmad); 376 377 377 378 ret = dma_submit_error(dmat); ··· 1350 1313 1351 1314 static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page) 1352 1315 { 1353 - nand->pagebuf = -1; 1316 + u8 *buf = nand_get_data_buf(nand); 1354 1317 1355 - return nand->ecc.read_page(nand, nand->data_buf, 1, page); 1318 + return nand->ecc.read_page(nand, buf, 1, page); 1356 1319 } 1357 1320 1358 1321 static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page) 1359 1322 { 1360 1323 struct mtd_info *mtd = nand_to_mtd(nand); 1324 + u8 *buf = nand_get_data_buf(nand); 1361 1325 int ret; 1362 1326 1363 - nand->pagebuf = -1; 1364 - 1365 - memset(nand->data_buf, 0xff, mtd->writesize); 1366 - ret = nand->ecc.write_page(nand, nand->data_buf, 1, page); 1327 + memset(buf, 0xff, mtd->writesize); 1328 + ret = nand->ecc.write_page(nand, buf, 1, page); 1367 1329 if (ret) 1368 1330 return ret; 1369 1331 ··· 1760 1724 nand->options |= NAND_SUBPAGE_READ; 1761 1725 1762 1726 if (!ecc->size) { 1763 - ecc->size = nand->ecc_step_ds; 1764 - ecc->strength = nand->ecc_strength_ds; 1727 + ecc->size = nand->base.eccreq.step_size; 1728 + ecc->strength = nand->base.eccreq.strength; 1765 1729 } 1766 1730 1767 1731 if (!ecc->size || !ecc->strength) ··· 2124 2088 goto out_mod_clk_unprepare; 2125 2089 } 2126 2090 2091 + nfc->caps = of_device_get_match_data(&pdev->dev); 2092 + if (!nfc->caps) { 2093 + ret = -EINVAL; 2094 + goto out_ahb_reset_reassert; 2095 + } 2096 + 2127 2097 ret = sunxi_nfc_rst(nfc); 2128 2098 if (ret) 2129 2099 goto out_ahb_reset_reassert; ··· 2144 2102 if (nfc->dmac) { 2145 2103 struct dma_slave_config dmac_cfg = { }; 2146 2104 2147 - dmac_cfg.src_addr = r->start + NFC_REG_IO_DATA; 2105 + dmac_cfg.src_addr = r->start + nfc->caps->reg_io_data; 2148 2106 dmac_cfg.dst_addr = dmac_cfg.src_addr; 2149 2107 dmac_cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 2150 2108 dmac_cfg.dst_addr_width = dmac_cfg.src_addr_width; 2151 - dmac_cfg.src_maxburst = 4; 2152 - dmac_cfg.dst_maxburst = 4; 2109 + dmac_cfg.src_maxburst = nfc->caps->dma_maxburst; 2110 + dmac_cfg.dst_maxburst = nfc->caps->dma_maxburst; 2153 2111 dmaengine_slave_config(nfc->dmac, &dmac_cfg); 2154 2112 } else { 2155 2113 dev_warn(dev, "failed to request rxtx DMA channel\n"); ··· 2194 2152 return 0; 2195 2153 } 2196 2154 2155 + static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { 2156 + .reg_io_data = NFC_REG_A10_IO_DATA, 2157 + .dma_maxburst = 4, 2158 + }; 2159 + 2160 + static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { 2161 + .sram_through_ahb = true, 2162 + .reg_io_data = NFC_REG_A23_IO_DATA, 2163 + .dma_maxburst = 8, 2164 + }; 2165 + 2197 2166 static const struct of_device_id sunxi_nfc_ids[] = { 2198 - { .compatible = "allwinner,sun4i-a10-nand" }, 2167 + { 2168 + .compatible = "allwinner,sun4i-a10-nand", 2169 + .data = &sunxi_nfc_a10_caps, 2170 + }, 2171 + { 2172 + .compatible = "allwinner,sun8i-a23-nand-controller", 2173 + .data = &sunxi_nfc_a23_caps, 2174 + }, 2199 2175 { /* sentinel */ } 2200 2176 }; 2201 2177 MODULE_DEVICE_TABLE(of, sunxi_nfc_ids);
+4 -4
drivers/mtd/nand/raw/tegra_nand.c
··· 853 853 } else { 854 854 strength_sel = strength[i]; 855 855 856 - if (strength_sel < chip->ecc_strength_ds) 856 + if (strength_sel < chip->base.eccreq.strength) 857 857 continue; 858 858 } 859 859 ··· 917 917 chip->ecc.mode = NAND_ECC_HW; 918 918 chip->ecc.size = 512; 919 919 chip->ecc.steps = mtd->writesize / chip->ecc.size; 920 - if (chip->ecc_step_ds != 512) { 920 + if (chip->base.eccreq.step_size != 512) { 921 921 dev_err(ctrl->dev, "Unsupported step size %d\n", 922 - chip->ecc_step_ds); 922 + chip->base.eccreq.step_size); 923 923 return -EINVAL; 924 924 } 925 925 ··· 950 950 if (ret < 0) { 951 951 dev_err(ctrl->dev, 952 952 "No valid strength found, minimum %d\n", 953 - chip->ecc_strength_ds); 953 + chip->base.eccreq.strength); 954 954 return ret; 955 955 } 956 956
+3
drivers/mtd/nand/raw/vf610_nfc.c
··· 850 850 } 851 851 852 852 of_id = of_match_device(vf610_nfc_dt_ids, &pdev->dev); 853 + if (!of_id) 854 + return -ENODEV; 855 + 853 856 nfc->variant = (enum vf610_nfc_variant)of_id->data; 854 857 855 858 for_each_available_child_of_node(nfc->dev->of_node, child) {
+85 -84
drivers/mtd/nand/spi/core.c
··· 19 19 #include <linux/spi/spi.h> 20 20 #include <linux/spi/spi-mem.h> 21 21 22 - static void spinand_cache_op_adjust_colum(struct spinand_device *spinand, 23 - const struct nand_page_io_req *req, 24 - u16 *column) 25 - { 26 - struct nand_device *nand = spinand_to_nand(spinand); 27 - unsigned int shift; 28 - 29 - if (nand->memorg.planes_per_lun < 2) 30 - return; 31 - 32 - /* The plane number is passed in MSB just above the column address */ 33 - shift = fls(nand->memorg.pagesize); 34 - *column |= req->pos.plane << shift; 35 - } 36 - 37 22 static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val) 38 23 { 39 24 struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg, ··· 212 227 static int spinand_read_from_cache_op(struct spinand_device *spinand, 213 228 const struct nand_page_io_req *req) 214 229 { 215 - struct spi_mem_op op = *spinand->op_templates.read_cache; 216 230 struct nand_device *nand = spinand_to_nand(spinand); 217 231 struct mtd_info *mtd = nanddev_to_mtd(nand); 218 - struct nand_page_io_req adjreq = *req; 232 + struct spi_mem_dirmap_desc *rdesc; 219 233 unsigned int nbytes = 0; 220 234 void *buf = NULL; 221 235 u16 column = 0; 222 - int ret; 236 + ssize_t ret; 223 237 224 238 if (req->datalen) { 225 - adjreq.datalen = nanddev_page_size(nand); 226 - adjreq.dataoffs = 0; 227 - adjreq.databuf.in = spinand->databuf; 228 239 buf = spinand->databuf; 229 - nbytes = adjreq.datalen; 240 + nbytes = nanddev_page_size(nand); 241 + column = 0; 230 242 } 231 243 232 244 if (req->ooblen) { 233 - adjreq.ooblen = nanddev_per_page_oobsize(nand); 234 - adjreq.ooboffs = 0; 235 - adjreq.oobbuf.in = spinand->oobbuf; 236 245 nbytes += nanddev_per_page_oobsize(nand); 237 246 if (!buf) { 238 247 buf = spinand->oobbuf; ··· 234 255 } 235 256 } 236 257 237 - spinand_cache_op_adjust_colum(spinand, &adjreq, &column); 238 - op.addr.val = column; 258 + rdesc = spinand->dirmaps[req->pos.plane].rdesc; 239 259 240 - /* 241 - * Some controllers are limited in term of max RX data size. In this 242 - * case, just repeat the READ_CACHE operation after updating the 243 - * column. 244 - */ 245 260 while (nbytes) { 246 - op.data.buf.in = buf; 247 - op.data.nbytes = nbytes; 248 - ret = spi_mem_adjust_op_size(spinand->spimem, &op); 249 - if (ret) 261 + ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf); 262 + if (ret < 0) 250 263 return ret; 251 264 252 - ret = spi_mem_exec_op(spinand->spimem, &op); 253 - if (ret) 254 - return ret; 265 + if (!ret || ret > nbytes) 266 + return -EIO; 255 267 256 - buf += op.data.nbytes; 257 - nbytes -= op.data.nbytes; 258 - op.addr.val += op.data.nbytes; 268 + nbytes -= ret; 269 + column += ret; 270 + buf += ret; 259 271 } 260 272 261 273 if (req->datalen) ··· 270 300 static int spinand_write_to_cache_op(struct spinand_device *spinand, 271 301 const struct nand_page_io_req *req) 272 302 { 273 - struct spi_mem_op op = *spinand->op_templates.write_cache; 274 303 struct nand_device *nand = spinand_to_nand(spinand); 275 304 struct mtd_info *mtd = nanddev_to_mtd(nand); 276 - struct nand_page_io_req adjreq = *req; 305 + struct spi_mem_dirmap_desc *wdesc; 306 + unsigned int nbytes, column = 0; 277 307 void *buf = spinand->databuf; 278 - unsigned int nbytes; 279 - u16 column = 0; 280 - int ret; 308 + ssize_t ret; 281 309 282 310 /* 283 311 * Looks like PROGRAM LOAD (AKA write cache) does not necessarily reset ··· 286 318 */ 287 319 nbytes = nanddev_page_size(nand) + nanddev_per_page_oobsize(nand); 288 320 memset(spinand->databuf, 0xff, nbytes); 289 - adjreq.dataoffs = 0; 290 - adjreq.datalen = nanddev_page_size(nand); 291 - adjreq.databuf.out = spinand->databuf; 292 - adjreq.ooblen = nanddev_per_page_oobsize(nand); 293 - adjreq.ooboffs = 0; 294 - adjreq.oobbuf.out = spinand->oobbuf; 295 321 296 322 if (req->datalen) 297 323 memcpy(spinand->databuf + req->dataoffs, req->databuf.out, ··· 302 340 req->ooblen); 303 341 } 304 342 305 - spinand_cache_op_adjust_colum(spinand, &adjreq, &column); 343 + wdesc = spinand->dirmaps[req->pos.plane].wdesc; 306 344 307 - op = *spinand->op_templates.write_cache; 308 - op.addr.val = column; 309 - 310 - /* 311 - * Some controllers are limited in term of max TX data size. In this 312 - * case, split the operation into one LOAD CACHE and one or more 313 - * LOAD RANDOM CACHE. 314 - */ 315 345 while (nbytes) { 316 - op.data.buf.out = buf; 317 - op.data.nbytes = nbytes; 318 - 319 - ret = spi_mem_adjust_op_size(spinand->spimem, &op); 320 - if (ret) 346 + ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf); 347 + if (ret < 0) 321 348 return ret; 322 349 323 - ret = spi_mem_exec_op(spinand->spimem, &op); 324 - if (ret) 325 - return ret; 350 + if (!ret || ret > nbytes) 351 + return -EIO; 326 352 327 - buf += op.data.nbytes; 328 - nbytes -= op.data.nbytes; 329 - op.addr.val += op.data.nbytes; 330 - 331 - /* 332 - * We need to use the RANDOM LOAD CACHE operation if there's 333 - * more than one iteration, because the LOAD operation might 334 - * reset the cache to 0xff. 335 - */ 336 - if (nbytes) { 337 - column = op.addr.val; 338 - op = *spinand->op_templates.update_cache; 339 - op.addr.val = column; 340 - } 353 + nbytes -= ret; 354 + column += ret; 355 + buf += ret; 341 356 } 342 357 343 358 return 0; ··· 694 755 return ret; 695 756 } 696 757 758 + static int spinand_create_dirmap(struct spinand_device *spinand, 759 + unsigned int plane) 760 + { 761 + struct nand_device *nand = spinand_to_nand(spinand); 762 + struct spi_mem_dirmap_info info = { 763 + .length = nanddev_page_size(nand) + 764 + nanddev_per_page_oobsize(nand), 765 + }; 766 + struct spi_mem_dirmap_desc *desc; 767 + 768 + /* The plane number is passed in MSB just above the column address */ 769 + info.offset = plane << fls(nand->memorg.pagesize); 770 + 771 + info.op_tmpl = *spinand->op_templates.update_cache; 772 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, 773 + spinand->spimem, &info); 774 + if (IS_ERR(desc)) 775 + return PTR_ERR(desc); 776 + 777 + spinand->dirmaps[plane].wdesc = desc; 778 + 779 + info.op_tmpl = *spinand->op_templates.read_cache; 780 + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, 781 + spinand->spimem, &info); 782 + if (IS_ERR(desc)) 783 + return PTR_ERR(desc); 784 + 785 + spinand->dirmaps[plane].rdesc = desc; 786 + 787 + return 0; 788 + } 789 + 790 + static int spinand_create_dirmaps(struct spinand_device *spinand) 791 + { 792 + struct nand_device *nand = spinand_to_nand(spinand); 793 + int i, ret; 794 + 795 + spinand->dirmaps = devm_kzalloc(&spinand->spimem->spi->dev, 796 + sizeof(*spinand->dirmaps) * 797 + nand->memorg.planes_per_lun, 798 + GFP_KERNEL); 799 + if (!spinand->dirmaps) 800 + return -ENOMEM; 801 + 802 + for (i = 0; i < nand->memorg.planes_per_lun; i++) { 803 + ret = spinand_create_dirmap(spinand, i); 804 + if (ret) 805 + return ret; 806 + } 807 + 808 + return 0; 809 + } 810 + 697 811 static const struct nand_ops spinand_ops = { 698 812 .erase = spinand_erase, 699 813 .markbad = spinand_markbad, ··· 1004 1012 goto err_free_bufs; 1005 1013 } 1006 1014 1015 + ret = spinand_create_dirmaps(spinand); 1016 + if (ret) { 1017 + dev_err(dev, 1018 + "Failed to create direct mappings for read/write operations (err = %d)\n", 1019 + ret); 1020 + goto err_manuf_cleanup; 1021 + } 1022 + 1007 1023 /* After power up, all blocks are locked, so unlock them here. */ 1008 1024 for (i = 0; i < nand->memorg.ntargets; i++) { 1009 1025 ret = spinand_select_target(spinand, i); ··· 1037 1037 mtd->_block_markbad = spinand_mtd_block_markbad; 1038 1038 mtd->_block_isreserved = spinand_mtd_block_isreserved; 1039 1039 mtd->_erase = spinand_mtd_erase; 1040 + mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks; 1040 1041 1041 1042 if (spinand->eccinfo.ooblayout) 1042 1043 mtd_set_ooblayout(mtd, spinand->eccinfo.ooblayout);
+4 -4
drivers/mtd/nand/spi/gigadevice.c
··· 162 162 163 163 static const struct spinand_info gigadevice_spinand_table[] = { 164 164 SPINAND_INFO("GD5F1GQ4xA", 0xF1, 165 - NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 165 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), 166 166 NAND_ECCREQ(8, 512), 167 167 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 168 168 &write_cache_variants, ··· 171 171 SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout, 172 172 gd5fxgq4xa_ecc_get_status)), 173 173 SPINAND_INFO("GD5F2GQ4xA", 0xF2, 174 - NAND_MEMORG(1, 2048, 64, 64, 2048, 1, 1, 1), 174 + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1), 175 175 NAND_ECCREQ(8, 512), 176 176 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 177 177 &write_cache_variants, ··· 180 180 SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout, 181 181 gd5fxgq4xa_ecc_get_status)), 182 182 SPINAND_INFO("GD5F4GQ4xA", 0xF4, 183 - NAND_MEMORG(1, 2048, 64, 64, 4096, 1, 1, 1), 183 + NAND_MEMORG(1, 2048, 64, 64, 4096, 40, 1, 1, 1), 184 184 NAND_ECCREQ(8, 512), 185 185 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 186 186 &write_cache_variants, ··· 189 189 SPINAND_ECCINFO(&gd5fxgq4xa_ooblayout, 190 190 gd5fxgq4xa_ecc_get_status)), 191 191 SPINAND_INFO("GD5F1GQ4UExxG", 0xd1, 192 - NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1), 192 + NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1), 193 193 NAND_ECCREQ(8, 512), 194 194 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 195 195 &write_cache_variants,
+2 -2
drivers/mtd/nand/spi/macronix.c
··· 100 100 101 101 static const struct spinand_info macronix_spinand_table[] = { 102 102 SPINAND_INFO("MX35LF1GE4AB", 0x12, 103 - NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 103 + NAND_MEMORG(1, 2048, 64, 64, 1024, 40, 1, 1, 1), 104 104 NAND_ECCREQ(4, 512), 105 105 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 106 106 &write_cache_variants, ··· 109 109 SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, 110 110 mx35lf1ge4ab_ecc_get_status)), 111 111 SPINAND_INFO("MX35LF2GE4AB", 0x22, 112 - NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1), 112 + NAND_MEMORG(1, 2048, 64, 64, 2048, 20, 2, 1, 1), 113 113 NAND_ECCREQ(4, 512), 114 114 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 115 115 &write_cache_variants,
+1 -1
drivers/mtd/nand/spi/micron.c
··· 92 92 93 93 static const struct spinand_info micron_spinand_table[] = { 94 94 SPINAND_INFO("MT29F2G01ABAGD", 0x24, 95 - NAND_MEMORG(1, 2048, 128, 64, 2048, 2, 1, 1), 95 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1), 96 96 NAND_ECCREQ(8, 512), 97 97 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 98 98 &write_cache_variants,
+6 -6
drivers/mtd/nand/spi/toshiba.c
··· 96 96 static const struct spinand_info toshiba_spinand_table[] = { 97 97 /* 3.3V 1Gb */ 98 98 SPINAND_INFO("TC58CVG0S3", 0xC2, 99 - NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1), 99 + NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1), 100 100 NAND_ECCREQ(8, 512), 101 101 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 102 102 &write_cache_variants, ··· 106 106 tc58cxgxsx_ecc_get_status)), 107 107 /* 3.3V 2Gb */ 108 108 SPINAND_INFO("TC58CVG1S3", 0xCB, 109 - NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1), 109 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1), 110 110 NAND_ECCREQ(8, 512), 111 111 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 112 112 &write_cache_variants, ··· 116 116 tc58cxgxsx_ecc_get_status)), 117 117 /* 3.3V 4Gb */ 118 118 SPINAND_INFO("TC58CVG2S0", 0xCD, 119 - NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1), 119 + NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1), 120 120 NAND_ECCREQ(8, 512), 121 121 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 122 122 &write_cache_variants, ··· 126 126 tc58cxgxsx_ecc_get_status)), 127 127 /* 1.8V 1Gb */ 128 128 SPINAND_INFO("TC58CYG0S3", 0xB2, 129 - NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1), 129 + NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1), 130 130 NAND_ECCREQ(8, 512), 131 131 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 132 132 &write_cache_variants, ··· 136 136 tc58cxgxsx_ecc_get_status)), 137 137 /* 1.8V 2Gb */ 138 138 SPINAND_INFO("TC58CYG1S3", 0xBB, 139 - NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1), 139 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1), 140 140 NAND_ECCREQ(8, 512), 141 141 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 142 142 &write_cache_variants, ··· 146 146 tc58cxgxsx_ecc_get_status)), 147 147 /* 1.8V 4Gb */ 148 148 SPINAND_INFO("TC58CYG2S0", 0xBD, 149 - NAND_MEMORG(1, 4096, 256, 64, 2048, 1, 1, 1), 149 + NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1), 150 150 NAND_ECCREQ(8, 512), 151 151 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 152 152 &write_cache_variants,
+2 -2
drivers/mtd/nand/spi/winbond.c
··· 76 76 77 77 static const struct spinand_info winbond_spinand_table[] = { 78 78 SPINAND_INFO("W25M02GV", 0xAB, 79 - NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2), 79 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2), 80 80 NAND_ECCREQ(1, 512), 81 81 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 82 82 &write_cache_variants, ··· 85 85 SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL), 86 86 SPINAND_SELECT_TARGET(w25m02gv_select_target)), 87 87 SPINAND_INFO("W25N01GV", 0xAA, 88 - NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), 88 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1), 89 89 NAND_ECCREQ(1, 512), 90 90 SPINAND_INFO_OP_VARIANTS(&read_cache_variants, 91 91 &write_cache_variants,
+27
drivers/mtd/parsers/Kconfig
··· 1 + config MTD_PARSER_IMAGETAG 2 + tristate "Parser for BCM963XX Image Tag format partitions" 3 + depends on BCM63XX || BMIPS_GENERIC || COMPILE_TEST 4 + select CRC32 5 + help 6 + Image Tag is the firmware header used by broadcom on their xDSL line 7 + of devices. It is used to describe the offsets and lengths of kernel 8 + and rootfs partitions. 9 + This driver adds support for parsing a partition with an Image Tag 10 + header and creates up to two partitions, kernel and rootfs. 11 + 12 + config MTD_AFS_PARTS 13 + tristate "ARM Firmware Suite partition parsing" 14 + depends on (ARM || ARM64) 15 + help 16 + The ARM Firmware Suite allows the user to divide flash devices into 17 + multiple 'images'. Each such image has a header containing its name 18 + and offset/size etc. 19 + 20 + If you need code which can detect and parse these tables, and 21 + register MTD 'partitions' corresponding to each image detected, 22 + enable this option. 23 + 24 + You will still need the parsing functions to be called by the driver 25 + for your particular device. It won't happen automatically. The 26 + 'physmap' map driver (CONFIG_MTD_PHYSMAP) does this, for example. 27 + 1 28 config MTD_PARSER_TRX 2 29 tristate "Parser for TRX format partitions" 3 30 depends on MTD && (BCM47XX || ARCH_BCM_5301X || COMPILE_TEST)
+2
drivers/mtd/parsers/Makefile
··· 1 + obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o 2 + obj-$(CONFIG_MTD_AFS_PARTS) += afs.o 1 3 obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o 2 4 obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o 3 5 obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
+410
drivers/mtd/parsers/afs.c
··· 1 + /*====================================================================== 2 + 3 + drivers/mtd/afs.c: ARM Flash Layout/Partitioning 4 + 5 + Copyright © 2000 ARM Limited 6 + Copyright (C) 2019 Linus Walleij 7 + 8 + This program is free software; you can redistribute it and/or modify 9 + it under the terms of the GNU General Public License as published by 10 + the Free Software Foundation; either version 2 of the License, or 11 + (at your option) any later version. 12 + 13 + This program is distributed in the hope that it will be useful, 14 + but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + GNU General Public License for more details. 17 + 18 + You should have received a copy of the GNU General Public License 19 + along with this program; if not, write to the Free Software 20 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 + 22 + This is access code for flashes using ARM's flash partitioning 23 + standards. 24 + 25 + ======================================================================*/ 26 + 27 + #include <linux/module.h> 28 + #include <linux/types.h> 29 + #include <linux/kernel.h> 30 + #include <linux/slab.h> 31 + #include <linux/string.h> 32 + #include <linux/init.h> 33 + 34 + #include <linux/mtd/mtd.h> 35 + #include <linux/mtd/map.h> 36 + #include <linux/mtd/partitions.h> 37 + 38 + #define AFSV1_FOOTER_MAGIC 0xA0FFFF9F 39 + #define AFSV2_FOOTER_MAGIC1 0x464C5348 /* "FLSH" */ 40 + #define AFSV2_FOOTER_MAGIC2 0x464F4F54 /* "FOOT" */ 41 + 42 + struct footer_v1 { 43 + u32 image_info_base; /* Address of first word of ImageFooter */ 44 + u32 image_start; /* Start of area reserved by this footer */ 45 + u32 signature; /* 'Magic' number proves it's a footer */ 46 + u32 type; /* Area type: ARM Image, SIB, customer */ 47 + u32 checksum; /* Just this structure */ 48 + }; 49 + 50 + struct image_info_v1 { 51 + u32 bootFlags; /* Boot flags, compression etc. */ 52 + u32 imageNumber; /* Unique number, selects for boot etc. */ 53 + u32 loadAddress; /* Address program should be loaded to */ 54 + u32 length; /* Actual size of image */ 55 + u32 address; /* Image is executed from here */ 56 + char name[16]; /* Null terminated */ 57 + u32 headerBase; /* Flash Address of any stripped header */ 58 + u32 header_length; /* Length of header in memory */ 59 + u32 headerType; /* AIF, RLF, s-record etc. */ 60 + u32 checksum; /* Image checksum (inc. this struct) */ 61 + }; 62 + 63 + static u32 word_sum(void *words, int num) 64 + { 65 + u32 *p = words; 66 + u32 sum = 0; 67 + 68 + while (num--) 69 + sum += *p++; 70 + 71 + return sum; 72 + } 73 + 74 + static u32 word_sum_v2(u32 *p, u32 num) 75 + { 76 + u32 sum = 0; 77 + int i; 78 + 79 + for (i = 0; i < num; i++) { 80 + u32 val; 81 + 82 + val = p[i]; 83 + if (val > ~sum) 84 + sum++; 85 + sum += val; 86 + } 87 + return ~sum; 88 + } 89 + 90 + static bool afs_is_v1(struct mtd_info *mtd, u_int off) 91 + { 92 + /* The magic is 12 bytes from the end of the erase block */ 93 + u_int ptr = off + mtd->erasesize - 12; 94 + u32 magic; 95 + size_t sz; 96 + int ret; 97 + 98 + ret = mtd_read(mtd, ptr, 4, &sz, (u_char *)&magic); 99 + if (ret < 0) { 100 + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 101 + ptr, ret); 102 + return false; 103 + } 104 + if (ret >= 0 && sz != 4) 105 + return false; 106 + 107 + return (magic == AFSV1_FOOTER_MAGIC); 108 + } 109 + 110 + static bool afs_is_v2(struct mtd_info *mtd, u_int off) 111 + { 112 + /* The magic is the 8 last bytes of the erase block */ 113 + u_int ptr = off + mtd->erasesize - 8; 114 + u32 foot[2]; 115 + size_t sz; 116 + int ret; 117 + 118 + ret = mtd_read(mtd, ptr, 8, &sz, (u_char *)foot); 119 + if (ret < 0) { 120 + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 121 + ptr, ret); 122 + return false; 123 + } 124 + if (ret >= 0 && sz != 8) 125 + return false; 126 + 127 + return (foot[0] == AFSV2_FOOTER_MAGIC1 && 128 + foot[1] == AFSV2_FOOTER_MAGIC2); 129 + } 130 + 131 + static int afs_parse_v1_partition(struct mtd_info *mtd, 132 + u_int off, struct mtd_partition *part) 133 + { 134 + struct footer_v1 fs; 135 + struct image_info_v1 iis; 136 + u_int mask; 137 + /* 138 + * Static checks cannot see that we bail out if we have an error 139 + * reading the footer. 140 + */ 141 + u_int uninitialized_var(iis_ptr); 142 + u_int uninitialized_var(img_ptr); 143 + u_int ptr; 144 + size_t sz; 145 + int ret; 146 + int i; 147 + 148 + /* 149 + * This is the address mask; we use this to mask off out of 150 + * range address bits. 151 + */ 152 + mask = mtd->size - 1; 153 + 154 + ptr = off + mtd->erasesize - sizeof(fs); 155 + ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); 156 + if (ret >= 0 && sz != sizeof(fs)) 157 + ret = -EINVAL; 158 + if (ret < 0) { 159 + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 160 + ptr, ret); 161 + return ret; 162 + } 163 + /* 164 + * Check the checksum. 165 + */ 166 + if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff) 167 + return -EINVAL; 168 + 169 + /* 170 + * Hide the SIB (System Information Block) 171 + */ 172 + if (fs.type == 2) 173 + return 0; 174 + 175 + iis_ptr = fs.image_info_base & mask; 176 + img_ptr = fs.image_start & mask; 177 + 178 + /* 179 + * Check the image info base. This can not 180 + * be located after the footer structure. 181 + */ 182 + if (iis_ptr >= ptr) 183 + return 0; 184 + 185 + /* 186 + * Check the start of this image. The image 187 + * data can not be located after this block. 188 + */ 189 + if (img_ptr > off) 190 + return 0; 191 + 192 + /* Read the image info block */ 193 + memset(&iis, 0, sizeof(iis)); 194 + ret = mtd_read(mtd, iis_ptr, sizeof(iis), &sz, (u_char *)&iis); 195 + if (ret < 0) { 196 + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n", 197 + iis_ptr, ret); 198 + return -EINVAL; 199 + } 200 + 201 + if (sz != sizeof(iis)) 202 + return -EINVAL; 203 + 204 + /* 205 + * Validate the name - it must be NUL terminated. 206 + */ 207 + for (i = 0; i < sizeof(iis.name); i++) 208 + if (iis.name[i] == '\0') 209 + break; 210 + if (i > sizeof(iis.name)) 211 + return -EINVAL; 212 + 213 + part->name = kstrdup(iis.name, GFP_KERNEL); 214 + if (!part->name) 215 + return -ENOMEM; 216 + 217 + part->size = (iis.length + mtd->erasesize - 1) & ~(mtd->erasesize - 1); 218 + part->offset = img_ptr; 219 + part->mask_flags = 0; 220 + 221 + printk(" mtd: at 0x%08x, %5lluKiB, %8u, %s\n", 222 + img_ptr, part->size / 1024, 223 + iis.imageNumber, part->name); 224 + 225 + return 0; 226 + } 227 + 228 + static int afs_parse_v2_partition(struct mtd_info *mtd, 229 + u_int off, struct mtd_partition *part) 230 + { 231 + u_int ptr; 232 + u32 footer[12]; 233 + u32 imginfo[36]; 234 + char *name; 235 + u32 version; 236 + u32 entrypoint; 237 + u32 attributes; 238 + u32 region_count; 239 + u32 block_start; 240 + u32 block_end; 241 + u32 crc; 242 + size_t sz; 243 + int ret; 244 + int i; 245 + int pad = 0; 246 + 247 + pr_debug("Parsing v2 partition @%08x-%08x\n", 248 + off, off + mtd->erasesize); 249 + 250 + /* First read the footer */ 251 + ptr = off + mtd->erasesize - sizeof(footer); 252 + ret = mtd_read(mtd, ptr, sizeof(footer), &sz, (u_char *)footer); 253 + if ((ret < 0) || (ret >= 0 && sz != sizeof(footer))) { 254 + pr_err("AFS: mtd read failed at 0x%x: %d\n", 255 + ptr, ret); 256 + return -EIO; 257 + } 258 + name = (char *) &footer[0]; 259 + version = footer[9]; 260 + ptr = off + mtd->erasesize - sizeof(footer) - footer[8]; 261 + 262 + pr_debug("found image \"%s\", version %08x, info @%08x\n", 263 + name, version, ptr); 264 + 265 + /* Then read the image information */ 266 + ret = mtd_read(mtd, ptr, sizeof(imginfo), &sz, (u_char *)imginfo); 267 + if ((ret < 0) || (ret >= 0 && sz != sizeof(imginfo))) { 268 + pr_err("AFS: mtd read failed at 0x%x: %d\n", 269 + ptr, ret); 270 + return -EIO; 271 + } 272 + 273 + /* 32bit platforms have 4 bytes padding */ 274 + crc = word_sum_v2(&imginfo[1], 34); 275 + if (!crc) { 276 + pr_debug("Padding 1 word (4 bytes)\n"); 277 + pad = 1; 278 + } else { 279 + /* 64bit platforms have 8 bytes padding */ 280 + crc = word_sum_v2(&imginfo[2], 34); 281 + if (!crc) { 282 + pr_debug("Padding 2 words (8 bytes)\n"); 283 + pad = 2; 284 + } 285 + } 286 + if (crc) { 287 + pr_err("AFS: bad checksum on v2 image info: %08x\n", crc); 288 + return -EINVAL; 289 + } 290 + entrypoint = imginfo[pad]; 291 + attributes = imginfo[pad+1]; 292 + region_count = imginfo[pad+2]; 293 + block_start = imginfo[20]; 294 + block_end = imginfo[21]; 295 + 296 + pr_debug("image entry=%08x, attr=%08x, regions=%08x, " 297 + "bs=%08x, be=%08x\n", 298 + entrypoint, attributes, region_count, 299 + block_start, block_end); 300 + 301 + for (i = 0; i < region_count; i++) { 302 + u32 region_load_addr = imginfo[pad + 3 + i*4]; 303 + u32 region_size = imginfo[pad + 4 + i*4]; 304 + u32 region_offset = imginfo[pad + 5 + i*4]; 305 + u32 region_start; 306 + u32 region_end; 307 + 308 + pr_debug(" region %d: address: %08x, size: %08x, " 309 + "offset: %08x\n", 310 + i, 311 + region_load_addr, 312 + region_size, 313 + region_offset); 314 + 315 + region_start = off + region_offset; 316 + region_end = region_start + region_size; 317 + /* Align partition to end of erase block */ 318 + region_end += (mtd->erasesize - 1); 319 + region_end &= ~(mtd->erasesize -1); 320 + pr_debug(" partition start = %08x, partition end = %08x\n", 321 + region_start, region_end); 322 + 323 + /* Create one partition per region */ 324 + part->name = kstrdup(name, GFP_KERNEL); 325 + if (!part->name) 326 + return -ENOMEM; 327 + part->offset = region_start; 328 + part->size = region_end - region_start; 329 + part->mask_flags = 0; 330 + } 331 + 332 + return 0; 333 + } 334 + 335 + static int parse_afs_partitions(struct mtd_info *mtd, 336 + const struct mtd_partition **pparts, 337 + struct mtd_part_parser_data *data) 338 + { 339 + struct mtd_partition *parts; 340 + u_int off, sz; 341 + int ret = 0; 342 + int i; 343 + 344 + /* Count the partitions by looping over all erase blocks */ 345 + for (i = off = sz = 0; off < mtd->size; off += mtd->erasesize) { 346 + if (afs_is_v1(mtd, off)) { 347 + sz += sizeof(struct mtd_partition); 348 + i += 1; 349 + } 350 + if (afs_is_v2(mtd, off)) { 351 + sz += sizeof(struct mtd_partition); 352 + i += 1; 353 + } 354 + } 355 + 356 + if (!i) 357 + return 0; 358 + 359 + parts = kzalloc(sz, GFP_KERNEL); 360 + if (!parts) 361 + return -ENOMEM; 362 + 363 + /* 364 + * Identify the partitions 365 + */ 366 + for (i = off = 0; off < mtd->size; off += mtd->erasesize) { 367 + if (afs_is_v1(mtd, off)) { 368 + ret = afs_parse_v1_partition(mtd, off, &parts[i]); 369 + if (ret) 370 + goto out_free_parts; 371 + i++; 372 + } 373 + if (afs_is_v2(mtd, off)) { 374 + ret = afs_parse_v2_partition(mtd, off, &parts[i]); 375 + if (ret) 376 + goto out_free_parts; 377 + i++; 378 + } 379 + } 380 + 381 + *pparts = parts; 382 + return i; 383 + 384 + out_free_parts: 385 + while (i >= 0) { 386 + if (parts[i].name) 387 + kfree(parts[i].name); 388 + i--; 389 + } 390 + kfree(parts); 391 + *pparts = NULL; 392 + return ret; 393 + } 394 + 395 + static const struct of_device_id mtd_parser_afs_of_match_table[] = { 396 + { .compatible = "arm,arm-firmware-suite" }, 397 + {}, 398 + }; 399 + MODULE_DEVICE_TABLE(of, mtd_parser_afs_of_match_table); 400 + 401 + static struct mtd_part_parser afs_parser = { 402 + .parse_fn = parse_afs_partitions, 403 + .name = "afs", 404 + .of_match_table = mtd_parser_afs_of_match_table, 405 + }; 406 + module_mtd_part_parser(afs_parser); 407 + 408 + MODULE_AUTHOR("ARM Ltd"); 409 + MODULE_DESCRIPTION("ARM Firmware Suite partition parser"); 410 + MODULE_LICENSE("GPL");
+222
drivers/mtd/parsers/parser_imagetag.c
··· 1 + /* 2 + * BCM63XX CFE image tag parser 3 + * 4 + * Copyright © 2006-2008 Florian Fainelli <florian@openwrt.org> 5 + * Mike Albon <malbon@openwrt.org> 6 + * Copyright © 2009-2010 Daniel Dickinson <openwrt@cshore.neomailbox.net> 7 + * Copyright © 2011-2013 Jonas Gorski <jonas.gorski@gmail.com> 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 13 + * 14 + */ 15 + 16 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 17 + 18 + #include <linux/bcm963xx_tag.h> 19 + #include <linux/crc32.h> 20 + #include <linux/module.h> 21 + #include <linux/kernel.h> 22 + #include <linux/sizes.h> 23 + #include <linux/slab.h> 24 + #include <linux/vmalloc.h> 25 + #include <linux/mtd/mtd.h> 26 + #include <linux/mtd/partitions.h> 27 + #include <linux/of.h> 28 + 29 + /* Ensure strings read from flash structs are null terminated */ 30 + #define STR_NULL_TERMINATE(x) \ 31 + do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0) 32 + 33 + static int bcm963xx_read_imagetag(struct mtd_info *master, const char *name, 34 + loff_t tag_offset, struct bcm_tag *buf) 35 + { 36 + int ret; 37 + size_t retlen; 38 + u32 computed_crc; 39 + 40 + ret = mtd_read(master, tag_offset, sizeof(*buf), &retlen, (void *)buf); 41 + if (ret) 42 + return ret; 43 + 44 + if (retlen != sizeof(*buf)) 45 + return -EIO; 46 + 47 + computed_crc = crc32_le(IMAGETAG_CRC_START, (u8 *)buf, 48 + offsetof(struct bcm_tag, header_crc)); 49 + if (computed_crc == buf->header_crc) { 50 + STR_NULL_TERMINATE(buf->board_id); 51 + STR_NULL_TERMINATE(buf->tag_version); 52 + 53 + pr_info("%s: CFE image tag found at 0x%llx with version %s, board type %s\n", 54 + name, tag_offset, buf->tag_version, buf->board_id); 55 + 56 + return 0; 57 + } 58 + 59 + pr_warn("%s: CFE image tag at 0x%llx CRC invalid (expected %08x, actual %08x)\n", 60 + name, tag_offset, buf->header_crc, computed_crc); 61 + return -EINVAL; 62 + } 63 + 64 + static int bcm963xx_parse_imagetag_partitions(struct mtd_info *master, 65 + const struct mtd_partition **pparts, 66 + struct mtd_part_parser_data *data) 67 + { 68 + /* CFE, NVRAM and global Linux are always present */ 69 + int nrparts = 0, curpart = 0; 70 + struct bcm_tag *buf = NULL; 71 + struct mtd_partition *parts; 72 + int ret; 73 + unsigned int rootfsaddr, kerneladdr, spareaddr, offset; 74 + unsigned int rootfslen, kernellen, sparelen, totallen; 75 + int i; 76 + bool rootfs_first = false; 77 + 78 + buf = vmalloc(sizeof(struct bcm_tag)); 79 + if (!buf) 80 + return -ENOMEM; 81 + 82 + /* Get the tag */ 83 + ret = bcm963xx_read_imagetag(master, "rootfs", 0, buf); 84 + if (!ret) { 85 + STR_NULL_TERMINATE(buf->flash_image_start); 86 + if (kstrtouint(buf->flash_image_start, 10, &rootfsaddr) || 87 + rootfsaddr < BCM963XX_EXTENDED_SIZE) { 88 + pr_err("invalid rootfs address: %*ph\n", 89 + (int)sizeof(buf->flash_image_start), 90 + buf->flash_image_start); 91 + goto out; 92 + } 93 + 94 + STR_NULL_TERMINATE(buf->kernel_address); 95 + if (kstrtouint(buf->kernel_address, 10, &kerneladdr) || 96 + kerneladdr < BCM963XX_EXTENDED_SIZE) { 97 + pr_err("invalid kernel address: %*ph\n", 98 + (int)sizeof(buf->kernel_address), 99 + buf->kernel_address); 100 + goto out; 101 + } 102 + 103 + STR_NULL_TERMINATE(buf->kernel_length); 104 + if (kstrtouint(buf->kernel_length, 10, &kernellen)) { 105 + pr_err("invalid kernel length: %*ph\n", 106 + (int)sizeof(buf->kernel_length), 107 + buf->kernel_length); 108 + goto out; 109 + } 110 + 111 + STR_NULL_TERMINATE(buf->total_length); 112 + if (kstrtouint(buf->total_length, 10, &totallen)) { 113 + pr_err("invalid total length: %*ph\n", 114 + (int)sizeof(buf->total_length), 115 + buf->total_length); 116 + goto out; 117 + } 118 + 119 + /* 120 + * Addresses are flash absolute, so convert to partition 121 + * relative addresses. Assume either kernel or rootfs will 122 + * directly follow the image tag. 123 + */ 124 + if (rootfsaddr < kerneladdr) 125 + offset = rootfsaddr - sizeof(struct bcm_tag); 126 + else 127 + offset = kerneladdr - sizeof(struct bcm_tag); 128 + 129 + kerneladdr = kerneladdr - offset; 130 + rootfsaddr = rootfsaddr - offset; 131 + spareaddr = roundup(totallen, master->erasesize); 132 + 133 + if (rootfsaddr < kerneladdr) { 134 + /* default Broadcom layout */ 135 + rootfslen = kerneladdr - rootfsaddr; 136 + rootfs_first = true; 137 + } else { 138 + /* OpenWrt layout */ 139 + rootfsaddr = kerneladdr + kernellen; 140 + rootfslen = spareaddr - rootfsaddr; 141 + } 142 + } else { 143 + goto out; 144 + } 145 + sparelen = master->size - spareaddr; 146 + 147 + /* Determine number of partitions */ 148 + if (rootfslen > 0) 149 + nrparts++; 150 + 151 + if (kernellen > 0) 152 + nrparts++; 153 + 154 + parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); 155 + if (!parts) { 156 + ret = -ENOMEM; 157 + goto out; 158 + } 159 + 160 + /* Start building partition list */ 161 + if (kernellen > 0) { 162 + int kernelpart = curpart; 163 + 164 + if (rootfslen > 0 && rootfs_first) 165 + kernelpart++; 166 + parts[kernelpart].name = "kernel"; 167 + parts[kernelpart].offset = kerneladdr; 168 + parts[kernelpart].size = kernellen; 169 + curpart++; 170 + } 171 + 172 + if (rootfslen > 0) { 173 + int rootfspart = curpart; 174 + 175 + if (kernellen > 0 && rootfs_first) 176 + rootfspart--; 177 + parts[rootfspart].name = "rootfs"; 178 + parts[rootfspart].offset = rootfsaddr; 179 + parts[rootfspart].size = rootfslen; 180 + if (sparelen > 0 && !rootfs_first) 181 + parts[rootfspart].size += sparelen; 182 + curpart++; 183 + } 184 + 185 + for (i = 0; i < nrparts; i++) 186 + pr_info("Partition %d is %s offset %llx and length %llx\n", i, 187 + parts[i].name, parts[i].offset, parts[i].size); 188 + 189 + pr_info("Spare partition is offset %x and length %x\n", spareaddr, 190 + sparelen); 191 + 192 + *pparts = parts; 193 + ret = 0; 194 + 195 + out: 196 + vfree(buf); 197 + 198 + if (ret) 199 + return ret; 200 + 201 + return nrparts; 202 + } 203 + 204 + static const struct of_device_id parse_bcm963xx_imagetag_match_table[] = { 205 + { .compatible = "brcm,bcm963xx-imagetag" }, 206 + {}, 207 + }; 208 + MODULE_DEVICE_TABLE(of, parse_bcm963xx_imagetag_match_table); 209 + 210 + static struct mtd_part_parser bcm963xx_imagetag_parser = { 211 + .parse_fn = bcm963xx_parse_imagetag_partitions, 212 + .name = "bcm963xx-imagetag", 213 + .of_match_table = parse_bcm963xx_imagetag_match_table, 214 + }; 215 + module_mtd_part_parser(bcm963xx_imagetag_parser); 216 + 217 + MODULE_LICENSE("GPL"); 218 + MODULE_AUTHOR("Daniel Dickinson <openwrt@cshore.neomailbox.net>"); 219 + MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>"); 220 + MODULE_AUTHOR("Mike Albon <malbon@openwrt.org>"); 221 + MODULE_AUTHOR("Jonas Gorski <jonas.gorski@gmail.com>"); 222 + MODULE_DESCRIPTION("MTD parser for BCM963XX CFE Image Tag partitions");
+6 -6
drivers/mtd/sm_ftl.c
··· 222 222 uint8_t ecc[3]; 223 223 224 224 __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc, 225 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 225 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 226 226 if (__nand_correct_data(buffer, ecc, oob->ecc1, SM_SMALL_PAGE, 227 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)) < 0) 227 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0) 228 228 return -EIO; 229 229 230 230 buffer += SM_SMALL_PAGE; 231 231 232 232 __nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc, 233 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 233 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 234 234 if (__nand_correct_data(buffer, ecc, oob->ecc2, SM_SMALL_PAGE, 235 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)) < 0) 235 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0) 236 236 return -EIO; 237 237 return 0; 238 238 } ··· 399 399 if (ftl->smallpagenand) { 400 400 __nand_calculate_ecc(buf + boffset, SM_SMALL_PAGE, 401 401 oob.ecc1, 402 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 402 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 403 403 404 404 __nand_calculate_ecc(buf + boffset + SM_SMALL_PAGE, 405 405 SM_SMALL_PAGE, oob.ecc2, 406 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 406 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 407 407 } 408 408 if (!sm_write_sector(ftl, zone, block, boffset, 409 409 buf + boffset, &oob))
+1
drivers/mtd/spi-nor/intel-spi-pci.c
··· 63 63 } 64 64 65 65 static const struct pci_device_id intel_spi_pci_ids[] = { 66 + { PCI_VDEVICE(INTEL, 0x02a4), (unsigned long)&bxt_info }, 66 67 { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info }, 67 68 { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info }, 68 69 { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info },
+8
drivers/mtd/spi-nor/intel-spi.c
··· 632 632 while (len > 0) { 633 633 block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); 634 634 635 + /* Read cannot cross 4K boundary */ 636 + block_size = min_t(loff_t, from + block_size, 637 + round_up(from + 1, SZ_4K)) - from; 638 + 635 639 writel(from, ispi->base + FADDR); 636 640 637 641 val = readl(ispi->base + HSFSTS_CTL); ··· 688 684 689 685 while (len > 0) { 690 686 block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ); 687 + 688 + /* Write cannot cross 4K boundary */ 689 + block_size = min_t(loff_t, to + block_size, 690 + round_up(to + 1, SZ_4K)) - to; 691 691 692 692 writel(to, ispi->base + FADDR); 693 693
+6 -4
drivers/mtd/spi-nor/spi-nor.c
··· 744 744 u8 erase_mask = region->offset & SNOR_ERASE_TYPE_MASK; 745 745 746 746 /* 747 - * Erase types are ordered by size, with the biggest erase type at 747 + * Erase types are ordered by size, with the smallest erase type at 748 748 * index 0. 749 749 */ 750 750 for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) { ··· 1905 1905 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, 1906 1906 { "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, USE_CLSR) }, 1907 1907 { "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, 1908 - { "s25fl512s", INFO6(0x010220, 0x4d0080, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, 1908 + { "s25fl512s", INFO6(0x010220, 0x4d0080, 256 * 1024, 256, 1909 + SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 1910 + SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB | USE_CLSR) }, 1909 1911 { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) }, 1910 1912 { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) }, 1911 1913 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, ··· 2073 2071 return &spi_nor_ids[tmp]; 2074 2072 } 2075 2073 } 2076 - dev_err(nor->dev, "unrecognized JEDEC id bytes: %02x, %02x, %02x\n", 2077 - id[0], id[1], id[2]); 2074 + dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", 2075 + SPI_NOR_MAX_ID_LEN, id); 2078 2076 return ERR_PTR(-ENODEV); 2079 2077 } 2080 2078
+8 -8
drivers/mtd/tests/mtd_nandecctest.c
··· 21 21 * or detected. 22 22 */ 23 23 24 - #if IS_ENABLED(CONFIG_MTD_NAND) 24 + #if IS_ENABLED(CONFIG_MTD_RAW_NAND) 25 25 26 26 struct nand_ecc_test { 27 27 const char *name; ··· 122 122 int ret; 123 123 124 124 __nand_calculate_ecc(error_data, size, calc_ecc, 125 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 125 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 126 126 ret = __nand_correct_data(error_data, error_ecc, calc_ecc, size, 127 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 127 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 128 128 if (ret == 0 && !memcmp(correct_data, error_data, size)) 129 129 return 0; 130 130 ··· 152 152 int ret; 153 153 154 154 __nand_calculate_ecc(error_data, size, calc_ecc, 155 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 155 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 156 156 ret = __nand_correct_data(error_data, error_ecc, calc_ecc, size, 157 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 157 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 158 158 if (ret == 1 && !memcmp(correct_data, error_data, size)) 159 159 return 0; 160 160 ··· 189 189 int ret; 190 190 191 191 __nand_calculate_ecc(error_data, size, calc_ecc, 192 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 192 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 193 193 ret = __nand_correct_data(error_data, error_ecc, calc_ecc, size, 194 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 194 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 195 195 196 196 return (ret == -EBADMSG) ? 0 : -EINVAL; 197 197 } ··· 266 266 267 267 prandom_bytes(correct_data, size); 268 268 __nand_calculate_ecc(correct_data, size, correct_ecc, 269 - IS_ENABLED(CONFIG_MTD_NAND_ECC_SMC)); 269 + IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)); 270 270 271 271 for (i = 0; i < ARRAY_SIZE(nand_ecc_test); i++) { 272 272 nand_ecc_test[i].prepare(error_data, error_ecc,
+1 -13
include/linux/mtd/bbm.h
··· 93 93 #define NAND_BBT_WRITE 0x00002000 94 94 /* Read and write back block contents when writing bbt */ 95 95 #define NAND_BBT_SAVECONTENT 0x00004000 96 - /* Search good / bad pattern on the first and the second page */ 97 - #define NAND_BBT_SCAN2NDPAGE 0x00008000 98 - /* Search good / bad pattern on the last page of the eraseblock */ 99 - #define NAND_BBT_SCANLASTPAGE 0x00010000 96 + 100 97 /* 101 98 * Use a flash based bad block table. By default, OOB identifier is saved in 102 99 * OOB area. This option is passed to the default bad block table function. ··· 121 124 #define NAND_BBT_SCAN_MAXBLOCKS 4 122 125 123 126 /* 124 - * Constants for oob configuration 125 - */ 126 - #define NAND_SMALL_BADBLOCK_POS 5 127 - #define NAND_LARGE_BADBLOCK_POS 0 128 - #define ONENAND_BADBLOCK_POS 0 129 - 130 - /* 131 127 * Bad block scanning errors 132 128 */ 133 129 #define ONENAND_BBT_READ_ERROR 1 ··· 130 140 /** 131 141 * struct bbm_info - [GENERIC] Bad Block Table data structure 132 142 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry 133 - * @badblockpos: [INTERN] position of the bad block marker in the oob area 134 143 * @options: options for this descriptor 135 144 * @bbt: [INTERN] bad block table pointer 136 145 * @isbad_bbt: function to determine if a block is bad ··· 139 150 */ 140 151 struct bbm_info { 141 152 int bbt_erase_shift; 142 - int badblockpos; 143 153 int options; 144 154 145 155 uint8_t *bbt;
+31 -1
include/linux/mtd/nand.h
··· 19 19 * @oobsize: OOB area size 20 20 * @pages_per_eraseblock: number of pages per eraseblock 21 21 * @eraseblocks_per_lun: number of eraseblocks per LUN (Logical Unit Number) 22 + * @max_bad_eraseblocks_per_lun: maximum number of eraseblocks per LUN 22 23 * @planes_per_lun: number of planes per LUN 23 24 * @luns_per_target: number of LUN per target (target is a synonym for die) 24 25 * @ntargets: total number of targets exposed by the NAND device ··· 30 29 unsigned int oobsize; 31 30 unsigned int pages_per_eraseblock; 32 31 unsigned int eraseblocks_per_lun; 32 + unsigned int max_bad_eraseblocks_per_lun; 33 33 unsigned int planes_per_lun; 34 34 unsigned int luns_per_target; 35 35 unsigned int ntargets; 36 36 }; 37 37 38 - #define NAND_MEMORG(bpc, ps, os, ppe, epl, ppl, lpt, nt) \ 38 + #define NAND_MEMORG(bpc, ps, os, ppe, epl, mbb, ppl, lpt, nt) \ 39 39 { \ 40 40 .bits_per_cell = (bpc), \ 41 41 .pagesize = (ps), \ 42 42 .oobsize = (os), \ 43 43 .pages_per_eraseblock = (ppe), \ 44 44 .eraseblocks_per_lun = (epl), \ 45 + .max_bad_eraseblocks_per_lun = (mbb), \ 45 46 .planes_per_lun = (ppl), \ 46 47 .luns_per_target = (lpt), \ 47 48 .ntargets = (nt), \ ··· 272 269 } 273 270 274 271 /** 272 + * nanddev_pages_per_target() - Get the number of pages per target 273 + * @nand: NAND device 274 + * 275 + * Return: the number of pages per target. 276 + */ 277 + static inline unsigned int 278 + nanddev_pages_per_target(const struct nand_device *nand) 279 + { 280 + return nand->memorg.pages_per_eraseblock * 281 + nand->memorg.eraseblocks_per_lun * 282 + nand->memorg.luns_per_target; 283 + } 284 + 285 + /** 275 286 * nanddev_per_page_oobsize() - Get NAND erase block size 276 287 * @nand: NAND device 277 288 * ··· 306 289 nanddev_eraseblocks_per_lun(const struct nand_device *nand) 307 290 { 308 291 return nand->memorg.eraseblocks_per_lun; 292 + } 293 + 294 + /** 295 + * nanddev_eraseblocks_per_target() - Get the number of eraseblocks per target 296 + * @nand: NAND device 297 + * 298 + * Return: the number of eraseblocks per target. 299 + */ 300 + static inline unsigned int 301 + nanddev_eraseblocks_per_target(const struct nand_device *nand) 302 + { 303 + return nand->memorg.eraseblocks_per_lun * nand->memorg.luns_per_target; 309 304 } 310 305 311 306 /** ··· 758 729 759 730 /* MTD -> NAND helper functions. */ 760 731 int nanddev_mtd_erase(struct mtd_info *mtd, struct erase_info *einfo); 732 + int nanddev_mtd_max_bad_blocks(struct mtd_info *mtd, loff_t offs, size_t len); 761 733 762 734 #endif /* __LINUX_MTD_NAND_H */
+3 -3
include/linux/mtd/nand_bch.h
··· 15 15 struct nand_chip; 16 16 struct nand_bch_control; 17 17 18 - #if defined(CONFIG_MTD_NAND_ECC_BCH) 18 + #if IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH) 19 19 20 20 static inline int mtd_nand_has_bch(void) { return 1; } 21 21 ··· 39 39 */ 40 40 void nand_bch_free(struct nand_bch_control *nbc); 41 41 42 - #else /* !CONFIG_MTD_NAND_ECC_BCH */ 42 + #else /* !CONFIG_MTD_NAND_ECC_SW_BCH */ 43 43 44 44 static inline int mtd_nand_has_bch(void) { return 0; } 45 45 ··· 64 64 65 65 static inline void nand_bch_free(struct nand_bch_control *nbc) {} 66 66 67 - #endif /* CONFIG_MTD_NAND_ECC_BCH */ 67 + #endif /* CONFIG_MTD_NAND_ECC_SW_BCH */ 68 68 69 69 #endif /* __MTD_NAND_BCH_H__ */
+3
include/linux/mtd/onenand.h
··· 94 94 unsigned int technology; 95 95 unsigned int density_mask; 96 96 unsigned int options; 97 + unsigned int badblockpos; 97 98 98 99 unsigned int erase_shift; 99 100 unsigned int page_shift; ··· 188 187 189 188 /* Check byte access in OneNAND */ 190 189 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) 190 + 191 + #define ONENAND_BADBLOCK_POS 0 191 192 192 193 /* 193 194 * Options bits
+73 -49
include/linux/mtd/rawnand.h
··· 20 20 #include <linux/mtd/flashchip.h> 21 21 #include <linux/mtd/bbm.h> 22 22 #include <linux/mtd/jedec.h> 23 + #include <linux/mtd/nand.h> 23 24 #include <linux/mtd/onfi.h> 24 25 #include <linux/mutex.h> 25 26 #include <linux/of.h> ··· 168 167 169 168 /* Macros to identify the above */ 170 169 #define NAND_HAS_SUBPAGE_READ(chip) ((chip->options & NAND_SUBPAGE_READ)) 170 + 171 + /* 172 + * There are different places where the manufacturer stores the factory bad 173 + * block markers. 174 + * 175 + * Position within the block: Each of these pages needs to be checked for a 176 + * bad block marking pattern. 177 + */ 178 + #define NAND_BBM_FIRSTPAGE 0x01000000 179 + #define NAND_BBM_SECONDPAGE 0x02000000 180 + #define NAND_BBM_LASTPAGE 0x04000000 181 + 182 + /* Position within the OOB data of the page */ 183 + #define NAND_BBM_POS_SMALL 5 184 + #define NAND_BBM_POS_LARGE 0 171 185 172 186 /* Non chip related options */ 173 187 /* This option skips the bbt scan during initialization. */ ··· 821 805 #define NAND_OP_PARSER_PATTERN(_exec, ...) \ 822 806 { \ 823 807 .exec = _exec, \ 824 - .elems = (struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }, \ 808 + .elems = (const struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }, \ 825 809 .nelems = sizeof((struct nand_op_parser_pattern_elem[]) { __VA_ARGS__ }) / \ 826 810 sizeof(struct nand_op_parser_pattern_elem), \ 827 811 } ··· 847 831 848 832 #define NAND_OP_PARSER(...) \ 849 833 { \ 850 - .patterns = (struct nand_op_parser_pattern[]) { __VA_ARGS__ }, \ 834 + .patterns = (const struct nand_op_parser_pattern[]) { __VA_ARGS__ }, \ 851 835 .npatterns = sizeof((struct nand_op_parser_pattern[]) { __VA_ARGS__ }) / \ 852 836 sizeof(struct nand_op_parser_pattern), \ 853 837 } ··· 876 860 int nand_op_parser_exec_op(struct nand_chip *chip, 877 861 const struct nand_op_parser *parser, 878 862 const struct nand_operation *op, bool check_only); 863 + 879 864 /** 880 865 * struct nand_controller_ops - Controller operations 881 866 * ··· 979 962 980 963 /** 981 964 * struct nand_chip - NAND Private Flash Chip Data 982 - * @mtd: MTD device registered to the MTD framework 965 + * @base: Inherit from the generic NAND device 983 966 * @legacy: All legacy fields/hooks. If you develop a new driver, 984 967 * don't even try to use any of these fields/hooks, and if 985 968 * you're modifying an existing driver that is using those ··· 1007 990 * @badblockbits: [INTERN] minimum number of set bits in a good block's 1008 991 * bad block marker position; i.e., BBM == 11110111b is 1009 992 * not bad when badblockbits == 7 1010 - * @bits_per_cell: [INTERN] number of bits per cell. i.e., 1 means SLC. 1011 - * @ecc_strength_ds: [INTERN] ECC correctability from the datasheet. 1012 - * Minimum amount of bit errors per @ecc_step_ds guaranteed 1013 - * to be correctable. If unknown, set to zero. 1014 - * @ecc_step_ds: [INTERN] ECC step required by the @ecc_strength_ds, 1015 - * also from the datasheet. It is the recommended ECC step 1016 - * size, if known; if unknown, set to zero. 1017 993 * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is 1018 994 * set to the actually used ONFI mode if the chip is 1019 995 * ONFI compliant or deduced from the datasheet if 1020 996 * the NAND chip is not ONFI compliant. 1021 - * @numchips: [INTERN] number of physical chips 1022 - * @chipsize: [INTERN] the size of one chip for multichip arrays 1023 997 * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 1024 998 * @data_buf: [INTERN] buffer for data, size is (page size + oobsize). 1025 - * @pagebuf: [INTERN] holds the pagenumber which is currently in 1026 - * data_buf. 1027 - * @pagebuf_bitflips: [INTERN] holds the bitflip count for the page which is 1028 - * currently in data_buf. 999 + * @pagecache: Structure containing page cache related fields 1000 + * @pagecache.bitflips: Number of bitflips of the cached page 1001 + * @pagecache.page: Page number currently in the cache. -1 means no page is 1002 + * currently cached 1029 1003 * @subpagesize: [INTERN] holds the subpagesize 1030 1004 * @id: [INTERN] holds NAND ID 1031 1005 * @parameters: [INTERN] holds generic parameters under an easily 1032 1006 * readable form. 1033 - * @max_bb_per_die: [INTERN] the max number of bad blocks each die of a 1034 - * this nand device will encounter their life times. 1035 - * @blocks_per_die: [INTERN] The number of PEBs in a die 1036 1007 * @data_interface: [INTERN] NAND interface timing information 1037 1008 * @cur_cs: currently selected target. -1 means no target selected, 1038 1009 * otherwise we should always have cur_cs >= 0 && 1039 - * cur_cs < numchips. NAND Controller drivers should not 1040 - * modify this value, but they're allowed to read it. 1010 + * cur_cs < nanddev_ntargets(). NAND Controller drivers 1011 + * should not modify this value, but they're allowed to 1012 + * read it. 1041 1013 * @read_retries: [INTERN] the number of read retry modes supported 1042 1014 * @lock: lock protecting the suspended field. Also used to 1043 1015 * serialize accesses to the NAND device. ··· 1047 1041 */ 1048 1042 1049 1043 struct nand_chip { 1050 - struct mtd_info mtd; 1044 + struct nand_device base; 1051 1045 1052 1046 struct nand_legacy legacy; 1053 1047 ··· 1060 1054 int phys_erase_shift; 1061 1055 int bbt_erase_shift; 1062 1056 int chip_shift; 1063 - int numchips; 1064 - uint64_t chipsize; 1065 1057 int pagemask; 1066 1058 u8 *data_buf; 1067 - int pagebuf; 1068 - unsigned int pagebuf_bitflips; 1059 + 1060 + struct { 1061 + unsigned int bitflips; 1062 + int page; 1063 + } pagecache; 1064 + 1069 1065 int subpagesize; 1070 - uint8_t bits_per_cell; 1071 - uint16_t ecc_strength_ds; 1072 - uint16_t ecc_step_ds; 1073 1066 int onfi_timing_mode_default; 1074 - int badblockpos; 1067 + unsigned int badblockpos; 1075 1068 int badblockbits; 1076 1069 1077 1070 struct nand_id id; 1078 1071 struct nand_parameters parameters; 1079 - u16 max_bb_per_die; 1080 - u32 blocks_per_die; 1081 1072 1082 1073 struct nand_data_interface data_interface; 1083 1074 ··· 1108 1105 extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops; 1109 1106 extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops; 1110 1107 1111 - static inline void nand_set_flash_node(struct nand_chip *chip, 1112 - struct device_node *np) 1113 - { 1114 - mtd_set_of_node(&chip->mtd, np); 1115 - } 1116 - 1117 - static inline struct device_node *nand_get_flash_node(struct nand_chip *chip) 1118 - { 1119 - return mtd_get_of_node(&chip->mtd); 1120 - } 1121 - 1122 1108 static inline struct nand_chip *mtd_to_nand(struct mtd_info *mtd) 1123 1109 { 1124 - return container_of(mtd, struct nand_chip, mtd); 1110 + return container_of(mtd, struct nand_chip, base.mtd); 1125 1111 } 1126 1112 1127 1113 static inline struct mtd_info *nand_to_mtd(struct nand_chip *chip) 1128 1114 { 1129 - return &chip->mtd; 1115 + return &chip->base.mtd; 1130 1116 } 1131 1117 1132 1118 static inline void *nand_get_controller_data(struct nand_chip *chip) ··· 1137 1145 static inline void *nand_get_manufacturer_data(struct nand_chip *chip) 1138 1146 { 1139 1147 return chip->manufacturer.priv; 1148 + } 1149 + 1150 + static inline void nand_set_flash_node(struct nand_chip *chip, 1151 + struct device_node *np) 1152 + { 1153 + mtd_set_of_node(nand_to_mtd(chip), np); 1154 + } 1155 + 1156 + static inline struct device_node *nand_get_flash_node(struct nand_chip *chip) 1157 + { 1158 + return mtd_get_of_node(nand_to_mtd(chip)); 1140 1159 } 1141 1160 1142 1161 /* ··· 1183 1180 * @name: a human-readable name of the NAND chip 1184 1181 * @dev_id: the device ID (the second byte of the full chip ID array) 1185 1182 * @mfr_id: manufecturer ID part of the full chip ID array (refers the same 1186 - * memory address as @id[0]) 1183 + * memory address as ``id[0]``) 1187 1184 * @dev_id: device ID part of the full chip ID array (refers the same memory 1188 - * address as @id[1]) 1185 + * address as ``id[1]``) 1189 1186 * @id: full device ID array 1190 1187 * @pagesize: size of the NAND page in bytes; if 0, then the real page size (as 1191 1188 * well as the eraseblock size) is determined from the extended NAND ··· 1238 1235 */ 1239 1236 static inline bool nand_is_slc(struct nand_chip *chip) 1240 1237 { 1241 - WARN(chip->bits_per_cell == 0, 1238 + WARN(nanddev_bits_per_cell(&chip->base) == 0, 1242 1239 "chip->bits_per_cell is used uninitialized\n"); 1243 - return chip->bits_per_cell == 1; 1240 + return nanddev_bits_per_cell(&chip->base) == 1; 1244 1241 } 1245 1242 1246 1243 /** ··· 1350 1347 /* Select/deselect a NAND target. */ 1351 1348 void nand_select_target(struct nand_chip *chip, unsigned int cs); 1352 1349 void nand_deselect_target(struct nand_chip *chip); 1350 + 1351 + /** 1352 + * nand_get_data_buf() - Get the internal page buffer 1353 + * @chip: NAND chip object 1354 + * 1355 + * Returns the pre-allocated page buffer after invalidating the cache. This 1356 + * function should be used by drivers that do not want to allocate their own 1357 + * bounce buffer and still need such a buffer for specific operations (most 1358 + * commonly when reading OOB data only). 1359 + * 1360 + * Be careful to never call this function in the write/write_oob path, because 1361 + * the core may have placed the data to be written out in this buffer. 1362 + * 1363 + * Return: pointer to the page cache buffer 1364 + */ 1365 + static inline void *nand_get_data_buf(struct nand_chip *chip) 1366 + { 1367 + chip->pagecache.page = -1; 1368 + 1369 + return chip->data_buf; 1370 + } 1353 1371 1354 1372 #endif /* __LINUX_MTD_RAWNAND_H */
+7
include/linux/mtd/spinand.h
··· 302 302 __VA_ARGS__ \ 303 303 } 304 304 305 + struct spinand_dirmap { 306 + struct spi_mem_dirmap_desc *wdesc; 307 + struct spi_mem_dirmap_desc *rdesc; 308 + }; 309 + 305 310 /** 306 311 * struct spinand_device - SPI NAND device instance 307 312 * @base: NAND device instance ··· 345 340 const struct spi_mem_op *write_cache; 346 341 const struct spi_mem_op *update_cache; 347 342 } op_templates; 343 + 344 + struct spinand_dirmap *dirmaps; 348 345 349 346 int (*select_target)(struct spinand_device *spinand, 350 347 unsigned int target);
+1 -1
include/linux/platform_data/elm.h
··· 60 60 { 61 61 return -ENOSYS; 62 62 } 63 - #endif /* CONFIG_MTD_NAND_ECC_BCH */ 63 + #endif /* CONFIG_MTD_NAND_OMAP_BCH */ 64 64 65 65 #endif /* __ELM_H */
+27 -7
include/soc/at91/atmel-sfr.h
··· 14 14 #define _LINUX_MFD_SYSCON_ATMEL_SFR_H 15 15 16 16 #define AT91_SFR_DDRCFG 0x04 /* DDR Configuration Register */ 17 + #define AT91_SFR_CCFG_EBICSA 0x04 /* EBI Chip Select Register */ 17 18 /* 0x08 ~ 0x0c: Reserved */ 18 19 #define AT91_SFR_OHCIICR 0x10 /* OHCI INT Configuration Register */ 19 20 #define AT91_SFR_OHCIISR 0x14 /* OHCI INT Status Register */ 20 21 #define AT91_SFR_UTMICKTRIM 0x30 /* UTMI Clock Trimming Register */ 22 + #define AT91_SFR_UTMISWAP 0x3c /* UTMI DP/DM Pin Swapping Register */ 23 + #define AT91_SFR_LS 0x7c /* Light Sleep Register */ 21 24 #define AT91_SFR_I2SCLKSEL 0x90 /* I2SC Register */ 25 + #define AT91_SFR_WPMR 0xe4 /* Write Protection Mode Register */ 22 26 23 27 /* Field definitions */ 24 - #define AT91_OHCIICR_SUSPEND_A BIT(8) 25 - #define AT91_OHCIICR_SUSPEND_B BIT(9) 26 - #define AT91_OHCIICR_SUSPEND_C BIT(10) 28 + #define AT91_SFR_CCFG_EBI_CSA(cs, val) ((val) << (cs)) 29 + #define AT91_SFR_CCFG_EBI_DBPUC BIT(8) 30 + #define AT91_SFR_CCFG_EBI_DBPDC BIT(9) 31 + #define AT91_SFR_CCFG_EBI_DRIVE BIT(17) 32 + #define AT91_SFR_CCFG_NFD0_ON_D16 BIT(24) 33 + #define AT91_SFR_CCFG_DDR_MP_EN BIT(25) 27 34 28 - #define AT91_OHCIICR_USB_SUSPEND (AT91_OHCIICR_SUSPEND_A | \ 29 - AT91_OHCIICR_SUSPEND_B | \ 30 - AT91_OHCIICR_SUSPEND_C) 35 + #define AT91_SFR_OHCIICR_RES(x) BIT(x) 36 + #define AT91_SFR_OHCIICR_ARIE BIT(4) 37 + #define AT91_SFR_OHCIICR_APPSTART BIT(5) 38 + #define AT91_SFR_OHCIICR_USB_SUSP(x) BIT(8 + (x)) 39 + #define AT91_SFR_OHCIICR_UDPPUDIS BIT(23) 40 + #define AT91_OHCIICR_USB_SUSPEND GENMASK(10, 8) 31 41 32 - #define AT91_UTMICKTRIM_FREQ GENMASK(1, 0) 42 + #define AT91_SFR_OHCIISR_RIS(x) BIT(x) 43 + 44 + #define AT91_UTMICKTRIM_FREQ GENMASK(1, 0) 45 + 46 + #define AT91_SFR_UTMISWAP_PORT(x) BIT(x) 47 + 48 + #define AT91_SFR_LS_VALUE(x) BIT(x) 49 + #define AT91_SFR_LS_MEM_POWER_GATING_ULP1_EN BIT(16) 50 + 51 + #define AT91_SFR_WPMR_WPEN BIT(0) 52 + #define AT91_SFR_WPMR_WPKEY_MASK GENMASK(31, 8) 33 53 34 54 #endif /* _LINUX_MFD_SYSCON_ATMEL_SFR_H */