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

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

Pull mtd updates from Miquel Raynal:
"MTD core changes:
- Spelling
- http to https updates

NAND core changes:
- Drop useless 'depends on' in Kconfig
- Add an extra level in the Kconfig hierarchy
- Trivial spellings
- Dynamic allocation of the interface configurations
- Dropping the default ONFI timing mode
- Various cleanup (types, structures, naming, comments)
- Hide the chip->data_interface indirection
- Add the generic rb-gpios property
- Add the ->choose_interface_config() hook
- Introduce nand_choose_best_sdr_timings()
- Use default values for tPROG_max and tBERS_max
- Avoid redefining tR_max and tCCS_min
- Add a helper to find the closest ONFI mode
- bcm63xx MTD parsers: simplify CFE detection

Raw NAND controller drivers changes:
- fsl-upm: Deprecation of specific DT properties
- fsl_upm: Driver rework and cleanup in favor of ->exec_op()
- Ingenic: Cleanup ARRAY_SIZE() vs sizeof() use
- brcmnand: ECC error handling on EDU transfers
- brcmnand: Don't default to EDU transfers
- qcom: Set BAM mode only if not set already
- qcom: Avoid write to unavailable register
- gpio: Driver rework in favor of ->exec_op()
- tango: ->exec_op() conversion
- mtk: ->exec_op() conversion

Raw NAND chip drivers changes:
- toshiba: Implement ->choose_interface_config() for TH58NVG2S3HBAI4,
TC58NVG0S3E, and TC58TEG5DCLTA00
- hynix: Implement ->choose_interface_config() for H27UCG8T2ATR-BC

SPI NOR core changes:
- Disable Quad Mode in spi_nor_restore().
- Don't abort BFPT parsing when QER reserved value is used.
- Add support/update capabilities for few flashes.
- Drop s70fl01gs flash: it does not support RDSR(05h) which is
critical for erase/write.
- Merge the SPIMEM DTR bits in spi-nor/next to avoid conflicts during
the release cycle.

SPI NOR controller drivers changes:
- Move the cadence-quadspi driver to spi-mem. The series was taken
through the SPI tree. Merge it also in spi-nor/next to avoid
conflicts during the release cycle.
- intel-spi:
- Add new PCI IDs.
- Ignore the Write Disable command, the controller doesn't support
it.
- Fix performance regression"

* tag 'mtd/for-5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux: (79 commits)
MTD: pfow.h: drop a duplicated word
MTD: mtd-abi.h: drop a duplicated word
mtd: rawnand: omap_elm: Replace HTTP links with HTTPS ones
mtd: Replace HTTP links with HTTPS ones
mtd: hyperbus: Replace HTTP links with HTTPS ones
mtd: revert "spi-nor: intel: provide a range for poll_timout"
mtd: spi-nor: update read capabilities for w25q64 and s25fl064k
mtd: spi-nor: micron: Add SPI_NOR_DUAL_READ flag on mt25qu02g
mtd: spi-nor: macronix: Add support for mx66u2g45g
mtd: spi-nor: intel-spi: Simulate WRDI command
mtd: spi-nor: Disable the flash quad mode in spi_nor_restore()
mtd: spi-nor: Add capability to disable flash quad mode
mtd: spi-nor: spansion: Remove s70fl01gs from flash_info
mtd: spi-nor: sfdp: do not make invalid quad enable fatal
dt-bindings: mtd: fsl-upm-nand: Deprecate chip-delay and fsl, upm-wait-flags
mtd: rawnand: stm32_fmc2: get resources from parent node
mtd: rawnand: stm32_fmc2: use regmap APIs
memory: stm32-fmc2-ebi: add STM32 FMC2 EBI controller driver
dt-bindings: memory-controller: add STM32 FMC2 EBI controller documentation
dt-bindings: mtd: update STM32 FMC2 NAND controller documentation
...

+2807 -985
+252
Documentation/devicetree/bindings/memory-controllers/st,stm32-fmc2-ebi.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/memory-controllers/st,stm32-fmc2-ebi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: STMicroelectronics Flexible Memory Controller 2 (FMC2) Bindings 8 + 9 + description: | 10 + The FMC2 functional block makes the interface with: synchronous and 11 + asynchronous static devices (such as PSNOR, PSRAM or other memory-mapped 12 + peripherals) and NAND flash memories. 13 + Its main purposes are: 14 + - to translate AXI transactions into the appropriate external device 15 + protocol 16 + - to meet the access time requirements of the external devices 17 + All external devices share the addresses, data and control signals with the 18 + controller. Each external device is accessed by means of a unique Chip 19 + Select. The FMC2 performs only one access at a time to an external device. 20 + 21 + maintainers: 22 + - Christophe Kerello <christophe.kerello@st.com> 23 + 24 + properties: 25 + compatible: 26 + const: st,stm32mp1-fmc2-ebi 27 + 28 + reg: 29 + maxItems: 1 30 + 31 + clocks: 32 + maxItems: 1 33 + 34 + resets: 35 + maxItems: 1 36 + 37 + "#address-cells": 38 + const: 2 39 + 40 + "#size-cells": 41 + const: 1 42 + 43 + ranges: 44 + description: | 45 + Reflects the memory layout with four integer values per bank. Format: 46 + <bank-number> 0 <address of the bank> <size> 47 + 48 + patternProperties: 49 + "^.*@[0-4],[a-f0-9]+$": 50 + type: object 51 + 52 + properties: 53 + reg: 54 + description: Bank number, base address and size of the device. 55 + 56 + st,fmc2-ebi-cs-transaction-type: 57 + description: | 58 + Select one of the transactions type supported 59 + 0: Asynchronous mode 1 SRAM/FRAM. 60 + 1: Asynchronous mode 1 PSRAM. 61 + 2: Asynchronous mode A SRAM/FRAM. 62 + 3: Asynchronous mode A PSRAM. 63 + 4: Asynchronous mode 2 NOR. 64 + 5: Asynchronous mode B NOR. 65 + 6: Asynchronous mode C NOR. 66 + 7: Asynchronous mode D NOR. 67 + 8: Synchronous read synchronous write PSRAM. 68 + 9: Synchronous read asynchronous write PSRAM. 69 + 10: Synchronous read synchronous write NOR. 70 + 11: Synchronous read asynchronous write NOR. 71 + $ref: /schemas/types.yaml#/definitions/uint32 72 + minimum: 0 73 + maximum: 11 74 + 75 + st,fmc2-ebi-cs-cclk-enable: 76 + description: Continuous clock enable (first bank must be configured 77 + in synchronous mode). The FMC_CLK is generated continuously 78 + during asynchronous and synchronous access. By default, the 79 + FMC_CLK is only generated during synchronous access. 80 + $ref: /schemas/types.yaml#/definitions/flag 81 + 82 + st,fmc2-ebi-cs-mux-enable: 83 + description: Address/Data multiplexed on databus (valid only with 84 + NOR and PSRAM transactions type). By default, Address/Data 85 + are not multiplexed. 86 + $ref: /schemas/types.yaml#/definitions/flag 87 + 88 + st,fmc2-ebi-cs-buswidth: 89 + description: Data bus width 90 + $ref: /schemas/types.yaml#/definitions/uint32 91 + enum: [ 8, 16 ] 92 + default: 16 93 + 94 + st,fmc2-ebi-cs-waitpol-high: 95 + description: Wait signal polarity (NWAIT signal active high). 96 + By default, NWAIT is active low. 97 + $ref: /schemas/types.yaml#/definitions/flag 98 + 99 + st,fmc2-ebi-cs-waitcfg-enable: 100 + description: The NWAIT signal indicates wheither the data from the 101 + device are valid or if a wait state must be inserted when accessing 102 + the device in synchronous mode. By default, the NWAIT signal is 103 + active one data cycle before wait state. 104 + $ref: /schemas/types.yaml#/definitions/flag 105 + 106 + st,fmc2-ebi-cs-wait-enable: 107 + description: The NWAIT signal is enabled (its level is taken into 108 + account after the programmed latency period to insert wait states 109 + if asserted). By default, the NWAIT signal is disabled. 110 + $ref: /schemas/types.yaml#/definitions/flag 111 + 112 + st,fmc2-ebi-cs-asyncwait-enable: 113 + description: The NWAIT signal is taken into account during asynchronous 114 + transactions. By default, the NWAIT signal is not taken into account 115 + during asynchronous transactions. 116 + $ref: /schemas/types.yaml#/definitions/flag 117 + 118 + st,fmc2-ebi-cs-cpsize: 119 + description: CRAM page size. The controller splits the burst access 120 + when the memory page is reached. By default, no burst split when 121 + crossing page boundary. 122 + $ref: /schemas/types.yaml#/definitions/uint32 123 + enum: [ 0, 128, 256, 512, 1024 ] 124 + default: 0 125 + 126 + st,fmc2-ebi-cs-byte-lane-setup-ns: 127 + description: This property configures the byte lane setup timing 128 + defined in nanoseconds from NBLx low to Chip Select NEx low. 129 + 130 + st,fmc2-ebi-cs-address-setup-ns: 131 + description: This property defines the duration of the address setup 132 + phase in nanoseconds used for asynchronous read/write transactions. 133 + 134 + st,fmc2-ebi-cs-address-hold-ns: 135 + description: This property defines the duration of the address hold 136 + phase in nanoseconds used for asynchronous multiplexed read/write 137 + transactions. 138 + 139 + st,fmc2-ebi-cs-data-setup-ns: 140 + description: This property defines the duration of the data setup phase 141 + in nanoseconds used for asynchronous read/write transactions. 142 + 143 + st,fmc2-ebi-cs-bus-turnaround-ns: 144 + description: This property defines the delay in nanoseconds between the 145 + end of current read/write transaction and the next transaction. 146 + 147 + st,fmc2-ebi-cs-data-hold-ns: 148 + description: This property defines the duration of the data hold phase 149 + in nanoseconds used for asynchronous read/write transactions. 150 + 151 + st,fmc2-ebi-cs-clk-period-ns: 152 + description: This property defines the FMC_CLK output signal period in 153 + nanoseconds. 154 + 155 + st,fmc2-ebi-cs-data-latency-ns: 156 + description: This property defines the data latency before reading or 157 + writing the first data in nanoseconds. 158 + 159 + st,fmc2_ebi-cs-write-address-setup-ns: 160 + description: This property defines the duration of the address setup 161 + phase in nanoseconds used for asynchronous write transactions. 162 + 163 + st,fmc2-ebi-cs-write-address-hold-ns: 164 + description: This property defines the duration of the address hold 165 + phase in nanoseconds used for asynchronous multiplexed write 166 + transactions. 167 + 168 + st,fmc2-ebi-cs-write-data-setup-ns: 169 + description: This property defines the duration of the data setup 170 + phase in nanoseconds used for asynchronous write transactions. 171 + 172 + st,fmc2-ebi-cs-write-bus-turnaround-ns: 173 + description: This property defines the delay between the end of current 174 + write transaction and the next transaction in nanoseconds. 175 + 176 + st,fmc2-ebi-cs-write-data-hold-ns: 177 + description: This property defines the duration of the data hold phase 178 + in nanoseconds used for asynchronous write transactions. 179 + 180 + st,fmc2-ebi-cs-max-low-pulse-ns: 181 + description: This property defines the maximum chip select low pulse 182 + duration in nanoseconds for synchronous transactions. When this timing 183 + reaches 0, the controller splits the current access, toggles NE to 184 + allow device refresh and restarts a new access. 185 + 186 + required: 187 + - reg 188 + 189 + required: 190 + - "#address-cells" 191 + - "#size-cells" 192 + - compatible 193 + - reg 194 + - clocks 195 + - ranges 196 + 197 + examples: 198 + - | 199 + #include <dt-bindings/interrupt-controller/arm-gic.h> 200 + #include <dt-bindings/clock/stm32mp1-clks.h> 201 + #include <dt-bindings/reset/stm32mp1-resets.h> 202 + memory-controller@58002000 { 203 + #address-cells = <2>; 204 + #size-cells = <1>; 205 + compatible = "st,stm32mp1-fmc2-ebi"; 206 + reg = <0x58002000 0x1000>; 207 + clocks = <&rcc FMC_K>; 208 + resets = <&rcc FMC_R>; 209 + 210 + ranges = <0 0 0x60000000 0x04000000>, /* EBI CS 1 */ 211 + <1 0 0x64000000 0x04000000>, /* EBI CS 2 */ 212 + <2 0 0x68000000 0x04000000>, /* EBI CS 3 */ 213 + <3 0 0x6c000000 0x04000000>, /* EBI CS 4 */ 214 + <4 0 0x80000000 0x10000000>; /* NAND */ 215 + 216 + psram@0,0 { 217 + compatible = "mtd-ram"; 218 + reg = <0 0x00000000 0x100000>; 219 + bank-width = <2>; 220 + 221 + st,fmc2-ebi-cs-transaction-type = <1>; 222 + st,fmc2-ebi-cs-address-setup-ns = <60>; 223 + st,fmc2-ebi-cs-data-setup-ns = <30>; 224 + st,fmc2-ebi-cs-bus-turnaround-ns = <5>; 225 + }; 226 + 227 + nand-controller@4,0 { 228 + #address-cells = <1>; 229 + #size-cells = <0>; 230 + compatible = "st,stm32mp1-fmc2-nfc"; 231 + reg = <4 0x00000000 0x1000>, 232 + <4 0x08010000 0x1000>, 233 + <4 0x08020000 0x1000>, 234 + <4 0x01000000 0x1000>, 235 + <4 0x09010000 0x1000>, 236 + <4 0x09020000 0x1000>; 237 + interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>; 238 + dmas = <&mdma1 20 0x2 0x12000a02 0x0 0x0>, 239 + <&mdma1 20 0x2 0x12000a08 0x0 0x0>, 240 + <&mdma1 21 0x2 0x12000a0a 0x0 0x0>; 241 + dma-names = "tx", "rx", "ecc"; 242 + 243 + nand@0 { 244 + reg = <0>; 245 + nand-on-flash-bbt; 246 + #address-cells = <1>; 247 + #size-cells = <1>; 248 + }; 249 + }; 250 + }; 251 + 252 + ...
+2 -2
Documentation/devicetree/bindings/mtd/davinci-nand.txt
··· 4 4 NAND interface contains. 5 5 6 6 Documentation: 7 - Davinci DM646x - http://www.ti.com/lit/ug/sprueq7c/sprueq7c.pdf 8 - Kestone - http://www.ti.com/lit/ug/sprugz3a/sprugz3a.pdf 7 + Davinci DM646x - https://www.ti.com/lit/ug/sprueq7c/sprueq7c.pdf 8 + Kestone - https://www.ti.com/lit/ug/sprugz3a/sprugz3a.pdf 9 9 10 10 Required properties: 11 11
+5 -5
Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt
··· 7 7 - fsl,upm-cmd-offset : UPM pattern offset for the command latch. 8 8 9 9 Optional properties: 10 - - fsl,upm-wait-flags : add chip-dependent short delays after running the 11 - UPM pattern (0x1), after writing a data byte (0x2) or after 12 - writing out a buffer (0x4). 13 10 - fsl,upm-addr-line-cs-offsets : address offsets for multi-chip support. 14 11 The corresponding address lines are used to select the chip. 15 12 - gpios : may specify optional GPIOs connected to the Ready-Not-Busy pins 16 13 (R/B#). For multi-chip devices, "n" GPIO definitions are required 17 14 according to the number of chips. 15 + 16 + Deprecated properties: 17 + - fsl,upm-wait-flags : add chip-dependent short delays after running the 18 + UPM pattern (0x1), after writing a data byte (0x2) or after 19 + writing out a buffer (0x4). 18 20 - chip-delay : chip dependent delay for transferring data from array to 19 21 read registers (tR). Required if property "gpios" is not used 20 22 (R/B# pins not connected). ··· 54 52 fsl,upm-cmd-offset = <0x08>; 55 53 /* Multi-chip NAND device */ 56 54 fsl,upm-addr-line-cs-offsets = <0x0 0x200>; 57 - fsl,upm-wait-flags = <0x5>; 58 - chip-delay = <25>; // in micro-seconds 59 55 60 56 nand@0 { 61 57 #address-cells = <1>;
+7
Documentation/devicetree/bindings/mtd/nand-controller.yaml
··· 114 114 description: 115 115 Contains the native Ready/Busy IDs. 116 116 117 + rb-gpios: 118 + description: 119 + Contains one or more GPIO descriptor (the numper of descriptor 120 + depends on the number of R/B pins exposed by the flash) for the 121 + Ready/Busy pins. Active state refers to the NAND ready state and 122 + should be set to GPIOD_ACTIVE_HIGH unless the signal is inverted. 123 + 117 124 required: 118 125 - reg 119 126
+57 -26
Documentation/devicetree/bindings/mtd/st,stm32-fmc2-nand.yaml
··· 9 9 maintainers: 10 10 - Christophe Kerello <christophe.kerello@st.com> 11 11 12 - allOf: 13 - - $ref: "nand-controller.yaml#" 14 - 15 12 properties: 16 13 compatible: 17 - const: st,stm32mp15-fmc2 14 + enum: 15 + - st,stm32mp15-fmc2 16 + - st,stm32mp1-fmc2-nfc 18 17 19 18 reg: 20 - items: 21 - - description: Registers 22 - - description: Chip select 0 data 23 - - description: Chip select 0 command 24 - - description: Chip select 0 address space 25 - - description: Chip select 1 data 26 - - description: Chip select 1 command 27 - - description: Chip select 1 address space 19 + minItems: 6 20 + maxItems: 7 28 21 29 22 interrupts: 30 - maxItems: 1 31 - 32 - clocks: 33 - maxItems: 1 34 - 35 - resets: 36 23 maxItems: 1 37 24 38 25 dmas: ··· 44 57 nand-ecc-strength: 45 58 enum: [1, 4 ,8 ] 46 59 60 + allOf: 61 + - $ref: "nand-controller.yaml#" 62 + 63 + - if: 64 + properties: 65 + compatible: 66 + contains: 67 + const: st,stm32mp15-fmc2 68 + then: 69 + properties: 70 + reg: 71 + items: 72 + - description: Registers 73 + - description: Chip select 0 data 74 + - description: Chip select 0 command 75 + - description: Chip select 0 address space 76 + - description: Chip select 1 data 77 + - description: Chip select 1 command 78 + - description: Chip select 1 address space 79 + 80 + clocks: 81 + maxItems: 1 82 + 83 + resets: 84 + maxItems: 1 85 + 86 + required: 87 + - clocks 88 + 89 + - if: 90 + properties: 91 + compatible: 92 + contains: 93 + const: st,stm32mp1-fmc2-nfc 94 + then: 95 + properties: 96 + reg: 97 + items: 98 + - description: Chip select 0 data 99 + - description: Chip select 0 command 100 + - description: Chip select 0 address space 101 + - description: Chip select 1 data 102 + - description: Chip select 1 command 103 + - description: Chip select 1 address space 104 + 47 105 required: 48 106 - compatible 49 107 - reg 50 108 - interrupts 51 - - clocks 52 109 53 110 examples: 54 111 - | ··· 108 77 <0x81000000 0x1000>, 109 78 <0x89010000 0x1000>, 110 79 <0x89020000 0x1000>; 111 - interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>; 112 - dmas = <&mdma1 20 0x10 0x12000a02 0x0 0x0>, 113 - <&mdma1 20 0x10 0x12000a08 0x0 0x0>, 114 - <&mdma1 21 0x10 0x12000a0a 0x0 0x0>; 115 - dma-names = "tx", "rx", "ecc"; 116 - clocks = <&rcc FMC_K>; 117 - resets = <&rcc FMC_R>; 80 + interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>; 81 + dmas = <&mdma1 20 0x2 0x12000a02 0x0 0x0>, 82 + <&mdma1 20 0x2 0x12000a08 0x0 0x0>, 83 + <&mdma1 21 0x2 0x12000a0a 0x0 0x0>; 84 + dma-names = "tx", "rx", "ecc"; 85 + clocks = <&rcc FMC_K>; 86 + resets = <&rcc FMC_R>; 118 87 #address-cells = <1>; 119 88 #size-cells = <0>; 120 89
+10
drivers/memory/Kconfig
··· 188 188 host or HyperFlash. You'll have to select individual components 189 189 under the corresponding menu. 190 190 191 + config STM32_FMC2_EBI 192 + tristate "Support for FMC2 External Bus Interface on STM32MP SoCs" 193 + depends on MACH_STM32MP157 || COMPILE_TEST 194 + select MFD_SYSCON 195 + help 196 + Select this option to enable the STM32 FMC2 External Bus Interface 197 + controller. This driver configures the transactions with external 198 + devices (like SRAM, ethernet adapters, FPGAs, LCD displays, ...) on 199 + SOCs containing the FMC2 External Bus Interface. 200 + 191 201 source "drivers/memory/samsung/Kconfig" 192 202 source "drivers/memory/tegra/Kconfig" 193 203
+1
drivers/memory/Makefile
··· 23 23 obj-$(CONFIG_DA8XX_DDRCTL) += da8xx-ddrctl.o 24 24 obj-$(CONFIG_PL353_SMC) += pl353-smc.o 25 25 obj-$(CONFIG_RENESAS_RPCIF) += renesas-rpc-if.o 26 + obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o 26 27 27 28 obj-$(CONFIG_SAMSUNG_MC) += samsung/ 28 29 obj-$(CONFIG_TEGRA_MC) += tegra/
+1206
drivers/memory/stm32-fmc2-ebi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * Copyright (C) STMicroelectronics 2020 4 + */ 5 + 6 + #include <linux/bitfield.h> 7 + #include <linux/clk.h> 8 + #include <linux/mfd/syscon.h> 9 + #include <linux/module.h> 10 + #include <linux/of_platform.h> 11 + #include <linux/pinctrl/consumer.h> 12 + #include <linux/regmap.h> 13 + #include <linux/reset.h> 14 + 15 + /* FMC2 Controller Registers */ 16 + #define FMC2_BCR1 0x0 17 + #define FMC2_BTR1 0x4 18 + #define FMC2_BCR(x) ((x) * 0x8 + FMC2_BCR1) 19 + #define FMC2_BTR(x) ((x) * 0x8 + FMC2_BTR1) 20 + #define FMC2_PCSCNTR 0x20 21 + #define FMC2_BWTR1 0x104 22 + #define FMC2_BWTR(x) ((x) * 0x8 + FMC2_BWTR1) 23 + 24 + /* Register: FMC2_BCR1 */ 25 + #define FMC2_BCR1_CCLKEN BIT(20) 26 + #define FMC2_BCR1_FMC2EN BIT(31) 27 + 28 + /* Register: FMC2_BCRx */ 29 + #define FMC2_BCR_MBKEN BIT(0) 30 + #define FMC2_BCR_MUXEN BIT(1) 31 + #define FMC2_BCR_MTYP GENMASK(3, 2) 32 + #define FMC2_BCR_MWID GENMASK(5, 4) 33 + #define FMC2_BCR_FACCEN BIT(6) 34 + #define FMC2_BCR_BURSTEN BIT(8) 35 + #define FMC2_BCR_WAITPOL BIT(9) 36 + #define FMC2_BCR_WAITCFG BIT(11) 37 + #define FMC2_BCR_WREN BIT(12) 38 + #define FMC2_BCR_WAITEN BIT(13) 39 + #define FMC2_BCR_EXTMOD BIT(14) 40 + #define FMC2_BCR_ASYNCWAIT BIT(15) 41 + #define FMC2_BCR_CPSIZE GENMASK(18, 16) 42 + #define FMC2_BCR_CBURSTRW BIT(19) 43 + #define FMC2_BCR_NBLSET GENMASK(23, 22) 44 + 45 + /* Register: FMC2_BTRx/FMC2_BWTRx */ 46 + #define FMC2_BXTR_ADDSET GENMASK(3, 0) 47 + #define FMC2_BXTR_ADDHLD GENMASK(7, 4) 48 + #define FMC2_BXTR_DATAST GENMASK(15, 8) 49 + #define FMC2_BXTR_BUSTURN GENMASK(19, 16) 50 + #define FMC2_BTR_CLKDIV GENMASK(23, 20) 51 + #define FMC2_BTR_DATLAT GENMASK(27, 24) 52 + #define FMC2_BXTR_ACCMOD GENMASK(29, 28) 53 + #define FMC2_BXTR_DATAHLD GENMASK(31, 30) 54 + 55 + /* Register: FMC2_PCSCNTR */ 56 + #define FMC2_PCSCNTR_CSCOUNT GENMASK(15, 0) 57 + #define FMC2_PCSCNTR_CNTBEN(x) BIT((x) + 16) 58 + 59 + #define FMC2_MAX_EBI_CE 4 60 + #define FMC2_MAX_BANKS 5 61 + 62 + #define FMC2_BCR_CPSIZE_0 0x0 63 + #define FMC2_BCR_CPSIZE_128 0x1 64 + #define FMC2_BCR_CPSIZE_256 0x2 65 + #define FMC2_BCR_CPSIZE_512 0x3 66 + #define FMC2_BCR_CPSIZE_1024 0x4 67 + 68 + #define FMC2_BCR_MWID_8 0x0 69 + #define FMC2_BCR_MWID_16 0x1 70 + 71 + #define FMC2_BCR_MTYP_SRAM 0x0 72 + #define FMC2_BCR_MTYP_PSRAM 0x1 73 + #define FMC2_BCR_MTYP_NOR 0x2 74 + 75 + #define FMC2_BXTR_EXTMOD_A 0x0 76 + #define FMC2_BXTR_EXTMOD_B 0x1 77 + #define FMC2_BXTR_EXTMOD_C 0x2 78 + #define FMC2_BXTR_EXTMOD_D 0x3 79 + 80 + #define FMC2_BCR_NBLSET_MAX 0x3 81 + #define FMC2_BXTR_ADDSET_MAX 0xf 82 + #define FMC2_BXTR_ADDHLD_MAX 0xf 83 + #define FMC2_BXTR_DATAST_MAX 0xff 84 + #define FMC2_BXTR_BUSTURN_MAX 0xf 85 + #define FMC2_BXTR_DATAHLD_MAX 0x3 86 + #define FMC2_BTR_CLKDIV_MAX 0xf 87 + #define FMC2_BTR_DATLAT_MAX 0xf 88 + #define FMC2_PCSCNTR_CSCOUNT_MAX 0xff 89 + 90 + enum stm32_fmc2_ebi_bank { 91 + FMC2_EBI1 = 0, 92 + FMC2_EBI2, 93 + FMC2_EBI3, 94 + FMC2_EBI4, 95 + FMC2_NAND 96 + }; 97 + 98 + enum stm32_fmc2_ebi_register_type { 99 + FMC2_REG_BCR = 1, 100 + FMC2_REG_BTR, 101 + FMC2_REG_BWTR, 102 + FMC2_REG_PCSCNTR 103 + }; 104 + 105 + enum stm32_fmc2_ebi_transaction_type { 106 + FMC2_ASYNC_MODE_1_SRAM = 0, 107 + FMC2_ASYNC_MODE_1_PSRAM, 108 + FMC2_ASYNC_MODE_A_SRAM, 109 + FMC2_ASYNC_MODE_A_PSRAM, 110 + FMC2_ASYNC_MODE_2_NOR, 111 + FMC2_ASYNC_MODE_B_NOR, 112 + FMC2_ASYNC_MODE_C_NOR, 113 + FMC2_ASYNC_MODE_D_NOR, 114 + FMC2_SYNC_READ_SYNC_WRITE_PSRAM, 115 + FMC2_SYNC_READ_ASYNC_WRITE_PSRAM, 116 + FMC2_SYNC_READ_SYNC_WRITE_NOR, 117 + FMC2_SYNC_READ_ASYNC_WRITE_NOR 118 + }; 119 + 120 + enum stm32_fmc2_ebi_buswidth { 121 + FMC2_BUSWIDTH_8 = 8, 122 + FMC2_BUSWIDTH_16 = 16 123 + }; 124 + 125 + enum stm32_fmc2_ebi_cpsize { 126 + FMC2_CPSIZE_0 = 0, 127 + FMC2_CPSIZE_128 = 128, 128 + FMC2_CPSIZE_256 = 256, 129 + FMC2_CPSIZE_512 = 512, 130 + FMC2_CPSIZE_1024 = 1024 131 + }; 132 + 133 + struct stm32_fmc2_ebi { 134 + struct device *dev; 135 + struct clk *clk; 136 + struct regmap *regmap; 137 + u8 bank_assigned; 138 + 139 + u32 bcr[FMC2_MAX_EBI_CE]; 140 + u32 btr[FMC2_MAX_EBI_CE]; 141 + u32 bwtr[FMC2_MAX_EBI_CE]; 142 + u32 pcscntr; 143 + }; 144 + 145 + /* 146 + * struct stm32_fmc2_prop - STM32 FMC2 EBI property 147 + * @name: the device tree binding name of the property 148 + * @bprop: indicate that it is a boolean property 149 + * @mprop: indicate that it is a mandatory property 150 + * @reg_type: the register that have to be modified 151 + * @reg_mask: the bit that have to be modified in the selected register 152 + * in case of it is a boolean property 153 + * @reset_val: the default value that have to be set in case the property 154 + * has not been defined in the device tree 155 + * @check: this callback ckecks that the property is compliant with the 156 + * transaction type selected 157 + * @calculate: this callback is called to calculate for exemple a timing 158 + * set in nanoseconds in the device tree in clock cycles or in 159 + * clock period 160 + * @set: this callback applies the values in the registers 161 + */ 162 + struct stm32_fmc2_prop { 163 + const char *name; 164 + bool bprop; 165 + bool mprop; 166 + int reg_type; 167 + u32 reg_mask; 168 + u32 reset_val; 169 + int (*check)(struct stm32_fmc2_ebi *ebi, 170 + const struct stm32_fmc2_prop *prop, int cs); 171 + u32 (*calculate)(struct stm32_fmc2_ebi *ebi, int cs, u32 setup); 172 + int (*set)(struct stm32_fmc2_ebi *ebi, 173 + const struct stm32_fmc2_prop *prop, 174 + int cs, u32 setup); 175 + }; 176 + 177 + static int stm32_fmc2_ebi_check_mux(struct stm32_fmc2_ebi *ebi, 178 + const struct stm32_fmc2_prop *prop, 179 + int cs) 180 + { 181 + u32 bcr; 182 + 183 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 184 + 185 + if (bcr & FMC2_BCR_MTYP) 186 + return 0; 187 + 188 + return -EINVAL; 189 + } 190 + 191 + static int stm32_fmc2_ebi_check_waitcfg(struct stm32_fmc2_ebi *ebi, 192 + const struct stm32_fmc2_prop *prop, 193 + int cs) 194 + { 195 + u32 bcr, val = FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 196 + 197 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 198 + 199 + if ((bcr & FMC2_BCR_MTYP) == val && bcr & FMC2_BCR_BURSTEN) 200 + return 0; 201 + 202 + return -EINVAL; 203 + } 204 + 205 + static int stm32_fmc2_ebi_check_sync_trans(struct stm32_fmc2_ebi *ebi, 206 + const struct stm32_fmc2_prop *prop, 207 + int cs) 208 + { 209 + u32 bcr; 210 + 211 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 212 + 213 + if (bcr & FMC2_BCR_BURSTEN) 214 + return 0; 215 + 216 + return -EINVAL; 217 + } 218 + 219 + static int stm32_fmc2_ebi_check_async_trans(struct stm32_fmc2_ebi *ebi, 220 + const struct stm32_fmc2_prop *prop, 221 + int cs) 222 + { 223 + u32 bcr; 224 + 225 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 226 + 227 + if (!(bcr & FMC2_BCR_BURSTEN) || !(bcr & FMC2_BCR_CBURSTRW)) 228 + return 0; 229 + 230 + return -EINVAL; 231 + } 232 + 233 + static int stm32_fmc2_ebi_check_cpsize(struct stm32_fmc2_ebi *ebi, 234 + const struct stm32_fmc2_prop *prop, 235 + int cs) 236 + { 237 + u32 bcr, val = FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM); 238 + 239 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 240 + 241 + if ((bcr & FMC2_BCR_MTYP) == val && bcr & FMC2_BCR_BURSTEN) 242 + return 0; 243 + 244 + return -EINVAL; 245 + } 246 + 247 + static int stm32_fmc2_ebi_check_address_hold(struct stm32_fmc2_ebi *ebi, 248 + const struct stm32_fmc2_prop *prop, 249 + int cs) 250 + { 251 + u32 bcr, bxtr, val = FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_D); 252 + 253 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 254 + if (prop->reg_type == FMC2_REG_BWTR) 255 + regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr); 256 + else 257 + regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr); 258 + 259 + if ((!(bcr & FMC2_BCR_BURSTEN) || !(bcr & FMC2_BCR_CBURSTRW)) && 260 + ((bxtr & FMC2_BXTR_ACCMOD) == val || bcr & FMC2_BCR_MUXEN)) 261 + return 0; 262 + 263 + return -EINVAL; 264 + } 265 + 266 + static int stm32_fmc2_ebi_check_clk_period(struct stm32_fmc2_ebi *ebi, 267 + const struct stm32_fmc2_prop *prop, 268 + int cs) 269 + { 270 + u32 bcr, bcr1; 271 + 272 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 273 + if (cs) 274 + regmap_read(ebi->regmap, FMC2_BCR1, &bcr1); 275 + else 276 + bcr1 = bcr; 277 + 278 + if (bcr & FMC2_BCR_BURSTEN && (!cs || !(bcr1 & FMC2_BCR1_CCLKEN))) 279 + return 0; 280 + 281 + return -EINVAL; 282 + } 283 + 284 + static int stm32_fmc2_ebi_check_cclk(struct stm32_fmc2_ebi *ebi, 285 + const struct stm32_fmc2_prop *prop, 286 + int cs) 287 + { 288 + if (cs) 289 + return -EINVAL; 290 + 291 + return stm32_fmc2_ebi_check_sync_trans(ebi, prop, cs); 292 + } 293 + 294 + static u32 stm32_fmc2_ebi_ns_to_clock_cycles(struct stm32_fmc2_ebi *ebi, 295 + int cs, u32 setup) 296 + { 297 + unsigned long hclk = clk_get_rate(ebi->clk); 298 + unsigned long hclkp = NSEC_PER_SEC / (hclk / 1000); 299 + 300 + return DIV_ROUND_UP(setup * 1000, hclkp); 301 + } 302 + 303 + static u32 stm32_fmc2_ebi_ns_to_clk_period(struct stm32_fmc2_ebi *ebi, 304 + int cs, u32 setup) 305 + { 306 + u32 nb_clk_cycles = stm32_fmc2_ebi_ns_to_clock_cycles(ebi, cs, setup); 307 + u32 bcr, btr, clk_period; 308 + 309 + regmap_read(ebi->regmap, FMC2_BCR1, &bcr); 310 + if (bcr & FMC2_BCR1_CCLKEN || !cs) 311 + regmap_read(ebi->regmap, FMC2_BTR1, &btr); 312 + else 313 + regmap_read(ebi->regmap, FMC2_BTR(cs), &btr); 314 + 315 + clk_period = FIELD_GET(FMC2_BTR_CLKDIV, btr) + 1; 316 + 317 + return DIV_ROUND_UP(nb_clk_cycles, clk_period); 318 + } 319 + 320 + static int stm32_fmc2_ebi_get_reg(int reg_type, int cs, u32 *reg) 321 + { 322 + switch (reg_type) { 323 + case FMC2_REG_BCR: 324 + *reg = FMC2_BCR(cs); 325 + break; 326 + case FMC2_REG_BTR: 327 + *reg = FMC2_BTR(cs); 328 + break; 329 + case FMC2_REG_BWTR: 330 + *reg = FMC2_BWTR(cs); 331 + break; 332 + case FMC2_REG_PCSCNTR: 333 + *reg = FMC2_PCSCNTR; 334 + break; 335 + default: 336 + return -EINVAL; 337 + } 338 + 339 + return 0; 340 + } 341 + 342 + static int stm32_fmc2_ebi_set_bit_field(struct stm32_fmc2_ebi *ebi, 343 + const struct stm32_fmc2_prop *prop, 344 + int cs, u32 setup) 345 + { 346 + u32 reg; 347 + int ret; 348 + 349 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 350 + if (ret) 351 + return ret; 352 + 353 + regmap_update_bits(ebi->regmap, reg, prop->reg_mask, 354 + setup ? prop->reg_mask : 0); 355 + 356 + return 0; 357 + } 358 + 359 + static int stm32_fmc2_ebi_set_trans_type(struct stm32_fmc2_ebi *ebi, 360 + const struct stm32_fmc2_prop *prop, 361 + int cs, u32 setup) 362 + { 363 + u32 bcr_mask, bcr = FMC2_BCR_WREN; 364 + u32 btr_mask, btr = 0; 365 + u32 bwtr_mask, bwtr = 0; 366 + 367 + bwtr_mask = FMC2_BXTR_ACCMOD; 368 + btr_mask = FMC2_BXTR_ACCMOD; 369 + bcr_mask = FMC2_BCR_MUXEN | FMC2_BCR_MTYP | FMC2_BCR_FACCEN | 370 + FMC2_BCR_WREN | FMC2_BCR_WAITEN | FMC2_BCR_BURSTEN | 371 + FMC2_BCR_EXTMOD | FMC2_BCR_CBURSTRW; 372 + 373 + switch (setup) { 374 + case FMC2_ASYNC_MODE_1_SRAM: 375 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_SRAM); 376 + /* 377 + * MUXEN = 0, MTYP = 0, FACCEN = 0, BURSTEN = 0, WAITEN = 0, 378 + * WREN = 1, EXTMOD = 0, CBURSTRW = 0, ACCMOD = 0 379 + */ 380 + break; 381 + case FMC2_ASYNC_MODE_1_PSRAM: 382 + /* 383 + * MUXEN = 0, MTYP = 1, FACCEN = 0, BURSTEN = 0, WAITEN = 0, 384 + * WREN = 1, EXTMOD = 0, CBURSTRW = 0, ACCMOD = 0 385 + */ 386 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM); 387 + break; 388 + case FMC2_ASYNC_MODE_A_SRAM: 389 + /* 390 + * MUXEN = 0, MTYP = 0, FACCEN = 0, BURSTEN = 0, WAITEN = 0, 391 + * WREN = 1, EXTMOD = 1, CBURSTRW = 0, ACCMOD = 0 392 + */ 393 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_SRAM); 394 + bcr |= FMC2_BCR_EXTMOD; 395 + btr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_A); 396 + bwtr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_A); 397 + break; 398 + case FMC2_ASYNC_MODE_A_PSRAM: 399 + /* 400 + * MUXEN = 0, MTYP = 1, FACCEN = 0, BURSTEN = 0, WAITEN = 0, 401 + * WREN = 1, EXTMOD = 1, CBURSTRW = 0, ACCMOD = 0 402 + */ 403 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM); 404 + bcr |= FMC2_BCR_EXTMOD; 405 + btr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_A); 406 + bwtr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_A); 407 + break; 408 + case FMC2_ASYNC_MODE_2_NOR: 409 + /* 410 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 0, WAITEN = 0, 411 + * WREN = 1, EXTMOD = 0, CBURSTRW = 0, ACCMOD = 0 412 + */ 413 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 414 + bcr |= FMC2_BCR_FACCEN; 415 + break; 416 + case FMC2_ASYNC_MODE_B_NOR: 417 + /* 418 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 0, WAITEN = 0, 419 + * WREN = 1, EXTMOD = 1, CBURSTRW = 0, ACCMOD = 1 420 + */ 421 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 422 + bcr |= FMC2_BCR_FACCEN | FMC2_BCR_EXTMOD; 423 + btr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_B); 424 + bwtr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_B); 425 + break; 426 + case FMC2_ASYNC_MODE_C_NOR: 427 + /* 428 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 0, WAITEN = 0, 429 + * WREN = 1, EXTMOD = 1, CBURSTRW = 0, ACCMOD = 2 430 + */ 431 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 432 + bcr |= FMC2_BCR_FACCEN | FMC2_BCR_EXTMOD; 433 + btr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_C); 434 + bwtr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_C); 435 + break; 436 + case FMC2_ASYNC_MODE_D_NOR: 437 + /* 438 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 0, WAITEN = 0, 439 + * WREN = 1, EXTMOD = 1, CBURSTRW = 0, ACCMOD = 3 440 + */ 441 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 442 + bcr |= FMC2_BCR_FACCEN | FMC2_BCR_EXTMOD; 443 + btr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_D); 444 + bwtr |= FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_D); 445 + break; 446 + case FMC2_SYNC_READ_SYNC_WRITE_PSRAM: 447 + /* 448 + * MUXEN = 0, MTYP = 1, FACCEN = 0, BURSTEN = 1, WAITEN = 0, 449 + * WREN = 1, EXTMOD = 0, CBURSTRW = 1, ACCMOD = 0 450 + */ 451 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM); 452 + bcr |= FMC2_BCR_BURSTEN | FMC2_BCR_CBURSTRW; 453 + break; 454 + case FMC2_SYNC_READ_ASYNC_WRITE_PSRAM: 455 + /* 456 + * MUXEN = 0, MTYP = 1, FACCEN = 0, BURSTEN = 1, WAITEN = 0, 457 + * WREN = 1, EXTMOD = 0, CBURSTRW = 0, ACCMOD = 0 458 + */ 459 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_PSRAM); 460 + bcr |= FMC2_BCR_BURSTEN; 461 + break; 462 + case FMC2_SYNC_READ_SYNC_WRITE_NOR: 463 + /* 464 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 1, WAITEN = 0, 465 + * WREN = 1, EXTMOD = 0, CBURSTRW = 1, ACCMOD = 0 466 + */ 467 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 468 + bcr |= FMC2_BCR_FACCEN | FMC2_BCR_BURSTEN | FMC2_BCR_CBURSTRW; 469 + break; 470 + case FMC2_SYNC_READ_ASYNC_WRITE_NOR: 471 + /* 472 + * MUXEN = 0, MTYP = 2, FACCEN = 1, BURSTEN = 1, WAITEN = 0, 473 + * WREN = 1, EXTMOD = 0, CBURSTRW = 0, ACCMOD = 0 474 + */ 475 + bcr |= FIELD_PREP(FMC2_BCR_MTYP, FMC2_BCR_MTYP_NOR); 476 + bcr |= FMC2_BCR_FACCEN | FMC2_BCR_BURSTEN; 477 + break; 478 + default: 479 + /* Type of transaction not supported */ 480 + return -EINVAL; 481 + } 482 + 483 + if (bcr & FMC2_BCR_EXTMOD) 484 + regmap_update_bits(ebi->regmap, FMC2_BWTR(cs), 485 + bwtr_mask, bwtr); 486 + regmap_update_bits(ebi->regmap, FMC2_BTR(cs), btr_mask, btr); 487 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), bcr_mask, bcr); 488 + 489 + return 0; 490 + } 491 + 492 + static int stm32_fmc2_ebi_set_buswidth(struct stm32_fmc2_ebi *ebi, 493 + const struct stm32_fmc2_prop *prop, 494 + int cs, u32 setup) 495 + { 496 + u32 val; 497 + 498 + switch (setup) { 499 + case FMC2_BUSWIDTH_8: 500 + val = FIELD_PREP(FMC2_BCR_MWID, FMC2_BCR_MWID_8); 501 + break; 502 + case FMC2_BUSWIDTH_16: 503 + val = FIELD_PREP(FMC2_BCR_MWID, FMC2_BCR_MWID_16); 504 + break; 505 + default: 506 + /* Buswidth not supported */ 507 + return -EINVAL; 508 + } 509 + 510 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_MWID, val); 511 + 512 + return 0; 513 + } 514 + 515 + static int stm32_fmc2_ebi_set_cpsize(struct stm32_fmc2_ebi *ebi, 516 + const struct stm32_fmc2_prop *prop, 517 + int cs, u32 setup) 518 + { 519 + u32 val; 520 + 521 + switch (setup) { 522 + case FMC2_CPSIZE_0: 523 + val = FIELD_PREP(FMC2_BCR_CPSIZE, FMC2_BCR_CPSIZE_0); 524 + break; 525 + case FMC2_CPSIZE_128: 526 + val = FIELD_PREP(FMC2_BCR_CPSIZE, FMC2_BCR_CPSIZE_128); 527 + break; 528 + case FMC2_CPSIZE_256: 529 + val = FIELD_PREP(FMC2_BCR_CPSIZE, FMC2_BCR_CPSIZE_256); 530 + break; 531 + case FMC2_CPSIZE_512: 532 + val = FIELD_PREP(FMC2_BCR_CPSIZE, FMC2_BCR_CPSIZE_512); 533 + break; 534 + case FMC2_CPSIZE_1024: 535 + val = FIELD_PREP(FMC2_BCR_CPSIZE, FMC2_BCR_CPSIZE_1024); 536 + break; 537 + default: 538 + /* Cpsize not supported */ 539 + return -EINVAL; 540 + } 541 + 542 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_CPSIZE, val); 543 + 544 + return 0; 545 + } 546 + 547 + static int stm32_fmc2_ebi_set_bl_setup(struct stm32_fmc2_ebi *ebi, 548 + const struct stm32_fmc2_prop *prop, 549 + int cs, u32 setup) 550 + { 551 + u32 val; 552 + 553 + val = min_t(u32, setup, FMC2_BCR_NBLSET_MAX); 554 + val = FIELD_PREP(FMC2_BCR_NBLSET, val); 555 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_NBLSET, val); 556 + 557 + return 0; 558 + } 559 + 560 + static int stm32_fmc2_ebi_set_address_setup(struct stm32_fmc2_ebi *ebi, 561 + const struct stm32_fmc2_prop *prop, 562 + int cs, u32 setup) 563 + { 564 + u32 bcr, bxtr, reg; 565 + u32 val = FIELD_PREP(FMC2_BXTR_ACCMOD, FMC2_BXTR_EXTMOD_D); 566 + int ret; 567 + 568 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 569 + if (ret) 570 + return ret; 571 + 572 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 573 + if (prop->reg_type == FMC2_REG_BWTR) 574 + regmap_read(ebi->regmap, FMC2_BWTR(cs), &bxtr); 575 + else 576 + regmap_read(ebi->regmap, FMC2_BTR(cs), &bxtr); 577 + 578 + if ((bxtr & FMC2_BXTR_ACCMOD) == val || bcr & FMC2_BCR_MUXEN) 579 + val = clamp_val(setup, 1, FMC2_BXTR_ADDSET_MAX); 580 + else 581 + val = min_t(u32, setup, FMC2_BXTR_ADDSET_MAX); 582 + val = FIELD_PREP(FMC2_BXTR_ADDSET, val); 583 + regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_ADDSET, val); 584 + 585 + return 0; 586 + } 587 + 588 + static int stm32_fmc2_ebi_set_address_hold(struct stm32_fmc2_ebi *ebi, 589 + const struct stm32_fmc2_prop *prop, 590 + int cs, u32 setup) 591 + { 592 + u32 val, reg; 593 + int ret; 594 + 595 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 596 + if (ret) 597 + return ret; 598 + 599 + val = clamp_val(setup, 1, FMC2_BXTR_ADDHLD_MAX); 600 + val = FIELD_PREP(FMC2_BXTR_ADDHLD, val); 601 + regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_ADDHLD, val); 602 + 603 + return 0; 604 + } 605 + 606 + static int stm32_fmc2_ebi_set_data_setup(struct stm32_fmc2_ebi *ebi, 607 + const struct stm32_fmc2_prop *prop, 608 + int cs, u32 setup) 609 + { 610 + u32 val, reg; 611 + int ret; 612 + 613 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 614 + if (ret) 615 + return ret; 616 + 617 + val = clamp_val(setup, 1, FMC2_BXTR_DATAST_MAX); 618 + val = FIELD_PREP(FMC2_BXTR_DATAST, val); 619 + regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_DATAST, val); 620 + 621 + return 0; 622 + } 623 + 624 + static int stm32_fmc2_ebi_set_bus_turnaround(struct stm32_fmc2_ebi *ebi, 625 + const struct stm32_fmc2_prop *prop, 626 + int cs, u32 setup) 627 + { 628 + u32 val, reg; 629 + int ret; 630 + 631 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 632 + if (ret) 633 + return ret; 634 + 635 + val = setup ? min_t(u32, setup - 1, FMC2_BXTR_BUSTURN_MAX) : 0; 636 + val = FIELD_PREP(FMC2_BXTR_BUSTURN, val); 637 + regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_BUSTURN, val); 638 + 639 + return 0; 640 + } 641 + 642 + static int stm32_fmc2_ebi_set_data_hold(struct stm32_fmc2_ebi *ebi, 643 + const struct stm32_fmc2_prop *prop, 644 + int cs, u32 setup) 645 + { 646 + u32 val, reg; 647 + int ret; 648 + 649 + ret = stm32_fmc2_ebi_get_reg(prop->reg_type, cs, &reg); 650 + if (ret) 651 + return ret; 652 + 653 + if (prop->reg_type == FMC2_REG_BWTR) 654 + val = setup ? min_t(u32, setup - 1, FMC2_BXTR_DATAHLD_MAX) : 0; 655 + else 656 + val = min_t(u32, setup, FMC2_BXTR_DATAHLD_MAX); 657 + val = FIELD_PREP(FMC2_BXTR_DATAHLD, val); 658 + regmap_update_bits(ebi->regmap, reg, FMC2_BXTR_DATAHLD, val); 659 + 660 + return 0; 661 + } 662 + 663 + static int stm32_fmc2_ebi_set_clk_period(struct stm32_fmc2_ebi *ebi, 664 + const struct stm32_fmc2_prop *prop, 665 + int cs, u32 setup) 666 + { 667 + u32 val; 668 + 669 + val = setup ? clamp_val(setup - 1, 1, FMC2_BTR_CLKDIV_MAX) : 1; 670 + val = FIELD_PREP(FMC2_BTR_CLKDIV, val); 671 + regmap_update_bits(ebi->regmap, FMC2_BTR(cs), FMC2_BTR_CLKDIV, val); 672 + 673 + return 0; 674 + } 675 + 676 + static int stm32_fmc2_ebi_set_data_latency(struct stm32_fmc2_ebi *ebi, 677 + const struct stm32_fmc2_prop *prop, 678 + int cs, u32 setup) 679 + { 680 + u32 val; 681 + 682 + val = setup > 1 ? min_t(u32, setup - 2, FMC2_BTR_DATLAT_MAX) : 0; 683 + val = FIELD_PREP(FMC2_BTR_DATLAT, val); 684 + regmap_update_bits(ebi->regmap, FMC2_BTR(cs), FMC2_BTR_DATLAT, val); 685 + 686 + return 0; 687 + } 688 + 689 + static int stm32_fmc2_ebi_set_max_low_pulse(struct stm32_fmc2_ebi *ebi, 690 + const struct stm32_fmc2_prop *prop, 691 + int cs, u32 setup) 692 + { 693 + u32 old_val, new_val, pcscntr; 694 + 695 + if (setup < 1) 696 + return 0; 697 + 698 + regmap_read(ebi->regmap, FMC2_PCSCNTR, &pcscntr); 699 + 700 + /* Enable counter for the bank */ 701 + regmap_update_bits(ebi->regmap, FMC2_PCSCNTR, 702 + FMC2_PCSCNTR_CNTBEN(cs), 703 + FMC2_PCSCNTR_CNTBEN(cs)); 704 + 705 + new_val = min_t(u32, setup - 1, FMC2_PCSCNTR_CSCOUNT_MAX); 706 + old_val = FIELD_GET(FMC2_PCSCNTR_CSCOUNT, pcscntr); 707 + if (old_val && new_val > old_val) 708 + /* Keep current counter value */ 709 + return 0; 710 + 711 + new_val = FIELD_PREP(FMC2_PCSCNTR_CSCOUNT, new_val); 712 + regmap_update_bits(ebi->regmap, FMC2_PCSCNTR, 713 + FMC2_PCSCNTR_CSCOUNT, new_val); 714 + 715 + return 0; 716 + } 717 + 718 + static const struct stm32_fmc2_prop stm32_fmc2_child_props[] = { 719 + /* st,fmc2-ebi-cs-trans-type must be the first property */ 720 + { 721 + .name = "st,fmc2-ebi-cs-transaction-type", 722 + .mprop = true, 723 + .set = stm32_fmc2_ebi_set_trans_type, 724 + }, 725 + { 726 + .name = "st,fmc2-ebi-cs-cclk-enable", 727 + .bprop = true, 728 + .reg_type = FMC2_REG_BCR, 729 + .reg_mask = FMC2_BCR1_CCLKEN, 730 + .check = stm32_fmc2_ebi_check_cclk, 731 + .set = stm32_fmc2_ebi_set_bit_field, 732 + }, 733 + { 734 + .name = "st,fmc2-ebi-cs-mux-enable", 735 + .bprop = true, 736 + .reg_type = FMC2_REG_BCR, 737 + .reg_mask = FMC2_BCR_MUXEN, 738 + .check = stm32_fmc2_ebi_check_mux, 739 + .set = stm32_fmc2_ebi_set_bit_field, 740 + }, 741 + { 742 + .name = "st,fmc2-ebi-cs-buswidth", 743 + .reset_val = FMC2_BUSWIDTH_16, 744 + .set = stm32_fmc2_ebi_set_buswidth, 745 + }, 746 + { 747 + .name = "st,fmc2-ebi-cs-waitpol-high", 748 + .bprop = true, 749 + .reg_type = FMC2_REG_BCR, 750 + .reg_mask = FMC2_BCR_WAITPOL, 751 + .set = stm32_fmc2_ebi_set_bit_field, 752 + }, 753 + { 754 + .name = "st,fmc2-ebi-cs-waitcfg-enable", 755 + .bprop = true, 756 + .reg_type = FMC2_REG_BCR, 757 + .reg_mask = FMC2_BCR_WAITCFG, 758 + .check = stm32_fmc2_ebi_check_waitcfg, 759 + .set = stm32_fmc2_ebi_set_bit_field, 760 + }, 761 + { 762 + .name = "st,fmc2-ebi-cs-wait-enable", 763 + .bprop = true, 764 + .reg_type = FMC2_REG_BCR, 765 + .reg_mask = FMC2_BCR_WAITEN, 766 + .check = stm32_fmc2_ebi_check_sync_trans, 767 + .set = stm32_fmc2_ebi_set_bit_field, 768 + }, 769 + { 770 + .name = "st,fmc2-ebi-cs-asyncwait-enable", 771 + .bprop = true, 772 + .reg_type = FMC2_REG_BCR, 773 + .reg_mask = FMC2_BCR_ASYNCWAIT, 774 + .check = stm32_fmc2_ebi_check_async_trans, 775 + .set = stm32_fmc2_ebi_set_bit_field, 776 + }, 777 + { 778 + .name = "st,fmc2-ebi-cs-cpsize", 779 + .check = stm32_fmc2_ebi_check_cpsize, 780 + .set = stm32_fmc2_ebi_set_cpsize, 781 + }, 782 + { 783 + .name = "st,fmc2-ebi-cs-byte-lane-setup-ns", 784 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 785 + .set = stm32_fmc2_ebi_set_bl_setup, 786 + }, 787 + { 788 + .name = "st,fmc2-ebi-cs-address-setup-ns", 789 + .reg_type = FMC2_REG_BTR, 790 + .reset_val = FMC2_BXTR_ADDSET_MAX, 791 + .check = stm32_fmc2_ebi_check_async_trans, 792 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 793 + .set = stm32_fmc2_ebi_set_address_setup, 794 + }, 795 + { 796 + .name = "st,fmc2-ebi-cs-address-hold-ns", 797 + .reg_type = FMC2_REG_BTR, 798 + .reset_val = FMC2_BXTR_ADDHLD_MAX, 799 + .check = stm32_fmc2_ebi_check_address_hold, 800 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 801 + .set = stm32_fmc2_ebi_set_address_hold, 802 + }, 803 + { 804 + .name = "st,fmc2-ebi-cs-data-setup-ns", 805 + .reg_type = FMC2_REG_BTR, 806 + .reset_val = FMC2_BXTR_DATAST_MAX, 807 + .check = stm32_fmc2_ebi_check_async_trans, 808 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 809 + .set = stm32_fmc2_ebi_set_data_setup, 810 + }, 811 + { 812 + .name = "st,fmc2-ebi-cs-bus-turnaround-ns", 813 + .reg_type = FMC2_REG_BTR, 814 + .reset_val = FMC2_BXTR_BUSTURN_MAX + 1, 815 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 816 + .set = stm32_fmc2_ebi_set_bus_turnaround, 817 + }, 818 + { 819 + .name = "st,fmc2-ebi-cs-data-hold-ns", 820 + .reg_type = FMC2_REG_BTR, 821 + .check = stm32_fmc2_ebi_check_async_trans, 822 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 823 + .set = stm32_fmc2_ebi_set_data_hold, 824 + }, 825 + { 826 + .name = "st,fmc2-ebi-cs-clk-period-ns", 827 + .reset_val = FMC2_BTR_CLKDIV_MAX + 1, 828 + .check = stm32_fmc2_ebi_check_clk_period, 829 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 830 + .set = stm32_fmc2_ebi_set_clk_period, 831 + }, 832 + { 833 + .name = "st,fmc2-ebi-cs-data-latency-ns", 834 + .check = stm32_fmc2_ebi_check_sync_trans, 835 + .calculate = stm32_fmc2_ebi_ns_to_clk_period, 836 + .set = stm32_fmc2_ebi_set_data_latency, 837 + }, 838 + { 839 + .name = "st,fmc2-ebi-cs-write-address-setup-ns", 840 + .reg_type = FMC2_REG_BWTR, 841 + .reset_val = FMC2_BXTR_ADDSET_MAX, 842 + .check = stm32_fmc2_ebi_check_async_trans, 843 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 844 + .set = stm32_fmc2_ebi_set_address_setup, 845 + }, 846 + { 847 + .name = "st,fmc2-ebi-cs-write-address-hold-ns", 848 + .reg_type = FMC2_REG_BWTR, 849 + .reset_val = FMC2_BXTR_ADDHLD_MAX, 850 + .check = stm32_fmc2_ebi_check_address_hold, 851 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 852 + .set = stm32_fmc2_ebi_set_address_hold, 853 + }, 854 + { 855 + .name = "st,fmc2-ebi-cs-write-data-setup-ns", 856 + .reg_type = FMC2_REG_BWTR, 857 + .reset_val = FMC2_BXTR_DATAST_MAX, 858 + .check = stm32_fmc2_ebi_check_async_trans, 859 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 860 + .set = stm32_fmc2_ebi_set_data_setup, 861 + }, 862 + { 863 + .name = "st,fmc2-ebi-cs-write-bus-turnaround-ns", 864 + .reg_type = FMC2_REG_BWTR, 865 + .reset_val = FMC2_BXTR_BUSTURN_MAX + 1, 866 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 867 + .set = stm32_fmc2_ebi_set_bus_turnaround, 868 + }, 869 + { 870 + .name = "st,fmc2-ebi-cs-write-data-hold-ns", 871 + .reg_type = FMC2_REG_BWTR, 872 + .check = stm32_fmc2_ebi_check_async_trans, 873 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 874 + .set = stm32_fmc2_ebi_set_data_hold, 875 + }, 876 + { 877 + .name = "st,fmc2-ebi-cs-max-low-pulse-ns", 878 + .calculate = stm32_fmc2_ebi_ns_to_clock_cycles, 879 + .set = stm32_fmc2_ebi_set_max_low_pulse, 880 + }, 881 + }; 882 + 883 + static int stm32_fmc2_ebi_parse_prop(struct stm32_fmc2_ebi *ebi, 884 + struct device_node *dev_node, 885 + const struct stm32_fmc2_prop *prop, 886 + int cs) 887 + { 888 + struct device *dev = ebi->dev; 889 + u32 setup = 0; 890 + 891 + if (!prop->set) { 892 + dev_err(dev, "property %s is not well defined\n", prop->name); 893 + return -EINVAL; 894 + } 895 + 896 + if (prop->check && prop->check(ebi, prop, cs)) 897 + /* Skeep this property */ 898 + return 0; 899 + 900 + if (prop->bprop) { 901 + bool bprop; 902 + 903 + bprop = of_property_read_bool(dev_node, prop->name); 904 + if (prop->mprop && !bprop) { 905 + dev_err(dev, "mandatory property %s not defined in the device tree\n", 906 + prop->name); 907 + return -EINVAL; 908 + } 909 + 910 + if (bprop) 911 + setup = 1; 912 + } else { 913 + u32 val; 914 + int ret; 915 + 916 + ret = of_property_read_u32(dev_node, prop->name, &val); 917 + if (prop->mprop && ret) { 918 + dev_err(dev, "mandatory property %s not defined in the device tree\n", 919 + prop->name); 920 + return ret; 921 + } 922 + 923 + if (ret) 924 + setup = prop->reset_val; 925 + else if (prop->calculate) 926 + setup = prop->calculate(ebi, cs, val); 927 + else 928 + setup = val; 929 + } 930 + 931 + return prop->set(ebi, prop, cs, setup); 932 + } 933 + 934 + static void stm32_fmc2_ebi_enable_bank(struct stm32_fmc2_ebi *ebi, int cs) 935 + { 936 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), 937 + FMC2_BCR_MBKEN, FMC2_BCR_MBKEN); 938 + } 939 + 940 + static void stm32_fmc2_ebi_disable_bank(struct stm32_fmc2_ebi *ebi, int cs) 941 + { 942 + regmap_update_bits(ebi->regmap, FMC2_BCR(cs), FMC2_BCR_MBKEN, 0); 943 + } 944 + 945 + static void stm32_fmc2_ebi_save_setup(struct stm32_fmc2_ebi *ebi) 946 + { 947 + unsigned int cs; 948 + 949 + for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { 950 + regmap_read(ebi->regmap, FMC2_BCR(cs), &ebi->bcr[cs]); 951 + regmap_read(ebi->regmap, FMC2_BTR(cs), &ebi->btr[cs]); 952 + regmap_read(ebi->regmap, FMC2_BWTR(cs), &ebi->bwtr[cs]); 953 + } 954 + 955 + regmap_read(ebi->regmap, FMC2_PCSCNTR, &ebi->pcscntr); 956 + } 957 + 958 + static void stm32_fmc2_ebi_set_setup(struct stm32_fmc2_ebi *ebi) 959 + { 960 + unsigned int cs; 961 + 962 + for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { 963 + regmap_write(ebi->regmap, FMC2_BCR(cs), ebi->bcr[cs]); 964 + regmap_write(ebi->regmap, FMC2_BTR(cs), ebi->btr[cs]); 965 + regmap_write(ebi->regmap, FMC2_BWTR(cs), ebi->bwtr[cs]); 966 + } 967 + 968 + regmap_write(ebi->regmap, FMC2_PCSCNTR, ebi->pcscntr); 969 + } 970 + 971 + static void stm32_fmc2_ebi_disable_banks(struct stm32_fmc2_ebi *ebi) 972 + { 973 + unsigned int cs; 974 + 975 + for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { 976 + if (!(ebi->bank_assigned & BIT(cs))) 977 + continue; 978 + 979 + stm32_fmc2_ebi_disable_bank(ebi, cs); 980 + } 981 + } 982 + 983 + /* NWAIT signal can not be connected to EBI controller and NAND controller */ 984 + static bool stm32_fmc2_ebi_nwait_used_by_ctrls(struct stm32_fmc2_ebi *ebi) 985 + { 986 + unsigned int cs; 987 + u32 bcr; 988 + 989 + for (cs = 0; cs < FMC2_MAX_EBI_CE; cs++) { 990 + if (!(ebi->bank_assigned & BIT(cs))) 991 + continue; 992 + 993 + regmap_read(ebi->regmap, FMC2_BCR(cs), &bcr); 994 + if ((bcr & FMC2_BCR_WAITEN || bcr & FMC2_BCR_ASYNCWAIT) && 995 + ebi->bank_assigned & BIT(FMC2_NAND)) 996 + return true; 997 + } 998 + 999 + return false; 1000 + } 1001 + 1002 + static void stm32_fmc2_ebi_enable(struct stm32_fmc2_ebi *ebi) 1003 + { 1004 + regmap_update_bits(ebi->regmap, FMC2_BCR1, 1005 + FMC2_BCR1_FMC2EN, FMC2_BCR1_FMC2EN); 1006 + } 1007 + 1008 + static void stm32_fmc2_ebi_disable(struct stm32_fmc2_ebi *ebi) 1009 + { 1010 + regmap_update_bits(ebi->regmap, FMC2_BCR1, FMC2_BCR1_FMC2EN, 0); 1011 + } 1012 + 1013 + static int stm32_fmc2_ebi_setup_cs(struct stm32_fmc2_ebi *ebi, 1014 + struct device_node *dev_node, 1015 + u32 cs) 1016 + { 1017 + unsigned int i; 1018 + int ret; 1019 + 1020 + stm32_fmc2_ebi_disable_bank(ebi, cs); 1021 + 1022 + for (i = 0; i < ARRAY_SIZE(stm32_fmc2_child_props); i++) { 1023 + const struct stm32_fmc2_prop *p = &stm32_fmc2_child_props[i]; 1024 + 1025 + ret = stm32_fmc2_ebi_parse_prop(ebi, dev_node, p, cs); 1026 + if (ret) { 1027 + dev_err(ebi->dev, "property %s could not be set: %d\n", 1028 + p->name, ret); 1029 + return ret; 1030 + } 1031 + } 1032 + 1033 + stm32_fmc2_ebi_enable_bank(ebi, cs); 1034 + 1035 + return 0; 1036 + } 1037 + 1038 + static int stm32_fmc2_ebi_parse_dt(struct stm32_fmc2_ebi *ebi) 1039 + { 1040 + struct device *dev = ebi->dev; 1041 + struct device_node *child; 1042 + bool child_found = false; 1043 + u32 bank; 1044 + int ret; 1045 + 1046 + for_each_available_child_of_node(dev->of_node, child) { 1047 + ret = of_property_read_u32(child, "reg", &bank); 1048 + if (ret) { 1049 + dev_err(dev, "could not retrieve reg property: %d\n", 1050 + ret); 1051 + return ret; 1052 + } 1053 + 1054 + if (bank >= FMC2_MAX_BANKS) { 1055 + dev_err(dev, "invalid reg value: %d\n", bank); 1056 + return -EINVAL; 1057 + } 1058 + 1059 + if (ebi->bank_assigned & BIT(bank)) { 1060 + dev_err(dev, "bank already assigned: %d\n", bank); 1061 + return -EINVAL; 1062 + } 1063 + 1064 + if (bank < FMC2_MAX_EBI_CE) { 1065 + ret = stm32_fmc2_ebi_setup_cs(ebi, child, bank); 1066 + if (ret) { 1067 + dev_err(dev, "setup chip select %d failed: %d\n", 1068 + bank, ret); 1069 + return ret; 1070 + } 1071 + } 1072 + 1073 + ebi->bank_assigned |= BIT(bank); 1074 + child_found = true; 1075 + } 1076 + 1077 + if (!child_found) { 1078 + dev_warn(dev, "no subnodes found, disable the driver.\n"); 1079 + return -ENODEV; 1080 + } 1081 + 1082 + if (stm32_fmc2_ebi_nwait_used_by_ctrls(ebi)) { 1083 + dev_err(dev, "NWAIT signal connected to EBI and NAND controllers\n"); 1084 + return -EINVAL; 1085 + } 1086 + 1087 + stm32_fmc2_ebi_enable(ebi); 1088 + 1089 + return of_platform_populate(dev->of_node, NULL, NULL, dev); 1090 + } 1091 + 1092 + static int stm32_fmc2_ebi_probe(struct platform_device *pdev) 1093 + { 1094 + struct device *dev = &pdev->dev; 1095 + struct stm32_fmc2_ebi *ebi; 1096 + struct reset_control *rstc; 1097 + int ret; 1098 + 1099 + ebi = devm_kzalloc(&pdev->dev, sizeof(*ebi), GFP_KERNEL); 1100 + if (!ebi) 1101 + return -ENOMEM; 1102 + 1103 + ebi->dev = dev; 1104 + 1105 + ebi->regmap = device_node_to_regmap(dev->of_node); 1106 + if (IS_ERR(ebi->regmap)) 1107 + return PTR_ERR(ebi->regmap); 1108 + 1109 + ebi->clk = devm_clk_get(dev, NULL); 1110 + if (IS_ERR(ebi->clk)) 1111 + return PTR_ERR(ebi->clk); 1112 + 1113 + rstc = devm_reset_control_get(dev, NULL); 1114 + if (PTR_ERR(rstc) == -EPROBE_DEFER) 1115 + return -EPROBE_DEFER; 1116 + 1117 + ret = clk_prepare_enable(ebi->clk); 1118 + if (ret) 1119 + return ret; 1120 + 1121 + if (!IS_ERR(rstc)) { 1122 + reset_control_assert(rstc); 1123 + reset_control_deassert(rstc); 1124 + } 1125 + 1126 + ret = stm32_fmc2_ebi_parse_dt(ebi); 1127 + if (ret) 1128 + goto err_release; 1129 + 1130 + stm32_fmc2_ebi_save_setup(ebi); 1131 + platform_set_drvdata(pdev, ebi); 1132 + 1133 + return 0; 1134 + 1135 + err_release: 1136 + stm32_fmc2_ebi_disable_banks(ebi); 1137 + stm32_fmc2_ebi_disable(ebi); 1138 + clk_disable_unprepare(ebi->clk); 1139 + 1140 + return ret; 1141 + } 1142 + 1143 + static int stm32_fmc2_ebi_remove(struct platform_device *pdev) 1144 + { 1145 + struct stm32_fmc2_ebi *ebi = platform_get_drvdata(pdev); 1146 + 1147 + of_platform_depopulate(&pdev->dev); 1148 + stm32_fmc2_ebi_disable_banks(ebi); 1149 + stm32_fmc2_ebi_disable(ebi); 1150 + clk_disable_unprepare(ebi->clk); 1151 + 1152 + return 0; 1153 + } 1154 + 1155 + static int __maybe_unused stm32_fmc2_ebi_suspend(struct device *dev) 1156 + { 1157 + struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); 1158 + 1159 + stm32_fmc2_ebi_disable(ebi); 1160 + clk_disable_unprepare(ebi->clk); 1161 + pinctrl_pm_select_sleep_state(dev); 1162 + 1163 + return 0; 1164 + } 1165 + 1166 + static int __maybe_unused stm32_fmc2_ebi_resume(struct device *dev) 1167 + { 1168 + struct stm32_fmc2_ebi *ebi = dev_get_drvdata(dev); 1169 + int ret; 1170 + 1171 + pinctrl_pm_select_default_state(dev); 1172 + 1173 + ret = clk_prepare_enable(ebi->clk); 1174 + if (ret) 1175 + return ret; 1176 + 1177 + stm32_fmc2_ebi_set_setup(ebi); 1178 + stm32_fmc2_ebi_enable(ebi); 1179 + 1180 + return 0; 1181 + } 1182 + 1183 + static SIMPLE_DEV_PM_OPS(stm32_fmc2_ebi_pm_ops, stm32_fmc2_ebi_suspend, 1184 + stm32_fmc2_ebi_resume); 1185 + 1186 + static const struct of_device_id stm32_fmc2_ebi_match[] = { 1187 + {.compatible = "st,stm32mp1-fmc2-ebi"}, 1188 + {} 1189 + }; 1190 + MODULE_DEVICE_TABLE(of, stm32_fmc2_ebi_match); 1191 + 1192 + static struct platform_driver stm32_fmc2_ebi_driver = { 1193 + .probe = stm32_fmc2_ebi_probe, 1194 + .remove = stm32_fmc2_ebi_remove, 1195 + .driver = { 1196 + .name = "stm32_fmc2_ebi", 1197 + .of_match_table = stm32_fmc2_ebi_match, 1198 + .pm = &stm32_fmc2_ebi_pm_ops, 1199 + }, 1200 + }; 1201 + module_platform_driver(stm32_fmc2_ebi_driver); 1202 + 1203 + MODULE_ALIAS("platform:stm32_fmc2_ebi"); 1204 + MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>"); 1205 + MODULE_DESCRIPTION("STMicroelectronics STM32 FMC2 ebi driver"); 1206 + MODULE_LICENSE("GPL v2");
+1 -1
drivers/mtd/chips/Kconfig
··· 11 11 AMD and other flash manufactures that provides a universal method 12 12 for probing the capabilities of flash devices. If you wish to 13 13 support any device that is CFI-compliant, you need to enable this 14 - option. Visit <http://www.amd.com/products/nvd/overview/cfi.html> 14 + option. Visit <https://www.amd.com/products/nvd/overview/cfi.html> 15 15 for more information on CFI. 16 16 17 17 config MTD_JEDECPROBE
+1 -1
drivers/mtd/hyperbus/hbmc-am654.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // 3 - // Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ 3 + // Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/ 4 4 // Author: Vignesh Raghavendra <vigneshr@ti.com> 5 5 6 6 #include <linux/err.h>
+1 -1
drivers/mtd/hyperbus/hyperbus-core.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // 3 - // Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ 3 + // Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/ 4 4 // Author: Vignesh Raghavendra <vigneshr@ti.com> 5 5 6 6 #include <linux/err.h>
+1 -1
drivers/mtd/maps/Kconfig
··· 310 310 help 311 311 This provides a driver for the flash accessed using Intel's 312 312 21285 bridge used with Intel's StrongARM processors. More info at 313 - <http://www.intel.com/design/bridge/docs/21285_documentation.htm>. 313 + <https://www.intel.com/design/bridge/docs/21285_documentation.htm>. 314 314 315 315 config MTD_IXP4XX 316 316 tristate "CFI Flash device mapped on Intel IXP4xx based systems"
+1 -1
drivers/mtd/maps/sc520cdp.c
··· 6 6 * The SC520CDP is an evaluation board for the Elan SC520 processor available 7 7 * from AMD. It has two banks of 32-bit Flash ROM, each 8 Megabytes in size, 8 8 * and up to 512 KiB of 8-bit DIL Flash ROM. 9 - * For details see http://www.amd.com/products/epd/desiging/evalboards/18.elansc520/520_cdp_brief/index.html 9 + * For details see https://www.amd.com/products/epd/desiging/evalboards/18.elansc520/520_cdp_brief/index.html 10 10 */ 11 11 12 12 #include <linux/module.h>
+5
drivers/mtd/nand/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + menu "NAND" 4 + 2 5 config MTD_NAND_CORE 3 6 tristate 4 7 5 8 source "drivers/mtd/nand/onenand/Kconfig" 6 9 source "drivers/mtd/nand/raw/Kconfig" 7 10 source "drivers/mtd/nand/spi/Kconfig" 11 + 12 + endmenu
-1
drivers/mtd/nand/onenand/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 menuconfig MTD_ONENAND 3 3 tristate "OneNAND Device Support" 4 - depends on MTD 5 4 depends on HAS_IOMEM 6 5 help 7 6 This enables support for accessing all type of OneNAND flash
+1 -1
drivers/mtd/nand/raw/Kconfig
··· 12 12 13 13 menuconfig MTD_RAW_NAND 14 14 tristate "Raw/Parallel NAND Device Support" 15 - depends on MTD 16 15 select MTD_NAND_CORE 17 16 select MTD_NAND_ECC_SW_HAMMING 18 17 help ··· 414 415 config MTD_NAND_STM32_FMC2 415 416 tristate "Support for NAND controller on STM32MP SoCs" 416 417 depends on MACH_STM32MP157 || COMPILE_TEST 418 + select MFD_SYSCON 417 419 help 418 420 Enables support for NAND Flash chips on SoCs containing the FMC2 419 421 NAND controller. This controller is found on STM32MP SoCs.
+3 -3
drivers/mtd/nand/raw/ams-delta.c
··· 191 191 return ret; 192 192 } 193 193 194 - static int gpio_nand_setup_data_interface(struct nand_chip *this, int csline, 195 - const struct nand_data_interface *cf) 194 + static int gpio_nand_setup_interface(struct nand_chip *this, int csline, 195 + const struct nand_interface_config *cf) 196 196 { 197 197 struct gpio_nand *priv = nand_get_controller_data(this); 198 198 const struct nand_sdr_timings *sdr = nand_get_sdr_timings(cf); ··· 217 217 218 218 static const struct nand_controller_ops gpio_nand_ops = { 219 219 .exec_op = gpio_nand_exec_op, 220 - .setup_data_interface = gpio_nand_setup_data_interface, 220 + .setup_interface = gpio_nand_setup_interface, 221 221 }; 222 222 223 223 /*
+3 -3
drivers/mtd/nand/raw/arasan-nand-controller.c
··· 854 854 return nand_op_parser_exec_op(chip, &anfc_op_parser, op, check_only); 855 855 } 856 856 857 - static int anfc_setup_data_interface(struct nand_chip *chip, int target, 858 - const struct nand_data_interface *conf) 857 + static int anfc_setup_interface(struct nand_chip *chip, int target, 858 + const struct nand_interface_config *conf) 859 859 { 860 860 struct anand *anand = to_anand(chip); 861 861 struct arasan_nfc *nfc = to_anfc(chip->controller); ··· 1083 1083 1084 1084 static const struct nand_controller_ops anfc_ops = { 1085 1085 .exec_op = anfc_exec_op, 1086 - .setup_data_interface = anfc_setup_data_interface, 1086 + .setup_interface = anfc_setup_interface, 1087 1087 .attach_chip = anfc_attach_chip, 1088 1088 .detach_chip = anfc_detach_chip, 1089 1089 };
+17 -17
drivers/mtd/nand/raw/atmel/nand-controller.c
··· 200 200 void (*nand_init)(struct atmel_nand_controller *nc, 201 201 struct atmel_nand *nand); 202 202 int (*ecc_init)(struct nand_chip *chip); 203 - int (*setup_data_interface)(struct atmel_nand *nand, int csline, 204 - const struct nand_data_interface *conf); 203 + int (*setup_interface)(struct atmel_nand *nand, int csline, 204 + const struct nand_interface_config *conf); 205 205 }; 206 206 207 207 struct atmel_nand_controller_caps { ··· 1168 1168 } 1169 1169 1170 1170 static int atmel_smc_nand_prepare_smcconf(struct atmel_nand *nand, 1171 - const struct nand_data_interface *conf, 1171 + const struct nand_interface_config *conf, 1172 1172 struct atmel_smc_cs_conf *smcconf) 1173 1173 { 1174 1174 u32 ncycles, totalcycles, timeps, mckperiodps; ··· 1397 1397 return 0; 1398 1398 } 1399 1399 1400 - static int atmel_smc_nand_setup_data_interface(struct atmel_nand *nand, 1400 + static int atmel_smc_nand_setup_interface(struct atmel_nand *nand, 1401 1401 int csline, 1402 - const struct nand_data_interface *conf) 1402 + const struct nand_interface_config *conf) 1403 1403 { 1404 1404 struct atmel_nand_controller *nc; 1405 1405 struct atmel_smc_cs_conf smcconf; ··· 1422 1422 return 0; 1423 1423 } 1424 1424 1425 - static int atmel_hsmc_nand_setup_data_interface(struct atmel_nand *nand, 1425 + static int atmel_hsmc_nand_setup_interface(struct atmel_nand *nand, 1426 1426 int csline, 1427 - const struct nand_data_interface *conf) 1427 + const struct nand_interface_config *conf) 1428 1428 { 1429 1429 struct atmel_hsmc_nand_controller *nc; 1430 1430 struct atmel_smc_cs_conf smcconf; ··· 1452 1452 return 0; 1453 1453 } 1454 1454 1455 - static int atmel_nand_setup_data_interface(struct nand_chip *chip, int csline, 1456 - const struct nand_data_interface *conf) 1455 + static int atmel_nand_setup_interface(struct nand_chip *chip, int csline, 1456 + const struct nand_interface_config *conf) 1457 1457 { 1458 1458 struct atmel_nand *nand = to_atmel_nand(chip); 1459 1459 struct atmel_nand_controller *nc; ··· 1464 1464 (csline < 0 && csline != NAND_DATA_IFACE_CHECK_ONLY)) 1465 1465 return -EINVAL; 1466 1466 1467 - return nc->caps->ops->setup_data_interface(nand, csline, conf); 1467 + return nc->caps->ops->setup_interface(nand, csline, conf); 1468 1468 } 1469 1469 1470 1470 static void atmel_nand_init(struct atmel_nand_controller *nc, ··· 1483 1483 chip->legacy.write_buf = atmel_nand_write_buf; 1484 1484 chip->legacy.select_chip = atmel_nand_select_chip; 1485 1485 1486 - if (!nc->mck || !nc->caps->ops->setup_data_interface) 1486 + if (!nc->mck || !nc->caps->ops->setup_interface) 1487 1487 chip->options |= NAND_KEEP_TIMINGS; 1488 1488 1489 1489 /* Some NANDs require a longer delay than the default one (20us). */ ··· 1956 1956 1957 1957 static const struct nand_controller_ops atmel_nand_controller_ops = { 1958 1958 .attach_chip = atmel_nand_attach_chip, 1959 - .setup_data_interface = atmel_nand_setup_data_interface, 1959 + .setup_interface = atmel_nand_setup_interface, 1960 1960 }; 1961 1961 1962 1962 static int atmel_nand_controller_init(struct atmel_nand_controller *nc, ··· 2318 2318 .remove = atmel_hsmc_nand_controller_remove, 2319 2319 .ecc_init = atmel_hsmc_nand_ecc_init, 2320 2320 .nand_init = atmel_hsmc_nand_init, 2321 - .setup_data_interface = atmel_hsmc_nand_setup_data_interface, 2321 + .setup_interface = atmel_hsmc_nand_setup_interface, 2322 2322 }; 2323 2323 2324 2324 static const struct atmel_nand_controller_caps atmel_sama5_nc_caps = { ··· 2375 2375 2376 2376 /* 2377 2377 * The SMC reg layout of at91rm9200 is completely different which prevents us 2378 - * from re-using atmel_smc_nand_setup_data_interface() for the 2379 - * ->setup_data_interface() hook. 2378 + * from re-using atmel_smc_nand_setup_interface() for the 2379 + * ->setup_interface() hook. 2380 2380 * At this point, there's no support for the at91rm9200 SMC IP, so we leave 2381 - * ->setup_data_interface() unassigned. 2381 + * ->setup_interface() unassigned. 2382 2382 */ 2383 2383 static const struct atmel_nand_controller_ops at91rm9200_nc_ops = { 2384 2384 .probe = atmel_smc_nand_controller_probe, ··· 2399 2399 .remove = atmel_smc_nand_controller_remove, 2400 2400 .ecc_init = atmel_nand_ecc_init, 2401 2401 .nand_init = atmel_smc_nand_init, 2402 - .setup_data_interface = atmel_smc_nand_setup_data_interface, 2402 + .setup_interface = atmel_smc_nand_setup_interface, 2403 2403 }; 2404 2404 2405 2405 static const struct atmel_nand_controller_caps atmel_sam9260_nc_caps = {
+29 -2
drivers/mtd/nand/raw/brcmnand/brcmnand.c
··· 1918 1918 edu_writel(ctrl, EDU_STOP, 0); /* force stop */ 1919 1919 edu_readl(ctrl, EDU_STOP); 1920 1920 1921 + if (!ret && edu_cmd == EDU_CMD_READ) { 1922 + u64 err_addr = 0; 1923 + 1924 + /* 1925 + * check for ECC errors here, subpage ECC errors are 1926 + * retained in ECC error address register 1927 + */ 1928 + err_addr = brcmnand_get_uncorrecc_addr(ctrl); 1929 + if (!err_addr) { 1930 + err_addr = brcmnand_get_correcc_addr(ctrl); 1931 + if (err_addr) 1932 + ret = -EUCLEAN; 1933 + } else 1934 + ret = -EBADMSG; 1935 + } 1936 + 1921 1937 return ret; 1922 1938 } 1923 1939 ··· 2140 2124 u64 err_addr = 0; 2141 2125 int err; 2142 2126 bool retry = true; 2127 + bool edu_err = false; 2143 2128 2144 2129 dev_dbg(ctrl->dev, "read %llx -> %p\n", (unsigned long long)addr, buf); 2145 2130 ··· 2158 2141 else 2159 2142 return -EIO; 2160 2143 } 2144 + 2145 + if (has_edu(ctrl) && err_addr) 2146 + edu_err = true; 2147 + 2161 2148 } else { 2162 2149 if (oob) 2163 2150 memset(oob, 0x99, mtd->oobsize); ··· 2208 2187 2209 2188 if (mtd_is_bitflip(err)) { 2210 2189 unsigned int corrected = brcmnand_count_corrected(ctrl); 2190 + 2191 + /* in case of EDU correctable error we read again using PIO */ 2192 + if (edu_err) 2193 + err = brcmnand_read_by_pio(mtd, chip, addr, trans, buf, 2194 + oob, &err_addr); 2211 2195 2212 2196 dev_dbg(ctrl->dev, "corrected error at 0x%llx\n", 2213 2197 (unsigned long long)err_addr); ··· 3049 3023 if (ret < 0) 3050 3024 goto err; 3051 3025 3052 - /* set edu transfer function to call */ 3053 - ctrl->dma_trans = brcmnand_edu_trans; 3026 + if (has_edu(ctrl)) 3027 + /* set edu transfer function to call */ 3028 + ctrl->dma_trans = brcmnand_edu_trans; 3054 3029 } 3055 3030 3056 3031 /* Disable automatic device ID config, direct addressing */
+3 -3
drivers/mtd/nand/raw/cadence-nand-controller.c
··· 2304 2304 } 2305 2305 2306 2306 static int 2307 - cadence_nand_setup_data_interface(struct nand_chip *chip, int chipnr, 2308 - const struct nand_data_interface *conf) 2307 + cadence_nand_setup_interface(struct nand_chip *chip, int chipnr, 2308 + const struct nand_interface_config *conf) 2309 2309 { 2310 2310 const struct nand_sdr_timings *sdr; 2311 2311 struct cdns_nand_ctrl *cdns_ctrl = to_cdns_nand_ctrl(chip->controller); ··· 2691 2691 static const struct nand_controller_ops cadence_nand_controller_ops = { 2692 2692 .attach_chip = cadence_nand_attach_chip, 2693 2693 .exec_op = cadence_nand_exec_op, 2694 - .setup_data_interface = cadence_nand_setup_data_interface, 2694 + .setup_interface = cadence_nand_setup_interface, 2695 2695 }; 2696 2696 2697 2697 static int cadence_nand_chip_init(struct cdns_nand_ctrl *cdns_ctrl,
+4 -4
drivers/mtd/nand/raw/denali.c
··· 761 761 return denali_page_xfer(chip, (void *)buf, mtd->writesize, page, true); 762 762 } 763 763 764 - static int denali_setup_data_interface(struct nand_chip *chip, int chipnr, 765 - const struct nand_data_interface *conf) 764 + static int denali_setup_interface(struct nand_chip *chip, int chipnr, 765 + const struct nand_interface_config *conf) 766 766 { 767 767 static const unsigned int data_setup_on_host = 10000; 768 768 struct denali_controller *denali = to_denali_controller(chip); ··· 1173 1173 static const struct nand_controller_ops denali_controller_ops = { 1174 1174 .attach_chip = denali_attach_chip, 1175 1175 .exec_op = denali_exec_op, 1176 - .setup_data_interface = denali_setup_data_interface, 1176 + .setup_interface = denali_setup_interface, 1177 1177 }; 1178 1178 1179 1179 int denali_chip_init(struct denali_controller *denali, ··· 1230 1230 chip->buf_align = 16; 1231 1231 } 1232 1232 1233 - /* clk rate info is needed for setup_data_interface */ 1233 + /* clk rate info is needed for setup_interface */ 1234 1234 if (!denali->clk_rate || !denali->clk_x_rate) 1235 1235 chip->options |= NAND_KEEP_TIMINGS; 1236 1236
+112 -199
drivers/mtd/nand/raw/fsl_upm.c
··· 14 14 #include <linux/mtd/nand_ecc.h> 15 15 #include <linux/mtd/partitions.h> 16 16 #include <linux/mtd/mtd.h> 17 - #include <linux/of_address.h> 18 17 #include <linux/of_platform.h> 19 - #include <linux/of_gpio.h> 20 18 #include <linux/io.h> 21 19 #include <linux/slab.h> 22 20 #include <asm/fsl_lbc.h> 23 21 24 - #define FSL_UPM_WAIT_RUN_PATTERN 0x1 25 - #define FSL_UPM_WAIT_WRITE_BYTE 0x2 26 - #define FSL_UPM_WAIT_WRITE_BUFFER 0x4 27 - 28 22 struct fsl_upm_nand { 23 + struct nand_controller base; 29 24 struct device *dev; 30 25 struct nand_chip chip; 31 - int last_ctrl; 32 - struct mtd_partition *parts; 33 26 struct fsl_upm upm; 34 27 uint8_t upm_addr_offset; 35 28 uint8_t upm_cmd_offset; 36 29 void __iomem *io_base; 37 - int rnb_gpio[NAND_MAX_CHIPS]; 30 + struct gpio_desc *rnb_gpio[NAND_MAX_CHIPS]; 38 31 uint32_t mchip_offsets[NAND_MAX_CHIPS]; 39 32 uint32_t mchip_count; 40 33 uint32_t mchip_number; 41 - int chip_delay; 42 - uint32_t wait_flags; 43 34 }; 44 35 45 36 static inline struct fsl_upm_nand *to_fsl_upm_nand(struct mtd_info *mtdinfo) 46 37 { 47 38 return container_of(mtd_to_nand(mtdinfo), struct fsl_upm_nand, 48 39 chip); 49 - } 50 - 51 - static int fun_chip_ready(struct nand_chip *chip) 52 - { 53 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 54 - 55 - if (gpio_get_value(fun->rnb_gpio[fun->mchip_number])) 56 - return 1; 57 - 58 - dev_vdbg(fun->dev, "busy\n"); 59 - return 0; 60 - } 61 - 62 - static void fun_wait_rnb(struct fsl_upm_nand *fun) 63 - { 64 - if (fun->rnb_gpio[fun->mchip_number] >= 0) { 65 - struct mtd_info *mtd = nand_to_mtd(&fun->chip); 66 - int cnt = 1000000; 67 - 68 - while (--cnt && !fun_chip_ready(&fun->chip)) 69 - cpu_relax(); 70 - if (!cnt) 71 - dev_err(fun->dev, "tired waiting for RNB\n"); 72 - } else { 73 - ndelay(100); 74 - } 75 - } 76 - 77 - static void fun_cmd_ctrl(struct nand_chip *chip, int cmd, unsigned int ctrl) 78 - { 79 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 80 - u32 mar; 81 - 82 - if (!(ctrl & fun->last_ctrl)) { 83 - fsl_upm_end_pattern(&fun->upm); 84 - 85 - if (cmd == NAND_CMD_NONE) 86 - return; 87 - 88 - fun->last_ctrl = ctrl & (NAND_ALE | NAND_CLE); 89 - } 90 - 91 - if (ctrl & NAND_CTRL_CHANGE) { 92 - if (ctrl & NAND_ALE) 93 - fsl_upm_start_pattern(&fun->upm, fun->upm_addr_offset); 94 - else if (ctrl & NAND_CLE) 95 - fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset); 96 - } 97 - 98 - mar = (cmd << (32 - fun->upm.width)) | 99 - fun->mchip_offsets[fun->mchip_number]; 100 - fsl_upm_run_pattern(&fun->upm, chip->legacy.IO_ADDR_R, mar); 101 - 102 - if (fun->wait_flags & FSL_UPM_WAIT_RUN_PATTERN) 103 - fun_wait_rnb(fun); 104 - } 105 - 106 - static void fun_select_chip(struct nand_chip *chip, int mchip_nr) 107 - { 108 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 109 - 110 - if (mchip_nr == -1) { 111 - chip->legacy.cmd_ctrl(chip, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); 112 - } else if (mchip_nr >= 0 && mchip_nr < NAND_MAX_CHIPS) { 113 - fun->mchip_number = mchip_nr; 114 - chip->legacy.IO_ADDR_R = fun->io_base + fun->mchip_offsets[mchip_nr]; 115 - chip->legacy.IO_ADDR_W = chip->legacy.IO_ADDR_R; 116 - } else { 117 - BUG(); 118 - } 119 - } 120 - 121 - static uint8_t fun_read_byte(struct nand_chip *chip) 122 - { 123 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 124 - 125 - return in_8(fun->chip.legacy.IO_ADDR_R); 126 - } 127 - 128 - static void fun_read_buf(struct nand_chip *chip, uint8_t *buf, int len) 129 - { 130 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 131 - int i; 132 - 133 - for (i = 0; i < len; i++) 134 - buf[i] = in_8(fun->chip.legacy.IO_ADDR_R); 135 - } 136 - 137 - static void fun_write_buf(struct nand_chip *chip, const uint8_t *buf, int len) 138 - { 139 - struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 140 - int i; 141 - 142 - for (i = 0; i < len; i++) { 143 - out_8(fun->chip.legacy.IO_ADDR_W, buf[i]); 144 - if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BYTE) 145 - fun_wait_rnb(fun); 146 - } 147 - if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BUFFER) 148 - fun_wait_rnb(fun); 149 40 } 150 41 151 42 static int fun_chip_init(struct fsl_upm_nand *fun, ··· 47 156 int ret; 48 157 struct device_node *flash_np; 49 158 50 - fun->chip.legacy.IO_ADDR_R = fun->io_base; 51 - fun->chip.legacy.IO_ADDR_W = fun->io_base; 52 - fun->chip.legacy.cmd_ctrl = fun_cmd_ctrl; 53 - fun->chip.legacy.chip_delay = fun->chip_delay; 54 - fun->chip.legacy.read_byte = fun_read_byte; 55 - fun->chip.legacy.read_buf = fun_read_buf; 56 - fun->chip.legacy.write_buf = fun_write_buf; 57 159 fun->chip.ecc.mode = NAND_ECC_SOFT; 58 160 fun->chip.ecc.algo = NAND_ECC_HAMMING; 59 - if (fun->mchip_count > 1) 60 - fun->chip.legacy.select_chip = fun_select_chip; 61 - 62 - if (fun->rnb_gpio[0] >= 0) 63 - fun->chip.legacy.dev_ready = fun_chip_ready; 64 - 161 + fun->chip.controller = &fun->base; 65 162 mtd->dev.parent = fun->dev; 66 163 67 164 flash_np = of_get_next_child(upm_np, NULL); ··· 57 178 return -ENODEV; 58 179 59 180 nand_set_flash_node(&fun->chip, flash_np); 60 - mtd->name = kasprintf(GFP_KERNEL, "0x%llx.%pOFn", (u64)io_res->start, 61 - flash_np); 181 + mtd->name = devm_kasprintf(fun->dev, GFP_KERNEL, "0x%llx.%pOFn", 182 + (u64)io_res->start, 183 + flash_np); 62 184 if (!mtd->name) { 63 185 ret = -ENOMEM; 64 186 goto err; ··· 72 192 ret = mtd_device_register(mtd, NULL, 0); 73 193 err: 74 194 of_node_put(flash_np); 75 - if (ret) 76 - kfree(mtd->name); 77 195 return ret; 78 196 } 197 + 198 + static int func_exec_instr(struct nand_chip *chip, 199 + const struct nand_op_instr *instr) 200 + { 201 + struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 202 + u32 mar, reg_offs = fun->mchip_offsets[fun->mchip_number]; 203 + unsigned int i; 204 + const u8 *out; 205 + u8 *in; 206 + 207 + switch (instr->type) { 208 + case NAND_OP_CMD_INSTR: 209 + fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset); 210 + mar = (instr->ctx.cmd.opcode << (32 - fun->upm.width)) | 211 + reg_offs; 212 + fsl_upm_run_pattern(&fun->upm, fun->io_base + reg_offs, mar); 213 + fsl_upm_end_pattern(&fun->upm); 214 + return 0; 215 + 216 + case NAND_OP_ADDR_INSTR: 217 + fsl_upm_start_pattern(&fun->upm, fun->upm_addr_offset); 218 + for (i = 0; i < instr->ctx.addr.naddrs; i++) { 219 + mar = (instr->ctx.addr.addrs[i] << (32 - fun->upm.width)) | 220 + reg_offs; 221 + fsl_upm_run_pattern(&fun->upm, fun->io_base + reg_offs, mar); 222 + } 223 + fsl_upm_end_pattern(&fun->upm); 224 + return 0; 225 + 226 + case NAND_OP_DATA_IN_INSTR: 227 + in = instr->ctx.data.buf.in; 228 + for (i = 0; i < instr->ctx.data.len; i++) 229 + in[i] = in_8(fun->io_base + reg_offs); 230 + return 0; 231 + 232 + case NAND_OP_DATA_OUT_INSTR: 233 + out = instr->ctx.data.buf.out; 234 + for (i = 0; i < instr->ctx.data.len; i++) 235 + out_8(fun->io_base + reg_offs, out[i]); 236 + return 0; 237 + 238 + case NAND_OP_WAITRDY_INSTR: 239 + if (!fun->rnb_gpio[fun->mchip_number]) 240 + return nand_soft_waitrdy(chip, instr->ctx.waitrdy.timeout_ms); 241 + 242 + return nand_gpio_waitrdy(chip, fun->rnb_gpio[fun->mchip_number], 243 + instr->ctx.waitrdy.timeout_ms); 244 + 245 + default: 246 + return -EINVAL; 247 + } 248 + 249 + return 0; 250 + } 251 + 252 + static int fun_exec_op(struct nand_chip *chip, const struct nand_operation *op, 253 + bool check_only) 254 + { 255 + struct fsl_upm_nand *fun = to_fsl_upm_nand(nand_to_mtd(chip)); 256 + unsigned int i; 257 + int ret; 258 + 259 + if (op->cs > NAND_MAX_CHIPS) 260 + return -EINVAL; 261 + 262 + if (check_only) 263 + return 0; 264 + 265 + fun->mchip_number = op->cs; 266 + 267 + for (i = 0; i < op->ninstrs; i++) { 268 + ret = func_exec_instr(chip, &op->instrs[i]); 269 + if (ret) 270 + return ret; 271 + 272 + if (op->instrs[i].delay_ns) 273 + ndelay(op->instrs[i].delay_ns); 274 + } 275 + 276 + return 0; 277 + } 278 + 279 + static const struct nand_controller_ops fun_ops = { 280 + .exec_op = fun_exec_op, 281 + }; 79 282 80 283 static int fun_probe(struct platform_device *ofdev) 81 284 { 82 285 struct fsl_upm_nand *fun; 83 - struct resource io_res; 286 + struct resource *io_res; 84 287 const __be32 *prop; 85 - int rnb_gpio; 86 288 int ret; 87 289 int size; 88 290 int i; 89 291 90 - fun = kzalloc(sizeof(*fun), GFP_KERNEL); 292 + fun = devm_kzalloc(&ofdev->dev, sizeof(*fun), GFP_KERNEL); 91 293 if (!fun) 92 294 return -ENOMEM; 93 295 94 - ret = of_address_to_resource(ofdev->dev.of_node, 0, &io_res); 95 - if (ret) { 96 - dev_err(&ofdev->dev, "can't get IO base\n"); 97 - goto err1; 98 - } 296 + io_res = platform_get_resource(ofdev, IORESOURCE_MEM, 0); 297 + fun->io_base = devm_ioremap_resource(&ofdev->dev, io_res); 298 + if (IS_ERR(fun->io_base)) 299 + return PTR_ERR(fun->io_base); 99 300 100 - ret = fsl_upm_find(io_res.start, &fun->upm); 301 + ret = fsl_upm_find(io_res->start, &fun->upm); 101 302 if (ret) { 102 303 dev_err(&ofdev->dev, "can't find UPM\n"); 103 - goto err1; 304 + return ret; 104 305 } 105 306 106 307 prop = of_get_property(ofdev->dev.of_node, "fsl,upm-addr-offset", 107 308 &size); 108 309 if (!prop || size != sizeof(uint32_t)) { 109 310 dev_err(&ofdev->dev, "can't get UPM address offset\n"); 110 - ret = -EINVAL; 111 - goto err1; 311 + return -EINVAL; 112 312 } 113 313 fun->upm_addr_offset = *prop; 114 314 115 315 prop = of_get_property(ofdev->dev.of_node, "fsl,upm-cmd-offset", &size); 116 316 if (!prop || size != sizeof(uint32_t)) { 117 317 dev_err(&ofdev->dev, "can't get UPM command offset\n"); 118 - ret = -EINVAL; 119 - goto err1; 318 + return -EINVAL; 120 319 } 121 320 fun->upm_cmd_offset = *prop; 122 321 ··· 205 246 fun->mchip_count = size / sizeof(uint32_t); 206 247 if (fun->mchip_count >= NAND_MAX_CHIPS) { 207 248 dev_err(&ofdev->dev, "too much multiple chips\n"); 208 - goto err1; 249 + return -EINVAL; 209 250 } 210 251 for (i = 0; i < fun->mchip_count; i++) 211 252 fun->mchip_offsets[i] = be32_to_cpu(prop[i]); ··· 214 255 } 215 256 216 257 for (i = 0; i < fun->mchip_count; i++) { 217 - fun->rnb_gpio[i] = -1; 218 - rnb_gpio = of_get_gpio(ofdev->dev.of_node, i); 219 - if (rnb_gpio >= 0) { 220 - ret = gpio_request(rnb_gpio, dev_name(&ofdev->dev)); 221 - if (ret) { 222 - dev_err(&ofdev->dev, 223 - "can't request RNB gpio #%d\n", i); 224 - goto err2; 225 - } 226 - gpio_direction_input(rnb_gpio); 227 - fun->rnb_gpio[i] = rnb_gpio; 228 - } else if (rnb_gpio == -EINVAL) { 258 + fun->rnb_gpio[i] = devm_gpiod_get_index_optional(&ofdev->dev, 259 + NULL, i, 260 + GPIOD_IN); 261 + if (IS_ERR(fun->rnb_gpio[i])) { 229 262 dev_err(&ofdev->dev, "RNB gpio #%d is invalid\n", i); 230 - goto err2; 263 + return PTR_ERR(fun->rnb_gpio[i]); 231 264 } 232 265 } 233 266 234 - prop = of_get_property(ofdev->dev.of_node, "chip-delay", NULL); 235 - if (prop) 236 - fun->chip_delay = be32_to_cpup(prop); 237 - else 238 - fun->chip_delay = 50; 239 - 240 - prop = of_get_property(ofdev->dev.of_node, "fsl,upm-wait-flags", &size); 241 - if (prop && size == sizeof(uint32_t)) 242 - fun->wait_flags = be32_to_cpup(prop); 243 - else 244 - fun->wait_flags = FSL_UPM_WAIT_RUN_PATTERN | 245 - FSL_UPM_WAIT_WRITE_BYTE; 246 - 247 - fun->io_base = devm_ioremap(&ofdev->dev, io_res.start, 248 - resource_size(&io_res)); 249 - if (!fun->io_base) { 250 - ret = -ENOMEM; 251 - goto err2; 252 - } 253 - 267 + nand_controller_init(&fun->base); 268 + fun->base.ops = &fun_ops; 254 269 fun->dev = &ofdev->dev; 255 - fun->last_ctrl = NAND_CLE; 256 270 257 - ret = fun_chip_init(fun, ofdev->dev.of_node, &io_res); 271 + ret = fun_chip_init(fun, ofdev->dev.of_node, io_res); 258 272 if (ret) 259 - goto err2; 273 + return ret; 260 274 261 275 dev_set_drvdata(&ofdev->dev, fun); 262 276 263 277 return 0; 264 - err2: 265 - for (i = 0; i < fun->mchip_count; i++) { 266 - if (fun->rnb_gpio[i] < 0) 267 - break; 268 - gpio_free(fun->rnb_gpio[i]); 269 - } 270 - err1: 271 - kfree(fun); 272 - 273 - return ret; 274 278 } 275 279 276 280 static int fun_remove(struct platform_device *ofdev) ··· 241 319 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); 242 320 struct nand_chip *chip = &fun->chip; 243 321 struct mtd_info *mtd = nand_to_mtd(chip); 244 - int ret, i; 322 + int ret; 245 323 246 324 ret = mtd_device_unregister(mtd); 247 325 WARN_ON(ret); 248 326 nand_cleanup(chip); 249 - kfree(mtd->name); 250 - 251 - for (i = 0; i < fun->mchip_count; i++) { 252 - if (fun->rnb_gpio[i] < 0) 253 - break; 254 - gpio_free(fun->rnb_gpio[i]); 255 - } 256 - 257 - kfree(fun); 258 327 259 328 return 0; 260 329 }
+3 -3
drivers/mtd/nand/raw/fsmc_nand.c
··· 327 327 return 0; 328 328 } 329 329 330 - static int fsmc_setup_data_interface(struct nand_chip *nand, int csline, 331 - const struct nand_data_interface *conf) 330 + static int fsmc_setup_interface(struct nand_chip *nand, int csline, 331 + const struct nand_interface_config *conf) 332 332 { 333 333 struct fsmc_nand_data *host = nand_to_fsmc(nand); 334 334 struct fsmc_nand_timings tims; ··· 951 951 static const struct nand_controller_ops fsmc_nand_controller_ops = { 952 952 .attach_chip = fsmc_nand_attach_chip, 953 953 .exec_op = fsmc_exec_op, 954 - .setup_data_interface = fsmc_setup_data_interface, 954 + .setup_interface = fsmc_setup_interface, 955 955 }; 956 956 957 957 /**
+91 -25
drivers/mtd/nand/raw/gpio.c
··· 25 25 #include <linux/mtd/nand-gpio.h> 26 26 #include <linux/of.h> 27 27 #include <linux/of_address.h> 28 + #include <linux/delay.h> 28 29 29 30 struct gpiomtd { 31 + struct nand_controller base; 32 + void __iomem *io; 30 33 void __iomem *io_sync; 31 34 struct nand_chip nand_chip; 32 35 struct gpio_nand_platdata plat; ··· 72 69 static inline void gpio_nand_dosync(struct gpiomtd *gpiomtd) {} 73 70 #endif 74 71 75 - static void gpio_nand_cmd_ctrl(struct nand_chip *chip, int cmd, 76 - unsigned int ctrl) 72 + static int gpio_nand_exec_instr(struct nand_chip *chip, 73 + const struct nand_op_instr *instr) 77 74 { 78 75 struct gpiomtd *gpiomtd = gpio_nand_getpriv(nand_to_mtd(chip)); 76 + unsigned int i; 79 77 80 - gpio_nand_dosync(gpiomtd); 81 - 82 - if (ctrl & NAND_CTRL_CHANGE) { 83 - if (gpiomtd->nce) 84 - gpiod_set_value(gpiomtd->nce, !(ctrl & NAND_NCE)); 85 - gpiod_set_value(gpiomtd->cle, !!(ctrl & NAND_CLE)); 86 - gpiod_set_value(gpiomtd->ale, !!(ctrl & NAND_ALE)); 78 + switch (instr->type) { 79 + case NAND_OP_CMD_INSTR: 87 80 gpio_nand_dosync(gpiomtd); 88 - } 89 - if (cmd == NAND_CMD_NONE) 90 - return; 81 + gpiod_set_value(gpiomtd->cle, 1); 82 + gpio_nand_dosync(gpiomtd); 83 + writeb(instr->ctx.cmd.opcode, gpiomtd->io); 84 + gpio_nand_dosync(gpiomtd); 85 + gpiod_set_value(gpiomtd->cle, 0); 86 + return 0; 91 87 92 - writeb(cmd, gpiomtd->nand_chip.legacy.IO_ADDR_W); 93 - gpio_nand_dosync(gpiomtd); 88 + case NAND_OP_ADDR_INSTR: 89 + gpio_nand_dosync(gpiomtd); 90 + gpiod_set_value(gpiomtd->ale, 1); 91 + gpio_nand_dosync(gpiomtd); 92 + for (i = 0; i < instr->ctx.addr.naddrs; i++) 93 + writeb(instr->ctx.addr.addrs[i], gpiomtd->io); 94 + gpio_nand_dosync(gpiomtd); 95 + gpiod_set_value(gpiomtd->ale, 0); 96 + return 0; 97 + 98 + case NAND_OP_DATA_IN_INSTR: 99 + gpio_nand_dosync(gpiomtd); 100 + if ((chip->options & NAND_BUSWIDTH_16) && 101 + !instr->ctx.data.force_8bit) 102 + ioread16_rep(gpiomtd->io, instr->ctx.data.buf.in, 103 + instr->ctx.data.len / 2); 104 + else 105 + ioread8_rep(gpiomtd->io, instr->ctx.data.buf.in, 106 + instr->ctx.data.len); 107 + return 0; 108 + 109 + case NAND_OP_DATA_OUT_INSTR: 110 + gpio_nand_dosync(gpiomtd); 111 + if ((chip->options & NAND_BUSWIDTH_16) && 112 + !instr->ctx.data.force_8bit) 113 + iowrite16_rep(gpiomtd->io, instr->ctx.data.buf.out, 114 + instr->ctx.data.len / 2); 115 + else 116 + iowrite8_rep(gpiomtd->io, instr->ctx.data.buf.out, 117 + instr->ctx.data.len); 118 + return 0; 119 + 120 + case NAND_OP_WAITRDY_INSTR: 121 + if (!gpiomtd->rdy) 122 + return nand_soft_waitrdy(chip, instr->ctx.waitrdy.timeout_ms); 123 + 124 + return nand_gpio_waitrdy(chip, gpiomtd->rdy, 125 + instr->ctx.waitrdy.timeout_ms); 126 + 127 + default: 128 + return -EINVAL; 129 + } 130 + 131 + return 0; 94 132 } 95 133 96 - static int gpio_nand_devready(struct nand_chip *chip) 134 + static int gpio_nand_exec_op(struct nand_chip *chip, 135 + const struct nand_operation *op, 136 + bool check_only) 97 137 { 98 138 struct gpiomtd *gpiomtd = gpio_nand_getpriv(nand_to_mtd(chip)); 139 + unsigned int i; 140 + int ret = 0; 99 141 100 - return gpiod_get_value(gpiomtd->rdy); 142 + if (check_only) 143 + return 0; 144 + 145 + gpio_nand_dosync(gpiomtd); 146 + gpiod_set_value(gpiomtd->nce, 0); 147 + for (i = 0; i < op->ninstrs; i++) { 148 + ret = gpio_nand_exec_instr(chip, &op->instrs[i]); 149 + if (ret) 150 + break; 151 + 152 + if (op->instrs[i].delay_ns) 153 + ndelay(op->instrs[i].delay_ns); 154 + } 155 + gpio_nand_dosync(gpiomtd); 156 + gpiod_set_value(gpiomtd->nce, 1); 157 + 158 + return ret; 101 159 } 160 + 161 + static const struct nand_controller_ops gpio_nand_ops = { 162 + .exec_op = gpio_nand_exec_op, 163 + }; 102 164 103 165 #ifdef CONFIG_OF 104 166 static const struct of_device_id gpio_nand_id_table[] = { ··· 293 225 chip = &gpiomtd->nand_chip; 294 226 295 227 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 296 - chip->legacy.IO_ADDR_R = devm_ioremap_resource(dev, res); 297 - if (IS_ERR(chip->legacy.IO_ADDR_R)) 298 - return PTR_ERR(chip->legacy.IO_ADDR_R); 228 + gpiomtd->io = devm_ioremap_resource(dev, res); 229 + if (IS_ERR(gpiomtd->io)) 230 + return PTR_ERR(gpiomtd->io); 299 231 300 232 res = gpio_nand_get_io_sync(pdev); 301 233 if (res) { ··· 337 269 ret = PTR_ERR(gpiomtd->rdy); 338 270 goto out_ce; 339 271 } 340 - /* Using RDY pin */ 341 - if (gpiomtd->rdy) 342 - chip->legacy.dev_ready = gpio_nand_devready; 272 + 273 + nand_controller_init(&gpiomtd->base); 274 + gpiomtd->base.ops = &gpio_nand_ops; 343 275 344 276 nand_set_flash_node(chip, pdev->dev.of_node); 345 - chip->legacy.IO_ADDR_W = chip->legacy.IO_ADDR_R; 346 277 chip->ecc.mode = NAND_ECC_SOFT; 347 278 chip->ecc.algo = NAND_ECC_HAMMING; 348 279 chip->options = gpiomtd->plat.options; 349 - chip->legacy.chip_delay = gpiomtd->plat.chip_delay; 350 - chip->legacy.cmd_ctrl = gpio_nand_cmd_ctrl; 280 + chip->controller = &gpiomtd->base; 351 281 352 282 mtd = nand_to_mtd(chip); 353 283 mtd->dev.parent = dev;
+3 -3
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
··· 736 736 udelay(dll_wait_time_us); 737 737 } 738 738 739 - static int gpmi_setup_data_interface(struct nand_chip *chip, int chipnr, 740 - const struct nand_data_interface *conf) 739 + static int gpmi_setup_interface(struct nand_chip *chip, int chipnr, 740 + const struct nand_interface_config *conf) 741 741 { 742 742 struct gpmi_nand_data *this = nand_get_controller_data(chip); 743 743 const struct nand_sdr_timings *sdr; ··· 2400 2400 2401 2401 static const struct nand_controller_ops gpmi_nand_controller_ops = { 2402 2402 .attach_chip = gpmi_nand_attach_chip, 2403 - .setup_data_interface = gpmi_setup_data_interface, 2403 + .setup_interface = gpmi_setup_interface, 2404 2404 .exec_op = gpmi_nfc_exec_op, 2405 2405 }; 2406 2406
+2 -2
drivers/mtd/nand/raw/ingenic/jz4740_ecc.c
··· 90 90 * If the written data is completely 0xff, we also want to write 0xff as 91 91 * ECC, otherwise we will get in trouble when doing subpage writes. 92 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)); 93 + if (memcmp(ecc_code, empty_block_ecc, sizeof(empty_block_ecc)) == 0) 94 + memset(ecc_code, 0xff, sizeof(empty_block_ecc)); 95 95 96 96 return 0; 97 97 }
+15 -8
drivers/mtd/nand/raw/internals.h
··· 53 53 }; 54 54 55 55 /** 56 - * struct nand_manufacturer - NAND Flash Manufacturer structure 56 + * struct nand_manufacturer_desc - NAND Flash Manufacturer descriptor 57 57 * @name: Manufacturer name 58 58 * @id: manufacturer ID code of device. 59 59 * @ops: manufacturer operations 60 60 */ 61 - struct nand_manufacturer { 61 + struct nand_manufacturer_desc { 62 62 int id; 63 63 char *name; 64 64 const struct nand_manufacturer_ops *ops; ··· 79 79 extern const struct mtd_pairing_scheme dist3_pairing_scheme; 80 80 81 81 /* Core functions */ 82 - const struct nand_manufacturer *nand_get_manufacturer(u8 id); 82 + const struct nand_manufacturer_desc *nand_get_manufacturer_desc(u8 id); 83 83 int nand_bbm_get_next_page(struct nand_chip *chip, int page); 84 84 int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs); 85 85 int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, 86 86 int allowbbt); 87 - int onfi_fill_data_interface(struct nand_chip *chip, 88 - enum nand_data_interface_type type, 89 - int timing_mode); 87 + void onfi_fill_interface_config(struct nand_chip *chip, 88 + struct nand_interface_config *iface, 89 + enum nand_interface_type type, 90 + unsigned int timing_mode); 91 + unsigned int 92 + onfi_find_closest_sdr_mode(const struct nand_sdr_timings *spec_timings); 93 + int nand_choose_best_sdr_timings(struct nand_chip *chip, 94 + struct nand_interface_config *iface, 95 + struct nand_sdr_timings *spec_timings); 96 + const struct nand_interface_config *nand_get_reset_interface_config(void); 90 97 int nand_get_features(struct nand_chip *chip, int addr, u8 *subfeature_param); 91 98 int nand_set_features(struct nand_chip *chip, int addr, u8 *subfeature_param); 92 99 int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf, ··· 137 130 return chip->controller->ops->exec_op(chip, op, false); 138 131 } 139 132 140 - static inline bool nand_has_setup_data_iface(struct nand_chip *chip) 133 + static inline bool nand_controller_can_setup_interface(struct nand_chip *chip) 141 134 { 142 135 if (!chip->controller || !chip->controller->ops || 143 - !chip->controller->ops->setup_data_interface) 136 + !chip->controller->ops->setup_interface) 144 137 return false; 145 138 146 139 if (chip->options & NAND_KEEP_TIMINGS)
+10 -8
drivers/mtd/nand/raw/marvell_nand.c
··· 1096 1096 const u8 *oob_buf, bool raw, 1097 1097 int page) 1098 1098 { 1099 + const struct nand_sdr_timings *sdr = 1100 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1099 1101 struct marvell_nand_chip *marvell_nand = to_marvell_nand(chip); 1100 1102 struct marvell_nfc *nfc = to_marvell_nfc(chip->controller); 1101 1103 const struct marvell_hw_ecc_layout *lt = to_marvell_nand(chip)->layout; ··· 1143 1141 return ret; 1144 1142 1145 1143 ret = marvell_nfc_wait_op(chip, 1146 - PSEC_TO_MSEC(chip->data_interface.timings.sdr.tPROG_max)); 1144 + PSEC_TO_MSEC(sdr->tPROG_max)); 1147 1145 return ret; 1148 1146 } 1149 1147 ··· 1564 1562 const u8 *buf, 1565 1563 int oob_required, int page) 1566 1564 { 1565 + const struct nand_sdr_timings *sdr = 1566 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1567 1567 struct mtd_info *mtd = nand_to_mtd(chip); 1568 1568 const struct marvell_hw_ecc_layout *lt = to_marvell_nand(chip)->layout; 1569 1569 const u8 *data = buf; ··· 1602 1598 marvell_nfc_wait_ndrun(chip); 1603 1599 } 1604 1600 1605 - ret = marvell_nfc_wait_op(chip, 1606 - PSEC_TO_MSEC(chip->data_interface.timings.sdr.tPROG_max)); 1601 + ret = marvell_nfc_wait_op(chip, PSEC_TO_MSEC(sdr->tPROG_max)); 1607 1602 1608 1603 marvell_nfc_disable_hw_ecc(chip); 1609 1604 ··· 2308 2305 .pattern = bbt_mirror_pattern 2309 2306 }; 2310 2307 2311 - static int marvell_nfc_setup_data_interface(struct nand_chip *chip, int chipnr, 2312 - const struct nand_data_interface 2313 - *conf) 2308 + static int marvell_nfc_setup_interface(struct nand_chip *chip, int chipnr, 2309 + const struct nand_interface_config *conf) 2314 2310 { 2315 2311 struct marvell_nand_chip *marvell_nand = to_marvell_nand(chip); 2316 2312 struct marvell_nfc *nfc = to_marvell_nfc(chip->controller); ··· 2510 2508 static const struct nand_controller_ops marvell_nand_controller_ops = { 2511 2509 .attach_chip = marvell_nand_attach_chip, 2512 2510 .exec_op = marvell_nfc_exec_op, 2513 - .setup_data_interface = marvell_nfc_setup_data_interface, 2511 + .setup_interface = marvell_nfc_setup_interface, 2514 2512 }; 2515 2513 2516 2514 static int marvell_nand_chip_init(struct device *dev, struct marvell_nfc *nfc, ··· 2646 2644 2647 2645 /* 2648 2646 * Save a reference value for timing registers before 2649 - * ->setup_data_interface() is called. 2647 + * ->setup_interface() is called. 2650 2648 */ 2651 2649 marvell_nand->ndtr0 = readl_relaxed(nfc->regs + NDTR0); 2652 2650 marvell_nand->ndtr1 = readl_relaxed(nfc->regs + NDTR1);
+7 -7
drivers/mtd/nand/raw/meson_nand.c
··· 573 573 static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, 574 574 int page, bool in) 575 575 { 576 + const struct nand_sdr_timings *sdr = 577 + nand_get_sdr_timings(nand_get_interface_config(nand)); 576 578 struct mtd_info *mtd = nand_to_mtd(nand); 577 579 struct meson_nfc *nfc = nand_get_controller_data(nand); 578 - const struct nand_sdr_timings *sdr = 579 - nand_get_sdr_timings(&nand->data_interface); 580 580 u32 *addrs = nfc->cmdfifo.rw.addrs; 581 581 u32 cs = nfc->param.chip_select; 582 582 u32 cmd0, cmd_num, row_start; ··· 626 626 static int meson_nfc_write_page_sub(struct nand_chip *nand, 627 627 int page, int raw) 628 628 { 629 - struct mtd_info *mtd = nand_to_mtd(nand); 630 629 const struct nand_sdr_timings *sdr = 631 - nand_get_sdr_timings(&nand->data_interface); 630 + nand_get_sdr_timings(nand_get_interface_config(nand)); 631 + struct mtd_info *mtd = nand_to_mtd(nand); 632 632 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); 633 633 struct meson_nfc *nfc = nand_get_controller_data(nand); 634 634 int data_len, info_len; ··· 1097 1097 } 1098 1098 1099 1099 static 1100 - int meson_nfc_setup_data_interface(struct nand_chip *nand, int csline, 1101 - const struct nand_data_interface *conf) 1100 + int meson_nfc_setup_interface(struct nand_chip *nand, int csline, 1101 + const struct nand_interface_config *conf) 1102 1102 { 1103 1103 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); 1104 1104 const struct nand_sdr_timings *timings; ··· 1222 1222 static const struct nand_controller_ops meson_nand_controller_ops = { 1223 1223 .attach_chip = meson_nand_attach_chip, 1224 1224 .detach_chip = meson_nand_detach_chip, 1225 - .setup_data_interface = meson_nfc_setup_data_interface, 1225 + .setup_interface = meson_nfc_setup_interface, 1226 1226 .exec_op = meson_nfc_exec_op, 1227 1227 }; 1228 1228
+74 -48
drivers/mtd/nand/raw/mtk_nand.c
··· 387 387 return 0; 388 388 } 389 389 390 - static void mtk_nfc_select_chip(struct nand_chip *nand, int chip) 391 - { 392 - struct mtk_nfc *nfc = nand_get_controller_data(nand); 393 - struct mtk_nfc_nand_chip *mtk_nand = to_mtk_nand(nand); 394 - 395 - if (chip < 0) 396 - return; 397 - 398 - mtk_nfc_hw_runtime_config(nand_to_mtd(nand)); 399 - 400 - nfi_writel(nfc, mtk_nand->sels[chip], NFI_CSEL); 401 - } 402 - 403 - static int mtk_nfc_dev_ready(struct nand_chip *nand) 404 - { 405 - struct mtk_nfc *nfc = nand_get_controller_data(nand); 406 - 407 - if (nfi_readl(nfc, NFI_STA) & STA_BUSY) 408 - return 0; 409 - 410 - return 1; 411 - } 412 - 413 - static void mtk_nfc_cmd_ctrl(struct nand_chip *chip, int dat, 414 - unsigned int ctrl) 415 - { 416 - struct mtk_nfc *nfc = nand_get_controller_data(chip); 417 - 418 - if (ctrl & NAND_ALE) { 419 - mtk_nfc_send_address(nfc, dat); 420 - } else if (ctrl & NAND_CLE) { 421 - mtk_nfc_hw_reset(nfc); 422 - 423 - nfi_writew(nfc, CNFG_OP_CUST, NFI_CNFG); 424 - mtk_nfc_send_command(nfc, dat); 425 - } 426 - } 427 - 428 390 static inline void mtk_nfc_wait_ioready(struct mtk_nfc *nfc) 429 391 { 430 392 int rc; ··· 463 501 mtk_nfc_write_byte(chip, buf[i]); 464 502 } 465 503 466 - static int mtk_nfc_setup_data_interface(struct nand_chip *chip, int csline, 467 - const struct nand_data_interface *conf) 504 + static int mtk_nfc_exec_instr(struct nand_chip *chip, 505 + const struct nand_op_instr *instr) 506 + { 507 + struct mtk_nfc *nfc = nand_get_controller_data(chip); 508 + unsigned int i; 509 + u32 status; 510 + 511 + switch (instr->type) { 512 + case NAND_OP_CMD_INSTR: 513 + mtk_nfc_send_command(nfc, instr->ctx.cmd.opcode); 514 + return 0; 515 + case NAND_OP_ADDR_INSTR: 516 + for (i = 0; i < instr->ctx.addr.naddrs; i++) 517 + mtk_nfc_send_address(nfc, instr->ctx.addr.addrs[i]); 518 + return 0; 519 + case NAND_OP_DATA_IN_INSTR: 520 + mtk_nfc_read_buf(chip, instr->ctx.data.buf.in, 521 + instr->ctx.data.len); 522 + return 0; 523 + case NAND_OP_DATA_OUT_INSTR: 524 + mtk_nfc_write_buf(chip, instr->ctx.data.buf.out, 525 + instr->ctx.data.len); 526 + return 0; 527 + case NAND_OP_WAITRDY_INSTR: 528 + return readl_poll_timeout(nfc->regs + NFI_STA, status, 529 + status & STA_BUSY, 20, 530 + instr->ctx.waitrdy.timeout_ms); 531 + default: 532 + break; 533 + } 534 + 535 + return -EINVAL; 536 + } 537 + 538 + static void mtk_nfc_select_target(struct nand_chip *nand, unsigned int cs) 539 + { 540 + struct mtk_nfc *nfc = nand_get_controller_data(nand); 541 + struct mtk_nfc_nand_chip *mtk_nand = to_mtk_nand(nand); 542 + 543 + mtk_nfc_hw_runtime_config(nand_to_mtd(nand)); 544 + 545 + nfi_writel(nfc, mtk_nand->sels[cs], NFI_CSEL); 546 + } 547 + 548 + static int mtk_nfc_exec_op(struct nand_chip *chip, 549 + const struct nand_operation *op, 550 + bool check_only) 551 + { 552 + struct mtk_nfc *nfc = nand_get_controller_data(chip); 553 + unsigned int i; 554 + int ret = 0; 555 + 556 + if (check_only) 557 + return 0; 558 + 559 + mtk_nfc_hw_reset(nfc); 560 + nfi_writew(nfc, CNFG_OP_CUST, NFI_CNFG); 561 + mtk_nfc_select_target(chip, op->cs); 562 + 563 + for (i = 0; i < op->ninstrs; i++) { 564 + ret = mtk_nfc_exec_instr(chip, &op->instrs[i]); 565 + if (ret) 566 + break; 567 + } 568 + 569 + return ret; 570 + } 571 + 572 + static int mtk_nfc_setup_interface(struct nand_chip *chip, int csline, 573 + const struct nand_interface_config *conf) 468 574 { 469 575 struct mtk_nfc *nfc = nand_get_controller_data(chip); 470 576 const struct nand_sdr_timings *timings; ··· 833 803 u32 reg; 834 804 int ret; 835 805 806 + mtk_nfc_select_target(chip, chip->cur_cs); 836 807 nand_prog_page_begin_op(chip, page, 0, NULL, 0); 837 808 838 809 if (!raw) { ··· 951 920 u8 *buf; 952 921 int rc; 953 922 923 + mtk_nfc_select_target(chip, chip->cur_cs); 954 924 start = data_offs / chip->ecc.size; 955 925 end = DIV_ROUND_UP(data_offs + readlen, chip->ecc.size); 956 926 ··· 1357 1325 1358 1326 static const struct nand_controller_ops mtk_nfc_controller_ops = { 1359 1327 .attach_chip = mtk_nfc_attach_chip, 1360 - .setup_data_interface = mtk_nfc_setup_data_interface, 1328 + .setup_interface = mtk_nfc_setup_interface, 1329 + .exec_op = mtk_nfc_exec_op, 1361 1330 }; 1362 1331 1363 1332 static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, ··· 1414 1381 nand_set_controller_data(nand, nfc); 1415 1382 1416 1383 nand->options |= NAND_USES_DMA | NAND_SUBPAGE_READ; 1417 - nand->legacy.dev_ready = mtk_nfc_dev_ready; 1418 - nand->legacy.select_chip = mtk_nfc_select_chip; 1419 - nand->legacy.write_byte = mtk_nfc_write_byte; 1420 - nand->legacy.write_buf = mtk_nfc_write_buf; 1421 - nand->legacy.read_byte = mtk_nfc_read_byte; 1422 - nand->legacy.read_buf = mtk_nfc_read_buf; 1423 - nand->legacy.cmd_ctrl = mtk_nfc_cmd_ctrl; 1424 1384 1425 1385 /* set default mode in case dt entry is missing */ 1426 1386 nand->ecc.mode = NAND_ECC_HW;
+11 -11
drivers/mtd/nand/raw/mxc_nand.c
··· 137 137 u32 (*get_ecc_status)(struct mxc_nand_host *); 138 138 const struct mtd_ooblayout_ops *ooblayout; 139 139 void (*select_chip)(struct nand_chip *chip, int cs); 140 - int (*setup_data_interface)(struct nand_chip *chip, int csline, 141 - const struct nand_data_interface *conf); 140 + int (*setup_interface)(struct nand_chip *chip, int csline, 141 + const struct nand_interface_config *conf); 142 142 void (*enable_hwecc)(struct nand_chip *chip, bool enable); 143 143 144 144 /* ··· 1139 1139 writew(0x4, NFC_V1_V2_WRPROT); 1140 1140 } 1141 1141 1142 - static int mxc_nand_v2_setup_data_interface(struct nand_chip *chip, int csline, 1143 - const struct nand_data_interface *conf) 1142 + static int mxc_nand_v2_setup_interface(struct nand_chip *chip, int csline, 1143 + const struct nand_interface_config *conf) 1144 1144 { 1145 1145 struct mxc_nand_host *host = nand_get_controller_data(chip); 1146 1146 int tRC_min_ns, tRC_ps, ret; ··· 1432 1432 } 1433 1433 1434 1434 /* 1435 - * The generic flash bbt decriptors overlap with our ecc 1435 + * The generic flash bbt descriptors overlap with our ecc 1436 1436 * hardware, so define some i.MX specific ones. 1437 1437 */ 1438 1438 static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' }; ··· 1521 1521 .get_ecc_status = get_ecc_status_v2, 1522 1522 .ooblayout = &mxc_v2_ooblayout_ops, 1523 1523 .select_chip = mxc_nand_select_chip_v2, 1524 - .setup_data_interface = mxc_nand_v2_setup_data_interface, 1524 + .setup_interface = mxc_nand_v2_setup_interface, 1525 1525 .enable_hwecc = mxc_nand_enable_hwecc_v1_v2, 1526 1526 .irqpending_quirk = 0, 1527 1527 .needs_ip = 0, ··· 1738 1738 return 0; 1739 1739 } 1740 1740 1741 - static int mxcnd_setup_data_interface(struct nand_chip *chip, int chipnr, 1742 - const struct nand_data_interface *conf) 1741 + static int mxcnd_setup_interface(struct nand_chip *chip, int chipnr, 1742 + const struct nand_interface_config *conf) 1743 1743 { 1744 1744 struct mxc_nand_host *host = nand_get_controller_data(chip); 1745 1745 1746 - return host->devtype_data->setup_data_interface(chip, chipnr, conf); 1746 + return host->devtype_data->setup_interface(chip, chipnr, conf); 1747 1747 } 1748 1748 1749 1749 static const struct nand_controller_ops mxcnd_controller_ops = { 1750 1750 .attach_chip = mxcnd_attach_chip, 1751 - .setup_data_interface = mxcnd_setup_data_interface, 1751 + .setup_interface = mxcnd_setup_interface, 1752 1752 }; 1753 1753 1754 1754 static int mxcnd_probe(struct platform_device *pdev) ··· 1809 1809 if (err < 0) 1810 1810 return err; 1811 1811 1812 - if (!host->devtype_data->setup_data_interface) 1812 + if (!host->devtype_data->setup_interface) 1813 1813 this->options |= NAND_KEEP_TIMINGS; 1814 1814 1815 1815 if (host->devtype_data->needs_ip) {
+3 -3
drivers/mtd/nand/raw/mxic_nand.c
··· 451 451 return ret; 452 452 } 453 453 454 - static int mxic_nfc_setup_data_interface(struct nand_chip *chip, int chipnr, 455 - const struct nand_data_interface *conf) 454 + static int mxic_nfc_setup_interface(struct nand_chip *chip, int chipnr, 455 + const struct nand_interface_config *conf) 456 456 { 457 457 struct mxic_nand_ctlr *nfc = nand_get_controller_data(chip); 458 458 const struct nand_sdr_timings *sdr; ··· 480 480 481 481 static const struct nand_controller_ops mxic_nand_controller_ops = { 482 482 .exec_op = mxic_nfc_exec_op, 483 - .setup_data_interface = mxic_nfc_setup_data_interface, 483 + .setup_interface = mxic_nfc_setup_interface, 484 484 }; 485 485 486 486 static int mxic_nfc_probe(struct platform_device *pdev)
+154 -121
drivers/mtd/nand/raw/nand_base.c
··· 773 773 return -ENOTSUPP; 774 774 775 775 /* Wait tWB before polling the STATUS reg. */ 776 - timings = nand_get_sdr_timings(&chip->data_interface); 776 + timings = nand_get_sdr_timings(nand_get_interface_config(chip)); 777 777 ndelay(PSEC_TO_NSEC(timings->tWB_max)); 778 778 779 779 ret = nand_status_op(chip, NULL); ··· 898 898 } 899 899 900 900 /** 901 - * nand_reset_data_interface - Reset data interface and timings 901 + * nand_reset_interface - Reset data interface and timings 902 902 * @chip: The NAND chip 903 903 * @chipnr: Internal die id 904 904 * ··· 906 906 * 907 907 * Returns 0 for success or negative error code otherwise. 908 908 */ 909 - static int nand_reset_data_interface(struct nand_chip *chip, int chipnr) 909 + static int nand_reset_interface(struct nand_chip *chip, int chipnr) 910 910 { 911 + const struct nand_controller_ops *ops = chip->controller->ops; 911 912 int ret; 912 913 913 - if (!nand_has_setup_data_iface(chip)) 914 + if (!nand_controller_can_setup_interface(chip)) 914 915 return 0; 915 916 916 917 /* ··· 928 927 * timings to timing mode 0. 929 928 */ 930 929 931 - onfi_fill_data_interface(chip, NAND_SDR_IFACE, 0); 932 - ret = chip->controller->ops->setup_data_interface(chip, chipnr, 933 - &chip->data_interface); 930 + chip->current_interface_config = nand_get_reset_interface_config(); 931 + ret = ops->setup_interface(chip, chipnr, 932 + chip->current_interface_config); 934 933 if (ret) 935 934 pr_err("Failed to configure data interface to SDR timing mode 0\n"); 936 935 ··· 938 937 } 939 938 940 939 /** 941 - * nand_setup_data_interface - Setup the best data interface and timings 940 + * nand_setup_interface - Setup the best data interface and timings 942 941 * @chip: The NAND chip 943 942 * @chipnr: Internal die id 944 943 * 945 - * Find and configure the best data interface and NAND timings supported by 946 - * the chip and the driver. 947 - * First tries to retrieve supported timing modes from ONFI information, 948 - * and if the NAND chip does not support ONFI, relies on the 949 - * ->onfi_timing_mode_default specified in the nand_ids table. 944 + * Configure what has been reported to be the best data interface and NAND 945 + * timings supported by the chip and the driver. 950 946 * 951 947 * Returns 0 for success or negative error code otherwise. 952 948 */ 953 - static int nand_setup_data_interface(struct nand_chip *chip, int chipnr) 949 + static int nand_setup_interface(struct nand_chip *chip, int chipnr) 954 950 { 955 - u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = { 956 - chip->onfi_timing_mode_default, 957 - }; 951 + const struct nand_controller_ops *ops = chip->controller->ops; 952 + u8 tmode_param[ONFI_SUBFEATURE_PARAM_LEN] = { }; 958 953 int ret; 959 954 960 - if (!nand_has_setup_data_iface(chip)) 955 + if (!nand_controller_can_setup_interface(chip)) 961 956 return 0; 957 + 958 + /* 959 + * A nand_reset_interface() put both the NAND chip and the NAND 960 + * controller in timings mode 0. If the default mode for this chip is 961 + * also 0, no need to proceed to the change again. Plus, at probe time, 962 + * nand_setup_interface() uses ->set/get_features() which would 963 + * fail anyway as the parameter page is not available yet. 964 + */ 965 + if (!chip->best_interface_config) 966 + return 0; 967 + 968 + tmode_param[0] = chip->best_interface_config->timings.mode; 962 969 963 970 /* Change the mode on the chip side (if supported by the NAND chip) */ 964 971 if (nand_supports_set_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE)) { ··· 979 970 } 980 971 981 972 /* Change the mode on the controller side */ 982 - ret = chip->controller->ops->setup_data_interface(chip, chipnr, 983 - &chip->data_interface); 973 + ret = ops->setup_interface(chip, chipnr, chip->best_interface_config); 984 974 if (ret) 985 975 return ret; 986 976 987 977 /* Check the mode has been accepted by the chip, if supported */ 988 978 if (!nand_supports_get_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE)) 989 - return 0; 979 + goto update_interface_config; 990 980 991 981 memset(tmode_param, 0, ONFI_SUBFEATURE_PARAM_LEN); 992 982 nand_select_target(chip, chipnr); ··· 995 987 if (ret) 996 988 goto err_reset_chip; 997 989 998 - if (tmode_param[0] != chip->onfi_timing_mode_default) { 990 + if (tmode_param[0] != chip->best_interface_config->timings.mode) { 999 991 pr_warn("timing mode %d not acknowledged by the NAND chip\n", 1000 - chip->onfi_timing_mode_default); 992 + chip->best_interface_config->timings.mode); 1001 993 goto err_reset_chip; 1002 994 } 995 + 996 + update_interface_config: 997 + chip->current_interface_config = chip->best_interface_config; 1003 998 1004 999 return 0; 1005 1000 ··· 1011 1000 * Fallback to mode 0 if the chip explicitly did not ack the chosen 1012 1001 * timing mode. 1013 1002 */ 1014 - nand_reset_data_interface(chip, chipnr); 1003 + nand_reset_interface(chip, chipnr); 1015 1004 nand_select_target(chip, chipnr); 1016 1005 nand_reset_op(chip); 1017 1006 nand_deselect_target(chip); ··· 1020 1009 } 1021 1010 1022 1011 /** 1023 - * nand_init_data_interface - find the best data interface and timings 1012 + * nand_choose_best_sdr_timings - Pick up the best SDR timings that both the 1013 + * NAND controller and the NAND chip support 1014 + * @chip: the NAND chip 1015 + * @iface: the interface configuration (can eventually be updated) 1016 + * @spec_timings: specific timings, when not fitting the ONFI specification 1017 + * 1018 + * If specific timings are provided, use them. Otherwise, retrieve supported 1019 + * timing modes from ONFI information. 1020 + */ 1021 + int nand_choose_best_sdr_timings(struct nand_chip *chip, 1022 + struct nand_interface_config *iface, 1023 + struct nand_sdr_timings *spec_timings) 1024 + { 1025 + const struct nand_controller_ops *ops = chip->controller->ops; 1026 + int best_mode = 0, mode, ret; 1027 + 1028 + iface->type = NAND_SDR_IFACE; 1029 + 1030 + if (spec_timings) { 1031 + iface->timings.sdr = *spec_timings; 1032 + iface->timings.mode = onfi_find_closest_sdr_mode(spec_timings); 1033 + 1034 + /* Verify the controller supports the requested interface */ 1035 + ret = ops->setup_interface(chip, NAND_DATA_IFACE_CHECK_ONLY, 1036 + iface); 1037 + if (!ret) { 1038 + chip->best_interface_config = iface; 1039 + return ret; 1040 + } 1041 + 1042 + /* Fallback to slower modes */ 1043 + best_mode = iface->timings.mode; 1044 + } else if (chip->parameters.onfi) { 1045 + best_mode = fls(chip->parameters.onfi->async_timing_mode) - 1; 1046 + } 1047 + 1048 + for (mode = best_mode; mode >= 0; mode--) { 1049 + onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, mode); 1050 + 1051 + ret = ops->setup_interface(chip, NAND_DATA_IFACE_CHECK_ONLY, 1052 + iface); 1053 + if (!ret) 1054 + break; 1055 + } 1056 + 1057 + chip->best_interface_config = iface; 1058 + 1059 + return 0; 1060 + } 1061 + 1062 + /** 1063 + * nand_choose_interface_config - find the best data interface and timings 1024 1064 * @chip: The NAND chip 1025 1065 * 1026 1066 * Find the best data interface and NAND timings supported by the chip 1027 - * and the driver. 1028 - * First tries to retrieve supported timing modes from ONFI information, 1029 - * and if the NAND chip does not support ONFI, relies on the 1030 - * ->onfi_timing_mode_default specified in the nand_ids table. After this 1031 - * function nand_chip->data_interface is initialized with the best timing mode 1032 - * available. 1067 + * and the driver. Eventually let the NAND manufacturer driver propose his own 1068 + * set of timings. 1069 + * 1070 + * After this function nand_chip->interface_config is initialized with the best 1071 + * timing mode available. 1033 1072 * 1034 1073 * Returns 0 for success or negative error code otherwise. 1035 1074 */ 1036 - static int nand_init_data_interface(struct nand_chip *chip) 1075 + static int nand_choose_interface_config(struct nand_chip *chip) 1037 1076 { 1038 - int modes, mode, ret; 1077 + struct nand_interface_config *iface; 1078 + int ret; 1039 1079 1040 - if (!nand_has_setup_data_iface(chip)) 1080 + if (!nand_controller_can_setup_interface(chip)) 1041 1081 return 0; 1042 1082 1043 - /* 1044 - * First try to identify the best timings from ONFI parameters and 1045 - * if the NAND does not support ONFI, fallback to the default ONFI 1046 - * timing mode. 1047 - */ 1048 - if (chip->parameters.onfi) { 1049 - modes = chip->parameters.onfi->async_timing_mode; 1050 - } else { 1051 - if (!chip->onfi_timing_mode_default) 1052 - return 0; 1083 + iface = kzalloc(sizeof(*iface), GFP_KERNEL); 1084 + if (!iface) 1085 + return -ENOMEM; 1053 1086 1054 - modes = GENMASK(chip->onfi_timing_mode_default, 0); 1055 - } 1087 + if (chip->ops.choose_interface_config) 1088 + ret = chip->ops.choose_interface_config(chip, iface); 1089 + else 1090 + ret = nand_choose_best_sdr_timings(chip, iface, NULL); 1056 1091 1057 - for (mode = fls(modes) - 1; mode >= 0; mode--) { 1058 - ret = onfi_fill_data_interface(chip, NAND_SDR_IFACE, mode); 1059 - if (ret) 1060 - continue; 1092 + if (ret) 1093 + kfree(iface); 1061 1094 1062 - /* 1063 - * Pass NAND_DATA_IFACE_CHECK_ONLY to only check if the 1064 - * controller supports the requested timings. 1065 - */ 1066 - ret = chip->controller->ops->setup_data_interface(chip, 1067 - NAND_DATA_IFACE_CHECK_ONLY, 1068 - &chip->data_interface); 1069 - if (!ret) { 1070 - chip->onfi_timing_mode_default = mode; 1071 - break; 1072 - } 1073 - } 1074 - 1075 - return 0; 1095 + return ret; 1076 1096 } 1077 1097 1078 1098 /** ··· 1164 1122 unsigned int offset_in_page, void *buf, 1165 1123 unsigned int len) 1166 1124 { 1167 - struct mtd_info *mtd = nand_to_mtd(chip); 1168 1125 const struct nand_sdr_timings *sdr = 1169 - nand_get_sdr_timings(&chip->data_interface); 1126 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1127 + struct mtd_info *mtd = nand_to_mtd(chip); 1170 1128 u8 addrs[4]; 1171 1129 struct nand_op_instr instrs[] = { 1172 1130 NAND_OP_CMD(NAND_CMD_READ0, 0), ··· 1208 1166 unsigned int len) 1209 1167 { 1210 1168 const struct nand_sdr_timings *sdr = 1211 - nand_get_sdr_timings(&chip->data_interface); 1169 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1212 1170 u8 addrs[5]; 1213 1171 struct nand_op_instr instrs[] = { 1214 1172 NAND_OP_CMD(NAND_CMD_READ0, 0), ··· 1305 1263 1306 1264 if (nand_has_exec_op(chip)) { 1307 1265 const struct nand_sdr_timings *sdr = 1308 - nand_get_sdr_timings(&chip->data_interface); 1266 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1309 1267 struct nand_op_instr instrs[] = { 1310 1268 NAND_OP_CMD(NAND_CMD_PARAM, 0), 1311 1269 NAND_OP_ADDR(1, &page, PSEC_TO_NSEC(sdr->tWB_max)), ··· 1360 1318 1361 1319 if (nand_has_exec_op(chip)) { 1362 1320 const struct nand_sdr_timings *sdr = 1363 - nand_get_sdr_timings(&chip->data_interface); 1321 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1364 1322 u8 addrs[2] = {}; 1365 1323 struct nand_op_instr instrs[] = { 1366 1324 NAND_OP_CMD(NAND_CMD_RNDOUT, 0), ··· 1434 1392 unsigned int offset_in_page, const void *buf, 1435 1393 unsigned int len, bool prog) 1436 1394 { 1437 - struct mtd_info *mtd = nand_to_mtd(chip); 1438 1395 const struct nand_sdr_timings *sdr = 1439 - nand_get_sdr_timings(&chip->data_interface); 1396 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1397 + struct mtd_info *mtd = nand_to_mtd(chip); 1440 1398 u8 addrs[5] = {}; 1441 1399 struct nand_op_instr instrs[] = { 1442 1400 /* ··· 1559 1517 1560 1518 if (nand_has_exec_op(chip)) { 1561 1519 const struct nand_sdr_timings *sdr = 1562 - nand_get_sdr_timings(&chip->data_interface); 1520 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1563 1521 struct nand_op_instr instrs[] = { 1564 1522 NAND_OP_CMD(NAND_CMD_PAGEPROG, 1565 1523 PSEC_TO_NSEC(sdr->tWB_max)), ··· 1666 1624 1667 1625 if (nand_has_exec_op(chip)) { 1668 1626 const struct nand_sdr_timings *sdr = 1669 - nand_get_sdr_timings(&chip->data_interface); 1627 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1670 1628 u8 addrs[2]; 1671 1629 struct nand_op_instr instrs[] = { 1672 1630 NAND_OP_CMD(NAND_CMD_RNDIN, 0), ··· 1721 1679 1722 1680 if (nand_has_exec_op(chip)) { 1723 1681 const struct nand_sdr_timings *sdr = 1724 - nand_get_sdr_timings(&chip->data_interface); 1682 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1725 1683 struct nand_op_instr instrs[] = { 1726 1684 NAND_OP_CMD(NAND_CMD_READID, 0), 1727 1685 NAND_OP_ADDR(1, &addr, PSEC_TO_NSEC(sdr->tADL_min)), ··· 1760 1718 { 1761 1719 if (nand_has_exec_op(chip)) { 1762 1720 const struct nand_sdr_timings *sdr = 1763 - nand_get_sdr_timings(&chip->data_interface); 1721 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1764 1722 struct nand_op_instr instrs[] = { 1765 1723 NAND_OP_CMD(NAND_CMD_STATUS, 1766 1724 PSEC_TO_NSEC(sdr->tADL_min)), ··· 1829 1787 1830 1788 if (nand_has_exec_op(chip)) { 1831 1789 const struct nand_sdr_timings *sdr = 1832 - nand_get_sdr_timings(&chip->data_interface); 1790 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1833 1791 u8 addrs[3] = { page, page >> 8, page >> 16 }; 1834 1792 struct nand_op_instr instrs[] = { 1835 1793 NAND_OP_CMD(NAND_CMD_ERASE1, 0), ··· 1888 1846 1889 1847 if (nand_has_exec_op(chip)) { 1890 1848 const struct nand_sdr_timings *sdr = 1891 - nand_get_sdr_timings(&chip->data_interface); 1849 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1892 1850 struct nand_op_instr instrs[] = { 1893 1851 NAND_OP_CMD(NAND_CMD_SET_FEATURES, 0), 1894 1852 NAND_OP_ADDR(1, &feature, PSEC_TO_NSEC(sdr->tADL_min)), ··· 1935 1893 1936 1894 if (nand_has_exec_op(chip)) { 1937 1895 const struct nand_sdr_timings *sdr = 1938 - nand_get_sdr_timings(&chip->data_interface); 1896 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1939 1897 struct nand_op_instr instrs[] = { 1940 1898 NAND_OP_CMD(NAND_CMD_GET_FEATURES, 0), 1941 1899 NAND_OP_ADDR(1, &feature, PSEC_TO_NSEC(sdr->tWB_max)), ··· 1992 1950 { 1993 1951 if (nand_has_exec_op(chip)) { 1994 1952 const struct nand_sdr_timings *sdr = 1995 - nand_get_sdr_timings(&chip->data_interface); 1953 + nand_get_sdr_timings(nand_get_interface_config(chip)); 1996 1954 struct nand_op_instr instrs[] = { 1997 1955 NAND_OP_CMD(NAND_CMD_RESET, PSEC_TO_NSEC(sdr->tWB_max)), 1998 1956 NAND_OP_WAIT_RDY(PSEC_TO_MSEC(sdr->tRST_max), 0), ··· 2522 2480 * @chipnr: Internal die id 2523 2481 * 2524 2482 * Save the timings data structure, then apply SDR timings mode 0 (see 2525 - * nand_reset_data_interface for details), do the reset operation, and 2526 - * apply back the previous timings. 2483 + * nand_reset_interface for details), do the reset operation, and apply 2484 + * back the previous timings. 2527 2485 * 2528 2486 * Returns 0 on success, a negative error code otherwise. 2529 2487 */ 2530 2488 int nand_reset(struct nand_chip *chip, int chipnr) 2531 2489 { 2532 - struct nand_data_interface saved_data_intf = chip->data_interface; 2533 2490 int ret; 2534 2491 2535 - ret = nand_reset_data_interface(chip, chipnr); 2492 + ret = nand_reset_interface(chip, chipnr); 2536 2493 if (ret) 2537 2494 return ret; 2538 2495 ··· 2546 2505 if (ret) 2547 2506 return ret; 2548 2507 2549 - /* 2550 - * A nand_reset_data_interface() put both the NAND chip and the NAND 2551 - * controller in timings mode 0. If the default mode for this chip is 2552 - * also 0, no need to proceed to the change again. Plus, at probe time, 2553 - * nand_setup_data_interface() uses ->set/get_features() which would 2554 - * fail anyway as the parameter page is not available yet. 2555 - */ 2556 - if (!chip->onfi_timing_mode_default) 2557 - return 0; 2558 - 2559 - chip->data_interface = saved_data_intf; 2560 - ret = nand_setup_data_interface(chip, chipnr); 2508 + ret = nand_setup_interface(chip, chipnr); 2561 2509 if (ret) 2562 2510 return ret; 2563 2511 ··· 3245 3215 if (retry_mode >= chip->read_retries) 3246 3216 return -EINVAL; 3247 3217 3248 - if (!chip->setup_read_retry) 3218 + if (!chip->ops.setup_read_retry) 3249 3219 return -EOPNOTSUPP; 3250 3220 3251 - return chip->setup_read_retry(chip, retry_mode); 3221 + return chip->ops.setup_read_retry(chip, retry_mode); 3252 3222 } 3253 3223 3254 3224 static void nand_wait_readrdy(struct nand_chip *chip) ··· 3258 3228 if (!(chip->options & NAND_NEED_READRDY)) 3259 3229 return; 3260 3230 3261 - sdr = nand_get_sdr_timings(&chip->data_interface); 3231 + sdr = nand_get_sdr_timings(nand_get_interface_config(chip)); 3262 3232 WARN_ON(nand_wait_rdy_op(chip, PSEC_TO_MSEC(sdr->tR_max), 0)); 3263 3233 } 3264 3234 ··· 4492 4462 int ret = 0; 4493 4463 4494 4464 mutex_lock(&chip->lock); 4495 - if (chip->suspend) 4496 - ret = chip->suspend(chip); 4465 + if (chip->ops.suspend) 4466 + ret = chip->ops.suspend(chip); 4497 4467 if (!ret) 4498 4468 chip->suspended = 1; 4499 4469 mutex_unlock(&chip->lock); ··· 4511 4481 4512 4482 mutex_lock(&chip->lock); 4513 4483 if (chip->suspended) { 4514 - if (chip->resume) 4515 - chip->resume(chip); 4484 + if (chip->ops.resume) 4485 + chip->ops.resume(chip); 4516 4486 chip->suspended = 0; 4517 4487 } else { 4518 4488 pr_err("%s called for a chip which is not in suspended state\n", ··· 4541 4511 { 4542 4512 struct nand_chip *chip = mtd_to_nand(mtd); 4543 4513 4544 - if (!chip->lock_area) 4514 + if (!chip->ops.lock_area) 4545 4515 return -ENOTSUPP; 4546 4516 4547 - return chip->lock_area(chip, ofs, len); 4517 + return chip->ops.lock_area(chip, ofs, len); 4548 4518 } 4549 4519 4550 4520 /** ··· 4557 4527 { 4558 4528 struct nand_chip *chip = mtd_to_nand(mtd); 4559 4529 4560 - if (!chip->unlock_area) 4530 + if (!chip->ops.unlock_area) 4561 4531 return -ENOTSUPP; 4562 4532 4563 - return chip->unlock_area(chip, ofs, len); 4533 + return chip->ops.unlock_area(chip, ofs, len); 4564 4534 } 4565 4535 4566 4536 /* Set default functions */ ··· 4773 4743 chip->options |= type->options; 4774 4744 chip->base.eccreq.strength = NAND_ECC_STRENGTH(type); 4775 4745 chip->base.eccreq.step_size = NAND_ECC_STEP(type); 4776 - chip->onfi_timing_mode_default = 4777 - type->onfi_timing_mode_default; 4778 4746 4779 4747 chip->parameters.model = kstrdup(type->name, GFP_KERNEL); 4780 4748 if (!chip->parameters.model) ··· 4838 4810 } 4839 4811 4840 4812 static const char * 4841 - nand_manufacturer_name(const struct nand_manufacturer *manufacturer) 4813 + nand_manufacturer_name(const struct nand_manufacturer_desc *manufacturer_desc) 4842 4814 { 4843 - return manufacturer ? manufacturer->name : "Unknown"; 4815 + return manufacturer_desc ? manufacturer_desc->name : "Unknown"; 4844 4816 } 4845 4817 4846 4818 /* ··· 4848 4820 */ 4849 4821 static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) 4850 4822 { 4851 - const struct nand_manufacturer *manufacturer; 4823 + const struct nand_manufacturer_desc *manufacturer_desc; 4852 4824 struct mtd_info *mtd = nand_to_mtd(chip); 4853 4825 struct nand_memory_organization *memorg; 4854 4826 int busw, ret; ··· 4905 4877 chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); 4906 4878 4907 4879 /* Try to identify manufacturer */ 4908 - manufacturer = nand_get_manufacturer(maf_id); 4909 - chip->manufacturer.desc = manufacturer; 4880 + manufacturer_desc = nand_get_manufacturer_desc(maf_id); 4881 + chip->manufacturer.desc = manufacturer_desc; 4910 4882 4911 4883 if (!type) 4912 4884 type = nand_flash_ids; ··· 4985 4957 */ 4986 4958 pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", 4987 4959 maf_id, dev_id); 4988 - pr_info("%s %s\n", nand_manufacturer_name(manufacturer), 4960 + pr_info("%s %s\n", nand_manufacturer_name(manufacturer_desc), 4989 4961 mtd->name); 4990 4962 pr_warn("bus width %d instead of %d bits\n", busw ? 16 : 8, 4991 4963 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8); ··· 5020 4992 5021 4993 pr_info("device found, Manufacturer ID: 0x%02x, Chip ID: 0x%02x\n", 5022 4994 maf_id, dev_id); 5023 - pr_info("%s %s\n", nand_manufacturer_name(manufacturer), 4995 + pr_info("%s %s\n", nand_manufacturer_name(manufacturer_desc), 5024 4996 chip->parameters.model); 5025 4997 pr_info("%d MiB, %s, erase size: %d KiB, page size: %d, OOB size: %d\n", 5026 4998 (int)(targetsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", ··· 5213 5185 mutex_init(&chip->lock); 5214 5186 5215 5187 /* Enforce the right timings for reset/detection */ 5216 - onfi_fill_data_interface(chip, NAND_SDR_IFACE, 0); 5188 + chip->current_interface_config = nand_get_reset_interface_config(); 5217 5189 5218 5190 ret = nand_dt_init(chip); 5219 5191 if (ret) ··· 6000 5972 if (!mtd->bitflip_threshold) 6001 5973 mtd->bitflip_threshold = DIV_ROUND_UP(mtd->ecc_strength * 3, 4); 6002 5974 6003 - /* Initialize the ->data_interface field. */ 6004 - ret = nand_init_data_interface(chip); 5975 + /* Find the fastest data interface for this chip */ 5976 + ret = nand_choose_interface_config(chip); 6005 5977 if (ret) 6006 5978 goto err_nanddev_cleanup; 6007 5979 6008 5980 /* Enter fastest possible mode on all dies. */ 6009 5981 for (i = 0; i < nanddev_ntargets(&chip->base); i++) { 6010 - ret = nand_setup_data_interface(chip, i); 5982 + ret = nand_setup_interface(chip, i); 6011 5983 if (ret) 6012 - goto err_nanddev_cleanup; 5984 + goto err_free_interface_config; 6013 5985 } 6014 5986 6015 5987 /* Check, if we should skip the bad block table scan */ ··· 6019 5991 /* Build bad block table */ 6020 5992 ret = nand_create_bbt(chip); 6021 5993 if (ret) 6022 - goto err_nanddev_cleanup; 5994 + goto err_free_interface_config; 6023 5995 6024 5996 return 0; 6025 5997 5998 + err_free_interface_config: 5999 + kfree(chip->best_interface_config); 6026 6000 6027 6001 err_nanddev_cleanup: 6028 6002 nanddev_cleanup(&chip->base); ··· 6117 6087 if (chip->badblock_pattern && chip->badblock_pattern->options 6118 6088 & NAND_BBT_DYNAMICSTRUCT) 6119 6089 kfree(chip->badblock_pattern); 6090 + 6091 + /* Free the data interface */ 6092 + kfree(chip->best_interface_config); 6120 6093 6121 6094 /* Free manufacturer priv data. */ 6122 6095 nand_manufacturer_cleanup(chip);
+1 -1
drivers/mtd/nand/raw/nand_bbt.c
··· 1226 1226 return -ENOMEM; 1227 1227 1228 1228 /* 1229 - * If no primary table decriptor is given, scan the device to build a 1229 + * If no primary table descriptor is given, scan the device to build a 1230 1230 * memory based bad block table. 1231 1231 */ 1232 1232 if (!td) {
+15 -1
drivers/mtd/nand/raw/nand_hynix.c
··· 337 337 rr->nregs = nregs; 338 338 rr->regs = hynix_1xnm_mlc_read_retry_regs; 339 339 hynix->read_retry = rr; 340 - chip->setup_read_retry = hynix_nand_setup_read_retry; 340 + chip->ops.setup_read_retry = hynix_nand_setup_read_retry; 341 341 chip->read_retries = nmodes; 342 342 343 343 out: ··· 673 673 nand_set_manufacturer_data(chip, NULL); 674 674 } 675 675 676 + static int 677 + h27ucg8t2atrbc_choose_interface_config(struct nand_chip *chip, 678 + struct nand_interface_config *iface) 679 + { 680 + onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, 4); 681 + 682 + return nand_choose_best_sdr_timings(chip, iface, NULL); 683 + } 684 + 676 685 static int hynix_nand_init(struct nand_chip *chip) 677 686 { 678 687 struct hynix_nand *hynix; ··· 697 688 return -ENOMEM; 698 689 699 690 nand_set_manufacturer_data(chip, hynix); 691 + 692 + if (!strncmp("H27UCG8T2ATR-BC", chip->parameters.model, 693 + sizeof("H27UCG8T2ATR-BC") - 1)) 694 + chip->ops.choose_interface_config = 695 + h27ucg8t2atrbc_choose_interface_config; 700 696 701 697 ret = hynix_nand_rr_init(chip); 702 698 if (ret)
+13 -11
drivers/mtd/nand/raw/nand_ids.c
··· 28 28 */ 29 29 {"TC58NVG0S3E 1G 3.3V 8-bit", 30 30 { .id = {0x98, 0xd1, 0x90, 0x15, 0x76, 0x14, 0x01, 0x00} }, 31 - SZ_2K, SZ_128, SZ_128K, 0, 8, 64, NAND_ECC_INFO(1, SZ_512), 32 - 2 }, 31 + SZ_2K, SZ_128, SZ_128K, 0, 8, 64, NAND_ECC_INFO(1, SZ_512), }, 33 32 {"TC58NVG2S0F 4G 3.3V 8-bit", 34 33 { .id = {0x98, 0xdc, 0x90, 0x26, 0x76, 0x15, 0x01, 0x08} }, 35 34 SZ_4K, SZ_512, SZ_256K, 0, 8, 224, NAND_ECC_INFO(4, SZ_512) }, ··· 50 51 {"H27UCG8T2ATR-BC 64G 3.3V 8-bit", 51 52 { .id = {0xad, 0xde, 0x94, 0xda, 0x74, 0xc4} }, 52 53 SZ_8K, SZ_8K, SZ_2M, NAND_NEED_SCRAMBLING, 6, 640, 53 - NAND_ECC_INFO(40, SZ_1K), 4 }, 54 + NAND_ECC_INFO(40, SZ_1K) }, 55 + {"TH58NVG2S3HBAI4 4G 3.3V 8-bit", 56 + { .id = {0x98, 0xdc, 0x91, 0x15, 0x76} }, 57 + SZ_2K, SZ_512, SZ_128K, 0, 5, 128, NAND_ECC_INFO(8, SZ_512) }, 54 58 55 59 LEGACY_ID_NAND("NAND 4MiB 5V 8-bit", 0x6B, 4, SZ_8K, SP_OPTIONS), 56 60 LEGACY_ID_NAND("NAND 4MiB 3,3V 8-bit", 0xE3, 4, SZ_8K, SP_OPTIONS), ··· 168 166 }; 169 167 170 168 /* Manufacturer IDs */ 171 - static const struct nand_manufacturer nand_manufacturers[] = { 169 + static const struct nand_manufacturer_desc nand_manufacturer_descs[] = { 172 170 {NAND_MFR_AMD, "AMD/Spansion", &amd_nand_manuf_ops}, 173 171 {NAND_MFR_ATO, "ATO"}, 174 172 {NAND_MFR_EON, "Eon"}, ··· 188 186 }; 189 187 190 188 /** 191 - * nand_get_manufacturer - Get manufacturer information from the manufacturer 192 - * ID 189 + * nand_get_manufacturer_desc - Get manufacturer information from the 190 + * manufacturer ID 193 191 * @id: manufacturer ID 194 192 * 195 - * Returns a pointer a nand_manufacturer object if the manufacturer is defined 193 + * Returns a nand_manufacturer_desc object if the manufacturer is defined 196 194 * in the NAND manufacturers database, NULL otherwise. 197 195 */ 198 - const struct nand_manufacturer *nand_get_manufacturer(u8 id) 196 + const struct nand_manufacturer_desc *nand_get_manufacturer_desc(u8 id) 199 197 { 200 198 int i; 201 199 202 - for (i = 0; i < ARRAY_SIZE(nand_manufacturers); i++) 203 - if (nand_manufacturers[i].id == id) 204 - return &nand_manufacturers[i]; 200 + for (i = 0; i < ARRAY_SIZE(nand_manufacturer_descs); i++) 201 + if (nand_manufacturer_descs[i].id == id) 202 + return &nand_manufacturer_descs[i]; 205 203 206 204 return NULL; 207 205 }
+5 -2
drivers/mtd/nand/raw/nand_legacy.c
··· 354 354 355 355 static void nand_ccs_delay(struct nand_chip *chip) 356 356 { 357 + const struct nand_sdr_timings *sdr = 358 + nand_get_sdr_timings(nand_get_interface_config(chip)); 359 + 357 360 /* 358 361 * The controller already takes care of waiting for tCCS when the RNDIN 359 362 * or RNDOUT command is sent, return directly. ··· 368 365 * Wait tCCS_min if it is correctly defined, otherwise wait 500ns 369 366 * (which should be safe for all NANDs). 370 367 */ 371 - if (nand_has_setup_data_iface(chip)) 372 - ndelay(chip->data_interface.timings.sdr.tCCS_min / 1000); 368 + if (nand_controller_can_setup_interface(chip)) 369 + ndelay(sdr->tCCS_min / 1000); 373 370 else 374 371 ndelay(500); 375 372 }
+5 -5
drivers/mtd/nand/raw/nand_macronix.c
··· 130 130 return; 131 131 132 132 chip->read_retries = MACRONIX_NUM_READ_RETRY_MODES; 133 - chip->setup_read_retry = macronix_nand_setup_read_retry; 133 + chip->ops.setup_read_retry = macronix_nand_setup_read_retry; 134 134 135 135 if (p->supports_set_get_features) { 136 136 bitmap_set(p->set_feature_list, ··· 242 242 bitmap_set(chip->parameters.set_feature_list, 243 243 ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); 244 244 245 - chip->lock_area = mxic_nand_lock; 246 - chip->unlock_area = mxic_nand_unlock; 245 + chip->ops.lock_area = mxic_nand_lock; 246 + chip->ops.unlock_area = mxic_nand_unlock; 247 247 } 248 248 249 249 static int nand_power_down_op(struct nand_chip *chip) ··· 312 312 if (i < 0) 313 313 return; 314 314 315 - chip->suspend = mxic_nand_suspend; 316 - chip->resume = mxic_nand_resume; 315 + chip->ops.suspend = mxic_nand_suspend; 316 + chip->ops.resume = mxic_nand_resume; 317 317 } 318 318 319 319 static int macronix_nand_init(struct nand_chip *chip)
+1 -1
drivers/mtd/nand/raw/nand_micron.c
··· 84 84 struct nand_onfi_vendor_micron *micron = (void *)p->onfi->vendor; 85 85 86 86 chip->read_retries = micron->read_retry_options; 87 - chip->setup_read_retry = micron_nand_setup_read_retry; 87 + chip->ops.setup_read_retry = micron_nand_setup_read_retry; 88 88 } 89 89 90 90 if (p->supports_set_get_features) {
+89 -31
drivers/mtd/nand/raw/nand_timings.c
··· 12 12 13 13 #define ONFI_DYN_TIMING_MAX U16_MAX 14 14 15 - static const struct nand_data_interface onfi_sdr_timings[] = { 15 + /* 16 + * For non-ONFI chips we use the highest possible value for tPROG and tBERS. 17 + * tR and tCCS will take the default values precised in the ONFI specification 18 + * for timing mode 0, respectively 200us and 500ns. 19 + * 20 + * These four values are tweaked to be more accurate in the case of ONFI chips. 21 + */ 22 + static const struct nand_interface_config onfi_sdr_timings[] = { 16 23 /* Mode 0 */ 17 24 { 18 25 .type = NAND_SDR_IFACE, ··· 27 20 .timings.sdr = { 28 21 .tCCS_min = 500000, 29 22 .tR_max = 200000000, 23 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 24 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 30 25 .tADL_min = 400000, 31 26 .tALH_min = 20000, 32 27 .tALS_min = 50000, ··· 72 63 .timings.sdr = { 73 64 .tCCS_min = 500000, 74 65 .tR_max = 200000000, 66 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 67 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 75 68 .tADL_min = 400000, 76 69 .tALH_min = 10000, 77 70 .tALS_min = 25000, ··· 117 106 .timings.sdr = { 118 107 .tCCS_min = 500000, 119 108 .tR_max = 200000000, 109 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 110 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 120 111 .tADL_min = 400000, 121 112 .tALH_min = 10000, 122 113 .tALS_min = 15000, ··· 162 149 .timings.sdr = { 163 150 .tCCS_min = 500000, 164 151 .tR_max = 200000000, 152 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 153 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 165 154 .tADL_min = 400000, 166 155 .tALH_min = 5000, 167 156 .tALS_min = 10000, ··· 207 192 .timings.sdr = { 208 193 .tCCS_min = 500000, 209 194 .tR_max = 200000000, 195 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 196 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 210 197 .tADL_min = 400000, 211 198 .tALH_min = 5000, 212 199 .tALS_min = 10000, ··· 252 235 .timings.sdr = { 253 236 .tCCS_min = 500000, 254 237 .tR_max = 200000000, 238 + .tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 239 + .tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX, 255 240 .tADL_min = 400000, 256 241 .tALH_min = 5000, 257 242 .tALS_min = 10000, ··· 292 273 }, 293 274 }; 294 275 295 - /** 296 - * onfi_fill_data_interface - [NAND Interface] Initialize a data interface from 297 - * given ONFI mode 298 - * @mode: The ONFI timing mode 299 - */ 300 - int onfi_fill_data_interface(struct nand_chip *chip, 301 - enum nand_data_interface_type type, 302 - int timing_mode) 276 + /* All NAND chips share the same reset data interface: SDR mode 0 */ 277 + const struct nand_interface_config *nand_get_reset_interface_config(void) 303 278 { 304 - struct nand_data_interface *iface = &chip->data_interface; 279 + return &onfi_sdr_timings[0]; 280 + } 281 + 282 + /** 283 + * onfi_find_closest_sdr_mode - Derive the closest ONFI SDR timing mode given a 284 + * set of timings 285 + * @spec_timings: the timings to challenge 286 + */ 287 + unsigned int 288 + onfi_find_closest_sdr_mode(const struct nand_sdr_timings *spec_timings) 289 + { 290 + const struct nand_sdr_timings *onfi_timings; 291 + int mode; 292 + 293 + for (mode = ARRAY_SIZE(onfi_sdr_timings) - 1; mode > 0; mode--) { 294 + onfi_timings = &onfi_sdr_timings[mode].timings.sdr; 295 + 296 + if (spec_timings->tCCS_min <= onfi_timings->tCCS_min && 297 + spec_timings->tADL_min <= onfi_timings->tADL_min && 298 + spec_timings->tALH_min <= onfi_timings->tALH_min && 299 + spec_timings->tALS_min <= onfi_timings->tALS_min && 300 + spec_timings->tAR_min <= onfi_timings->tAR_min && 301 + spec_timings->tCEH_min <= onfi_timings->tCEH_min && 302 + spec_timings->tCH_min <= onfi_timings->tCH_min && 303 + spec_timings->tCLH_min <= onfi_timings->tCLH_min && 304 + spec_timings->tCLR_min <= onfi_timings->tCLR_min && 305 + spec_timings->tCLS_min <= onfi_timings->tCLS_min && 306 + spec_timings->tCOH_min <= onfi_timings->tCOH_min && 307 + spec_timings->tCS_min <= onfi_timings->tCS_min && 308 + spec_timings->tDH_min <= onfi_timings->tDH_min && 309 + spec_timings->tDS_min <= onfi_timings->tDS_min && 310 + spec_timings->tIR_min <= onfi_timings->tIR_min && 311 + spec_timings->tRC_min <= onfi_timings->tRC_min && 312 + spec_timings->tREH_min <= onfi_timings->tREH_min && 313 + spec_timings->tRHOH_min <= onfi_timings->tRHOH_min && 314 + spec_timings->tRHW_min <= onfi_timings->tRHW_min && 315 + spec_timings->tRLOH_min <= onfi_timings->tRLOH_min && 316 + spec_timings->tRP_min <= onfi_timings->tRP_min && 317 + spec_timings->tRR_min <= onfi_timings->tRR_min && 318 + spec_timings->tWC_min <= onfi_timings->tWC_min && 319 + spec_timings->tWH_min <= onfi_timings->tWH_min && 320 + spec_timings->tWHR_min <= onfi_timings->tWHR_min && 321 + spec_timings->tWP_min <= onfi_timings->tWP_min && 322 + spec_timings->tWW_min <= onfi_timings->tWW_min) 323 + return mode; 324 + } 325 + 326 + return 0; 327 + } 328 + 329 + /** 330 + * onfi_fill_interface_config - Initialize an interface config from a given 331 + * ONFI mode 332 + * @chip: The NAND chip 333 + * @iface: The interface configuration to fill 334 + * @type: The interface type 335 + * @timing_mode: The ONFI timing mode 336 + */ 337 + void onfi_fill_interface_config(struct nand_chip *chip, 338 + struct nand_interface_config *iface, 339 + enum nand_interface_type type, 340 + unsigned int timing_mode) 341 + { 305 342 struct onfi_params *onfi = chip->parameters.onfi; 306 343 307 - if (type != NAND_SDR_IFACE) 308 - return -EINVAL; 344 + if (WARN_ON(type != NAND_SDR_IFACE)) 345 + return; 309 346 310 - if (timing_mode < 0 || timing_mode >= ARRAY_SIZE(onfi_sdr_timings)) 311 - return -EINVAL; 347 + if (WARN_ON(timing_mode >= ARRAY_SIZE(onfi_sdr_timings))) 348 + return; 312 349 313 350 *iface = onfi_sdr_timings[timing_mode]; 314 351 ··· 383 308 384 309 /* nanoseconds -> picoseconds */ 385 310 timings->tCCS_min = 1000UL * onfi->tCCS; 386 - } else { 387 - struct nand_sdr_timings *timings = &iface->timings.sdr; 388 - /* 389 - * For non-ONFI chips we use the highest possible value for 390 - * tPROG and tBERS. tR and tCCS will take the default values 391 - * precised in the ONFI specification for timing mode 0, 392 - * respectively 200us and 500ns. 393 - */ 394 - 395 - /* microseconds -> picoseconds */ 396 - timings->tPROG_max = 1000000ULL * ONFI_DYN_TIMING_MAX; 397 - timings->tBERS_max = 1000000ULL * ONFI_DYN_TIMING_MAX; 398 - 399 - timings->tR_max = 200000000; 400 - timings->tCCS_min = 500000; 401 311 } 402 - 403 - return 0; 404 312 }
+70 -2
drivers/mtd/nand/raw/nand_toshiba.c
··· 33 33 34 34 if (nand_has_exec_op(chip)) { 35 35 const struct nand_sdr_timings *sdr = 36 - nand_get_sdr_timings(&chip->data_interface); 36 + nand_get_sdr_timings(nand_get_interface_config(chip)); 37 37 struct nand_op_instr instrs[] = { 38 38 NAND_OP_CMD(TOSHIBA_NAND_CMD_ECC_STATUS_READ, 39 39 PSEC_TO_NSEC(sdr->tADL_min)), ··· 194 194 } 195 195 } 196 196 197 + static int 198 + tc58teg5dclta00_choose_interface_config(struct nand_chip *chip, 199 + struct nand_interface_config *iface) 200 + { 201 + onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, 5); 202 + 203 + return nand_choose_best_sdr_timings(chip, iface, NULL); 204 + } 205 + 206 + static int 207 + tc58nvg0s3e_choose_interface_config(struct nand_chip *chip, 208 + struct nand_interface_config *iface) 209 + { 210 + onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, 2); 211 + 212 + return nand_choose_best_sdr_timings(chip, iface, NULL); 213 + } 214 + 215 + static int 216 + th58nvg2s3hbai4_choose_interface_config(struct nand_chip *chip, 217 + struct nand_interface_config *iface) 218 + { 219 + struct nand_sdr_timings *sdr = &iface->timings.sdr; 220 + 221 + /* Start with timings from the closest timing mode, mode 4. */ 222 + onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, 4); 223 + 224 + /* Patch timings that differ from mode 4. */ 225 + sdr->tALS_min = 12000; 226 + sdr->tCHZ_max = 20000; 227 + sdr->tCLS_min = 12000; 228 + sdr->tCOH_min = 0; 229 + sdr->tDS_min = 12000; 230 + sdr->tRHOH_min = 25000; 231 + sdr->tRHW_min = 30000; 232 + sdr->tRHZ_max = 60000; 233 + sdr->tWHR_min = 60000; 234 + 235 + /* Patch timings not part of onfi timing mode. */ 236 + sdr->tPROG_max = 700000000; 237 + sdr->tBERS_max = 5000000000; 238 + 239 + return nand_choose_best_sdr_timings(chip, iface, sdr); 240 + } 241 + 197 242 static int tc58teg5dclta00_init(struct nand_chip *chip) 198 243 { 199 244 struct mtd_info *mtd = nand_to_mtd(chip); 200 245 201 - chip->onfi_timing_mode_default = 5; 246 + chip->ops.choose_interface_config = 247 + &tc58teg5dclta00_choose_interface_config; 202 248 chip->options |= NAND_NEED_SCRAMBLING; 203 249 mtd_set_pairing_scheme(mtd, &dist3_pairing_scheme); 250 + 251 + return 0; 252 + } 253 + 254 + static int tc58nvg0s3e_init(struct nand_chip *chip) 255 + { 256 + chip->ops.choose_interface_config = 257 + &tc58nvg0s3e_choose_interface_config; 258 + 259 + return 0; 260 + } 261 + 262 + static int th58nvg2s3hbai4_init(struct nand_chip *chip) 263 + { 264 + chip->ops.choose_interface_config = 265 + &th58nvg2s3hbai4_choose_interface_config; 204 266 205 267 return 0; 206 268 } ··· 279 217 280 218 if (!strcmp("TC58TEG5DCLTA00", chip->parameters.model)) 281 219 tc58teg5dclta00_init(chip); 220 + if (!strncmp("TC58NVG0S3E", chip->parameters.model, 221 + sizeof("TC58NVG0S3E") - 1)) 222 + tc58nvg0s3e_init(chip); 223 + if (!strncmp("TH58NVG2S3HBAI4", chip->parameters.model, 224 + sizeof("TH58NVG2S3HBAI4") - 1)) 225 + th58nvg2s3hbai4_init(chip); 282 226 283 227 return 0; 284 228 }
+1 -1
drivers/mtd/nand/raw/omap_elm.c
··· 2 2 /* 3 3 * Error Location Module 4 4 * 5 - * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ 5 + * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/ 6 6 */ 7 7 8 8 #define DRIVER_NAME "omap-elm"
+16 -2
drivers/mtd/nand/raw/qcom_nandc.c
··· 459 459 * among different NAND controllers. 460 460 * @ecc_modes - ecc mode for NAND 461 461 * @is_bam - whether NAND controller is using BAM 462 + * @is_qpic - whether NAND CTRL is part of qpic IP 462 463 * @dev_cmd_reg_start - NAND_DEV_CMD_* registers starting offset 463 464 */ 464 465 struct qcom_nandc_props { 465 466 u32 ecc_modes; 466 467 bool is_bam; 468 + bool is_qpic; 467 469 u32 dev_cmd_reg_start; 468 470 }; 469 471 ··· 2776 2774 u32 nand_ctrl; 2777 2775 2778 2776 /* kill onenand */ 2779 - nandc_write(nandc, SFLASHC_BURST_CFG, 0); 2777 + if (!nandc->props->is_qpic) 2778 + nandc_write(nandc, SFLASHC_BURST_CFG, 0); 2780 2779 nandc_write(nandc, dev_cmd_reg_addr(nandc, NAND_DEV_CMD_VLD), 2781 2780 NAND_DEV_CMD_VLD_VAL); 2782 2781 2783 2782 /* enable ADM or BAM DMA */ 2784 2783 if (nandc->props->is_bam) { 2785 2784 nand_ctrl = nandc_read(nandc, NAND_CTRL); 2786 - nandc_write(nandc, NAND_CTRL, nand_ctrl | BAM_MODE_EN); 2785 + 2786 + /* 2787 + *NAND_CTRL is an operational registers, and CPU 2788 + * access to operational registers are read only 2789 + * in BAM mode. So update the NAND_CTRL register 2790 + * only if it is not in BAM mode. In most cases BAM 2791 + * mode will be enabled in bootloader 2792 + */ 2793 + if (!(nand_ctrl & BAM_MODE_EN)) 2794 + nandc_write(nandc, NAND_CTRL, nand_ctrl | BAM_MODE_EN); 2787 2795 } else { 2788 2796 nandc_write(nandc, NAND_FLASH_CHIP_SELECT, DM_EN); 2789 2797 } ··· 3047 3035 static const struct qcom_nandc_props ipq4019_nandc_props = { 3048 3036 .ecc_modes = (ECC_BCH_4BIT | ECC_BCH_8BIT), 3049 3037 .is_bam = true, 3038 + .is_qpic = true, 3050 3039 .dev_cmd_reg_start = 0x0, 3051 3040 }; 3052 3041 3053 3042 static const struct qcom_nandc_props ipq8074_nandc_props = { 3054 3043 .ecc_modes = (ECC_BCH_4BIT | ECC_BCH_8BIT), 3055 3044 .is_bam = true, 3045 + .is_qpic = true, 3056 3046 .dev_cmd_reg_start = 0x7000, 3057 3047 }; 3058 3048
+3 -3
drivers/mtd/nand/raw/s3c2410.c
··· 808 808 return -ENODEV; 809 809 } 810 810 811 - static int s3c2410_nand_setup_data_interface(struct nand_chip *chip, int csline, 812 - const struct nand_data_interface *conf) 811 + static int s3c2410_nand_setup_interface(struct nand_chip *chip, int csline, 812 + const struct nand_interface_config *conf) 813 813 { 814 814 struct mtd_info *mtd = nand_to_mtd(chip); 815 815 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); ··· 999 999 1000 1000 static const struct nand_controller_ops s3c24xx_nand_controller_ops = { 1001 1001 .attach_chip = s3c2410_nand_attach_chip, 1002 - .setup_data_interface = s3c2410_nand_setup_data_interface, 1002 + .setup_interface = s3c2410_nand_setup_interface, 1003 1003 }; 1004 1004 1005 1005 static const struct of_device_id s3c24xx_nand_dt_ids[] = {
+165 -154
drivers/mtd/nand/raw/stm32_fmc2_nand.c
··· 11 11 #include <linux/errno.h> 12 12 #include <linux/interrupt.h> 13 13 #include <linux/iopoll.h> 14 + #include <linux/mfd/syscon.h> 14 15 #include <linux/module.h> 15 16 #include <linux/mtd/rawnand.h> 17 + #include <linux/of_address.h> 16 18 #include <linux/pinctrl/consumer.h> 17 19 #include <linux/platform_device.h> 20 + #include <linux/regmap.h> 18 21 #include <linux/reset.h> 19 22 20 23 /* Bad block marker length */ ··· 245 242 struct nand_controller base; 246 243 struct stm32_fmc2_nand nand; 247 244 struct device *dev; 248 - void __iomem *io_base; 245 + struct device *cdev; 246 + struct regmap *regmap; 249 247 void __iomem *data_base[FMC2_MAX_CE]; 250 248 void __iomem *cmd_base[FMC2_MAX_CE]; 251 249 void __iomem *addr_base[FMC2_MAX_CE]; ··· 281 277 struct stm32_fmc2_nfc *nfc = to_stm32_nfc(chip->controller); 282 278 struct stm32_fmc2_nand *nand = to_fmc2_nand(chip); 283 279 struct stm32_fmc2_timings *timings = &nand->timings; 284 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 285 280 u32 pmem, patt; 286 281 287 282 /* Set tclr/tar timings */ 288 - pcr &= ~FMC2_PCR_TCLR; 289 - pcr |= FIELD_PREP(FMC2_PCR_TCLR, timings->tclr); 290 - pcr &= ~FMC2_PCR_TAR; 291 - pcr |= FIELD_PREP(FMC2_PCR_TAR, timings->tar); 283 + regmap_update_bits(nfc->regmap, FMC2_PCR, 284 + FMC2_PCR_TCLR | FMC2_PCR_TAR, 285 + FIELD_PREP(FMC2_PCR_TCLR, timings->tclr) | 286 + FIELD_PREP(FMC2_PCR_TAR, timings->tar)); 292 287 293 288 /* Set tset/twait/thold/thiz timings in common bank */ 294 289 pmem = FIELD_PREP(FMC2_PMEM_MEMSET, timings->tset_mem); 295 290 pmem |= FIELD_PREP(FMC2_PMEM_MEMWAIT, timings->twait); 296 291 pmem |= FIELD_PREP(FMC2_PMEM_MEMHOLD, timings->thold_mem); 297 292 pmem |= FIELD_PREP(FMC2_PMEM_MEMHIZ, timings->thiz); 293 + regmap_write(nfc->regmap, FMC2_PMEM, pmem); 298 294 299 295 /* Set tset/twait/thold/thiz timings in attribut bank */ 300 296 patt = FIELD_PREP(FMC2_PATT_ATTSET, timings->tset_att); 301 297 patt |= FIELD_PREP(FMC2_PATT_ATTWAIT, timings->twait); 302 298 patt |= FIELD_PREP(FMC2_PATT_ATTHOLD, timings->thold_att); 303 299 patt |= FIELD_PREP(FMC2_PATT_ATTHIZ, timings->thiz); 304 - 305 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 306 - writel_relaxed(pmem, nfc->io_base + FMC2_PMEM); 307 - writel_relaxed(patt, nfc->io_base + FMC2_PATT); 300 + regmap_write(nfc->regmap, FMC2_PATT, patt); 308 301 } 309 302 310 303 static void stm32_fmc2_nfc_setup(struct nand_chip *chip) 311 304 { 312 305 struct stm32_fmc2_nfc *nfc = to_stm32_nfc(chip->controller); 313 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 306 + u32 pcr = 0, pcr_mask; 314 307 315 308 /* Configure ECC algorithm (default configuration is Hamming) */ 316 - pcr &= ~FMC2_PCR_ECCALG; 317 - pcr &= ~FMC2_PCR_BCHECC; 309 + pcr_mask = FMC2_PCR_ECCALG; 310 + pcr_mask |= FMC2_PCR_BCHECC; 318 311 if (chip->ecc.strength == FMC2_ECC_BCH8) { 319 312 pcr |= FMC2_PCR_ECCALG; 320 313 pcr |= FMC2_PCR_BCHECC; ··· 320 319 } 321 320 322 321 /* Set buswidth */ 323 - pcr &= ~FMC2_PCR_PWID; 322 + pcr_mask |= FMC2_PCR_PWID; 324 323 if (chip->options & NAND_BUSWIDTH_16) 325 324 pcr |= FIELD_PREP(FMC2_PCR_PWID, FMC2_PCR_PWID_BUSWIDTH_16); 326 325 327 326 /* Set ECC sector size */ 328 - pcr &= ~FMC2_PCR_ECCSS; 327 + pcr_mask |= FMC2_PCR_ECCSS; 329 328 pcr |= FIELD_PREP(FMC2_PCR_ECCSS, FMC2_PCR_ECCSS_512); 330 329 331 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 330 + regmap_update_bits(nfc->regmap, FMC2_PCR, pcr_mask, pcr); 332 331 } 333 332 334 333 static int stm32_fmc2_nfc_select_chip(struct nand_chip *chip, int chipnr) ··· 394 393 395 394 static void stm32_fmc2_nfc_set_buswidth_16(struct stm32_fmc2_nfc *nfc, bool set) 396 395 { 397 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 396 + u32 pcr; 398 397 399 - pcr &= ~FMC2_PCR_PWID; 400 - if (set) 401 - pcr |= FIELD_PREP(FMC2_PCR_PWID, FMC2_PCR_PWID_BUSWIDTH_16); 402 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 398 + pcr = set ? FIELD_PREP(FMC2_PCR_PWID, FMC2_PCR_PWID_BUSWIDTH_16) : 399 + FIELD_PREP(FMC2_PCR_PWID, FMC2_PCR_PWID_BUSWIDTH_8); 400 + 401 + regmap_update_bits(nfc->regmap, FMC2_PCR, FMC2_PCR_PWID, pcr); 403 402 } 404 403 405 404 static void stm32_fmc2_nfc_set_ecc(struct stm32_fmc2_nfc *nfc, bool enable) 406 405 { 407 - u32 pcr = readl(nfc->io_base + FMC2_PCR); 408 - 409 - pcr &= ~FMC2_PCR_ECCEN; 410 - if (enable) 411 - pcr |= FMC2_PCR_ECCEN; 412 - writel(pcr, nfc->io_base + FMC2_PCR); 406 + regmap_update_bits(nfc->regmap, FMC2_PCR, FMC2_PCR_ECCEN, 407 + enable ? FMC2_PCR_ECCEN : 0); 413 408 } 414 409 415 - static inline void stm32_fmc2_nfc_enable_seq_irq(struct stm32_fmc2_nfc *nfc) 410 + static void stm32_fmc2_nfc_enable_seq_irq(struct stm32_fmc2_nfc *nfc) 416 411 { 417 - u32 csqier = readl_relaxed(nfc->io_base + FMC2_CSQIER); 418 - 419 - csqier |= FMC2_CSQIER_TCIE; 420 - 421 412 nfc->irq_state = FMC2_IRQ_SEQ; 422 413 423 - writel_relaxed(csqier, nfc->io_base + FMC2_CSQIER); 414 + regmap_update_bits(nfc->regmap, FMC2_CSQIER, 415 + FMC2_CSQIER_TCIE, FMC2_CSQIER_TCIE); 424 416 } 425 417 426 - static inline void stm32_fmc2_nfc_disable_seq_irq(struct stm32_fmc2_nfc *nfc) 418 + static void stm32_fmc2_nfc_disable_seq_irq(struct stm32_fmc2_nfc *nfc) 427 419 { 428 - u32 csqier = readl_relaxed(nfc->io_base + FMC2_CSQIER); 429 - 430 - csqier &= ~FMC2_CSQIER_TCIE; 431 - 432 - writel_relaxed(csqier, nfc->io_base + FMC2_CSQIER); 420 + regmap_update_bits(nfc->regmap, FMC2_CSQIER, FMC2_CSQIER_TCIE, 0); 433 421 434 422 nfc->irq_state = FMC2_IRQ_UNKNOWN; 435 423 } 436 424 437 - static inline void stm32_fmc2_nfc_clear_seq_irq(struct stm32_fmc2_nfc *nfc) 425 + static void stm32_fmc2_nfc_clear_seq_irq(struct stm32_fmc2_nfc *nfc) 438 426 { 439 - writel_relaxed(FMC2_CSQICR_CLEAR_IRQ, nfc->io_base + FMC2_CSQICR); 427 + regmap_write(nfc->regmap, FMC2_CSQICR, FMC2_CSQICR_CLEAR_IRQ); 440 428 } 441 429 442 - static inline void stm32_fmc2_nfc_enable_bch_irq(struct stm32_fmc2_nfc *nfc, 443 - int mode) 430 + static void stm32_fmc2_nfc_enable_bch_irq(struct stm32_fmc2_nfc *nfc, int mode) 444 431 { 445 - u32 bchier = readl_relaxed(nfc->io_base + FMC2_BCHIER); 446 - 447 - if (mode == NAND_ECC_WRITE) 448 - bchier |= FMC2_BCHIER_EPBRIE; 449 - else 450 - bchier |= FMC2_BCHIER_DERIE; 451 - 452 432 nfc->irq_state = FMC2_IRQ_BCH; 453 433 454 - writel_relaxed(bchier, nfc->io_base + FMC2_BCHIER); 434 + if (mode == NAND_ECC_WRITE) 435 + regmap_update_bits(nfc->regmap, FMC2_BCHIER, 436 + FMC2_BCHIER_EPBRIE, FMC2_BCHIER_EPBRIE); 437 + else 438 + regmap_update_bits(nfc->regmap, FMC2_BCHIER, 439 + FMC2_BCHIER_DERIE, FMC2_BCHIER_DERIE); 455 440 } 456 441 457 - static inline void stm32_fmc2_nfc_disable_bch_irq(struct stm32_fmc2_nfc *nfc) 442 + static void stm32_fmc2_nfc_disable_bch_irq(struct stm32_fmc2_nfc *nfc) 458 443 { 459 - u32 bchier = readl_relaxed(nfc->io_base + FMC2_BCHIER); 460 - 461 - bchier &= ~FMC2_BCHIER_DERIE; 462 - bchier &= ~FMC2_BCHIER_EPBRIE; 463 - 464 - writel_relaxed(bchier, nfc->io_base + FMC2_BCHIER); 444 + regmap_update_bits(nfc->regmap, FMC2_BCHIER, 445 + FMC2_BCHIER_DERIE | FMC2_BCHIER_EPBRIE, 0); 465 446 466 447 nfc->irq_state = FMC2_IRQ_UNKNOWN; 467 448 } 468 449 469 - static inline void stm32_fmc2_nfc_clear_bch_irq(struct stm32_fmc2_nfc *nfc) 450 + static void stm32_fmc2_nfc_clear_bch_irq(struct stm32_fmc2_nfc *nfc) 470 451 { 471 - writel_relaxed(FMC2_BCHICR_CLEAR_IRQ, nfc->io_base + FMC2_BCHICR); 452 + regmap_write(nfc->regmap, FMC2_BCHICR, FMC2_BCHICR_CLEAR_IRQ); 472 453 } 473 454 474 455 /* ··· 464 481 stm32_fmc2_nfc_set_ecc(nfc, false); 465 482 466 483 if (chip->ecc.strength != FMC2_ECC_HAM) { 467 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 468 - 469 - if (mode == NAND_ECC_WRITE) 470 - pcr |= FMC2_PCR_WEN; 471 - else 472 - pcr &= ~FMC2_PCR_WEN; 473 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 484 + regmap_update_bits(nfc->regmap, FMC2_PCR, FMC2_PCR_WEN, 485 + mode == NAND_ECC_WRITE ? FMC2_PCR_WEN : 0); 474 486 475 487 reinit_completion(&nfc->complete); 476 488 stm32_fmc2_nfc_clear_bch_irq(nfc); ··· 480 502 * ECC is 3 bytes for 512 bytes of data (supports error correction up to 481 503 * max of 1-bit) 482 504 */ 483 - static inline void stm32_fmc2_nfc_ham_set_ecc(const u32 ecc_sta, u8 *ecc) 505 + static void stm32_fmc2_nfc_ham_set_ecc(const u32 ecc_sta, u8 *ecc) 484 506 { 485 507 ecc[0] = ecc_sta; 486 508 ecc[1] = ecc_sta >> 8; ··· 494 516 u32 sr, heccr; 495 517 int ret; 496 518 497 - ret = readl_relaxed_poll_timeout(nfc->io_base + FMC2_SR, 498 - sr, sr & FMC2_SR_NWRF, 1, 499 - 1000 * FMC2_TIMEOUT_MS); 519 + ret = regmap_read_poll_timeout(nfc->regmap, FMC2_SR, sr, 520 + sr & FMC2_SR_NWRF, 1, 521 + 1000 * FMC2_TIMEOUT_MS); 500 522 if (ret) { 501 523 dev_err(nfc->dev, "ham timeout\n"); 502 524 return ret; 503 525 } 504 526 505 - heccr = readl_relaxed(nfc->io_base + FMC2_HECCR); 527 + regmap_read(nfc->regmap, FMC2_HECCR, &heccr); 506 528 stm32_fmc2_nfc_ham_set_ecc(heccr, ecc); 507 529 stm32_fmc2_nfc_set_ecc(nfc, false); 508 530 ··· 581 603 } 582 604 583 605 /* Read parity bits */ 584 - bchpbr = readl_relaxed(nfc->io_base + FMC2_BCHPBR1); 606 + regmap_read(nfc->regmap, FMC2_BCHPBR1, &bchpbr); 585 607 ecc[0] = bchpbr; 586 608 ecc[1] = bchpbr >> 8; 587 609 ecc[2] = bchpbr >> 16; 588 610 ecc[3] = bchpbr >> 24; 589 611 590 - bchpbr = readl_relaxed(nfc->io_base + FMC2_BCHPBR2); 612 + regmap_read(nfc->regmap, FMC2_BCHPBR2, &bchpbr); 591 613 ecc[4] = bchpbr; 592 614 ecc[5] = bchpbr >> 8; 593 615 ecc[6] = bchpbr >> 16; ··· 595 617 if (chip->ecc.strength == FMC2_ECC_BCH8) { 596 618 ecc[7] = bchpbr >> 24; 597 619 598 - bchpbr = readl_relaxed(nfc->io_base + FMC2_BCHPBR3); 620 + regmap_read(nfc->regmap, FMC2_BCHPBR3, &bchpbr); 599 621 ecc[8] = bchpbr; 600 622 ecc[9] = bchpbr >> 8; 601 623 ecc[10] = bchpbr >> 16; 602 624 ecc[11] = bchpbr >> 24; 603 625 604 - bchpbr = readl_relaxed(nfc->io_base + FMC2_BCHPBR4); 626 + regmap_read(nfc->regmap, FMC2_BCHPBR4, &bchpbr); 605 627 ecc[12] = bchpbr; 606 628 } 607 629 ··· 663 685 return -ETIMEDOUT; 664 686 } 665 687 666 - ecc_sta[0] = readl_relaxed(nfc->io_base + FMC2_BCHDSR0); 667 - ecc_sta[1] = readl_relaxed(nfc->io_base + FMC2_BCHDSR1); 668 - ecc_sta[2] = readl_relaxed(nfc->io_base + FMC2_BCHDSR2); 669 - ecc_sta[3] = readl_relaxed(nfc->io_base + FMC2_BCHDSR3); 670 - ecc_sta[4] = readl_relaxed(nfc->io_base + FMC2_BCHDSR4); 688 + regmap_bulk_read(nfc->regmap, FMC2_BCHDSR0, ecc_sta, 5); 671 689 672 690 stm32_fmc2_nfc_set_ecc(nfc, false); 673 691 ··· 738 764 { 739 765 struct stm32_fmc2_nfc *nfc = to_stm32_nfc(chip->controller); 740 766 struct mtd_info *mtd = nand_to_mtd(chip); 741 - u32 csqcfgr1, csqcfgr2, csqcfgr3; 742 - u32 csqar1, csqar2; 743 767 u32 ecc_offset = mtd->writesize + FMC2_BBM_LEN; 744 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 768 + /* 769 + * cfg[0] => csqcfgr1, cfg[1] => csqcfgr2, cfg[2] => csqcfgr3 770 + * cfg[3] => csqar1, cfg[4] => csqar2 771 + */ 772 + u32 cfg[5]; 745 773 746 - if (write_data) 747 - pcr |= FMC2_PCR_WEN; 748 - else 749 - pcr &= ~FMC2_PCR_WEN; 750 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 774 + regmap_update_bits(nfc->regmap, FMC2_PCR, FMC2_PCR_WEN, 775 + write_data ? FMC2_PCR_WEN : 0); 751 776 752 777 /* 753 778 * - Set Program Page/Page Read command 754 779 * - Enable DMA request data 755 780 * - Set timings 756 781 */ 757 - csqcfgr1 = FMC2_CSQCFGR1_DMADEN | FMC2_CSQCFGR1_CMD1T; 782 + cfg[0] = FMC2_CSQCFGR1_DMADEN | FMC2_CSQCFGR1_CMD1T; 758 783 if (write_data) 759 - csqcfgr1 |= FIELD_PREP(FMC2_CSQCFGR1_CMD1, NAND_CMD_SEQIN); 784 + cfg[0] |= FIELD_PREP(FMC2_CSQCFGR1_CMD1, NAND_CMD_SEQIN); 760 785 else 761 - csqcfgr1 |= FIELD_PREP(FMC2_CSQCFGR1_CMD1, NAND_CMD_READ0) | 762 - FMC2_CSQCFGR1_CMD2EN | 763 - FIELD_PREP(FMC2_CSQCFGR1_CMD2, NAND_CMD_READSTART) | 764 - FMC2_CSQCFGR1_CMD2T; 786 + cfg[0] |= FIELD_PREP(FMC2_CSQCFGR1_CMD1, NAND_CMD_READ0) | 787 + FMC2_CSQCFGR1_CMD2EN | 788 + FIELD_PREP(FMC2_CSQCFGR1_CMD2, NAND_CMD_READSTART) | 789 + FMC2_CSQCFGR1_CMD2T; 765 790 766 791 /* 767 792 * - Set Random Data Input/Random Data Read command ··· 769 796 * - Set timings 770 797 */ 771 798 if (write_data) 772 - csqcfgr2 = FIELD_PREP(FMC2_CSQCFGR2_RCMD1, NAND_CMD_RNDIN); 799 + cfg[1] = FIELD_PREP(FMC2_CSQCFGR2_RCMD1, NAND_CMD_RNDIN); 773 800 else 774 - csqcfgr2 = FIELD_PREP(FMC2_CSQCFGR2_RCMD1, NAND_CMD_RNDOUT) | 775 - FMC2_CSQCFGR2_RCMD2EN | 776 - FIELD_PREP(FMC2_CSQCFGR2_RCMD2, 777 - NAND_CMD_RNDOUTSTART) | 778 - FMC2_CSQCFGR2_RCMD1T | 779 - FMC2_CSQCFGR2_RCMD2T; 801 + cfg[1] = FIELD_PREP(FMC2_CSQCFGR2_RCMD1, NAND_CMD_RNDOUT) | 802 + FMC2_CSQCFGR2_RCMD2EN | 803 + FIELD_PREP(FMC2_CSQCFGR2_RCMD2, NAND_CMD_RNDOUTSTART) | 804 + FMC2_CSQCFGR2_RCMD1T | 805 + FMC2_CSQCFGR2_RCMD2T; 780 806 if (!raw) { 781 - csqcfgr2 |= write_data ? 0 : FMC2_CSQCFGR2_DMASEN; 782 - csqcfgr2 |= FMC2_CSQCFGR2_SQSDTEN; 807 + cfg[1] |= write_data ? 0 : FMC2_CSQCFGR2_DMASEN; 808 + cfg[1] |= FMC2_CSQCFGR2_SQSDTEN; 783 809 } 784 810 785 811 /* 786 812 * - Set the number of sectors to be written 787 813 * - Set timings 788 814 */ 789 - csqcfgr3 = FIELD_PREP(FMC2_CSQCFGR3_SNBR, chip->ecc.steps - 1); 815 + cfg[2] = FIELD_PREP(FMC2_CSQCFGR3_SNBR, chip->ecc.steps - 1); 790 816 if (write_data) { 791 - csqcfgr3 |= FMC2_CSQCFGR3_RAC2T; 817 + cfg[2] |= FMC2_CSQCFGR3_RAC2T; 792 818 if (chip->options & NAND_ROW_ADDR_3) 793 - csqcfgr3 |= FMC2_CSQCFGR3_AC5T; 819 + cfg[2] |= FMC2_CSQCFGR3_AC5T; 794 820 else 795 - csqcfgr3 |= FMC2_CSQCFGR3_AC4T; 821 + cfg[2] |= FMC2_CSQCFGR3_AC4T; 796 822 } 797 823 798 824 /* ··· 799 827 * Byte 1 and byte 2 => column, we start at 0x0 800 828 * Byte 3 and byte 4 => page 801 829 */ 802 - csqar1 = FIELD_PREP(FMC2_CSQCAR1_ADDC3, page); 803 - csqar1 |= FIELD_PREP(FMC2_CSQCAR1_ADDC4, page >> 8); 830 + cfg[3] = FIELD_PREP(FMC2_CSQCAR1_ADDC3, page); 831 + cfg[3] |= FIELD_PREP(FMC2_CSQCAR1_ADDC4, page >> 8); 804 832 805 833 /* 806 834 * - Set chip enable number ··· 808 836 * - Calculate the number of address cycles to be issued 809 837 * - Set byte 5 of address cycle if needed 810 838 */ 811 - csqar2 = FIELD_PREP(FMC2_CSQCAR2_NANDCEN, nfc->cs_sel); 839 + cfg[4] = FIELD_PREP(FMC2_CSQCAR2_NANDCEN, nfc->cs_sel); 812 840 if (chip->options & NAND_BUSWIDTH_16) 813 - csqar2 |= FIELD_PREP(FMC2_CSQCAR2_SAO, ecc_offset >> 1); 841 + cfg[4] |= FIELD_PREP(FMC2_CSQCAR2_SAO, ecc_offset >> 1); 814 842 else 815 - csqar2 |= FIELD_PREP(FMC2_CSQCAR2_SAO, ecc_offset); 843 + cfg[4] |= FIELD_PREP(FMC2_CSQCAR2_SAO, ecc_offset); 816 844 if (chip->options & NAND_ROW_ADDR_3) { 817 - csqcfgr1 |= FIELD_PREP(FMC2_CSQCFGR1_ACYNBR, 5); 818 - csqar2 |= FIELD_PREP(FMC2_CSQCAR2_ADDC5, page >> 16); 845 + cfg[0] |= FIELD_PREP(FMC2_CSQCFGR1_ACYNBR, 5); 846 + cfg[4] |= FIELD_PREP(FMC2_CSQCAR2_ADDC5, page >> 16); 819 847 } else { 820 - csqcfgr1 |= FIELD_PREP(FMC2_CSQCFGR1_ACYNBR, 4); 848 + cfg[0] |= FIELD_PREP(FMC2_CSQCFGR1_ACYNBR, 4); 821 849 } 822 850 823 - writel_relaxed(csqcfgr1, nfc->io_base + FMC2_CSQCFGR1); 824 - writel_relaxed(csqcfgr2, nfc->io_base + FMC2_CSQCFGR2); 825 - writel_relaxed(csqcfgr3, nfc->io_base + FMC2_CSQCFGR3); 826 - writel_relaxed(csqar1, nfc->io_base + FMC2_CSQAR1); 827 - writel_relaxed(csqar2, nfc->io_base + FMC2_CSQAR2); 851 + regmap_bulk_write(nfc->regmap, FMC2_CSQCFGR1, cfg, 5); 828 852 } 829 853 830 854 static void stm32_fmc2_nfc_dma_callback(void *arg) ··· 838 870 struct dma_chan *dma_ch = nfc->dma_rx_ch; 839 871 enum dma_data_direction dma_data_dir = DMA_FROM_DEVICE; 840 872 enum dma_transfer_direction dma_transfer_dir = DMA_DEV_TO_MEM; 841 - u32 csqcr = readl_relaxed(nfc->io_base + FMC2_CSQCR); 842 873 int eccsteps = chip->ecc.steps; 843 874 int eccsize = chip->ecc.size; 844 875 unsigned long timeout = msecs_to_jiffies(FMC2_TIMEOUT_MS); ··· 915 948 stm32_fmc2_nfc_enable_seq_irq(nfc); 916 949 917 950 /* Start the transfer */ 918 - csqcr |= FMC2_CSQCR_CSQSTART; 919 - writel_relaxed(csqcr, nfc->io_base + FMC2_CSQCR); 951 + regmap_update_bits(nfc->regmap, FMC2_CSQCR, 952 + FMC2_CSQCR_CSQSTART, FMC2_CSQCR_CSQSTART); 920 953 921 954 /* Wait end of sequencer transfer */ 922 955 if (!wait_for_completion_timeout(&nfc->complete, timeout)) { ··· 1009 1042 } 1010 1043 1011 1044 /* Get a status indicating which sectors have errors */ 1012 - static inline u16 stm32_fmc2_nfc_get_mapping_status(struct stm32_fmc2_nfc *nfc) 1045 + static u16 stm32_fmc2_nfc_get_mapping_status(struct stm32_fmc2_nfc *nfc) 1013 1046 { 1014 - u32 csqemsr = readl_relaxed(nfc->io_base + FMC2_CSQEMSR); 1047 + u32 csqemsr; 1015 1048 1016 - return csqemsr & FMC2_CSQEMSR_SEM; 1049 + regmap_read(nfc->regmap, FMC2_CSQEMSR, &csqemsr); 1050 + 1051 + return FIELD_GET(FMC2_CSQEMSR_SEM, csqemsr); 1017 1052 } 1018 1053 1019 1054 static int stm32_fmc2_nfc_seq_correct(struct nand_chip *chip, u8 *dat, ··· 1271 1302 u32 isr, sr; 1272 1303 1273 1304 /* Check if there is no pending requests to the NAND flash */ 1274 - if (readl_relaxed_poll_timeout_atomic(nfc->io_base + FMC2_SR, sr, 1275 - sr & FMC2_SR_NWRF, 1, 1276 - 1000 * FMC2_TIMEOUT_MS)) 1305 + if (regmap_read_poll_timeout(nfc->regmap, FMC2_SR, sr, 1306 + sr & FMC2_SR_NWRF, 1, 1307 + 1000 * FMC2_TIMEOUT_MS)) 1277 1308 dev_warn(nfc->dev, "Waitrdy timeout\n"); 1278 1309 1279 1310 /* Wait tWB before R/B# signal is low */ 1280 - timings = nand_get_sdr_timings(&chip->data_interface); 1311 + timings = nand_get_sdr_timings(nand_get_interface_config(chip)); 1281 1312 ndelay(PSEC_TO_NSEC(timings->tWB_max)); 1282 1313 1283 1314 /* R/B# signal is low, clear high level flag */ 1284 - writel_relaxed(FMC2_ICR_CIHLF, nfc->io_base + FMC2_ICR); 1315 + regmap_write(nfc->regmap, FMC2_ICR, FMC2_ICR_CIHLF); 1285 1316 1286 1317 /* Wait R/B# signal is high */ 1287 - return readl_relaxed_poll_timeout_atomic(nfc->io_base + FMC2_ISR, 1288 - isr, isr & FMC2_ISR_IHLF, 1289 - 5, 1000 * timeout_ms); 1318 + return regmap_read_poll_timeout(nfc->regmap, FMC2_ISR, isr, 1319 + isr & FMC2_ISR_IHLF, 5, 1320 + 1000 * FMC2_TIMEOUT_MS); 1290 1321 } 1291 1322 1292 1323 static int stm32_fmc2_nfc_exec_op(struct nand_chip *chip, ··· 1344 1375 1345 1376 static void stm32_fmc2_nfc_init(struct stm32_fmc2_nfc *nfc) 1346 1377 { 1347 - u32 pcr = readl_relaxed(nfc->io_base + FMC2_PCR); 1348 - u32 bcr1 = readl_relaxed(nfc->io_base + FMC2_BCR1); 1378 + u32 pcr; 1379 + 1380 + regmap_read(nfc->regmap, FMC2_PCR, &pcr); 1349 1381 1350 1382 /* Set CS used to undefined */ 1351 1383 nfc->cs_sel = -1; ··· 1377 1407 pcr |= FIELD_PREP(FMC2_PCR_TAR, FMC2_PCR_TAR_DEFAULT); 1378 1408 1379 1409 /* Enable FMC2 controller */ 1380 - bcr1 |= FMC2_BCR1_FMC2EN; 1410 + if (nfc->dev == nfc->cdev) 1411 + regmap_update_bits(nfc->regmap, FMC2_BCR1, 1412 + FMC2_BCR1_FMC2EN, FMC2_BCR1_FMC2EN); 1381 1413 1382 - writel_relaxed(bcr1, nfc->io_base + FMC2_BCR1); 1383 - writel_relaxed(pcr, nfc->io_base + FMC2_PCR); 1384 - writel_relaxed(FMC2_PMEM_DEFAULT, nfc->io_base + FMC2_PMEM); 1385 - writel_relaxed(FMC2_PATT_DEFAULT, nfc->io_base + FMC2_PATT); 1414 + regmap_write(nfc->regmap, FMC2_PCR, pcr); 1415 + regmap_write(nfc->regmap, FMC2_PMEM, FMC2_PMEM_DEFAULT); 1416 + regmap_write(nfc->regmap, FMC2_PATT, FMC2_PATT_DEFAULT); 1386 1417 } 1387 1418 1388 1419 static void stm32_fmc2_nfc_calc_timings(struct nand_chip *chip, ··· 1517 1546 } 1518 1547 1519 1548 static int stm32_fmc2_nfc_setup_interface(struct nand_chip *chip, int chipnr, 1520 - const struct nand_data_interface *conf) 1549 + const struct nand_interface_config *conf) 1521 1550 { 1522 1551 const struct nand_sdr_timings *sdrt; 1523 1552 ··· 1541 1570 nfc->dma_tx_ch = dma_request_chan(nfc->dev, "tx"); 1542 1571 if (IS_ERR(nfc->dma_tx_ch)) { 1543 1572 ret = PTR_ERR(nfc->dma_tx_ch); 1544 - if (ret != -ENODEV) 1573 + if (ret != -ENODEV && ret != -EPROBE_DEFER) 1545 1574 dev_err(nfc->dev, 1546 1575 "failed to request tx DMA channel: %d\n", ret); 1547 1576 nfc->dma_tx_ch = NULL; ··· 1551 1580 nfc->dma_rx_ch = dma_request_chan(nfc->dev, "rx"); 1552 1581 if (IS_ERR(nfc->dma_rx_ch)) { 1553 1582 ret = PTR_ERR(nfc->dma_rx_ch); 1554 - if (ret != -ENODEV) 1583 + if (ret != -ENODEV && ret != -EPROBE_DEFER) 1555 1584 dev_err(nfc->dev, 1556 1585 "failed to request rx DMA channel: %d\n", ret); 1557 1586 nfc->dma_rx_ch = NULL; ··· 1561 1590 nfc->dma_ecc_ch = dma_request_chan(nfc->dev, "ecc"); 1562 1591 if (IS_ERR(nfc->dma_ecc_ch)) { 1563 1592 ret = PTR_ERR(nfc->dma_ecc_ch); 1564 - if (ret != -ENODEV) 1593 + if (ret != -ENODEV && ret != -EPROBE_DEFER) 1565 1594 dev_err(nfc->dev, 1566 1595 "failed to request ecc DMA channel: %d\n", ret); 1567 1596 nfc->dma_ecc_ch = NULL; ··· 1735 1764 static const struct nand_controller_ops stm32_fmc2_nfc_controller_ops = { 1736 1765 .attach_chip = stm32_fmc2_nfc_attach_chip, 1737 1766 .exec_op = stm32_fmc2_nfc_exec_op, 1738 - .setup_data_interface = stm32_fmc2_nfc_setup_interface, 1767 + .setup_interface = stm32_fmc2_nfc_setup_interface, 1739 1768 }; 1740 1769 1741 1770 static int stm32_fmc2_nfc_parse_child(struct stm32_fmc2_nfc *nfc, ··· 1809 1838 return ret; 1810 1839 } 1811 1840 1841 + static int stm32_fmc2_nfc_set_cdev(struct stm32_fmc2_nfc *nfc) 1842 + { 1843 + struct device *dev = nfc->dev; 1844 + bool ebi_found = false; 1845 + 1846 + if (dev->parent && of_device_is_compatible(dev->parent->of_node, 1847 + "st,stm32mp1-fmc2-ebi")) 1848 + ebi_found = true; 1849 + 1850 + if (of_device_is_compatible(dev->of_node, "st,stm32mp1-fmc2-nfc")) { 1851 + if (ebi_found) { 1852 + nfc->cdev = dev->parent; 1853 + 1854 + return 0; 1855 + } 1856 + 1857 + return -EINVAL; 1858 + } 1859 + 1860 + if (ebi_found) 1861 + return -EINVAL; 1862 + 1863 + nfc->cdev = dev; 1864 + 1865 + return 0; 1866 + } 1867 + 1812 1868 static int stm32_fmc2_nfc_probe(struct platform_device *pdev) 1813 1869 { 1814 1870 struct device *dev = &pdev->dev; ··· 1845 1847 struct resource *res; 1846 1848 struct mtd_info *mtd; 1847 1849 struct nand_chip *chip; 1850 + struct resource cres; 1848 1851 int chip_cs, mem_region, ret, irq; 1852 + int start_region = 0; 1849 1853 1850 1854 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); 1851 1855 if (!nfc) ··· 1857 1857 nand_controller_init(&nfc->base); 1858 1858 nfc->base.ops = &stm32_fmc2_nfc_controller_ops; 1859 1859 1860 + ret = stm32_fmc2_nfc_set_cdev(nfc); 1861 + if (ret) 1862 + return ret; 1863 + 1860 1864 ret = stm32_fmc2_nfc_parse_dt(nfc); 1861 1865 if (ret) 1862 1866 return ret; 1863 1867 1864 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1865 - nfc->io_base = devm_ioremap_resource(dev, res); 1866 - if (IS_ERR(nfc->io_base)) 1867 - return PTR_ERR(nfc->io_base); 1868 + ret = of_address_to_resource(nfc->cdev->of_node, 0, &cres); 1869 + if (ret) 1870 + return ret; 1868 1871 1869 - nfc->io_phys_addr = res->start; 1872 + nfc->io_phys_addr = cres.start; 1870 1873 1871 - for (chip_cs = 0, mem_region = 1; chip_cs < FMC2_MAX_CE; 1874 + nfc->regmap = device_node_to_regmap(nfc->cdev->of_node); 1875 + if (IS_ERR(nfc->regmap)) 1876 + return PTR_ERR(nfc->regmap); 1877 + 1878 + if (nfc->dev == nfc->cdev) 1879 + start_region = 1; 1880 + 1881 + for (chip_cs = 0, mem_region = start_region; chip_cs < FMC2_MAX_CE; 1872 1882 chip_cs++, mem_region += 3) { 1873 1883 if (!(nfc->cs_assigned & BIT(chip_cs))) 1874 1884 continue; ··· 1916 1906 1917 1907 init_completion(&nfc->complete); 1918 1908 1919 - nfc->clk = devm_clk_get(dev, NULL); 1909 + nfc->clk = devm_clk_get(nfc->cdev, NULL); 1920 1910 if (IS_ERR(nfc->clk)) 1921 1911 return PTR_ERR(nfc->clk); 1922 1912 ··· 2057 2047 2058 2048 static const struct of_device_id stm32_fmc2_nfc_match[] = { 2059 2049 {.compatible = "st,stm32mp15-fmc2"}, 2050 + {.compatible = "st,stm32mp1-fmc2-nfc"}, 2060 2051 {} 2061 2052 }; 2062 2053 MODULE_DEVICE_TABLE(of, stm32_fmc2_nfc_match);
+3 -3
drivers/mtd/nand/raw/sunxi_nand.c
··· 1376 1376 #define sunxi_nand_lookup_timing(l, p, c) \ 1377 1377 _sunxi_nand_lookup_timing(l, ARRAY_SIZE(l), p, c) 1378 1378 1379 - static int sunxi_nfc_setup_data_interface(struct nand_chip *nand, int csline, 1380 - const struct nand_data_interface *conf) 1379 + static int sunxi_nfc_setup_interface(struct nand_chip *nand, int csline, 1380 + const struct nand_interface_config *conf) 1381 1381 { 1382 1382 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand); 1383 1383 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); ··· 1920 1920 1921 1921 static const struct nand_controller_ops sunxi_nand_controller_ops = { 1922 1922 .attach_chip = sunxi_nand_attach_chip, 1923 - .setup_data_interface = sunxi_nfc_setup_data_interface, 1923 + .setup_interface = sunxi_nfc_setup_interface, 1924 1924 .exec_op = sunxi_nfc_exec_op, 1925 1925 }; 1926 1926
+91 -58
drivers/mtd/nand/raw/tango_nand.c
··· 113 113 114 114 #define TIMING(t0, t1, t2, t3) ((t0) << 24 | (t1) << 16 | (t2) << 8 | (t3)) 115 115 116 - static void tango_cmd_ctrl(struct nand_chip *chip, int dat, unsigned int ctrl) 117 - { 118 - struct tango_chip *tchip = to_tango_chip(chip); 119 - 120 - if (ctrl & NAND_CLE) 121 - writeb_relaxed(dat, tchip->base + PBUS_CMD); 122 - 123 - if (ctrl & NAND_ALE) 124 - writeb_relaxed(dat, tchip->base + PBUS_ADDR); 125 - } 126 - 127 - static int tango_dev_ready(struct nand_chip *chip) 128 - { 129 - struct tango_nfc *nfc = to_tango_nfc(chip->controller); 130 - 131 - return readl_relaxed(nfc->pbus_base + PBUS_CS_CTRL) & PBUS_IORDY; 132 - } 133 - 134 - static u8 tango_read_byte(struct nand_chip *chip) 135 - { 136 - struct tango_chip *tchip = to_tango_chip(chip); 137 - 138 - return readb_relaxed(tchip->base + PBUS_DATA); 139 - } 140 - 141 - static void tango_read_buf(struct nand_chip *chip, u8 *buf, int len) 142 - { 143 - struct tango_chip *tchip = to_tango_chip(chip); 144 - 145 - ioread8_rep(tchip->base + PBUS_DATA, buf, len); 146 - } 147 - 148 - static void tango_write_buf(struct nand_chip *chip, const u8 *buf, int len) 149 - { 150 - struct tango_chip *tchip = to_tango_chip(chip); 151 - 152 - iowrite8_rep(tchip->base + PBUS_DATA, buf, len); 153 - } 154 - 155 - static void tango_select_chip(struct nand_chip *chip, int idx) 116 + static void tango_select_target(struct nand_chip *chip, unsigned int cs) 156 117 { 157 118 struct tango_nfc *nfc = to_tango_nfc(chip->controller); 158 119 struct tango_chip *tchip = to_tango_chip(chip); 159 - 160 - if (idx < 0) 161 - return; /* No "chip unselect" function */ 162 120 163 121 writel_relaxed(tchip->timing1, nfc->reg_base + NFC_TIMING1); 164 122 writel_relaxed(tchip->timing2, nfc->reg_base + NFC_TIMING2); ··· 124 166 writel_relaxed(tchip->pkt_0_cfg, nfc->reg_base + NFC_PKT_0_CFG); 125 167 writel_relaxed(tchip->pkt_n_cfg, nfc->reg_base + NFC_PKT_N_CFG); 126 168 writel_relaxed(tchip->bb_cfg, nfc->reg_base + NFC_BB_CFG); 169 + } 170 + 171 + static int tango_waitrdy(struct nand_chip *chip, unsigned int timeout_ms) 172 + { 173 + struct tango_nfc *nfc = to_tango_nfc(chip->controller); 174 + u32 status; 175 + 176 + return readl_relaxed_poll_timeout(nfc->pbus_base + PBUS_CS_CTRL, 177 + status, status & PBUS_IORDY, 20, 178 + timeout_ms); 179 + } 180 + 181 + static int tango_exec_instr(struct nand_chip *chip, 182 + const struct nand_op_instr *instr) 183 + { 184 + struct tango_chip *tchip = to_tango_chip(chip); 185 + unsigned int i; 186 + 187 + switch (instr->type) { 188 + case NAND_OP_CMD_INSTR: 189 + writeb_relaxed(instr->ctx.cmd.opcode, tchip->base + PBUS_CMD); 190 + return 0; 191 + case NAND_OP_ADDR_INSTR: 192 + for (i = 0; i < instr->ctx.addr.naddrs; i++) 193 + writeb_relaxed(instr->ctx.addr.addrs[i], 194 + tchip->base + PBUS_ADDR); 195 + return 0; 196 + case NAND_OP_DATA_IN_INSTR: 197 + ioread8_rep(tchip->base + PBUS_DATA, instr->ctx.data.buf.in, 198 + instr->ctx.data.len); 199 + return 0; 200 + case NAND_OP_DATA_OUT_INSTR: 201 + iowrite8_rep(tchip->base + PBUS_DATA, instr->ctx.data.buf.out, 202 + instr->ctx.data.len); 203 + return 0; 204 + case NAND_OP_WAITRDY_INSTR: 205 + return tango_waitrdy(chip, 206 + instr->ctx.waitrdy.timeout_ms); 207 + default: 208 + break; 209 + } 210 + 211 + return -EINVAL; 212 + } 213 + 214 + static int tango_exec_op(struct nand_chip *chip, 215 + const struct nand_operation *op, 216 + bool check_only) 217 + { 218 + unsigned int i; 219 + int ret = 0; 220 + 221 + if (check_only) 222 + return 0; 223 + 224 + tango_select_target(chip, op->cs); 225 + for (i = 0; i < op->ninstrs; i++) { 226 + ret = tango_exec_instr(chip, &op->instrs[i]); 227 + if (ret) 228 + break; 229 + } 230 + 231 + return ret; 127 232 } 128 233 129 234 /* ··· 300 279 struct tango_nfc *nfc = to_tango_nfc(chip->controller); 301 280 int err, res, len = mtd->writesize; 302 281 282 + tango_select_target(chip, chip->cur_cs); 303 283 if (oob_required) 304 284 chip->ecc.read_oob(chip, page); 305 285 ··· 322 300 { 323 301 struct mtd_info *mtd = nand_to_mtd(chip); 324 302 struct tango_nfc *nfc = to_tango_nfc(chip->controller); 325 - int err, status, len = mtd->writesize; 303 + const struct nand_sdr_timings *timings; 304 + int err, len = mtd->writesize; 305 + u8 status; 326 306 327 307 /* Calling tango_write_oob() would send PAGEPROG twice */ 328 308 if (oob_required) 329 309 return -ENOTSUPP; 330 310 311 + tango_select_target(chip, chip->cur_cs); 331 312 writel_relaxed(0xffffffff, nfc->mem_base + METADATA); 332 313 err = do_dma(nfc, DMA_TO_DEVICE, NFC_WRITE, buf, len, page); 333 314 if (err) 334 315 return err; 335 316 336 - status = chip->legacy.waitfunc(chip); 337 - if (status & NAND_STATUS_FAIL) 338 - return -EIO; 317 + timings = nand_get_sdr_timings(nand_get_interface_config(chip)); 318 + err = tango_waitrdy(chip, PSEC_TO_MSEC(timings->tR_max)); 319 + if (err) 320 + return err; 339 321 340 - return 0; 322 + err = nand_status_op(chip, &status); 323 + if (err) 324 + return err; 325 + 326 + return (status & NAND_STATUS_FAIL) ? -EIO : 0; 341 327 } 342 328 343 329 static void aux_read(struct nand_chip *chip, u8 **buf, int len, int *pos) ··· 356 326 /* skip over "len" bytes */ 357 327 nand_change_read_column_op(chip, *pos, NULL, 0, false); 358 328 } else { 359 - tango_read_buf(chip, *buf, len); 329 + struct tango_chip *tchip = to_tango_chip(chip); 330 + 331 + ioread8_rep(tchip->base + PBUS_DATA, *buf, len); 360 332 *buf += len; 361 333 } 362 334 } ··· 371 339 /* skip over "len" bytes */ 372 340 nand_change_write_column_op(chip, *pos, NULL, 0, false); 373 341 } else { 374 - tango_write_buf(chip, *buf, len); 342 + struct tango_chip *tchip = to_tango_chip(chip); 343 + 344 + iowrite8_rep(tchip->base + PBUS_DATA, *buf, len); 375 345 *buf += len; 376 346 } 377 347 } ··· 454 420 static int tango_read_page_raw(struct nand_chip *chip, u8 *buf, 455 421 int oob_required, int page) 456 422 { 423 + tango_select_target(chip, chip->cur_cs); 457 424 nand_read_page_op(chip, page, 0, NULL, 0); 458 425 raw_read(chip, buf, chip->oob_poi); 459 426 return 0; ··· 463 428 static int tango_write_page_raw(struct nand_chip *chip, const u8 *buf, 464 429 int oob_required, int page) 465 430 { 431 + tango_select_target(chip, chip->cur_cs); 466 432 nand_prog_page_begin_op(chip, page, 0, NULL, 0); 467 433 raw_write(chip, buf, chip->oob_poi); 468 434 return nand_prog_page_end_op(chip); ··· 471 435 472 436 static int tango_read_oob(struct nand_chip *chip, int page) 473 437 { 438 + tango_select_target(chip, chip->cur_cs); 474 439 nand_read_page_op(chip, page, 0, NULL, 0); 475 440 raw_read(chip, NULL, chip->oob_poi); 476 441 return 0; ··· 479 442 480 443 static int tango_write_oob(struct nand_chip *chip, int page) 481 444 { 445 + tango_select_target(chip, chip->cur_cs); 482 446 nand_prog_page_begin_op(chip, page, 0, NULL, 0); 483 447 raw_write(chip, NULL, chip->oob_poi); 484 448 return nand_prog_page_end_op(chip); ··· 515 477 } 516 478 517 479 static int tango_set_timings(struct nand_chip *chip, int csline, 518 - const struct nand_data_interface *conf) 480 + const struct nand_interface_config *conf) 519 481 { 520 482 const struct nand_sdr_timings *sdr = nand_get_sdr_timings(conf); 521 483 struct tango_nfc *nfc = to_tango_nfc(chip->controller); ··· 565 527 566 528 static const struct nand_controller_ops tango_controller_ops = { 567 529 .attach_chip = tango_attach_chip, 568 - .setup_data_interface = tango_set_timings, 530 + .setup_interface = tango_set_timings, 531 + .exec_op = tango_exec_op, 569 532 }; 570 533 571 534 static int chip_init(struct device *dev, struct device_node *np) ··· 601 562 ecc = &chip->ecc; 602 563 mtd = nand_to_mtd(chip); 603 564 604 - chip->legacy.read_byte = tango_read_byte; 605 - chip->legacy.write_buf = tango_write_buf; 606 - chip->legacy.read_buf = tango_read_buf; 607 - chip->legacy.select_chip = tango_select_chip; 608 - chip->legacy.cmd_ctrl = tango_cmd_ctrl; 609 - chip->legacy.dev_ready = tango_dev_ready; 610 565 chip->options = NAND_USES_DMA | 611 566 NAND_NO_SUBPAGE_WRITE | 612 567 NAND_WAIT_TCCS;
+3 -3
drivers/mtd/nand/raw/tegra_nand.c
··· 813 813 writel_relaxed(reg, ctrl->regs + TIMING_2); 814 814 } 815 815 816 - static int tegra_nand_setup_data_interface(struct nand_chip *chip, int csline, 817 - const struct nand_data_interface *conf) 816 + static int tegra_nand_setup_interface(struct nand_chip *chip, int csline, 817 + const struct nand_interface_config *conf) 818 818 { 819 819 struct tegra_nand_controller *ctrl = to_tegra_ctrl(chip->controller); 820 820 const struct nand_sdr_timings *timings; ··· 1053 1053 static const struct nand_controller_ops tegra_nand_controller_ops = { 1054 1054 .attach_chip = &tegra_nand_attach_chip, 1055 1055 .exec_op = tegra_nand_exec_op, 1056 - .setup_data_interface = tegra_nand_setup_data_interface, 1056 + .setup_interface = tegra_nand_setup_interface, 1057 1057 }; 1058 1058 1059 1059 static int tegra_nand_chips_init(struct device *dev,
+12 -20
drivers/mtd/parsers/bcm63xxpart.c
··· 22 22 #include <linux/mtd/partitions.h> 23 23 #include <linux/of.h> 24 24 25 + #ifdef CONFIG_MIPS 26 + #include <asm/bootinfo.h> 27 + #include <asm/fw/cfe/cfe_api.h> 28 + #endif /* CONFIG_MIPS */ 29 + 25 30 #define BCM963XX_CFE_BLOCK_SIZE SZ_64K /* always at least 64KiB */ 26 31 27 32 #define BCM963XX_CFE_MAGIC_OFFSET 0x4e0 ··· 37 32 #define STR_NULL_TERMINATE(x) \ 38 33 do { char *_str = (x); _str[sizeof(x) - 1] = 0; } while (0) 39 34 40 - static int bcm63xx_detect_cfe(struct mtd_info *master) 35 + static inline int bcm63xx_detect_cfe(void) 41 36 { 42 - char buf[9]; 43 - int ret; 44 - size_t retlen; 37 + int ret = 0; 45 38 46 - ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen, 47 - (void *)buf); 48 - buf[retlen] = 0; 39 + #ifdef CONFIG_MIPS 40 + ret = (fw_arg3 == CFE_EPTSEAL); 41 + #endif /* CONFIG_MIPS */ 49 42 50 - if (ret) 51 - return ret; 52 - 53 - if (strncmp("cfe-v", buf, 5) == 0) 54 - return 0; 55 - 56 - /* very old CFE's do not have the cfe-v string, so check for magic */ 57 - ret = mtd_read(master, BCM963XX_CFE_MAGIC_OFFSET, 8, &retlen, 58 - (void *)buf); 59 - buf[retlen] = 0; 60 - 61 - return strncmp("CFE1CFE1", buf, 8); 43 + return ret; 62 44 } 63 45 64 46 static int bcm63xx_read_nvram(struct mtd_info *master, ··· 130 138 struct bcm963xx_nvram *nvram = NULL; 131 139 int ret; 132 140 133 - if (bcm63xx_detect_cfe(master)) 141 + if (!bcm63xx_detect_cfe()) 134 142 return -EINVAL; 135 143 136 144 nvram = vzalloc(sizeof(*nvram));
+2
drivers/mtd/spi-nor/controllers/intel-spi-pci.c
··· 68 68 { PCI_VDEVICE(INTEL, 0x06a4), (unsigned long)&bxt_info }, 69 69 { PCI_VDEVICE(INTEL, 0x18e0), (unsigned long)&bxt_info }, 70 70 { PCI_VDEVICE(INTEL, 0x19e0), (unsigned long)&bxt_info }, 71 + { PCI_VDEVICE(INTEL, 0x1bca), (unsigned long)&bxt_info }, 71 72 { PCI_VDEVICE(INTEL, 0x34a4), (unsigned long)&bxt_info }, 73 + { PCI_VDEVICE(INTEL, 0x43a4), (unsigned long)&cnl_info }, 72 74 { PCI_VDEVICE(INTEL, 0x4b24), (unsigned long)&bxt_info }, 73 75 { PCI_VDEVICE(INTEL, 0x4da4), (unsigned long)&bxt_info }, 74 76 { PCI_VDEVICE(INTEL, 0xa0a4), (unsigned long)&bxt_info },
+11 -2
drivers/mtd/spi-nor/controllers/intel-spi.c
··· 292 292 u32 val; 293 293 294 294 return readl_poll_timeout(ispi->base + HSFSTS_CTL, val, 295 - !(val & HSFSTS_CTL_SCIP), 40, 295 + !(val & HSFSTS_CTL_SCIP), 0, 296 296 INTEL_SPI_TIMEOUT * 1000); 297 297 } 298 298 ··· 301 301 u32 val; 302 302 303 303 return readl_poll_timeout(ispi->sregs + SSFSTS_CTL, val, 304 - !(val & SSFSTS_CTL_SCIP), 40, 304 + !(val & SSFSTS_CTL_SCIP), 0, 305 305 INTEL_SPI_TIMEOUT * 1000); 306 306 } 307 307 ··· 611 611 ispi->atomic_preopcode = opcode; 612 612 return 0; 613 613 } 614 + 615 + /* 616 + * We hope that HW sequencer will do the right thing automatically and 617 + * with the SW sequencer we cannot use preopcode anyway, so just ignore 618 + * the Write Disable operation and pretend it was completed 619 + * successfully. 620 + */ 621 + if (opcode == SPINOR_OP_WRDI) 622 + return 0; 614 623 615 624 writel(0, ispi->base + FADDR); 616 625
+38 -19
drivers/mtd/spi-nor/core.c
··· 1907 1907 } 1908 1908 1909 1909 /** 1910 - * spi_nor_sr1_bit6_quad_enable() - Set the Quad Enable BIT(6) in the Status 1911 - * Register 1. 1910 + * spi_nor_sr1_bit6_quad_enable() - Set/Unset the Quad Enable BIT(6) in the 1911 + * Status Register 1. 1912 1912 * @nor: pointer to a 'struct spi_nor' 1913 + * @enable: true to enable Quad mode, false to disable Quad mode. 1913 1914 * 1914 1915 * Bit 6 of the Status Register 1 is the QE bit for Macronix like QSPI memories. 1915 1916 * 1916 1917 * Return: 0 on success, -errno otherwise. 1917 1918 */ 1918 - int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor) 1919 + int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor, bool enable) 1919 1920 { 1920 1921 int ret; 1921 1922 ··· 1924 1923 if (ret) 1925 1924 return ret; 1926 1925 1927 - if (nor->bouncebuf[0] & SR1_QUAD_EN_BIT6) 1926 + if ((enable && (nor->bouncebuf[0] & SR1_QUAD_EN_BIT6)) || 1927 + (!enable && !(nor->bouncebuf[0] & SR1_QUAD_EN_BIT6))) 1928 1928 return 0; 1929 1929 1930 - nor->bouncebuf[0] |= SR1_QUAD_EN_BIT6; 1930 + if (enable) 1931 + nor->bouncebuf[0] |= SR1_QUAD_EN_BIT6; 1932 + else 1933 + nor->bouncebuf[0] &= ~SR1_QUAD_EN_BIT6; 1931 1934 1932 1935 return spi_nor_write_sr1_and_check(nor, nor->bouncebuf[0]); 1933 1936 } 1934 1937 1935 1938 /** 1936 - * spi_nor_sr2_bit1_quad_enable() - set the Quad Enable BIT(1) in the Status 1937 - * Register 2. 1939 + * spi_nor_sr2_bit1_quad_enable() - set/unset the Quad Enable BIT(1) in the 1940 + * Status Register 2. 1938 1941 * @nor: pointer to a 'struct spi_nor'. 1942 + * @enable: true to enable Quad mode, false to disable Quad mode. 1939 1943 * 1940 1944 * Bit 1 of the Status Register 2 is the QE bit for Spansion like QSPI memories. 1941 1945 * 1942 1946 * Return: 0 on success, -errno otherwise. 1943 1947 */ 1944 - int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor) 1948 + int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor, bool enable) 1945 1949 { 1946 1950 int ret; 1947 1951 1948 1952 if (nor->flags & SNOR_F_NO_READ_CR) 1949 - return spi_nor_write_16bit_cr_and_check(nor, SR2_QUAD_EN_BIT1); 1953 + return spi_nor_write_16bit_cr_and_check(nor, 1954 + enable ? SR2_QUAD_EN_BIT1 : 0); 1950 1955 1951 1956 ret = spi_nor_read_cr(nor, nor->bouncebuf); 1952 1957 if (ret) 1953 1958 return ret; 1954 1959 1955 - if (nor->bouncebuf[0] & SR2_QUAD_EN_BIT1) 1960 + if ((enable && (nor->bouncebuf[0] & SR2_QUAD_EN_BIT1)) || 1961 + (!enable && !(nor->bouncebuf[0] & SR2_QUAD_EN_BIT1))) 1956 1962 return 0; 1957 1963 1958 - nor->bouncebuf[0] |= SR2_QUAD_EN_BIT1; 1964 + if (enable) 1965 + nor->bouncebuf[0] |= SR2_QUAD_EN_BIT1; 1966 + else 1967 + nor->bouncebuf[0] &= ~SR2_QUAD_EN_BIT1; 1959 1968 1960 1969 return spi_nor_write_16bit_cr_and_check(nor, nor->bouncebuf[0]); 1961 1970 } 1962 1971 1963 1972 /** 1964 - * spi_nor_sr2_bit7_quad_enable() - set QE bit in Status Register 2. 1973 + * spi_nor_sr2_bit7_quad_enable() - set/unset QE bit in Status Register 2. 1965 1974 * @nor: pointer to a 'struct spi_nor' 1975 + * @enable: true to enable Quad mode, false to disable Quad mode. 1966 1976 * 1967 1977 * Set the Quad Enable (QE) bit in the Status Register 2. 1968 1978 * ··· 1983 1971 * 1984 1972 * Return: 0 on success, -errno otherwise. 1985 1973 */ 1986 - int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor) 1974 + int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor, bool enable) 1987 1975 { 1988 1976 u8 *sr2 = nor->bouncebuf; 1989 1977 int ret; ··· 1993 1981 ret = spi_nor_read_sr2(nor, sr2); 1994 1982 if (ret) 1995 1983 return ret; 1996 - if (*sr2 & SR2_QUAD_EN_BIT7) 1984 + if ((enable && (*sr2 & SR2_QUAD_EN_BIT7)) || 1985 + (!enable && !(*sr2 & SR2_QUAD_EN_BIT7))) 1997 1986 return 0; 1998 1987 1999 1988 /* Update the Quad Enable bit. */ 2000 - *sr2 |= SR2_QUAD_EN_BIT7; 1989 + if (enable) 1990 + *sr2 |= SR2_QUAD_EN_BIT7; 1991 + else 1992 + *sr2 &= ~SR2_QUAD_EN_BIT7; 2001 1993 2002 1994 ret = spi_nor_write_sr2(nor, sr2); 2003 1995 if (ret) ··· 2914 2898 } 2915 2899 2916 2900 /** 2917 - * spi_nor_quad_enable() - enable Quad I/O if needed. 2901 + * spi_nor_quad_enable() - enable/disable Quad I/O if needed. 2918 2902 * @nor: pointer to a 'struct spi_nor' 2903 + * @enable: true to enable Quad mode. false to disable Quad mode. 2919 2904 * 2920 2905 * Return: 0 on success, -errno otherwise. 2921 2906 */ 2922 - static int spi_nor_quad_enable(struct spi_nor *nor) 2907 + static int spi_nor_quad_enable(struct spi_nor *nor, bool enable) 2923 2908 { 2924 2909 if (!nor->params->quad_enable) 2925 2910 return 0; ··· 2929 2912 spi_nor_get_protocol_width(nor->write_proto) == 4)) 2930 2913 return 0; 2931 2914 2932 - return nor->params->quad_enable(nor); 2915 + return nor->params->quad_enable(nor, enable); 2933 2916 } 2934 2917 2935 2918 /** ··· 2953 2936 { 2954 2937 int err; 2955 2938 2956 - err = spi_nor_quad_enable(nor); 2939 + err = spi_nor_quad_enable(nor, true); 2957 2940 if (err) { 2958 2941 dev_dbg(nor->dev, "quad mode not supported\n"); 2959 2942 return err; ··· 3000 2983 if (nor->addr_width == 4 && !(nor->flags & SNOR_F_4B_OPCODES) && 3001 2984 nor->flags & SNOR_F_BROKEN_RESET) 3002 2985 nor->params->set_4byte_addr_mode(nor, false); 2986 + 2987 + spi_nor_quad_enable(nor, false); 3003 2988 } 3004 2989 EXPORT_SYMBOL_GPL(spi_nor_restore); 3005 2990
+5 -5
drivers/mtd/spi-nor/core.h
··· 198 198 * higher index in the array, the higher priority. 199 199 * @erase_map: the erase map parsed from the SFDP Sector Map Parameter 200 200 * Table. 201 - * @quad_enable: enables SPI NOR quad mode. 201 + * @quad_enable: enables/disables SPI NOR Quad mode. 202 202 * @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode. 203 203 * @convert_addr: converts an absolute address into something the flash 204 204 * will understand. Particularly useful when pagesize is ··· 219 219 220 220 struct spi_nor_erase_map erase_map; 221 221 222 - int (*quad_enable)(struct spi_nor *nor); 222 + int (*quad_enable)(struct spi_nor *nor, bool enable); 223 223 int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable); 224 224 u32 (*convert_addr)(struct spi_nor *nor, u32 addr); 225 225 int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps); ··· 406 406 int spi_nor_wait_till_ready(struct spi_nor *nor); 407 407 int spi_nor_lock_and_prep(struct spi_nor *nor); 408 408 void spi_nor_unlock_and_unprep(struct spi_nor *nor); 409 - int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor); 410 - int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor); 411 - int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor); 409 + int spi_nor_sr1_bit6_quad_enable(struct spi_nor *nor, bool enable); 410 + int spi_nor_sr2_bit1_quad_enable(struct spi_nor *nor, bool enable); 411 + int spi_nor_sr2_bit7_quad_enable(struct spi_nor *nor, bool enable); 412 412 413 413 int spi_nor_xread_sr(struct spi_nor *nor, u8 *sr); 414 414 ssize_t spi_nor_read_data(struct spi_nor *nor, loff_t from, size_t len,
+6
drivers/mtd/spi-nor/macronix.c
··· 52 52 { "mx25u6435f", INFO(0xc22537, 0, 64 * 1024, 128, SECT_4K) }, 53 53 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, 54 54 { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) }, 55 + { "mx25r1635f", INFO(0xc22815, 0, 64 * 1024, 32, 56 + SECT_4K | SPI_NOR_DUAL_READ | 57 + SPI_NOR_QUAD_READ) }, 55 58 { "mx25r3235f", INFO(0xc22816, 0, 64 * 1024, 64, 56 59 SECT_4K | SPI_NOR_DUAL_READ | 57 60 SPI_NOR_QUAD_READ) }, ··· 87 84 SPI_NOR_QUAD_READ) }, 88 85 { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, 89 86 SPI_NOR_QUAD_READ) }, 87 + { "mx66u2g45g", INFO(0xc2253c, 0, 64 * 1024, 4096, 88 + SECT_4K | SPI_NOR_DUAL_READ | 89 + SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) }, 90 90 }; 91 91 92 92 static void macronix_default_init(struct spi_nor *nor)
+2 -2
drivers/mtd/spi-nor/micron-st.c
··· 71 71 SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | 72 72 NO_CHIP_ERASE) }, 73 73 { "mt25qu02g", INFO(0x20bb22, 0, 64 * 1024, 4096, 74 - SECT_4K | USE_FSR | SPI_NOR_QUAD_READ | 75 - NO_CHIP_ERASE) }, 74 + SECT_4K | USE_FSR | SPI_NOR_DUAL_READ | 75 + SPI_NOR_QUAD_READ | NO_CHIP_ERASE) }, 76 76 77 77 { "m25p05", INFO(0x202010, 0, 32 * 1024, 2, 0) }, 78 78 { "m25p10", INFO(0x202011, 0, 32 * 1024, 4, 0) },
+2 -1
drivers/mtd/spi-nor/sfdp.c
··· 598 598 break; 599 599 600 600 default: 601 - return -EINVAL; 601 + dev_dbg(nor->dev, "BFPT QER reserved value used\n"); 602 + break; 602 603 } 603 604 604 605 /* Stop here if not JESD216 rev C or later. */
+2 -2
drivers/mtd/spi-nor/spansion.c
··· 64 64 { "s25fs512s", INFO6(0x010220, 0x4d0081, 256 * 1024, 256, 65 65 SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | USE_CLSR) 66 66 .fixups = &s25fs_s_fixups, }, 67 - { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) }, 68 67 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, 69 68 { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, 70 69 { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, ··· 83 84 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 84 85 { "s25fl016k", INFO(0xef4015, 0, 64 * 1024, 32, 85 86 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 86 - { "s25fl064k", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, 87 + { "s25fl064k", INFO(0xef4017, 0, 64 * 1024, 128, 88 + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 87 89 { "s25fl116k", INFO(0x014015, 0, 64 * 1024, 32, 88 90 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 89 91 { "s25fl132k", INFO(0x014016, 0, 64 * 1024, 64, SECT_4K) },
+3 -1
drivers/mtd/spi-nor/winbond.c
··· 64 64 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 65 65 SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 66 66 { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, 67 - { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, SECT_4K) }, 67 + { "w25q64", INFO(0xef4017, 0, 64 * 1024, 128, 68 + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, 68 69 { "w25q64dw", INFO(0xef6017, 0, 64 * 1024, 128, 69 70 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 70 71 SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) }, 72 + { "w25q64jvm", INFO(0xef7017, 0, 64 * 1024, 128, SECT_4K) }, 71 73 { "w25q128fw", INFO(0xef6018, 0, 64 * 1024, 256, 72 74 SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | 73 75 SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB) },
+1 -1
include/linux/mtd/hyperbus.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 2 2 * 3 - * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/ 3 + * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/ 4 4 */ 5 5 6 6 #ifndef __LINUX_MTD_HYPERBUS_H__
+6 -6
include/linux/mtd/nand.h
··· 12 12 13 13 #include <linux/mtd/mtd.h> 14 14 15 + struct nand_device; 16 + 15 17 /** 16 18 * struct nand_memory_organization - Memory organization structure 17 19 * @bits_per_cell: number of bits per NAND cell ··· 116 114 }; 117 115 118 116 /** 119 - * struct nand_ecc_req - NAND ECC requirements 117 + * struct nand_ecc_props - NAND ECC properties 120 118 * @strength: ECC strength 121 - * @step_size: ECC step/block size 119 + * @step_size: Number of bytes per step 122 120 */ 123 - struct nand_ecc_req { 121 + struct nand_ecc_props { 124 122 unsigned int strength; 125 123 unsigned int step_size; 126 124 }; ··· 134 132 struct nand_bbt { 135 133 unsigned long *cache; 136 134 }; 137 - 138 - struct nand_device; 139 135 140 136 /** 141 137 * struct nand_ops - NAND operations ··· 179 179 struct nand_device { 180 180 struct mtd_info mtd; 181 181 struct nand_memory_organization memorg; 182 - struct nand_ecc_req eccreq; 182 + struct nand_ecc_props eccreq; 183 183 struct nand_row_converter rowconv; 184 184 struct nand_bbt bbt; 185 185 const struct nand_ops *ops;
+1 -1
include/linux/mtd/pfow.h
··· 19 19 /* Identification info for LPDDR chip */ 20 20 #define PFOW_MANUFACTURER_ID 0x0020 21 21 #define PFOW_DEVICE_ID 0x0022 22 - /* Address in PFOW where prog buffer can can be found */ 22 + /* Address in PFOW where prog buffer can be found */ 23 23 #define PFOW_PROGRAM_BUFFER_OFFSET 0x0040 24 24 /* Size of program buffer in words */ 25 25 #define PFOW_PROGRAM_BUFFER_SIZE 0x0042
+138 -135
include/linux/mtd/rawnand.h
··· 492 492 }; 493 493 494 494 /** 495 - * enum nand_data_interface_type - NAND interface timing type 495 + * enum nand_interface_type - NAND interface type 496 496 * @NAND_SDR_IFACE: Single Data Rate interface 497 497 */ 498 - enum nand_data_interface_type { 498 + enum nand_interface_type { 499 499 NAND_SDR_IFACE, 500 500 }; 501 501 502 502 /** 503 - * struct nand_data_interface - NAND interface timing 503 + * struct nand_interface_config - NAND interface timing 504 504 * @type: type of the timing 505 505 * @timings: The timing information 506 506 * @timings.mode: Timing mode as defined in the specification 507 507 * @timings.sdr: Use it when @type is %NAND_SDR_IFACE. 508 508 */ 509 - struct nand_data_interface { 510 - enum nand_data_interface_type type; 509 + struct nand_interface_config { 510 + enum nand_interface_type type; 511 511 struct nand_timings { 512 512 unsigned int mode; 513 513 union { ··· 521 521 * @conf: The data interface 522 522 */ 523 523 static inline const struct nand_sdr_timings * 524 - nand_get_sdr_timings(const struct nand_data_interface *conf) 524 + nand_get_sdr_timings(const struct nand_interface_config *conf) 525 525 { 526 526 if (conf->type != NAND_SDR_IFACE) 527 527 return ERR_PTR(-EINVAL); ··· 944 944 * This method replaces chip->legacy.cmdfunc(), 945 945 * chip->legacy.{read,write}_{buf,byte,word}(), 946 946 * chip->legacy.dev_ready() and chip->legacy.waifunc(). 947 - * @setup_data_interface: setup the data interface and timing. If 948 - * chipnr is set to %NAND_DATA_IFACE_CHECK_ONLY this 949 - * means the configuration should not be applied but 950 - * only checked. 951 - * This hook is optional. 947 + * @setup_interface: setup the data interface and timing. If chipnr is set to 948 + * %NAND_DATA_IFACE_CHECK_ONLY this means the configuration 949 + * should not be applied but only checked. 950 + * This hook is optional. 952 951 */ 953 952 struct nand_controller_ops { 954 953 int (*attach_chip)(struct nand_chip *chip); ··· 955 956 int (*exec_op)(struct nand_chip *chip, 956 957 const struct nand_operation *op, 957 958 bool check_only); 958 - int (*setup_data_interface)(struct nand_chip *chip, int chipnr, 959 - const struct nand_data_interface *conf); 959 + int (*setup_interface)(struct nand_chip *chip, int chipnr, 960 + const struct nand_interface_config *conf); 960 961 }; 961 962 962 963 /** ··· 1027 1028 }; 1028 1029 1029 1030 /** 1030 - * struct nand_chip - NAND Private Flash Chip Data 1031 - * @base: Inherit from the generic NAND device 1032 - * @legacy: All legacy fields/hooks. If you develop a new driver, 1033 - * don't even try to use any of these fields/hooks, and if 1034 - * you're modifying an existing driver that is using those 1035 - * fields/hooks, you should consider reworking the driver 1036 - * avoid using them. 1037 - * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for 1038 - * setting the read-retry mode. Mostly needed for MLC NAND. 1039 - * @ecc: [BOARDSPECIFIC] ECC control structure 1040 - * @buf_align: minimum buffer alignment required by a platform 1041 - * @oob_poi: "poison value buffer," used for laying out OOB data 1042 - * before writing 1043 - * @page_shift: [INTERN] number of address bits in a page (column 1044 - * address bits). 1045 - * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock 1046 - * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry 1047 - * @chip_shift: [INTERN] number of address bits in one chip 1048 - * @options: [BOARDSPECIFIC] various chip options. They can partly 1049 - * be set to inform nand_scan about special functionality. 1050 - * See the defines for further explanation. 1051 - * @bbt_options: [INTERN] bad block specific options. All options used 1052 - * here must come from bbm.h. By default, these options 1053 - * will be copied to the appropriate nand_bbt_descr's. 1054 - * @badblockpos: [INTERN] position of the bad block marker in the oob 1055 - * area. 1056 - * @badblockbits: [INTERN] minimum number of set bits in a good block's 1057 - * bad block marker position; i.e., BBM == 11110111b is 1058 - * not bad when badblockbits == 7 1059 - * @onfi_timing_mode_default: [INTERN] default ONFI timing mode. This field is 1060 - * set to the actually used ONFI mode if the chip is 1061 - * ONFI compliant or deduced from the datasheet if 1062 - * the NAND chip is not ONFI compliant. 1063 - * @pagemask: [INTERN] page number mask = number of (pages / chip) - 1 1064 - * @data_buf: [INTERN] buffer for data, size is (page size + oobsize). 1065 - * @pagecache: Structure containing page cache related fields 1066 - * @pagecache.bitflips: Number of bitflips of the cached page 1067 - * @pagecache.page: Page number currently in the cache. -1 means no page is 1068 - * currently cached 1069 - * @subpagesize: [INTERN] holds the subpagesize 1070 - * @id: [INTERN] holds NAND ID 1071 - * @parameters: [INTERN] holds generic parameters under an easily 1072 - * readable form. 1073 - * @data_interface: [INTERN] NAND interface timing information 1074 - * @cur_cs: currently selected target. -1 means no target selected, 1075 - * otherwise we should always have cur_cs >= 0 && 1076 - * cur_cs < nanddev_ntargets(). NAND Controller drivers 1077 - * should not modify this value, but they're allowed to 1078 - * read it. 1079 - * @read_retries: [INTERN] the number of read retry modes supported 1080 - * @lock: lock protecting the suspended field. Also used to 1081 - * serialize accesses to the NAND device. 1082 - * @suspended: set to 1 when the device is suspended, 0 when it's not. 1083 - * @suspend: [REPLACEABLE] specific NAND device suspend operation 1084 - * @resume: [REPLACEABLE] specific NAND device resume operation 1085 - * @bbt: [INTERN] bad block table pointer 1086 - * @bbt_td: [REPLACEABLE] bad block table descriptor for flash 1087 - * lookup. 1088 - * @bbt_md: [REPLACEABLE] bad block table mirror descriptor 1089 - * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial 1090 - * bad block scan. 1091 - * @controller: [REPLACEABLE] a pointer to a hardware controller 1092 - * structure which is shared among multiple independent 1093 - * devices. 1094 - * @priv: [OPTIONAL] pointer to private chip data 1095 - * @manufacturer: [INTERN] Contains manufacturer information 1096 - * @manufacturer.desc: [INTERN] Contains manufacturer's description 1097 - * @manufacturer.priv: [INTERN] Contains manufacturer private information 1098 - * @lock_area: [REPLACEABLE] specific NAND chip lock operation 1099 - * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation 1031 + * struct nand_chip_ops - NAND chip operations 1032 + * @suspend: Suspend operation 1033 + * @resume: Resume operation 1034 + * @lock_area: Lock operation 1035 + * @unlock_area: Unlock operation 1036 + * @setup_read_retry: Set the read-retry mode (mostly needed for MLC NANDs) 1037 + * @choose_interface_config: Choose the best interface configuration 1100 1038 */ 1039 + struct nand_chip_ops { 1040 + int (*suspend)(struct nand_chip *chip); 1041 + void (*resume)(struct nand_chip *chip); 1042 + int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); 1043 + int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); 1044 + int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); 1045 + int (*choose_interface_config)(struct nand_chip *chip, 1046 + struct nand_interface_config *iface); 1047 + }; 1101 1048 1049 + /** 1050 + * struct nand_manufacturer - NAND manufacturer structure 1051 + * @desc: The manufacturer description 1052 + * @priv: Private information for the manufacturer driver 1053 + */ 1054 + struct nand_manufacturer { 1055 + const struct nand_manufacturer_desc *desc; 1056 + void *priv; 1057 + }; 1058 + 1059 + /** 1060 + * struct nand_chip - NAND Private Flash Chip Data 1061 + * @base: Inherit from the generic NAND device 1062 + * @id: Holds NAND ID 1063 + * @parameters: Holds generic parameters under an easily readable form 1064 + * @manufacturer: Manufacturer information 1065 + * @ops: NAND chip operations 1066 + * @legacy: All legacy fields/hooks. If you develop a new driver, don't even try 1067 + * to use any of these fields/hooks, and if you're modifying an 1068 + * existing driver that is using those fields/hooks, you should 1069 + * consider reworking the driver and avoid using them. 1070 + * @options: Various chip options. They can partly be set to inform nand_scan 1071 + * about special functionality. See the defines for further 1072 + * explanation. 1073 + * @current_interface_config: The currently used NAND interface configuration 1074 + * @best_interface_config: The best NAND interface configuration which fits both 1075 + * the NAND chip and NAND controller constraints. If 1076 + * unset, the default reset interface configuration must 1077 + * be used. 1078 + * @bbt_erase_shift: Number of address bits in a bbt entry 1079 + * @bbt_options: Bad block table specific options. All options used here must 1080 + * come from bbm.h. By default, these options will be copied to 1081 + * the appropriate nand_bbt_descr's. 1082 + * @badblockpos: Bad block marker position in the oob area 1083 + * @badblockbits: Minimum number of set bits in a good block's bad block marker 1084 + * position; i.e., BBM = 11110111b is good when badblockbits = 7 1085 + * @bbt_td: Bad block table descriptor for flash lookup 1086 + * @bbt_md: Bad block table mirror descriptor 1087 + * @badblock_pattern: Bad block scan pattern used for initial bad block scan 1088 + * @bbt: Bad block table pointer 1089 + * @page_shift: Number of address bits in a page (column address bits) 1090 + * @phys_erase_shift: Number of address bits in a physical eraseblock 1091 + * @chip_shift: Number of address bits in one chip 1092 + * @pagemask: Page number mask = number of (pages / chip) - 1 1093 + * @subpagesize: Holds the subpagesize 1094 + * @data_buf: Buffer for data, size is (page size + oobsize) 1095 + * @oob_poi: pointer on the OOB area covered by data_buf 1096 + * @pagecache: Structure containing page cache related fields 1097 + * @pagecache.bitflips: Number of bitflips of the cached page 1098 + * @pagecache.page: Page number currently in the cache. -1 means no page is 1099 + * currently cached 1100 + * @buf_align: Minimum buffer alignment required by a platform 1101 + * @lock: Lock protecting the suspended field. Also used to serialize accesses 1102 + * to the NAND device 1103 + * @suspended: Set to 1 when the device is suspended, 0 when it's not 1104 + * @cur_cs: Currently selected target. -1 means no target selected, otherwise we 1105 + * should always have cur_cs >= 0 && cur_cs < nanddev_ntargets(). 1106 + * NAND Controller drivers should not modify this value, but they're 1107 + * allowed to read it. 1108 + * @read_retries: The number of read retry modes supported 1109 + * @controller: The hardware controller structure which is shared among multiple 1110 + * independent devices 1111 + * @ecc: The ECC controller structure 1112 + * @priv: Chip private data 1113 + */ 1102 1114 struct nand_chip { 1103 1115 struct nand_device base; 1104 - 1116 + struct nand_id id; 1117 + struct nand_parameters parameters; 1118 + struct nand_manufacturer manufacturer; 1119 + struct nand_chip_ops ops; 1105 1120 struct nand_legacy legacy; 1106 - 1107 - int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); 1108 - 1109 1121 unsigned int options; 1122 + 1123 + /* Data interface */ 1124 + const struct nand_interface_config *current_interface_config; 1125 + struct nand_interface_config *best_interface_config; 1126 + 1127 + /* Bad block information */ 1128 + unsigned int bbt_erase_shift; 1110 1129 unsigned int bbt_options; 1130 + unsigned int badblockpos; 1131 + unsigned int badblockbits; 1132 + struct nand_bbt_descr *bbt_td; 1133 + struct nand_bbt_descr *bbt_md; 1134 + struct nand_bbt_descr *badblock_pattern; 1135 + u8 *bbt; 1111 1136 1112 - int page_shift; 1113 - int phys_erase_shift; 1114 - int bbt_erase_shift; 1115 - int chip_shift; 1116 - int pagemask; 1137 + /* Device internal layout */ 1138 + unsigned int page_shift; 1139 + unsigned int phys_erase_shift; 1140 + unsigned int chip_shift; 1141 + unsigned int pagemask; 1142 + unsigned int subpagesize; 1143 + 1144 + /* Buffers */ 1117 1145 u8 *data_buf; 1118 - 1146 + u8 *oob_poi; 1119 1147 struct { 1120 1148 unsigned int bitflips; 1121 1149 int page; 1122 1150 } pagecache; 1123 - 1124 - int subpagesize; 1125 - int onfi_timing_mode_default; 1126 - unsigned int badblockpos; 1127 - int badblockbits; 1128 - 1129 - struct nand_id id; 1130 - struct nand_parameters parameters; 1131 - 1132 - struct nand_data_interface data_interface; 1133 - 1134 - int cur_cs; 1135 - 1136 - int read_retries; 1137 - 1138 - struct mutex lock; 1139 - unsigned int suspended : 1; 1140 - int (*suspend)(struct nand_chip *chip); 1141 - void (*resume)(struct nand_chip *chip); 1142 - 1143 - uint8_t *oob_poi; 1144 - struct nand_controller *controller; 1145 - 1146 - struct nand_ecc_ctrl ecc; 1147 1151 unsigned long buf_align; 1148 1152 1149 - uint8_t *bbt; 1150 - struct nand_bbt_descr *bbt_td; 1151 - struct nand_bbt_descr *bbt_md; 1153 + /* Internals */ 1154 + struct mutex lock; 1155 + unsigned int suspended : 1; 1156 + int cur_cs; 1157 + int read_retries; 1152 1158 1153 - struct nand_bbt_descr *badblock_pattern; 1154 - 1159 + /* Externals */ 1160 + struct nand_controller *controller; 1161 + struct nand_ecc_ctrl ecc; 1155 1162 void *priv; 1156 - 1157 - struct { 1158 - const struct nand_manufacturer *desc; 1159 - void *priv; 1160 - } manufacturer; 1161 - 1162 - int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); 1163 - int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); 1164 1163 }; 1165 1164 1166 1165 extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops; ··· 1204 1207 static inline struct device_node *nand_get_flash_node(struct nand_chip *chip) 1205 1208 { 1206 1209 return mtd_get_of_node(nand_to_mtd(chip)); 1210 + } 1211 + 1212 + /** 1213 + * nand_get_interface_config - Retrieve the current interface configuration 1214 + * of a NAND chip 1215 + * @chip: The NAND chip 1216 + */ 1217 + static inline const struct nand_interface_config * 1218 + nand_get_interface_config(struct nand_chip *chip) 1219 + { 1220 + return chip->current_interface_config; 1207 1221 } 1208 1222 1209 1223 /* ··· 1269 1261 * @ecc_step_ds in nand_chip{}, also from the datasheet. 1270 1262 * For example, the "4bit ECC for each 512Byte" can be set with 1271 1263 * NAND_ECC_INFO(4, 512). 1272 - * @onfi_timing_mode_default: the default ONFI timing mode entered after a NAND 1273 - * reset. Should be deduced from timings described 1274 - * in the datasheet. 1275 - * 1276 1264 */ 1277 1265 struct nand_flash_dev { 1278 1266 char *name; ··· 1289 1285 uint16_t strength_ds; 1290 1286 uint16_t step_ds; 1291 1287 } ecc; 1292 - int onfi_timing_mode_default; 1293 1288 }; 1294 1289 1295 1290 int nand_create_bbt(struct nand_chip *chip);
+1 -1
include/linux/mtd/spinand.h
··· 309 309 struct spinand_devid devid; 310 310 u32 flags; 311 311 struct nand_memory_organization memorg; 312 - struct nand_ecc_req eccreq; 312 + struct nand_ecc_props eccreq; 313 313 struct spinand_ecc_info eccinfo; 314 314 struct { 315 315 const struct spinand_op_variants *read_cache;
+1 -1
include/uapi/mtd/mtd-abi.h
··· 262 262 * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode 263 263 * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled 264 264 * 265 - * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained 265 + * These modes can be set via ioctl(MTDFILEMODE). The mode will be retained 266 266 * separately for each open file descriptor. 267 267 * 268 268 * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -