Merge tag 'drm-4.7-rc1-headers-fix' of git://people.freedesktop.org/~airlied/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 25 May 2016 16:37:50 +0000 (09:37 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 25 May 2016 16:37:50 +0000 (09:37 -0700)
Pull header warning fix from Dave Airlie:
 "Here is the C++ guards warning fix from Arnd"

[ Background: there are 'extern "C" { }' guards in include/uapi for the
  GPU headers.

  They should arguably be wrapped somehow, but as it is they caused
  checkpatch to warn because it would trigger on the 'extern' and think
  it's exporting a function or variable from the kernel to user space.

  This just fixes checkpatch.  Whether we wrap the C++ guards some way
  in the future will be an independent issue. ]

* tag 'drm-4.7-rc1-headers-fix' of git://people.freedesktop.org/~airlied/linux:
  headers_check: don't warn about c++ guards

237 files changed:
Documentation/devicetree/bindings/bus/ti-gpmc.txt [deleted file]
Documentation/devicetree/bindings/memory-controllers/omap-gpmc.txt [new file with mode: 0644]
Documentation/devicetree/bindings/mtd/brcm,brcmnand.txt
Documentation/devicetree/bindings/mtd/gpmc-nand.txt
Documentation/devicetree/bindings/mtd/nand.txt
Documentation/devicetree/bindings/spi/microchip,spi-pic32.txt [new file with mode: 0644]
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt
Documentation/devicetree/bindings/spi/sqi-pic32.txt [new file with mode: 0644]
arch/arc/include/uapi/asm/unistd.h
arch/arm/boot/dts/Makefile
arch/arm/boot/dts/exynos3250-monk.dts
arch/arm/boot/dts/exynos3250-rinato.dts
arch/arm/boot/dts/exynos3250.dtsi
arch/arm/boot/dts/exynos4210.dtsi
arch/arm/boot/dts/exynos4412-odroid-common.dtsi
arch/arm/boot/dts/exynos4412-ppmu-common.dtsi [new file with mode: 0644]
arch/arm/boot/dts/exynos4412-trats2.dts
arch/arm/boot/dts/exynos4x12.dtsi
arch/arm/boot/dts/exynos5420.dtsi
arch/arm/boot/dts/exynos5422-odroidxu3-common.dtsi
arch/arm/boot/dts/imx7d-nitrogen7.dts [new file with mode: 0644]
arch/arm/boot/dts/imx7d.dtsi
arch/arm/boot/dts/r8a7779.dtsi
arch/arm/boot/dts/r8a7790.dtsi
arch/arm/boot/dts/r8a7791.dtsi
arch/arm/boot/dts/r8a7793.dtsi
arch/arm/boot/dts/r8a7794.dtsi
arch/arm/boot/dts/tegra124-jetson-tk1.dts
arch/arm/boot/dts/tegra124-nyan.dtsi
arch/arm/boot/dts/tegra124-venice2.dts
arch/arm/boot/dts/tegra124.dtsi
arch/arm/boot/dts/vf-colibri-eval-v3.dtsi
arch/arm/boot/dts/vf-colibri.dtsi
arch/arm/boot/dts/vfxxx.dtsi
arch/arm/mach-lpc32xx/Makefile
arch/arm/mach-lpc32xx/include/mach/irqs.h
arch/arm/mach-lpc32xx/irq.c [deleted file]
arch/arm/mach-omap2/gpmc-nand.c
arch/arm/mach-pxa/Kconfig
arch/arm/mach-pxa/eseries.c
arch/arm/mach-pxa/spitz.c
arch/arm64/boot/dts/renesas/r8a7795.dtsi
arch/arm64/include/uapi/asm/unistd.h
arch/c6x/include/uapi/asm/unistd.h
arch/cris/arch-v32/drivers/mach-a3/nandflash.c
arch/cris/arch-v32/drivers/mach-fs/nandflash.c
arch/h8300/include/uapi/asm/unistd.h
arch/hexagon/include/uapi/asm/unistd.h
arch/metag/include/uapi/asm/unistd.h
arch/microblaze/include/asm/unistd.h
arch/microblaze/include/uapi/asm/unistd.h
arch/microblaze/kernel/syscall_table.S
arch/microblaze/pci/pci-common.c
arch/mips/include/asm/mach-jz4740/jz4740_nand.h
arch/mips/jz4740/board-qi_lb60.c
arch/nios2/Makefile
arch/nios2/include/uapi/asm/unistd.h
arch/openrisc/include/uapi/asm/unistd.h
arch/parisc/Kconfig
arch/parisc/include/asm/cmpxchg.h
arch/parisc/include/asm/eisa_eeprom.h
arch/parisc/include/asm/ftrace.h
arch/parisc/include/asm/futex.h
arch/parisc/include/asm/ldcw.h
arch/parisc/include/asm/syscall.h
arch/parisc/include/asm/thread_info.h
arch/parisc/include/asm/uaccess.h
arch/parisc/include/uapi/asm/pdc.h
arch/parisc/include/uapi/asm/ptrace.h
arch/parisc/include/uapi/asm/unistd.h
arch/parisc/kernel/entry.S
arch/parisc/kernel/ftrace.c
arch/parisc/kernel/ptrace.c
arch/parisc/kernel/syscall.S
arch/parisc/kernel/time.c
arch/parisc/lib/bitops.c
arch/parisc/math-emu/fpudispatch.c
arch/score/include/uapi/asm/unistd.h
arch/tile/include/uapi/asm/unistd.h
arch/unicore32/include/uapi/asm/unistd.h
arch/x86/pci/xen.c
arch/x86/xen/setup.c
arch/x86/xen/time.c
drivers/bcma/driver_chipcommon_sflash.c
drivers/memory/Kconfig
drivers/memory/fsl_ifc.c
drivers/memory/omap-gpmc.c
drivers/mtd/chips/Kconfig
drivers/mtd/devices/bcm47xxsflash.c
drivers/mtd/devices/bcm47xxsflash.h
drivers/mtd/devices/docg3.c
drivers/mtd/devices/m25p80.c
drivers/mtd/devices/pmc551.c
drivers/mtd/maps/ck804xrom.c
drivers/mtd/maps/esb2rom.c
drivers/mtd/maps/ichxrom.c
drivers/mtd/maps/uclinux.c
drivers/mtd/mtdchar.c
drivers/mtd/mtdconcat.c
drivers/mtd/mtdcore.c
drivers/mtd/mtdpart.c
drivers/mtd/nand/ams-delta.c
drivers/mtd/nand/atmel_nand.c
drivers/mtd/nand/au1550nd.c
drivers/mtd/nand/bf5xx_nand.c
drivers/mtd/nand/brcmnand/brcmnand.c
drivers/mtd/nand/cafe_nand.c
drivers/mtd/nand/cmx270_nand.c
drivers/mtd/nand/davinci_nand.c
drivers/mtd/nand/denali.c
drivers/mtd/nand/diskonchip.c
drivers/mtd/nand/docg4.c
drivers/mtd/nand/fsl_elbc_nand.c
drivers/mtd/nand/fsl_ifc_nand.c
drivers/mtd/nand/fsl_upm.c
drivers/mtd/nand/fsmc_nand.c
drivers/mtd/nand/gpio.c
drivers/mtd/nand/gpmi-nand/gpmi-nand.c
drivers/mtd/nand/hisi504_nand.c
drivers/mtd/nand/jz4740_nand.c
drivers/mtd/nand/jz4780_bch.c
drivers/mtd/nand/jz4780_nand.c
drivers/mtd/nand/lpc32xx_mlc.c
drivers/mtd/nand/lpc32xx_slc.c
drivers/mtd/nand/mpc5121_nfc.c
drivers/mtd/nand/mxc_nand.c
drivers/mtd/nand/nand_base.c
drivers/mtd/nand/nand_bch.c
drivers/mtd/nand/nandsim.c
drivers/mtd/nand/nuc900_nand.c
drivers/mtd/nand/omap2.c
drivers/mtd/nand/orion_nand.c
drivers/mtd/nand/pasemi_nand.c
drivers/mtd/nand/plat_nand.c
drivers/mtd/nand/pxa3xx_nand.c
drivers/mtd/nand/qcom_nandc.c
drivers/mtd/nand/s3c2410.c
drivers/mtd/nand/sh_flctl.c
drivers/mtd/nand/sharpsl.c
drivers/mtd/nand/sm_common.c
drivers/mtd/nand/socrates_nand.c
drivers/mtd/nand/sunxi_nand.c
drivers/mtd/nand/vf610_nfc.c
drivers/mtd/onenand/onenand_base.c
drivers/mtd/spi-nor/spi-nor.c
drivers/of/Makefile
drivers/of/of_mtd.c [deleted file]
drivers/soc/mediatek/mtk-pmic-wrap.c
drivers/spi/Kconfig
drivers/spi/Makefile
drivers/spi/spi-axi-spi-engine.c
drivers/spi/spi-bcm53xx.c
drivers/spi/spi-cadence.c
drivers/spi/spi-davinci.c
drivers/spi/spi-dln2.c
drivers/spi/spi-dw-pci.c
drivers/spi/spi-fsl-dspi.c
drivers/spi/spi-fsl-espi.c
drivers/spi/spi-octeon.c
drivers/spi/spi-omap2-mcspi.c
drivers/spi/spi-pic32-sqi.c [new file with mode: 0644]
drivers/spi/spi-pic32.c [new file with mode: 0644]
drivers/spi/spi-pxa2xx-dma.c
drivers/spi/spi-pxa2xx-pci.c
drivers/spi/spi-pxa2xx.c
drivers/spi/spi-pxa2xx.h
drivers/spi/spi-qup.c
drivers/spi/spi-rockchip.c
drivers/spi/spi-st-ssc4.c
drivers/spi/spi-zynqmp-gqspi.c
drivers/spi/spi.c
drivers/staging/mt29f_spinand/mt29f_spinand.c
drivers/virtio/virtio_balloon.c
drivers/xen/Makefile
drivers/xen/events/events_base.c
drivers/xen/gntdev.c
fs/compat.c
fs/dax.c
fs/ext4/balloc.c
fs/ext4/dir.c
fs/ext4/ext4.h
fs/ext4/ext4_jbd2.h
fs/ext4/extents.c
fs/ext4/extents_status.c
fs/ext4/file.c
fs/ext4/ialloc.c
fs/ext4/indirect.c
fs/ext4/inline.c
fs/ext4/inode.c
fs/ext4/ioctl.c
fs/ext4/mballoc.c
fs/ext4/mmp.c
fs/ext4/move_extent.c
fs/ext4/namei.c
fs/ext4/page-io.c
fs/ext4/resize.c
fs/ext4/super.c
fs/jbd2/commit.c
fs/jbd2/journal.c
fs/jbd2/transaction.c
fs/nfsd/nfs3xdr.c
fs/nfsd/nfs4layouts.c
fs/nfsd/nfs4state.c
fs/nfsd/state.h
fs/ocfs2/journal.h
fs/readdir.c
include/linux/bcma/bcma_driver_chipcommon.h
include/linux/fsl_ifc.h
include/linux/jbd2.h
include/linux/mtd/fsmc.h
include/linux/mtd/map.h
include/linux/mtd/mtd.h
include/linux/mtd/nand.h
include/linux/mtd/onenand.h
include/linux/mtd/sharpsl.h
include/linux/mtd/spi-nor.h
include/linux/of_mtd.h [deleted file]
include/linux/omap-gpmc.h
include/linux/platform_data/gpmc-omap.h [new file with mode: 0644]
include/linux/platform_data/mtd-nand-omap2.h
include/linux/spi/spi.h
include/linux/sunrpc/svc_rdma.h
include/uapi/asm-generic/unistd.h
include/uapi/mtd/mtd-abi.h
kernel/locking/percpu-rwsem.c
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/svc_xprt.c
net/sunrpc/xprtrdma/svc_rdma_marshal.c
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
net/sunrpc/xprtrdma/svc_rdma_sendto.c
net/sunrpc/xprtrdma/svc_rdma_transport.c
tools/testing/selftests/seccomp/seccomp_bpf.c
tools/testing/selftests/vm/thuge-gen.c
tools/virtio/ringtest/Makefile
tools/virtio/ringtest/main.c
tools/virtio/ringtest/virtio_ring_0_9.c
tools/virtio/ringtest/virtio_ring_inorder.c [new file with mode: 0644]

diff --git a/Documentation/devicetree/bindings/bus/ti-gpmc.txt b/Documentation/devicetree/bindings/bus/ti-gpmc.txt
deleted file mode 100644 (file)
index 0168370..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-Device tree bindings for OMAP general purpose memory controllers (GPMC)
-
-The actual devices are instantiated from the child nodes of a GPMC node.
-
-Required properties:
-
- - compatible:         Should be set to one of the following:
-
-                       ti,omap2420-gpmc (omap2420)
-                       ti,omap2430-gpmc (omap2430)
-                       ti,omap3430-gpmc (omap3430 & omap3630)
-                       ti,omap4430-gpmc (omap4430 & omap4460 & omap543x)
-                       ti,am3352-gpmc   (am335x devices)
-
- - reg:                        A resource specifier for the register space
-                       (see the example below)
- - ti,hwmods:          Should be set to "ti,gpmc" until the DT transition is
-                       completed.
- - #address-cells:     Must be set to 2 to allow memory address translation
- - #size-cells:                Must be set to 1 to allow CS address passing
- - gpmc,num-cs:                The maximum number of chip-select lines that controller
-                       can support.
- - gpmc,num-waitpins:  The maximum number of wait pins that controller can
-                       support.
- - ranges:             Must be set up to reflect the memory layout with four
-                       integer values for each chip-select line in use:
-
-                          <cs-number> 0 <physical address of mapping> <size>
-
-                       Currently, calculated values derived from the contents
-                       of the per-CS register GPMC_CONFIG7 (as set up by the
-                       bootloader) are used for the physical address decoding.
-                       As this will change in the future, filling correct
-                       values here is a requirement.
-
-Timing properties for child nodes. All are optional and default to 0.
-
- - gpmc,sync-clk-ps:   Minimum clock period for synchronous mode, in picoseconds
-
- Chip-select signal timings (in nanoseconds) corresponding to GPMC_CONFIG2:
- - gpmc,cs-on-ns:      Assertion time
- - gpmc,cs-rd-off-ns:  Read deassertion time
- - gpmc,cs-wr-off-ns:  Write deassertion time
-
- ADV signal timings (in nanoseconds) corresponding to GPMC_CONFIG3:
- - gpmc,adv-on-ns:     Assertion time
- - gpmc,adv-rd-off-ns: Read deassertion time
- - gpmc,adv-wr-off-ns: Write deassertion time
- - gpmc,adv-aad-mux-on-ns:     Assertion time for AAD
- - gpmc,adv-aad-mux-rd-off-ns: Read deassertion time for AAD
- - gpmc,adv-aad-mux-wr-off-ns: Write deassertion time for AAD
-
- WE signals timings (in nanoseconds) corresponding to GPMC_CONFIG4:
- - gpmc,we-on-ns       Assertion time
- - gpmc,we-off-ns:     Deassertion time
-
- OE signals timings (in nanoseconds) corresponding to GPMC_CONFIG4:
- - gpmc,oe-on-ns:      Assertion time
- - gpmc,oe-off-ns:     Deassertion time
- - gpmc,oe-aad-mux-on-ns:      Assertion time for AAD
- - gpmc,oe-aad-mux-off-ns:     Deassertion time for AAD
-
- Access time and cycle time timings (in nanoseconds) corresponding to
- GPMC_CONFIG5:
- - gpmc,page-burst-access-ns:  Multiple access word delay
- - gpmc,access-ns:             Start-cycle to first data valid delay
- - gpmc,rd-cycle-ns:           Total read cycle time
- - gpmc,wr-cycle-ns:           Total write cycle time
- - gpmc,bus-turnaround-ns:     Turn-around time between successive accesses
- - gpmc,cycle2cycle-delay-ns:  Delay between chip-select pulses
- - gpmc,clk-activation-ns:     GPMC clock activation time
- - gpmc,wait-monitoring-ns:    Start of wait monitoring with regard to valid
-                               data
-
-Boolean timing parameters. If property is present parameter enabled and
-disabled if omitted:
- - gpmc,adv-extra-delay:       ADV signal is delayed by half GPMC clock
- - gpmc,cs-extra-delay:                CS signal is delayed by half GPMC clock
- - gpmc,cycle2cycle-diffcsen:  Add "cycle2cycle-delay" between successive
-                               accesses to a different CS
- - gpmc,cycle2cycle-samecsen:  Add "cycle2cycle-delay" between successive
-                               accesses to the same CS
- - gpmc,oe-extra-delay:                OE signal is delayed by half GPMC clock
- - gpmc,we-extra-delay:                WE signal is delayed by half GPMC clock
- - gpmc,time-para-granularity: Multiply all access times by 2
-
-The following are only applicable to OMAP3+ and AM335x:
- - gpmc,wr-access-ns:          In synchronous write mode, for single or
-                               burst accesses, defines the number of
-                               GPMC_FCLK cycles from start access time
-                               to the GPMC_CLK rising edge used by the
-                               memory device for the first data capture.
- - gpmc,wr-data-mux-bus-ns:    In address-data multiplex mode, specifies
-                               the time when the first data is driven on
-                               the address-data bus.
-
-GPMC chip-select settings properties for child nodes. All are optional.
-
-- gpmc,burst-length    Page/burst length. Must be 4, 8 or 16.
-- gpmc,burst-wrap      Enables wrap bursting
-- gpmc,burst-read      Enables read page/burst mode
-- gpmc,burst-write     Enables write page/burst mode
-- gpmc,device-width    Total width of device(s) connected to a GPMC
-                       chip-select in bytes. The GPMC supports 8-bit
-                       and 16-bit devices and so this property must be
-                       1 or 2.
-- gpmc,mux-add-data    Address and data multiplexing configuration.
-                       Valid values are 1 for address-address-data
-                       multiplexing mode and 2 for address-data
-                       multiplexing mode.
-- gpmc,sync-read       Enables synchronous read. Defaults to asynchronous
-                       is this is not set.
-- gpmc,sync-write      Enables synchronous writes. Defaults to asynchronous
-                       is this is not set.
-- gpmc,wait-pin                Wait-pin used by client. Must be less than
-                       "gpmc,num-waitpins".
-- gpmc,wait-on-read    Enables wait monitoring on reads.
-- gpmc,wait-on-write   Enables wait monitoring on writes.
-
-Example for an AM33xx board:
-
-       gpmc: gpmc@50000000 {
-               compatible = "ti,am3352-gpmc";
-               ti,hwmods = "gpmc";
-               reg = <0x50000000 0x2000>;
-               interrupts = <100>;
-
-               gpmc,num-cs = <8>;
-               gpmc,num-waitpins = <2>;
-               #address-cells = <2>;
-               #size-cells = <1>;
-               ranges = <0 0 0x08000000 0x10000000>; /* CS0 @addr 0x8000000, size 0x10000000 */
-
-               /* child nodes go here */
-       };
diff --git a/Documentation/devicetree/bindings/memory-controllers/omap-gpmc.txt b/Documentation/devicetree/bindings/memory-controllers/omap-gpmc.txt
new file mode 100644 (file)
index 0000000..21055e2
--- /dev/null
@@ -0,0 +1,152 @@
+Device tree bindings for OMAP general purpose memory controllers (GPMC)
+
+The actual devices are instantiated from the child nodes of a GPMC node.
+
+Required properties:
+
+ - compatible:         Should be set to one of the following:
+
+                       ti,omap2420-gpmc (omap2420)
+                       ti,omap2430-gpmc (omap2430)
+                       ti,omap3430-gpmc (omap3430 & omap3630)
+                       ti,omap4430-gpmc (omap4430 & omap4460 & omap543x)
+                       ti,am3352-gpmc   (am335x devices)
+
+ - reg:                        A resource specifier for the register space
+                       (see the example below)
+ - ti,hwmods:          Should be set to "ti,gpmc" until the DT transition is
+                       completed.
+ - #address-cells:     Must be set to 2 to allow memory address translation
+ - #size-cells:                Must be set to 1 to allow CS address passing
+ - gpmc,num-cs:                The maximum number of chip-select lines that controller
+                       can support.
+ - gpmc,num-waitpins:  The maximum number of wait pins that controller can
+                       support.
+ - ranges:             Must be set up to reflect the memory layout with four
+                       integer values for each chip-select line in use:
+
+                          <cs-number> 0 <physical address of mapping> <size>
+
+                       Currently, calculated values derived from the contents
+                       of the per-CS register GPMC_CONFIG7 (as set up by the
+                       bootloader) are used for the physical address decoding.
+                       As this will change in the future, filling correct
+                       values here is a requirement.
+ - interrupt-controller: The GPMC driver implements and interrupt controller for
+                       the NAND events "fifoevent" and "termcount" plus the
+                       rising/falling edges on the GPMC_WAIT pins.
+                       The interrupt number mapping is as follows
+                       0 - NAND_fifoevent
+                       1 - NAND_termcount
+                       2 - GPMC_WAIT0 pin edge
+                       3 - GPMC_WAIT1 pin edge, and so on.
+ - interrupt-cells:    Must be set to 2
+ - gpio-controller:    The GPMC driver implements a GPIO controller for the
+                       GPMC WAIT pins that can be used as general purpose inputs.
+                       0 maps to GPMC_WAIT0 pin.
+ - gpio-cells:         Must be set to 2
+
+Timing properties for child nodes. All are optional and default to 0.
+
+ - gpmc,sync-clk-ps:   Minimum clock period for synchronous mode, in picoseconds
+
+ Chip-select signal timings (in nanoseconds) corresponding to GPMC_CONFIG2:
+ - gpmc,cs-on-ns:      Assertion time
+ - gpmc,cs-rd-off-ns:  Read deassertion time
+ - gpmc,cs-wr-off-ns:  Write deassertion time
+
+ ADV signal timings (in nanoseconds) corresponding to GPMC_CONFIG3:
+ - gpmc,adv-on-ns:     Assertion time
+ - gpmc,adv-rd-off-ns: Read deassertion time
+ - gpmc,adv-wr-off-ns: Write deassertion time
+ - gpmc,adv-aad-mux-on-ns:     Assertion time for AAD
+ - gpmc,adv-aad-mux-rd-off-ns: Read deassertion time for AAD
+ - gpmc,adv-aad-mux-wr-off-ns: Write deassertion time for AAD
+
+ WE signals timings (in nanoseconds) corresponding to GPMC_CONFIG4:
+ - gpmc,we-on-ns       Assertion time
+ - gpmc,we-off-ns:     Deassertion time
+
+ OE signals timings (in nanoseconds) corresponding to GPMC_CONFIG4:
+ - gpmc,oe-on-ns:      Assertion time
+ - gpmc,oe-off-ns:     Deassertion time
+ - gpmc,oe-aad-mux-on-ns:      Assertion time for AAD
+ - gpmc,oe-aad-mux-off-ns:     Deassertion time for AAD
+
+ Access time and cycle time timings (in nanoseconds) corresponding to
+ GPMC_CONFIG5:
+ - gpmc,page-burst-access-ns:  Multiple access word delay
+ - gpmc,access-ns:             Start-cycle to first data valid delay
+ - gpmc,rd-cycle-ns:           Total read cycle time
+ - gpmc,wr-cycle-ns:           Total write cycle time
+ - gpmc,bus-turnaround-ns:     Turn-around time between successive accesses
+ - gpmc,cycle2cycle-delay-ns:  Delay between chip-select pulses
+ - gpmc,clk-activation-ns:     GPMC clock activation time
+ - gpmc,wait-monitoring-ns:    Start of wait monitoring with regard to valid
+                               data
+
+Boolean timing parameters. If property is present parameter enabled and
+disabled if omitted:
+ - gpmc,adv-extra-delay:       ADV signal is delayed by half GPMC clock
+ - gpmc,cs-extra-delay:                CS signal is delayed by half GPMC clock
+ - gpmc,cycle2cycle-diffcsen:  Add "cycle2cycle-delay" between successive
+                               accesses to a different CS
+ - gpmc,cycle2cycle-samecsen:  Add "cycle2cycle-delay" between successive
+                               accesses to the same CS
+ - gpmc,oe-extra-delay:                OE signal is delayed by half GPMC clock
+ - gpmc,we-extra-delay:                WE signal is delayed by half GPMC clock
+ - gpmc,time-para-granularity: Multiply all access times by 2
+
+The following are only applicable to OMAP3+ and AM335x:
+ - gpmc,wr-access-ns:          In synchronous write mode, for single or
+                               burst accesses, defines the number of
+                               GPMC_FCLK cycles from start access time
+                               to the GPMC_CLK rising edge used by the
+                               memory device for the first data capture.
+ - gpmc,wr-data-mux-bus-ns:    In address-data multiplex mode, specifies
+                               the time when the first data is driven on
+                               the address-data bus.
+
+GPMC chip-select settings properties for child nodes. All are optional.
+
+- gpmc,burst-length    Page/burst length. Must be 4, 8 or 16.
+- gpmc,burst-wrap      Enables wrap bursting
+- gpmc,burst-read      Enables read page/burst mode
+- gpmc,burst-write     Enables write page/burst mode
+- gpmc,device-width    Total width of device(s) connected to a GPMC
+                       chip-select in bytes. The GPMC supports 8-bit
+                       and 16-bit devices and so this property must be
+                       1 or 2.
+- gpmc,mux-add-data    Address and data multiplexing configuration.
+                       Valid values are 1 for address-address-data
+                       multiplexing mode and 2 for address-data
+                       multiplexing mode.
+- gpmc,sync-read       Enables synchronous read. Defaults to asynchronous
+                       is this is not set.
+- gpmc,sync-write      Enables synchronous writes. Defaults to asynchronous
+                       is this is not set.
+- gpmc,wait-pin                Wait-pin used by client. Must be less than
+                       "gpmc,num-waitpins".
+- gpmc,wait-on-read    Enables wait monitoring on reads.
+- gpmc,wait-on-write   Enables wait monitoring on writes.
+
+Example for an AM33xx board:
+
+       gpmc: gpmc@50000000 {
+               compatible = "ti,am3352-gpmc";
+               ti,hwmods = "gpmc";
+               reg = <0x50000000 0x2000>;
+               interrupts = <100>;
+
+               gpmc,num-cs = <8>;
+               gpmc,num-waitpins = <2>;
+               #address-cells = <2>;
+               #size-cells = <1>;
+               ranges = <0 0 0x08000000 0x10000000>; /* CS0 @addr 0x8000000, size 0x10000000 */
+               interrupt-controller;
+               #interrupt-cells = <2>;
+               gpio-controller;
+               #gpio-cells = <2>;
+
+               /* child nodes go here */
+       };
index 0f6985b5de49afb7eb38991d86197ba407cb87cf..7066597c9a81850af6db19424b4c7449baf828b1 100644 (file)
@@ -24,6 +24,7 @@ Required properties:
                          brcm,brcmnand-v5.0
                          brcm,brcmnand-v6.0
                          brcm,brcmnand-v6.1
+                         brcm,brcmnand-v6.2
                          brcm,brcmnand-v7.0
                          brcm,brcmnand-v7.1
                          brcm,brcmnand
index fb733c4e1c116e76bea05e690bbd968fd66c8395..3ee7e202657cdb83f7e430ff7b00a29ba69ed097 100644 (file)
@@ -13,7 +13,11 @@ Documentation/devicetree/bindings/mtd/nand.txt
 
 Required properties:
 
- - reg:                The CS line the peripheral is connected to
+ - compatible: "ti,omap2-nand"
+ - reg:                range id (CS number), base offset and length of the
+               NAND I/O space
+ - interrupt-parent: must point to gpmc node
+ - interrupts: Two interrupt specifiers, one for fifoevent, one for termcount.
 
 Optional properties:
 
@@ -44,6 +48,7 @@ Optional properties:
                locating ECC errors for BCHx algorithms. SoC devices which have
                ELM hardware engines should specify this device node in .dtsi
                Using ELM for ECC error correction frees some CPU cycles.
+ - rb-gpios:   GPIO specifier for the ready/busy# pin.
 
 For inline partition table parsing (optional):
 
@@ -55,20 +60,26 @@ Example for an AM33xx board:
        gpmc: gpmc@50000000 {
                compatible = "ti,am3352-gpmc";
                ti,hwmods = "gpmc";
-               reg = <0x50000000 0x1000000>;
+               reg = <0x50000000 0x36c>;
                interrupts = <100>;
                gpmc,num-cs = <8>;
                gpmc,num-waitpins = <2>;
                #address-cells = <2>;
                #size-cells = <1>;
-               ranges = <0 0 0x08000000 0x2000>;       /* CS0: NAND */
+               ranges = <0 0 0x08000000 0x1000000>;    /* CS0 space, 16MB */
                elm_id = <&elm>;
+               interrupt-controller;
+               #interrupt-cells = <2>;
 
                nand@0,0 {
-                       reg = <0 0 0>; /* CS0, offset 0 */
+                       compatible = "ti,omap2-nand";
+                       reg = <0 0 4>;          /* CS0, offset 0, NAND I/O window 4 */
+                       interrupt-parent = <&gpmc>;
+                       interrupts = <0 IRQ_TYPE_NONE>, <1 IRQ_TYPE NONE>;
                        nand-bus-width = <16>;
                        ti,nand-ecc-opt = "bch8";
                        ti,nand-xfer-type = "polled";
+                       rb-gpios = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
 
                        gpmc,sync-clk-ps = <0>;
                        gpmc,cs-on-ns = <0>;
index b53f92e252d4a7f48427ca1e123381dc04e91e41..68342eac23833951c272b5153874cdd6f774db5f 100644 (file)
@@ -1,8 +1,31 @@
-* MTD generic binding
+* NAND chip and NAND controller generic binding
+
+NAND controller/NAND chip representation:
+
+The NAND controller should be represented with its own DT node, and all
+NAND chips attached to this controller should be defined as children nodes
+of the NAND controller. This representation should be enforced even for
+simple controllers supporting only one chip.
+
+Mandatory NAND controller properties:
+- #address-cells: depends on your controller. Should at least be 1 to
+                 encode the CS line id.
+- #size-cells: depends on your controller. Put zero unless you need a
+              mapping between CS lines and dedicated memory regions
+
+Optional NAND controller properties
+- ranges: only needed if you need to define a mapping between CS lines and
+         memory regions
+
+Optional NAND chip properties:
 
 - nand-ecc-mode : String, operation mode of the NAND ecc mode.
-  Supported values are: "none", "soft", "hw", "hw_syndrome", "hw_oob_first",
-  "soft_bch".
+                 Supported values are: "none", "soft", "hw", "hw_syndrome",
+                 "hw_oob_first".
+                 Deprecated values:
+                 "soft_bch": use "soft" and nand-ecc-algo instead
+- nand-ecc-algo: string, algorithm of NAND ECC.
+                Supported values are: "hamming", "bch".
 - nand-bus-width : 8 or 16 bus width if not present 8
 - nand-on-flash-bbt: boolean to enable on flash bbt option if not present false
 
@@ -19,3 +42,19 @@ errors per {size} bytes".
 The interpretation of these parameters is implementation-defined, so not all
 implementations must support all possible combinations. However, implementations
 are encouraged to further specify the value(s) they support.
+
+Example:
+
+       nand-controller {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               /* controller specific properties */
+
+               nand@0 {
+                       reg = <0>;
+                       nand-ecc-mode = "soft_bch";
+
+                       /* controller specific properties */
+               };
+       };
diff --git a/Documentation/devicetree/bindings/spi/microchip,spi-pic32.txt b/Documentation/devicetree/bindings/spi/microchip,spi-pic32.txt
new file mode 100644 (file)
index 0000000..79de379
--- /dev/null
@@ -0,0 +1,34 @@
+Microchip PIC32 SPI Master controller
+
+Required properties:
+- compatible: Should be "microchip,pic32mzda-spi".
+- reg: Address and length of register space for the device.
+- interrupts: Should contain all three spi interrupts in sequence
+              of <fault-irq>, <receive-irq>, <transmit-irq>.
+- interrupt-names: Should be "fault", "rx", "tx" in order.
+- clocks: Phandle of the clock generating SPI clock on the bus.
+- clock-names: Should be "mck0".
+- cs-gpios: Specifies the gpio pins to be used for chipselects.
+            See: Documentation/devicetree/bindings/spi/spi-bus.txt
+
+Optional properties:
+- dmas: Two or more DMA channel specifiers following the convention outlined
+        in Documentation/devicetree/bindings/dma/dma.txt
+- dma-names: Names for the dma channels. There must be at least one channel
+             named "spi-tx" for transmit and named "spi-rx" for receive.
+
+Example:
+
+spi1: spi@1f821000 {
+        compatible = "microchip,pic32mzda-spi";
+        reg = <0x1f821000 0x200>;
+        interrupts = <109 IRQ_TYPE_LEVEL_HIGH>,
+                     <110 IRQ_TYPE_LEVEL_HIGH>,
+                     <111 IRQ_TYPE_LEVEL_HIGH>;
+        interrupt-names = "fault", "rx", "tx";
+        clocks = <&PBCLK2>;
+        clock-names = "mck0";
+        cs-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
+        dmas = <&dma 134>, <&dma 135>;
+        dma-names = "spi-rx", "spi-tx";
+};
index 1ad0fe310ff990966cb18ae64c1e992793086c52..ff5893d275a2132e63f5f824f9a074d18e904865 100644 (file)
@@ -16,8 +16,7 @@ Required properties:
 
 Optional property:
 - big-endian: If present the dspi device's registers are implemented
-  in big endian mode, otherwise in native mode(same with CPU), for more
-  detail please see: Documentation/devicetree/bindings/regmap/regmap.txt.
+  in big endian mode.
 
 Optional SPI slave node properties:
 - fsl,spi-cs-sck-delay: a delay in nanoseconds between activating chip
diff --git a/Documentation/devicetree/bindings/spi/sqi-pic32.txt b/Documentation/devicetree/bindings/spi/sqi-pic32.txt
new file mode 100644 (file)
index 0000000..c82d021
--- /dev/null
@@ -0,0 +1,18 @@
+Microchip PIC32 Quad SPI controller
+-----------------------------------
+Required properties:
+- compatible: Should be "microchip,pic32mzda-sqi".
+- reg: Address and length of SQI controller register space.
+- interrupts: Should contain SQI interrupt.
+- clocks: Should contain phandle of two clocks in sequence, one that drives
+          clock on SPI bus and other that drives SQI controller.
+- clock-names: Should be "spi_ck" and "reg_ck" in order.
+
+Example:
+       sqi1: spi@1f8e2000 {
+               compatible = "microchip,pic32mzda-sqi";
+               reg = <0x1f8e2000 0x200>;
+               clocks = <&rootclk REF2CLK>, <&rootclk PB5CLK>;
+               clock-names = "spi_ck", "reg_ck";
+               interrupts = <169 IRQ_TYPE_LEVEL_HIGH>;
+       };
index 39e58d1cdf90b7d8f84d108d8024d8974c3b800c..41fa2ec9e02c7721717e5c513bc9703ebed5bed4 100644 (file)
@@ -15,6 +15,7 @@
 #if !defined(_UAPI_ASM_ARC_UNISTD_H) || defined(__SYSCALL)
 #define _UAPI_ASM_ARC_UNISTD_H
 
+#define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_SYS_EXECVE
 #define __ARCH_WANT_SYS_CLONE
 #define __ARCH_WANT_SYS_VFORK
index 0f89d87cb2a0ab99f801471a24e17eb5391a13bb..06b6c2d695bfb6bfbb0a61bbfffd958a58bf20d3 100644 (file)
@@ -399,6 +399,7 @@ dtb-$(CONFIG_SOC_IMX6UL) += \
        imx6ul-tx6ul-mainboard.dtb
 dtb-$(CONFIG_SOC_IMX7D) += \
        imx7d-cl-som-imx7.dtb \
+       imx7d-nitrogen7.dtb \
        imx7d-sbc-imx7.dtb \
        imx7d-sdb.dtb
 dtb-$(CONFIG_SOC_LS1021A) += \
index 267f81adb42fbc01e4361fc6ea9014bfa2bc5a9a..8c89062663108a7f4e9579f911778f5954cba33d 100644 (file)
@@ -14,6 +14,7 @@
 
 /dts-v1/;
 #include "exynos3250.dtsi"
+#include "exynos4412-ppmu-common.dtsi"
 #include <dt-bindings/input/input.h>
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/clock/samsung,s2mps11.h>
        };
 };
 
+&bus_dmc {
+       devfreq-events = <&ppmu_dmc0_3>, <&ppmu_dmc1_3>;
+       vdd-supply = <&buck1_reg>;
+       status = "okay";
+};
+
 &cpu0 {
        cpu0-supply = <&buck2_reg>;
 };
        status = "okay";
 };
 
-&ppmu_dmc0 {
-       status = "okay";
-
-       events {
-               ppmu_dmc0_3: ppmu-event3-dmc0 {
-                       event-name = "ppmu-event3-dmc0";
-               };
-       };
-};
-
-&ppmu_dmc1 {
-       status = "okay";
-
-       events {
-               ppmu_dmc1_3: ppmu-event3-dmc1 {
-                       event-name = "ppmu-event3-dmc1";
-               };
-       };
-};
-
-&ppmu_leftbus {
-       status = "okay";
-
-       events {
-               ppmu_leftbus_3: ppmu-event3-leftbus {
-                       event-name = "ppmu-event3-leftbus";
-               };
-       };
-};
-
-&ppmu_rightbus {
-       status = "okay";
-
-       events {
-               ppmu_rightbus_3: ppmu-event3-rightbus {
-                       event-name = "ppmu-event3-rightbus";
-               };
-       };
-};
-
 &xusbxti {
        clock-frequency = <24000000>;
 };
index 31eb09bae0a2f9b10f7cd7b6f984d7a8ef57916d..e422819591dcb32e33b27a4f2ef6a94057961e4b 100644 (file)
@@ -14,6 +14,7 @@
 
 /dts-v1/;
 #include "exynos3250.dtsi"
+#include "exynos4412-ppmu-common.dtsi"
 #include <dt-bindings/input/input.h>
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/clock/samsung,s2mps11.h>
        };
 };
 
+&bus_dmc {
+       devfreq-events = <&ppmu_dmc0_3>, <&ppmu_dmc1_3>;
+       vdd-supply = <&buck1_reg>;
+       status = "okay";
+};
+
+&bus_leftbus {
+       devfreq-events = <&ppmu_leftbus_3>, <&ppmu_rightbus_3>;
+       vdd-supply = <&buck3_reg>;
+       status = "okay";
+};
+
+&bus_rightbus {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_lcd0 {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_fsys {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_mcuisp {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_isp {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_peril {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_mfc {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
 &cpu0 {
        cpu0-supply = <&buck2_reg>;
 };
        status = "okay";
 };
 
-&ppmu_dmc0 {
-       status = "okay";
-
-       events {
-               ppmu_dmc0_3: ppmu-event3-dmc0 {
-                       event-name = "ppmu-event3-dmc0";
-               };
-       };
-};
-
-&ppmu_dmc1 {
-       status = "okay";
-
-       events {
-               ppmu_dmc1_3: ppmu-event3-dmc1 {
-                       event-name = "ppmu-event3-dmc1";
-               };
-       };
-};
-
-&ppmu_leftbus {
-       status = "okay";
-
-       events {
-               ppmu_leftbus_3: ppmu-event3-leftbus {
-                       event-name = "ppmu-event3-leftbus";
-               };
-       };
-};
-
-&ppmu_rightbus {
-       status = "okay";
-
-       events {
-               ppmu_rightbus_3: ppmu-event3-rightbus {
-                       event-name = "ppmu-event3-rightbus";
-               };
-       };
-};
-
 &xusbxti {
        clock-frequency = <24000000>;
 };
index 094782b207ee138362d294f4770438a175a77730..62f3dcd9e046c3dc526d81a8bd70a575be99487f 100644 (file)
                        clock-names = "ppmu";
                        status = "disabled";
                };
+
+               bus_dmc: bus_dmc {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu_dmc CLK_DIV_DMC>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_dmc_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_dmc_opp_table: opp_table1 {
+                       compatible = "operating-points-v2";
+                       opp-shared;
+
+                       opp@50000000 {
+                               opp-hz = /bits/ 64 <50000000>;
+                               opp-microvolt = <800000>;
+                       };
+                       opp@100000000 {
+                               opp-hz = /bits/ 64 <100000000>;
+                               opp-microvolt = <800000>;
+                       };
+                       opp@134000000 {
+                               opp-hz = /bits/ 64 <134000000>;
+                               opp-microvolt = <800000>;
+                       };
+                       opp@200000000 {
+                               opp-hz = /bits/ 64 <200000000>;
+                               opp-microvolt = <825000>;
+                       };
+                       opp@400000000 {
+                               opp-hz = /bits/ 64 <400000000>;
+                               opp-microvolt = <875000>;
+                       };
+               };
+
+               bus_leftbus: bus_leftbus {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_GDL>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_leftbus_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_rightbus: bus_rightbus {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_GDR>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_leftbus_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_lcd0: bus_lcd0 {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_ACLK_160>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_leftbus_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_fsys: bus_fsys {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_ACLK_200>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_leftbus_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_mcuisp: bus_mcuisp {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_ACLK_400_MCUISP>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_mcuisp_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_isp: bus_isp {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_ACLK_266>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_isp_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_peril: bus_peril {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_DIV_ACLK_100>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_peril_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_mfc: bus_mfc {
+                       compatible = "samsung,exynos-bus";
+                       clocks = <&cmu CLK_SCLK_MFC>;
+                       clock-names = "bus";
+                       operating-points-v2 = <&bus_leftbus_opp_table>;
+                       status = "disabled";
+               };
+
+               bus_leftbus_opp_table: opp_table2 {
+                       compatible = "operating-points-v2";
+                       opp-shared;
+
+                       opp@50000000 {
+                               opp-hz = /bits/ 64 <50000000>;
+                               opp-microvolt = <900000>;
+                       };
+                       opp@80000000 {
+                               opp-hz = /bits/ 64 <80000000>;
+                               opp-microvolt = <900000>;
+                       };
+                       opp@100000000 {
+                               opp-hz = /bits/ 64 <100000000>;
+                               opp-microvolt = <1000000>;
+                       };
+                       opp@134000000 {
+                               opp-hz = /bits/ 64 <134000000>;
+                               opp-microvolt = <1000000>;
+                       };
+                       opp@200000000 {
+                               opp-hz = /bits/ 64 <200000000>;
+                               opp-microvolt = <1000000>;
+                       };
+               };
+
+               bus_mcuisp_opp_table: opp_table3 {
+                       compatible = "operating-points-v2";
+                       opp-shared;
+
+                       opp@50000000 {
+                               opp-hz = /bits/ 64 <50000000>;
+                       };
+                       opp@80000000 {
+                               opp-hz = /bits/ 64 <80000000>;
+                       };
+                       opp@100000000 {
+                               opp-hz = /bits/ 64 <100000000>;
+                       };
+                       opp@200000000 {
+                               opp-hz = /bits/ 64 <200000000>;
+                       };
+                       opp@400000000 {
+                               opp-hz = /bits/ 64 <400000000>;
+                       };
+               };
+
+               bus_isp_opp_table: opp_table4 {
+                       compatible = "operating-points-v2";
+                       opp-shared;
+
+                       opp@50000000 {
+                               opp-hz = /bits/ 64 <50000000>;
+                       };
+                       opp@80000000 {
+                               opp-hz = /bits/ 64 <80000000>;
+                       };
+                       opp@100000000 {
+                               opp-hz = /bits/ 64 <100000000>;
+                       };
+                       opp@200000000 {
+                               opp-hz = /bits/ 64 <200000000>;
+                       };
+                       opp@300000000 {
+                               opp-hz = /bits/ 64 <300000000>;
+                       };
+               };
+
+               bus_peril_opp_table: opp_table5 {
+                       compatible = "operating-points-v2";
+                       opp-shared;
+
+                       opp@50000000 {
+                               opp-hz = /bits/ 64 <50000000>;
+                       };
+                       opp@80000000 {
+                               opp-hz = /bits/ 64 <80000000>;
+                       };
+                       opp@100000000 {
+                               opp-hz = /bits/ 64 <100000000>;
+                       };
+               };
        };
 };
 
index c1cb8df6da0771f90d06280babf3ca202b702c99..2d9b02967105fd7e9320adba5625d4e5bb2a0be4 100644 (file)
                power-domains = <&pd_lcd1>;
                #iommu-cells = <0>;
        };
+
+       bus_dmc: bus_dmc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_DMC>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_dmc_opp_table>;
+               status = "disabled";
+       };
+
+       bus_acp: bus_acp {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_ACP>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_acp_opp_table>;
+               status = "disabled";
+       };
+
+       bus_peri: bus_peri {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK100>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_peri_opp_table>;
+               status = "disabled";
+       };
+
+       bus_fsys: bus_fsys {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK133>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_fsys_opp_table>;
+               status = "disabled";
+       };
+
+       bus_display: bus_display {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK160>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_display_opp_table>;
+               status = "disabled";
+       };
+
+       bus_lcd0: bus_lcd0 {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK200>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_leftbus: bus_leftbus {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_GDL>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_rightbus: bus_rightbus {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_GDR>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_mfc: bus_mfc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_SCLK_MFC>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_dmc_opp_table: opp_table1 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+                       opp-microvolt = <1025000>;
+               };
+               opp@267000000 {
+                       opp-hz = /bits/ 64 <267000000>;
+                       opp-microvolt = <1050000>;
+               };
+               opp@400000000 {
+                       opp-hz = /bits/ 64 <400000000>;
+                       opp-microvolt = <1150000>;
+               };
+       };
+
+       bus_acp_opp_table: opp_table2 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+               };
+               opp@200000000 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+       };
+
+       bus_peri_opp_table: opp_table3 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@5000000 {
+                       opp-hz = /bits/ 64 <5000000>;
+               };
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+       };
+
+       bus_fsys_opp_table: opp_table4 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@10000000 {
+                       opp-hz = /bits/ 64 <10000000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+       };
+
+       bus_display_opp_table: opp_table5 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+               };
+       };
+
+       bus_leftbus_opp_table: opp_table6 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+               };
+               opp@200000000 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+       };
 };
 
 &gic {
index cab0f07d7d282a168df14516426951106aecf3bc..ec7619a384a2b31943ba61f624c893341df90e38 100644 (file)
@@ -11,6 +11,7 @@
 #include <dt-bindings/input/input.h>
 #include <dt-bindings/clock/maxim,max77686.h>
 #include "exynos4412.dtsi"
+#include "exynos4412-ppmu-common.dtsi"
 #include <dt-bindings/gpio/gpio.h>
 
 / {
        };
 };
 
+&bus_dmc {
+       devfreq-events = <&ppmu_dmc0_3>, <&ppmu_dmc1_3>;
+       vdd-supply = <&buck1_reg>;
+       status = "okay";
+};
+
+&bus_acp {
+       devfreq = <&bus_dmc>;
+       status = "okay";
+};
+
+&bus_c2c {
+       devfreq = <&bus_dmc>;
+       status = "okay";
+};
+
+&bus_leftbus {
+       devfreq-events = <&ppmu_leftbus_3>, <&ppmu_rightbus_3>;
+       vdd-supply = <&buck3_reg>;
+       status = "okay";
+};
+
+&bus_rightbus {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_display {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_fsys {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_peri {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_mfc {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
 &cpu0 {
        cpu0-supply = <&buck2_reg>;
 };
 
                        buck1_reg: BUCK1 {
                                regulator-name = "vdd_mif";
-                               regulator-min-microvolt = <1000000>;
-                               regulator-max-microvolt = <1000000>;
+                               regulator-min-microvolt = <900000>;
+                               regulator-max-microvolt = <1100000>;
                                regulator-always-on;
                                regulator-boot-on;
                        };
 
                        buck3_reg: BUCK3 {
                                regulator-name = "vdd_int";
-                               regulator-min-microvolt = <1000000>;
-                               regulator-max-microvolt = <1000000>;
+                               regulator-min-microvolt = <900000>;
+                               regulator-max-microvolt = <1050000>;
                                regulator-always-on;
                                regulator-boot-on;
                        };
diff --git a/arch/arm/boot/dts/exynos4412-ppmu-common.dtsi b/arch/arm/boot/dts/exynos4412-ppmu-common.dtsi
new file mode 100644 (file)
index 0000000..16e4b77
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Device tree sources for Exynos4412 PPMU common device tree
+ *
+ * Copyright (C) 2015 Samsung Electronics
+ * Author: Chanwoo Choi <cw00.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+&ppmu_dmc0 {
+       status = "okay";
+
+       events {
+              ppmu_dmc0_3: ppmu-event3-dmc0 {
+                      event-name = "ppmu-event3-dmc0";
+              };
+       };
+};
+
+&ppmu_dmc1 {
+       status = "okay";
+
+       events {
+              ppmu_dmc1_3: ppmu-event3-dmc1 {
+                      event-name = "ppmu-event3-dmc1";
+              };
+       };
+};
+
+&ppmu_leftbus {
+       status = "okay";
+
+       events {
+              ppmu_leftbus_3: ppmu-event3-leftbus {
+                      event-name = "ppmu-event3-leftbus";
+              };
+       };
+};
+
+&ppmu_rightbus {
+       status = "okay";
+
+       events {
+              ppmu_rightbus_3: ppmu-event3-rightbus {
+                      event-name = "ppmu-event3-rightbus";
+              };
+       };
+};
index 5d1eaea3f77806ae8c4d6a9b26893d3437ecdf9c..9336fd4824d9949db63f3b91b59e8dfb67e81d14 100644 (file)
@@ -14,6 +14,7 @@
 
 /dts-v1/;
 #include "exynos4412.dtsi"
+#include "exynos4412-ppmu-common.dtsi"
 #include <dt-bindings/gpio/gpio.h>
 #include <dt-bindings/interrupt-controller/irq.h>
 #include <dt-bindings/clock/maxim,max77686.h>
        status = "okay";
 };
 
+&bus_dmc {
+       devfreq-events = <&ppmu_dmc0_3>, <&ppmu_dmc1_3>;
+       vdd-supply = <&buck1_reg>;
+       status = "okay";
+};
+
+&bus_acp {
+       devfreq = <&bus_dmc>;
+       status = "okay";
+};
+
+&bus_c2c {
+       devfreq = <&bus_dmc>;
+       status = "okay";
+};
+
+&bus_leftbus {
+       devfreq-events = <&ppmu_leftbus_3>, <&ppmu_rightbus_3>;
+       vdd-supply = <&buck3_reg>;
+       status = "okay";
+};
+
+&bus_rightbus {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_display {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_fsys {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_peri {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
+&bus_mfc {
+       devfreq = <&bus_leftbus>;
+       status = "okay";
+};
+
 &cpu0 {
        cpu0-supply = <&buck2_reg>;
 };
        assigned-clock-parents =  <&clock CLK_XUSBXTI>;
 };
 
-&ppmu_dmc0 {
-       status = "okay";
-
-       events {
-               ppmu_dmc0_3: ppmu-event3-dmc0 {
-                       event-name = "ppmu-event3-dmc0";
-               };
-       };
-};
-
-&ppmu_dmc1 {
-       status = "okay";
-
-       events {
-               ppmu_dmc1_3: ppmu-event3-dmc1 {
-                       event-name = "ppmu-event3-dmc1";
-               };
-       };
-};
-
-&ppmu_leftbus {
-       status = "okay";
-
-       events {
-               ppmu_leftbus_3: ppmu-event3-leftbus {
-                       event-name = "ppmu-event3-leftbus";
-               };
-       };
-};
-
-&ppmu_rightbus {
-       status = "okay";
-
-       events {
-               ppmu_rightbus_3: ppmu-event3-rightbus {
-                       event-name = "ppmu-event3-rightbus";
-               };
-       };
-};
-
 &pinctrl_0 {
        pinctrl-names = "default";
        pinctrl-0 = <&sleep0>;
index b7490ea0c75cc536c89f5d8f014b6248d50ab0e6..c452499ae8c9a45a128e15dd80f9e29a439d3155 100644 (file)
                clocks = <&clock CLK_SMMU_LITE1>, <&clock CLK_FIMC_LITE1>;
                #iommu-cells = <0>;
        };
+
+       bus_dmc: bus_dmc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_DMC>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_dmc_opp_table>;
+               status = "disabled";
+       };
+
+       bus_acp: bus_acp {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_ACP>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_acp_opp_table>;
+               status = "disabled";
+       };
+
+       bus_c2c: bus_c2c {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_C2C>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_dmc_opp_table>;
+               status = "disabled";
+       };
+
+       bus_dmc_opp_table: opp_table1 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+                       opp-microvolt = <900000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+                       opp-microvolt = <900000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+                       opp-microvolt = <900000>;
+               };
+               opp@267000000 {
+                       opp-hz = /bits/ 64 <267000000>;
+                       opp-microvolt = <950000>;
+               };
+               opp@400000000 {
+                       opp-hz = /bits/ 64 <400000000>;
+                       opp-microvolt = <1050000>;
+               };
+       };
+
+       bus_acp_opp_table: opp_table2 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+               };
+               opp@267000000 {
+                       opp-hz = /bits/ 64 <267000000>;
+               };
+       };
+
+       bus_leftbus: bus_leftbus {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_GDL>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_rightbus: bus_rightbus {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DIV_GDR>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_display: bus_display {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK160>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_display_opp_table>;
+               status = "disabled";
+       };
+
+       bus_fsys: bus_fsys {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK133>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_fsys_opp_table>;
+               status = "disabled";
+       };
+
+       bus_peri: bus_peri {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_ACLK100>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_peri_opp_table>;
+               status = "disabled";
+       };
+
+       bus_mfc: bus_mfc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_SCLK_MFC>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_leftbus_opp_table>;
+               status = "disabled";
+       };
+
+       bus_leftbus_opp_table: opp_table3 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+                       opp-microvolt = <900000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+                       opp-microvolt = <925000>;
+               };
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+                       opp-microvolt = <950000>;
+               };
+               opp@200000000 {
+                       opp-hz = /bits/ 64 <200000000>;
+                       opp-microvolt = <1000000>;
+               };
+       };
+
+       bus_display_opp_table: opp_table4 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@160000000 {
+                       opp-hz = /bits/ 64 <160000000>;
+               };
+               opp@200000000 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+       };
+
+       bus_fsys_opp_table: opp_table5 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp@134000000 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+       };
+
+       bus_peri_opp_table: opp_table6 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp@50000000 {
+                       opp-hz = /bits/ 64 <50000000>;
+               };
+               opp@100000000 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+       };
 };
 
 &combiner {
index 4c8523471c65e5701ac5ccd34bb748a029caa83e..c6e05eb88937d0c59bf09a2b546435937f723c1c 100644 (file)
                };
        };
 
+       nocp_mem0_0: nocp@10CA1000 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x10CA1000 0x200>;
+               status = "disabled";
+       };
+
+       nocp_mem0_1: nocp@10CA1400 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x10CA1400 0x200>;
+               status = "disabled";
+       };
+
+       nocp_mem1_0: nocp@10CA1800 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x10CA1800 0x200>;
+               status = "disabled";
+       };
+
+       nocp_mem1_1: nocp@10CA1C00 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x10CA1C00 0x200>;
+               status = "disabled";
+       };
+
+       nocp_g3d_0: nocp@11A51000 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x11A51000 0x200>;
+               status = "disabled";
+       };
+
+       nocp_g3d_1: nocp@11A51400 {
+               compatible = "samsung,exynos5420-nocp";
+               reg = <0x11A51400 0x200>;
+               status = "disabled";
+       };
+
        gsc_pd: power-domain@10044000 {
                compatible = "samsung,exynos4210-pd";
                reg = <0x10044000 0x20>;
                power-domains = <&disp_pd>;
                #iommu-cells = <0>;
        };
+
+       bus_wcore: bus_wcore {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK400_WCORE>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_wcore_opp_table>;
+               status = "disabled";
+       };
+
+       bus_noc: bus_noc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK100_NOC>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_noc_opp_table>;
+               status = "disabled";
+       };
+
+       bus_fsys_apb: bus_fsys_apb {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_PCLK200_FSYS>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_fsys_apb_opp_table>;
+               status = "disabled";
+       };
+
+       bus_fsys: bus_fsys {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK200_FSYS>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_fsys_apb_opp_table>;
+               status = "disabled";
+       };
+
+       bus_fsys2: bus_fsys2 {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK200_FSYS2>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_fsys2_opp_table>;
+               status = "disabled";
+       };
+
+       bus_mfc: bus_mfc {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK333>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_mfc_opp_table>;
+               status = "disabled";
+       };
+
+       bus_gen: bus_gen {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK266>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_gen_opp_table>;
+               status = "disabled";
+       };
+
+       bus_peri: bus_peri {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK66>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_peri_opp_table>;
+               status = "disabled";
+       };
+
+       bus_g2d: bus_g2d {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK333_G2D>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_g2d_opp_table>;
+               status = "disabled";
+       };
+
+       bus_g2d_acp: bus_g2d_acp {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK266_G2D>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_g2d_acp_opp_table>;
+               status = "disabled";
+       };
+
+       bus_jpeg: bus_jpeg {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK300_JPEG>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_jpeg_opp_table>;
+               status = "disabled";
+       };
+
+       bus_jpeg_apb: bus_jpeg_apb {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK166>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_jpeg_apb_opp_table>;
+               status = "disabled";
+       };
+
+       bus_disp1_fimd: bus_disp1_fimd {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK300_DISP1>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_disp1_fimd_opp_table>;
+               status = "disabled";
+       };
+
+       bus_disp1: bus_disp1 {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK400_DISP1>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_disp1_opp_table>;
+               status = "disabled";
+       };
+
+       bus_gscl_scaler: bus_gscl_scaler {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK300_GSCL>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_gscl_opp_table>;
+               status = "disabled";
+       };
+
+       bus_mscl: bus_mscl {
+               compatible = "samsung,exynos-bus";
+               clocks = <&clock CLK_DOUT_ACLK400_MSCL>;
+               clock-names = "bus";
+               operating-points-v2 = <&bus_mscl_opp_table>;
+               status = "disabled";
+       };
+
+       bus_wcore_opp_table: opp_table2 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <84000000>;
+                       opp-microvolt = <925000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <111000000>;
+                       opp-microvolt = <950000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <222000000>;
+                       opp-microvolt = <950000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <333000000>;
+                       opp-microvolt = <950000>;
+               };
+               opp04 {
+                       opp-hz = /bits/ 64 <400000000>;
+                       opp-microvolt = <987500>;
+               };
+       };
+
+       bus_noc_opp_table: opp_table3 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <67000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <75000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <86000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+       };
+
+       bus_fsys_apb_opp_table: opp_table4 {
+               compatible = "operating-points-v2";
+               opp-shared;
+
+               opp00 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+       };
+
+       bus_fsys2_opp_table: opp_table5 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <75000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <100000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <150000000>;
+               };
+       };
+
+       bus_mfc_opp_table: opp_table6 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <96000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <111000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <167000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <222000000>;
+               };
+               opp04 {
+                       opp-hz = /bits/ 64 <333000000>;
+               };
+       };
+
+       bus_gen_opp_table: opp_table7 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <89000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <133000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <178000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <267000000>;
+               };
+       };
+
+       bus_peri_opp_table: opp_table8 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <67000000>;
+               };
+       };
+
+       bus_g2d_opp_table: opp_table9 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <84000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <167000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <222000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <300000000>;
+               };
+               opp04 {
+                       opp-hz = /bits/ 64 <333000000>;
+               };
+       };
+
+       bus_g2d_acp_opp_table: opp_table10 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <67000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <133000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <178000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <267000000>;
+               };
+       };
+
+       bus_jpeg_opp_table: opp_table11 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <75000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <150000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <300000000>;
+               };
+       };
+
+       bus_jpeg_apb_opp_table: opp_table12 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <84000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <111000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <134000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <167000000>;
+               };
+       };
+
+       bus_disp1_fimd_opp_table: opp_table13 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <120000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+       };
+
+       bus_disp1_opp_table: opp_table14 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <120000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <300000000>;
+               };
+       };
+
+       bus_gscl_opp_table: opp_table15 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <150000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <200000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <300000000>;
+               };
+       };
+
+       bus_mscl_opp_table: opp_table16 {
+               compatible = "operating-points-v2";
+
+               opp00 {
+                       opp-hz = /bits/ 64 <84000000>;
+               };
+               opp01 {
+                       opp-hz = /bits/ 64 <167000000>;
+               };
+               opp02 {
+                       opp-hz = /bits/ 64 <222000000>;
+               };
+               opp03 {
+                       opp-hz = /bits/ 64 <333000000>;
+               };
+               opp04 {
+                       opp-hz = /bits/ 64 <400000000>;
+               };
+       };
 };
 
 &dp {
index 20fa7612080d9f065685a9fde7aa140e90afa185..2a4e10bc88012cfd976a205f6c8f0b81f9c788ee 100644 (file)
        };
 };
 
+&bus_wcore {
+       devfreq-events = <&nocp_mem0_0>, <&nocp_mem0_1>,
+                       <&nocp_mem1_0>, <&nocp_mem1_1>;
+       vdd-supply = <&buck3_reg>;
+       exynos,saturation-ratio = <100>;
+       status = "okay";
+};
+
+&bus_noc {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_fsys_apb {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_fsys {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_fsys2 {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_mfc {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_gen {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_peri {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_g2d {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_g2d_acp {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_jpeg {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_jpeg_apb {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_disp1_fimd {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_disp1 {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_gscl_scaler {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
+&bus_mscl {
+       devfreq = <&bus_wcore>;
+       status = "okay";
+};
+
 &clock_audss {
        assigned-clocks = <&clock_audss EXYNOS_MOUT_AUDSS>,
                        <&clock_audss EXYNOS_MOUT_I2S>,
        vqmmc-supply = <&ldo13_reg>;
 };
 
+&nocp_mem0_0 {
+       status = "okay";
+};
+
+&nocp_mem0_1 {
+       status = "okay";
+};
+
+&nocp_mem1_0 {
+       status = "okay";
+};
+
+&nocp_mem1_1 {
+       status = "okay";
+};
+
 &pinctrl_0 {
        hdmi_hpd_irq: hdmi-hpd-irq {
                samsung,pins = "gpx3-7";
diff --git a/arch/arm/boot/dts/imx7d-nitrogen7.dts b/arch/arm/boot/dts/imx7d-nitrogen7.dts
new file mode 100644 (file)
index 0000000..1ce9780
--- /dev/null
@@ -0,0 +1,745 @@
+/*
+ * Copyright 2016 Boundary Devices, Inc.
+ *
+ * This file is dual-licensed: you can use it either under the terms
+ * of the GPL or the X11 license, at your option. Note that this dual
+ * licensing only applies to this file, and not this project as a
+ * whole.
+ *
+ *  a) This file is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License as
+ *     published by the Free Software Foundation; either version 2 of the
+ *     License, or (at your option) any later version.
+ *
+ *     This file is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *     GNU General Public License for more details.
+ *
+ * Or, alternatively,
+ *
+ *  b) Permission is hereby granted, free of charge, to any person
+ *     obtaining a copy of this software and associated documentation
+ *     files (the "Software"), to deal in the Software without
+ *     restriction, including without limitation the rights to use,
+ *     copy, modify, merge, publish, distribute, sublicense, and/or
+ *     sell copies of the Software, and to permit persons to whom the
+ *     Software is furnished to do so, subject to the following
+ *     conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ *     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ *     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ *     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ *     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ *     OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/dts-v1/;
+
+#include <dt-bindings/input/input.h>
+#include "imx7d.dtsi"
+
+/ {
+       model = "Boundary Devices i.MX7 Nitrogen7 Board";
+       compatible = "boundary,imx7d-nitrogen7", "fsl,imx7d";
+
+       aliases {
+               fb_lcd = &lcdif;
+               t_lcd = &t_lcd;
+       };
+
+       memory {
+               reg = <0x80000000 0x40000000>;
+       };
+
+       backlight-j9 {
+               compatible = "gpio-backlight";
+               pinctrl-names = "default";
+               pinctrl-0 = <&pinctrl_backlight_j9>;
+               gpios = <&gpio1 7 GPIO_ACTIVE_HIGH>;
+               default-on;
+       };
+
+       backlight-j20 {
+               compatible = "pwm-backlight";
+               pwms = <&pwm1 0 5000000>;
+               brightness-levels = <0 4 8 16 32 64 128 255>;
+               default-brightness-level = <6>;
+               status = "okay";
+       };
+
+       reg_usb_otg1_vbus: regulator-usb-otg1-vbus {
+               compatible = "regulator-fixed";
+               regulator-name = "usb_otg1_vbus";
+               regulator-min-microvolt = <5000000>;
+               regulator-max-microvolt = <5000000>;
+               gpio = <&gpio1 5 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
+
+       reg_usb_otg2_vbus: regulator-usb-otg2-vbus {
+               compatible = "regulator-fixed";
+               regulator-name = "usb_otg2_vbus";
+               regulator-min-microvolt = <5000000>;
+               regulator-max-microvolt = <5000000>;
+               gpio = <&gpio4 7 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
+
+       reg_can2_3v3: regulator-can2-3v3 {
+               compatible = "regulator-fixed";
+               regulator-name = "can2-3v3";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               gpio = <&gpio2 14 GPIO_ACTIVE_LOW>;
+       };
+
+       reg_vref_1v8: regulator-vref-1v8 {
+               compatible = "regulator-fixed";
+               regulator-name = "vref-1v8";
+               regulator-min-microvolt = <1800000>;
+               regulator-max-microvolt = <1800000>;
+       };
+
+       reg_vref_3v3: regulator-vref-3v3 {
+               compatible = "regulator-fixed";
+               regulator-name = "vref-3v3";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+       };
+
+       reg_wlan: regulator-wlan {
+               compatible = "regulator-fixed";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               clocks = <&clks IMX7D_CLKO2_ROOT_DIV>;
+               clock-names = "slow";
+               regulator-name = "reg_wlan";
+               startup-delay-us = <70000>;
+               gpio = <&gpio4 21 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
+};
+
+&adc1 {
+       vref-supply = <&reg_vref_1v8>;
+       status = "okay";
+};
+
+&adc2 {
+       vref-supply = <&reg_vref_1v8>;
+       status = "okay";
+};
+
+&clks {
+       assigned-clocks = <&clks IMX7D_CLKO2_ROOT_SRC>,
+                         <&clks IMX7D_CLKO2_ROOT_DIV>;
+       assigned-clock-parents = <&clks IMX7D_CKIL>;
+       assigned-clock-rates = <0>, <32768>;
+};
+
+&cpu0 {
+       arm-supply = <&sw1a_reg>;
+};
+
+&fec1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_enet1>;
+       assigned-clocks = <&clks IMX7D_ENET1_TIME_ROOT_SRC>,
+                         <&clks IMX7D_ENET1_TIME_ROOT_CLK>;
+       assigned-clock-parents = <&clks IMX7D_PLL_ENET_MAIN_100M_CLK>;
+       assigned-clock-rates = <0>, <100000000>;
+       phy-mode = "rgmii";
+       phy-handle = <&ethphy0>;
+       fsl,magic-packet;
+       status = "okay";
+
+       mdio {
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               ethphy0: ethernet-phy@4 {
+                       reg = <4>;
+               };
+       };
+};
+
+&flexcan2 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_flexcan2>;
+       xceiver-supply = <&reg_can2_3v3>;
+       status = "okay";
+};
+
+&i2c1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_i2c1>;
+       status = "okay";
+
+       pmic: pfuze3000@08 {
+               compatible = "fsl,pfuze3000";
+               reg = <0x08>;
+
+               regulators {
+                       sw1a_reg: sw1a {
+                               regulator-min-microvolt = <700000>;
+                               regulator-max-microvolt = <1475000>;
+                               regulator-boot-on;
+                               regulator-always-on;
+                               regulator-ramp-delay = <6250>;
+                       };
+
+                       /* use sw1c_reg to align with pfuze100/pfuze200 */
+                       sw1c_reg: sw1b {
+                               regulator-min-microvolt = <700000>;
+                               regulator-max-microvolt = <1475000>;
+                               regulator-boot-on;
+                               regulator-always-on;
+                               regulator-ramp-delay = <6250>;
+                       };
+
+                       sw2_reg: sw2 {
+                               regulator-min-microvolt = <1500000>;
+                               regulator-max-microvolt = <1850000>;
+                               regulator-boot-on;
+                               regulator-always-on;
+                       };
+
+                       sw3a_reg: sw3 {
+                               regulator-min-microvolt = <900000>;
+                               regulator-max-microvolt = <1650000>;
+                               regulator-boot-on;
+                               regulator-always-on;
+                       };
+
+                       swbst_reg: swbst {
+                               regulator-min-microvolt = <5000000>;
+                               regulator-max-microvolt = <5150000>;
+                       };
+
+                       snvs_reg: vsnvs {
+                               regulator-min-microvolt = <1000000>;
+                               regulator-max-microvolt = <3000000>;
+                               regulator-boot-on;
+                               regulator-always-on;
+                       };
+
+                       vref_reg: vrefddr {
+                               regulator-boot-on;
+                               regulator-always-on;
+                       };
+
+                       vgen1_reg: vldo1 {
+                               regulator-min-microvolt = <1800000>;
+                               regulator-max-microvolt = <3300000>;
+                               regulator-always-on;
+                       };
+
+                       vgen2_reg: vldo2 {
+                               regulator-min-microvolt = <800000>;
+                               regulator-max-microvolt = <1550000>;
+                               regulator-always-on;
+                       };
+
+                       vgen3_reg: vccsd {
+                               regulator-min-microvolt = <2850000>;
+                               regulator-max-microvolt = <3300000>;
+                               regulator-always-on;
+                       };
+
+                       vgen4_reg: v33 {
+                               regulator-min-microvolt = <2850000>;
+                               regulator-max-microvolt = <3300000>;
+                               regulator-always-on;
+                       };
+
+                       vgen5_reg: vldo3 {
+                               regulator-min-microvolt = <1800000>;
+                               regulator-max-microvolt = <3300000>;
+                               regulator-always-on;
+                       };
+
+                       vgen6_reg: vldo4 {
+                               regulator-min-microvolt = <1800000>;
+                               regulator-max-microvolt = <3300000>;
+                               regulator-always-on;
+                       };
+               };
+       };
+};
+
+&i2c2 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_i2c2>;
+       status = "okay";
+
+       rtc@68 {
+               compatible = "rv4162";
+               pinctrl-names = "default";
+               pinctrl-0 = <&pinctrl_i2c2_rv4162>;
+               reg = <0x68>;
+               interrupts-extended = <&gpio2 15 IRQ_TYPE_LEVEL_LOW>;
+       };
+};
+
+&i2c3 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_i2c3>;
+       status = "okay";
+
+       touch@48 {
+               compatible = "ti,tsc2004";
+               reg = <0x48>;
+               pinctrl-names = "default";
+               pinctrl-0 = <&pinctrl_i2c3_tsc2004>;
+               interrupts-extended = <&gpio3 4 IRQ_TYPE_EDGE_FALLING>;
+               wakeup-gpios = <&gpio3 4 GPIO_ACTIVE_LOW>;
+       };
+};
+
+&i2c4 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_i2c4>;
+       status = "okay";
+
+       codec: wm8960@1a {
+               compatible = "wlf,wm8960";
+               reg = <0x1a>;
+               clocks = <&clks IMX7D_AUDIO_MCLK_ROOT_CLK>;
+               clock-names = "mclk";
+               wlf,shared-lrclk;
+       };
+};
+
+&lcdif {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_lcdif_dat
+                    &pinctrl_lcdif_ctrl>;
+       lcd-supply = <&reg_vref_3v3>;
+       display = <&display0>;
+       status = "okay";
+
+       display0: lcd-display {
+               bits-per-pixel = <16>;
+               bus-width = <18>;
+
+               display-timings {
+                       native-mode = <&t_lcd>;
+                       t_lcd: t_lcd_default {
+                               /* default to Okaya display */
+                               clock-frequency = <30000000>;
+                               hactive = <800>;
+                               vactive = <480>;
+                               hfront-porch = <40>;
+                               hback-porch = <40>;
+                               hsync-len = <48>;
+                               vback-porch = <29>;
+                               vfront-porch = <13>;
+                               vsync-len = <3>;
+                               hsync-active = <0>;
+                               vsync-active = <0>;
+                               de-active = <1>;
+                               pixelclk-active = <0>;
+                       };
+               };
+       };
+};
+
+&pwm1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_pwm1>;
+       status = "okay";
+};
+
+&pwm2 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_pwm2>;
+       status = "okay";
+};
+
+&uart1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_uart1>;
+       assigned-clocks = <&clks IMX7D_UART1_ROOT_SRC>;
+       assigned-clock-parents = <&clks IMX7D_OSC_24M_CLK>;
+       status = "okay";
+};
+
+&uart2 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_uart2>;
+       assigned-clocks = <&clks IMX7D_UART2_ROOT_SRC>;
+       assigned-clock-parents = <&clks IMX7D_OSC_24M_CLK>;
+       status = "okay";
+};
+
+&uart3 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_uart3>;
+       assigned-clocks = <&clks IMX7D_UART3_ROOT_SRC>;
+       assigned-clock-parents = <&clks IMX7D_OSC_24M_CLK>;
+       status = "okay";
+};
+
+&uart6 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_uart6>;
+       assigned-clocks = <&clks IMX7D_UART6_ROOT_SRC>;
+       assigned-clock-parents = <&clks IMX7D_PLL_SYS_MAIN_240M_CLK>;
+       fsl,uart-has-rtscts;
+       status = "okay";
+};
+
+&usbotg1 {
+       vbus-supply = <&reg_usb_otg1_vbus>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_usbotg1>;
+       status = "okay";
+};
+
+&usbotg2 {
+       vbus-supply = <&reg_usb_otg2_vbus>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_usbotg2>;
+       dr_mode = "host";
+       status = "okay";
+};
+
+&usdhc1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_usdhc1>;
+       cd-gpios = <&gpio5 0 GPIO_ACTIVE_LOW>;
+       vmmc-supply = <&vgen3_reg>;
+       bus-width = <4>;
+       fsl,tuning-step = <2>;
+       wakeup-source;
+       keep-power-in-suspend;
+       status = "okay";
+};
+
+&usdhc2 {
+       #address-cells = <1>;
+       #size-cells = <0>;
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_usdhc2>;
+       bus-width = <4>;
+       non-removable;
+       vmmc-supply = <&reg_wlan>;
+       cap-power-off-card;
+       keep-power-in-suspend;
+       status = "okay";
+
+       wlcore: wlcore@2 {
+               compatible = "ti,wl1271";
+               reg = <2>;
+               interrupt-parent = <&gpio4>;
+               interrupts = <20 IRQ_TYPE_LEVEL_HIGH>;
+               ref-clock-frequency = <38400000>;
+       };
+};
+
+&usdhc3 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_usdhc3>;
+       assigned-clocks = <&clks IMX7D_USDHC3_ROOT_CLK>;
+       assigned-clock-rates = <400000000>;
+       bus-width = <8>;
+       fsl,tuning-step = <2>;
+       non-removable;
+       status = "okay";
+};
+
+&wdog1 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_wdog1>;
+       status = "okay";
+};
+
+&iomuxc {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_hog_1 &pinctrl_j2>;
+
+       pinctrl_hog_1: hoggrp-1 {
+               fsl,pins = <
+                       MX7D_PAD_SD3_RESET_B__GPIO6_IO11        0x5d
+                       MX7D_PAD_GPIO1_IO13__GPIO1_IO13         0x7d
+                       MX7D_PAD_ECSPI2_MISO__GPIO4_IO22        0x7d
+               >;
+       };
+
+       pinctrl_enet1: enet1grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO10__ENET1_MDIO                 0x3
+                       MX7D_PAD_GPIO1_IO11__ENET1_MDC                  0x3
+                       MX7D_PAD_GPIO1_IO12__CCM_ENET_REF_CLK1          0x3
+                       MX7D_PAD_ENET1_RGMII_TXC__ENET1_RGMII_TXC       0x71
+                       MX7D_PAD_ENET1_RGMII_TD0__ENET1_RGMII_TD0       0x71
+                       MX7D_PAD_ENET1_RGMII_TD1__ENET1_RGMII_TD1       0x71
+                       MX7D_PAD_ENET1_RGMII_TD2__ENET1_RGMII_TD2       0x71
+                       MX7D_PAD_ENET1_RGMII_TD3__ENET1_RGMII_TD3       0x71
+                       MX7D_PAD_ENET1_RGMII_TX_CTL__ENET1_RGMII_TX_CTL 0x71
+                       MX7D_PAD_ENET1_RGMII_RXC__ENET1_RGMII_RXC       0x71
+                       MX7D_PAD_ENET1_RGMII_RD0__ENET1_RGMII_RD0       0x11
+                       MX7D_PAD_ENET1_RGMII_RD1__ENET1_RGMII_RD1       0x11
+                       MX7D_PAD_ENET1_RGMII_RD2__ENET1_RGMII_RD2       0x11
+                       MX7D_PAD_ENET1_RGMII_RD3__ENET1_RGMII_RD3       0x71
+                       MX7D_PAD_ENET1_RGMII_RX_CTL__ENET1_RGMII_RX_CTL 0x11
+                       MX7D_PAD_SD3_STROBE__GPIO6_IO10                 0x75
+               >;
+       };
+
+       pinctrl_flexcan2: flexcan2grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO14__FLEXCAN2_RX        0x7d
+                       MX7D_PAD_GPIO1_IO15__FLEXCAN2_TX        0x7d
+                       MX7D_PAD_EPDC_DATA14__GPIO2_IO14        0x7d
+               >;
+       };
+
+       pinctrl_i2c1: i2c1grp {
+               fsl,pins = <
+                       MX7D_PAD_I2C1_SDA__I2C1_SDA             0x4000007f
+                       MX7D_PAD_I2C1_SCL__I2C1_SCL             0x4000007f
+               >;
+       };
+
+       pinctrl_i2c2: i2c2grp {
+               fsl,pins = <
+                       MX7D_PAD_I2C2_SDA__I2C2_SDA             0x4000007f
+                       MX7D_PAD_I2C2_SCL__I2C2_SCL             0x4000007f
+               >;
+       };
+
+       pinctrl_i2c2_rv4162: i2c2-rv4162grp {
+               fsl,pins = <
+                       MX7D_PAD_EPDC_DATA15__GPIO2_IO15        0x7d
+               >;
+       };
+
+       pinctrl_i2c3: i2c3grp {
+               fsl,pins = <
+                       MX7D_PAD_I2C3_SDA__I2C3_SDA             0x4000007f
+                       MX7D_PAD_I2C3_SCL__I2C3_SCL             0x4000007f
+               >;
+       };
+
+       pinctrl_i2c3_tsc2004: i2c3tsc2004grp {
+               fsl,pins = <
+                       MX7D_PAD_LCD_RESET__GPIO3_IO4           0x79
+                       MX7D_PAD_SD2_WP__GPIO5_IO10             0x7d
+               >;
+       };
+
+       pinctrl_i2c4: i2c4grp {
+               fsl,pins = <
+                       MX7D_PAD_I2C4_SDA__I2C4_SDA             0x4000007f
+                       MX7D_PAD_I2C4_SCL__I2C4_SCL             0x4000007f
+               >;
+       };
+
+       pinctrl_j2: j2grp {
+               fsl,pins = <
+                       MX7D_PAD_SAI1_TX_DATA__GPIO6_IO15       0x7d
+                       MX7D_PAD_EPDC_BDR0__GPIO2_IO28          0x7d
+                       MX7D_PAD_SAI1_RX_DATA__GPIO6_IO12       0x7d
+                       MX7D_PAD_EPDC_BDR1__GPIO2_IO29          0x7d
+                       MX7D_PAD_SD1_WP__GPIO5_IO1              0x7d
+                       MX7D_PAD_EPDC_SDSHR__GPIO2_IO19         0x7d
+                       MX7D_PAD_SD1_RESET_B__GPIO5_IO2         0x7d
+                       MX7D_PAD_SD2_RESET_B__GPIO5_IO11        0x7d
+                       MX7D_PAD_EPDC_DATA07__GPIO2_IO7         0x7d
+                       MX7D_PAD_EPDC_DATA08__GPIO2_IO8         0x7d
+                       MX7D_PAD_EPDC_DATA09__GPIO2_IO9         0x7d
+                       MX7D_PAD_EPDC_DATA10__GPIO2_IO10        0x7d
+                       MX7D_PAD_EPDC_DATA11__GPIO2_IO11        0x7d
+                       MX7D_PAD_EPDC_DATA12__GPIO2_IO12        0x7d
+                       MX7D_PAD_SAI1_TX_SYNC__GPIO6_IO14       0x7d
+                       MX7D_PAD_EPDC_DATA13__GPIO2_IO13        0x7d
+                       MX7D_PAD_SAI1_TX_BCLK__GPIO6_IO13       0x7d
+                       MX7D_PAD_SD2_CD_B__GPIO5_IO9            0x7d
+                       MX7D_PAD_EPDC_GDCLK__GPIO2_IO24         0x7d
+                       MX7D_PAD_SAI2_RX_DATA__GPIO6_IO21       0x7d
+                       MX7D_PAD_EPDC_GDOE__GPIO2_IO25          0x7d
+                       MX7D_PAD_EPDC_GDRL__GPIO2_IO26          0x7d
+                       MX7D_PAD_SAI2_TX_DATA__GPIO6_IO22       0x7d
+                       MX7D_PAD_EPDC_SDCE0__GPIO2_IO20         0x7d
+                       MX7D_PAD_SAI2_TX_BCLK__GPIO6_IO20       0x7d
+                       MX7D_PAD_EPDC_SDCE1__GPIO2_IO21         0x7d
+                       MX7D_PAD_SAI2_TX_SYNC__GPIO6_IO19       0x7d
+                       MX7D_PAD_EPDC_SDCE2__GPIO2_IO22         0x7d
+                       MX7D_PAD_EPDC_SDCE3__GPIO2_IO23         0x7d
+                       MX7D_PAD_EPDC_GDSP__GPIO2_IO27          0x7d
+                       MX7D_PAD_EPDC_SDCLK__GPIO2_IO16         0x7d
+                       MX7D_PAD_EPDC_SDLE__GPIO2_IO17          0x7d
+                       MX7D_PAD_EPDC_SDOE__GPIO2_IO18          0x7d
+                       MX7D_PAD_EPDC_PWR_COM__GPIO2_IO30       0x7d
+                       MX7D_PAD_EPDC_PWR_STAT__GPIO2_IO31      0x7d
+               >;
+       };
+
+       pinctrl_lcdif_dat: lcdifdatgrp {
+               fsl,pins = <
+                       MX7D_PAD_LCD_DATA00__LCD_DATA0          0x79
+                       MX7D_PAD_LCD_DATA01__LCD_DATA1          0x79
+                       MX7D_PAD_LCD_DATA02__LCD_DATA2          0x79
+                       MX7D_PAD_LCD_DATA03__LCD_DATA3          0x79
+                       MX7D_PAD_LCD_DATA04__LCD_DATA4          0x79
+                       MX7D_PAD_LCD_DATA05__LCD_DATA5          0x79
+                       MX7D_PAD_LCD_DATA06__LCD_DATA6          0x79
+                       MX7D_PAD_LCD_DATA07__LCD_DATA7          0x79
+                       MX7D_PAD_LCD_DATA08__LCD_DATA8          0x79
+                       MX7D_PAD_LCD_DATA09__LCD_DATA9          0x79
+                       MX7D_PAD_LCD_DATA10__LCD_DATA10         0x79
+                       MX7D_PAD_LCD_DATA11__LCD_DATA11         0x79
+                       MX7D_PAD_LCD_DATA12__LCD_DATA12         0x79
+                       MX7D_PAD_LCD_DATA13__LCD_DATA13         0x79
+                       MX7D_PAD_LCD_DATA14__LCD_DATA14         0x79
+                       MX7D_PAD_LCD_DATA15__LCD_DATA15         0x79
+                       MX7D_PAD_LCD_DATA16__LCD_DATA16         0x79
+                       MX7D_PAD_LCD_DATA17__LCD_DATA17         0x79
+                       MX7D_PAD_LCD_DATA18__LCD_DATA18         0x79
+                       MX7D_PAD_LCD_DATA19__LCD_DATA19         0x79
+                       MX7D_PAD_LCD_DATA20__LCD_DATA20         0x79
+                       MX7D_PAD_LCD_DATA21__LCD_DATA21         0x79
+                       MX7D_PAD_LCD_DATA22__LCD_DATA22         0x79
+                       MX7D_PAD_LCD_DATA23__LCD_DATA23         0x79
+               >;
+       };
+
+       pinctrl_lcdif_ctrl: lcdifctrlgrp {
+               fsl,pins = <
+                       MX7D_PAD_LCD_CLK__LCD_CLK               0x79
+                       MX7D_PAD_LCD_ENABLE__LCD_ENABLE         0x79
+                       MX7D_PAD_LCD_VSYNC__LCD_VSYNC           0x79
+                       MX7D_PAD_LCD_HSYNC__LCD_HSYNC           0x79
+               >;
+       };
+
+       pinctrl_pwm2: pwm2grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO09__PWM2_OUT           0x7d
+               >;
+       };
+
+       pinctrl_uart1: uart1grp {
+               fsl,pins = <
+                       MX7D_PAD_UART1_TX_DATA__UART1_DCE_TX    0x79
+                       MX7D_PAD_UART1_RX_DATA__UART1_DCE_RX    0x79
+               >;
+       };
+
+       pinctrl_uart2: uart2grp {
+               fsl,pins = <
+                       MX7D_PAD_UART2_TX_DATA__UART2_DCE_TX    0x79
+                       MX7D_PAD_UART2_RX_DATA__UART2_DCE_RX    0x79
+               >;
+       };
+
+       pinctrl_uart3: uart3grp {
+               fsl,pins = <
+                       MX7D_PAD_UART3_TX_DATA__UART3_DCE_TX    0x79
+                       MX7D_PAD_UART3_RX_DATA__UART3_DCE_RX    0x79
+                       MX7D_PAD_EPDC_DATA04__GPIO2_IO4         0x7d
+               >;
+       };
+
+       pinctrl_uart6: uart6grp {
+               fsl,pins = <
+                       MX7D_PAD_ECSPI1_MOSI__UART6_DCE_TX      0x79
+                       MX7D_PAD_ECSPI1_SCLK__UART6_DCE_RX      0x79
+                       MX7D_PAD_ECSPI1_SS0__UART6_DCE_CTS      0x79
+                       MX7D_PAD_ECSPI1_MISO__UART6_DCE_RTS     0x79
+               >;
+       };
+
+       pinctrl_usbotg2: usbotg2grp {
+               fsl,pins = <
+                       MX7D_PAD_UART3_RTS_B__USB_OTG2_OC       0x7d
+                       MX7D_PAD_UART3_CTS_B__GPIO4_IO7         0x14
+               >;
+       };
+
+       pinctrl_usdhc1: usdhc1grp {
+               fsl,pins = <
+                       MX7D_PAD_SD1_CMD__SD1_CMD               0x59
+                       MX7D_PAD_SD1_CLK__SD1_CLK               0x19
+                       MX7D_PAD_SD1_DATA0__SD1_DATA0           0x59
+                       MX7D_PAD_SD1_DATA1__SD1_DATA1           0x59
+                       MX7D_PAD_SD1_DATA2__SD1_DATA2           0x59
+                       MX7D_PAD_SD1_DATA3__SD1_DATA3           0x59
+                       MX7D_PAD_GPIO1_IO08__SD1_VSELECT        0x75
+                       MX7D_PAD_SD1_CD_B__GPIO5_IO0            0x75
+               >;
+       };
+
+       pinctrl_usdhc2: usdhc2grp {
+               fsl,pins = <
+                       MX7D_PAD_SD2_CMD__SD2_CMD               0x59
+                       MX7D_PAD_SD2_CLK__SD2_CLK               0x19
+                       MX7D_PAD_SD2_DATA0__SD2_DATA0           0x59
+                       MX7D_PAD_SD2_DATA1__SD2_DATA1           0x59
+                       MX7D_PAD_SD2_DATA2__SD2_DATA2           0x59
+                       MX7D_PAD_SD2_DATA3__SD2_DATA3           0x59
+                       MX7D_PAD_ECSPI2_SCLK__GPIO4_IO20        0x59
+                       MX7D_PAD_ECSPI2_MOSI__GPIO4_IO21        0x59
+               >;
+       };
+
+       pinctrl_usdhc3: usdhc3grp {
+               fsl,pins = <
+                       MX7D_PAD_SD3_CMD__SD3_CMD               0x59
+                       MX7D_PAD_SD3_CLK__SD3_CLK               0x19
+                       MX7D_PAD_SD3_DATA0__SD3_DATA0           0x59
+                       MX7D_PAD_SD3_DATA1__SD3_DATA1           0x59
+                       MX7D_PAD_SD3_DATA2__SD3_DATA2           0x59
+                       MX7D_PAD_SD3_DATA3__SD3_DATA3           0x59
+                       MX7D_PAD_SD3_DATA4__SD3_DATA4           0x59
+                       MX7D_PAD_SD3_DATA5__SD3_DATA5           0x59
+                       MX7D_PAD_SD3_DATA6__SD3_DATA6           0x59
+                       MX7D_PAD_SD3_DATA7__SD3_DATA7           0x59
+               >;
+       };
+};
+
+&iomuxc_lpsr {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_hog_2>;
+
+       pinctrl_hog_2: hoggrp-2 {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO02__GPIO1_IO2          0x7d
+                       MX7D_PAD_GPIO1_IO03__CCM_CLKO2          0x7d
+               >;
+       };
+
+       pinctrl_backlight_j9: backlightj9grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO07__GPIO1_IO7          0x7d
+               >;
+       };
+
+       pinctrl_pwm1: pwm1grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO01__PWM1_OUT           0x7d
+               >;
+       };
+
+       pinctrl_usbotg1: usbotg1grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO04__USB_OTG1_OC        0x7d
+                       MX7D_PAD_GPIO1_IO05__GPIO1_IO5          0x14
+               >;
+       };
+
+       pinctrl_wdog1: wdog1grp {
+               fsl,pins = <
+                       MX7D_PAD_GPIO1_IO00__WDOD1_WDOG_B       0x75
+               >;
+       };
+};
index b5a50e0e7ff1980523e6567934135b7aad7a73d9..6b3faa298417dcf4e084279f204e6ae97f0019bc 100644 (file)
                                #pwm-cells = <2>;
                                status = "disabled";
                        };
+
+                       lcdif: lcdif@30730000 {
+                               compatible = "fsl,imx7d-lcdif", "fsl,imx28-lcdif";
+                               reg = <0x30730000 0x10000>;
+                               interrupts = <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>;
+                               clocks = <&clks IMX7D_LCDIF_PIXEL_ROOT_CLK>,
+                                       <&clks IMX7D_CLK_DUMMY>,
+                                       <&clks IMX7D_CLK_DUMMY>;
+                               clock-names = "pix", "axi", "disp_axi";
+                               status = "disabled";
+                       };
                };
 
                aips3: aips-bus@30800000 {
                                status = "disabled";
                        };
 
+                       flexcan1: can@30a00000 {
+                               compatible = "fsl,imx7d-flexcan", "fsl,imx6q-flexcan";
+                               reg = <0x30a00000 0x10000>;
+                               interrupts = <GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
+                               clocks = <&clks IMX7D_CLK_DUMMY>,
+                                       <&clks IMX7D_CAN1_ROOT_CLK>;
+                               clock-names = "ipg", "per";
+                               status = "disabled";
+                       };
+
+                       flexcan2: can@30a10000 {
+                               compatible = "fsl,imx7d-flexcan", "fsl,imx6q-flexcan";
+                               reg = <0x30a10000 0x10000>;
+                               interrupts = <GIC_SPI 111 IRQ_TYPE_LEVEL_HIGH>;
+                               clocks = <&clks IMX7D_CLK_DUMMY>,
+                                       <&clks IMX7D_CAN2_ROOT_CLK>;
+                               clock-names = "ipg", "per";
+                               status = "disabled";
+                       };
+
                        i2c1: i2c@30a20000 {
                                #address-cells = <1>;
                                #size-cells = <0>;
index 0c82097daffcdd8bd3ac5c0840c7cae0a039d277..b9bbcce69dfbd5b9efda7ae20a83752cf459c925 100644 (file)
@@ -14,6 +14,7 @@
 #include <dt-bindings/clock/r8a7779-clock.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/power/r8a7779-sysc.h>
 
 / {
        compatible = "renesas,r8a7779";
                        compatible = "arm,cortex-a9";
                        reg = <1>;
                        clock-frequency = <1000000000>;
+                       power-domains = <&sysc R8A7779_PD_ARM1>;
                };
                cpu@2 {
                        device_type = "cpu";
                        compatible = "arm,cortex-a9";
                        reg = <2>;
                        clock-frequency = <1000000000>;
+                       power-domains = <&sysc R8A7779_PD_ARM2>;
                };
                cpu@3 {
                        device_type = "cpu";
                        compatible = "arm,cortex-a9";
                        reg = <3>;
                        clock-frequency = <1000000000>;
+                       power-domains = <&sysc R8A7779_PD_ARM3>;
                };
        };
 
                reg = <0xffc70000 0x1000>;
                interrupts = <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_I2C0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffc71000 0x1000>;
                interrupts = <GIC_SPI 82 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_I2C1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffc72000 0x1000>;
                interrupts = <GIC_SPI 80 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_I2C2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffc73000 0x1000>;
                interrupts = <GIC_SPI 81 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_I2C3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF0>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF1>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF2>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF3>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF4>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp0_clks R8A7779_CLK_SCIF5>,
                         <&cpg_clocks R8A7779_CLK_S1>, <&scif_clk>;
                clock-names = "fck", "brg_int", "scif_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                             <GIC_SPI 34 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_TMU0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
 
                #renesas,channels = <3>;
 
                             <GIC_SPI 38 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_TMU1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
 
                #renesas,channels = <3>;
 
                             <GIC_SPI 42 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp0_clks R8A7779_CLK_TMU2>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
 
                #renesas,channels = <3>;
 
                reg = <0xfc600000 0x2000>;
                interrupts = <GIC_SPI 100 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7779_CLK_SATA>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
        };
 
        sdhi0: sd@ffe4c000 {
                reg = <0xffe4c000 0x100>;
                interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7779_CLK_SDHI0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffe4d000 0x100>;
                interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7779_CLK_SDHI1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffe4e000 0x100>;
                interrupts = <GIC_SPI 107 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7779_CLK_SDHI2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0xffe4f000 0x100>;
                interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7779_CLK_SDHI3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp0_clks R8A7779_CLK_HSPI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp0_clks R8A7779_CLK_HSPI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp0_clks R8A7779_CLK_HSPI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xfff80000 0 0x40000>;
                interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7779_CLK_DU>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7779_PD_ALWAYS_ON>;
                status = "disabled";
 
                ports {
                                "mmc1", "mmc0";
                };
        };
+
+       sysc: system-controller@ffd85000 {
+               compatible = "renesas,r8a7779-sysc";
+               reg = <0xffd85000 0x0200>;
+               #power-domain-cells = <1>;
+       };
 };
index 935064fe7b13497bcc2a7e5f59e3831d02d2dfcd..83cf23cd26bb51e6632cffb9e87a12cdc2ea442f 100644 (file)
@@ -13,6 +13,7 @@
 #include <dt-bindings/clock/r8a7790-clock.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/power/r8a7790-sysc.h>
 
 / {
        compatible = "renesas,r8a7790";
@@ -52,6 +53,7 @@
                        voltage-tolerance = <1>; /* 1% */
                        clocks = <&cpg_clocks R8A7790_CLK_Z>;
                        clock-latency = <300000>; /* 300 us */
+                       power-domains = <&sysc R8A7790_PD_CA15_CPU0>;
                        next-level-cache = <&L2_CA15>;
 
                        /* kHz - uV - OPPs unknown yet */
@@ -68,6 +70,7 @@
                        compatible = "arm,cortex-a15";
                        reg = <1>;
                        clock-frequency = <1300000000>;
+                       power-domains = <&sysc R8A7790_PD_CA15_CPU1>;
                        next-level-cache = <&L2_CA15>;
                };
 
@@ -76,6 +79,7 @@
                        compatible = "arm,cortex-a15";
                        reg = <2>;
                        clock-frequency = <1300000000>;
+                       power-domains = <&sysc R8A7790_PD_CA15_CPU2>;
                        next-level-cache = <&L2_CA15>;
                };
 
@@ -84,6 +88,7 @@
                        compatible = "arm,cortex-a15";
                        reg = <3>;
                        clock-frequency = <1300000000>;
+                       power-domains = <&sysc R8A7790_PD_CA15_CPU3>;
                        next-level-cache = <&L2_CA15>;
                };
 
@@ -92,6 +97,7 @@
                        compatible = "arm,cortex-a7";
                        reg = <0x100>;
                        clock-frequency = <780000000>;
+                       power-domains = <&sysc R8A7790_PD_CA7_CPU0>;
                        next-level-cache = <&L2_CA7>;
                };
 
                        compatible = "arm,cortex-a7";
                        reg = <0x101>;
                        clock-frequency = <780000000>;
+                       power-domains = <&sysc R8A7790_PD_CA7_CPU1>;
                        next-level-cache = <&L2_CA7>;
                };
 
                        compatible = "arm,cortex-a7";
                        reg = <0x102>;
                        clock-frequency = <780000000>;
+                       power-domains = <&sysc R8A7790_PD_CA7_CPU2>;
                        next-level-cache = <&L2_CA7>;
                };
 
                        compatible = "arm,cortex-a7";
                        reg = <0x103>;
                        clock-frequency = <780000000>;
+                       power-domains = <&sysc R8A7790_PD_CA7_CPU3>;
                        next-level-cache = <&L2_CA7>;
                };
        };
 
        L2_CA15: cache-controller@0 {
                compatible = "cache";
+               power-domains = <&sysc R8A7790_PD_CA15_SCU>;
                cache-unified;
                cache-level = <2>;
        };
 
        L2_CA7: cache-controller@1 {
                compatible = "cache";
+               power-domains = <&sysc R8A7790_PD_CA7_SCU>;
                cache-unified;
                cache-level = <2>;
        };
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        gpio1: gpio@e6051000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        gpio2: gpio@e6052000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        gpio3: gpio@e6053000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        gpio4: gpio@e6054000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        gpio5: gpio@e6055000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7790_CLK_GPIO5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        thermal: thermal@e61f0000 {
                reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>;
                interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp5_clks R8A7790_CLK_THERMAL>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #thermal-sensor-cells = <0>;
        };
 
                             <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_CMT0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0x60>;
 
                             <GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7790_CLK_CMT1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0xff>;
 
                             <GIC_SPI 2 IRQ_TYPE_LEVEL_HIGH>,
                             <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp4_clks R8A7790_CLK_IRQC>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        dmac0: dma-controller@e6700000 {
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7790_CLK_SYS_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7790_CLK_SYS_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7790_CLK_AUDIO_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7790_CLK_AUDIO_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                              GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "ch0", "ch1";
                clocks = <&mstp3_clks R8A7790_CLK_USBDMAC0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <2>;
        };
                              GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "ch0", "ch1";
                clocks = <&mstp3_clks R8A7790_CLK_USBDMAC1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <2>;
        };
                reg = <0 0xe6508000 0 0x40>;
                interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7790_CLK_I2C0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <110>;
                status = "disabled";
        };
                reg = <0 0xe6518000 0 0x40>;
                interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7790_CLK_I2C1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6530000 0 0x40>;
                interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7790_CLK_I2C2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6540000 0 0x40>;
                interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7790_CLK_I2C3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <110>;
                status = "disabled";
        };
                clocks = <&mstp3_clks R8A7790_CLK_IIC0>;
                dmas = <&dmac0 0x61>, <&dmac0 0x62>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7790_CLK_IIC1>;
                dmas = <&dmac0 0x65>, <&dmac0 0x66>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7790_CLK_IIC2>;
                dmas = <&dmac0 0x69>, <&dmac0 0x6a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7790_CLK_IICDVFS>;
                dmas = <&dmac0 0x77>, <&dmac0 0x78>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7790_CLK_MMCIF0>;
                dmas = <&dmac0 0xd1>, <&dmac0 0xd2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                reg-io-width = <4>;
                status = "disabled";
                max-frequency = <97500000>;
                clocks = <&mstp3_clks R8A7790_CLK_MMCIF1>;
                dmas = <&dmac0 0xe1>, <&dmac0 0xe2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                reg-io-width = <4>;
                status = "disabled";
                max-frequency = <97500000>;
                dmas = <&dmac1 0xcd>, <&dmac1 0xce>;
                dma-names = "tx", "rx";
                max-frequency = <195000000>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                dmas = <&dmac1 0xc9>, <&dmac1 0xca>;
                dma-names = "tx", "rx";
                max-frequency = <195000000>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                dmas = <&dmac1 0xc1>, <&dmac1 0xc2>;
                dma-names = "tx", "rx";
                max-frequency = <97500000>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                dmas = <&dmac1 0xd3>, <&dmac1 0xd4>;
                dma-names = "tx", "rx";
                max-frequency = <97500000>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x21>, <&dmac0 0x22>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x25>, <&dmac0 0x26>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x27>, <&dmac0 0x28>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x3d>, <&dmac0 0x3e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x19>, <&dmac0 0x1a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1d>, <&dmac0 0x1e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x29>, <&dmac0 0x2a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2d>, <&dmac0 0x2e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2b>, <&dmac0 0x2c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x39>, <&dmac0 0x3a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x4d>, <&dmac0 0x4e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee700000 0 0x400>;
                interrupts = <GIC_SPI 162 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_ETHER>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                phy-mode = "rmii";
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0 0xe6800000 0 0x800>, <0 0xee0e8000 0 0x4000>;
                interrupts = <GIC_SPI 163 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_ETHERAVB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                reg = <0 0xee300000 0 0x2000>;
                interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_SATA0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee500000 0 0x2000>;
                interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_SATA1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                dmas = <&usb_dmac0 0>, <&usb_dmac0 1>,
                       <&usb_dmac1 0>, <&usb_dmac1 1>;
                dma-names = "ch0", "ch1", "ch2", "ch3";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                renesas,buswait = <4>;
                phys = <&usb0 1>;
                phy-names = "usb";
                #size-cells = <0>;
                clocks = <&mstp7_clks R8A7790_CLK_HSUSB>;
                clock-names = "usbhs";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
 
                usb0: usb-channel@0 {
                reg = <0 0xe6ef0000 0 0x1000>;
                interrupts = <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_VIN0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef1000 0 0x1000>;
                interrupts = <GIC_SPI 189 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_VIN1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef2000 0 0x1000>;
                interrupts = <GIC_SPI 190 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_VIN2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef3000 0 0x1000>;
                interrupts = <GIC_SPI 191 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7790_CLK_VIN3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xfe920000 0 0x8000>;
                interrupts = <GIC_SPI 266 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_VSP1_R>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,has-sru;
                renesas,#rpf = <5>;
                reg = <0 0xfe928000 0 0x8000>;
                interrupts = <GIC_SPI 267 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_VSP1_S>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,has-lut;
                renesas,has-sru;
                reg = <0 0xfe930000 0 0x8000>;
                interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_VSP1_DU0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,has-lif;
                renesas,has-lut;
                reg = <0 0xfe938000 0 0x8000>;
                interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_VSP1_DU1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                renesas,has-lif;
                renesas,has-lut;
                clocks = <&mstp9_clks R8A7790_CLK_RCAN0>,
                         <&cpg_clocks R8A7790_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7790_CLK_RCAN1>,
                         <&cpg_clocks R8A7790_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xfe980000 0 0x10300>;
                interrupts = <GIC_SPI 272 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7790_CLK_JPU>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
        };
 
        clocks {
                };
        };
 
+       sysc: system-controller@e6180000 {
+               compatible = "renesas,r8a7790-sysc";
+               reg = <0 0xe6180000 0 0x0200>;
+               #power-domain-cells = <1>;
+       };
+
        qspi: spi@e6b10000 {
                compatible = "renesas,qspi-r8a7790", "renesas,qspi";
                reg = <0 0xe6b10000 0 0x2c>;
                clocks = <&mstp9_clks R8A7790_CLK_QSPI_MOD>;
                dmas = <&dmac0 0x17>, <&dmac0 0x18>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                num-cs = <1>;
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp0_clks R8A7790_CLK_MSIOF0>;
                dmas = <&dmac0 0x51>, <&dmac0 0x52>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp2_clks R8A7790_CLK_MSIOF1>;
                dmas = <&dmac0 0x55>, <&dmac0 0x56>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp2_clks R8A7790_CLK_MSIOF2>;
                dmas = <&dmac0 0x41>, <&dmac0 0x42>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp2_clks R8A7790_CLK_MSIOF3>;
                dmas = <&dmac0 0x45>, <&dmac0 0x46>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                reg = <0 0xee000000 0 0xc00>;
                interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7790_CLK_SSUSB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                phys = <&usb2 1>;
                phy-names = "usb";
                status = "disabled";
                      <0 0xee080000 0 0x1100>;
                interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7790_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <0 0>;
                      <0 0xee0a0000 0 0x1100>;
                interrupts = <GIC_SPI 112 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7790_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <1 1>;
                compatible = "renesas,pci-r8a7790", "renesas,pci-rcar-gen2";
                device_type = "pci";
                clocks = <&mstp7_clks R8A7790_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                reg = <0 0xee0d0000 0 0xc00>,
                      <0 0xee0c0000 0 0x1100>;
                interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-map = <0 0 0 0 &gic GIC_SPI 116 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7790_CLK_PCIEC>, <&pcie_bus_clk>;
                clock-names = "pcie", "pcie_bus";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                                "mix.0", "mix.1",
                                "dvc.0", "dvc.1",
                                "clk_a", "clk_b", "clk_c", "clk_i";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7790_PD_ALWAYS_ON>;
 
                status = "disabled";
 
index 565c270e549d2bb603d5f87384cdcb417161ab30..db67e342c58566fac210e1ccaa849259ec35090a 100644 (file)
@@ -13,6 +13,7 @@
 #include <dt-bindings/clock/r8a7791-clock.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/power/r8a7791-sysc.h>
 
 / {
        compatible = "renesas,r8a7791";
@@ -51,6 +52,7 @@
                        voltage-tolerance = <1>; /* 1% */
                        clocks = <&cpg_clocks R8A7791_CLK_Z>;
                        clock-latency = <300000>; /* 300 us */
+                       power-domains = <&sysc R8A7791_PD_CA15_CPU0>;
                        next-level-cache = <&L2_CA15>;
 
                        /* kHz - uV - OPPs unknown yet */
@@ -67,6 +69,7 @@
                        compatible = "arm,cortex-a15";
                        reg = <1>;
                        clock-frequency = <1500000000>;
+                       power-domains = <&sysc R8A7791_PD_CA15_CPU1>;
                        next-level-cache = <&L2_CA15>;
                };
        };
@@ -92,6 +95,7 @@
 
        L2_CA15: cache-controller@0 {
                compatible = "cache";
+               power-domains = <&sysc R8A7791_PD_CA15_SCU>;
                cache-unified;
                cache-level = <2>;
        };
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio1: gpio@e6051000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio2: gpio@e6052000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio3: gpio@e6053000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio4: gpio@e6054000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio5: gpio@e6055000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio6: gpio@e6055400 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO6>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        gpio7: gpio@e6055800 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7791_CLK_GPIO7>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        thermal: thermal@e61f0000 {
                reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>;
                interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp5_clks R8A7791_CLK_THERMAL>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #thermal-sensor-cells = <0>;
        };
 
                             <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7791_CLK_CMT0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0x60>;
 
                             <GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7791_CLK_CMT1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0xff>;
 
                             <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>,
                             <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp4_clks R8A7791_CLK_IRQC>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        dmac0: dma-controller@e6700000 {
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7791_CLK_SYS_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7791_CLK_SYS_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7791_CLK_AUDIO_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7791_CLK_AUDIO_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                              GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "ch0", "ch1";
                clocks = <&mstp3_clks R8A7791_CLK_USBDMAC0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <2>;
        };
                              GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
                interrupt-names = "ch0", "ch1";
                clocks = <&mstp3_clks R8A7791_CLK_USBDMAC1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <2>;
        };
                reg = <0 0xe6508000 0 0x40>;
                interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6518000 0 0x40>;
                interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6530000 0 0x40>;
                interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6540000 0 0x40>;
                interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6520000 0 0x40>;
                interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6528000 0 0x40>;
                interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7791_CLK_I2C5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <110>;
                status = "disabled";
        };
                clocks = <&mstp9_clks R8A7791_CLK_IICDVFS>;
                dmas = <&dmac0 0x77>, <&dmac0 0x78>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7791_CLK_IIC0>;
                dmas = <&dmac0 0x61>, <&dmac0 0x62>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7791_CLK_IIC1>;
                dmas = <&dmac0 0x65>, <&dmac0 0x66>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7791_CLK_MMCIF0>;
                dmas = <&dmac0 0xd1>, <&dmac0 0xd2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                reg-io-width = <4>;
                status = "disabled";
                max-frequency = <97500000>;
                clocks = <&mstp3_clks R8A7791_CLK_SDHI0>;
                dmas = <&dmac1 0xcd>, <&dmac1 0xce>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7791_CLK_SDHI1>;
                dmas = <&dmac1 0xc1>, <&dmac1 0xc2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7791_CLK_SDHI2>;
                dmas = <&dmac1 0xd3>, <&dmac1 0xd4>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x21>, <&dmac0 0x22>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x25>, <&dmac0 0x26>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x27>, <&dmac0 0x28>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1b>, <&dmac0 0x1c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1f>, <&dmac0 0x20>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x23>, <&dmac0 0x24>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x3d>, <&dmac0 0x3e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x19>, <&dmac0 0x1a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1d>, <&dmac0 0x1e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x29>, <&dmac0 0x2a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2d>, <&dmac0 0x2e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2b>, <&dmac0 0x2c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2f>, <&dmac0 0x30>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfb>, <&dmac0 0xfc>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfd>, <&dmac0 0xfe>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x39>, <&dmac0 0x3a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x4d>, <&dmac0 0x4e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x3b>, <&dmac0 0x3c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee700000 0 0x400>;
                interrupts = <GIC_SPI 162 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_ETHER>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                phy-mode = "rmii";
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0 0xe6800000 0 0x800>, <0 0xee0e8000 0 0x4000>;
                interrupts = <GIC_SPI 163 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_ETHERAVB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                reg = <0 0xee300000 0 0x2000>;
                interrupts = <GIC_SPI 105 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_SATA0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee500000 0 0x2000>;
                interrupts = <GIC_SPI 106 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_SATA1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                dmas = <&usb_dmac0 0>, <&usb_dmac0 1>,
                       <&usb_dmac1 0>, <&usb_dmac1 1>;
                dma-names = "ch0", "ch1", "ch2", "ch3";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                renesas,buswait = <4>;
                phys = <&usb0 1>;
                phy-names = "usb";
                #size-cells = <0>;
                clocks = <&mstp7_clks R8A7791_CLK_HSUSB>;
                clock-names = "usbhs";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
 
                usb0: usb-channel@0 {
                reg = <0 0xe6ef0000 0 0x1000>;
                interrupts = <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_VIN0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef1000 0 0x1000>;
                interrupts = <GIC_SPI 189 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_VIN1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef2000 0 0x1000>;
                interrupts = <GIC_SPI 190 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7791_CLK_VIN2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xfe928000 0 0x8000>;
                interrupts = <GIC_SPI 267 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7791_CLK_VSP1_S>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                renesas,has-lut;
                renesas,has-sru;
                reg = <0 0xfe930000 0 0x8000>;
                interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                renesas,has-lif;
                renesas,has-lut;
                reg = <0 0xfe938000 0 0x8000>;
                interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                renesas,has-lif;
                renesas,has-lut;
                clocks = <&mstp9_clks R8A7791_CLK_RCAN0>,
                         <&cpg_clocks R8A7791_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7791_CLK_RCAN1>,
                         <&cpg_clocks R8A7791_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xfe980000 0 0x10300>;
                interrupts = <GIC_SPI 272 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7791_CLK_JPU>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
        };
 
        clocks {
                };
        };
 
+       sysc: system-controller@e6180000 {
+               compatible = "renesas,r8a7791-sysc";
+               reg = <0 0xe6180000 0 0x0200>;
+               #power-domain-cells = <1>;
+       };
+
        qspi: spi@e6b10000 {
                compatible = "renesas,qspi-r8a7791", "renesas,qspi";
                reg = <0 0xe6b10000 0 0x2c>;
                clocks = <&mstp9_clks R8A7791_CLK_QSPI_MOD>;
                dmas = <&dmac0 0x17>, <&dmac0 0x18>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                num-cs = <1>;
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp0_clks R8A7791_CLK_MSIOF0>;
                dmas = <&dmac0 0x51>, <&dmac0 0x52>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp2_clks R8A7791_CLK_MSIOF1>;
                dmas = <&dmac0 0x55>, <&dmac0 0x56>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp2_clks R8A7791_CLK_MSIOF2>;
                dmas = <&dmac0 0x41>, <&dmac0 0x42>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                reg = <0 0xee000000 0 0xc00>;
                interrupts = <GIC_SPI 101 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7791_CLK_SSUSB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                phys = <&usb2 1>;
                phy-names = "usb";
                status = "disabled";
                      <0 0xee080000 0 0x1100>;
                interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7791_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <0 0>;
                      <0 0xee0c0000 0 0x1100>;
                interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7791_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <1 1>;
                interrupt-map = <0 0 0 0 &gic GIC_SPI 116 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7791_CLK_PCIEC>, <&pcie_bus_clk>;
                clock-names = "pcie", "pcie_bus";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                                "mix.0", "mix.1",
                                "dvc.0", "dvc.1",
                                "clk_a", "clk_b", "clk_c", "clk_i";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7791_PD_ALWAYS_ON>;
 
                status = "disabled";
 
index cf6dc2aeef201ab69b9ce589bae18bcd7184ed68..1dd6d202cd4ce54579edf79f90971dd3f91f08bd 100644 (file)
@@ -11,6 +11,7 @@
 #include <dt-bindings/clock/r8a7793-clock.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/power/r8a7793-sysc.h>
 
 / {
        compatible = "renesas,r8a7793";
@@ -43,6 +44,7 @@
                        voltage-tolerance = <1>; /* 1% */
                        clocks = <&cpg_clocks R8A7793_CLK_Z>;
                        clock-latency = <300000>; /* 300 us */
+                       power-domains = <&sysc R8A7793_PD_CA15_CPU0>;
 
                        /* kHz - uV - OPPs unknown yet */
                        operating-points = <1500000 1000000>,
@@ -76,6 +78,7 @@
 
        L2_CA15: cache-controller@0 {
                compatible = "cache";
+               power-domains = <&sysc R8A7793_PD_CA15_SCU>;
                cache-unified;
                cache-level = <2>;
        };
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio1: gpio@e6051000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio2: gpio@e6052000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio3: gpio@e6053000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio4: gpio@e6054000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio5: gpio@e6055000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio6: gpio@e6055400 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO6>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        gpio7: gpio@e6055800 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7793_CLK_GPIO7>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        thermal: thermal@e61f0000 {
                reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>;
                interrupts = <GIC_SPI 69 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp5_clks R8A7793_CLK_THERMAL>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                #thermal-sensor-cells = <0>;
        };
 
                             <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7793_CLK_CMT0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0x60>;
 
                             <GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7793_CLK_CMT1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0xff>;
 
                             <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>,
                             <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp4_clks R8A7793_CLK_IRQC>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
        };
 
        dmac0: dma-controller@e6700000 {
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7793_CLK_SYS_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7793_CLK_SYS_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7793_CLK_AUDIO_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                                "ch12";
                clocks = <&mstp5_clks R8A7793_CLK_AUDIO_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <13>;
        };
                reg = <0 0xe6508000 0 0x40>;
                interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6518000 0 0x40>;
                interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6530000 0 0x40>;
                interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6540000 0 0x40>;
                interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6520000 0 0x40>;
                interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <6>;
                status = "disabled";
        };
                reg = <0 0xe6528000 0 0x40>;
                interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7793_CLK_I2C5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                i2c-scl-internal-delay-ns = <110>;
                status = "disabled";
        };
                clocks = <&mstp9_clks R8A7793_CLK_IICDVFS>;
                dmas = <&dmac0 0x77>, <&dmac0 0x78>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7793_CLK_IIC0>;
                dmas = <&dmac0 0x61>, <&dmac0 0x62>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7793_CLK_IIC1>;
                dmas = <&dmac0 0x65>, <&dmac0 0x66>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7793_CLK_SDHI0>;
                dmas = <&dmac0 0xcd>, <&dmac0 0xce>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7793_CLK_SDHI1>;
                dmas = <&dmac0 0xc1>, <&dmac0 0xc2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp3_clks R8A7793_CLK_SDHI2>;
                dmas = <&dmac0 0xd3>, <&dmac0 0xd4>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x21>, <&dmac0 0x22>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x25>, <&dmac0 0x26>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x27>, <&dmac0 0x28>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1b>, <&dmac0 0x1c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1f>, <&dmac0 0x20>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x23>, <&dmac0 0x24>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x3d>, <&dmac0 0x3e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x19>, <&dmac0 0x1a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1d>, <&dmac0 0x1e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x29>, <&dmac0 0x2a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2d>, <&dmac0 0x2e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2b>, <&dmac0 0x2c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2f>, <&dmac0 0x30>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfb>, <&dmac0 0xfc>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfd>, <&dmac0 0xfe>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x39>, <&dmac0 0x3a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x4d>, <&dmac0 0x4e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x3b>, <&dmac0 0x3c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee700000 0 0x400>;
                interrupts = <GIC_SPI 162 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7793_CLK_ETHER>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                phy-mode = "rmii";
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp9_clks R8A7793_CLK_QSPI_MOD>;
                dmas = <&dmac0 0x17>, <&dmac0 0x18>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                num-cs = <1>;
                #address-cells = <1>;
                #size-cells = <0>;
                clocks = <&mstp9_clks R8A7793_CLK_RCAN0>,
                         <&cpg_clocks R8A7793_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7793_CLK_RCAN1>,
                         <&cpg_clocks R8A7793_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                };
        };
 
+       sysc: system-controller@e6180000 {
+               compatible = "renesas,r8a7793-sysc";
+               reg = <0 0xe6180000 0 0x0200>;
+               #power-domain-cells = <1>;
+       };
+
        ipmmu_sy0: mmu@e6280000 {
                compatible = "renesas,ipmmu-r8a7793", "renesas,ipmmu-vmsa";
                reg = <0 0xe6280000 0 0x1000>;
                                "src.4", "src.3", "src.2", "src.1", "src.0",
                                "dvc.0", "dvc.1",
                                "clk_a", "clk_b", "clk_c", "clk_i";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7793_PD_ALWAYS_ON>;
 
                status = "disabled";
 
index e45b23f3114954fff02d6ca6baa9764b49420597..f334a3a715f27d127aa4ebbe7c6ef8281bb30b1f 100644 (file)
@@ -12,6 +12,7 @@
 #include <dt-bindings/clock/r8a7794-clock.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/interrupt-controller/irq.h>
+#include <dt-bindings/power/r8a7794-sysc.h>
 
 / {
        compatible = "renesas,r8a7794";
@@ -42,6 +43,7 @@
                        compatible = "arm,cortex-a7";
                        reg = <0>;
                        clock-frequency = <1000000000>;
+                       power-domains = <&sysc R8A7794_PD_CA7_CPU0>;
                        next-level-cache = <&L2_CA7>;
                };
 
                        compatible = "arm,cortex-a7";
                        reg = <1>;
                        clock-frequency = <1000000000>;
+                       power-domains = <&sysc R8A7794_PD_CA7_CPU1>;
                        next-level-cache = <&L2_CA7>;
                };
        };
 
        L2_CA7: cache-controller@1 {
                compatible = "cache";
+               power-domains = <&sysc R8A7794_PD_CA7_SCU>;
                cache-unified;
                cache-level = <2>;
        };
@@ -82,7 +86,7 @@
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio1: gpio@e6051000 {
@@ -95,7 +99,7 @@
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio2: gpio@e6052000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio3: gpio@e6053000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio4: gpio@e6054000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio5: gpio@e6055000 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        gpio6: gpio@e6055400 {
                #interrupt-cells = <2>;
                interrupt-controller;
                clocks = <&mstp9_clks R8A7794_CLK_GPIO6>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        cmt0: timer@ffca0000 {
                             <GIC_SPI 143 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp1_clks R8A7794_CLK_CMT0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0x60>;
 
                             <GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7794_CLK_CMT1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
 
                renesas,channels-mask = <0xff>;
 
                             <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>,
                             <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp4_clks R8A7794_CLK_IRQC>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
        };
 
        pfc: pin-controller@e6060000 {
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7794_CLK_SYS_DMAC0>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                                "ch12", "ch13", "ch14";
                clocks = <&mstp2_clks R8A7794_CLK_SYS_DMAC1>;
                clock-names = "fck";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #dma-cells = <1>;
                dma-channels = <15>;
        };
                clock-names = "fck";
                dmas = <&dmac0 0x21>, <&dmac0 0x22>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x25>, <&dmac0 0x26>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x27>, <&dmac0 0x28>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1b>, <&dmac0 0x1c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1f>, <&dmac0 0x20>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x23>, <&dmac0 0x24>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x3d>, <&dmac0 0x3e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x19>, <&dmac0 0x1a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck";
                dmas = <&dmac0 0x1d>, <&dmac0 0x1e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x29>, <&dmac0 0x2a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2d>, <&dmac0 0x2e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2b>, <&dmac0 0x2c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x2f>, <&dmac0 0x30>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfb>, <&dmac0 0xfc>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0xfd>, <&dmac0 0xfe>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x39>, <&dmac0 0x3a>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x4d>, <&dmac0 0x4e>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clock-names = "fck", "brg_int", "scif_clk";
                dmas = <&dmac0 0x3b>, <&dmac0 0x3c>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee700000 0 0x400>;
                interrupts = <GIC_SPI 162 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7794_CLK_ETHER>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                phy-mode = "rmii";
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0 0xe6800000 0 0x800>, <0 0xee0e8000 0 0x4000>;
                interrupts = <GIC_SPI 163 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7794_CLK_ETHERAVB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                reg = <0 0xe6508000 0 0x40>;
                interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                reg = <0 0xe6518000 0 0x40>;
                interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                reg = <0 0xe6530000 0 0x40>;
                interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                reg = <0 0xe6540000 0 0x40>;
                interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C3>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                reg = <0 0xe6520000 0 0x40>;
                interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C4>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                reg = <0 0xe6528000 0 0x40>;
                interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp9_clks R8A7794_CLK_I2C5>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                i2c-scl-internal-delay-ns = <6>;
                clocks = <&mstp3_clks R8A7794_CLK_IIC0>;
                dmas = <&dmac0 0x61>, <&dmac0 0x62>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp3_clks R8A7794_CLK_IIC1>;
                dmas = <&dmac0 0x65>, <&dmac0 0x66>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                #address-cells = <1>;
                #size-cells = <0>;
                status = "disabled";
                clocks = <&mstp3_clks R8A7794_CLK_MMCIF0>;
                dmas = <&dmac0 0xd1>, <&dmac0 0xd2>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                reg-io-width = <4>;
                status = "disabled";
        };
                reg = <0 0xee100000 0 0x200>;
                interrupts = <GIC_SPI 165 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7794_CLK_SDHI0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee140000 0 0x100>;
                interrupts = <GIC_SPI 167 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7794_CLK_SDHI1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xee160000 0 0x100>;
                interrupts = <GIC_SPI 168 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp3_clks R8A7794_CLK_SDHI2>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7794_CLK_QSPI_MOD>;
                dmas = <&dmac0 0x17>, <&dmac0 0x18>;
                dma-names = "tx", "rx";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                num-cs = <1>;
                #address-cells = <1>;
                #size-cells = <0>;
                reg = <0 0xe6ef0000 0 0x1000>;
                interrupts = <GIC_SPI 188 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7794_CLK_VIN0>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                reg = <0 0xe6ef1000 0 0x1000>;
                interrupts = <GIC_SPI 189 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp8_clks R8A7794_CLK_VIN1>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                      <0 0xee080000 0 0x1100>;
                interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7794_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <0 0>;
                      <0 0xee0c0000 0 0x1100>;
                interrupts = <GIC_SPI 113 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7794_CLK_EHCI>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
 
                bus-range = <1 1>;
                reg = <0 0xe6590000 0 0x100>;
                interrupts = <GIC_SPI 107 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&mstp7_clks R8A7794_CLK_HSUSB>;
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                renesas,buswait = <4>;
                phys = <&usb0 1>;
                phy-names = "usb";
                #size-cells = <0>;
                clocks = <&mstp7_clks R8A7794_CLK_HSUSB>;
                clock-names = "usbhs";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
 
                usb0: usb-channel@0 {
                clocks = <&mstp9_clks R8A7794_CLK_RCAN0>,
                         <&cpg_clocks R8A7794_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                clocks = <&mstp9_clks R8A7794_CLK_RCAN1>,
                         <&cpg_clocks R8A7794_CLK_RCAN>, <&can_clk>;
                clock-names = "clkp1", "clkp2", "can_clk";
-               power-domains = <&cpg_clocks>;
+               power-domains = <&sysc R8A7794_PD_ALWAYS_ON>;
                status = "disabled";
        };
 
                };
        };
 
+       sysc: system-controller@e6180000 {
+               compatible = "renesas,r8a7794-sysc";
+               reg = <0 0xe6180000 0 0x0200>;
+               #power-domain-cells = <1>;
+       };
+
        ipmmu_sy0: mmu@e6280000 {
                compatible = "renesas,ipmmu-r8a7794", "renesas,ipmmu-vmsa";
                reg = <0 0xe6280000 0 0x1000>;
index a99f07ad6312d62682fe0893acaaaf57f6e6bcc2..941f36263c8ff97f21a1703ac58fcf24b0599896 100644 (file)
                vddio-pex-ctl-supply = <&vdd_3v3_lp0>;
                avdd-pll-erefe-supply = <&avdd_1v05_run>;
 
+               /* Mini PCIe */
                pci@1,0 {
+                       phys = <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-4}>;
+                       phy-names = "pcie-0";
                        status = "okay";
                };
 
+               /* Gigabit Ethernet */
                pci@2,0 {
+                       phys = <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-2}>;
+                       phy-names = "pcie-0";
                        status = "okay";
                };
        };
        sata@0,70020000 {
                status = "okay";
 
+               phys = <&{/padctl@0,7009f000/pads/sata/lanes/sata-0}>;
+               phy-names = "sata-0";
+
                hvdd-supply = <&vdd_3v3_lp0>;
                vddio-supply = <&vdd_1v05_run>;
                avdd-supply = <&vdd_1v05_run>;
                status = "okay";
        };
 
+       usb@0,70090000 {
+               phys = <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-0}>, /* Micro A/B */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-1}>, /* Mini PCIe */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-2}>, /* USB3 */
+                      <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-0}>; /* USB3 */
+               phy-names = "usb2-0", "usb2-1", "usb2-2", "usb3-0";
+
+               avddio-pex-supply = <&vdd_1v05_run>;
+               dvddio-pex-supply = <&vdd_1v05_run>;
+               avdd-usb-supply = <&vdd_3v3_lp0>;
+               avdd-pll-utmip-supply = <&vddio_1v8>;
+               avdd-pll-erefe-supply = <&avdd_1v05_run>;
+               avdd-usb-ss-pll-supply = <&vdd_1v05_run>;
+               hvdd-usb-ss-supply = <&vdd_3v3_lp0>;
+               hvdd-usb-ss-pll-e-supply = <&vdd_3v3_lp0>;
+
+               status = "okay";
+       };
+
        padctl@0,7009f000 {
-               pinctrl-0 = <&padctl_default>;
-               pinctrl-names = "default";
+               status = "okay";
 
-               padctl_default: pinmux {
-                       usb3 {
-                               nvidia,lanes = "pcie-0", "pcie-1";
-                               nvidia,function = "usb3";
-                               nvidia,iddq = <0>;
+               pads {
+                       usb2 {
+                               status = "okay";
+
+                               lanes {
+                                       usb2-0 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-1 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-2 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+                               };
                        };
 
                        pcie {
-                               nvidia,lanes = "pcie-2", "pcie-3",
-                                              "pcie-4";
-                               nvidia,function = "pcie";
-                               nvidia,iddq = <0>;
+                               status = "okay";
+
+                               lanes {
+                                       pcie-0 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+
+                                       pcie-2 {
+                                               nvidia,function = "pcie";
+                                               status = "okay";
+                                       };
+
+                                       pcie-4 {
+                                               nvidia,function = "pcie";
+                                               status = "okay";
+                                       };
+                               };
                        };
 
                        sata {
-                               nvidia,lanes = "sata-0";
-                               nvidia,function = "sata";
-                               nvidia,iddq = <0>;
+                               status = "okay";
+
+                               lanes {
+                                       sata-0 {
+                                               nvidia,function = "sata";
+                                               status = "okay";
+                                       };
+                               };
+                       };
+               };
+
+               ports {
+                       /* Micro A/B */
+                       usb2-0 {
+                               status = "okay";
+                               mode = "otg";
+                       };
+
+                       /* Mini PCIe */
+                       usb2-1 {
+                               status = "okay";
+                               mode = "host";
+                       };
+
+                       /* USB3 */
+                       usb2-2 {
+                               status = "okay";
+                               mode = "host";
+
+                               vbus-supply = <&vdd_usb3_vbus>;
+                       };
+
+                       usb3-0 {
+                               nvidia,usb2-companion = <2>;
+                               status = "okay";
                        };
                };
        };
index 5f1fc1410bd0dc4461caff4f7ff976cc81f8e22a..0710a600cc69306ab1dc4619f0b8237851eba343 100644 (file)
                                        regulator-always-on;
                                };
 
-                               ldo0 {
+                               avdd_1v05_run: ldo0 {
                                        regulator-name = "+1.05V_RUN_AVDD";
                                        regulator-min-microvolt = <1050000>;
                                        regulator-max-microvolt = <1050000>;
                status = "okay";
        };
 
+       usb@0,70090000 {
+               phys = <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-0}>, /* 1st USB A */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-1}>, /* Internal USB */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-2}>, /* 2nd USB A */
+                      <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-0}>, /* 1st USB A */
+                      <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-1}>; /* 2nd USB A */
+               phy-names = "usb2-0", "usb2-1", "usb2-2", "usb3-0", "usb3-1";
+
+               avddio-pex-supply = <&vdd_1v05_run>;
+               dvddio-pex-supply = <&vdd_1v05_run>;
+               avdd-usb-supply = <&vdd_3v3_lp0>;
+               avdd-pll-utmip-supply = <&vddio_1v8>;
+               avdd-pll-erefe-supply = <&avdd_1v05_run>;
+               avdd-usb-ss-pll-supply = <&vdd_1v05_run>;
+               hvdd-usb-ss-supply = <&vdd_3v3_lp0>;
+               hvdd-usb-ss-pll-e-supply = <&vdd_3v3_lp0>;
+
+               status = "okay";
+       };
+
+       padctl@0,7009f000 {
+               status = "okay";
+
+               pads {
+                       usb2 {
+                               status = "okay";
+
+                               lanes {
+                                       usb2-0 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-1 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-2 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+                               };
+                       };
+
+                       pcie {
+                               status = "okay";
+
+                               lanes {
+                                       pcie-0 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+
+                                       pcie-1 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+                               };
+                       };
+               };
+
+               ports {
+                       usb2-0 {
+                               vbus-supply = <&vdd_usb1_vbus>;
+                               status = "okay";
+                               mode = "otg";
+                       };
+
+                       usb2-1 {
+                               vbus-supply = <&vdd_run_cam>;
+                               status = "okay";
+                               mode = "host";
+                       };
+
+                       usb2-2 {
+                               vbus-supply = <&vdd_usb3_vbus>;
+                               status = "okay";
+                               mode = "host";
+                       };
+
+                       usb3-0 {
+                               nvidia,usb2-companion = <0>;
+                               status = "okay";
+                       };
+
+                       usb3-1 {
+                               nvidia,usb2-companion = <1>;
+                               status = "okay";
+                       };
+               };
+       };
+
        sdhci0_pwrseq: sdhci0_pwrseq {
                compatible = "mmc-pwrseq-simple";
 
                };
        };
 
-       usb@0,7d000000 { /* Rear external USB port. */
-               status = "okay";
-       };
-
-       usb-phy@0,7d000000 {
-               status = "okay";
-               vbus-supply = <&vdd_usb1_vbus>;
-       };
-
-       usb@0,7d004000 { /* Internal webcam. */
-               status = "okay";
-       };
-
-       usb-phy@0,7d004000 {
-               status = "okay";
-               vbus-supply = <&vdd_run_cam>;
-       };
-
-       usb@0,7d008000 { /* Left external USB port. */
-               status = "okay";
-       };
-
-       usb-phy@0,7d008000 {
-               status = "okay";
-               vbus-supply = <&vdd_usb3_vbus>;
-       };
-
        backlight: backlight {
                compatible = "pwm-backlight";
 
index 0318258dde3e098c788bcf4fc7cfca9b08914f21..973446d07182cd8958cddd2a7dd33e2f9f08815f 100644 (file)
                                        regulator-always-on;
                                };
 
-                               ldo0 {
+                               avdd_1v05_run: ldo0 {
                                        regulator-name = "+1.05V_RUN_AVDD";
                                        regulator-min-microvolt = <1050000>;
                                        regulator-max-microvolt = <1050000>;
                status = "okay";
        };
 
+       usb@0,70090000 {
+               phys = <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-0}>, /* 1st USB A */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-1}>, /* Internal USB */
+                      <&{/padctl@0,7009f000/pads/usb2/lanes/usb2-2}>, /* 2nd USB A */
+                      <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-0}>, /* 1st USB A */
+                      <&{/padctl@0,7009f000/pads/pcie/lanes/pcie-1}>; /* 2nd USB A */
+               phy-names = "usb2-0", "usb2-1", "usb2-2", "usb3-0", "usb3-1";
+
+               avddio-pex-supply = <&vdd_1v05_run>;
+               dvddio-pex-supply = <&vdd_1v05_run>;
+               avdd-usb-supply = <&vdd_3v3_lp0>;
+               avdd-pll-utmip-supply = <&vddio_1v8>;
+               avdd-pll-erefe-supply = <&avdd_1v05_run>;
+               avdd-usb-ss-pll-supply = <&vdd_1v05_run>;
+               hvdd-usb-ss-supply = <&vdd_3v3_lp0>;
+               hvdd-usb-ss-pll-e-supply = <&vdd_3v3_lp0>;
+
+               status = "okay";
+       };
+
+       padctl@0,7009f000 {
+               pads {
+                       usb2 {
+                               status = "okay";
+
+                               lanes {
+                                       usb2-0 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-1 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+
+                                       usb2-2 {
+                                               nvidia,function = "xusb";
+                                               status = "okay";
+                                       };
+                               };
+                       };
+
+                       pcie {
+                               status = "okay";
+
+                               lanes {
+                                       pcie-0 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+
+                                       pcie-1 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+
+                                       pcie-1 {
+                                               nvidia,function = "usb3-ss";
+                                               status = "okay";
+                                       };
+                               };
+                       };
+               };
+
+               ports {
+                       usb2-0 {
+                               status = "okay";
+                               mode = "otg";
+
+                               vbus-supply = <&vdd_usb1_vbus>;
+                       };
+
+                       usb2-1 {
+                               status = "okay";
+                               mode = "host";
+
+                               vbus-supply = <&vdd_run_cam>;
+                       };
+
+                       usb2-2 {
+                               status = "okay";
+                               mode = "host";
+
+                               vbus-supply = <&vdd_usb3_vbus>;
+                       };
+
+                       usb3-0 {
+                               nvidia,usb2-companion = <0>;
+                               status = "okay";
+                       };
+
+                       usb3-1 {
+                               nvidia,usb2-companion = <2>;
+                               status = "okay";
+                       };
+               };
+       };
+
        sdhci@0,700b0400 {
                cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_HIGH>;
                power-gpios = <&gpio TEGRA_GPIO(R, 0) GPIO_ACTIVE_HIGH>;
index e4eac1f01e645f608e16483a0e37086ad1a2df91..ea4811870de271b0cd74f0caa8173535d86d7d3d 100644 (file)
@@ -2,7 +2,6 @@
 #include <dt-bindings/gpio/tegra-gpio.h>
 #include <dt-bindings/memory/tegra124-mc.h>
 #include <dt-bindings/pinctrl/pinctrl-tegra.h>
-#include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
 #include <dt-bindings/reset/tegra124-car.h>
 #include <dt-bindings/thermal/tegra124-soctherm.h>
@@ -51,9 +50,6 @@
                reset-names = "pex", "afi", "pcie_x";
                status = "disabled";
 
-               phys = <&padctl TEGRA_XUSB_PADCTL_PCIE>;
-               phy-names = "pcie";
-
                pci@1,0 {
                        device_type = "pci";
                        assigned-addresses = <0x82000800 0 0x01000000 0 0x1000>;
                         <&tegra_car 123>,
                         <&tegra_car 129>;
                reset-names = "sata", "sata-oob", "sata-cold";
-               phys = <&padctl TEGRA_XUSB_PADCTL_SATA>;
-               phy-names = "sata-phy";
                status = "disabled";
        };
 
                status = "disabled";
        };
 
+       usb@0,70090000 {
+               compatible = "nvidia,tegra124-xusb";
+               reg = <0x0 0x70090000 0x0 0x8000>,
+                     <0x0 0x70098000 0x0 0x1000>,
+                     <0x0 0x70099000 0x0 0x1000>;
+               reg-names = "hcd", "fpci", "ipfs";
+
+               interrupts = <GIC_SPI 39 IRQ_TYPE_LEVEL_HIGH>,
+                            <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
+
+               clocks = <&tegra_car TEGRA124_CLK_XUSB_HOST>,
+                        <&tegra_car TEGRA124_CLK_XUSB_HOST_SRC>,
+                        <&tegra_car TEGRA124_CLK_XUSB_FALCON_SRC>,
+                        <&tegra_car TEGRA124_CLK_XUSB_SS>,
+                        <&tegra_car TEGRA124_CLK_XUSB_SS_DIV2>,
+                        <&tegra_car TEGRA124_CLK_XUSB_SS_SRC>,
+                        <&tegra_car TEGRA124_CLK_XUSB_HS_SRC>,
+                        <&tegra_car TEGRA124_CLK_XUSB_FS_SRC>,
+                        <&tegra_car TEGRA124_CLK_PLL_U_480M>,
+                        <&tegra_car TEGRA124_CLK_CLK_M>,
+                        <&tegra_car TEGRA124_CLK_PLL_E>;
+               clock-names = "xusb_host", "xusb_host_src",
+                             "xusb_falcon_src", "xusb_ss",
+                             "xusb_ss_div2", "xusb_ss_src",
+                             "xusb_hs_src", "xusb_fs_src",
+                             "pll_u_480m", "clk_m", "pll_e";
+               resets = <&tegra_car 89>, <&tegra_car 156>,
+                        <&tegra_car 143>;
+               reset-names = "xusb_host", "xusb_ss", "xusb_src";
+
+               nvidia,xusb-padctl = <&padctl>;
+
+               status = "disabled";
+       };
+
        padctl: padctl@0,7009f000 {
                compatible = "nvidia,tegra124-xusb-padctl";
                reg = <0x0 0x7009f000 0x0 0x1000>;
                resets = <&tegra_car 142>;
                reset-names = "padctl";
 
-               #phy-cells = <1>;
+               pads {
+                       usb2 {
+                               status = "disabled";
+
+                               lanes {
+                                       usb2-0 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       usb2-1 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       usb2-2 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+                               };
+                       };
+
+                       ulpi {
+                               status = "disabled";
+
+                               lanes {
+                                       ulpi-0 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+                               };
+                       };
+
+                       hsic {
+                               status = "disabled";
+
+                               lanes {
+                                       hsic-0 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       hsic-1 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+                               };
+                       };
+
+                       pcie {
+                               status = "disabled";
+
+                               lanes {
+                                       pcie-0 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       pcie-1 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       pcie-2 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       pcie-3 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+
+                                       pcie-4 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+                               };
+                       };
+
+                       sata {
+                               status = "disabled";
+
+                               lanes {
+                                       sata-0 {
+                                               status = "disabled";
+                                               #phy-cells = <0>;
+                                       };
+                               };
+                       };
+               };
+
+               ports {
+                       usb2-0 {
+                               status = "disabled";
+                       };
+
+                       usb2-1 {
+                               status = "disabled";
+                       };
+
+                       usb2-2 {
+                               status = "disabled";
+                       };
+
+                       ulpi-0 {
+                               status = "disabled";
+                       };
+
+                       hsic-0 {
+                               status = "disabled";
+                       };
+
+                       hsic-1 {
+                               status = "disabled";
+                       };
+
+                       usb3-0 {
+                               status = "disabled";
+                       };
+
+                       usb3-1 {
+                               status = "disabled";
+                       };
+               };
        };
 
        sdhci@0,700b0000 {
index 4d8b7f69353551b1c065d4a27d5609bf6266fff3..a8a8e434fb2717560bf80959794560015c5cc3fb 100644 (file)
                clock-frequency = <16000000>;
        };
 
+       panel: panel {
+               compatible = "edt,et057090dhu";
+               backlight = <&bl>;
+       };
+
        reg_3v3: regulator-3v3 {
                compatible = "regulator-fixed";
                regulator-name = "3.3V";
        status  = "okay";
 };
 
+&dcu0 {
+       pinctrl-names = "default";
+       pinctrl-0 = <&pinctrl_dcu0_1>;
+       fsl,panel = <&panel>;
+       status = "okay";
+};
+
 &dspi1 {
        status = "okay";
 
        vin-supply = <&reg_3v3>;
 };
 
+&tcon0 {
+       status = "okay";
+};
+
 &uart0 {
        status = "okay";
 };
index 226a86ffd3c9c87da92cc6428237183bd393c635..b7417094dc11c32578856090b2bfc22f4df6ddb8 100644 (file)
                        >;
                };
 
+               pinctrl_dcu0_1: dcu0grp_1 {
+                       fsl,pins = <
+                               VF610_PAD_PTE0__DCU0_HSYNC      0x1902
+                               VF610_PAD_PTE1__DCU0_VSYNC      0x1902
+                               VF610_PAD_PTE2__DCU0_PCLK       0x1902
+                               VF610_PAD_PTE4__DCU0_DE         0x1902
+                               VF610_PAD_PTE5__DCU0_R0         0x1902
+                               VF610_PAD_PTE6__DCU0_R1         0x1902
+                               VF610_PAD_PTE7__DCU0_R2         0x1902
+                               VF610_PAD_PTE8__DCU0_R3         0x1902
+                               VF610_PAD_PTE9__DCU0_R4         0x1902
+                               VF610_PAD_PTE10__DCU0_R5        0x1902
+                               VF610_PAD_PTE11__DCU0_R6        0x1902
+                               VF610_PAD_PTE12__DCU0_R7        0x1902
+                               VF610_PAD_PTE13__DCU0_G0        0x1902
+                               VF610_PAD_PTE14__DCU0_G1        0x1902
+                               VF610_PAD_PTE15__DCU0_G2        0x1902
+                               VF610_PAD_PTE16__DCU0_G3        0x1902
+                               VF610_PAD_PTE17__DCU0_G4        0x1902
+                               VF610_PAD_PTE18__DCU0_G5        0x1902
+                               VF610_PAD_PTE19__DCU0_G6        0x1902
+                               VF610_PAD_PTE20__DCU0_G7        0x1902
+                               VF610_PAD_PTE21__DCU0_B0        0x1902
+                               VF610_PAD_PTE22__DCU0_B1        0x1902
+                               VF610_PAD_PTE23__DCU0_B2        0x1902
+                               VF610_PAD_PTE24__DCU0_B3        0x1902
+                               VF610_PAD_PTE25__DCU0_B4        0x1902
+                               VF610_PAD_PTE26__DCU0_B5        0x1902
+                               VF610_PAD_PTE27__DCU0_B6        0x1902
+                               VF610_PAD_PTE28__DCU0_B7        0x1902
+                       >;
+               };
+
                pinctrl_dspi1: dspi1grp {
                        fsl,pins = <
                                VF610_PAD_PTD5__DSPI1_CS0               0x33e2
index 04ef54d45a917059b8ec3d3578420a93aa5d9f60..2c13ec696ac541f96d781c5a94c251bad36e481a 100644 (file)
                                                        <20000000>;
                        };
 
+                       tcon0: timing-controller@4003d000 {
+                               compatible = "fsl,vf610-tcon";
+                               reg = <0x4003d000 0x1000>;
+                               clocks = <&clks VF610_CLK_TCON0>;
+                               clock-names = "ipg";
+                               status = "disabled";
+                       };
+
                        wdoga5: wdog@4003e000 {
                                compatible = "fsl,vf610-wdt", "fsl,imx21-wdt";
                                reg = <0x4003e000 0x1000>;
                                status = "disabled";
                        };
 
+                       dcu0: dcu@40058000 {
+                               compatible = "fsl,vf610-dcu";
+                               reg = <0x40058000 0x1200>;
+                               interrupts = <30 IRQ_TYPE_LEVEL_HIGH>;
+                               clocks = <&clks VF610_CLK_DCU0>,
+                                       <&clks VF610_CLK_DCU0_DIV>;
+                               clock-names = "dcu", "pix";
+                               fsl,tcon = <&tcon0>;
+                               status = "disabled";
+                       };
+
                        i2c0: i2c@40066000 {
                                #address-cells = <1>;
                                #size-cells = <0>;
index c70709ada692ed05a001131e36e63b4d15103a95..79b6b07e115d55b1be05c676ed0326f2bba3c22a 100644 (file)
@@ -2,6 +2,6 @@
 # Makefile for the linux kernel.
 #
 
-obj-y  := irq.o common.o serial.o
+obj-y  := common.o serial.o
 obj-y  += pm.o suspend.o
 obj-y  += phy3250.o
index 9e3b90df32e1626c3858367910a2b446369d279d..00190535df9061ad6750bcac1f1a07ce65173574 100644 (file)
 #define IRQ_LPC32XX_GPI_06             LPC32XX_SIC2_IRQ(28)
 #define IRQ_LPC32XX_SYSCLK             LPC32XX_SIC2_IRQ(31)
 
-#define NR_IRQS                                96
+#define LPC32XX_NR_IRQS                        96
 
 #endif
diff --git a/arch/arm/mach-lpc32xx/irq.c b/arch/arm/mach-lpc32xx/irq.c
deleted file mode 100644 (file)
index 2ae431e..0000000
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * arch/arm/mach-lpc32xx/irq.c
- *
- * Author: Kevin Wells <kevin.wells@nxp.com>
- *
- * Copyright (C) 2010 NXP Semiconductors
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
-
-#include <linux/kernel.h>
-#include <linux/types.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/err.h>
-#include <linux/io.h>
-#include <linux/of.h>
-#include <linux/of_address.h>
-#include <linux/of_irq.h>
-#include <linux/irqdomain.h>
-#include <linux/module.h>
-
-#include <mach/irqs.h>
-#include <mach/hardware.h>
-#include <mach/platform.h>
-#include "common.h"
-
-/*
- * Default value representing the Activation polarity of all internal
- * interrupt sources
- */
-#define MIC_APR_DEFAULT                0x3FF0EFE0
-#define SIC1_APR_DEFAULT       0xFBD27186
-#define SIC2_APR_DEFAULT       0x801810C0
-
-/*
- * Default value representing the Activation Type of all internal
- * interrupt sources. All are level sensitive.
- */
-#define MIC_ATR_DEFAULT                0x00000000
-#define SIC1_ATR_DEFAULT       0x00026000
-#define SIC2_ATR_DEFAULT       0x00000000
-
-static struct irq_domain *lpc32xx_mic_domain;
-static struct device_node *lpc32xx_mic_np;
-
-struct lpc32xx_event_group_regs {
-       void __iomem *enab_reg;
-       void __iomem *edge_reg;
-       void __iomem *maskstat_reg;
-       void __iomem *rawstat_reg;
-};
-
-static const struct lpc32xx_event_group_regs lpc32xx_event_int_regs = {
-       .enab_reg = LPC32XX_CLKPWR_INT_ER,
-       .edge_reg = LPC32XX_CLKPWR_INT_AP,
-       .maskstat_reg = LPC32XX_CLKPWR_INT_SR,
-       .rawstat_reg = LPC32XX_CLKPWR_INT_RS,
-};
-
-static const struct lpc32xx_event_group_regs lpc32xx_event_pin_regs = {
-       .enab_reg = LPC32XX_CLKPWR_PIN_ER,
-       .edge_reg = LPC32XX_CLKPWR_PIN_AP,
-       .maskstat_reg = LPC32XX_CLKPWR_PIN_SR,
-       .rawstat_reg = LPC32XX_CLKPWR_PIN_RS,
-};
-
-struct lpc32xx_event_info {
-       const struct lpc32xx_event_group_regs *event_group;
-       u32 mask;
-};
-
-/*
- * Maps an IRQ number to and event mask and register
- */
-static const struct lpc32xx_event_info lpc32xx_events[NR_IRQS] = {
-       [IRQ_LPC32XX_GPI_08] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_08_BIT,
-       },
-       [IRQ_LPC32XX_GPI_09] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_09_BIT,
-       },
-       [IRQ_LPC32XX_GPI_19] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_19_BIT,
-       },
-       [IRQ_LPC32XX_GPI_07] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_07_BIT,
-       },
-       [IRQ_LPC32XX_GPI_00] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_00_BIT,
-       },
-       [IRQ_LPC32XX_GPI_01] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_01_BIT,
-       },
-       [IRQ_LPC32XX_GPI_02] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_02_BIT,
-       },
-       [IRQ_LPC32XX_GPI_03] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_03_BIT,
-       },
-       [IRQ_LPC32XX_GPI_04] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_04_BIT,
-       },
-       [IRQ_LPC32XX_GPI_05] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_05_BIT,
-       },
-       [IRQ_LPC32XX_GPI_06] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_06_BIT,
-       },
-       [IRQ_LPC32XX_GPI_28] = {
-               .event_group = &lpc32xx_event_pin_regs,
-               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_28_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_00] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_00_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_01] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_01_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_02] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_02_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_03] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_03_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_04] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_04_BIT,
-       },
-       [IRQ_LPC32XX_GPIO_05] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_05_BIT,
-       },
-       [IRQ_LPC32XX_KEY] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_KEY_BIT,
-       },
-       [IRQ_LPC32XX_ETHERNET] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_MAC_BIT,
-       },
-       [IRQ_LPC32XX_USB_OTG_ATX] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_USBATXINT_BIT,
-       },
-       [IRQ_LPC32XX_USB_HOST] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_USB_BIT,
-       },
-       [IRQ_LPC32XX_RTC] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_RTC_BIT,
-       },
-       [IRQ_LPC32XX_MSTIMER] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_MSTIMER_BIT,
-       },
-       [IRQ_LPC32XX_TS_AUX] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_TS_AUX_BIT,
-       },
-       [IRQ_LPC32XX_TS_P] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_TS_P_BIT,
-       },
-       [IRQ_LPC32XX_TS_IRQ] = {
-               .event_group = &lpc32xx_event_int_regs,
-               .mask = LPC32XX_CLKPWR_INTSRC_ADC_BIT,
-       },
-};
-
-static void get_controller(unsigned int irq, unsigned int *base,
-       unsigned int *irqbit)
-{
-       if (irq < 32) {
-               *base = LPC32XX_MIC_BASE;
-               *irqbit = 1 << irq;
-       } else if (irq < 64) {
-               *base = LPC32XX_SIC1_BASE;
-               *irqbit = 1 << (irq - 32);
-       } else {
-               *base = LPC32XX_SIC2_BASE;
-               *irqbit = 1 << (irq - 64);
-       }
-}
-
-static void lpc32xx_mask_irq(struct irq_data *d)
-{
-       unsigned int reg, ctrl, mask;
-
-       get_controller(d->hwirq, &ctrl, &mask);
-
-       reg = __raw_readl(LPC32XX_INTC_MASK(ctrl)) & ~mask;
-       __raw_writel(reg, LPC32XX_INTC_MASK(ctrl));
-}
-
-static void lpc32xx_unmask_irq(struct irq_data *d)
-{
-       unsigned int reg, ctrl, mask;
-
-       get_controller(d->hwirq, &ctrl, &mask);
-
-       reg = __raw_readl(LPC32XX_INTC_MASK(ctrl)) | mask;
-       __raw_writel(reg, LPC32XX_INTC_MASK(ctrl));
-}
-
-static void lpc32xx_ack_irq(struct irq_data *d)
-{
-       unsigned int ctrl, mask;
-
-       get_controller(d->hwirq, &ctrl, &mask);
-
-       __raw_writel(mask, LPC32XX_INTC_RAW_STAT(ctrl));
-
-       /* Also need to clear pending wake event */
-       if (lpc32xx_events[d->hwirq].mask != 0)
-               __raw_writel(lpc32xx_events[d->hwirq].mask,
-                       lpc32xx_events[d->hwirq].event_group->rawstat_reg);
-}
-
-static void __lpc32xx_set_irq_type(unsigned int irq, int use_high_level,
-       int use_edge)
-{
-       unsigned int reg, ctrl, mask;
-
-       get_controller(irq, &ctrl, &mask);
-
-       /* Activation level, high or low */
-       reg = __raw_readl(LPC32XX_INTC_POLAR(ctrl));
-       if (use_high_level)
-               reg |= mask;
-       else
-               reg &= ~mask;
-       __raw_writel(reg, LPC32XX_INTC_POLAR(ctrl));
-
-       /* Activation type, edge or level */
-       reg = __raw_readl(LPC32XX_INTC_ACT_TYPE(ctrl));
-       if (use_edge)
-               reg |= mask;
-       else
-               reg &= ~mask;
-       __raw_writel(reg, LPC32XX_INTC_ACT_TYPE(ctrl));
-
-       /* Use same polarity for the wake events */
-       if (lpc32xx_events[irq].mask != 0) {
-               reg = __raw_readl(lpc32xx_events[irq].event_group->edge_reg);
-
-               if (use_high_level)
-                       reg |= lpc32xx_events[irq].mask;
-               else
-                       reg &= ~lpc32xx_events[irq].mask;
-
-               __raw_writel(reg, lpc32xx_events[irq].event_group->edge_reg);
-       }
-}
-
-static int lpc32xx_set_irq_type(struct irq_data *d, unsigned int type)
-{
-       switch (type) {
-       case IRQ_TYPE_EDGE_RISING:
-               /* Rising edge sensitive */
-               __lpc32xx_set_irq_type(d->hwirq, 1, 1);
-               irq_set_handler_locked(d, handle_edge_irq);
-               break;
-
-       case IRQ_TYPE_EDGE_FALLING:
-               /* Falling edge sensitive */
-               __lpc32xx_set_irq_type(d->hwirq, 0, 1);
-               irq_set_handler_locked(d, handle_edge_irq);
-               break;
-
-       case IRQ_TYPE_LEVEL_LOW:
-               /* Low level sensitive */
-               __lpc32xx_set_irq_type(d->hwirq, 0, 0);
-               irq_set_handler_locked(d, handle_level_irq);
-               break;
-
-       case IRQ_TYPE_LEVEL_HIGH:
-               /* High level sensitive */
-               __lpc32xx_set_irq_type(d->hwirq, 1, 0);
-               irq_set_handler_locked(d, handle_level_irq);
-               break;
-
-       /* Other modes are not supported */
-       default:
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int lpc32xx_irq_wake(struct irq_data *d, unsigned int state)
-{
-       unsigned long eventreg;
-
-       if (lpc32xx_events[d->hwirq].mask != 0) {
-               eventreg = __raw_readl(lpc32xx_events[d->hwirq].
-                       event_group->enab_reg);
-
-               if (state)
-                       eventreg |= lpc32xx_events[d->hwirq].mask;
-               else {
-                       eventreg &= ~lpc32xx_events[d->hwirq].mask;
-
-                       /*
-                        * When disabling the wakeup, clear the latched
-                        * event
-                        */
-                       __raw_writel(lpc32xx_events[d->hwirq].mask,
-                               lpc32xx_events[d->hwirq].
-                               event_group->rawstat_reg);
-               }
-
-               __raw_writel(eventreg,
-                       lpc32xx_events[d->hwirq].event_group->enab_reg);
-
-               return 0;
-       }
-
-       /* Clear event */
-       __raw_writel(lpc32xx_events[d->hwirq].mask,
-               lpc32xx_events[d->hwirq].event_group->rawstat_reg);
-
-       return -ENODEV;
-}
-
-static void __init lpc32xx_set_default_mappings(unsigned int apr,
-       unsigned int atr, unsigned int offset)
-{
-       unsigned int i;
-
-       /* Set activation levels for each interrupt */
-       i = 0;
-       while (i < 32) {
-               __lpc32xx_set_irq_type(offset + i, ((apr >> i) & 0x1),
-                       ((atr >> i) & 0x1));
-               i++;
-       }
-}
-
-static struct irq_chip lpc32xx_irq_chip = {
-       .name = "MIC",
-       .irq_ack = lpc32xx_ack_irq,
-       .irq_mask = lpc32xx_mask_irq,
-       .irq_unmask = lpc32xx_unmask_irq,
-       .irq_set_type = lpc32xx_set_irq_type,
-       .irq_set_wake = lpc32xx_irq_wake
-};
-
-static void lpc32xx_sic1_handler(struct irq_desc *desc)
-{
-       unsigned long ints = __raw_readl(LPC32XX_INTC_STAT(LPC32XX_SIC1_BASE));
-
-       while (ints != 0) {
-               int irqno = fls(ints) - 1;
-
-               ints &= ~(1 << irqno);
-
-               generic_handle_irq(LPC32XX_SIC1_IRQ(irqno));
-       }
-}
-
-static void lpc32xx_sic2_handler(struct irq_desc *desc)
-{
-       unsigned long ints = __raw_readl(LPC32XX_INTC_STAT(LPC32XX_SIC2_BASE));
-
-       while (ints != 0) {
-               int irqno = fls(ints) - 1;
-
-               ints &= ~(1 << irqno);
-
-               generic_handle_irq(LPC32XX_SIC2_IRQ(irqno));
-       }
-}
-
-static int __init __lpc32xx_mic_of_init(struct device_node *node,
-                                       struct device_node *parent)
-{
-       lpc32xx_mic_np = node;
-
-       return 0;
-}
-
-static const struct of_device_id mic_of_match[] __initconst = {
-       { .compatible = "nxp,lpc3220-mic", .data = __lpc32xx_mic_of_init },
-       { }
-};
-
-void __init lpc32xx_init_irq(void)
-{
-       unsigned int i;
-
-       /* Setup MIC */
-       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_MIC_BASE));
-       __raw_writel(MIC_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_MIC_BASE));
-       __raw_writel(MIC_ATR_DEFAULT, LPC32XX_INTC_ACT_TYPE(LPC32XX_MIC_BASE));
-
-       /* Setup SIC1 */
-       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC1_BASE));
-       __raw_writel(SIC1_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_SIC1_BASE));
-       __raw_writel(SIC1_ATR_DEFAULT,
-                               LPC32XX_INTC_ACT_TYPE(LPC32XX_SIC1_BASE));
-
-       /* Setup SIC2 */
-       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC2_BASE));
-       __raw_writel(SIC2_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_SIC2_BASE));
-       __raw_writel(SIC2_ATR_DEFAULT,
-                               LPC32XX_INTC_ACT_TYPE(LPC32XX_SIC2_BASE));
-
-       /* Configure supported IRQ's */
-       for (i = 0; i < NR_IRQS; i++) {
-               irq_set_chip_and_handler(i, &lpc32xx_irq_chip,
-                                        handle_level_irq);
-               irq_clear_status_flags(i, IRQ_NOREQUEST);
-       }
-
-       /* Set default mappings */
-       lpc32xx_set_default_mappings(MIC_APR_DEFAULT, MIC_ATR_DEFAULT, 0);
-       lpc32xx_set_default_mappings(SIC1_APR_DEFAULT, SIC1_ATR_DEFAULT, 32);
-       lpc32xx_set_default_mappings(SIC2_APR_DEFAULT, SIC2_ATR_DEFAULT, 64);
-
-       /* Initially disable all wake events */
-       __raw_writel(0, LPC32XX_CLKPWR_P01_ER);
-       __raw_writel(0, LPC32XX_CLKPWR_INT_ER);
-       __raw_writel(0, LPC32XX_CLKPWR_PIN_ER);
-
-       /*
-        * Default wake activation polarities, all pin sources are low edge
-        * triggered
-        */
-       __raw_writel(LPC32XX_CLKPWR_INTSRC_TS_P_BIT |
-               LPC32XX_CLKPWR_INTSRC_MSTIMER_BIT |
-               LPC32XX_CLKPWR_INTSRC_RTC_BIT,
-               LPC32XX_CLKPWR_INT_AP);
-       __raw_writel(0, LPC32XX_CLKPWR_PIN_AP);
-
-       /* Clear latched wake event states */
-       __raw_writel(__raw_readl(LPC32XX_CLKPWR_PIN_RS),
-               LPC32XX_CLKPWR_PIN_RS);
-       __raw_writel(__raw_readl(LPC32XX_CLKPWR_INT_RS),
-               LPC32XX_CLKPWR_INT_RS);
-
-       of_irq_init(mic_of_match);
-
-       lpc32xx_mic_domain = irq_domain_add_legacy(lpc32xx_mic_np, NR_IRQS,
-                                                  0, 0, &irq_domain_simple_ops,
-                                                  NULL);
-       if (!lpc32xx_mic_domain)
-               panic("Unable to add MIC irq domain\n");
-
-       /* MIC SUBIRQx interrupts will route handling to the chain handlers */
-       irq_set_chained_handler(IRQ_LPC32XX_SUB1IRQ, lpc32xx_sic1_handler);
-       irq_set_chained_handler(IRQ_LPC32XX_SUB2IRQ, lpc32xx_sic2_handler);
-}
index 72918c4973ea7f0cc86da080916c9f72bd327fcd..f6ac027f3c3bf2d5bb41b436fd85fa40a9a2a670 100644 (file)
@@ -97,10 +97,7 @@ int gpmc_nand_init(struct omap_nand_platform_data *gpmc_nand_data,
        gpmc_nand_res[2].start = gpmc_get_client_irq(GPMC_IRQ_COUNT_EVENT);
 
        memset(&s, 0, sizeof(struct gpmc_settings));
-       if (gpmc_nand_data->of_node)
-               gpmc_read_settings_dt(gpmc_nand_data->of_node, &s);
-       else
-               gpmc_set_legacy(gpmc_nand_data, &s);
+       gpmc_set_legacy(gpmc_nand_data, &s);
 
        s.device_nand = true;
 
@@ -121,8 +118,6 @@ int gpmc_nand_init(struct omap_nand_platform_data *gpmc_nand_data,
        if (err < 0)
                goto out_free_cs;
 
-       gpmc_update_nand_reg(&gpmc_nand_data->reg, gpmc_nand_data->cs);
-
        if (!gpmc_hwecc_bch_capable(gpmc_nand_data->ecc_opt)) {
                pr_err("omap2-nand: Unsupported NAND ECC scheme selected\n");
                err = -EINVAL;
index 7ee4652b4c61d9a3a921d52de13d3e46dd356d78..cd894d69e7663a8abf187ed77a3b7dff84752fc9 100644 (file)
@@ -6,6 +6,7 @@ comment "Intel/Marvell Dev Platforms (sorted by hardware release time)"
 
 config MACH_PXA27X_DT
        bool "Support PXA27x platforms from device tree"
+       select PINCTRL
        select POWER_SUPPLY
        select PXA27x
        select USE_OF
@@ -17,6 +18,7 @@ config MACH_PXA27X_DT
 config MACH_PXA3XX_DT
        bool "Support PXA3xx platforms from device tree"
        select CPU_PXA300
+       select PINCTRL
        select POWER_SUPPLY
        select PXA3xx
        select USE_OF
index e838b11fb8c7d3992f88d247522064a83e2ea08f..fa9d71d194f01f44fb5bccf065a8a362838f6b3a 100644 (file)
@@ -128,7 +128,7 @@ struct resource eseries_tmio_resources[] = {
 /* Some e-series hardware cannot control the 32K clock */
 static void __init __maybe_unused eseries_register_clks(void)
 {
-       clk_register_fixed_rate(NULL, "CLK_CK32K", NULL, CLK_IS_ROOT, 32768);
+       clk_register_fixed_rate(NULL, "CLK_CK32K", NULL, 0, 32768);
 }
 
 #ifdef CONFIG_MACH_E330
index d9578bc49fdc61766c430e55e1ab21857a6ebf03..bd7cd8b6a286ec3713145c3713e861c7419bd25e 100644 (file)
@@ -763,14 +763,49 @@ static struct nand_bbt_descr spitz_nand_bbt = {
        .pattern        = scan_ff_pattern
 };
 
-static struct nand_ecclayout akita_oobinfo = {
-       .oobfree        = { {0x08, 0x09} },
-       .eccbytes       = 24,
-       .eccpos         = {
-                       0x05, 0x01, 0x02, 0x03, 0x06, 0x07, 0x15, 0x11,
-                       0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23,
-                       0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37,
-       },
+static int akita_ooblayout_ecc(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       if (section > 12)
+               return -ERANGE;
+
+       switch (section % 3) {
+       case 0:
+               oobregion->offset = 5;
+               oobregion->length = 1;
+               break;
+
+       case 1:
+               oobregion->offset = 1;
+               oobregion->length = 3;
+               break;
+
+       case 2:
+               oobregion->offset = 6;
+               oobregion->length = 2;
+               break;
+       }
+
+       oobregion->offset += (section / 3) * 0x10;
+
+       return 0;
+}
+
+static int akita_ooblayout_free(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 8;
+       oobregion->length = 9;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops akita_ooblayout_ops = {
+       .ecc = akita_ooblayout_ecc,
+       .free = akita_ooblayout_free,
 };
 
 static struct sharpsl_nand_platform_data spitz_nand_pdata = {
@@ -804,11 +839,11 @@ static void __init spitz_nand_init(void)
        } else if (machine_is_akita()) {
                spitz_nand_partitions[1].size = 58 * 1024 * 1024;
                spitz_nand_bbt.len = 1;
-               spitz_nand_pdata.ecc_layout = &akita_oobinfo;
+               spitz_nand_pdata.ecc_layout = &akita_ooblayout_ops;
        } else if (machine_is_borzoi()) {
                spitz_nand_partitions[1].size = 32 * 1024 * 1024;
                spitz_nand_bbt.len = 1;
-               spitz_nand_pdata.ecc_layout = &akita_oobinfo;
+               spitz_nand_pdata.ecc_layout = &akita_ooblayout_ops;
        }
 
        platform_device_register(&spitz_nand_device);
index 7cb2d72e7378301a83b6e493701daa5ff9799868..3285a9286786c48cce2ba1cba1b3f1be3d4d4f2f 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <dt-bindings/clock/r8a7795-cpg-mssr.h>
 #include <dt-bindings/interrupt-controller/arm-gic.h>
+#include <dt-bindings/power/r8a7795-sysc.h>
 
 / {
        compatible = "renesas,r8a7795";
@@ -39,6 +40,7 @@
                        compatible = "arm,cortex-a57", "arm,armv8";
                        reg = <0x0>;
                        device_type = "cpu";
+                       power-domains = <&sysc R8A7795_PD_CA57_CPU0>;
                        next-level-cache = <&L2_CA57>;
                        enable-method = "psci";
                };
@@ -47,6 +49,7 @@
                        compatible = "arm,cortex-a57","arm,armv8";
                        reg = <0x1>;
                        device_type = "cpu";
+                       power-domains = <&sysc R8A7795_PD_CA57_CPU1>;
                        next-level-cache = <&L2_CA57>;
                        enable-method = "psci";
                };
@@ -54,6 +57,7 @@
                        compatible = "arm,cortex-a57","arm,armv8";
                        reg = <0x2>;
                        device_type = "cpu";
+                       power-domains = <&sysc R8A7795_PD_CA57_CPU2>;
                        next-level-cache = <&L2_CA57>;
                        enable-method = "psci";
                };
@@ -61,6 +65,7 @@
                        compatible = "arm,cortex-a57","arm,armv8";
                        reg = <0x3>;
                        device_type = "cpu";
+                       power-domains = <&sysc R8A7795_PD_CA57_CPU3>;
                        next-level-cache = <&L2_CA57>;
                        enable-method = "psci";
                };
 
        L2_CA57: cache-controller@0 {
                compatible = "cache";
+               power-domains = <&sysc R8A7795_PD_CA57_SCU>;
                cache-unified;
                cache-level = <2>;
        };
 
        L2_CA53: cache-controller@1 {
                compatible = "cache";
+               power-domains = <&sysc R8A7795_PD_CA53_SCU>;
                cache-unified;
                cache-level = <2>;
        };
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 912>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio1: gpio@e6051000 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 911>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio2: gpio@e6052000 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 910>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio3: gpio@e6053000 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 909>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio4: gpio@e6054000 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 908>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio5: gpio@e6055000 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 907>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio6: gpio@e6055400 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 906>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                gpio7: gpio@e6055800 {
                        #interrupt-cells = <2>;
                        interrupt-controller;
                        clocks = <&cpg CPG_MOD 905>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                pmu_a57 {
                        #power-domain-cells = <0>;
                };
 
+               sysc: system-controller@e6180000 {
+                       compatible = "renesas,r8a7795-sysc";
+                       reg = <0 0xe6180000 0 0x0400>;
+                       #power-domain-cells = <1>;
+               };
+
                audma0: dma-controller@ec700000 {
                        compatible = "renesas,rcar-dmac";
                        reg = <0 0xec700000 0 0x10000>;
                                        "ch12", "ch13", "ch14", "ch15";
                        clocks = <&cpg CPG_MOD 502>;
                        clock-names = "fck";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <16>;
                };
                                        "ch12", "ch13", "ch14", "ch15";
                        clocks = <&cpg CPG_MOD 501>;
                        clock-names = "fck";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <16>;
                };
                                      GIC_SPI 18 IRQ_TYPE_LEVEL_HIGH
                                      GIC_SPI 161 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 407>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                };
 
                dmac0: dma-controller@e6700000 {
                                        "ch12", "ch13", "ch14", "ch15";
                        clocks = <&cpg CPG_MOD 219>;
                        clock-names = "fck";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <16>;
                };
                                        "ch12", "ch13", "ch14", "ch15";
                        clocks = <&cpg CPG_MOD 218>;
                        clock-names = "fck";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <16>;
                };
                                        "ch12", "ch13", "ch14", "ch15";
                        clocks = <&cpg CPG_MOD 217>;
                        clock-names = "fck";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <16>;
                };
                                          "ch20", "ch21", "ch22", "ch23",
                                          "ch24";
                        clocks = <&cpg CPG_MOD 812>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        phy-mode = "rgmii-id";
                        #address-cells = <1>;
                        #size-cells = <0>;
                        clock-names = "clkp1", "clkp2", "can_clk";
                        assigned-clocks = <&cpg CPG_CORE R8A7795_CLK_CANFD>;
                        assigned-clock-rates = <40000000>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "clkp1", "clkp2", "can_clk";
                        assigned-clocks = <&cpg CPG_CORE R8A7795_CLK_CANFD>;
                        assigned-clock-rates = <40000000>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x31>, <&dmac1 0x30>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x33>, <&dmac1 0x32>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x35>, <&dmac1 0x34>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac0 0x37>, <&dmac0 0x36>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac0 0x39>, <&dmac0 0x38>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x51>, <&dmac1 0x50>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x53>, <&dmac1 0x52>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x13>, <&dmac1 0x12>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac0 0x57>, <&dmac0 0x56>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac0 0x59>, <&dmac0 0x58>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clock-names = "fck", "brg_int", "scif_clk";
                        dmas = <&dmac1 0x5b>, <&dmac1 0x5a>;
                        dma-names = "tx", "rx";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        reg = <0 0xe6500000 0 0x40>;
                        interrupts = <GIC_SPI 287 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 931>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <110>;
                        status = "disabled";
                };
                        reg = <0 0xe6508000 0 0x40>;
                        interrupts = <GIC_SPI 288 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 930>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <6>;
                        status = "disabled";
                };
                        reg = <0 0xe6510000 0 0x40>;
                        interrupts = <GIC_SPI 286 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 929>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <6>;
                        status = "disabled";
                };
                        reg = <0 0xe66d0000 0 0x40>;
                        interrupts = <GIC_SPI 290 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 928>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <110>;
                        status = "disabled";
                };
                        reg = <0 0xe66d8000 0 0x40>;
                        interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 927>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <110>;
                        status = "disabled";
                };
                        reg = <0 0xe66e0000 0 0x40>;
                        interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 919>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <110>;
                        status = "disabled";
                };
                        reg = <0 0xe66e8000 0 0x40>;
                        interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 918>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        i2c-scl-internal-delay-ns = <6>;
                        status = "disabled";
                };
                                      "src.1", "src.0",
                                      "dvc.0", "dvc.1",
                                      "clk_a", "clk_b", "clk_c", "clk_i";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
 
                        rcar_sound,dvc {
                        reg = <0 0xee000000 0 0xc00>;
                        interrupts = <GIC_SPI 102 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 328>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        reg = <0 0xee040000 0 0xc00>;
                        interrupts = <GIC_SPI 98 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 327>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                                      GIC_SPI 109 IRQ_TYPE_LEVEL_HIGH>;
                        interrupt-names = "ch0", "ch1";
                        clocks = <&cpg CPG_MOD 330>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <2>;
                };
                                      GIC_SPI 110 IRQ_TYPE_LEVEL_HIGH>;
                        interrupt-names = "ch0", "ch1";
                        clocks = <&cpg CPG_MOD 331>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #dma-cells = <1>;
                        dma-channels = <2>;
                };
                        reg = <0 0xee100000 0 0x2000>;
                        interrupts = <GIC_SPI 165 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 314>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        reg = <0 0xee120000 0 0x2000>;
                        interrupts = <GIC_SPI 166 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 313>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        reg = <0 0xee140000 0 0x2000>;
                        interrupts = <GIC_SPI 167 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 312>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        cap-mmc-highspeed;
                        status = "disabled";
                };
                        reg = <0 0xee160000 0 0x2000>;
                        interrupts = <GIC_SPI 168 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 311>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        cap-mmc-highspeed;
                        status = "disabled";
                };
                        reg = <0 0xee080200 0 0x700>;
                        interrupts = <GIC_SPI 108 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 703>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #phy-cells = <0>;
                        status = "disabled";
                };
                        compatible = "renesas,usb2-phy-r8a7795";
                        reg = <0 0xee0a0200 0 0x700>;
                        clocks = <&cpg CPG_MOD 702>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #phy-cells = <0>;
                        status = "disabled";
                };
                        compatible = "renesas,usb2-phy-r8a7795";
                        reg = <0 0xee0c0200 0 0x700>;
                        clocks = <&cpg CPG_MOD 701>;
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        #phy-cells = <0>;
                        status = "disabled";
                };
                        clocks = <&cpg CPG_MOD 703>;
                        phys = <&usb2_phy0>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clocks = <&cpg CPG_MOD 702>;
                        phys = <&usb2_phy1>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clocks = <&cpg CPG_MOD 701>;
                        phys = <&usb2_phy2>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clocks = <&cpg CPG_MOD 703>;
                        phys = <&usb2_phy0>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clocks = <&cpg CPG_MOD 702>;
                        phys = <&usb2_phy1>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        clocks = <&cpg CPG_MOD 701>;
                        phys = <&usb2_phy2>;
                        phy-names = "usb";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
                pciec0: pcie@fe000000 {
                        interrupt-map = <0 0 0 0 &gic GIC_SPI 116 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 319>, <&pcie_bus_clk>;
                        clock-names = "pcie", "pcie_bus";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
 
                        interrupt-map = <0 0 0 0 &gic GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
                        clocks = <&cpg CPG_MOD 318>, <&pcie_bus_clk>;
                        clock-names = "pcie", "pcie_bus";
-                       power-domains = <&cpg>;
+                       power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
                        status = "disabled";
                };
        };
index 1caadc24e3fe99c1ed3169cfbb238ab279ad0ff4..043d17a21342e8168ca2e71933b72316cfd6eb5f 100644 (file)
@@ -13,4 +13,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
+#define __ARCH_WANT_RENAMEAT
+
 #include <asm-generic/unistd.h>
index e7d09a614d1028b4e0673f73f05d3fa0388e23f5..12d73d9d81f55ceba344eb91ca95130a308a35f9 100644 (file)
@@ -14,6 +14,7 @@
  *   more details.
  */
 
+#define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_SYS_CLONE
 
 /* Use the standard ABI for syscalls. */
index 5aa3f516231081ccc92e29999e9826b8d61a85b4..3f646c787e584e40a097208abd9fdb05221cf755 100644 (file)
@@ -157,6 +157,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
        /* 20 us command delay time */
        this->chip_delay = 20;
        this->ecc.mode = NAND_ECC_SOFT;
+       this->ecc.algo = NAND_ECC_HAMMING;
 
        /* Enable the following for a flash based bad block table */
        /* this->bbt_options = NAND_BBT_USE_FLASH; */
index a7c17b0f172a360e4b57465ad7c19b8c5196ac2f..a74540514bdbdcde086259df8f08a9beec340cd0 100644 (file)
@@ -148,6 +148,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)
        /* 20 us command delay time */
        this->chip_delay = 20;
        this->ecc.mode = NAND_ECC_SOFT;
+       this->ecc.algo = NAND_ECC_HAMMING;
 
        /* Enable the following for a flash based bad block table */
        /* this->bbt_options = NAND_BBT_USE_FLASH; */
index 7a2eb698def355b6c418782ae47e3653289394a8..7dd20ef7625adeeba03fba80cde6aaa70d91e3c2 100644 (file)
@@ -1,3 +1,5 @@
 #define __ARCH_NOMMU
 
+#define __ARCH_WANT_RENAMEAT
+
 #include <asm-generic/unistd.h>
index ffee405d68034a004168e0763e26fd146273d14f..21517600432b42e529ea9a1bc2fb68771e97b16a 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #define sys_mmap2 sys_mmap_pgoff
+#define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_SYS_EXECVE
 #define __ARCH_WANT_SYS_CLONE
 #define __ARCH_WANT_SYS_VFORK
index b80b8e899d22dfd202bbf8b9403a48b342d3462e..459b6ec1584862e20212a34c56b7ed7ce57082d3 100644 (file)
@@ -7,6 +7,8 @@
  * (at your option) any later version.
  */
 
+#define __ARCH_WANT_RENAMEAT
+
 /* Use the standard ABI for syscalls. */
 #include <asm-generic/unistd.h>
 
index 76ed17b56fead0092462c7f5498767b281c0339a..805ae5d712e8baa63095199f1601ce548c26d606 100644 (file)
@@ -38,6 +38,6 @@
 
 #endif /* __ASSEMBLY__ */
 
-#define __NR_syscalls         389
+#define __NR_syscalls         392
 
 #endif /* _ASM_MICROBLAZE_UNISTD_H */
index 32850c73be09b915309fe892486c0d5187eed0a5..a8bd3fa28bc7f4e97158fff49d25443524647b0d 100644 (file)
 #define __NR_memfd_create      386
 #define __NR_bpf               387
 #define __NR_execveat          388
+#define __NR_userfaultfd       389
+#define __NR_membarrier                390
+#define __NR_mlock2            391
 
 #endif /* _UAPI_ASM_MICROBLAZE_UNISTD_H */
index 29c8568ec55c32776139cd79e1e441d23638078d..6b3dd99126d753a22a9ed270ec92761c2f936e27 100644 (file)
@@ -389,3 +389,6 @@ ENTRY(sys_call_table)
        .long sys_memfd_create
        .long sys_bpf
        .long sys_execveat
+       .long sys_userfaultfd
+       .long sys_membarrier            /* 390 */
+       .long sys_mlock2
index 35654be3f1c03289bda596b184b64c2d734d7655..14cba600da7ae4fff9573cfcb27465e8f322e73d 100644 (file)
@@ -48,6 +48,8 @@ static int global_phb_number;         /* Global phb counter */
 resource_size_t isa_mem_base;
 
 unsigned long isa_io_base;
+EXPORT_SYMBOL(isa_io_base);
+
 static int pci_bus_count;
 
 struct pci_controller *pcibios_alloc_controller(struct device_node *dev)
index 398733e3e2cf65006541cf5c3eff6c68b06b0eb0..7f7b0fc554da5c5a706768f73cfd730d7ed9ae85 100644 (file)
@@ -27,7 +27,7 @@ struct jz_nand_platform_data {
 
        unsigned char banks[JZ_NAND_NUM_BANKS];
 
-       void (*ident_callback)(struct platform_device *, struct nand_chip *,
+       void (*ident_callback)(struct platform_device *, struct mtd_info *,
                                struct mtd_partition **, int *num_partitions);
 };
 
index 4e3f9b7a02e4997101843a9283c45cb97fa81866..258fd03c9ef5aa98145cb69b699f39f5dd92e81a 100644 (file)
 #define QI_LB60_GPIO_KEYIN8            JZ_GPIO_PORTD(26)
 
 /* NAND */
-static struct nand_ecclayout qi_lb60_ecclayout_1gb = {
-       .eccbytes = 36,
-       .eccpos = {
-               6,  7,  8,  9,  10, 11, 12, 13,
-               14, 15, 16, 17, 18, 19, 20, 21,
-               22, 23, 24, 25, 26, 27, 28, 29,
-               30, 31, 32, 33, 34, 35, 36, 37,
-               38, 39, 40, 41
-       },
-       .oobfree = {
-               { .offset = 2, .length = 4 },
-               { .offset = 42, .length = 22 }
-       },
-};
 
 /* Early prototypes of the QI LB60 had only 1GB of NAND.
  * In order to support these devices as well the partition and ecc layout is
@@ -84,25 +70,6 @@ static struct mtd_partition qi_lb60_partitions_1gb[] = {
        },
 };
 
-static struct nand_ecclayout qi_lb60_ecclayout_2gb = {
-       .eccbytes = 72,
-       .eccpos = {
-               12, 13, 14, 15, 16, 17, 18, 19,
-               20, 21, 22, 23, 24, 25, 26, 27,
-               28, 29, 30, 31, 32, 33, 34, 35,
-               36, 37, 38, 39, 40, 41, 42, 43,
-               44, 45, 46, 47, 48, 49, 50, 51,
-               52, 53, 54, 55, 56, 57, 58, 59,
-               60, 61, 62, 63, 64, 65, 66, 67,
-               68, 69, 70, 71, 72, 73, 74, 75,
-               76, 77, 78, 79, 80, 81, 82, 83
-       },
-       .oobfree = {
-               { .offset = 2, .length = 10 },
-               { .offset = 84, .length = 44 },
-       },
-};
-
 static struct mtd_partition qi_lb60_partitions_2gb[] = {
        {
                .name = "NAND BOOT partition",
@@ -121,19 +88,67 @@ static struct mtd_partition qi_lb60_partitions_2gb[] = {
        },
 };
 
+static int qi_lb60_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = 36;
+       oobregion->offset = 6;
+
+       if (mtd->oobsize == 128) {
+               oobregion->length *= 2;
+               oobregion->offset *= 2;
+       }
+
+       return 0;
+}
+
+static int qi_lb60_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       int eccbytes = 36, eccoff = 6;
+
+       if (section > 1)
+               return -ERANGE;
+
+       if (mtd->oobsize == 128) {
+               eccbytes *= 2;
+               eccoff *= 2;
+       }
+
+       if (!section) {
+               oobregion->offset = 2;
+               oobregion->length = eccoff - 2;
+       } else {
+               oobregion->offset = eccoff + eccbytes;
+               oobregion->length = mtd->oobsize - oobregion->offset;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops qi_lb60_ooblayout_ops = {
+       .ecc = qi_lb60_ooblayout_ecc,
+       .free = qi_lb60_ooblayout_free,
+};
+
 static void qi_lb60_nand_ident(struct platform_device *pdev,
-               struct nand_chip *chip, struct mtd_partition **partitions,
+               struct mtd_info *mtd, struct mtd_partition **partitions,
                int *num_partitions)
 {
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
        if (chip->page_shift == 12) {
-               chip->ecc.layout = &qi_lb60_ecclayout_2gb;
                *partitions = qi_lb60_partitions_2gb;
                *num_partitions = ARRAY_SIZE(qi_lb60_partitions_2gb);
        } else {
-               chip->ecc.layout = &qi_lb60_ecclayout_1gb;
                *partitions = qi_lb60_partitions_1gb;
                *num_partitions = ARRAY_SIZE(qi_lb60_partitions_1gb);
        }
+
+       mtd_set_ooblayout(mtd, &qi_lb60_ooblayout_ops);
 }
 
 static struct jz_nand_platform_data qi_lb60_nand_pdata = {
index 2328f82ba2a8a47527c45dc99ba69c97e8bf6f0a..e74afc12d5163259c200e0280a382f64355d0196 100644 (file)
@@ -20,7 +20,7 @@ UTS_SYSNAME = Linux
 
 export MMU
 
-LIBGCC         := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
+LIBGCC         := $(shell $(CC) $(KBUILD_CFLAGS) $(KCFLAGS) -print-libgcc-file-name)
 
 KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__
 KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul)
@@ -53,7 +53,7 @@ all: vmImage
 archclean:
        $(Q)$(MAKE) $(clean)=$(nios2-boot)
 
-%.dtb:
+%.dtb: | scripts
        $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
 
 dtbs:
index c4bf7951046153b3a39f5c11a21dadfe3de0f74a..51a32c71ce2bd0a5950701f402a1b963d54169df 100644 (file)
@@ -17,6 +17,8 @@
 
  #define sys_mmap2 sys_mmap_pgoff
 
+#define __ARCH_WANT_RENAMEAT
+
 /* Use the standard ABI for syscalls */
 #include <asm-generic/unistd.h>
 
index ce40b71df0069d8516a94141556cb37ab32819ee..471905bd77452b06ad8bca2143038ef31da41f81 100644 (file)
@@ -20,6 +20,7 @@
 
 #define sys_mmap2 sys_mmap_pgoff
 
+#define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_SYS_FORK
 #define __ARCH_WANT_SYS_CLONE
 
index 3d498a676551d0fa778f0bafe0cbced3fe44765d..dc117385ce2e17480f15771fdb96969f7e1971bf 100644 (file)
@@ -6,6 +6,7 @@ config PARISC
        select HAVE_OPROFILE
        select HAVE_FUNCTION_TRACER
        select HAVE_FUNCTION_GRAPH_TRACER
+       select HAVE_SYSCALL_TRACEPOINTS
        select ARCH_WANT_FRAME_POINTERS
        select RTC_CLASS
        select RTC_DRV_GENERIC
@@ -31,6 +32,8 @@ config PARISC
        select HAVE_DEBUG_STACKOVERFLOW
        select HAVE_ARCH_AUDITSYSCALL
        select HAVE_ARCH_SECCOMP_FILTER
+       select HAVE_ARCH_TRACEHOOK
+       select HAVE_UNSTABLE_SCHED_CLOCK if (SMP || !64BIT)
        select ARCH_NO_COHERENT_DMA_MMAP
        select CPU_NO_EFFICIENT_FFS
 
index 0a90b965cccbefe172be5dde879b5035b4589685..7ada309008073ac62021942709107f526a76a11f 100644 (file)
@@ -52,8 +52,7 @@ extern void __cmpxchg_called_with_bad_pointer(void);
 /* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */
 extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old,
                                   unsigned int new_);
-extern unsigned long __cmpxchg_u64(volatile unsigned long *ptr,
-                                  unsigned long old, unsigned long new_);
+extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_);
 
 /* don't worry...optimizer will get rid of most of this */
 static inline unsigned long
@@ -61,7 +60,7 @@ __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
 {
        switch (size) {
 #ifdef CONFIG_64BIT
-       case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
+       case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
 #endif
        case 4: return __cmpxchg_u32((unsigned int *)ptr,
                                     (unsigned int)old, (unsigned int)new_);
@@ -86,7 +85,7 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
 {
        switch (size) {
 #ifdef CONFIG_64BIT
-       case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
+       case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
 #endif
        case 4: return __cmpxchg_u32(ptr, old, new_);
        default:
@@ -111,4 +110,6 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
 #endif
 
+#define cmpxchg64(ptr, o, n) __cmpxchg_u64(ptr, o, n)
+
 #endif /* _ASM_PARISC_CMPXCHG_H_ */
index 8ce8b85ca588411c469ebb4527db83bfe0a48f35..5637ac962f8ec9b43551847a4d3a9202bf45726e 100644 (file)
@@ -99,7 +99,7 @@ struct eeprom_eisa_slot_info
 #define HPEE_MEMORY_DECODE_24BITS 0x04
 #define HPEE_MEMORY_DECODE_32BITS 0x08
 /* byte 2 and 3 are a 16bit LE value
- * containging the memory size in kilobytes */
+ * containing the memory size in kilobytes */
 /* byte 4,5,6 are a 24bit LE value
  * containing the memory base address */
 
@@ -135,7 +135,7 @@ struct eeprom_eisa_slot_info
 #define HPEE_PORT_SHARED    0x40
 #define HPEE_PORT_MORE      0x80
 /* byte 1 and 2 is a 16bit LE value
- * conating the start port number */
+ * containing the start port number */
 
 #define HPEE_PORT_INIT_MAX_LEN     60 /* in bytes here */
 /* port init entry byte 0 */
index 24cd81d58d706faafe469c10a85f1182a28b958a..d635c6b0269df84337cf0abc23f87603aad99296 100644 (file)
@@ -6,6 +6,8 @@ extern void mcount(void);
 
 #define MCOUNT_INSN_SIZE 4
 
+extern unsigned long sys_call_table[];
+
 extern unsigned long return_address(unsigned int);
 
 #define ftrace_return_address(n) return_address(n)
index 49df14805a9b44bba6857ec4138fe62164e935ab..ac8bd586ace8d17329e2536244b7833c0db46c83 100644 (file)
@@ -35,70 +35,57 @@ static inline int
 futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
 {
        unsigned long int flags;
-       u32 val;
        int op = (encoded_op >> 28) & 7;
        int cmp = (encoded_op >> 24) & 15;
        int oparg = (encoded_op << 8) >> 20;
        int cmparg = (encoded_op << 20) >> 20;
-       int oldval = 0, ret;
+       int oldval, ret;
+       u32 tmp;
+
        if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
                oparg = 1 << oparg;
 
        if (!access_ok(VERIFY_WRITE, uaddr, sizeof(*uaddr)))
                return -EFAULT;
 
+       _futex_spin_lock_irqsave(uaddr, &flags);
        pagefault_disable();
 
-       _futex_spin_lock_irqsave(uaddr, &flags);
+       ret = -EFAULT;
+       if (unlikely(get_user(oldval, uaddr) != 0))
+               goto out_pagefault_enable;
+
+       ret = 0;
+       tmp = oldval;
 
        switch (op) {
        case FUTEX_OP_SET:
-               /* *(int *)UADDR2 = OPARG; */
-               ret = get_user(oldval, uaddr);
-               if (!ret)
-                       ret = put_user(oparg, uaddr);
+               tmp = oparg;
                break;
        case FUTEX_OP_ADD:
-               /* *(int *)UADDR2 += OPARG; */
-               ret = get_user(oldval, uaddr);
-               if (!ret) {
-                       val = oldval + oparg;
-                       ret = put_user(val, uaddr);
-               }
+               tmp += oparg;
                break;
        case FUTEX_OP_OR:
-               /* *(int *)UADDR2 |= OPARG; */
-               ret = get_user(oldval, uaddr);
-               if (!ret) {
-                       val = oldval | oparg;
-                       ret = put_user(val, uaddr);
-               }
+               tmp |= oparg;
                break;
        case FUTEX_OP_ANDN:
-               /* *(int *)UADDR2 &= ~OPARG; */
-               ret = get_user(oldval, uaddr);
-               if (!ret) {
-                       val = oldval & ~oparg;
-                       ret = put_user(val, uaddr);
-               }
+               tmp &= ~oparg;
                break;
        case FUTEX_OP_XOR:
-               /* *(int *)UADDR2 ^= OPARG; */
-               ret = get_user(oldval, uaddr);
-               if (!ret) {
-                       val = oldval ^ oparg;
-                       ret = put_user(val, uaddr);
-               }
+               tmp ^= oparg;
                break;
        default:
                ret = -ENOSYS;
        }
 
-       _futex_spin_unlock_irqrestore(uaddr, &flags);
+       if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0))
+               ret = -EFAULT;
 
+out_pagefault_enable:
        pagefault_enable();
+       _futex_spin_unlock_irqrestore(uaddr, &flags);
 
-       if (!ret) {
+       if (ret == 0) {
                switch (cmp) {
                case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
                case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
@@ -112,12 +99,10 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
        return ret;
 }
 
-/* Non-atomic version */
 static inline int
 futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
                              u32 oldval, u32 newval)
 {
-       int ret;
        u32 val;
        unsigned long flags;
 
@@ -137,17 +122,20 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
         */
 
        _futex_spin_lock_irqsave(uaddr, &flags);
+       if (unlikely(get_user(val, uaddr) != 0)) {
+               _futex_spin_unlock_irqrestore(uaddr, &flags);
+               return -EFAULT;
+       }
 
-       ret = get_user(val, uaddr);
-
-       if (!ret && val == oldval)
-               ret = put_user(newval, uaddr);
+       if (val == oldval && unlikely(put_user(newval, uaddr) != 0)) {
+               _futex_spin_unlock_irqrestore(uaddr, &flags);
+               return -EFAULT;
+       }
 
        *uval = val;
-
        _futex_spin_unlock_irqrestore(uaddr, &flags);
 
-       return ret;
+       return 0;
 }
 
 #endif /*__KERNEL__*/
index 8121aa6db2ff21ad37510879dd82a3fe7ba7fa29..8be707e1b6c77f291a722a0f2b4b1cdb62a1f273 100644 (file)
@@ -40,7 +40,7 @@
    memory to indicate to the compiler that the assembly code reads
    or writes to items other than those listed in the input and output
    operands.  This may pessimize the code somewhat but __ldcw is
-   usually used within code blocks surrounded by memory barriors.  */
+   usually used within code blocks surrounded by memory barriers.  */
 #define __ldcw(a) ({                                           \
        unsigned __ret;                                         \
        __asm__ __volatile__(__LDCW " 0(%1),%0"                 \
index 637ce8d6f3752425371acee122b207d8e5af0b50..5e0b4e6bd99d14c94437ae409faca2ae413d9cde 100644 (file)
@@ -8,6 +8,8 @@
 #include <linux/err.h>
 #include <asm/ptrace.h>
 
+#define NR_syscalls (__NR_Linux_syscalls)
+
 static inline long syscall_get_nr(struct task_struct *tsk,
                                  struct pt_regs *regs)
 {
@@ -33,12 +35,19 @@ static inline void syscall_get_arguments(struct task_struct *tsk,
                args[1] = regs->gr[25];
        case 1:
                args[0] = regs->gr[26];
+       case 0:
                break;
        default:
                BUG();
        }
 }
 
+static inline long syscall_get_return_value(struct task_struct *task,
+                                               struct pt_regs *regs)
+{
+       return regs->gr[28];
+}
+
 static inline void syscall_set_return_value(struct task_struct *task,
                                            struct pt_regs *regs,
                                            int error, long val)
index e96e693fd58ca0df4a231a35a6f753e447dac1cb..7581330ea35be1e15498cf5cef9bbcbd3889aab9 100644 (file)
@@ -55,6 +55,7 @@ struct thread_info {
 #define TIF_SINGLESTEP         9       /* single stepping? */
 #define TIF_BLOCKSTEP          10      /* branch stepping? */
 #define TIF_SECCOMP            11      /* secure computing */
+#define TIF_SYSCALL_TRACEPOINT 12      /* syscall tracepoint instrumentation */
 
 #define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
@@ -66,12 +67,13 @@ struct thread_info {
 #define _TIF_SINGLESTEP                (1 << TIF_SINGLESTEP)
 #define _TIF_BLOCKSTEP         (1 << TIF_BLOCKSTEP)
 #define _TIF_SECCOMP           (1 << TIF_SECCOMP)
+#define _TIF_SYSCALL_TRACEPOINT        (1 << TIF_SYSCALL_TRACEPOINT)
 
 #define _TIF_USER_WORK_MASK     (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \
                                  _TIF_NEED_RESCHED)
 #define _TIF_SYSCALL_TRACE_MASK (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP |        \
                                 _TIF_BLOCKSTEP | _TIF_SYSCALL_AUDIT | \
-                                _TIF_SECCOMP)
+                                _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
 
 #ifdef CONFIG_64BIT
 # ifdef CONFIG_COMPAT
index 7955e43f3f3f27558da65b100b9c3f64ebe26b02..0f59fd9ca20526d8a27066c724ab2499965ec62c 100644 (file)
@@ -40,14 +40,10 @@ static inline long access_ok(int type, const void __user * addr,
 #define get_user __get_user
 
 #if !defined(CONFIG_64BIT)
-#define LDD_KERNEL(ptr)                BUILD_BUG()
-#define LDD_USER(ptr)          BUILD_BUG()
-#define STD_KERNEL(x, ptr)     __put_kernel_asm64(x, ptr)
+#define LDD_USER(ptr)          __get_user_asm64(ptr)
 #define STD_USER(x, ptr)       __put_user_asm64(x, ptr)
 #else
-#define LDD_KERNEL(ptr)                __get_kernel_asm("ldd", ptr)
 #define LDD_USER(ptr)          __get_user_asm("ldd", ptr)
-#define STD_KERNEL(x, ptr)     __put_kernel_asm("std", x, ptr)
 #define STD_USER(x, ptr)       __put_user_asm("std", x, ptr)
 #endif
 
@@ -80,70 +76,70 @@ struct exception_data {
        unsigned long fault_addr;
 };
 
+/*
+ * load_sr2() preloads the space register %%sr2 - based on the value of
+ * get_fs() - with either a value of 0 to access kernel space (KERNEL_DS which
+ * is 0), or with the current value of %%sr3 to access user space (USER_DS)
+ * memory. The following __get_user_asm() and __put_user_asm() functions have
+ * %%sr2 hard-coded to access the requested memory.
+ */
+#define load_sr2() \
+       __asm__(" or,=  %0,%%r0,%%r0\n\t"       \
+               " mfsp %%sr3,%0\n\t"            \
+               " mtsp %0,%%sr2\n\t"            \
+               : : "r"(get_fs()) : )
+
 #define __get_user(x, ptr)                               \
 ({                                                       \
        register long __gu_err __asm__ ("r8") = 0;       \
        register long __gu_val __asm__ ("r9") = 0;       \
                                                         \
-       if (segment_eq(get_fs(), KERNEL_DS)) {           \
-           switch (sizeof(*(ptr))) {                    \
-           case 1: __get_kernel_asm("ldb", ptr); break; \
-           case 2: __get_kernel_asm("ldh", ptr); break; \
-           case 4: __get_kernel_asm("ldw", ptr); break; \
-           case 8: LDD_KERNEL(ptr); break;              \
-           default: BUILD_BUG(); break;                 \
-           }                                            \
-       }                                                \
-       else {                                           \
-           switch (sizeof(*(ptr))) {                    \
+       load_sr2();                                      \
+       switch (sizeof(*(ptr))) {                        \
            case 1: __get_user_asm("ldb", ptr); break;   \
            case 2: __get_user_asm("ldh", ptr); break;   \
            case 4: __get_user_asm("ldw", ptr); break;   \
            case 8: LDD_USER(ptr);  break;               \
            default: BUILD_BUG(); break;                 \
-           }                                            \
        }                                                \
                                                         \
        (x) = (__force __typeof__(*(ptr))) __gu_val;     \
        __gu_err;                                        \
 })
 
-#define __get_kernel_asm(ldx, ptr)                      \
-       __asm__("\n1:\t" ldx "\t0(%2),%0\n\t"           \
+#define __get_user_asm(ldx, ptr)                        \
+       __asm__("\n1:\t" ldx "\t0(%%sr2,%2),%0\n\t"     \
                ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
                : "=r"(__gu_val), "=r"(__gu_err)        \
                : "r"(ptr), "1"(__gu_err)               \
                : "r1");
 
-#define __get_user_asm(ldx, ptr)                        \
-       __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n\t"     \
-               ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
-               : "=r"(__gu_val), "=r"(__gu_err)        \
+#if !defined(CONFIG_64BIT)
+
+#define __get_user_asm64(ptr)                          \
+       __asm__("\n1:\tldw 0(%%sr2,%2),%0"              \
+               "\n2:\tldw 4(%%sr2,%2),%R0\n\t"         \
+               ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_2)\
+               ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_get_user_skip_1)\
+               : "=r"(__gu_val), "=r"(__gu_err)        \
                : "r"(ptr), "1"(__gu_err)               \
                : "r1");
 
+#endif /* !defined(CONFIG_64BIT) */
+
+
 #define __put_user(x, ptr)                                      \
 ({                                                             \
        register long __pu_err __asm__ ("r8") = 0;              \
         __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x);      \
                                                                \
-       if (segment_eq(get_fs(), KERNEL_DS)) {                  \
-           switch (sizeof(*(ptr))) {                           \
-           case 1: __put_kernel_asm("stb", __x, ptr); break;   \
-           case 2: __put_kernel_asm("sth", __x, ptr); break;   \
-           case 4: __put_kernel_asm("stw", __x, ptr); break;   \
-           case 8: STD_KERNEL(__x, ptr); break;                \
-           default: BUILD_BUG(); break;                        \
-           }                                                   \
-       }                                                       \
-       else {                                                  \
-           switch (sizeof(*(ptr))) {                           \
+       load_sr2();                                             \
+       switch (sizeof(*(ptr))) {                               \
            case 1: __put_user_asm("stb", __x, ptr); break;     \
            case 2: __put_user_asm("sth", __x, ptr); break;     \
            case 4: __put_user_asm("stw", __x, ptr); break;     \
            case 8: STD_USER(__x, ptr); break;                  \
            default: BUILD_BUG(); break;                        \
-           }                                                   \
        }                                                       \
                                                                \
        __pu_err;                                               \
@@ -159,17 +155,9 @@ struct exception_data {
  * r8/r9 are already listed as err/val.
  */
 
-#define __put_kernel_asm(stx, x, ptr)                       \
-       __asm__ __volatile__ (                              \
-               "\n1:\t" stx "\t%2,0(%1)\n\t"               \
-               ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_1)\
-               : "=r"(__pu_err)                            \
-               : "r"(ptr), "r"(x), "0"(__pu_err)           \
-               : "r1")
-
 #define __put_user_asm(stx, x, ptr)                         \
        __asm__ __volatile__ (                              \
-               "\n1:\t" stx "\t%2,0(%%sr3,%1)\n\t"         \
+               "\n1:\t" stx "\t%2,0(%%sr2,%1)\n\t"         \
                ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_1)\
                : "=r"(__pu_err)                            \
                : "r"(ptr), "r"(x), "0"(__pu_err)           \
@@ -178,21 +166,10 @@ struct exception_data {
 
 #if !defined(CONFIG_64BIT)
 
-#define __put_kernel_asm64(__val, ptr) do {                \
-       __asm__ __volatile__ (                              \
-               "\n1:\tstw %2,0(%1)"                        \
-               "\n2:\tstw %R2,4(%1)\n\t"                   \
-               ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_2)\
-               ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_put_user_skip_1)\
-               : "=r"(__pu_err)                            \
-               : "r"(ptr), "r"(__val), "0"(__pu_err) \
-               : "r1");                                    \
-} while (0)
-
 #define __put_user_asm64(__val, ptr) do {                  \
        __asm__ __volatile__ (                              \
-               "\n1:\tstw %2,0(%%sr3,%1)"                  \
-               "\n2:\tstw %R2,4(%%sr3,%1)\n\t"             \
+               "\n1:\tstw %2,0(%%sr2,%1)"                  \
+               "\n2:\tstw %R2,4(%%sr2,%1)\n\t"             \
                ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_2)\
                ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_put_user_skip_1)\
                : "=r"(__pu_err)                            \
index 702498f7705bf29c4f08507852031ea91def5a03..0609ff117f67e56c7d12bd3c1f312d97ebc9f286 100644 (file)
@@ -59,7 +59,7 @@
 #define PDC_MODEL_GET_BOOT__OP 8       /* returns boot test options    */
 #define PDC_MODEL_SET_BOOT__OP 9       /* set boot test options        */
 
-#define PA89_INSTRUCTION_SET   0x4     /* capatibilies returned        */
+#define PA89_INSTRUCTION_SET   0x4     /* capabilities returned        */
 #define PA90_INSTRUCTION_SET   0x8
 
 #define PDC_CACHE      5               /* return/set cache (& TLB) info*/
index c4fa6c8b9ad9fa865e7766bb774d7e4bfcada3c5..02ce2eb99a7f91ef66d0cdb783b9e3d87e493102 100644 (file)
  * N.B. gdb/strace care about the size and offsets within this
  * structure. If you change things, you may break object compatibility
  * for those applications.
+ *
+ * Please do NOT use this structure for future programs, but use
+ * user_regs_struct (see below) instead.
+ *
+ * It can be accessed through PTRACE_PEEKUSR/PTRACE_POKEUSR only.
  */
 
 struct pt_regs {
@@ -33,6 +38,45 @@ struct pt_regs {
        unsigned long ipsw;     /* CR22 */
 };
 
+/**
+ * struct user_regs_struct - User general purpose registers
+ *
+ * This is the user-visible general purpose register state structure
+ * which is used to define the elf_gregset_t.
+ *
+ * It can be accessed through PTRACE_GETREGSET with NT_PRSTATUS
+ * and through PTRACE_GETREGS.
+ */
+struct user_regs_struct {
+       unsigned long gr[32];   /* PSW is in gr[0] */
+       unsigned long sr[8];
+       unsigned long iaoq[2];
+       unsigned long iasq[2];
+       unsigned long sar;      /* CR11 */
+       unsigned long iir;      /* CR19 */
+       unsigned long isr;      /* CR20 */
+       unsigned long ior;      /* CR21 */
+       unsigned long ipsw;     /* CR22 */
+       unsigned long cr0;
+       unsigned long cr24, cr25, cr26, cr27, cr28, cr29, cr30, cr31;
+       unsigned long cr8, cr9, cr12, cr13, cr10, cr15;
+       unsigned long _pad[80-64];      /* pad to ELF_NGREG (80) */
+};
+
+/**
+ * struct user_fp_struct - User floating point registers
+ *
+ * This is the user-visible floating point register state structure.
+ * It uses the same layout and size as elf_fpregset_t.
+ *
+ * It can be accessed through PTRACE_GETREGSET with NT_PRFPREG
+ * and through PTRACE_GETFPREGS.
+ */
+struct user_fp_struct {
+       __u64 fr[32];
+};
+
+
 /*
  * The numbers chosen here are somewhat arbitrary but absolutely MUST
  * not overlap with any of the number assigned in <linux/ptrace.h>.
@@ -43,5 +87,9 @@ struct pt_regs {
  */
 #define PTRACE_SINGLEBLOCK     12      /* resume execution until next branch */
 
+#define PTRACE_GETREGS         18
+#define PTRACE_SETREGS         19
+#define PTRACE_GETFPREGS       14
+#define PTRACE_SETFPREGS       15
 
 #endif /* _UAPI_PARISC_PTRACE_H */
index cc0ce92c93c78905c01ce06caaed92da41588db2..a9b9407f38f7c63a3ad9f42b0dcd7d11d1fb8d92 100644 (file)
 #define __NR_uselib              (__NR_Linux + 86)
 #define __NR_swapon              (__NR_Linux + 87)
 #define __NR_reboot              (__NR_Linux + 88)
-#define __NR_mmap2             (__NR_Linux + 89)
+#define __NR_mmap2               (__NR_Linux + 89)
 #define __NR_mmap                (__NR_Linux + 90)
 #define __NR_munmap              (__NR_Linux + 91)
 #define __NR_truncate            (__NR_Linux + 92)
 #define __NR_recv                (__NR_Linux + 98)
 #define __NR_statfs              (__NR_Linux + 99)
 #define __NR_fstatfs            (__NR_Linux + 100)
-#define __NR_stat64           (__NR_Linux + 101)
+#define __NR_stat64             (__NR_Linux + 101)
 /* #define __NR_socketcall         (__NR_Linux + 102) */
 #define __NR_syslog             (__NR_Linux + 103)
 #define __NR_setitimer          (__NR_Linux + 104)
 #define __NR_adjtimex           (__NR_Linux + 124)
 #define __NR_mprotect           (__NR_Linux + 125)
 #define __NR_sigprocmask        (__NR_Linux + 126)
-#define __NR_create_module      (__NR_Linux + 127)
+#define __NR_create_module      (__NR_Linux + 127) /* not used */
 #define __NR_init_module        (__NR_Linux + 128)
 #define __NR_delete_module      (__NR_Linux + 129)
-#define __NR_get_kernel_syms    (__NR_Linux + 130)
+#define __NR_get_kernel_syms    (__NR_Linux + 130) /* not used */
 #define __NR_quotactl           (__NR_Linux + 131)
 #define __NR_getpgid            (__NR_Linux + 132)
 #define __NR_fchdir             (__NR_Linux + 133)
 #define __NR_bdflush            (__NR_Linux + 134)
 #define __NR_sysfs              (__NR_Linux + 135)
 #define __NR_personality        (__NR_Linux + 136)
-#define __NR_afs_syscall        (__NR_Linux + 137) /* Syscall for Andrew File System */
+#define __NR_afs_syscall        (__NR_Linux + 137) /* not used */
 #define __NR_setfsuid           (__NR_Linux + 138)
 #define __NR_setfsgid           (__NR_Linux + 139)
 #define __NR__llseek            (__NR_Linux + 140)
 #define __NR_setresuid          (__NR_Linux + 164)
 #define __NR_getresuid          (__NR_Linux + 165)
 #define __NR_sigaltstack        (__NR_Linux + 166)
-#define __NR_query_module       (__NR_Linux + 167)
+#define __NR_query_module       (__NR_Linux + 167) /* not used */
 #define __NR_poll               (__NR_Linux + 168)
-#define __NR_nfsservctl         (__NR_Linux + 169)
+#define __NR_nfsservctl         (__NR_Linux + 169) /* not used */
 #define __NR_setresgid          (__NR_Linux + 170)
 #define __NR_getresgid          (__NR_Linux + 171)
 #define __NR_prctl              (__NR_Linux + 172)
 #define __NR_shmdt              (__NR_Linux + 193)
 #define __NR_shmget             (__NR_Linux + 194)
 #define __NR_shmctl             (__NR_Linux + 195)
-
-#define __NR_getpmsg           (__NR_Linux + 196) /* Somebody *wants* streams? */
-#define __NR_putpmsg           (__NR_Linux + 197)
-
+#define __NR_getpmsg            (__NR_Linux + 196) /* not used */
+#define __NR_putpmsg            (__NR_Linux + 197) /* not used */
 #define __NR_lstat64            (__NR_Linux + 198)
 #define __NR_truncate64         (__NR_Linux + 199)
 #define __NR_ftruncate64        (__NR_Linux + 200)
 #define __NR_getdents64         (__NR_Linux + 201)
 #define __NR_fcntl64            (__NR_Linux + 202)
-#define __NR_attrctl            (__NR_Linux + 203)
-#define __NR_acl_get            (__NR_Linux + 204)
-#define __NR_acl_set            (__NR_Linux + 205)
+#define __NR_attrctl            (__NR_Linux + 203) /* not used */
+#define __NR_acl_get            (__NR_Linux + 204) /* not used */
+#define __NR_acl_set            (__NR_Linux + 205) /* not used */
 #define __NR_gettid             (__NR_Linux + 206)
 #define __NR_readahead          (__NR_Linux + 207)
 #define __NR_tkill              (__NR_Linux + 208)
 #define __NR_futex              (__NR_Linux + 210)
 #define __NR_sched_setaffinity  (__NR_Linux + 211)
 #define __NR_sched_getaffinity  (__NR_Linux + 212)
-#define __NR_set_thread_area    (__NR_Linux + 213)
-#define __NR_get_thread_area    (__NR_Linux + 214)
+#define __NR_set_thread_area    (__NR_Linux + 213) /* not used */
+#define __NR_get_thread_area    (__NR_Linux + 214) /* not used */
 #define __NR_io_setup           (__NR_Linux + 215)
 #define __NR_io_destroy         (__NR_Linux + 216)
 #define __NR_io_getevents       (__NR_Linux + 217)
 #define __NR_mbind             (__NR_Linux + 260)
 #define __NR_get_mempolicy     (__NR_Linux + 261)
 #define __NR_set_mempolicy     (__NR_Linux + 262)
-#define __NR_vserver           (__NR_Linux + 263)
+#define __NR_vserver           (__NR_Linux + 263) /* not used */
 #define __NR_add_key           (__NR_Linux + 264)
 #define __NR_request_key       (__NR_Linux + 265)
 #define __NR_keyctl            (__NR_Linux + 266)
 #define __NR_kexec_load                (__NR_Linux + 300)
 #define __NR_utimensat         (__NR_Linux + 301)
 #define __NR_signalfd          (__NR_Linux + 302)
-#define __NR_timerfd           (__NR_Linux + 303)
+#define __NR_timerfd           (__NR_Linux + 303) /* not used */
 #define __NR_eventfd           (__NR_Linux + 304)
 #define __NR_fallocate         (__NR_Linux + 305)
 #define __NR_timerfd_create    (__NR_Linux + 306)
index 39127d3e70e56f2295b6e288f6642ed9908bcfbd..baa3d9d6e971f597326324220cfd3b091b2eec60 100644 (file)
         * boundary
         */
 
-       .text
+       .section .text.hot
        .align 2048
 
 ENTRY(fault_vector_20)
@@ -2019,6 +2019,7 @@ ftrace_stub:
        .procend
 ENDPROC(mcount)
 
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
        .align 8
        .globl return_to_handler
        .type  return_to_handler, @function
@@ -2040,11 +2041,17 @@ parisc_return_to_handler:
 #endif
 
        /* call ftrace_return_to_handler(0) */
+       .import ftrace_return_to_handler,code
+       load32 ftrace_return_to_handler,%ret0
+       load32 .Lftrace_ret,%r2
 #ifdef CONFIG_64BIT
        ldo -16(%sp),%ret1              /* Reference param save area */
+       bve     (%ret0)
+#else
+       bv      %r0(%ret0)
 #endif
-       BL ftrace_return_to_handler,%r2
        ldi 0,%r26
+.Lftrace_ret:
        copy %ret0,%rp
 
        /* restore original return values */
@@ -2062,6 +2069,8 @@ parisc_return_to_handler:
        .procend
 ENDPROC(return_to_handler)
 
+#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
+
 #endif /* CONFIG_FUNCTION_TRACER */
 
 #ifdef CONFIG_IRQSTACKS
index b13f9ec6f2946506c2b42ef4748b447652db81c1..a828a0adf52c0b19d14eb12219bf718c3cf37704 100644 (file)
 #include <asm/ftrace.h>
 
 
+#define __hot __attribute__ ((__section__ (".text.hot")))
+
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 /*
  * Hook the return address and push it in the stack of return addrs
  * in current thread info.
  */
-static void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
+static void __hot prepare_ftrace_return(unsigned long *parent,
+                                       unsigned long self_addr)
 {
        unsigned long old;
        struct ftrace_graph_ent trace;
@@ -53,7 +56,7 @@ static void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr
 }
 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
 
-void notrace ftrace_function_trampoline(unsigned long parent,
+void notrace __hot ftrace_function_trampoline(unsigned long parent,
                                unsigned long self_addr,
                                unsigned long org_sp_gr3)
 {
index 8fb81a3915990dc741324b560986895f5025a9d5..b5458b37fc5be2463f77a86cdddf35e4c88ab3ef 100644 (file)
@@ -4,18 +4,20 @@
  * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
  * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
  * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
- * Copyright (C) 2008 Helge Deller <deller@gmx.de>
+ * Copyright (C) 2008-2016 Helge Deller <deller@gmx.de>
  */
 
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
+#include <linux/elf.h>
 #include <linux/errno.h>
 #include <linux/ptrace.h>
 #include <linux/tracehook.h>
 #include <linux/user.h>
 #include <linux/personality.h>
+#include <linux/regset.h>
 #include <linux/security.h>
 #include <linux/seccomp.h>
 #include <linux/compat.h>
 /* PSW bits we allow the debugger to modify */
 #define USER_PSW_BITS  (PSW_N | PSW_B | PSW_V | PSW_CB)
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/syscalls.h>
+
+/*
+ * These are our native regset flavors.
+ */
+enum parisc_regset {
+       REGSET_GENERAL,
+       REGSET_FP
+};
+
 /*
  * Called by kernel/ptrace.c when detaching..
  *
@@ -114,6 +127,7 @@ void user_enable_block_step(struct task_struct *task)
 long arch_ptrace(struct task_struct *child, long request,
                 unsigned long addr, unsigned long data)
 {
+       unsigned long __user *datap = (unsigned long __user *)data;
        unsigned long tmp;
        long ret = -EIO;
 
@@ -126,7 +140,7 @@ long arch_ptrace(struct task_struct *child, long request,
                     addr >= sizeof(struct pt_regs))
                        break;
                tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
-               ret = put_user(tmp, (unsigned long __user *) data);
+               ret = put_user(tmp, datap);
                break;
 
        /* Write the word at location addr in the USER area.  This will need
@@ -165,6 +179,34 @@ long arch_ptrace(struct task_struct *child, long request,
                }
                break;
 
+       case PTRACE_GETREGS:    /* Get all gp regs from the child. */
+               return copy_regset_to_user(child,
+                                          task_user_regset_view(current),
+                                          REGSET_GENERAL,
+                                          0, sizeof(struct user_regs_struct),
+                                          datap);
+
+       case PTRACE_SETREGS:    /* Set all gp regs in the child. */
+               return copy_regset_from_user(child,
+                                            task_user_regset_view(current),
+                                            REGSET_GENERAL,
+                                            0, sizeof(struct user_regs_struct),
+                                            datap);
+
+       case PTRACE_GETFPREGS:  /* Get the child FPU state. */
+               return copy_regset_to_user(child,
+                                          task_user_regset_view(current),
+                                          REGSET_FP,
+                                          0, sizeof(struct user_fp_struct),
+                                          datap);
+
+       case PTRACE_SETFPREGS:  /* Set the child FPU state. */
+               return copy_regset_from_user(child,
+                                            task_user_regset_view(current),
+                                            REGSET_FP,
+                                            0, sizeof(struct user_fp_struct),
+                                            datap);
+
        default:
                ret = ptrace_request(child, request, addr, data);
                break;
@@ -283,6 +325,10 @@ long do_syscall_trace_enter(struct pt_regs *regs)
                regs->gr[20] = -1UL;
                goto out;
        }
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_enter(regs, regs->gr[20]);
+#endif
 
 #ifdef CONFIG_64BIT
        if (!is_compat_task())
@@ -311,6 +357,324 @@ void do_syscall_trace_exit(struct pt_regs *regs)
 
        audit_syscall_exit(regs);
 
+#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
+       if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
+               trace_sys_exit(regs, regs->gr[20]);
+#endif
+
        if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
                tracehook_report_syscall_exit(regs, stepping);
 }
+
+
+/*
+ * regset functions.
+ */
+
+static int fpr_get(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    void *kbuf, void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       __u64 *k = kbuf;
+       __u64 __user *u = ubuf;
+       __u64 reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NFPREG; --count)
+                       *k++ = regs->fr[pos++];
+       else
+               for (; count > 0 && pos < ELF_NFPREG; --count)
+                       if (__put_user(regs->fr[pos++], u++))
+                               return -EFAULT;
+
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                                       ELF_NFPREG * sizeof(reg), -1);
+}
+
+static int fpr_set(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    const void *kbuf, const void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       const __u64 *k = kbuf;
+       const __u64 __user *u = ubuf;
+       __u64 reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NFPREG; --count)
+                       regs->fr[pos++] = *k++;
+       else
+               for (; count > 0 && pos < ELF_NFPREG; --count) {
+                       if (__get_user(reg, u++))
+                               return -EFAULT;
+                       regs->fr[pos++] = reg;
+               }
+
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                                        ELF_NFPREG * sizeof(reg), -1);
+}
+
+#define RI(reg) (offsetof(struct user_regs_struct,reg) / sizeof(long))
+
+static unsigned long get_reg(struct pt_regs *regs, int num)
+{
+       switch (num) {
+       case RI(gr[0]) ... RI(gr[31]):  return regs->gr[num - RI(gr[0])];
+       case RI(sr[0]) ... RI(sr[7]):   return regs->sr[num - RI(sr[0])];
+       case RI(iasq[0]):               return regs->iasq[0];
+       case RI(iasq[1]):               return regs->iasq[1];
+       case RI(iaoq[0]):               return regs->iaoq[0];
+       case RI(iaoq[1]):               return regs->iaoq[1];
+       case RI(sar):                   return regs->sar;
+       case RI(iir):                   return regs->iir;
+       case RI(isr):                   return regs->isr;
+       case RI(ior):                   return regs->ior;
+       case RI(ipsw):                  return regs->ipsw;
+       case RI(cr27):                  return regs->cr27;
+       case RI(cr0):                   return mfctl(0);
+       case RI(cr24):                  return mfctl(24);
+       case RI(cr25):                  return mfctl(25);
+       case RI(cr26):                  return mfctl(26);
+       case RI(cr28):                  return mfctl(28);
+       case RI(cr29):                  return mfctl(29);
+       case RI(cr30):                  return mfctl(30);
+       case RI(cr31):                  return mfctl(31);
+       case RI(cr8):                   return mfctl(8);
+       case RI(cr9):                   return mfctl(9);
+       case RI(cr12):                  return mfctl(12);
+       case RI(cr13):                  return mfctl(13);
+       case RI(cr10):                  return mfctl(10);
+       case RI(cr15):                  return mfctl(15);
+       default:                        return 0;
+       }
+}
+
+static void set_reg(struct pt_regs *regs, int num, unsigned long val)
+{
+       switch (num) {
+       case RI(gr[0]): /*
+                        * PSW is in gr[0].
+                        * Allow writing to Nullify, Divide-step-correction,
+                        * and carry/borrow bits.
+                        * BEWARE, if you set N, and then single step, it won't
+                        * stop on the nullified instruction.
+                        */
+                       val &= USER_PSW_BITS;
+                       regs->gr[0] &= ~USER_PSW_BITS;
+                       regs->gr[0] |= val;
+                       return;
+       case RI(gr[1]) ... RI(gr[31]):
+                       regs->gr[num - RI(gr[0])] = val;
+                       return;
+       case RI(iaoq[0]):
+       case RI(iaoq[1]):
+                       regs->iaoq[num - RI(iaoq[0])] = val;
+                       return;
+       case RI(sar):   regs->sar = val;
+                       return;
+       default:        return;
+#if 0
+       /* do not allow to change any of the following registers (yet) */
+       case RI(sr[0]) ... RI(sr[7]):   return regs->sr[num - RI(sr[0])];
+       case RI(iasq[0]):               return regs->iasq[0];
+       case RI(iasq[1]):               return regs->iasq[1];
+       case RI(iir):                   return regs->iir;
+       case RI(isr):                   return regs->isr;
+       case RI(ior):                   return regs->ior;
+       case RI(ipsw):                  return regs->ipsw;
+       case RI(cr27):                  return regs->cr27;
+        case cr0, cr24, cr25, cr26, cr27, cr28, cr29, cr30, cr31;
+        case cr8, cr9, cr12, cr13, cr10, cr15;
+#endif
+       }
+}
+
+static int gpr_get(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    void *kbuf, void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       unsigned long *k = kbuf;
+       unsigned long __user *u = ubuf;
+       unsigned long reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       *k++ = get_reg(regs, pos++);
+       else
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       if (__put_user(get_reg(regs, pos++), u++))
+                               return -EFAULT;
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                                       ELF_NGREG * sizeof(reg), -1);
+}
+
+static int gpr_set(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    const void *kbuf, const void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       const unsigned long *k = kbuf;
+       const unsigned long __user *u = ubuf;
+       unsigned long reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       set_reg(regs, pos++, *k++);
+       else
+               for (; count > 0 && pos < ELF_NGREG; --count) {
+                       if (__get_user(reg, u++))
+                               return -EFAULT;
+                       set_reg(regs, pos++, reg);
+               }
+
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                                        ELF_NGREG * sizeof(reg), -1);
+}
+
+static const struct user_regset native_regsets[] = {
+       [REGSET_GENERAL] = {
+               .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
+               .size = sizeof(long), .align = sizeof(long),
+               .get = gpr_get, .set = gpr_set
+       },
+       [REGSET_FP] = {
+               .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
+               .size = sizeof(__u64), .align = sizeof(__u64),
+               .get = fpr_get, .set = fpr_set
+       }
+};
+
+static const struct user_regset_view user_parisc_native_view = {
+       .name = "parisc", .e_machine = ELF_ARCH, .ei_osabi = ELFOSABI_LINUX,
+       .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
+};
+
+#ifdef CONFIG_64BIT
+#include <linux/compat.h>
+
+static int gpr32_get(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    void *kbuf, void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       compat_ulong_t *k = kbuf;
+       compat_ulong_t __user *u = ubuf;
+       compat_ulong_t reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       *k++ = get_reg(regs, pos++);
+       else
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       if (__put_user((compat_ulong_t) get_reg(regs, pos++), u++))
+                               return -EFAULT;
+
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
+                                       ELF_NGREG * sizeof(reg), -1);
+}
+
+static int gpr32_set(struct task_struct *target,
+                    const struct user_regset *regset,
+                    unsigned int pos, unsigned int count,
+                    const void *kbuf, const void __user *ubuf)
+{
+       struct pt_regs *regs = task_regs(target);
+       const compat_ulong_t *k = kbuf;
+       const compat_ulong_t __user *u = ubuf;
+       compat_ulong_t reg;
+
+       pos /= sizeof(reg);
+       count /= sizeof(reg);
+
+       if (kbuf)
+               for (; count > 0 && pos < ELF_NGREG; --count)
+                       set_reg(regs, pos++, *k++);
+       else
+               for (; count > 0 && pos < ELF_NGREG; --count) {
+                       if (__get_user(reg, u++))
+                               return -EFAULT;
+                       set_reg(regs, pos++, reg);
+               }
+
+       kbuf = k;
+       ubuf = u;
+       pos *= sizeof(reg);
+       count *= sizeof(reg);
+       return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
+                                        ELF_NGREG * sizeof(reg), -1);
+}
+
+/*
+ * These are the regset flavors matching the 32bit native set.
+ */
+static const struct user_regset compat_regsets[] = {
+       [REGSET_GENERAL] = {
+               .core_note_type = NT_PRSTATUS, .n = ELF_NGREG,
+               .size = sizeof(compat_long_t), .align = sizeof(compat_long_t),
+               .get = gpr32_get, .set = gpr32_set
+       },
+       [REGSET_FP] = {
+               .core_note_type = NT_PRFPREG, .n = ELF_NFPREG,
+               .size = sizeof(__u64), .align = sizeof(__u64),
+               .get = fpr_get, .set = fpr_set
+       }
+};
+
+static const struct user_regset_view user_parisc_compat_view = {
+       .name = "parisc", .e_machine = EM_PARISC, .ei_osabi = ELFOSABI_LINUX,
+       .regsets = compat_regsets, .n = ARRAY_SIZE(compat_regsets)
+};
+#endif /* CONFIG_64BIT */
+
+const struct user_regset_view *task_user_regset_view(struct task_struct *task)
+{
+       BUILD_BUG_ON(sizeof(struct user_regs_struct)/sizeof(long) != ELF_NGREG);
+       BUILD_BUG_ON(sizeof(struct user_fp_struct)/sizeof(__u64) != ELF_NFPREG);
+#ifdef CONFIG_64BIT
+       if (is_compat_task())
+               return &user_parisc_compat_view;
+#endif
+       return &user_parisc_native_view;
+}
index 57b4836b7ecd898e10197aa0d473ea6107b9fb42..d03422e5f188368f8df5283cedfd4e32845e64df 100644 (file)
@@ -912,6 +912,7 @@ END(lws_table)
 
        .align 8
 ENTRY(sys_call_table)
+       .export sys_call_table,data
 #include "syscall_table.S"
 END(sys_call_table)
 
index 400acac0a304d12b235e05773d9c9f53a87f55b2..58dd6801f5bece511f16603b7db47906637582b0 100644 (file)
 
 static unsigned long clocktick __read_mostly;  /* timer cycles per tick */
 
+#ifndef CONFIG_64BIT
+/*
+ * The processor-internal cycle counter (Control Register 16) is used as time
+ * source for the sched_clock() function.  This register is 64bit wide on a
+ * 64-bit kernel and 32bit on a 32-bit kernel. Since sched_clock() always
+ * requires a 64bit counter we emulate on the 32-bit kernel the higher 32bits
+ * with a per-cpu variable which we increase every time the counter
+ * wraps-around (which happens every ~4 secounds).
+ */
+static DEFINE_PER_CPU(unsigned long, cr16_high_32_bits);
+#endif
+
 /*
  * We keep time on PA-RISC Linux by using the Interval Timer which is
  * a pair of registers; one is read-only and one is write-only; both
@@ -108,6 +120,12 @@ irqreturn_t __irq_entry timer_interrupt(int irq, void *dev_id)
         */
        mtctl(next_tick, 16);
 
+#if !defined(CONFIG_64BIT)
+       /* check for overflow on a 32bit kernel (every ~4 seconds). */
+       if (unlikely(next_tick < now))
+               this_cpu_inc(cr16_high_32_bits);
+#endif
+
        /* Skip one clocktick on purpose if we missed next_tick.
         * The new CR16 must be "later" than current CR16 otherwise
         * itimer would not fire until CR16 wrapped - e.g 4 seconds
@@ -219,6 +237,12 @@ void __init start_cpu_itimer(void)
        unsigned int cpu = smp_processor_id();
        unsigned long next_tick = mfctl(16) + clocktick;
 
+#if defined(CONFIG_HAVE_UNSTABLE_SCHED_CLOCK) && defined(CONFIG_64BIT)
+       /* With multiple 64bit CPUs online, the cr16's are not syncronized. */
+       if (cpu != 0)
+               clear_sched_clock_stable();
+#endif
+
        mtctl(next_tick, 16);           /* kick off Interval Timer (CR16) */
 
        per_cpu(cpu_data, cpu).it_value = next_tick;
@@ -246,15 +270,52 @@ void read_persistent_clock(struct timespec *ts)
        }
 }
 
+
+/*
+ * sched_clock() framework
+ */
+
+static u32 cyc2ns_mul __read_mostly;
+static u32 cyc2ns_shift __read_mostly;
+
+u64 sched_clock(void)
+{
+       u64 now;
+
+       /* Get current cycle counter (Control Register 16). */
+#ifdef CONFIG_64BIT
+       now = mfctl(16);
+#else
+       now = mfctl(16) + (((u64) this_cpu_read(cr16_high_32_bits)) << 32);
+#endif
+
+       /* return the value in ns (cycles_2_ns) */
+       return mul_u64_u32_shr(now, cyc2ns_mul, cyc2ns_shift);
+}
+
+
+/*
+ * timer interrupt and sched_clock() initialization
+ */
+
 void __init time_init(void)
 {
        unsigned long current_cr16_khz;
 
+       current_cr16_khz = PAGE0->mem_10msec/10;  /* kHz */
        clocktick = (100 * PAGE0->mem_10msec) / HZ;
 
+       /* calculate mult/shift values for cr16 */
+       clocks_calc_mult_shift(&cyc2ns_mul, &cyc2ns_shift, current_cr16_khz,
+                               NSEC_PER_MSEC, 0);
+
+#if defined(CONFIG_HAVE_UNSTABLE_SCHED_CLOCK) && defined(CONFIG_64BIT)
+       /* At bootup only one 64bit CPU is online and cr16 is "stable" */
+       set_sched_clock_stable();
+#endif
+
        start_cpu_itimer();     /* get CPU 0 started */
 
        /* register at clocksource framework */
-       current_cr16_khz = PAGE0->mem_10msec/10;  /* kHz */
        clocksource_register_khz(&clocksource_cr16, current_cr16_khz);
 }
index 187118841af193adf92025351bad2d29b253c38c..8e45b0a97abf67bfc7621c5a964502890038cf2e 100644 (file)
@@ -55,11 +55,10 @@ unsigned long __xchg8(char x, char *ptr)
 }
 
 
-#ifdef CONFIG_64BIT
-unsigned long __cmpxchg_u64(volatile unsigned long *ptr, unsigned long old, unsigned long new)
+u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new)
 {
        unsigned long flags;
-       unsigned long prev;
+       u64 prev;
 
        _atomic_spin_lock_irqsave(ptr, flags);
        if ((prev = *ptr) == old)
@@ -67,7 +66,6 @@ unsigned long __cmpxchg_u64(volatile unsigned long *ptr, unsigned long old, unsi
        _atomic_spin_unlock_irqrestore(ptr, flags);
        return prev;
 }
-#endif
 
 unsigned long __cmpxchg_u32(volatile unsigned int *ptr, unsigned int old, unsigned int new)
 {
index 673b73e8420d0fd5742264ad6c2214c43a78ef9a..18df1237c93cabb2356ca95cbb2050697f79b275 100644 (file)
@@ -184,7 +184,7 @@ static void parisc_linux_get_fpu_type(u_int fpregs[])
 
 /*
  * this routine will decode the excepting floating point instruction and
- * call the approiate emulation routine.
+ * call the appropriate emulation routine.
  * It is called by decode_fpu with the following parameters:
  * fpudispatch(current_ir, unimplemented_code, 0, &Fpu_register)
  * where current_ir is the instruction to be emulated,
index 9cb4260a5f3e3ea232fd1a328bac9f7e5ed854b3..d4008c339e8936da10255a677aa6bb1986760786 100644 (file)
@@ -1,5 +1,6 @@
 #define __ARCH_HAVE_MMU
 
+#define __ARCH_WANT_RENAMEAT
 #define __ARCH_WANT_SYSCALL_NO_AT
 #define __ARCH_WANT_SYSCALL_NO_FLAGS
 #define __ARCH_WANT_SYSCALL_OFF_T
index 3866397aaf5ae7c2a939911ed84a5130c50c9962..24e9187e85a86cd17911e64f76922e1034013919 100644 (file)
@@ -12,6 +12,7 @@
  *   more details.
  */
 
+#define __ARCH_WANT_RENAMEAT
 #if !defined(__LP64__) || defined(__SYSCALL_COMPAT)
 /* Use the flavor of this syscall that matches the 32-bit API better. */
 #define __ARCH_WANT_SYNC_FILE_RANGE2
index d4cc4559d8485f23838417c6f51208b4925082d3..1f63c476528e6ce58b590b16346a3d9961968f87 100644 (file)
@@ -10,6 +10,8 @@
  * published by the Free Software Foundation.
  */
 
+#define __ARCH_WANT_RENAMEAT
+
 /* Use the standard ABI for syscalls. */
 #include <asm-generic/unistd.h>
 #define __ARCH_WANT_SYS_CLONE
index 4bd08b0fc8ea1b1c9badf0128920858ef8d41336..99ddab79215e2d3858ccbd2c4178cdffb08b7382 100644 (file)
@@ -491,8 +491,11 @@ int __init pci_xen_initial_domain(void)
 #endif
        __acpi_register_gsi = acpi_register_gsi_xen;
        __acpi_unregister_gsi = NULL;
-       /* Pre-allocate legacy irqs */
-       for (irq = 0; irq < nr_legacy_irqs(); irq++) {
+       /*
+        * Pre-allocate the legacy IRQs.  Use NR_LEGACY_IRQS here
+        * because we don't have a PIC and thus nr_legacy_irqs() is zero.
+        */
+       for (irq = 0; irq < NR_IRQS_LEGACY; irq++) {
                int trigger, polarity;
 
                if (acpi_get_override_irq(irq, &trigger, &polarity) == -1)
index 7ab29518a3b9dc0c7f26bfa0d15727b378de324a..e345891450c3fcc2873a31d352b80afaacf7b74c 100644 (file)
@@ -393,6 +393,9 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
        unsigned long i = 0;
        unsigned long n = end_pfn - start_pfn;
 
+       if (remap_pfn == 0)
+               remap_pfn = nr_pages;
+
        while (i < n) {
                unsigned long cur_pfn = start_pfn + i;
                unsigned long left = n - i;
@@ -438,17 +441,29 @@ static unsigned long __init xen_set_identity_and_remap_chunk(
        return remap_pfn;
 }
 
-static void __init xen_set_identity_and_remap(unsigned long nr_pages)
+static unsigned long __init xen_count_remap_pages(
+       unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages,
+       unsigned long remap_pages)
+{
+       if (start_pfn >= nr_pages)
+               return remap_pages;
+
+       return remap_pages + min(end_pfn, nr_pages) - start_pfn;
+}
+
+static unsigned long __init xen_foreach_remap_area(unsigned long nr_pages,
+       unsigned long (*func)(unsigned long start_pfn, unsigned long end_pfn,
+                             unsigned long nr_pages, unsigned long last_val))
 {
        phys_addr_t start = 0;
-       unsigned long last_pfn = nr_pages;
+       unsigned long ret_val = 0;
        const struct e820entry *entry = xen_e820_map;
        int i;
 
        /*
         * Combine non-RAM regions and gaps until a RAM region (or the
-        * end of the map) is reached, then set the 1:1 map and
-        * remap the memory in those non-RAM regions.
+        * end of the map) is reached, then call the provided function
+        * to perform its duty on the non-RAM region.
         *
         * The combined non-RAM regions are rounded to a whole number
         * of pages so any partial pages are accessible via the 1:1
@@ -466,14 +481,13 @@ static void __init xen_set_identity_and_remap(unsigned long nr_pages)
                                end_pfn = PFN_UP(entry->addr);
 
                        if (start_pfn < end_pfn)
-                               last_pfn = xen_set_identity_and_remap_chunk(
-                                               start_pfn, end_pfn, nr_pages,
-                                               last_pfn);
+                               ret_val = func(start_pfn, end_pfn, nr_pages,
+                                              ret_val);
                        start = end;
                }
        }
 
-       pr_info("Released %ld page(s)\n", xen_released_pages);
+       return ret_val;
 }
 
 /*
@@ -596,35 +610,6 @@ static void __init xen_ignore_unusable(void)
        }
 }
 
-static unsigned long __init xen_count_remap_pages(unsigned long max_pfn)
-{
-       unsigned long extra = 0;
-       unsigned long start_pfn, end_pfn;
-       const struct e820entry *entry = xen_e820_map;
-       int i;
-
-       end_pfn = 0;
-       for (i = 0; i < xen_e820_map_entries; i++, entry++) {
-               start_pfn = PFN_DOWN(entry->addr);
-               /* Adjacent regions on non-page boundaries handling! */
-               end_pfn = min(end_pfn, start_pfn);
-
-               if (start_pfn >= max_pfn)
-                       return extra + max_pfn - end_pfn;
-
-               /* Add any holes in map to result. */
-               extra += start_pfn - end_pfn;
-
-               end_pfn = PFN_UP(entry->addr + entry->size);
-               end_pfn = min(end_pfn, max_pfn);
-
-               if (entry->type != E820_RAM)
-                       extra += end_pfn - start_pfn;
-       }
-
-       return extra;
-}
-
 bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size)
 {
        struct e820entry *entry;
@@ -804,7 +789,7 @@ char * __init xen_memory_setup(void)
        max_pages = xen_get_max_pages();
 
        /* How many extra pages do we need due to remapping? */
-       max_pages += xen_count_remap_pages(max_pfn);
+       max_pages += xen_foreach_remap_area(max_pfn, xen_count_remap_pages);
 
        if (max_pages > max_pfn)
                extra_pages += max_pages - max_pfn;
@@ -922,7 +907,9 @@ char * __init xen_memory_setup(void)
         * Set identity map on non-RAM pages and prepare remapping the
         * underlying RAM.
         */
-       xen_set_identity_and_remap(max_pfn);
+       xen_foreach_remap_area(max_pfn, xen_set_identity_and_remap_chunk);
+
+       pr_info("Released %ld page(s)\n", xen_released_pages);
 
        return "Xen";
 }
index a0a4e554c6f195ffe2abd37d712e12e9ee8d9e85..6deba5bc7e3490546031ce0a11e90e9f9a917884 100644 (file)
@@ -290,11 +290,11 @@ static int xen_vcpuop_set_next_event(unsigned long delta,
        WARN_ON(!clockevent_state_oneshot(evt));
 
        single.timeout_abs_ns = get_abs_timeout(delta);
-       single.flags = VCPU_SSHOTTMR_future;
+       /* Get an event anyway, even if the timeout is already expired */
+       single.flags = 0;
 
        ret = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &single);
-
-       BUG_ON(ret != 0 && ret != -ETIME);
+       BUG_ON(ret != 0);
 
        return ret;
 }
index 04d706ca5f439be4576c8f78afb4b10a66b5dd3e..35b13a08ca3e6a4f21cd602ecf3d9ab9c328f9f0 100644 (file)
@@ -146,7 +146,6 @@ int bcma_sflash_init(struct bcma_drv_cc *cc)
                return -ENOTSUPP;
        }
 
-       sflash->window = BCMA_SOC_FLASH2;
        sflash->blocksize = e->blocksize;
        sflash->numblocks = e->numblocks;
        sflash->size = sflash->blocksize * sflash->numblocks;
index c61a284133e023df5da91d2ecafe3e15199941e1..81ddb17575a99dc9c77fbfecb595d77be054befa 100644 (file)
@@ -51,6 +51,7 @@ config TI_EMIF
 
 config OMAP_GPMC
        bool
+       select GPIOLIB
        help
          This driver is for the General Purpose Memory Controller (GPMC)
          present on Texas Instruments SoCs (e.g. OMAP2+). GPMC allows
index 2a691da8c1c7c0441c08d97a8d1e711099a32299..904b4af5f1424ef978d317ba052f3a268d111818 100644 (file)
@@ -59,11 +59,11 @@ int fsl_ifc_find(phys_addr_t addr_base)
 {
        int i = 0;
 
-       if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
+       if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->gregs)
                return -ENODEV;
 
        for (i = 0; i < fsl_ifc_ctrl_dev->banks; i++) {
-               u32 cspr = ifc_in32(&fsl_ifc_ctrl_dev->regs->cspr_cs[i].cspr);
+               u32 cspr = ifc_in32(&fsl_ifc_ctrl_dev->gregs->cspr_cs[i].cspr);
                if (cspr & CSPR_V && (cspr & CSPR_BA) ==
                                convert_ifc_address(addr_base))
                        return i;
@@ -75,7 +75,7 @@ EXPORT_SYMBOL(fsl_ifc_find);
 
 static int fsl_ifc_ctrl_init(struct fsl_ifc_ctrl *ctrl)
 {
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_global __iomem *ifc = ctrl->gregs;
 
        /*
         * Clear all the common status and event registers
@@ -104,7 +104,7 @@ static int fsl_ifc_ctrl_remove(struct platform_device *dev)
        irq_dispose_mapping(ctrl->nand_irq);
        irq_dispose_mapping(ctrl->irq);
 
-       iounmap(ctrl->regs);
+       iounmap(ctrl->gregs);
 
        dev_set_drvdata(&dev->dev, NULL);
        kfree(ctrl);
@@ -122,7 +122,7 @@ static DEFINE_SPINLOCK(nand_irq_lock);
 
 static u32 check_nand_stat(struct fsl_ifc_ctrl *ctrl)
 {
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
        unsigned long flags;
        u32 stat;
 
@@ -157,7 +157,7 @@ static irqreturn_t fsl_ifc_nand_irq(int irqno, void *data)
 static irqreturn_t fsl_ifc_ctrl_irq(int irqno, void *data)
 {
        struct fsl_ifc_ctrl *ctrl = data;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_global __iomem *ifc = ctrl->gregs;
        u32 err_axiid, err_srcid, status, cs_err, err_addr;
        irqreturn_t ret = IRQ_NONE;
 
@@ -215,6 +215,7 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
 {
        int ret = 0;
        int version, banks;
+       void __iomem *addr;
 
        dev_info(&dev->dev, "Freescale Integrated Flash Controller\n");
 
@@ -225,22 +226,13 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
        dev_set_drvdata(&dev->dev, fsl_ifc_ctrl_dev);
 
        /* IOMAP the entire IFC region */
-       fsl_ifc_ctrl_dev->regs = of_iomap(dev->dev.of_node, 0);
-       if (!fsl_ifc_ctrl_dev->regs) {
+       fsl_ifc_ctrl_dev->gregs = of_iomap(dev->dev.of_node, 0);
+       if (!fsl_ifc_ctrl_dev->gregs) {
                dev_err(&dev->dev, "failed to get memory region\n");
                ret = -ENODEV;
                goto err;
        }
 
-       version = ifc_in32(&fsl_ifc_ctrl_dev->regs->ifc_rev) &
-                       FSL_IFC_VERSION_MASK;
-       banks = (version == FSL_IFC_VERSION_1_0_0) ? 4 : 8;
-       dev_info(&dev->dev, "IFC version %d.%d, %d banks\n",
-               version >> 24, (version >> 16) & 0xf, banks);
-
-       fsl_ifc_ctrl_dev->version = version;
-       fsl_ifc_ctrl_dev->banks = banks;
-
        if (of_property_read_bool(dev->dev.of_node, "little-endian")) {
                fsl_ifc_ctrl_dev->little_endian = true;
                dev_dbg(&dev->dev, "IFC REGISTERS are LITTLE endian\n");
@@ -249,8 +241,9 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
                dev_dbg(&dev->dev, "IFC REGISTERS are BIG endian\n");
        }
 
-       version = ioread32be(&fsl_ifc_ctrl_dev->regs->ifc_rev) &
+       version = ifc_in32(&fsl_ifc_ctrl_dev->gregs->ifc_rev) &
                        FSL_IFC_VERSION_MASK;
+
        banks = (version == FSL_IFC_VERSION_1_0_0) ? 4 : 8;
        dev_info(&dev->dev, "IFC version %d.%d, %d banks\n",
                version >> 24, (version >> 16) & 0xf, banks);
@@ -258,6 +251,13 @@ static int fsl_ifc_ctrl_probe(struct platform_device *dev)
        fsl_ifc_ctrl_dev->version = version;
        fsl_ifc_ctrl_dev->banks = banks;
 
+       addr = fsl_ifc_ctrl_dev->gregs;
+       if (version >= FSL_IFC_VERSION_2_0_0)
+               addr += PGOFFSET_64K;
+       else
+               addr += PGOFFSET_4K;
+       fsl_ifc_ctrl_dev->rregs = addr;
+
        /* get the Controller level irq */
        fsl_ifc_ctrl_dev->irq = irq_of_parse_and_map(dev->dev.of_node, 0);
        if (fsl_ifc_ctrl_dev->irq == 0) {
index 21825ddce4a3c83f70cd0c44beccee91210b37ee..af4884ba6b7cafa6fe5b2eeda1bee00e59fdd2a3 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/gpio/driver.h>
 #include <linux/interrupt.h>
+#include <linux/irqdomain.h>
 #include <linux/platform_device.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/of_mtd.h>
 #include <linux/of_device.h>
 #include <linux/of_platform.h>
 #include <linux/omap-gpmc.h>
-#include <linux/mtd/nand.h>
 #include <linux/pm_runtime.h>
 
 #include <linux/platform_data/mtd-nand-omap2.h>
@@ -81,6 +81,8 @@
 
 #define GPMC_CONFIG_LIMITEDADDRESS             BIT(1)
 
+#define GPMC_STATUS_EMPTYWRITEBUFFERSTATUS     BIT(0)
+
 #define        GPMC_CONFIG2_CSEXTRADELAY               BIT(7)
 #define        GPMC_CONFIG3_ADVEXTRADELAY              BIT(7)
 #define        GPMC_CONFIG4_OEEXTRADELAY               BIT(7)
 #define GPMC_CS_SIZE           0x30
 #define        GPMC_BCH_SIZE           0x10
 
+/*
+ * The first 1MB of GPMC address space is typically mapped to
+ * the internal ROM. Never allocate the first page, to
+ * facilitate bug detection; even if we didn't boot from ROM.
+ * As GPMC minimum partition size is 16MB we can only start from
+ * there.
+ */
+#define GPMC_MEM_START         0x1000000
 #define GPMC_MEM_END           0x3FFFFFFF
 
 #define GPMC_CHUNK_SHIFT       24              /* 16 MB */
 #define GPMC_CONFIG_RDY_BSY    0x00000001
 #define GPMC_CONFIG_DEV_SIZE   0x00000002
 #define GPMC_CONFIG_DEV_TYPE   0x00000003
-#define GPMC_SET_IRQ_STATUS    0x00000004
 
 #define GPMC_CONFIG1_WRAPBURST_SUPP     (1 << 31)
 #define GPMC_CONFIG1_READMULTIPLE_SUPP  (1 << 30)
 #define GPMC_CONFIG_WRITEPROTECT       0x00000010
 #define WR_RD_PIN_MONITORING           0x00600000
 
-#define GPMC_ENABLE_IRQ                0x0000000d
-
 /* ECC commands */
 #define GPMC_ECC_READ          0 /* Reset Hardware ECC for read */
 #define GPMC_ECC_WRITE         1 /* Reset Hardware ECC for write */
 #define GPMC_ECC_READSYN       2 /* Reset before syndrom is read back */
 
-/* XXX: Only NAND irq has been considered,currently these are the only ones used
- */
-#define        GPMC_NR_IRQ             2
+#define        GPMC_NR_NAND_IRQS       2 /* number of NAND specific IRQs */
 
 enum gpmc_clk_domain {
        GPMC_CD_FCLK,
@@ -199,11 +204,6 @@ struct gpmc_cs_data {
        struct resource mem;
 };
 
-struct gpmc_client_irq {
-       unsigned                irq;
-       u32                     bitmask;
-};
-
 /* Structure to save gpmc cs context */
 struct gpmc_cs_config {
        u32 config1;
@@ -231,9 +231,15 @@ struct omap3_gpmc_regs {
        struct gpmc_cs_config cs_context[GPMC_CS_NUM];
 };
 
-static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
-static struct irq_chip gpmc_irq_chip;
-static int gpmc_irq_start;
+struct gpmc_device {
+       struct device *dev;
+       int irq;
+       struct irq_chip irq_chip;
+       struct gpio_chip gpio_chip;
+       int nirqs;
+};
+
+static struct irq_domain *gpmc_irq_domain;
 
 static struct resource gpmc_mem_root;
 static struct gpmc_cs_data gpmc_cs[GPMC_CS_NUM];
@@ -241,8 +247,6 @@ static DEFINE_SPINLOCK(gpmc_mem_lock);
 /* Define chip-selects as reserved by default until probe completes */
 static unsigned int gpmc_cs_num = GPMC_CS_NUM;
 static unsigned int gpmc_nr_waitpins;
-static struct device *gpmc_dev;
-static int gpmc_irq;
 static resource_size_t phys_base, mem_size;
 static unsigned gpmc_capability;
 static void __iomem *gpmc_base;
@@ -1054,14 +1058,6 @@ int gpmc_configure(int cmd, int wval)
        u32 regval;
 
        switch (cmd) {
-       case GPMC_ENABLE_IRQ:
-               gpmc_write_reg(GPMC_IRQENABLE, wval);
-               break;
-
-       case GPMC_SET_IRQ_STATUS:
-               gpmc_write_reg(GPMC_IRQSTATUS, wval);
-               break;
-
        case GPMC_CONFIG_WP:
                regval = gpmc_read_reg(GPMC_CONFIG);
                if (wval)
@@ -1084,7 +1080,7 @@ void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
 {
        int i;
 
-       reg->gpmc_status = gpmc_base + GPMC_STATUS;
+       reg->gpmc_status = NULL;        /* deprecated */
        reg->gpmc_nand_command = gpmc_base + GPMC_CS0_OFFSET +
                                GPMC_CS_NAND_COMMAND + GPMC_CS_SIZE * cs;
        reg->gpmc_nand_address = gpmc_base + GPMC_CS0_OFFSET +
@@ -1118,87 +1114,201 @@ void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
        }
 }
 
-int gpmc_get_client_irq(unsigned irq_config)
+static bool gpmc_nand_writebuffer_empty(void)
 {
-       int i;
+       if (gpmc_read_reg(GPMC_STATUS) & GPMC_STATUS_EMPTYWRITEBUFFERSTATUS)
+               return true;
 
-       if (hweight32(irq_config) > 1)
+       return false;
+}
+
+static struct gpmc_nand_ops nand_ops = {
+       .nand_writebuffer_empty = gpmc_nand_writebuffer_empty,
+};
+
+/**
+ * gpmc_omap_get_nand_ops - Get the GPMC NAND interface
+ * @regs: the GPMC NAND register map exclusive for NAND use.
+ * @cs: GPMC chip select number on which the NAND sits. The
+ *      register map returned will be specific to this chip select.
+ *
+ * Returns NULL on error e.g. invalid cs.
+ */
+struct gpmc_nand_ops *gpmc_omap_get_nand_ops(struct gpmc_nand_regs *reg, int cs)
+{
+       if (cs >= gpmc_cs_num)
+               return NULL;
+
+       gpmc_update_nand_reg(reg, cs);
+
+       return &nand_ops;
+}
+EXPORT_SYMBOL_GPL(gpmc_omap_get_nand_ops);
+
+int gpmc_get_client_irq(unsigned irq_config)
+{
+       if (!gpmc_irq_domain) {
+               pr_warn("%s called before GPMC IRQ domain available\n",
+                       __func__);
                return 0;
+       }
 
-       for (i = 0; i < GPMC_NR_IRQ; i++)
-               if (gpmc_client_irq[i].bitmask & irq_config)
-                       return gpmc_client_irq[i].irq;
+       /* we restrict this to NAND IRQs only */
+       if (irq_config >= GPMC_NR_NAND_IRQS)
+               return 0;
 
-       return 0;
+       return irq_create_mapping(gpmc_irq_domain, irq_config);
 }
 
-static int gpmc_irq_endis(unsigned irq, bool endis)
+static int gpmc_irq_endis(unsigned long hwirq, bool endis)
 {
-       int i;
        u32 regval;
 
-       for (i = 0; i < GPMC_NR_IRQ; i++)
-               if (irq == gpmc_client_irq[i].irq) {
-                       regval = gpmc_read_reg(GPMC_IRQENABLE);
-                       if (endis)
-                               regval |= gpmc_client_irq[i].bitmask;
-                       else
-                               regval &= ~gpmc_client_irq[i].bitmask;
-                       gpmc_write_reg(GPMC_IRQENABLE, regval);
-                       break;
-               }
+       /* bits GPMC_NR_NAND_IRQS to 8 are reserved */
+       if (hwirq >= GPMC_NR_NAND_IRQS)
+               hwirq += 8 - GPMC_NR_NAND_IRQS;
+
+       regval = gpmc_read_reg(GPMC_IRQENABLE);
+       if (endis)
+               regval |= BIT(hwirq);
+       else
+               regval &= ~BIT(hwirq);
+       gpmc_write_reg(GPMC_IRQENABLE, regval);
 
        return 0;
 }
 
 static void gpmc_irq_disable(struct irq_data *p)
 {
-       gpmc_irq_endis(p->irq, false);
+       gpmc_irq_endis(p->hwirq, false);
 }
 
 static void gpmc_irq_enable(struct irq_data *p)
 {
-       gpmc_irq_endis(p->irq, true);
+       gpmc_irq_endis(p->hwirq, true);
 }
 
-static void gpmc_irq_noop(struct irq_data *data) { }
+static void gpmc_irq_mask(struct irq_data *d)
+{
+       gpmc_irq_endis(d->hwirq, false);
+}
 
-static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
+static void gpmc_irq_unmask(struct irq_data *d)
+{
+       gpmc_irq_endis(d->hwirq, true);
+}
 
-static int gpmc_setup_irq(void)
+static void gpmc_irq_edge_config(unsigned long hwirq, bool rising_edge)
 {
-       int i;
        u32 regval;
 
-       if (!gpmc_irq)
+       /* NAND IRQs polarity is not configurable */
+       if (hwirq < GPMC_NR_NAND_IRQS)
+               return;
+
+       /* WAITPIN starts at BIT 8 */
+       hwirq += 8 - GPMC_NR_NAND_IRQS;
+
+       regval = gpmc_read_reg(GPMC_CONFIG);
+       if (rising_edge)
+               regval &= ~BIT(hwirq);
+       else
+               regval |= BIT(hwirq);
+
+       gpmc_write_reg(GPMC_CONFIG, regval);
+}
+
+static void gpmc_irq_ack(struct irq_data *d)
+{
+       unsigned int hwirq = d->hwirq;
+
+       /* skip reserved bits */
+       if (hwirq >= GPMC_NR_NAND_IRQS)
+               hwirq += 8 - GPMC_NR_NAND_IRQS;
+
+       /* Setting bit to 1 clears (or Acks) the interrupt */
+       gpmc_write_reg(GPMC_IRQSTATUS, BIT(hwirq));
+}
+
+static int gpmc_irq_set_type(struct irq_data *d, unsigned int trigger)
+{
+       /* can't set type for NAND IRQs */
+       if (d->hwirq < GPMC_NR_NAND_IRQS)
                return -EINVAL;
 
-       gpmc_irq_start = irq_alloc_descs(-1, 0, GPMC_NR_IRQ, 0);
-       if (gpmc_irq_start < 0) {
-               pr_err("irq_alloc_descs failed\n");
-               return gpmc_irq_start;
+       /* We can support either rising or falling edge at a time */
+       if (trigger == IRQ_TYPE_EDGE_FALLING)
+               gpmc_irq_edge_config(d->hwirq, false);
+       else if (trigger == IRQ_TYPE_EDGE_RISING)
+               gpmc_irq_edge_config(d->hwirq, true);
+       else
+               return -EINVAL;
+
+       return 0;
+}
+
+static int gpmc_irq_map(struct irq_domain *d, unsigned int virq,
+                       irq_hw_number_t hw)
+{
+       struct gpmc_device *gpmc = d->host_data;
+
+       irq_set_chip_data(virq, gpmc);
+       if (hw < GPMC_NR_NAND_IRQS) {
+               irq_modify_status(virq, IRQ_NOREQUEST, IRQ_NOAUTOEN);
+               irq_set_chip_and_handler(virq, &gpmc->irq_chip,
+                                        handle_simple_irq);
+       } else {
+               irq_set_chip_and_handler(virq, &gpmc->irq_chip,
+                                        handle_edge_irq);
        }
 
-       gpmc_irq_chip.name = "gpmc";
-       gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
-       gpmc_irq_chip.irq_enable = gpmc_irq_enable;
-       gpmc_irq_chip.irq_disable = gpmc_irq_disable;
-       gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
-       gpmc_irq_chip.irq_ack = gpmc_irq_noop;
-       gpmc_irq_chip.irq_mask = gpmc_irq_noop;
-       gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
-
-       gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
-       gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
-
-       for (i = 0; i < GPMC_NR_IRQ; i++) {
-               gpmc_client_irq[i].irq = gpmc_irq_start + i;
-               irq_set_chip_and_handler(gpmc_client_irq[i].irq,
-                                       &gpmc_irq_chip, handle_simple_irq);
-               irq_modify_status(gpmc_client_irq[i].irq, IRQ_NOREQUEST,
-                                 IRQ_NOAUTOEN);
+       return 0;
+}
+
+static const struct irq_domain_ops gpmc_irq_domain_ops = {
+       .map    = gpmc_irq_map,
+       .xlate  = irq_domain_xlate_twocell,
+};
+
+static irqreturn_t gpmc_handle_irq(int irq, void *data)
+{
+       int hwirq, virq;
+       u32 regval, regvalx;
+       struct gpmc_device *gpmc = data;
+
+       regval = gpmc_read_reg(GPMC_IRQSTATUS);
+       regvalx = regval;
+
+       if (!regval)
+               return IRQ_NONE;
+
+       for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++) {
+               /* skip reserved status bits */
+               if (hwirq == GPMC_NR_NAND_IRQS)
+                       regvalx >>= 8 - GPMC_NR_NAND_IRQS;
+
+               if (regvalx & BIT(hwirq)) {
+                       virq = irq_find_mapping(gpmc_irq_domain, hwirq);
+                       if (!virq) {
+                               dev_warn(gpmc->dev,
+                                        "spurious irq detected hwirq %d, virq %d\n",
+                                        hwirq, virq);
+                       }
+
+                       generic_handle_irq(virq);
+               }
        }
 
+       gpmc_write_reg(GPMC_IRQSTATUS, regval);
+
+       return IRQ_HANDLED;
+}
+
+static int gpmc_setup_irq(struct gpmc_device *gpmc)
+{
+       u32 regval;
+       int rc;
+
        /* Disable interrupts */
        gpmc_write_reg(GPMC_IRQENABLE, 0);
 
@@ -1206,22 +1316,45 @@ static int gpmc_setup_irq(void)
        regval = gpmc_read_reg(GPMC_IRQSTATUS);
        gpmc_write_reg(GPMC_IRQSTATUS, regval);
 
-       return request_irq(gpmc_irq, gpmc_handle_irq, 0, "gpmc", NULL);
+       gpmc->irq_chip.name = "gpmc";
+       gpmc->irq_chip.irq_enable = gpmc_irq_enable;
+       gpmc->irq_chip.irq_disable = gpmc_irq_disable;
+       gpmc->irq_chip.irq_ack = gpmc_irq_ack;
+       gpmc->irq_chip.irq_mask = gpmc_irq_mask;
+       gpmc->irq_chip.irq_unmask = gpmc_irq_unmask;
+       gpmc->irq_chip.irq_set_type = gpmc_irq_set_type;
+
+       gpmc_irq_domain = irq_domain_add_linear(gpmc->dev->of_node,
+                                               gpmc->nirqs,
+                                               &gpmc_irq_domain_ops,
+                                               gpmc);
+       if (!gpmc_irq_domain) {
+               dev_err(gpmc->dev, "IRQ domain add failed\n");
+               return -ENODEV;
+       }
+
+       rc = request_irq(gpmc->irq, gpmc_handle_irq, 0, "gpmc", gpmc);
+       if (rc) {
+               dev_err(gpmc->dev, "failed to request irq %d: %d\n",
+                       gpmc->irq, rc);
+               irq_domain_remove(gpmc_irq_domain);
+               gpmc_irq_domain = NULL;
+       }
+
+       return rc;
 }
 
-static int gpmc_free_irq(void)
+static int gpmc_free_irq(struct gpmc_device *gpmc)
 {
-       int i;
+       int hwirq;
 
-       if (gpmc_irq)
-               free_irq(gpmc_irq, NULL);
+       free_irq(gpmc->irq, gpmc);
 
-       for (i = 0; i < GPMC_NR_IRQ; i++) {
-               irq_set_handler(gpmc_client_irq[i].irq, NULL);
-               irq_set_chip(gpmc_client_irq[i].irq, &no_irq_chip);
-       }
+       for (hwirq = 0; hwirq < gpmc->nirqs; hwirq++)
+               irq_dispose_mapping(irq_find_mapping(gpmc_irq_domain, hwirq));
 
-       irq_free_descs(gpmc_irq_start, GPMC_NR_IRQ);
+       irq_domain_remove(gpmc_irq_domain);
+       gpmc_irq_domain = NULL;
 
        return 0;
 }
@@ -1242,12 +1375,7 @@ static void gpmc_mem_init(void)
 {
        int cs;
 
-       /*
-        * The first 1MB of GPMC address space is typically mapped to
-        * the internal ROM. Never allocate the first page, to
-        * facilitate bug detection; even if we didn't boot from ROM.
-        */
-       gpmc_mem_root.start = SZ_1M;
+       gpmc_mem_root.start = GPMC_MEM_START;
        gpmc_mem_root.end = GPMC_MEM_END;
 
        /* Reserve all regions that has been set up by bootloader */
@@ -1796,105 +1924,6 @@ static void __maybe_unused gpmc_read_timings_dt(struct device_node *np,
                of_property_read_bool(np, "gpmc,time-para-granularity");
 }
 
-#if IS_ENABLED(CONFIG_MTD_NAND)
-
-static const char * const nand_xfer_types[] = {
-       [NAND_OMAP_PREFETCH_POLLED]             = "prefetch-polled",
-       [NAND_OMAP_POLLED]                      = "polled",
-       [NAND_OMAP_PREFETCH_DMA]                = "prefetch-dma",
-       [NAND_OMAP_PREFETCH_IRQ]                = "prefetch-irq",
-};
-
-static int gpmc_probe_nand_child(struct platform_device *pdev,
-                                struct device_node *child)
-{
-       u32 val;
-       const char *s;
-       struct gpmc_timings gpmc_t;
-       struct omap_nand_platform_data *gpmc_nand_data;
-
-       if (of_property_read_u32(child, "reg", &val) < 0) {
-               dev_err(&pdev->dev, "%s has no 'reg' property\n",
-                       child->full_name);
-               return -ENODEV;
-       }
-
-       gpmc_nand_data = devm_kzalloc(&pdev->dev, sizeof(*gpmc_nand_data),
-                                     GFP_KERNEL);
-       if (!gpmc_nand_data)
-               return -ENOMEM;
-
-       gpmc_nand_data->cs = val;
-       gpmc_nand_data->of_node = child;
-
-       /* Detect availability of ELM module */
-       gpmc_nand_data->elm_of_node = of_parse_phandle(child, "ti,elm-id", 0);
-       if (gpmc_nand_data->elm_of_node == NULL)
-               gpmc_nand_data->elm_of_node =
-                                       of_parse_phandle(child, "elm_id", 0);
-
-       /* select ecc-scheme for NAND */
-       if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) {
-               pr_err("%s: ti,nand-ecc-opt not found\n", __func__);
-               return -ENODEV;
-       }
-
-       if (!strcmp(s, "sw"))
-               gpmc_nand_data->ecc_opt = OMAP_ECC_HAM1_CODE_SW;
-       else if (!strcmp(s, "ham1") ||
-                !strcmp(s, "hw") || !strcmp(s, "hw-romcode"))
-               gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_HAM1_CODE_HW;
-       else if (!strcmp(s, "bch4"))
-               if (gpmc_nand_data->elm_of_node)
-                       gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_BCH4_CODE_HW;
-               else
-                       gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_BCH4_CODE_HW_DETECTION_SW;
-       else if (!strcmp(s, "bch8"))
-               if (gpmc_nand_data->elm_of_node)
-                       gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_BCH8_CODE_HW;
-               else
-                       gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
-       else if (!strcmp(s, "bch16"))
-               if (gpmc_nand_data->elm_of_node)
-                       gpmc_nand_data->ecc_opt =
-                               OMAP_ECC_BCH16_CODE_HW;
-               else
-                       pr_err("%s: BCH16 requires ELM support\n", __func__);
-       else
-               pr_err("%s: ti,nand-ecc-opt invalid value\n", __func__);
-
-       /* select data transfer mode for NAND controller */
-       if (!of_property_read_string(child, "ti,nand-xfer-type", &s))
-               for (val = 0; val < ARRAY_SIZE(nand_xfer_types); val++)
-                       if (!strcasecmp(s, nand_xfer_types[val])) {
-                               gpmc_nand_data->xfer_type = val;
-                               break;
-                       }
-
-       gpmc_nand_data->flash_bbt = of_get_nand_on_flash_bbt(child);
-
-       val = of_get_nand_bus_width(child);
-       if (val == 16)
-               gpmc_nand_data->devsize = NAND_BUSWIDTH_16;
-
-       gpmc_read_timings_dt(child, &gpmc_t);
-       gpmc_nand_init(gpmc_nand_data, &gpmc_t);
-
-       return 0;
-}
-#else
-static int gpmc_probe_nand_child(struct platform_device *pdev,
-                                struct device_node *child)
-{
-       return 0;
-}
-#endif
-
 #if IS_ENABLED(CONFIG_MTD_ONENAND)
 static int gpmc_probe_onenand_child(struct platform_device *pdev,
                                 struct device_node *child)
@@ -1950,6 +1979,8 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
        const char *name;
        int ret, cs;
        u32 val;
+       struct gpio_desc *waitpin_desc = NULL;
+       struct gpmc_device *gpmc = platform_get_drvdata(pdev);
 
        if (of_property_read_u32(child, "reg", &cs) < 0) {
                dev_err(&pdev->dev, "%s has no 'reg' property\n",
@@ -2010,23 +2041,80 @@ static int gpmc_probe_generic_child(struct platform_device *pdev,
        if (ret < 0) {
                dev_err(&pdev->dev, "cannot remap GPMC CS %d to %pa\n",
                        cs, &res.start);
+               if (res.start < GPMC_MEM_START) {
+                       dev_info(&pdev->dev,
+                                "GPMC CS %d start cannot be lesser than 0x%x\n",
+                                cs, GPMC_MEM_START);
+               } else if (res.end > GPMC_MEM_END) {
+                       dev_info(&pdev->dev,
+                                "GPMC CS %d end cannot be greater than 0x%x\n",
+                                cs, GPMC_MEM_END);
+               }
                goto err;
        }
 
-       ret = of_property_read_u32(child, "bank-width", &gpmc_s.device_width);
-       if (ret < 0)
-               goto err;
+       if (of_node_cmp(child->name, "nand") == 0) {
+               /* Warn about older DT blobs with no compatible property */
+               if (!of_property_read_bool(child, "compatible")) {
+                       dev_warn(&pdev->dev,
+                                "Incompatible NAND node: missing compatible");
+                       ret = -EINVAL;
+                       goto err;
+               }
+       }
+
+       if (of_device_is_compatible(child, "ti,omap2-nand")) {
+               /* NAND specific setup */
+               val = 8;
+               of_property_read_u32(child, "nand-bus-width", &val);
+               switch (val) {
+               case 8:
+                       gpmc_s.device_width = GPMC_DEVWIDTH_8BIT;
+                       break;
+               case 16:
+                       gpmc_s.device_width = GPMC_DEVWIDTH_16BIT;
+                       break;
+               default:
+                       dev_err(&pdev->dev, "%s: invalid 'nand-bus-width'\n",
+                               child->name);
+                       ret = -EINVAL;
+                       goto err;
+               }
+
+               /* disable write protect */
+               gpmc_configure(GPMC_CONFIG_WP, 0);
+               gpmc_s.device_nand = true;
+       } else {
+               ret = of_property_read_u32(child, "bank-width",
+                                          &gpmc_s.device_width);
+               if (ret < 0)
+                       goto err;
+       }
+
+       /* Reserve wait pin if it is required and valid */
+       if (gpmc_s.wait_on_read || gpmc_s.wait_on_write) {
+               unsigned int wait_pin = gpmc_s.wait_pin;
+
+               waitpin_desc = gpiochip_request_own_desc(&gpmc->gpio_chip,
+                                                        wait_pin, "WAITPIN");
+               if (IS_ERR(waitpin_desc)) {
+                       dev_err(&pdev->dev, "invalid wait-pin: %d\n", wait_pin);
+                       ret = PTR_ERR(waitpin_desc);
+                       goto err;
+               }
+       }
 
        gpmc_cs_show_timings(cs, "before gpmc_cs_program_settings");
+
        ret = gpmc_cs_program_settings(cs, &gpmc_s);
        if (ret < 0)
-               goto err;
+               goto err_cs;
 
        ret = gpmc_cs_set_timings(cs, &gpmc_t, &gpmc_s);
        if (ret) {
                dev_err(&pdev->dev, "failed to set gpmc timings for: %s\n",
                        child->name);
-               goto err;
+               goto err_cs;
        }
 
        /* Clear limited address i.e. enable A26-A11 */
@@ -2057,16 +2145,81 @@ err_child_fail:
        dev_err(&pdev->dev, "failed to create gpmc child %s\n", child->name);
        ret = -ENODEV;
 
+err_cs:
+       if (waitpin_desc)
+               gpiochip_free_own_desc(waitpin_desc);
+
 err:
        gpmc_cs_free(cs);
 
        return ret;
 }
 
+static int gpmc_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+       return 1;       /* we're input only */
+}
+
+static int gpmc_gpio_direction_input(struct gpio_chip *chip,
+                                    unsigned int offset)
+{
+       return 0;       /* we're input only */
+}
+
+static int gpmc_gpio_direction_output(struct gpio_chip *chip,
+                                     unsigned int offset, int value)
+{
+       return -EINVAL; /* we're input only */
+}
+
+static void gpmc_gpio_set(struct gpio_chip *chip, unsigned int offset,
+                         int value)
+{
+}
+
+static int gpmc_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+       u32 reg;
+
+       offset += 8;
+
+       reg = gpmc_read_reg(GPMC_STATUS) & BIT(offset);
+
+       return !!reg;
+}
+
+static int gpmc_gpio_init(struct gpmc_device *gpmc)
+{
+       int ret;
+
+       gpmc->gpio_chip.parent = gpmc->dev;
+       gpmc->gpio_chip.owner = THIS_MODULE;
+       gpmc->gpio_chip.label = DEVICE_NAME;
+       gpmc->gpio_chip.ngpio = gpmc_nr_waitpins;
+       gpmc->gpio_chip.get_direction = gpmc_gpio_get_direction;
+       gpmc->gpio_chip.direction_input = gpmc_gpio_direction_input;
+       gpmc->gpio_chip.direction_output = gpmc_gpio_direction_output;
+       gpmc->gpio_chip.set = gpmc_gpio_set;
+       gpmc->gpio_chip.get = gpmc_gpio_get;
+       gpmc->gpio_chip.base = -1;
+
+       ret = gpiochip_add(&gpmc->gpio_chip);
+       if (ret < 0) {
+               dev_err(gpmc->dev, "could not register gpio chip: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static void gpmc_gpio_exit(struct gpmc_device *gpmc)
+{
+       gpiochip_remove(&gpmc->gpio_chip);
+}
+
 static int gpmc_probe_dt(struct platform_device *pdev)
 {
        int ret;
-       struct device_node *child;
        const struct of_device_id *of_id =
                of_match_device(gpmc_dt_ids, &pdev->dev);
 
@@ -2094,17 +2247,26 @@ static int gpmc_probe_dt(struct platform_device *pdev)
                return ret;
        }
 
+       return 0;
+}
+
+static int gpmc_probe_dt_children(struct platform_device *pdev)
+{
+       int ret;
+       struct device_node *child;
+
        for_each_available_child_of_node(pdev->dev.of_node, child) {
 
                if (!child->name)
                        continue;
 
-               if (of_node_cmp(child->name, "nand") == 0)
-                       ret = gpmc_probe_nand_child(pdev, child);
-               else if (of_node_cmp(child->name, "onenand") == 0)
+               if (of_node_cmp(child->name, "onenand") == 0)
                        ret = gpmc_probe_onenand_child(pdev, child);
                else
                        ret = gpmc_probe_generic_child(pdev, child);
+
+               if (ret)
+                       return ret;
        }
 
        return 0;
@@ -2114,6 +2276,11 @@ static int gpmc_probe_dt(struct platform_device *pdev)
 {
        return 0;
 }
+
+static int gpmc_probe_dt_children(struct platform_device *pdev)
+{
+       return 0;
+}
 #endif
 
 static int gpmc_probe(struct platform_device *pdev)
@@ -2121,6 +2288,14 @@ static int gpmc_probe(struct platform_device *pdev)
        int rc;
        u32 l;
        struct resource *res;
+       struct gpmc_device *gpmc;
+
+       gpmc = devm_kzalloc(&pdev->dev, sizeof(*gpmc), GFP_KERNEL);
+       if (!gpmc)
+               return -ENOMEM;
+
+       gpmc->dev = &pdev->dev;
+       platform_set_drvdata(pdev, gpmc);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (res == NULL)
@@ -2134,15 +2309,16 @@ static int gpmc_probe(struct platform_device *pdev)
                return PTR_ERR(gpmc_base);
 
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-       if (res == NULL)
-               dev_warn(&pdev->dev, "Failed to get resource: irq\n");
-       else
-               gpmc_irq = res->start;
+       if (!res) {
+               dev_err(&pdev->dev, "Failed to get resource: irq\n");
+               return -ENOENT;
+       }
+
+       gpmc->irq = res->start;
 
        gpmc_l3_clk = devm_clk_get(&pdev->dev, "fck");
        if (IS_ERR(gpmc_l3_clk)) {
                dev_err(&pdev->dev, "Failed to get GPMC fck\n");
-               gpmc_irq = 0;
                return PTR_ERR(gpmc_l3_clk);
        }
 
@@ -2151,11 +2327,18 @@ static int gpmc_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
+       if (pdev->dev.of_node) {
+               rc = gpmc_probe_dt(pdev);
+               if (rc)
+                       return rc;
+       } else {
+               gpmc_cs_num = GPMC_CS_NUM;
+               gpmc_nr_waitpins = GPMC_NR_WAITPINS;
+       }
+
        pm_runtime_enable(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
 
-       gpmc_dev = &pdev->dev;
-
        l = gpmc_read_reg(GPMC_REVISION);
 
        /*
@@ -2174,36 +2357,51 @@ static int gpmc_probe(struct platform_device *pdev)
                gpmc_capability = GPMC_HAS_WR_ACCESS | GPMC_HAS_WR_DATA_MUX_BUS;
        if (GPMC_REVISION_MAJOR(l) > 0x5)
                gpmc_capability |= GPMC_HAS_MUX_AAD;
-       dev_info(gpmc_dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
+       dev_info(gpmc->dev, "GPMC revision %d.%d\n", GPMC_REVISION_MAJOR(l),
                 GPMC_REVISION_MINOR(l));
 
        gpmc_mem_init();
-
-       if (gpmc_setup_irq() < 0)
-               dev_warn(gpmc_dev, "gpmc_setup_irq failed\n");
-
-       if (!pdev->dev.of_node) {
-               gpmc_cs_num      = GPMC_CS_NUM;
-               gpmc_nr_waitpins = GPMC_NR_WAITPINS;
+       rc = gpmc_gpio_init(gpmc);
+       if (rc)
+               goto gpio_init_failed;
+
+       gpmc->nirqs = GPMC_NR_NAND_IRQS + gpmc_nr_waitpins;
+       rc = gpmc_setup_irq(gpmc);
+       if (rc) {
+               dev_err(gpmc->dev, "gpmc_setup_irq failed\n");
+               goto setup_irq_failed;
        }
 
-       rc = gpmc_probe_dt(pdev);
+       rc = gpmc_probe_dt_children(pdev);
        if (rc < 0) {
-               pm_runtime_put_sync(&pdev->dev);
-               dev_err(gpmc_dev, "failed to probe DT parameters\n");
-               return rc;
+               dev_err(gpmc->dev, "failed to probe DT children\n");
+               goto dt_children_failed;
        }
 
        return 0;
+
+dt_children_failed:
+       gpmc_free_irq(gpmc);
+setup_irq_failed:
+       gpmc_gpio_exit(gpmc);
+gpio_init_failed:
+       gpmc_mem_exit();
+       pm_runtime_put_sync(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
+
+       return rc;
 }
 
 static int gpmc_remove(struct platform_device *pdev)
 {
-       gpmc_free_irq();
+       struct gpmc_device *gpmc = platform_get_drvdata(pdev);
+
+       gpmc_free_irq(gpmc);
+       gpmc_gpio_exit(gpmc);
        gpmc_mem_exit();
        pm_runtime_put_sync(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
-       gpmc_dev = NULL;
+
        return 0;
 }
 
@@ -2249,25 +2447,6 @@ static __exit void gpmc_exit(void)
 postcore_initcall(gpmc_init);
 module_exit(gpmc_exit);
 
-static irqreturn_t gpmc_handle_irq(int irq, void *dev)
-{
-       int i;
-       u32 regval;
-
-       regval = gpmc_read_reg(GPMC_IRQSTATUS);
-
-       if (!regval)
-               return IRQ_NONE;
-
-       for (i = 0; i < GPMC_NR_IRQ; i++)
-               if (regval & gpmc_client_irq[i].bitmask)
-                       generic_handle_irq(gpmc_client_irq[i].irq);
-
-       gpmc_write_reg(GPMC_IRQSTATUS, regval);
-
-       return IRQ_HANDLED;
-}
-
 static struct omap3_gpmc_regs gpmc_context;
 
 void omap3_gpmc_save_context(void)
index 3b3dabce58de9d9b2d9ad1838800c06bf04aa6e5..bbfa1f1292668a84f7e0a6e708dfd9a6b01d1d20 100644 (file)
@@ -115,6 +115,7 @@ config MTD_MAP_BANK_WIDTH_16
 
 config MTD_MAP_BANK_WIDTH_32
        bool "Support 256-bit buswidth" if MTD_CFI_GEOMETRY
+       select MTD_COMPLEX_MAPPINGS if HAS_IOMEM
        default n
        help
          If you wish to support CFI devices on a physical bus which is
index 347bb83db8642a15320ed65771ca4e58d89da2b1..1c65c15b31a1aaed713363d5430c917754b13f13 100644 (file)
@@ -2,6 +2,7 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
+#include <linux/ioport.h>
 #include <linux/mtd/mtd.h>
 #include <linux/platform_device.h>
 #include <linux/bcma/bcma.h>
@@ -109,8 +110,7 @@ static int bcm47xxsflash_read(struct mtd_info *mtd, loff_t from, size_t len,
        if ((from + len) > mtd->size)
                return -EINVAL;
 
-       memcpy_fromio(buf, (void __iomem *)KSEG0ADDR(b47s->window + from),
-                     len);
+       memcpy_fromio(buf, b47s->window + from, len);
        *retlen = len;
 
        return len;
@@ -275,15 +275,33 @@ static void bcm47xxsflash_bcma_cc_write(struct bcm47xxsflash *b47s, u16 offset,
 
 static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
 {
-       struct bcma_sflash *sflash = dev_get_platdata(&pdev->dev);
+       struct device *dev = &pdev->dev;
+       struct bcma_sflash *sflash = dev_get_platdata(dev);
        struct bcm47xxsflash *b47s;
+       struct resource *res;
        int err;
 
-       b47s = devm_kzalloc(&pdev->dev, sizeof(*b47s), GFP_KERNEL);
+       b47s = devm_kzalloc(dev, sizeof(*b47s), GFP_KERNEL);
        if (!b47s)
                return -ENOMEM;
        sflash->priv = b47s;
 
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(dev, "invalid resource\n");
+               return -EINVAL;
+       }
+       if (!devm_request_mem_region(dev, res->start, resource_size(res),
+                                    res->name)) {
+               dev_err(dev, "can't request region for resource %pR\n", res);
+               return -EBUSY;
+       }
+       b47s->window = ioremap_cache(res->start, resource_size(res));
+       if (!b47s->window) {
+               dev_err(dev, "ioremap failed for resource %pR\n", res);
+               return -ENOMEM;
+       }
+
        b47s->bcma_cc = container_of(sflash, struct bcma_drv_cc, sflash);
        b47s->cc_read = bcm47xxsflash_bcma_cc_read;
        b47s->cc_write = bcm47xxsflash_bcma_cc_write;
@@ -297,7 +315,6 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
                break;
        }
 
-       b47s->window = sflash->window;
        b47s->blocksize = sflash->blocksize;
        b47s->numblocks = sflash->numblocks;
        b47s->size = sflash->size;
@@ -306,6 +323,7 @@ static int bcm47xxsflash_bcma_probe(struct platform_device *pdev)
        err = mtd_device_parse_register(&b47s->mtd, probes, NULL, NULL, 0);
        if (err) {
                pr_err("Failed to register MTD device: %d\n", err);
+               iounmap(b47s->window);
                return err;
        }
 
@@ -321,6 +339,7 @@ static int bcm47xxsflash_bcma_remove(struct platform_device *pdev)
        struct bcm47xxsflash *b47s = sflash->priv;
 
        mtd_device_unregister(&b47s->mtd);
+       iounmap(b47s->window);
 
        return 0;
 }
index fe93daf4f4894a35f2d7b8a65363d1d163d09ffc..1564b62b412e3c071f5f3062e2e992296d531f91 100644 (file)
@@ -65,7 +65,8 @@ struct bcm47xxsflash {
 
        enum bcm47xxsflash_type type;
 
-       u32 window;
+       void __iomem *window;
+
        u32 blocksize;
        u16 numblocks;
        u32 size;
index e7b2e439696c851298c21775a3117fd59811fbf1..b833e6cc684c389985bbe91aec15c2612daf6b5e 100644 (file)
@@ -67,16 +67,40 @@ module_param(reliable_mode, uint, 0);
 MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode (0=normal MLC, 1=fast, "
                 "2=reliable) : MLC normal operations are in normal mode");
 
-/**
- * struct docg3_oobinfo - DiskOnChip G3 OOB layout
- * @eccbytes: 8 bytes are used (1 for Hamming ECC, 7 for BCH ECC)
- * @eccpos: ecc positions (byte 7 is Hamming ECC, byte 8-14 are BCH ECC)
- * @oobfree: free pageinfo bytes (byte 0 until byte 6, byte 15
- */
-static struct nand_ecclayout docg3_oobinfo = {
-       .eccbytes = 8,
-       .eccpos = {7, 8, 9, 10, 11, 12, 13, 14},
-       .oobfree = {{0, 7}, {15, 1} },
+static int docg3_ooblayout_ecc(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       /* byte 7 is Hamming ECC, byte 8-14 are BCH ECC */
+       oobregion->offset = 7;
+       oobregion->length = 8;
+
+       return 0;
+}
+
+static int docg3_ooblayout_free(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       /* free bytes: byte 0 until byte 6, byte 15 */
+       if (!section) {
+               oobregion->offset = 0;
+               oobregion->length = 7;
+       } else {
+               oobregion->offset = 15;
+               oobregion->length = 1;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops nand_ooblayout_docg3_ops = {
+       .ecc = docg3_ooblayout_ecc,
+       .free = docg3_ooblayout_free,
 };
 
 static inline u8 doc_readb(struct docg3 *docg3, u16 reg)
@@ -1857,7 +1881,7 @@ static int __init doc_set_driver_info(int chip_id, struct mtd_info *mtd)
        mtd->_read_oob = doc_read_oob;
        mtd->_write_oob = doc_write_oob;
        mtd->_block_isbad = doc_block_isbad;
-       mtd->ecclayout = &docg3_oobinfo;
+       mtd_set_ooblayout(mtd, &nand_ooblayout_docg3_ops);
        mtd->oobavail = 8;
        mtd->ecc_strength = DOC_ECC_BCH_T;
 
index c9c3b7fa30511c2b4a8f1b9c97bdd1cd89992758..9d6854467651774182ab8895198d41ed7caaf945 100644 (file)
@@ -131,6 +131,28 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
        /* convert the dummy cycles to the number of bytes */
        dummy /= 8;
 
+       if (spi_flash_read_supported(spi)) {
+               struct spi_flash_read_message msg;
+               int ret;
+
+               memset(&msg, 0, sizeof(msg));
+
+               msg.buf = buf;
+               msg.from = from;
+               msg.len = len;
+               msg.read_opcode = nor->read_opcode;
+               msg.addr_width = nor->addr_width;
+               msg.dummy_bytes = dummy;
+               /* TODO: Support other combinations */
+               msg.opcode_nbits = SPI_NBITS_SINGLE;
+               msg.addr_nbits = SPI_NBITS_SINGLE;
+               msg.data_nbits = m25p80_rx_nbits(nor);
+
+               ret = spi_flash_read(spi, &msg);
+               *retlen = msg.retlen;
+               return ret;
+       }
+
        spi_message_init(&m);
        memset(t, 0, (sizeof t));
 
index 708b7e8c8b18ca27e00a6b9c59b11125808dfbdb..220f9200fa52f4bf01178d3b61dbc1926b3bca80 100644 (file)
@@ -353,7 +353,7 @@ static int pmc551_write(struct mtd_info *mtd, loff_t to, size_t len,
  * mechanism
  * returns the size of the memory region found.
  */
-static int fixup_pmc551(struct pci_dev *dev)
+static int __init fixup_pmc551(struct pci_dev *dev)
 {
 #ifdef CONFIG_MTD_PMC551_BUGFIX
        u32 dram_data;
index 0455166f05faeaf364252bf0ddd39ba1fa24931b..4f206a99164c1a2b78d991cb87924323128f5d87 100644 (file)
@@ -112,8 +112,8 @@ static void ck804xrom_cleanup(struct ck804xrom_window *window)
 }
 
 
-static int ck804xrom_init_one(struct pci_dev *pdev,
-                             const struct pci_device_id *ent)
+static int __init ck804xrom_init_one(struct pci_dev *pdev,
+                                    const struct pci_device_id *ent)
 {
        static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
        u8 byte;
index 76ed651b515beef6275b7d67820eb1c4fee8e8dc..9646b0766ce02ba9aa6f3f12f1719107cb309e5e 100644 (file)
@@ -144,8 +144,8 @@ static void esb2rom_cleanup(struct esb2rom_window *window)
        pci_dev_put(window->pdev);
 }
 
-static int esb2rom_init_one(struct pci_dev *pdev,
-                           const struct pci_device_id *ent)
+static int __init esb2rom_init_one(struct pci_dev *pdev,
+                                  const struct pci_device_id *ent)
 {
        static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
        struct esb2rom_window *window = &esb2rom_window;
index 8636bba422009a1f54ff58b1611acac54cbf9b45..e17d02ae03f0966419a8e42b5192967a98883b39 100644 (file)
@@ -84,8 +84,8 @@ static void ichxrom_cleanup(struct ichxrom_window *window)
 }
 
 
-static int ichxrom_init_one(struct pci_dev *pdev,
-                           const struct pci_device_id *ent)
+static int __init ichxrom_init_one(struct pci_dev *pdev,
+                                  const struct pci_device_id *ent)
 {
        static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
        struct ichxrom_window *window = &ichxrom_window;
index c1af83db5202fe46f503b68289fbc06d0ee59828..00a8190797ec1d4a445fd4bd46bfe03903699a15 100644 (file)
@@ -4,11 +4,13 @@
  *     uclinux.c -- generic memory mapped MTD driver for uclinux
  *
  *     (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
+ *
+ *      License: GPL
  */
 
 /****************************************************************************/
 
-#include <linux/module.h>
+#include <linux/moduleparam.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
@@ -117,27 +119,6 @@ static int __init uclinux_mtd_init(void)
 
        return(0);
 }
-
-/****************************************************************************/
-
-static void __exit uclinux_mtd_cleanup(void)
-{
-       if (uclinux_ram_mtdinfo) {
-               mtd_device_unregister(uclinux_ram_mtdinfo);
-               map_destroy(uclinux_ram_mtdinfo);
-               uclinux_ram_mtdinfo = NULL;
-       }
-       if (uclinux_ram_map.virt)
-               uclinux_ram_map.virt = 0;
-}
-
-/****************************************************************************/
-
-module_init(uclinux_mtd_init);
-module_exit(uclinux_mtd_cleanup);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
-MODULE_DESCRIPTION("Generic MTD for uClinux");
+device_initcall(uclinux_mtd_init);
 
 /****************************************************************************/
index 6d19835b80a952e098cfdfa8436971d5c68a593e..2a47a3f0e7308ea13b31391d77e8dab83f536dfe 100644 (file)
@@ -465,35 +465,108 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd,
 }
 
 /*
- * Copies (and truncates, if necessary) data from the larger struct,
- * nand_ecclayout, to the smaller, deprecated layout struct,
- * nand_ecclayout_user. This is necessary only to support the deprecated
- * API ioctl ECCGETLAYOUT while allowing all new functionality to use
- * nand_ecclayout flexibly (i.e. the struct may change size in new
- * releases without requiring major rewrites).
+ * Copies (and truncates, if necessary) OOB layout information to the
+ * deprecated layout struct, nand_ecclayout_user. This is necessary only to
+ * support the deprecated API ioctl ECCGETLAYOUT while allowing all new
+ * functionality to use mtd_ooblayout_ops flexibly (i.e. mtd_ooblayout_ops
+ * can describe any kind of OOB layout with almost zero overhead from a
+ * memory usage point of view).
  */
-static int shrink_ecclayout(const struct nand_ecclayout *from,
-               struct nand_ecclayout_user *to)
+static int shrink_ecclayout(struct mtd_info *mtd,
+                           struct nand_ecclayout_user *to)
 {
-       int i;
+       struct mtd_oob_region oobregion;
+       int i, section = 0, ret;
 
-       if (!from || !to)
+       if (!mtd || !to)
                return -EINVAL;
 
        memset(to, 0, sizeof(*to));
 
-       to->eccbytes = min((int)from->eccbytes, MTD_MAX_ECCPOS_ENTRIES);
-       for (i = 0; i < to->eccbytes; i++)
-               to->eccpos[i] = from->eccpos[i];
+       to->eccbytes = 0;
+       for (i = 0; i < MTD_MAX_ECCPOS_ENTRIES;) {
+               u32 eccpos;
+
+               ret = mtd_ooblayout_ecc(mtd, section, &oobregion);
+               if (ret < 0) {
+                       if (ret != -ERANGE)
+                               return ret;
+
+                       break;
+               }
+
+               eccpos = oobregion.offset;
+               for (; i < MTD_MAX_ECCPOS_ENTRIES &&
+                      eccpos < oobregion.offset + oobregion.length; i++) {
+                       to->eccpos[i] = eccpos++;
+                       to->eccbytes++;
+               }
+       }
 
        for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES; i++) {
-               if (from->oobfree[i].length == 0 &&
-                               from->oobfree[i].offset == 0)
+               ret = mtd_ooblayout_free(mtd, i, &oobregion);
+               if (ret < 0) {
+                       if (ret != -ERANGE)
+                               return ret;
+
+                       break;
+               }
+
+               to->oobfree[i].offset = oobregion.offset;
+               to->oobfree[i].length = oobregion.length;
+               to->oobavail += to->oobfree[i].length;
+       }
+
+       return 0;
+}
+
+static int get_oobinfo(struct mtd_info *mtd, struct nand_oobinfo *to)
+{
+       struct mtd_oob_region oobregion;
+       int i, section = 0, ret;
+
+       if (!mtd || !to)
+               return -EINVAL;
+
+       memset(to, 0, sizeof(*to));
+
+       to->eccbytes = 0;
+       for (i = 0; i < ARRAY_SIZE(to->eccpos);) {
+               u32 eccpos;
+
+               ret = mtd_ooblayout_ecc(mtd, section, &oobregion);
+               if (ret < 0) {
+                       if (ret != -ERANGE)
+                               return ret;
+
                        break;
-               to->oobavail += from->oobfree[i].length;
-               to->oobfree[i] = from->oobfree[i];
+               }
+
+               if (oobregion.length + i > ARRAY_SIZE(to->eccpos))
+                       return -EINVAL;
+
+               eccpos = oobregion.offset;
+               for (; eccpos < oobregion.offset + oobregion.length; i++) {
+                       to->eccpos[i] = eccpos++;
+                       to->eccbytes++;
+               }
        }
 
+       for (i = 0; i < 8; i++) {
+               ret = mtd_ooblayout_free(mtd, i, &oobregion);
+               if (ret < 0) {
+                       if (ret != -ERANGE)
+                               return ret;
+
+                       break;
+               }
+
+               to->oobfree[i][0] = oobregion.offset;
+               to->oobfree[i][1] = oobregion.length;
+       }
+
+       to->useecc = MTD_NANDECC_AUTOPLACE;
+
        return 0;
 }
 
@@ -815,16 +888,12 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
        {
                struct nand_oobinfo oi;
 
-               if (!mtd->ecclayout)
+               if (!mtd->ooblayout)
                        return -EOPNOTSUPP;
-               if (mtd->ecclayout->eccbytes > ARRAY_SIZE(oi.eccpos))
-                       return -EINVAL;
 
-               oi.useecc = MTD_NANDECC_AUTOPLACE;
-               memcpy(&oi.eccpos, mtd->ecclayout->eccpos, sizeof(oi.eccpos));
-               memcpy(&oi.oobfree, mtd->ecclayout->oobfree,
-                      sizeof(oi.oobfree));
-               oi.eccbytes = mtd->ecclayout->eccbytes;
+               ret = get_oobinfo(mtd, &oi);
+               if (ret)
+                       return ret;
 
                if (copy_to_user(argp, &oi, sizeof(struct nand_oobinfo)))
                        return -EFAULT;
@@ -913,14 +982,14 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
        {
                struct nand_ecclayout_user *usrlay;
 
-               if (!mtd->ecclayout)
+               if (!mtd->ooblayout)
                        return -EOPNOTSUPP;
 
                usrlay = kmalloc(sizeof(*usrlay), GFP_KERNEL);
                if (!usrlay)
                        return -ENOMEM;
 
-               shrink_ecclayout(mtd->ecclayout, usrlay);
+               shrink_ecclayout(mtd, usrlay);
 
                if (copy_to_user(argp, usrlay, sizeof(*usrlay)))
                        ret = -EFAULT;
index 239a8c806b6772df642bf6cb1385616147e975c8..d573606b91c2a57a4ff07e040b79fd86a7762c5b 100644 (file)
@@ -777,7 +777,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[],       /* subdevices to c
 
        }
 
-       concat->mtd.ecclayout = subdev[0]->ecclayout;
+       mtd_set_ooblayout(&concat->mtd, subdev[0]->ooblayout);
 
        concat->num_subdev = num_devs;
        concat->mtd.name = name;
index bee180bd11e79fe236e0287647986fe81fea864c..e3936b847c6b3a7adaf757dfa3e0cddde0ae28bf 100644 (file)
@@ -1016,6 +1016,366 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,
 }
 EXPORT_SYMBOL_GPL(mtd_write_oob);
 
+/**
+ * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
+ * @mtd: MTD device structure
+ * @section: ECC section. Depending on the layout you may have all the ECC
+ *          bytes stored in a single contiguous section, or one section
+ *          per ECC chunk (and sometime several sections for a single ECC
+ *          ECC chunk)
+ * @oobecc: OOB region struct filled with the appropriate ECC position
+ *         information
+ *
+ * This functions return ECC section information in the OOB area. I you want
+ * to get all the ECC bytes information, then you should call
+ * mtd_ooblayout_ecc(mtd, section++, oobecc) until it returns -ERANGE.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
+                     struct mtd_oob_region *oobecc)
+{
+       memset(oobecc, 0, sizeof(*oobecc));
+
+       if (!mtd || section < 0)
+               return -EINVAL;
+
+       if (!mtd->ooblayout || !mtd->ooblayout->ecc)
+               return -ENOTSUPP;
+
+       return mtd->ooblayout->ecc(mtd, section, oobecc);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_ecc);
+
+/**
+ * mtd_ooblayout_free - Get the OOB region definition of a specific free
+ *                     section
+ * @mtd: MTD device structure
+ * @section: Free section you are interested in. Depending on the layout
+ *          you may have all the free bytes stored in a single contiguous
+ *          section, or one section per ECC chunk plus an extra section
+ *          for the remaining bytes (or other funky layout).
+ * @oobfree: OOB region struct filled with the appropriate free position
+ *          information
+ *
+ * This functions return free bytes position in the OOB area. I you want
+ * to get all the free bytes information, then you should call
+ * mtd_ooblayout_free(mtd, section++, oobfree) until it returns -ERANGE.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_free(struct mtd_info *mtd, int section,
+                      struct mtd_oob_region *oobfree)
+{
+       memset(oobfree, 0, sizeof(*oobfree));
+
+       if (!mtd || section < 0)
+               return -EINVAL;
+
+       if (!mtd->ooblayout || !mtd->ooblayout->free)
+               return -ENOTSUPP;
+
+       return mtd->ooblayout->free(mtd, section, oobfree);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_free);
+
+/**
+ * mtd_ooblayout_find_region - Find the region attached to a specific byte
+ * @mtd: mtd info structure
+ * @byte: the byte we are searching for
+ * @sectionp: pointer where the section id will be stored
+ * @oobregion: used to retrieve the ECC position
+ * @iter: iterator function. Should be either mtd_ooblayout_free or
+ *       mtd_ooblayout_ecc depending on the region type you're searching for
+ *
+ * This functions returns the section id and oobregion information of a
+ * specific byte. For example, say you want to know where the 4th ECC byte is
+ * stored, you'll use:
+ *
+ * mtd_ooblayout_find_region(mtd, 3, &section, &oobregion, mtd_ooblayout_ecc);
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+static int mtd_ooblayout_find_region(struct mtd_info *mtd, int byte,
+                               int *sectionp, struct mtd_oob_region *oobregion,
+                               int (*iter)(struct mtd_info *,
+                                           int section,
+                                           struct mtd_oob_region *oobregion))
+{
+       int pos = 0, ret, section = 0;
+
+       memset(oobregion, 0, sizeof(*oobregion));
+
+       while (1) {
+               ret = iter(mtd, section, oobregion);
+               if (ret)
+                       return ret;
+
+               if (pos + oobregion->length > byte)
+                       break;
+
+               pos += oobregion->length;
+               section++;
+       }
+
+       /*
+        * Adjust region info to make it start at the beginning at the
+        * 'start' ECC byte.
+        */
+       oobregion->offset += byte - pos;
+       oobregion->length -= byte - pos;
+       *sectionp = section;
+
+       return 0;
+}
+
+/**
+ * mtd_ooblayout_find_eccregion - Find the ECC region attached to a specific
+ *                               ECC byte
+ * @mtd: mtd info structure
+ * @eccbyte: the byte we are searching for
+ * @sectionp: pointer where the section id will be stored
+ * @oobregion: OOB region information
+ *
+ * Works like mtd_ooblayout_find_region() except it searches for a specific ECC
+ * byte.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
+                                int *section,
+                                struct mtd_oob_region *oobregion)
+{
+       return mtd_ooblayout_find_region(mtd, eccbyte, section, oobregion,
+                                        mtd_ooblayout_ecc);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_find_eccregion);
+
+/**
+ * mtd_ooblayout_get_bytes - Extract OOB bytes from the oob buffer
+ * @mtd: mtd info structure
+ * @buf: destination buffer to store OOB bytes
+ * @oobbuf: OOB buffer
+ * @start: first byte to retrieve
+ * @nbytes: number of bytes to retrieve
+ * @iter: section iterator
+ *
+ * Extract bytes attached to a specific category (ECC or free)
+ * from the OOB buffer and copy them into buf.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+static int mtd_ooblayout_get_bytes(struct mtd_info *mtd, u8 *buf,
+                               const u8 *oobbuf, int start, int nbytes,
+                               int (*iter)(struct mtd_info *,
+                                           int section,
+                                           struct mtd_oob_region *oobregion))
+{
+       struct mtd_oob_region oobregion = { };
+       int section = 0, ret;
+
+       ret = mtd_ooblayout_find_region(mtd, start, &section,
+                                       &oobregion, iter);
+
+       while (!ret) {
+               int cnt;
+
+               cnt = oobregion.length > nbytes ? nbytes : oobregion.length;
+               memcpy(buf, oobbuf + oobregion.offset, cnt);
+               buf += cnt;
+               nbytes -= cnt;
+
+               if (!nbytes)
+                       break;
+
+               ret = iter(mtd, ++section, &oobregion);
+       }
+
+       return ret;
+}
+
+/**
+ * mtd_ooblayout_set_bytes - put OOB bytes into the oob buffer
+ * @mtd: mtd info structure
+ * @buf: source buffer to get OOB bytes from
+ * @oobbuf: OOB buffer
+ * @start: first OOB byte to set
+ * @nbytes: number of OOB bytes to set
+ * @iter: section iterator
+ *
+ * Fill the OOB buffer with data provided in buf. The category (ECC or free)
+ * is selected by passing the appropriate iterator.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+static int mtd_ooblayout_set_bytes(struct mtd_info *mtd, const u8 *buf,
+                               u8 *oobbuf, int start, int nbytes,
+                               int (*iter)(struct mtd_info *,
+                                           int section,
+                                           struct mtd_oob_region *oobregion))
+{
+       struct mtd_oob_region oobregion = { };
+       int section = 0, ret;
+
+       ret = mtd_ooblayout_find_region(mtd, start, &section,
+                                       &oobregion, iter);
+
+       while (!ret) {
+               int cnt;
+
+               cnt = oobregion.length > nbytes ? nbytes : oobregion.length;
+               memcpy(oobbuf + oobregion.offset, buf, cnt);
+               buf += cnt;
+               nbytes -= cnt;
+
+               if (!nbytes)
+                       break;
+
+               ret = iter(mtd, ++section, &oobregion);
+       }
+
+       return ret;
+}
+
+/**
+ * mtd_ooblayout_count_bytes - count the number of bytes in a OOB category
+ * @mtd: mtd info structure
+ * @iter: category iterator
+ *
+ * Count the number of bytes in a given category.
+ *
+ * Returns a positive value on success, a negative error code otherwise.
+ */
+static int mtd_ooblayout_count_bytes(struct mtd_info *mtd,
+                               int (*iter)(struct mtd_info *,
+                                           int section,
+                                           struct mtd_oob_region *oobregion))
+{
+       struct mtd_oob_region oobregion = { };
+       int section = 0, ret, nbytes = 0;
+
+       while (1) {
+               ret = iter(mtd, section++, &oobregion);
+               if (ret) {
+                       if (ret == -ERANGE)
+                               ret = nbytes;
+                       break;
+               }
+
+               nbytes += oobregion.length;
+       }
+
+       return ret;
+}
+
+/**
+ * mtd_ooblayout_get_eccbytes - extract ECC bytes from the oob buffer
+ * @mtd: mtd info structure
+ * @eccbuf: destination buffer to store ECC bytes
+ * @oobbuf: OOB buffer
+ * @start: first ECC byte to retrieve
+ * @nbytes: number of ECC bytes to retrieve
+ *
+ * Works like mtd_ooblayout_get_bytes(), except it acts on ECC bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
+                              const u8 *oobbuf, int start, int nbytes)
+{
+       return mtd_ooblayout_get_bytes(mtd, eccbuf, oobbuf, start, nbytes,
+                                      mtd_ooblayout_ecc);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_get_eccbytes);
+
+/**
+ * mtd_ooblayout_set_eccbytes - set ECC bytes into the oob buffer
+ * @mtd: mtd info structure
+ * @eccbuf: source buffer to get ECC bytes from
+ * @oobbuf: OOB buffer
+ * @start: first ECC byte to set
+ * @nbytes: number of ECC bytes to set
+ *
+ * Works like mtd_ooblayout_set_bytes(), except it acts on ECC bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
+                              u8 *oobbuf, int start, int nbytes)
+{
+       return mtd_ooblayout_set_bytes(mtd, eccbuf, oobbuf, start, nbytes,
+                                      mtd_ooblayout_ecc);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_set_eccbytes);
+
+/**
+ * mtd_ooblayout_get_databytes - extract data bytes from the oob buffer
+ * @mtd: mtd info structure
+ * @databuf: destination buffer to store ECC bytes
+ * @oobbuf: OOB buffer
+ * @start: first ECC byte to retrieve
+ * @nbytes: number of ECC bytes to retrieve
+ *
+ * Works like mtd_ooblayout_get_bytes(), except it acts on free bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
+                               const u8 *oobbuf, int start, int nbytes)
+{
+       return mtd_ooblayout_get_bytes(mtd, databuf, oobbuf, start, nbytes,
+                                      mtd_ooblayout_free);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_get_databytes);
+
+/**
+ * mtd_ooblayout_get_eccbytes - set data bytes into the oob buffer
+ * @mtd: mtd info structure
+ * @eccbuf: source buffer to get data bytes from
+ * @oobbuf: OOB buffer
+ * @start: first ECC byte to set
+ * @nbytes: number of ECC bytes to set
+ *
+ * Works like mtd_ooblayout_get_bytes(), except it acts on free bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
+                               u8 *oobbuf, int start, int nbytes)
+{
+       return mtd_ooblayout_set_bytes(mtd, databuf, oobbuf, start, nbytes,
+                                      mtd_ooblayout_free);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_set_databytes);
+
+/**
+ * mtd_ooblayout_count_freebytes - count the number of free bytes in OOB
+ * @mtd: mtd info structure
+ *
+ * Works like mtd_ooblayout_count_bytes(), except it count free bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_count_freebytes(struct mtd_info *mtd)
+{
+       return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_free);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_count_freebytes);
+
+/**
+ * mtd_ooblayout_count_freebytes - count the number of ECC bytes in OOB
+ * @mtd: mtd info structure
+ *
+ * Works like mtd_ooblayout_count_bytes(), except it count ECC bytes.
+ *
+ * Returns zero on success, a negative error code otherwise.
+ */
+int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd)
+{
+       return mtd_ooblayout_count_bytes(mtd, mtd_ooblayout_ecc);
+}
+EXPORT_SYMBOL_GPL(mtd_ooblayout_count_eccbytes);
+
 /*
  * Method to access the protection register area, present in some flash
  * devices. The user data is one time programmable but the factory data is read
index 08de4b2cf0f5ec291ba4bfe9e43b8f8d083c0bbd..1f13e32556f869634146c102ef1f2b0aea8fe4f1 100644 (file)
@@ -317,6 +317,27 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs)
        return res;
 }
 
+static int part_ooblayout_ecc(struct mtd_info *mtd, int section,
+                             struct mtd_oob_region *oobregion)
+{
+       struct mtd_part *part = mtd_to_part(mtd);
+
+       return mtd_ooblayout_ecc(part->master, section, oobregion);
+}
+
+static int part_ooblayout_free(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       struct mtd_part *part = mtd_to_part(mtd);
+
+       return mtd_ooblayout_free(part->master, section, oobregion);
+}
+
+static const struct mtd_ooblayout_ops part_ooblayout_ops = {
+       .ecc = part_ooblayout_ecc,
+       .free = part_ooblayout_free,
+};
+
 static inline void free_partition(struct mtd_part *p)
 {
        kfree(p->mtd.name);
@@ -533,7 +554,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master,
                        part->name);
        }
 
-       slave->mtd.ecclayout = master->ecclayout;
+       mtd_set_ooblayout(&slave->mtd, &part_ooblayout_ops);
        slave->mtd.ecc_step_size = master->ecc_step_size;
        slave->mtd.ecc_strength = master->ecc_strength;
        slave->mtd.bitflip_threshold = master->bitflip_threshold;
index 68b58c85789c354f16886e2c8d8045dec137bd43..78e12cc8bac2f5bc43cc54a7a809c8734571bad1 100644 (file)
@@ -224,6 +224,7 @@ static int ams_delta_init(struct platform_device *pdev)
        /* 25 us command delay time */
        this->chip_delay = 30;
        this->ecc.mode = NAND_ECC_SOFT;
+       this->ecc.algo = NAND_ECC_HAMMING;
 
        platform_set_drvdata(pdev, io_base);
 
index 20cbaabb29590f61f2009411e114e1fc83acec81..efc8ea250c1d5966409d9aabb6588af55e4d478a 100644 (file)
@@ -36,7 +36,6 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_gpio.h>
-#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -72,30 +71,44 @@ struct atmel_nand_nfc_caps {
        uint32_t rb_mask;
 };
 
-/* oob layout for large page size
+/*
+ * oob layout for large page size
  * bad block info is on bytes 0 and 1
  * the bytes have to be consecutives to avoid
  * several NAND_CMD_RNDOUT during read
- */
-static struct nand_ecclayout atmel_oobinfo_large = {
-       .eccbytes = 4,
-       .eccpos = {60, 61, 62, 63},
-       .oobfree = {
-               {2, 58}
-       },
-};
-
-/* oob layout for small page size
+ *
+ * oob layout for small page size
  * bad block info is on bytes 4 and 5
  * the bytes have to be consecutives to avoid
  * several NAND_CMD_RNDOUT during read
  */
-static struct nand_ecclayout atmel_oobinfo_small = {
-       .eccbytes = 4,
-       .eccpos = {0, 1, 2, 3},
-       .oobfree = {
-               {6, 10}
-       },
+static int atmel_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = 4;
+       oobregion->offset = 0;
+
+       return 0;
+}
+
+static int atmel_ooblayout_free_sp(struct mtd_info *mtd, int section,
+                                  struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 6;
+       oobregion->length = mtd->oobsize - oobregion->offset;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops atmel_ooblayout_sp_ops = {
+       .ecc = atmel_ooblayout_ecc_sp,
+       .free = atmel_ooblayout_free_sp,
 };
 
 struct atmel_nfc {
@@ -163,8 +176,6 @@ struct atmel_nand_host {
        int                     *pmecc_delta;
 };
 
-static struct nand_ecclayout atmel_pmecc_oobinfo;
-
 /*
  * Enable NAND.
  */
@@ -434,14 +445,13 @@ err_buf:
 static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
-       struct atmel_nand_host *host = nand_get_controller_data(chip);
 
        if (use_dma && len > mtd->oobsize)
                /* only use DMA for bigger than oob size: better performances */
                if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
                        return;
 
-       if (host->board.bus_width_16)
+       if (chip->options & NAND_BUSWIDTH_16)
                atmel_read_buf16(mtd, buf, len);
        else
                atmel_read_buf8(mtd, buf, len);
@@ -450,14 +460,13 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
-       struct atmel_nand_host *host = nand_get_controller_data(chip);
 
        if (use_dma && len > mtd->oobsize)
                /* only use DMA for bigger than oob size: better performances */
                if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
                        return;
 
-       if (host->board.bus_width_16)
+       if (chip->options & NAND_BUSWIDTH_16)
                atmel_write_buf16(mtd, buf, len);
        else
                atmel_write_buf8(mtd, buf, len);
@@ -483,22 +492,6 @@ static int pmecc_get_ecc_bytes(int cap, int sector_size)
        return (m * cap + 7) / 8;
 }
 
-static void pmecc_config_ecc_layout(struct nand_ecclayout *layout,
-                                   int oobsize, int ecc_len)
-{
-       int i;
-
-       layout->eccbytes = ecc_len;
-
-       /* ECC will occupy the last ecc_len bytes continuously */
-       for (i = 0; i < ecc_len; i++)
-               layout->eccpos[i] = oobsize - ecc_len + i;
-
-       layout->oobfree[0].offset = PMECC_OOB_RESERVED_BYTES;
-       layout->oobfree[0].length =
-               oobsize - ecc_len - layout->oobfree[0].offset;
-}
-
 static void __iomem *pmecc_get_alpha_to(struct atmel_nand_host *host)
 {
        int table_size;
@@ -836,13 +829,16 @@ static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
                        dev_dbg(host->dev, "Bit flip in data area, byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
                                pos, bit_pos, err_byte, *(buf + byte_pos));
                } else {
+                       struct mtd_oob_region oobregion;
+
                        /* Bit flip in OOB area */
                        tmp = sector_num * nand_chip->ecc.bytes
                                        + (byte_pos - sector_size);
                        err_byte = ecc[tmp];
                        ecc[tmp] ^= (1 << bit_pos);
 
-                       pos = tmp + nand_chip->ecc.layout->eccpos[0];
+                       mtd_ooblayout_ecc(mtd, 0, &oobregion);
+                       pos = tmp + oobregion.offset;
                        dev_dbg(host->dev, "Bit flip in OOB, oob_byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
                                pos, bit_pos, err_byte, ecc[tmp]);
                }
@@ -863,17 +859,6 @@ static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
        uint8_t *buf_pos;
        int max_bitflips = 0;
 
-       /* If can correct bitfilps from erased page, do the normal check */
-       if (host->caps->pmecc_correct_erase_page)
-               goto normal_check;
-
-       for (i = 0; i < nand_chip->ecc.total; i++)
-               if (ecc[i] != 0xff)
-                       goto normal_check;
-       /* Erased page, return OK */
-       return 0;
-
-normal_check:
        for (i = 0; i < nand_chip->ecc.steps; i++) {
                err_nbr = 0;
                if (pmecc_stat & 0x1) {
@@ -884,16 +869,30 @@ normal_check:
                        pmecc_get_sigma(mtd);
 
                        err_nbr = pmecc_err_location(mtd);
-                       if (err_nbr == -1) {
+                       if (err_nbr >= 0) {
+                               pmecc_correct_data(mtd, buf_pos, ecc, i,
+                                                  nand_chip->ecc.bytes,
+                                                  err_nbr);
+                       } else if (!host->caps->pmecc_correct_erase_page) {
+                               u8 *ecc_pos = ecc + (i * nand_chip->ecc.bytes);
+
+                               /* Try to detect erased pages */
+                               err_nbr = nand_check_erased_ecc_chunk(buf_pos,
+                                                       host->pmecc_sector_size,
+                                                       ecc_pos,
+                                                       nand_chip->ecc.bytes,
+                                                       NULL, 0,
+                                                       nand_chip->ecc.strength);
+                       }
+
+                       if (err_nbr < 0) {
                                dev_err(host->dev, "PMECC: Too many errors\n");
                                mtd->ecc_stats.failed++;
                                return -EIO;
-                       } else {
-                               pmecc_correct_data(mtd, buf_pos, ecc, i,
-                                       nand_chip->ecc.bytes, err_nbr);
-                               mtd->ecc_stats.corrected += err_nbr;
-                               max_bitflips = max_t(int, max_bitflips, err_nbr);
                        }
+
+                       mtd->ecc_stats.corrected += err_nbr;
+                       max_bitflips = max_t(int, max_bitflips, err_nbr);
                }
                pmecc_stat >>= 1;
        }
@@ -931,7 +930,6 @@ static int atmel_nand_pmecc_read_page(struct mtd_info *mtd,
        struct atmel_nand_host *host = nand_get_controller_data(chip);
        int eccsize = chip->ecc.size * chip->ecc.steps;
        uint8_t *oob = chip->oob_poi;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint32_t stat;
        unsigned long end_time;
        int bitflips = 0;
@@ -953,7 +951,11 @@ static int atmel_nand_pmecc_read_page(struct mtd_info *mtd,
 
        stat = pmecc_readl_relaxed(host->ecc, ISR);
        if (stat != 0) {
-               bitflips = pmecc_correction(mtd, stat, buf, &oob[eccpos[0]]);
+               struct mtd_oob_region oobregion;
+
+               mtd_ooblayout_ecc(mtd, 0, &oobregion);
+               bitflips = pmecc_correction(mtd, stat, buf,
+                                           &oob[oobregion.offset]);
                if (bitflips < 0)
                        /* uncorrectable errors */
                        return 0;
@@ -967,8 +969,8 @@ static int atmel_nand_pmecc_write_page(struct mtd_info *mtd,
                int page)
 {
        struct atmel_nand_host *host = nand_get_controller_data(chip);
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
-       int i, j;
+       struct mtd_oob_region oobregion = { };
+       int i, j, section = 0;
        unsigned long end_time;
 
        if (!host->nfc || !host->nfc->write_by_sram) {
@@ -987,11 +989,14 @@ static int atmel_nand_pmecc_write_page(struct mtd_info *mtd,
 
        for (i = 0; i < chip->ecc.steps; i++) {
                for (j = 0; j < chip->ecc.bytes; j++) {
-                       int pos;
+                       if (!oobregion.length)
+                               mtd_ooblayout_ecc(mtd, section, &oobregion);
 
-                       pos = i * chip->ecc.bytes + j;
-                       chip->oob_poi[eccpos[pos]] =
+                       chip->oob_poi[oobregion.offset] =
                                pmecc_readb_ecc_relaxed(host->ecc, i, j);
+                       oobregion.length--;
+                       oobregion.offset++;
+                       section++;
                }
        }
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -1003,8 +1008,9 @@ static void atmel_pmecc_core_init(struct mtd_info *mtd)
 {
        struct nand_chip *nand_chip = mtd_to_nand(mtd);
        struct atmel_nand_host *host = nand_get_controller_data(nand_chip);
+       int eccbytes = mtd_ooblayout_count_eccbytes(mtd);
        uint32_t val = 0;
-       struct nand_ecclayout *ecc_layout;
+       struct mtd_oob_region oobregion;
 
        pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST);
        pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
@@ -1054,11 +1060,11 @@ static void atmel_pmecc_core_init(struct mtd_info *mtd)
                | PMECC_CFG_AUTO_DISABLE);
        pmecc_writel(host->ecc, CFG, val);
 
-       ecc_layout = nand_chip->ecc.layout;
        pmecc_writel(host->ecc, SAREA, mtd->oobsize - 1);
-       pmecc_writel(host->ecc, SADDR, ecc_layout->eccpos[0]);
+       mtd_ooblayout_ecc(mtd, 0, &oobregion);
+       pmecc_writel(host->ecc, SADDR, oobregion.offset);
        pmecc_writel(host->ecc, EADDR,
-                       ecc_layout->eccpos[ecc_layout->eccbytes - 1]);
+                    oobregion.offset + eccbytes - 1);
        /* See datasheet about PMECC Clock Control Register */
        pmecc_writel(host->ecc, CLK, 2);
        pmecc_writel(host->ecc, IDR, 0xff);
@@ -1206,6 +1212,7 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
                dev_warn(host->dev,
                        "Can't get I/O resource regs for PMECC controller, rolling back on software ECC\n");
                nand_chip->ecc.mode = NAND_ECC_SOFT;
+               nand_chip->ecc.algo = NAND_ECC_HAMMING;
                return 0;
        }
 
@@ -1280,11 +1287,8 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
                        err_no = -EINVAL;
                        goto err;
                }
-               pmecc_config_ecc_layout(&atmel_pmecc_oobinfo,
-                                       mtd->oobsize,
-                                       nand_chip->ecc.total);
 
-               nand_chip->ecc.layout = &atmel_pmecc_oobinfo;
+               mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                break;
        default:
                dev_warn(host->dev,
@@ -1292,6 +1296,7 @@ static int atmel_pmecc_nand_init_params(struct platform_device *pdev,
                /* page size not handled by HW ECC */
                /* switching back to soft ECC */
                nand_chip->ecc.mode = NAND_ECC_SOFT;
+               nand_chip->ecc.algo = NAND_ECC_HAMMING;
                return 0;
        }
 
@@ -1359,12 +1364,12 @@ static int atmel_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
 {
        int eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *p = buf;
        uint8_t *oob = chip->oob_poi;
        uint8_t *ecc_pos;
        int stat;
        unsigned int max_bitflips = 0;
+       struct mtd_oob_region oobregion = {};
 
        /*
         * Errata: ALE is incorrectly wired up to the ECC controller
@@ -1382,19 +1387,20 @@ static int atmel_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
        chip->read_buf(mtd, p, eccsize);
 
        /* move to ECC position if needed */
-       if (eccpos[0] != 0) {
-               /* This only works on large pages
-                * because the ECC controller waits for
-                * NAND_CMD_RNDOUTSTART after the
-                * NAND_CMD_RNDOUT.
-                * anyway, for small pages, the eccpos[0] == 0
+       mtd_ooblayout_ecc(mtd, 0, &oobregion);
+       if (oobregion.offset != 0) {
+               /*
+                * This only works on large pages because the ECC controller
+                * waits for NAND_CMD_RNDOUTSTART after the NAND_CMD_RNDOUT.
+                * Anyway, for small pages, the first ECC byte is at offset
+                * 0 in the OOB area.
                 */
                chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
-                               mtd->writesize + eccpos[0], -1);
+                             mtd->writesize + oobregion.offset, -1);
        }
 
        /* the ECC controller needs to read the ECC just after the data */
-       ecc_pos = oob + eccpos[0];
+       ecc_pos = oob + oobregion.offset;
        chip->read_buf(mtd, ecc_pos, eccbytes);
 
        /* check if there's an error */
@@ -1504,58 +1510,17 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
                ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
 }
 
-static int atmel_of_init_port(struct atmel_nand_host *host,
-                             struct device_node *np)
+static int atmel_of_init_ecc(struct atmel_nand_host *host,
+                            struct device_node *np)
 {
-       u32 val;
        u32 offset[2];
-       int ecc_mode;
-       struct atmel_nand_data *board = &host->board;
-       enum of_gpio_flags flags = 0;
-
-       host->caps = (struct atmel_nand_caps *)
-               of_device_get_match_data(host->dev);
-
-       if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
-               if (val >= 32) {
-                       dev_err(host->dev, "invalid addr-offset %u\n", val);
-                       return -EINVAL;
-               }
-               board->ale = val;
-       }
-
-       if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
-               if (val >= 32) {
-                       dev_err(host->dev, "invalid cmd-offset %u\n", val);
-                       return -EINVAL;
-               }
-               board->cle = val;
-       }
-
-       ecc_mode = of_get_nand_ecc_mode(np);
-
-       board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
-
-       board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
-
-       board->has_dma = of_property_read_bool(np, "atmel,nand-has-dma");
-
-       if (of_get_nand_bus_width(np) == 16)
-               board->bus_width_16 = 1;
-
-       board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
-       board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
-
-       board->enable_pin = of_get_gpio(np, 1);
-       board->det_pin = of_get_gpio(np, 2);
+       u32 val;
 
        host->has_pmecc = of_property_read_bool(np, "atmel,has-pmecc");
 
-       /* load the nfc driver if there is */
-       of_platform_populate(np, NULL, NULL, host->dev);
-
-       if (!(board->ecc_mode == NAND_ECC_HW) || !host->has_pmecc)
-               return 0;       /* Not using PMECC */
+       /* Not using PMECC */
+       if (!(host->nand_chip.ecc.mode == NAND_ECC_HW) || !host->has_pmecc)
+               return 0;
 
        /* use PMECC, get correction capability, sector size and lookup
         * table offset.
@@ -1596,16 +1561,65 @@ static int atmel_of_init_port(struct atmel_nand_host *host,
                /* Will build a lookup table and initialize the offset later */
                return 0;
        }
+
        if (!offset[0] && !offset[1]) {
                dev_err(host->dev, "Invalid PMECC lookup table offset\n");
                return -EINVAL;
        }
+
        host->pmecc_lookup_table_offset_512 = offset[0];
        host->pmecc_lookup_table_offset_1024 = offset[1];
 
        return 0;
 }
 
+static int atmel_of_init_port(struct atmel_nand_host *host,
+                             struct device_node *np)
+{
+       u32 val;
+       struct atmel_nand_data *board = &host->board;
+       enum of_gpio_flags flags = 0;
+
+       host->caps = (struct atmel_nand_caps *)
+               of_device_get_match_data(host->dev);
+
+       if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
+               if (val >= 32) {
+                       dev_err(host->dev, "invalid addr-offset %u\n", val);
+                       return -EINVAL;
+               }
+               board->ale = val;
+       }
+
+       if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
+               if (val >= 32) {
+                       dev_err(host->dev, "invalid cmd-offset %u\n", val);
+                       return -EINVAL;
+               }
+               board->cle = val;
+       }
+
+       board->has_dma = of_property_read_bool(np, "atmel,nand-has-dma");
+
+       board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
+       board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
+
+       board->enable_pin = of_get_gpio(np, 1);
+       board->det_pin = of_get_gpio(np, 2);
+
+       /* load the nfc driver if there is */
+       of_platform_populate(np, NULL, NULL, host->dev);
+
+       /*
+        * Initialize ECC mode to NAND_ECC_SOFT so that we have a correct value
+        * even if the nand-ecc-mode property is not defined.
+        */
+       host->nand_chip.ecc.mode = NAND_ECC_SOFT;
+       host->nand_chip.ecc.algo = NAND_ECC_HAMMING;
+
+       return 0;
+}
+
 static int atmel_hw_nand_init_params(struct platform_device *pdev,
                                         struct atmel_nand_host *host)
 {
@@ -1618,6 +1632,7 @@ static int atmel_hw_nand_init_params(struct platform_device *pdev,
                dev_err(host->dev,
                        "Can't get I/O resource regs, use software ECC\n");
                nand_chip->ecc.mode = NAND_ECC_SOFT;
+               nand_chip->ecc.algo = NAND_ECC_HAMMING;
                return 0;
        }
 
@@ -1631,25 +1646,26 @@ static int atmel_hw_nand_init_params(struct platform_device *pdev,
        /* set ECC page size and oob layout */
        switch (mtd->writesize) {
        case 512:
-               nand_chip->ecc.layout = &atmel_oobinfo_small;
+               mtd_set_ooblayout(mtd, &atmel_ooblayout_sp_ops);
                ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_528);
                break;
        case 1024:
-               nand_chip->ecc.layout = &atmel_oobinfo_large;
+               mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_1056);
                break;
        case 2048:
-               nand_chip->ecc.layout = &atmel_oobinfo_large;
+               mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_2112);
                break;
        case 4096:
-               nand_chip->ecc.layout = &atmel_oobinfo_large;
+               mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_4224);
                break;
        default:
                /* page size not handled by HW ECC */
                /* switching back to soft ECC */
                nand_chip->ecc.mode = NAND_ECC_SOFT;
+               nand_chip->ecc.algo = NAND_ECC_HAMMING;
                return 0;
        }
 
@@ -2147,6 +2163,19 @@ static int atmel_nand_probe(struct platform_device *pdev)
        } else {
                memcpy(&host->board, dev_get_platdata(&pdev->dev),
                       sizeof(struct atmel_nand_data));
+               nand_chip->ecc.mode = host->board.ecc_mode;
+
+               /*
+                * When using software ECC every supported avr32 board means
+                * Hamming algorithm. If that ever changes we'll need to add
+                * ecc_algo field to the struct atmel_nand_data.
+                */
+               if (nand_chip->ecc.mode == NAND_ECC_SOFT)
+                       nand_chip->ecc.algo = NAND_ECC_HAMMING;
+
+               /* 16-bit bus width */
+               if (host->board.bus_width_16)
+                       nand_chip->options |= NAND_BUSWIDTH_16;
        }
 
         /* link the private data structures */
@@ -2188,11 +2217,8 @@ static int atmel_nand_probe(struct platform_device *pdev)
                nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
        }
 
-       nand_chip->ecc.mode = host->board.ecc_mode;
        nand_chip->chip_delay = 40;             /* 40us command delay time */
 
-       if (host->board.bus_width_16)   /* 16-bit bus width */
-               nand_chip->options |= NAND_BUSWIDTH_16;
 
        nand_chip->read_buf = atmel_read_buf;
        nand_chip->write_buf = atmel_write_buf;
@@ -2225,11 +2251,6 @@ static int atmel_nand_probe(struct platform_device *pdev)
                }
        }
 
-       if (host->board.on_flash_bbt || on_flash_bbt) {
-               dev_info(&pdev->dev, "Use On Flash BBT\n");
-               nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
-       }
-
        if (!host->board.has_dma)
                use_dma = 0;
 
@@ -2256,6 +2277,18 @@ static int atmel_nand_probe(struct platform_device *pdev)
                goto err_scan_ident;
        }
 
+       if (host->board.on_flash_bbt || on_flash_bbt)
+               nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
+
+       if (nand_chip->bbt_options & NAND_BBT_USE_FLASH)
+               dev_info(&pdev->dev, "Use On Flash BBT\n");
+
+       if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
+               res = atmel_of_init_ecc(host, pdev->dev.of_node);
+               if (res)
+                       goto err_hw_ecc;
+       }
+
        if (nand_chip->ecc.mode == NAND_ECC_HW) {
                if (host->has_pmecc)
                        res = atmel_pmecc_nand_init_params(pdev, host);
index 341ea4904164dec5dcfebac0ebf487eceaac2d88..9bf6d9915694e0cd69708fd0a3d4cc7f706968ae 100644 (file)
@@ -459,6 +459,7 @@ static int au1550nd_probe(struct platform_device *pdev)
        /* 30 us command delay time */
        this->chip_delay = 30;
        this->ecc.mode = NAND_ECC_SOFT;
+       this->ecc.algo = NAND_ECC_HAMMING;
 
        if (pd->devwidth)
                this->options |= NAND_BUSWIDTH_16;
index 7f6b30e615b7f47c2863fc5c11d33de24c319c43..37da4236ab908099217184bd310a567365396192 100644 (file)
@@ -109,28 +109,33 @@ static const unsigned short bfin_nfc_pin_req[] =
         0};
 
 #ifdef CONFIG_MTD_NAND_BF5XX_BOOTROM_ECC
-static struct nand_ecclayout bootrom_ecclayout = {
-       .eccbytes = 24,
-       .eccpos = {
-               0x8 * 0, 0x8 * 0 + 1, 0x8 * 0 + 2,
-               0x8 * 1, 0x8 * 1 + 1, 0x8 * 1 + 2,
-               0x8 * 2, 0x8 * 2 + 1, 0x8 * 2 + 2,
-               0x8 * 3, 0x8 * 3 + 1, 0x8 * 3 + 2,
-               0x8 * 4, 0x8 * 4 + 1, 0x8 * 4 + 2,
-               0x8 * 5, 0x8 * 5 + 1, 0x8 * 5 + 2,
-               0x8 * 6, 0x8 * 6 + 1, 0x8 * 6 + 2,
-               0x8 * 7, 0x8 * 7 + 1, 0x8 * 7 + 2
-       },
-       .oobfree = {
-               { 0x8 * 0 + 3, 5 },
-               { 0x8 * 1 + 3, 5 },
-               { 0x8 * 2 + 3, 5 },
-               { 0x8 * 3 + 3, 5 },
-               { 0x8 * 4 + 3, 5 },
-               { 0x8 * 5 + 3, 5 },
-               { 0x8 * 6 + 3, 5 },
-               { 0x8 * 7 + 3, 5 },
-       }
+static int bootrom_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       if (section > 7)
+               return -ERANGE;
+
+       oobregion->offset = section * 8;
+       oobregion->length = 3;
+
+       return 0;
+}
+
+static int bootrom_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section > 7)
+               return -ERANGE;
+
+       oobregion->offset = (section * 8) + 3;
+       oobregion->length = 5;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops bootrom_ooblayout_ops = {
+       .ecc = bootrom_ooblayout_ecc,
+       .free = bootrom_ooblayout_free,
 };
 #endif
 
@@ -800,7 +805,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
        /* setup hardware ECC data struct */
        if (hardware_ecc) {
 #ifdef CONFIG_MTD_NAND_BF5XX_BOOTROM_ECC
-               chip->ecc.layout = &bootrom_ecclayout;
+               mtd_set_ooblayout(mtd, &bootrom_ooblayout_ops);
 #endif
                chip->read_buf      = bf5xx_nand_dma_read_buf;
                chip->write_buf     = bf5xx_nand_dma_write_buf;
@@ -812,6 +817,7 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
                chip->ecc.write_page_raw = bf5xx_nand_write_page_raw;
        } else {
                chip->ecc.mode      = NAND_ECC_SOFT;
+               chip->ecc.algo  = NAND_ECC_HAMMING;
        }
 
        /* scan hardware nand chip and setup mtd info data struct */
index e0528397306a4d92d0a2624835c42b96f91e5897..b76ad7c0144f7501e7de328c8c0175690df3a039 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
-#include <linux/of_mtd.h>
 #include <linux/of_platform.h>
 #include <linux/slab.h>
 #include <linux/list.h>
@@ -601,7 +600,7 @@ static void brcmnand_wr_corr_thresh(struct brcmnand_host *host, u8 val)
 
 static inline int brcmnand_cmd_shift(struct brcmnand_controller *ctrl)
 {
-       if (ctrl->nand_version < 0x0700)
+       if (ctrl->nand_version < 0x0602)
                return 24;
        return 0;
 }
@@ -781,127 +780,183 @@ static inline bool is_hamming_ecc(struct brcmnand_cfg *cfg)
 }
 
 /*
- * Returns a nand_ecclayout strucutre for the given layout/configuration.
- * Returns NULL on failure.
+ * Set mtd->ooblayout to the appropriate mtd_ooblayout_ops given
+ * the layout/configuration.
+ * Returns -ERRCODE on failure.
  */
-static struct nand_ecclayout *brcmnand_create_layout(int ecc_level,
-                                                    struct brcmnand_host *host)
+static int brcmnand_hamming_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                         struct mtd_oob_region *oobregion)
 {
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct brcmnand_host *host = nand_get_controller_data(chip);
        struct brcmnand_cfg *cfg = &host->hwcfg;
-       int i, j;
-       struct nand_ecclayout *layout;
-       int req;
-       int sectors;
-       int sas;
-       int idx1, idx2;
-
-       layout = devm_kzalloc(&host->pdev->dev, sizeof(*layout), GFP_KERNEL);
-       if (!layout)
-               return NULL;
-
-       sectors = cfg->page_size / (512 << cfg->sector_size_1k);
-       sas = cfg->spare_area_size << cfg->sector_size_1k;
-
-       /* Hamming */
-       if (is_hamming_ecc(cfg)) {
-               for (i = 0, idx1 = 0, idx2 = 0; i < sectors; i++) {
-                       /* First sector of each page may have BBI */
-                       if (i == 0) {
-                               layout->oobfree[idx2].offset = i * sas + 1;
-                               /* Small-page NAND use byte 6 for BBI */
-                               if (cfg->page_size == 512)
-                                       layout->oobfree[idx2].offset--;
-                               layout->oobfree[idx2].length = 5;
-                       } else {
-                               layout->oobfree[idx2].offset = i * sas;
-                               layout->oobfree[idx2].length = 6;
-                       }
-                       idx2++;
-                       layout->eccpos[idx1++] = i * sas + 6;
-                       layout->eccpos[idx1++] = i * sas + 7;
-                       layout->eccpos[idx1++] = i * sas + 8;
-                       layout->oobfree[idx2].offset = i * sas + 9;
-                       layout->oobfree[idx2].length = 7;
-                       idx2++;
-                       /* Leave zero-terminated entry for OOBFREE */
-                       if (idx1 >= MTD_MAX_ECCPOS_ENTRIES_LARGE ||
-                                   idx2 >= MTD_MAX_OOBFREE_ENTRIES_LARGE - 1)
-                               break;
-               }
+       int sas = cfg->spare_area_size << cfg->sector_size_1k;
+       int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
 
-               return layout;
-       }
+       if (section >= sectors)
+               return -ERANGE;
 
-       /*
-        * CONTROLLER_VERSION:
-        *   < v5.0: ECC_REQ = ceil(BCH_T * 13/8)
-        *  >= v5.0: ECC_REQ = ceil(BCH_T * 14/8)
-        * But we will just be conservative.
-        */
-       req = DIV_ROUND_UP(ecc_level * 14, 8);
-       if (req >= sas) {
-               dev_err(&host->pdev->dev,
-                       "error: ECC too large for OOB (ECC bytes %d, spare sector %d)\n",
-                       req, sas);
-               return NULL;
-       }
+       oobregion->offset = (section * sas) + 6;
+       oobregion->length = 3;
+
+       return 0;
+}
+
+static int brcmnand_hamming_ooblayout_free(struct mtd_info *mtd, int section,
+                                          struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct brcmnand_host *host = nand_get_controller_data(chip);
+       struct brcmnand_cfg *cfg = &host->hwcfg;
+       int sas = cfg->spare_area_size << cfg->sector_size_1k;
+       int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
 
-       layout->eccbytes = req * sectors;
-       for (i = 0, idx1 = 0, idx2 = 0; i < sectors; i++) {
-               for (j = sas - req; j < sas && idx1 <
-                               MTD_MAX_ECCPOS_ENTRIES_LARGE; j++, idx1++)
-                       layout->eccpos[idx1] = i * sas + j;
+       if (section >= sectors * 2)
+               return -ERANGE;
+
+       oobregion->offset = (section / 2) * sas;
+
+       if (section & 1) {
+               oobregion->offset += 9;
+               oobregion->length = 7;
+       } else {
+               oobregion->length = 6;
 
                /* First sector of each page may have BBI */
-               if (i == 0) {
-                       if (cfg->page_size == 512 && (sas - req >= 6)) {
-                               /* Small-page NAND use byte 6 for BBI */
-                               layout->oobfree[idx2].offset = 0;
-                               layout->oobfree[idx2].length = 5;
-                               idx2++;
-                               if (sas - req > 6) {
-                                       layout->oobfree[idx2].offset = 6;
-                                       layout->oobfree[idx2].length =
-                                               sas - req - 6;
-                                       idx2++;
-                               }
-                       } else if (sas > req + 1) {
-                               layout->oobfree[idx2].offset = i * sas + 1;
-                               layout->oobfree[idx2].length = sas - req - 1;
-                               idx2++;
-                       }
-               } else if (sas > req) {
-                       layout->oobfree[idx2].offset = i * sas;
-                       layout->oobfree[idx2].length = sas - req;
-                       idx2++;
+               if (!section) {
+                       /*
+                        * Small-page NAND use byte 6 for BBI while large-page
+                        * NAND use byte 0.
+                        */
+                       if (cfg->page_size > 512)
+                               oobregion->offset++;
+                       oobregion->length--;
                }
-               /* Leave zero-terminated entry for OOBFREE */
-               if (idx1 >= MTD_MAX_ECCPOS_ENTRIES_LARGE ||
-                               idx2 >= MTD_MAX_OOBFREE_ENTRIES_LARGE - 1)
-                       break;
        }
 
-       return layout;
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops brcmnand_hamming_ooblayout_ops = {
+       .ecc = brcmnand_hamming_ooblayout_ecc,
+       .free = brcmnand_hamming_ooblayout_free,
+};
+
+static int brcmnand_bch_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                     struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct brcmnand_host *host = nand_get_controller_data(chip);
+       struct brcmnand_cfg *cfg = &host->hwcfg;
+       int sas = cfg->spare_area_size << cfg->sector_size_1k;
+       int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
+
+       if (section >= sectors)
+               return -ERANGE;
+
+       oobregion->offset = (section * (sas + 1)) - chip->ecc.bytes;
+       oobregion->length = chip->ecc.bytes;
+
+       return 0;
+}
+
+static int brcmnand_bch_ooblayout_free_lp(struct mtd_info *mtd, int section,
+                                         struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct brcmnand_host *host = nand_get_controller_data(chip);
+       struct brcmnand_cfg *cfg = &host->hwcfg;
+       int sas = cfg->spare_area_size << cfg->sector_size_1k;
+       int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
+
+       if (section >= sectors)
+               return -ERANGE;
+
+       if (sas <= chip->ecc.bytes)
+               return 0;
+
+       oobregion->offset = section * sas;
+       oobregion->length = sas - chip->ecc.bytes;
+
+       if (!section) {
+               oobregion->offset++;
+               oobregion->length--;
+       }
+
+       return 0;
 }
 
-static struct nand_ecclayout *brcmstb_choose_ecc_layout(
-               struct brcmnand_host *host)
+static int brcmnand_bch_ooblayout_free_sp(struct mtd_info *mtd, int section,
+                                         struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct brcmnand_host *host = nand_get_controller_data(chip);
+       struct brcmnand_cfg *cfg = &host->hwcfg;
+       int sas = cfg->spare_area_size << cfg->sector_size_1k;
+
+       if (section > 1 || sas - chip->ecc.bytes < 6 ||
+           (section && sas - chip->ecc.bytes == 6))
+               return -ERANGE;
+
+       if (!section) {
+               oobregion->offset = 0;
+               oobregion->length = 5;
+       } else {
+               oobregion->offset = 6;
+               oobregion->length = sas - chip->ecc.bytes - 6;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops brcmnand_bch_lp_ooblayout_ops = {
+       .ecc = brcmnand_bch_ooblayout_ecc,
+       .free = brcmnand_bch_ooblayout_free_lp,
+};
+
+static const struct mtd_ooblayout_ops brcmnand_bch_sp_ooblayout_ops = {
+       .ecc = brcmnand_bch_ooblayout_ecc,
+       .free = brcmnand_bch_ooblayout_free_sp,
+};
+
+static int brcmstb_choose_ecc_layout(struct brcmnand_host *host)
 {
-       struct nand_ecclayout *layout;
        struct brcmnand_cfg *p = &host->hwcfg;
+       struct mtd_info *mtd = nand_to_mtd(&host->chip);
+       struct nand_ecc_ctrl *ecc = &host->chip.ecc;
        unsigned int ecc_level = p->ecc_level;
+       int sas = p->spare_area_size << p->sector_size_1k;
+       int sectors = p->page_size / (512 << p->sector_size_1k);
 
        if (p->sector_size_1k)
                ecc_level <<= 1;
 
-       layout = brcmnand_create_layout(ecc_level, host);
-       if (!layout) {
+       if (is_hamming_ecc(p)) {
+               ecc->bytes = 3 * sectors;
+               mtd_set_ooblayout(mtd, &brcmnand_hamming_ooblayout_ops);
+               return 0;
+       }
+
+       /*
+        * CONTROLLER_VERSION:
+        *   < v5.0: ECC_REQ = ceil(BCH_T * 13/8)
+        *  >= v5.0: ECC_REQ = ceil(BCH_T * 14/8)
+        * But we will just be conservative.
+        */
+       ecc->bytes = DIV_ROUND_UP(ecc_level * 14, 8);
+       if (p->page_size == 512)
+               mtd_set_ooblayout(mtd, &brcmnand_bch_sp_ooblayout_ops);
+       else
+               mtd_set_ooblayout(mtd, &brcmnand_bch_lp_ooblayout_ops);
+
+       if (ecc->bytes >= sas) {
                dev_err(&host->pdev->dev,
-                               "no proper ecc_layout for this NAND cfg\n");
-               return NULL;
+                       "error: ECC too large for OOB (ECC bytes %d, spare sector %d)\n",
+                       ecc->bytes, sas);
+               return -EINVAL;
        }
 
-       return layout;
+       return 0;
 }
 
 static void brcmnand_wp(struct mtd_info *mtd, int wp)
@@ -1870,9 +1925,31 @@ static int brcmnand_setup_dev(struct brcmnand_host *host)
        cfg->col_adr_bytes = 2;
        cfg->blk_adr_bytes = get_blk_adr_bytes(mtd->size, mtd->writesize);
 
+       if (chip->ecc.mode != NAND_ECC_HW) {
+               dev_err(ctrl->dev, "only HW ECC supported; selected: %d\n",
+                       chip->ecc.mode);
+               return -EINVAL;
+       }
+
+       if (chip->ecc.algo == NAND_ECC_UNKNOWN) {
+               if (chip->ecc.strength == 1 && chip->ecc.size == 512)
+                       /* Default to Hamming for 1-bit ECC, if unspecified */
+                       chip->ecc.algo = NAND_ECC_HAMMING;
+               else
+                       /* Otherwise, BCH */
+                       chip->ecc.algo = NAND_ECC_BCH;
+       }
+
+       if (chip->ecc.algo == NAND_ECC_HAMMING && (chip->ecc.strength != 1 ||
+                                                  chip->ecc.size != 512)) {
+               dev_err(ctrl->dev, "invalid Hamming params: %d bits per %d bytes\n",
+                       chip->ecc.strength, chip->ecc.size);
+               return -EINVAL;
+       }
+
        switch (chip->ecc.size) {
        case 512:
-               if (chip->ecc.strength == 1) /* Hamming */
+               if (chip->ecc.algo == NAND_ECC_HAMMING)
                        cfg->ecc_level = 15;
                else
                        cfg->ecc_level = chip->ecc.strength;
@@ -2001,8 +2078,8 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
         */
        chip->options |= NAND_USE_BOUNCE_BUFFER;
 
-       if (of_get_nand_on_flash_bbt(dn))
-               chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
+       if (chip->bbt_options & NAND_BBT_USE_FLASH)
+               chip->bbt_options |= NAND_BBT_NO_OOB;
 
        if (brcmnand_setup_dev(host))
                return -ENXIO;
@@ -2011,9 +2088,9 @@ static int brcmnand_init_cs(struct brcmnand_host *host, struct device_node *dn)
        /* only use our internal HW threshold */
        mtd->bitflip_threshold = 1;
 
-       chip->ecc.layout = brcmstb_choose_ecc_layout(host);
-       if (!chip->ecc.layout)
-               return -ENXIO;
+       ret = brcmstb_choose_ecc_layout(host);
+       if (ret)
+               return ret;
 
        if (nand_scan_tail(mtd))
                return -ENXIO;
@@ -2115,6 +2192,7 @@ static const struct of_device_id brcmnand_of_match[] = {
        { .compatible = "brcm,brcmnand-v5.0" },
        { .compatible = "brcm,brcmnand-v6.0" },
        { .compatible = "brcm,brcmnand-v6.1" },
+       { .compatible = "brcm,brcmnand-v6.2" },
        { .compatible = "brcm,brcmnand-v7.0" },
        { .compatible = "brcm,brcmnand-v7.1" },
        {},
index e553aff689878ff6ef5185155eee71506b24d550..0b0c93702abbd43c96b4e48eda148db9d36ddbee 100644 (file)
@@ -459,10 +459,37 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
        return max_bitflips;
 }
 
-static struct nand_ecclayout cafe_oobinfo_2048 = {
-       .eccbytes = 14,
-       .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
-       .oobfree = {{14, 50}}
+static int cafe_ooblayout_ecc(struct mtd_info *mtd, int section,
+                             struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 0;
+       oobregion->length = chip->ecc.total;
+
+       return 0;
+}
+
+static int cafe_ooblayout_free(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = chip->ecc.total;
+       oobregion->length = mtd->oobsize - chip->ecc.total;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops cafe_ooblayout_ops = {
+       .ecc = cafe_ooblayout_ecc,
+       .free = cafe_ooblayout_free,
 };
 
 /* Ick. The BBT code really ought to be able to work this bit out
@@ -494,12 +521,6 @@ static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = {
        .pattern = cafe_mirror_pattern_2048
 };
 
-static struct nand_ecclayout cafe_oobinfo_512 = {
-       .eccbytes = 14,
-       .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
-       .oobfree = {{14, 2}}
-};
-
 static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
        .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
                | NAND_BBT_2BIT | NAND_BBT_VERSION,
@@ -743,12 +764,11 @@ static int cafe_nand_probe(struct pci_dev *pdev,
                cafe->ctl2 |= 1<<29; /* 2KiB page size */
 
        /* Set up ECC according to the type of chip we found */
+       mtd_set_ooblayout(mtd, &cafe_ooblayout_ops);
        if (mtd->writesize == 2048) {
-               cafe->nand.ecc.layout = &cafe_oobinfo_2048;
                cafe->nand.bbt_td = &cafe_bbt_main_descr_2048;
                cafe->nand.bbt_md = &cafe_bbt_mirror_descr_2048;
        } else if (mtd->writesize == 512) {
-               cafe->nand.ecc.layout = &cafe_oobinfo_512;
                cafe->nand.bbt_td = &cafe_bbt_main_descr_512;
                cafe->nand.bbt_md = &cafe_bbt_mirror_descr_512;
        } else {
index 6f97ebba52c4c1136bebf752a20578aaa8ecca0a..49133783ca5363f723cb2b9983f02e6ef9ba6b40 100644 (file)
@@ -187,6 +187,7 @@ static int __init cmx270_init(void)
        /* 15 us command delay time */
        this->chip_delay = 20;
        this->ecc.mode = NAND_ECC_SOFT;
+       this->ecc.algo = NAND_ECC_HAMMING;
 
        /* read/write functions */
        this->read_byte = cmx270_read_byte;
index 8cb821b6686efea3c22854946a5031718c598f94..cc07ba0f044deeb167772c529a635236377d983b 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/slab.h>
 #include <linux/of_device.h>
 #include <linux/of.h>
-#include <linux/of_mtd.h>
 
 #include <linux/platform_data/mtd-davinci.h>
 #include <linux/platform_data/mtd-davinci-aemif.h>
@@ -54,7 +53,6 @@
  */
 struct davinci_nand_info {
        struct nand_chip        chip;
-       struct nand_ecclayout   ecclayout;
 
        struct device           *dev;
        struct clk              *clk;
@@ -480,63 +478,46 @@ static int nand_davinci_dev_ready(struct mtd_info *mtd)
  * ten ECC bytes plus the manufacturer's bad block marker byte, and
  * and not overlapping the default BBT markers.
  */
-static struct nand_ecclayout hwecc4_small = {
-       .eccbytes = 10,
-       .eccpos = { 0, 1, 2, 3, 4,
-               /* offset 5 holds the badblock marker */
-               6, 7,
-               13, 14, 15, },
-       .oobfree = {
-               {.offset = 8, .length = 5, },
-               {.offset = 16, },
-       },
-};
+static int hwecc4_ooblayout_small_ecc(struct mtd_info *mtd, int section,
+                                     struct mtd_oob_region *oobregion)
+{
+       if (section > 2)
+               return -ERANGE;
+
+       if (!section) {
+               oobregion->offset = 0;
+               oobregion->length = 5;
+       } else if (section == 1) {
+               oobregion->offset = 6;
+               oobregion->length = 2;
+       } else {
+               oobregion->offset = 13;
+               oobregion->length = 3;
+       }
 
-/* An ECC layout for using 4-bit ECC with large-page (2048bytes) flash,
- * storing ten ECC bytes plus the manufacturer's bad block marker byte,
- * and not overlapping the default BBT markers.
- */
-static struct nand_ecclayout hwecc4_2048 = {
-       .eccbytes = 40,
-       .eccpos = {
-               /* at the end of spare sector */
-               24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
-               34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
-               44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
-               54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-               },
-       .oobfree = {
-               /* 2 bytes at offset 0 hold manufacturer badblock markers */
-               {.offset = 2, .length = 22, },
-               /* 5 bytes at offset 8 hold BBT markers */
-               /* 8 bytes at offset 16 hold JFFS2 clean markers */
-       },
-};
+       return 0;
+}
 
-/*
- * An ECC layout for using 4-bit ECC with large-page (4096bytes) flash,
- * storing ten ECC bytes plus the manufacturer's bad block marker byte,
- * and not overlapping the default BBT markers.
- */
-static struct nand_ecclayout hwecc4_4096 = {
-       .eccbytes = 80,
-       .eccpos = {
-               /* at the end of spare sector */
-               48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
-               58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
-               68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
-               78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
-               88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
-               98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
-               108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
-               118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-       },
-       .oobfree = {
-               /* 2 bytes at offset 0 hold manufacturer badblock markers */
-               {.offset = 2, .length = 46, },
-               /* 5 bytes at offset 8 hold BBT markers */
-               /* 8 bytes at offset 16 hold JFFS2 clean markers */
-       },
+static int hwecc4_ooblayout_small_free(struct mtd_info *mtd, int section,
+                                      struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       if (!section) {
+               oobregion->offset = 8;
+               oobregion->length = 5;
+       } else {
+               oobregion->offset = 16;
+               oobregion->length = mtd->oobsize - 16;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops hwecc4_small_ooblayout_ops = {
+       .ecc = hwecc4_ooblayout_small_ecc,
+       .free = hwecc4_ooblayout_small_free,
 };
 
 #if defined(CONFIG_OF)
@@ -577,8 +558,6 @@ static struct davinci_nand_pdata
                        "ti,davinci-mask-chipsel", &prop))
                        pdata->mask_chipsel = prop;
                if (!of_property_read_string(pdev->dev.of_node,
-                       "nand-ecc-mode", &mode) ||
-                   !of_property_read_string(pdev->dev.of_node,
                        "ti,davinci-ecc-mode", &mode)) {
                        if (!strncmp("none", mode, 4))
                                pdata->ecc_mode = NAND_ECC_NONE;
@@ -591,14 +570,11 @@ static struct davinci_nand_pdata
                        "ti,davinci-ecc-bits", &prop))
                        pdata->ecc_bits = prop;
 
-               prop = of_get_nand_bus_width(pdev->dev.of_node);
-               if (0 < prop || !of_property_read_u32(pdev->dev.of_node,
-                       "ti,davinci-nand-buswidth", &prop))
-                       if (prop == 16)
-                               pdata->options |= NAND_BUSWIDTH_16;
+               if (!of_property_read_u32(pdev->dev.of_node,
+                       "ti,davinci-nand-buswidth", &prop) && prop == 16)
+                       pdata->options |= NAND_BUSWIDTH_16;
+
                if (of_property_read_bool(pdev->dev.of_node,
-                       "nand-on-flash-bbt") ||
-                   of_property_read_bool(pdev->dev.of_node,
                        "ti,davinci-nand-use-bbt"))
                        pdata->bbt_options = NAND_BBT_USE_FLASH;
 
@@ -628,7 +604,6 @@ static int nand_davinci_probe(struct platform_device *pdev)
        void __iomem                    *base;
        int                             ret;
        uint32_t                        val;
-       nand_ecc_modes_t                ecc_mode;
        struct mtd_info                 *mtd;
 
        pdata = nand_davinci_get_pdata(pdev);
@@ -712,13 +687,53 @@ static int nand_davinci_probe(struct platform_device *pdev)
        info->chip.write_buf    = nand_davinci_write_buf;
 
        /* Use board-specific ECC config */
-       ecc_mode                = pdata->ecc_mode;
+       info->chip.ecc.mode     = pdata->ecc_mode;
 
        ret = -EINVAL;
-       switch (ecc_mode) {
+
+       info->clk = devm_clk_get(&pdev->dev, "aemif");
+       if (IS_ERR(info->clk)) {
+               ret = PTR_ERR(info->clk);
+               dev_dbg(&pdev->dev, "unable to get AEMIF clock, err %d\n", ret);
+               return ret;
+       }
+
+       ret = clk_prepare_enable(info->clk);
+       if (ret < 0) {
+               dev_dbg(&pdev->dev, "unable to enable AEMIF clock, err %d\n",
+                       ret);
+               goto err_clk_enable;
+       }
+
+       spin_lock_irq(&davinci_nand_lock);
+
+       /* put CSxNAND into NAND mode */
+       val = davinci_nand_readl(info, NANDFCR_OFFSET);
+       val |= BIT(info->core_chipsel);
+       davinci_nand_writel(info, NANDFCR_OFFSET, val);
+
+       spin_unlock_irq(&davinci_nand_lock);
+
+       /* Scan to find existence of the device(s) */
+       ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL);
+       if (ret < 0) {
+               dev_dbg(&pdev->dev, "no NAND chip(s) found\n");
+               goto err;
+       }
+
+       switch (info->chip.ecc.mode) {
        case NAND_ECC_NONE:
+               pdata->ecc_bits = 0;
+               break;
        case NAND_ECC_SOFT:
                pdata->ecc_bits = 0;
+               /*
+                * This driver expects Hamming based ECC when ecc_mode is set
+                * to NAND_ECC_SOFT. Force ecc.algo to NAND_ECC_HAMMING to
+                * avoid adding an extra ->ecc_algo field to
+                * davinci_nand_pdata.
+                */
+               info->chip.ecc.algo = NAND_ECC_HAMMING;
                break;
        case NAND_ECC_HW:
                if (pdata->ecc_bits == 4) {
@@ -754,37 +769,6 @@ static int nand_davinci_probe(struct platform_device *pdev)
        default:
                return -EINVAL;
        }
-       info->chip.ecc.mode = ecc_mode;
-
-       info->clk = devm_clk_get(&pdev->dev, "aemif");
-       if (IS_ERR(info->clk)) {
-               ret = PTR_ERR(info->clk);
-               dev_dbg(&pdev->dev, "unable to get AEMIF clock, err %d\n", ret);
-               return ret;
-       }
-
-       ret = clk_prepare_enable(info->clk);
-       if (ret < 0) {
-               dev_dbg(&pdev->dev, "unable to enable AEMIF clock, err %d\n",
-                       ret);
-               goto err_clk_enable;
-       }
-
-       spin_lock_irq(&davinci_nand_lock);
-
-       /* put CSxNAND into NAND mode */
-       val = davinci_nand_readl(info, NANDFCR_OFFSET);
-       val |= BIT(info->core_chipsel);
-       davinci_nand_writel(info, NANDFCR_OFFSET, val);
-
-       spin_unlock_irq(&davinci_nand_lock);
-
-       /* Scan to find existence of the device(s) */
-       ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL);
-       if (ret < 0) {
-               dev_dbg(&pdev->dev, "no NAND chip(s) found\n");
-               goto err;
-       }
 
        /* Update ECC layout if needed ... for 1-bit HW ECC, the default
         * is OK, but it allocates 6 bytes when only 3 are needed (for
@@ -805,26 +789,14 @@ static int nand_davinci_probe(struct platform_device *pdev)
                 * table marker fits in the free bytes.
                 */
                if (chunks == 1) {
-                       info->ecclayout = hwecc4_small;
-                       info->ecclayout.oobfree[1].length = mtd->oobsize - 16;
-                       goto syndrome_done;
-               }
-               if (chunks == 4) {
-                       info->ecclayout = hwecc4_2048;
-                       info->chip.ecc.mode = NAND_ECC_HW_OOB_FIRST;
-                       goto syndrome_done;
-               }
-               if (chunks == 8) {
-                       info->ecclayout = hwecc4_4096;
+                       mtd_set_ooblayout(mtd, &hwecc4_small_ooblayout_ops);
+               } else if (chunks == 4 || chunks == 8) {
+                       mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                        info->chip.ecc.mode = NAND_ECC_HW_OOB_FIRST;
-                       goto syndrome_done;
+               } else {
+                       ret = -EIO;
+                       goto err;
                }
-
-               ret = -EIO;
-               goto err;
-
-syndrome_done:
-               info->chip.ecc.layout = &info->ecclayout;
        }
 
        ret = nand_scan_tail(mtd);
@@ -850,7 +822,7 @@ err:
 
 err_clk_enable:
        spin_lock_irq(&davinci_nand_lock);
-       if (ecc_mode == NAND_ECC_HW_SYNDROME)
+       if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME)
                ecc4_busy = false;
        spin_unlock_irq(&davinci_nand_lock);
        return ret;
index 30bf5f690f787aefa13a2260a9cd3c303f362781..0476ae8776d938b09e09371d73cca855b85d4665 100644 (file)
@@ -1374,13 +1374,41 @@ static void denali_hw_init(struct denali_nand_info *denali)
  * correction
  */
 #define ECC_8BITS      14
-static struct nand_ecclayout nand_8bit_oob = {
-       .eccbytes = 14,
-};
-
 #define ECC_15BITS     26
-static struct nand_ecclayout nand_15bit_oob = {
-       .eccbytes = 26,
+
+static int denali_ooblayout_ecc(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       struct denali_nand_info *denali = mtd_to_denali(mtd);
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = denali->bbtskipbytes;
+       oobregion->length = chip->ecc.total;
+
+       return 0;
+}
+
+static int denali_ooblayout_free(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct denali_nand_info *denali = mtd_to_denali(mtd);
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = chip->ecc.total + denali->bbtskipbytes;
+       oobregion->length = mtd->oobsize - oobregion->offset;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops denali_ooblayout_ops = {
+       .ecc = denali_ooblayout_ecc,
+       .free = denali_ooblayout_free,
 };
 
 static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' };
@@ -1561,7 +1589,6 @@ int denali_init(struct denali_nand_info *denali)
                        ECC_SECTOR_SIZE)))) {
                /* if MLC OOB size is large enough, use 15bit ECC*/
                denali->nand.ecc.strength = 15;
-               denali->nand.ecc.layout = &nand_15bit_oob;
                denali->nand.ecc.bytes = ECC_15BITS;
                iowrite32(15, denali->flash_reg + ECC_CORRECTION);
        } else if (mtd->oobsize < (denali->bbtskipbytes +
@@ -1571,20 +1598,13 @@ int denali_init(struct denali_nand_info *denali)
                goto failed_req_irq;
        } else {
                denali->nand.ecc.strength = 8;
-               denali->nand.ecc.layout = &nand_8bit_oob;
                denali->nand.ecc.bytes = ECC_8BITS;
                iowrite32(8, denali->flash_reg + ECC_CORRECTION);
        }
 
+       mtd_set_ooblayout(mtd, &denali_ooblayout_ops);
        denali->nand.ecc.bytes *= denali->devnum;
        denali->nand.ecc.strength *= denali->devnum;
-       denali->nand.ecc.layout->eccbytes *=
-               mtd->writesize / ECC_SECTOR_SIZE;
-       denali->nand.ecc.layout->oobfree[0].offset =
-               denali->bbtskipbytes + denali->nand.ecc.layout->eccbytes;
-       denali->nand.ecc.layout->oobfree[0].length =
-               mtd->oobsize - denali->nand.ecc.layout->eccbytes -
-               denali->bbtskipbytes;
 
        /*
         * Let driver know the total blocks number and how many blocks
index 547c1002941da4e81cee37576f497ca67d836b2c..a023ab9e9cbf616501cf16309f1198b67fbcf867 100644 (file)
@@ -950,20 +950,50 @@ static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
 
 //u_char mydatabuf[528];
 
-/* The strange out-of-order .oobfree list below is a (possibly unneeded)
- * attempt to retain compatibility.  It used to read:
- *     .oobfree = { {8, 8} }
- * Since that leaves two bytes unusable, it was changed.  But the following
- * scheme might affect existing jffs2 installs by moving the cleanmarker:
- *     .oobfree = { {6, 10} }
- * jffs2 seems to handle the above gracefully, but the current scheme seems
- * safer.  The only problem with it is that any code that parses oobfree must
- * be able to handle out-of-order segments.
- */
-static struct nand_ecclayout doc200x_oobinfo = {
-       .eccbytes = 6,
-       .eccpos = {0, 1, 2, 3, 4, 5},
-       .oobfree = {{8, 8}, {6, 2}}
+static int doc200x_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 0;
+       oobregion->length = 6;
+
+       return 0;
+}
+
+static int doc200x_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       /*
+        * The strange out-of-order free bytes definition is a (possibly
+        * unneeded) attempt to retain compatibility.  It used to read:
+        *      .oobfree = { {8, 8} }
+        * Since that leaves two bytes unusable, it was changed.  But the
+        * following scheme might affect existing jffs2 installs by moving the
+        * cleanmarker:
+        *      .oobfree = { {6, 10} }
+        * jffs2 seems to handle the above gracefully, but the current scheme
+        * seems safer. The only problem with it is that any code retrieving
+        * free bytes position must be able to handle out-of-order segments.
+        */
+       if (!section) {
+               oobregion->offset = 8;
+               oobregion->length = 8;
+       } else {
+               oobregion->offset = 6;
+               oobregion->length = 2;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops doc200x_ooblayout_ops = {
+       .ecc = doc200x_ooblayout_ecc,
+       .free = doc200x_ooblayout_free,
 };
 
 /* Find the (I)NFTL Media Header, and optionally also the mirror media header.
@@ -1537,6 +1567,7 @@ static int __init doc_probe(unsigned long physadr)
        nand->bbt_md            = nand->bbt_td + 1;
 
        mtd->owner              = THIS_MODULE;
+       mtd_set_ooblayout(mtd, &doc200x_ooblayout_ops);
 
        nand_set_controller_data(nand, doc);
        nand->select_chip       = doc200x_select_chip;
@@ -1548,7 +1579,6 @@ static int __init doc_probe(unsigned long physadr)
        nand->ecc.calculate     = doc200x_calculate_ecc;
        nand->ecc.correct       = doc200x_correct_data;
 
-       nand->ecc.layout        = &doc200x_oobinfo;
        nand->ecc.mode          = NAND_ECC_HW_SYNDROME;
        nand->ecc.size          = 512;
        nand->ecc.bytes         = 6;
index d86a60e1bbcb433a380a0718d2251cd2216a8ff9..47316998017f3e160a0eaf64783f26d2b1808ad9 100644 (file)
@@ -222,10 +222,33 @@ struct docg4_priv {
  * Bytes 8 - 14 are hw-generated ecc covering entire page + oob bytes 0 - 14.
  * Byte 15 (the last) is used by the driver as a "page written" flag.
  */
-static struct nand_ecclayout docg4_oobinfo = {
-       .eccbytes = 9,
-       .eccpos = {7, 8, 9, 10, 11, 12, 13, 14, 15},
-       .oobfree = { {.offset = 2, .length = 5} }
+static int docg4_ooblayout_ecc(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 7;
+       oobregion->length = 9;
+
+       return 0;
+}
+
+static int docg4_ooblayout_free(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 2;
+       oobregion->length = 5;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops docg4_ooblayout_ops = {
+       .ecc = docg4_ooblayout_ecc,
+       .free = docg4_ooblayout_free,
 };
 
 /*
@@ -1209,6 +1232,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
        mtd->writesize = DOCG4_PAGE_SIZE;
        mtd->erasesize = DOCG4_BLOCK_SIZE;
        mtd->oobsize = DOCG4_OOB_SIZE;
+       mtd_set_ooblayout(mtd, &docg4_ooblayout_ops);
        nand->chipsize = DOCG4_CHIP_SIZE;
        nand->chip_shift = DOCG4_CHIP_SHIFT;
        nand->bbt_erase_shift = nand->phys_erase_shift = DOCG4_ERASE_SHIFT;
@@ -1217,7 +1241,6 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
        nand->pagemask = 0x3ffff;
        nand->badblockpos = NAND_LARGE_BADBLOCK_POS;
        nand->badblockbits = 8;
-       nand->ecc.layout = &docg4_oobinfo;
        nand->ecc.mode = NAND_ECC_HW_SYNDROME;
        nand->ecc.size = DOCG4_PAGE_SIZE;
        nand->ecc.prepad = 8;
index 059d5f7ec1248aeb412e186f58d8040dcc06f0f7..60a88f24c6b3279be38a5870dbb5957cfa5f4114 100644 (file)
@@ -79,32 +79,53 @@ struct fsl_elbc_fcm_ctrl {
 
 /* These map to the positions used by the FCM hardware ECC generator */
 
-/* Small Page FLASH with FMR[ECCM] = 0 */
-static struct nand_ecclayout fsl_elbc_oob_sp_eccm0 = {
-       .eccbytes = 3,
-       .eccpos = {6, 7, 8},
-       .oobfree = { {0, 5}, {9, 7} },
-};
+static int fsl_elbc_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct fsl_elbc_mtd *priv = nand_get_controller_data(chip);
 
-/* Small Page FLASH with FMR[ECCM] = 1 */
-static struct nand_ecclayout fsl_elbc_oob_sp_eccm1 = {
-       .eccbytes = 3,
-       .eccpos = {8, 9, 10},
-       .oobfree = { {0, 5}, {6, 2}, {11, 5} },
-};
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
 
-/* Large Page FLASH with FMR[ECCM] = 0 */
-static struct nand_ecclayout fsl_elbc_oob_lp_eccm0 = {
-       .eccbytes = 12,
-       .eccpos = {6, 7, 8, 22, 23, 24, 38, 39, 40, 54, 55, 56},
-       .oobfree = { {1, 5}, {9, 13}, {25, 13}, {41, 13}, {57, 7} },
-};
+       oobregion->offset = (16 * section) + 6;
+       if (priv->fmr & FMR_ECCM)
+               oobregion->offset += 2;
 
-/* Large Page FLASH with FMR[ECCM] = 1 */
-static struct nand_ecclayout fsl_elbc_oob_lp_eccm1 = {
-       .eccbytes = 12,
-       .eccpos = {8, 9, 10, 24, 25, 26, 40, 41, 42, 56, 57, 58},
-       .oobfree = { {1, 7}, {11, 13}, {27, 13}, {43, 13}, {59, 5} },
+       oobregion->length = chip->ecc.bytes;
+
+       return 0;
+}
+
+static int fsl_elbc_ooblayout_free(struct mtd_info *mtd, int section,
+                                  struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct fsl_elbc_mtd *priv = nand_get_controller_data(chip);
+
+       if (section > chip->ecc.steps)
+               return -ERANGE;
+
+       if (!section) {
+               oobregion->offset = 0;
+               if (mtd->writesize > 512)
+                       oobregion->offset++;
+               oobregion->length = (priv->fmr & FMR_ECCM) ? 7 : 5;
+       } else {
+               oobregion->offset = (16 * section) -
+                                   ((priv->fmr & FMR_ECCM) ? 5 : 7);
+               if (section < chip->ecc.steps)
+                       oobregion->length = 13;
+               else
+                       oobregion->length = mtd->oobsize - oobregion->offset;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops fsl_elbc_ooblayout_ops = {
+       .ecc = fsl_elbc_ooblayout_ecc,
+       .free = fsl_elbc_ooblayout_free,
 };
 
 /*
@@ -657,8 +678,8 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
                chip->ecc.bytes);
        dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.total = %d\n",
                chip->ecc.total);
-       dev_dbg(priv->dev, "fsl_elbc_init: nand->ecc.layout = %p\n",
-               chip->ecc.layout);
+       dev_dbg(priv->dev, "fsl_elbc_init: mtd->ooblayout = %p\n",
+               mtd->ooblayout);
        dev_dbg(priv->dev, "fsl_elbc_init: mtd->flags = %08x\n", mtd->flags);
        dev_dbg(priv->dev, "fsl_elbc_init: mtd->size = %lld\n", mtd->size);
        dev_dbg(priv->dev, "fsl_elbc_init: mtd->erasesize = %d\n",
@@ -675,14 +696,6 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
        } else if (mtd->writesize == 2048) {
                priv->page_size = 1;
                setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
-               /* adjust ecc setup if needed */
-               if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==
-                   BR_DECC_CHK_GEN) {
-                       chip->ecc.size = 512;
-                       chip->ecc.layout = (priv->fmr & FMR_ECCM) ?
-                                          &fsl_elbc_oob_lp_eccm1 :
-                                          &fsl_elbc_oob_lp_eccm0;
-               }
        } else {
                dev_err(priv->dev,
                        "fsl_elbc_init: page size %d is not supported\n",
@@ -780,15 +793,14 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv)
        if ((in_be32(&lbc->bank[priv->bank].br) & BR_DECC) ==
            BR_DECC_CHK_GEN) {
                chip->ecc.mode = NAND_ECC_HW;
-               /* put in small page settings and adjust later if needed */
-               chip->ecc.layout = (priv->fmr & FMR_ECCM) ?
-                               &fsl_elbc_oob_sp_eccm1 : &fsl_elbc_oob_sp_eccm0;
+               mtd_set_ooblayout(mtd, &fsl_elbc_ooblayout_ops);
                chip->ecc.size = 512;
                chip->ecc.bytes = 3;
                chip->ecc.strength = 1;
        } else {
                /* otherwise fall back to default software ECC */
                chip->ecc.mode = NAND_ECC_SOFT;
+               chip->ecc.algo = NAND_ECC_HAMMING;
        }
 
        return 0;
index 43f5a3a4873f247d2e01e5c24dde49b3c607b3ed..4e9e5fd8faf30c22d5fa9159fe6a979228131954 100644 (file)
@@ -67,136 +67,6 @@ struct fsl_ifc_nand_ctrl {
 
 static struct fsl_ifc_nand_ctrl *ifc_nand_ctrl;
 
-/* 512-byte page with 4-bit ECC, 8-bit */
-static struct nand_ecclayout oob_512_8bit_ecc4 = {
-       .eccbytes = 8,
-       .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
-       .oobfree = { {0, 5}, {6, 2} },
-};
-
-/* 512-byte page with 4-bit ECC, 16-bit */
-static struct nand_ecclayout oob_512_16bit_ecc4 = {
-       .eccbytes = 8,
-       .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
-       .oobfree = { {2, 6}, },
-};
-
-/* 2048-byte page size with 4-bit ECC */
-static struct nand_ecclayout oob_2048_ecc4 = {
-       .eccbytes = 32,
-       .eccpos = {
-               8, 9, 10, 11, 12, 13, 14, 15,
-               16, 17, 18, 19, 20, 21, 22, 23,
-               24, 25, 26, 27, 28, 29, 30, 31,
-               32, 33, 34, 35, 36, 37, 38, 39,
-       },
-       .oobfree = { {2, 6}, {40, 24} },
-};
-
-/* 4096-byte page size with 4-bit ECC */
-static struct nand_ecclayout oob_4096_ecc4 = {
-       .eccbytes = 64,
-       .eccpos = {
-               8, 9, 10, 11, 12, 13, 14, 15,
-               16, 17, 18, 19, 20, 21, 22, 23,
-               24, 25, 26, 27, 28, 29, 30, 31,
-               32, 33, 34, 35, 36, 37, 38, 39,
-               40, 41, 42, 43, 44, 45, 46, 47,
-               48, 49, 50, 51, 52, 53, 54, 55,
-               56, 57, 58, 59, 60, 61, 62, 63,
-               64, 65, 66, 67, 68, 69, 70, 71,
-       },
-       .oobfree = { {2, 6}, {72, 56} },
-};
-
-/* 4096-byte page size with 8-bit ECC -- requires 218-byte OOB */
-static struct nand_ecclayout oob_4096_ecc8 = {
-       .eccbytes = 128,
-       .eccpos = {
-               8, 9, 10, 11, 12, 13, 14, 15,
-               16, 17, 18, 19, 20, 21, 22, 23,
-               24, 25, 26, 27, 28, 29, 30, 31,
-               32, 33, 34, 35, 36, 37, 38, 39,
-               40, 41, 42, 43, 44, 45, 46, 47,
-               48, 49, 50, 51, 52, 53, 54, 55,
-               56, 57, 58, 59, 60, 61, 62, 63,
-               64, 65, 66, 67, 68, 69, 70, 71,
-               72, 73, 74, 75, 76, 77, 78, 79,
-               80, 81, 82, 83, 84, 85, 86, 87,
-               88, 89, 90, 91, 92, 93, 94, 95,
-               96, 97, 98, 99, 100, 101, 102, 103,
-               104, 105, 106, 107, 108, 109, 110, 111,
-               112, 113, 114, 115, 116, 117, 118, 119,
-               120, 121, 122, 123, 124, 125, 126, 127,
-               128, 129, 130, 131, 132, 133, 134, 135,
-       },
-       .oobfree = { {2, 6}, {136, 82} },
-};
-
-/* 8192-byte page size with 4-bit ECC */
-static struct nand_ecclayout oob_8192_ecc4 = {
-       .eccbytes = 128,
-       .eccpos = {
-               8, 9, 10, 11, 12, 13, 14, 15,
-               16, 17, 18, 19, 20, 21, 22, 23,
-               24, 25, 26, 27, 28, 29, 30, 31,
-               32, 33, 34, 35, 36, 37, 38, 39,
-               40, 41, 42, 43, 44, 45, 46, 47,
-               48, 49, 50, 51, 52, 53, 54, 55,
-               56, 57, 58, 59, 60, 61, 62, 63,
-               64, 65, 66, 67, 68, 69, 70, 71,
-               72, 73, 74, 75, 76, 77, 78, 79,
-               80, 81, 82, 83, 84, 85, 86, 87,
-               88, 89, 90, 91, 92, 93, 94, 95,
-               96, 97, 98, 99, 100, 101, 102, 103,
-               104, 105, 106, 107, 108, 109, 110, 111,
-               112, 113, 114, 115, 116, 117, 118, 119,
-               120, 121, 122, 123, 124, 125, 126, 127,
-               128, 129, 130, 131, 132, 133, 134, 135,
-       },
-       .oobfree = { {2, 6}, {136, 208} },
-};
-
-/* 8192-byte page size with 8-bit ECC -- requires 218-byte OOB */
-static struct nand_ecclayout oob_8192_ecc8 = {
-       .eccbytes = 256,
-       .eccpos = {
-               8, 9, 10, 11, 12, 13, 14, 15,
-               16, 17, 18, 19, 20, 21, 22, 23,
-               24, 25, 26, 27, 28, 29, 30, 31,
-               32, 33, 34, 35, 36, 37, 38, 39,
-               40, 41, 42, 43, 44, 45, 46, 47,
-               48, 49, 50, 51, 52, 53, 54, 55,
-               56, 57, 58, 59, 60, 61, 62, 63,
-               64, 65, 66, 67, 68, 69, 70, 71,
-               72, 73, 74, 75, 76, 77, 78, 79,
-               80, 81, 82, 83, 84, 85, 86, 87,
-               88, 89, 90, 91, 92, 93, 94, 95,
-               96, 97, 98, 99, 100, 101, 102, 103,
-               104, 105, 106, 107, 108, 109, 110, 111,
-               112, 113, 114, 115, 116, 117, 118, 119,
-               120, 121, 122, 123, 124, 125, 126, 127,
-               128, 129, 130, 131, 132, 133, 134, 135,
-               136, 137, 138, 139, 140, 141, 142, 143,
-               144, 145, 146, 147, 148, 149, 150, 151,
-               152, 153, 154, 155, 156, 157, 158, 159,
-               160, 161, 162, 163, 164, 165, 166, 167,
-               168, 169, 170, 171, 172, 173, 174, 175,
-               176, 177, 178, 179, 180, 181, 182, 183,
-               184, 185, 186, 187, 188, 189, 190, 191,
-               192, 193, 194, 195, 196, 197, 198, 199,
-               200, 201, 202, 203, 204, 205, 206, 207,
-               208, 209, 210, 211, 212, 213, 214, 215,
-               216, 217, 218, 219, 220, 221, 222, 223,
-               224, 225, 226, 227, 228, 229, 230, 231,
-               232, 233, 234, 235, 236, 237, 238, 239,
-               240, 241, 242, 243, 244, 245, 246, 247,
-               248, 249, 250, 251, 252, 253, 254, 255,
-               256, 257, 258, 259, 260, 261, 262, 263,
-       },
-       .oobfree = { {2, 6}, {264, 80} },
-};
-
 /*
  * Generic flash bbt descriptors
  */
@@ -223,6 +93,57 @@ static struct nand_bbt_descr bbt_mirror_descr = {
        .pattern = mirror_pattern,
 };
 
+static int fsl_ifc_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 8;
+       oobregion->length = chip->ecc.total;
+
+       return 0;
+}
+
+static int fsl_ifc_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section > 1)
+               return -ERANGE;
+
+       if (mtd->writesize == 512 &&
+           !(chip->options & NAND_BUSWIDTH_16)) {
+               if (!section) {
+                       oobregion->offset = 0;
+                       oobregion->length = 5;
+               } else {
+                       oobregion->offset = 6;
+                       oobregion->length = 2;
+               }
+
+               return 0;
+       }
+
+       if (!section) {
+               oobregion->offset = 2;
+               oobregion->length = 6;
+       } else {
+               oobregion->offset = chip->ecc.total + 8;
+               oobregion->length = mtd->oobsize - oobregion->offset;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops fsl_ifc_ooblayout_ops = {
+       .ecc = fsl_ifc_ooblayout_ecc,
+       .free = fsl_ifc_ooblayout_free,
+};
+
 /*
  * Set up the IFC hardware block and page address fields, and the ifc nand
  * structure addr field to point to the correct IFC buffer in memory
@@ -232,7 +153,7 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
        int buf_num;
 
        ifc_nand_ctrl->page = page_addr;
@@ -257,18 +178,22 @@ static int is_blank(struct mtd_info *mtd, unsigned int bufnum)
        u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2);
        u32 __iomem *mainarea = (u32 __iomem *)addr;
        u8 __iomem *oob = addr + mtd->writesize;
-       int i;
+       struct mtd_oob_region oobregion = { };
+       int i, section = 0;
 
        for (i = 0; i < mtd->writesize / 4; i++) {
                if (__raw_readl(&mainarea[i]) != 0xffffffff)
                        return 0;
        }
 
-       for (i = 0; i < chip->ecc.layout->eccbytes; i++) {
-               int pos = chip->ecc.layout->eccpos[i];
+       mtd_ooblayout_ecc(mtd, section++, &oobregion);
+       while (oobregion.length) {
+               for (i = 0; i < oobregion.length; i++) {
+                       if (__raw_readb(&oob[oobregion.offset + i]) != 0xff)
+                               return 0;
+               }
 
-               if (__raw_readb(&oob[pos]) != 0xff)
-                       return 0;
+               mtd_ooblayout_ecc(mtd, section++, &oobregion);
        }
 
        return 1;
@@ -295,7 +220,7 @@ static void fsl_ifc_run_command(struct mtd_info *mtd)
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
        struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
        u32 eccstat[4];
        int i;
 
@@ -371,7 +296,7 @@ static void fsl_ifc_do_read(struct nand_chip *chip,
 {
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
 
        /* Program FIR/IFC_NAND_FCR0 for Small/Large page */
        if (mtd->writesize > 512) {
@@ -411,7 +336,7 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
 
        /* clear the read buffer */
        ifc_nand_ctrl->read_bytes = 0;
@@ -723,7 +648,7 @@ static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
        struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
        u32 nand_fsr;
 
        /* Use READ_STATUS command, but wait for the device to be ready */
@@ -808,8 +733,8 @@ static int fsl_ifc_chip_init_tail(struct mtd_info *mtd)
                                                        chip->ecc.bytes);
        dev_dbg(priv->dev, "%s: nand->ecc.total = %d\n", __func__,
                                                        chip->ecc.total);
-       dev_dbg(priv->dev, "%s: nand->ecc.layout = %p\n", __func__,
-                                                       chip->ecc.layout);
+       dev_dbg(priv->dev, "%s: mtd->ooblayout = %p\n", __func__,
+                                                       mtd->ooblayout);
        dev_dbg(priv->dev, "%s: mtd->flags = %08x\n", __func__, mtd->flags);
        dev_dbg(priv->dev, "%s: mtd->size = %lld\n", __func__, mtd->size);
        dev_dbg(priv->dev, "%s: mtd->erasesize = %d\n", __func__,
@@ -825,39 +750,42 @@ static int fsl_ifc_chip_init_tail(struct mtd_info *mtd)
 static void fsl_ifc_sram_init(struct fsl_ifc_mtd *priv)
 {
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs;
+       struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
        uint32_t csor = 0, csor_8k = 0, csor_ext = 0;
        uint32_t cs = priv->bank;
 
        /* Save CSOR and CSOR_ext */
-       csor = ifc_in32(&ifc->csor_cs[cs].csor);
-       csor_ext = ifc_in32(&ifc->csor_cs[cs].csor_ext);
+       csor = ifc_in32(&ifc_global->csor_cs[cs].csor);
+       csor_ext = ifc_in32(&ifc_global->csor_cs[cs].csor_ext);
 
        /* chage PageSize 8K and SpareSize 1K*/
        csor_8k = (csor & ~(CSOR_NAND_PGS_MASK)) | 0x0018C000;
-       ifc_out32(csor_8k, &ifc->csor_cs[cs].csor);
-       ifc_out32(0x0000400, &ifc->csor_cs[cs].csor_ext);
+       ifc_out32(csor_8k, &ifc_global->csor_cs[cs].csor);
+       ifc_out32(0x0000400, &ifc_global->csor_cs[cs].csor_ext);
 
        /* READID */
        ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
-                 (IFC_FIR_OP_UA  << IFC_NAND_FIR0_OP1_SHIFT) |
-                 (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT),
-                 &ifc->ifc_nand.nand_fir0);
+                   (IFC_FIR_OP_UA  << IFC_NAND_FIR0_OP1_SHIFT) |
+                   (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT),
+                   &ifc_runtime->ifc_nand.nand_fir0);
        ifc_out32(NAND_CMD_READID << IFC_NAND_FCR0_CMD0_SHIFT,
-                 &ifc->ifc_nand.nand_fcr0);
-       ifc_out32(0x0, &ifc->ifc_nand.row3);
+                   &ifc_runtime->ifc_nand.nand_fcr0);
+       ifc_out32(0x0, &ifc_runtime->ifc_nand.row3);
 
-       ifc_out32(0x0, &ifc->ifc_nand.nand_fbcr);
+       ifc_out32(0x0, &ifc_runtime->ifc_nand.nand_fbcr);
 
        /* Program ROW0/COL0 */
-       ifc_out32(0x0, &ifc->ifc_nand.row0);
-       ifc_out32(0x0, &ifc->ifc_nand.col0);
+       ifc_out32(0x0, &ifc_runtime->ifc_nand.row0);
+       ifc_out32(0x0, &ifc_runtime->ifc_nand.col0);
 
        /* set the chip select for NAND Transaction */
-       ifc_out32(cs << IFC_NAND_CSEL_SHIFT, &ifc->ifc_nand.nand_csel);
+       ifc_out32(cs << IFC_NAND_CSEL_SHIFT,
+               &ifc_runtime->ifc_nand.nand_csel);
 
        /* start read seq */
-       ifc_out32(IFC_NAND_SEQ_STRT_FIR_STRT, &ifc->ifc_nand.nandseq_strt);
+       ifc_out32(IFC_NAND_SEQ_STRT_FIR_STRT,
+               &ifc_runtime->ifc_nand.nandseq_strt);
 
        /* wait for command complete flag or timeout */
        wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
@@ -867,17 +795,17 @@ static void fsl_ifc_sram_init(struct fsl_ifc_mtd *priv)
                printk(KERN_ERR "fsl-ifc: Failed to Initialise SRAM\n");
 
        /* Restore CSOR and CSOR_ext */
-       ifc_out32(csor, &ifc->csor_cs[cs].csor);
-       ifc_out32(csor_ext, &ifc->csor_cs[cs].csor_ext);
+       ifc_out32(csor, &ifc_global->csor_cs[cs].csor);
+       ifc_out32(csor_ext, &ifc_global->csor_cs[cs].csor_ext);
 }
 
 static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 {
        struct fsl_ifc_ctrl *ctrl = priv->ctrl;
-       struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
+       struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
+       struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs;
        struct nand_chip *chip = &priv->chip;
        struct mtd_info *mtd = nand_to_mtd(&priv->chip);
-       struct nand_ecclayout *layout;
        u32 csor;
 
        /* Fill in fsl_ifc_mtd structure */
@@ -886,7 +814,8 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
 
        /* fill in nand_chip structure */
        /* set up function call table */
-       if ((ifc_in32(&ifc->cspr_cs[priv->bank].cspr)) & CSPR_PORT_SIZE_16)
+       if ((ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr))
+               & CSPR_PORT_SIZE_16)
                chip->read_byte = fsl_ifc_read_byte16;
        else
                chip->read_byte = fsl_ifc_read_byte;
@@ -900,13 +829,14 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
        chip->bbt_td = &bbt_main_descr;
        chip->bbt_md = &bbt_mirror_descr;
 
-       ifc_out32(0x0, &ifc->ifc_nand.ncfgr);
+       ifc_out32(0x0, &ifc_runtime->ifc_nand.ncfgr);
 
        /* set up nand options */
        chip->bbt_options = NAND_BBT_USE_FLASH;
        chip->options = NAND_NO_SUBPAGE_WRITE;
 
-       if (ifc_in32(&ifc->cspr_cs[priv->bank].cspr) & CSPR_PORT_SIZE_16) {
+       if (ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr)
+               & CSPR_PORT_SIZE_16) {
                chip->read_byte = fsl_ifc_read_byte16;
                chip->options |= NAND_BUSWIDTH_16;
        } else {
@@ -919,20 +849,11 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
        chip->ecc.read_page = fsl_ifc_read_page;
        chip->ecc.write_page = fsl_ifc_write_page;
 
-       csor = ifc_in32(&ifc->csor_cs[priv->bank].csor);
-
-       /* Hardware generates ECC per 512 Bytes */
-       chip->ecc.size = 512;
-       chip->ecc.bytes = 8;
-       chip->ecc.strength = 4;
+       csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor);
 
        switch (csor & CSOR_NAND_PGS_MASK) {
        case CSOR_NAND_PGS_512:
-               if (chip->options & NAND_BUSWIDTH_16) {
-                       layout = &oob_512_16bit_ecc4;
-               } else {
-                       layout = &oob_512_8bit_ecc4;
-
+               if (!(chip->options & NAND_BUSWIDTH_16)) {
                        /* Avoid conflict with bad block marker */
                        bbt_main_descr.offs = 0;
                        bbt_mirror_descr.offs = 0;
@@ -942,35 +863,16 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
                break;
 
        case CSOR_NAND_PGS_2K:
-               layout = &oob_2048_ecc4;
                priv->bufnum_mask = 3;
                break;
 
        case CSOR_NAND_PGS_4K:
-               if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
-                   CSOR_NAND_ECC_MODE_4) {
-                       layout = &oob_4096_ecc4;
-               } else {
-                       layout = &oob_4096_ecc8;
-                       chip->ecc.bytes = 16;
-                       chip->ecc.strength = 8;
-               }
-
                priv->bufnum_mask = 1;
                break;
 
        case CSOR_NAND_PGS_8K:
-               if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
-                   CSOR_NAND_ECC_MODE_4) {
-                       layout = &oob_8192_ecc4;
-               } else {
-                       layout = &oob_8192_ecc8;
-                       chip->ecc.bytes = 16;
-                       chip->ecc.strength = 8;
-               }
-
                priv->bufnum_mask = 0;
-       break;
+               break;
 
        default:
                dev_err(priv->dev, "bad csor %#x: bad page size\n", csor);
@@ -980,9 +882,20 @@ static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
        /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
        if (csor & CSOR_NAND_ECC_DEC_EN) {
                chip->ecc.mode = NAND_ECC_HW;
-               chip->ecc.layout = layout;
+               mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
+
+               /* Hardware generates ECC per 512 Bytes */
+               chip->ecc.size = 512;
+               if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
+                       chip->ecc.bytes = 8;
+                       chip->ecc.strength = 4;
+               } else {
+                       chip->ecc.bytes = 16;
+                       chip->ecc.strength = 8;
+               }
        } else {
                chip->ecc.mode = NAND_ECC_SOFT;
+               chip->ecc.algo = NAND_ECC_HAMMING;
        }
 
        if (ctrl->version == FSL_IFC_VERSION_1_1_0)
@@ -1007,10 +920,10 @@ static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
        return 0;
 }
 
-static int match_bank(struct fsl_ifc_regs __iomem *ifc, int bank,
+static int match_bank(struct fsl_ifc_global __iomem *ifc_global, int bank,
                      phys_addr_t addr)
 {
-       u32 cspr = ifc_in32(&ifc->cspr_cs[bank].cspr);
+       u32 cspr = ifc_in32(&ifc_global->cspr_cs[bank].cspr);
 
        if (!(cspr & CSPR_V))
                return 0;
@@ -1024,7 +937,7 @@ static DEFINE_MUTEX(fsl_ifc_nand_mutex);
 
 static int fsl_ifc_nand_probe(struct platform_device *dev)
 {
-       struct fsl_ifc_regs __iomem *ifc;
+       struct fsl_ifc_runtime __iomem *ifc;
        struct fsl_ifc_mtd *priv;
        struct resource res;
        static const char *part_probe_types[]
@@ -1034,9 +947,9 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
        struct device_node *node = dev->dev.of_node;
        struct mtd_info *mtd;
 
-       if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->regs)
+       if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->rregs)
                return -ENODEV;
-       ifc = fsl_ifc_ctrl_dev->regs;
+       ifc = fsl_ifc_ctrl_dev->rregs;
 
        /* get, allocate and map the memory resource */
        ret = of_address_to_resource(node, 0, &res);
@@ -1047,7 +960,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 
        /* find which chip select it is connected to */
        for (bank = 0; bank < fsl_ifc_ctrl_dev->banks; bank++) {
-               if (match_bank(ifc, bank, res.start))
+               if (match_bank(fsl_ifc_ctrl_dev->gregs, bank, res.start))
                        break;
        }
 
index cafd12de72766f193ce409d46ac5ae9b3e9489a9..d85fa2555b6838b967ab3aee36f78360ec6ac321 100644 (file)
@@ -170,6 +170,7 @@ static int fun_chip_init(struct fsl_upm_nand *fun,
        fun->chip.read_buf = fun_read_buf;
        fun->chip.write_buf = fun_write_buf;
        fun->chip.ecc.mode = NAND_ECC_SOFT;
+       fun->chip.ecc.algo = NAND_ECC_HAMMING;
        if (fun->mchip_count > 1)
                fun->chip.select_chip = fun_select_chip;
 
index 1bdcd4fa26d4bcd9c7c98fc5767960ac6abe1da7..d4f454a4b35e7e5ed8aff7a6d5a326c86d62032f 100644 (file)
 #include <linux/amba/bus.h>
 #include <mtd/mtd-abi.h>
 
-static struct nand_ecclayout fsmc_ecc1_128_layout = {
-       .eccbytes = 24,
-       .eccpos = {2, 3, 4, 18, 19, 20, 34, 35, 36, 50, 51, 52,
-               66, 67, 68, 82, 83, 84, 98, 99, 100, 114, 115, 116},
-       .oobfree = {
-               {.offset = 8, .length = 8},
-               {.offset = 24, .length = 8},
-               {.offset = 40, .length = 8},
-               {.offset = 56, .length = 8},
-               {.offset = 72, .length = 8},
-               {.offset = 88, .length = 8},
-               {.offset = 104, .length = 8},
-               {.offset = 120, .length = 8}
-       }
-};
+static int fsmc_ecc1_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                  struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
-static struct nand_ecclayout fsmc_ecc1_64_layout = {
-       .eccbytes = 12,
-       .eccpos = {2, 3, 4, 18, 19, 20, 34, 35, 36, 50, 51, 52},
-       .oobfree = {
-               {.offset = 8, .length = 8},
-               {.offset = 24, .length = 8},
-               {.offset = 40, .length = 8},
-               {.offset = 56, .length = 8},
-       }
-};
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
 
-static struct nand_ecclayout fsmc_ecc1_16_layout = {
-       .eccbytes = 3,
-       .eccpos = {2, 3, 4},
-       .oobfree = {
-               {.offset = 8, .length = 8},
-       }
-};
+       oobregion->offset = (section * 16) + 2;
+       oobregion->length = 3;
 
-/*
- * ECC4 layout for NAND of pagesize 8192 bytes & OOBsize 256 bytes. 13*16 bytes
- * of OB size is reserved for ECC, Byte no. 0 & 1 reserved for bad block and 46
- * bytes are free for use.
- */
-static struct nand_ecclayout fsmc_ecc4_256_layout = {
-       .eccbytes = 208,
-       .eccpos = {  2,   3,   4,   5,   6,   7,   8,
-               9,  10,  11,  12,  13,  14,
-               18,  19,  20,  21,  22,  23,  24,
-               25,  26,  27,  28,  29,  30,
-               34,  35,  36,  37,  38,  39,  40,
-               41,  42,  43,  44,  45,  46,
-               50,  51,  52,  53,  54,  55,  56,
-               57,  58,  59,  60,  61,  62,
-               66,  67,  68,  69,  70,  71,  72,
-               73,  74,  75,  76,  77,  78,
-               82,  83,  84,  85,  86,  87,  88,
-               89,  90,  91,  92,  93,  94,
-               98,  99, 100, 101, 102, 103, 104,
-               105, 106, 107, 108, 109, 110,
-               114, 115, 116, 117, 118, 119, 120,
-               121, 122, 123, 124, 125, 126,
-               130, 131, 132, 133, 134, 135, 136,
-               137, 138, 139, 140, 141, 142,
-               146, 147, 148, 149, 150, 151, 152,
-               153, 154, 155, 156, 157, 158,
-               162, 163, 164, 165, 166, 167, 168,
-               169, 170, 171, 172, 173, 174,
-               178, 179, 180, 181, 182, 183, 184,
-               185, 186, 187, 188, 189, 190,
-               194, 195, 196, 197, 198, 199, 200,
-               201, 202, 203, 204, 205, 206,
-               210, 211, 212, 213, 214, 215, 216,
-               217, 218, 219, 220, 221, 222,
-               226, 227, 228, 229, 230, 231, 232,
-               233, 234, 235, 236, 237, 238,
-               242, 243, 244, 245, 246, 247, 248,
-               249, 250, 251, 252, 253, 254
-       },
-       .oobfree = {
-               {.offset = 15, .length = 3},
-               {.offset = 31, .length = 3},
-               {.offset = 47, .length = 3},
-               {.offset = 63, .length = 3},
-               {.offset = 79, .length = 3},
-               {.offset = 95, .length = 3},
-               {.offset = 111, .length = 3},
-               {.offset = 127, .length = 3},
-               {.offset = 143, .length = 3},
-               {.offset = 159, .length = 3},
-               {.offset = 175, .length = 3},
-               {.offset = 191, .length = 3},
-               {.offset = 207, .length = 3},
-               {.offset = 223, .length = 3},
-               {.offset = 239, .length = 3},
-               {.offset = 255, .length = 1}
-       }
-};
+       return 0;
+}
 
-/*
- * ECC4 layout for NAND of pagesize 4096 bytes & OOBsize 224 bytes. 13*8 bytes
- * of OOB size is reserved for ECC, Byte no. 0 & 1 reserved for bad block & 118
- * bytes are free for use.
- */
-static struct nand_ecclayout fsmc_ecc4_224_layout = {
-       .eccbytes = 104,
-       .eccpos = {  2,   3,   4,   5,   6,   7,   8,
-               9,  10,  11,  12,  13,  14,
-               18,  19,  20,  21,  22,  23,  24,
-               25,  26,  27,  28,  29,  30,
-               34,  35,  36,  37,  38,  39,  40,
-               41,  42,  43,  44,  45,  46,
-               50,  51,  52,  53,  54,  55,  56,
-               57,  58,  59,  60,  61,  62,
-               66,  67,  68,  69,  70,  71,  72,
-               73,  74,  75,  76,  77,  78,
-               82,  83,  84,  85,  86,  87,  88,
-               89,  90,  91,  92,  93,  94,
-               98,  99, 100, 101, 102, 103, 104,
-               105, 106, 107, 108, 109, 110,
-               114, 115, 116, 117, 118, 119, 120,
-               121, 122, 123, 124, 125, 126
-       },
-       .oobfree = {
-               {.offset = 15, .length = 3},
-               {.offset = 31, .length = 3},
-               {.offset = 47, .length = 3},
-               {.offset = 63, .length = 3},
-               {.offset = 79, .length = 3},
-               {.offset = 95, .length = 3},
-               {.offset = 111, .length = 3},
-               {.offset = 127, .length = 97}
-       }
-};
+static int fsmc_ecc1_ooblayout_free(struct mtd_info *mtd, int section,
+                                   struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
-/*
- * ECC4 layout for NAND of pagesize 4096 bytes & OOBsize 128 bytes. 13*8 bytes
- * of OOB size is reserved for ECC, Byte no. 0 & 1 reserved for bad block & 22
- * bytes are free for use.
- */
-static struct nand_ecclayout fsmc_ecc4_128_layout = {
-       .eccbytes = 104,
-       .eccpos = {  2,   3,   4,   5,   6,   7,   8,
-               9,  10,  11,  12,  13,  14,
-               18,  19,  20,  21,  22,  23,  24,
-               25,  26,  27,  28,  29,  30,
-               34,  35,  36,  37,  38,  39,  40,
-               41,  42,  43,  44,  45,  46,
-               50,  51,  52,  53,  54,  55,  56,
-               57,  58,  59,  60,  61,  62,
-               66,  67,  68,  69,  70,  71,  72,
-               73,  74,  75,  76,  77,  78,
-               82,  83,  84,  85,  86,  87,  88,
-               89,  90,  91,  92,  93,  94,
-               98,  99, 100, 101, 102, 103, 104,
-               105, 106, 107, 108, 109, 110,
-               114, 115, 116, 117, 118, 119, 120,
-               121, 122, 123, 124, 125, 126
-       },
-       .oobfree = {
-               {.offset = 15, .length = 3},
-               {.offset = 31, .length = 3},
-               {.offset = 47, .length = 3},
-               {.offset = 63, .length = 3},
-               {.offset = 79, .length = 3},
-               {.offset = 95, .length = 3},
-               {.offset = 111, .length = 3},
-               {.offset = 127, .length = 1}
-       }
-};
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
 
-/*
- * ECC4 layout for NAND of pagesize 2048 bytes & OOBsize 64 bytes. 13*4 bytes of
- * OOB size is reserved for ECC, Byte no. 0 & 1 reserved for bad block and 10
- * bytes are free for use.
- */
-static struct nand_ecclayout fsmc_ecc4_64_layout = {
-       .eccbytes = 52,
-       .eccpos = {  2,   3,   4,   5,   6,   7,   8,
-               9,  10,  11,  12,  13,  14,
-               18,  19,  20,  21,  22,  23,  24,
-               25,  26,  27,  28,  29,  30,
-               34,  35,  36,  37,  38,  39,  40,
-               41,  42,  43,  44,  45,  46,
-               50,  51,  52,  53,  54,  55,  56,
-               57,  58,  59,  60,  61,  62,
-       },
-       .oobfree = {
-               {.offset = 15, .length = 3},
-               {.offset = 31, .length = 3},
-               {.offset = 47, .length = 3},
-               {.offset = 63, .length = 1},
-       }
-};
+       oobregion->offset = (section * 16) + 8;
 
-/*
- * ECC4 layout for NAND of pagesize 512 bytes & OOBsize 16 bytes. 13 bytes of
- * OOB size is reserved for ECC, Byte no. 4 & 5 reserved for bad block and One
- * byte is free for use.
- */
-static struct nand_ecclayout fsmc_ecc4_16_layout = {
-       .eccbytes = 13,
-       .eccpos = { 0,  1,  2,  3,  6,  7, 8,
-               9, 10, 11, 12, 13, 14
-       },
-       .oobfree = {
-               {.offset = 15, .length = 1},
-       }
+       if (section < chip->ecc.steps - 1)
+               oobregion->length = 8;
+       else
+               oobregion->length = mtd->oobsize - oobregion->offset;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops fsmc_ecc1_ooblayout_ops = {
+       .ecc = fsmc_ecc1_ooblayout_ecc,
+       .free = fsmc_ecc1_ooblayout_free,
 };
 
 /*
@@ -250,28 +81,46 @@ static struct nand_ecclayout fsmc_ecc4_16_layout = {
  * There are 13 bytes of ecc for every 512 byte block and it has to be read
  * consecutively and immediately after the 512 byte data block for hardware to
  * generate the error bit offsets in 512 byte data.
- * Managing the ecc bytes in the following way makes it easier for software to
- * read ecc bytes consecutive to data bytes. This way is similar to
- * oobfree structure maintained already in generic nand driver
  */
-static struct fsmc_eccplace fsmc_ecc4_lp_place = {
-       .eccplace = {
-               {.offset = 2, .length = 13},
-               {.offset = 18, .length = 13},
-               {.offset = 34, .length = 13},
-               {.offset = 50, .length = 13},
-               {.offset = 66, .length = 13},
-               {.offset = 82, .length = 13},
-               {.offset = 98, .length = 13},
-               {.offset = 114, .length = 13}
-       }
-};
+static int fsmc_ecc4_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                  struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
 
-static struct fsmc_eccplace fsmc_ecc4_sp_place = {
-       .eccplace = {
-               {.offset = 0, .length = 4},
-               {.offset = 6, .length = 9}
-       }
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->length = chip->ecc.bytes;
+
+       if (!section && mtd->writesize <= 512)
+               oobregion->offset = 0;
+       else
+               oobregion->offset = (section * 16) + 2;
+
+       return 0;
+}
+
+static int fsmc_ecc4_ooblayout_free(struct mtd_info *mtd, int section,
+                                   struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 15;
+
+       if (section < chip->ecc.steps - 1)
+               oobregion->length = 3;
+       else
+               oobregion->length = mtd->oobsize - oobregion->offset;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops fsmc_ecc4_ooblayout_ops = {
+       .ecc = fsmc_ecc4_ooblayout_ecc,
+       .free = fsmc_ecc4_ooblayout_free,
 };
 
 /**
@@ -283,7 +132,6 @@ static struct fsmc_eccplace fsmc_ecc4_sp_place = {
  * @partitions:                Partition info for a NAND Flash.
  * @nr_partitions:     Total number of partition of a NAND flash.
  *
- * @ecc_place:         ECC placing locations in oobfree type format.
  * @bank:              Bank number for probed device.
  * @clk:               Clock structure for FSMC.
  *
@@ -303,7 +151,6 @@ struct fsmc_nand_data {
        struct mtd_partition    *partitions;
        unsigned int            nr_partitions;
 
-       struct fsmc_eccplace    *ecc_place;
        unsigned int            bank;
        struct device           *dev;
        enum access_mode        mode;
@@ -710,8 +557,6 @@ static void fsmc_write_buf_dma(struct mtd_info *mtd, const uint8_t *buf,
 static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                                 uint8_t *buf, int oob_required, int page)
 {
-       struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
-       struct fsmc_eccplace *ecc_place = host->ecc_place;
        int i, j, s, stat, eccsize = chip->ecc.size;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
@@ -734,9 +579,15 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                chip->read_buf(mtd, p, eccsize);
 
                for (j = 0; j < eccbytes;) {
-                       off = ecc_place->eccplace[group].offset;
-                       len = ecc_place->eccplace[group].length;
-                       group++;
+                       struct mtd_oob_region oobregion;
+                       int ret;
+
+                       ret = mtd_ooblayout_ecc(mtd, group++, &oobregion);
+                       if (ret)
+                               return ret;
+
+                       off = oobregion.offset;
+                       len = oobregion.length;
 
                        /*
                         * length is intentionally kept a higher multiple of 2
@@ -1084,24 +935,10 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
        if (AMBA_REV_BITS(host->pid) >= 8) {
                switch (mtd->oobsize) {
                case 16:
-                       nand->ecc.layout = &fsmc_ecc4_16_layout;
-                       host->ecc_place = &fsmc_ecc4_sp_place;
-                       break;
                case 64:
-                       nand->ecc.layout = &fsmc_ecc4_64_layout;
-                       host->ecc_place = &fsmc_ecc4_lp_place;
-                       break;
                case 128:
-                       nand->ecc.layout = &fsmc_ecc4_128_layout;
-                       host->ecc_place = &fsmc_ecc4_lp_place;
-                       break;
                case 224:
-                       nand->ecc.layout = &fsmc_ecc4_224_layout;
-                       host->ecc_place = &fsmc_ecc4_lp_place;
-                       break;
                case 256:
-                       nand->ecc.layout = &fsmc_ecc4_256_layout;
-                       host->ecc_place = &fsmc_ecc4_lp_place;
                        break;
                default:
                        dev_warn(&pdev->dev, "No oob scheme defined for oobsize %d\n",
@@ -1109,6 +946,8 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
                        ret = -EINVAL;
                        goto err_probe;
                }
+
+               mtd_set_ooblayout(mtd, &fsmc_ecc4_ooblayout_ops);
        } else {
                switch (nand->ecc.mode) {
                case NAND_ECC_HW:
@@ -1119,9 +958,11 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
                        nand->ecc.strength = 1;
                        break;
 
-               case NAND_ECC_SOFT_BCH:
-                       dev_info(&pdev->dev, "Using 4-bit SW BCH ECC scheme\n");
-                       break;
+               case NAND_ECC_SOFT:
+                       if (nand->ecc.algo == NAND_ECC_BCH) {
+                               dev_info(&pdev->dev, "Using 4-bit SW BCH ECC scheme\n");
+                               break;
+                       }
 
                default:
                        dev_err(&pdev->dev, "Unsupported ECC mode!\n");
@@ -1132,16 +973,13 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
                 * Don't set layout for BCH4 SW ECC. This will be
                 * generated later in nand_bch_init() later.
                 */
-               if (nand->ecc.mode != NAND_ECC_SOFT_BCH) {
+               if (nand->ecc.mode == NAND_ECC_HW) {
                        switch (mtd->oobsize) {
                        case 16:
-                               nand->ecc.layout = &fsmc_ecc1_16_layout;
-                               break;
                        case 64:
-                               nand->ecc.layout = &fsmc_ecc1_64_layout;
-                               break;
                        case 128:
-                               nand->ecc.layout = &fsmc_ecc1_128_layout;
+                               mtd_set_ooblayout(mtd,
+                                                 &fsmc_ecc1_ooblayout_ops);
                                break;
                        default:
                                dev_warn(&pdev->dev,
index ded658fc7d73d07265e0c21abf7599e22bef89f1..6317f6836022e8cbcd144b8df10fc698524d793b 100644 (file)
@@ -273,6 +273,7 @@ static int gpio_nand_probe(struct platform_device *pdev)
        nand_set_flash_node(chip, pdev->dev.of_node);
        chip->IO_ADDR_W         = chip->IO_ADDR_R;
        chip->ecc.mode          = NAND_ECC_SOFT;
+       chip->ecc.algo          = NAND_ECC_HAMMING;
        chip->options           = gpiomtd->plat.options;
        chip->chip_delay        = gpiomtd->plat.chip_delay;
        chip->cmd_ctrl          = gpio_nand_cmd_ctrl;
index 8122c699ccf20895e400b8ae9246b39db00b1f00..6e461560c6a8eff68f7b0698c73e332c8f6bf28a 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_mtd.h>
 #include "gpmi-nand.h"
 #include "bch-regs.h"
 
@@ -47,10 +46,44 @@ static struct nand_bbt_descr gpmi_bbt_descr = {
  * We may change the layout if we can get the ECC info from the datasheet,
  * else we will use all the (page + OOB).
  */
-static struct nand_ecclayout gpmi_hw_ecclayout = {
-       .eccbytes = 0,
-       .eccpos = { 0, },
-       .oobfree = { {.offset = 0, .length = 0} }
+static int gpmi_ooblayout_ecc(struct mtd_info *mtd, int section,
+                             struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct gpmi_nand_data *this = nand_get_controller_data(chip);
+       struct bch_geometry *geo = &this->bch_geometry;
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 0;
+       oobregion->length = geo->page_size - mtd->writesize;
+
+       return 0;
+}
+
+static int gpmi_ooblayout_free(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct gpmi_nand_data *this = nand_get_controller_data(chip);
+       struct bch_geometry *geo = &this->bch_geometry;
+
+       if (section)
+               return -ERANGE;
+
+       /* The available oob size we have. */
+       if (geo->page_size < mtd->writesize + mtd->oobsize) {
+               oobregion->offset = geo->page_size - mtd->writesize;
+               oobregion->length = mtd->oobsize - oobregion->offset;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops gpmi_ooblayout_ops = {
+       .ecc = gpmi_ooblayout_ecc,
+       .free = gpmi_ooblayout_free,
 };
 
 static const struct gpmi_devdata gpmi_devdata_imx23 = {
@@ -141,7 +174,6 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
        struct bch_geometry *geo = &this->bch_geometry;
        struct nand_chip *chip = &this->nand;
        struct mtd_info *mtd = nand_to_mtd(chip);
-       struct nand_oobfree *of = gpmi_hw_ecclayout.oobfree;
        unsigned int block_mark_bit_offset;
 
        if (!(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0))
@@ -229,12 +261,6 @@ static int set_geometry_by_ecc_info(struct gpmi_nand_data *this)
        geo->page_size = mtd->writesize + geo->metadata_size +
                (geo->gf_len * geo->ecc_strength * geo->ecc_chunk_count) / 8;
 
-       /* The available oob size we have. */
-       if (geo->page_size < mtd->writesize + mtd->oobsize) {
-               of->offset = geo->page_size - mtd->writesize;
-               of->length = mtd->oobsize - of->offset;
-       }
-
        geo->payload_size = mtd->writesize;
 
        geo->auxiliary_status_offset = ALIGN(geo->metadata_size, 4);
@@ -797,6 +823,7 @@ static void gpmi_free_dma_buffer(struct gpmi_nand_data *this)
 
        this->cmd_buffer        = NULL;
        this->data_buffer_dma   = NULL;
+       this->raw_buffer        = NULL;
        this->page_buffer_virt  = NULL;
        this->page_buffer_size  =  0;
 }
@@ -1037,14 +1064,87 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
        /* Loop over status bytes, accumulating ECC status. */
        status = auxiliary_virt + nfc_geo->auxiliary_status_offset;
 
+       read_page_swap_end(this, buf, nfc_geo->payload_size,
+                          this->payload_virt, this->payload_phys,
+                          nfc_geo->payload_size,
+                          payload_virt, payload_phys);
+
        for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) {
                if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED))
                        continue;
 
                if (*status == STATUS_UNCORRECTABLE) {
+                       int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len;
+                       u8 *eccbuf = this->raw_buffer;
+                       int offset, bitoffset;
+                       int eccbytes;
+                       int flips;
+
+                       /* Read ECC bytes into our internal raw_buffer */
+                       offset = nfc_geo->metadata_size * 8;
+                       offset += ((8 * nfc_geo->ecc_chunk_size) + eccbits) * (i + 1);
+                       offset -= eccbits;
+                       bitoffset = offset % 8;
+                       eccbytes = DIV_ROUND_UP(offset + eccbits, 8);
+                       offset /= 8;
+                       eccbytes -= offset;
+                       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, offset, -1);
+                       chip->read_buf(mtd, eccbuf, eccbytes);
+
+                       /*
+                        * ECC data are not byte aligned and we may have
+                        * in-band data in the first and last byte of
+                        * eccbuf. Set non-eccbits to one so that
+                        * nand_check_erased_ecc_chunk() does not count them
+                        * as bitflips.
+                        */
+                       if (bitoffset)
+                               eccbuf[0] |= GENMASK(bitoffset - 1, 0);
+
+                       bitoffset = (bitoffset + eccbits) % 8;
+                       if (bitoffset)
+                               eccbuf[eccbytes - 1] |= GENMASK(7, bitoffset);
+
+                       /*
+                        * The ECC hardware has an uncorrectable ECC status
+                        * code in case we have bitflips in an erased page. As
+                        * nothing was written into this subpage the ECC is
+                        * obviously wrong and we can not trust it. We assume
+                        * at this point that we are reading an erased page and
+                        * try to correct the bitflips in buffer up to
+                        * ecc_strength bitflips. If this is a page with random
+                        * data, we exceed this number of bitflips and have a
+                        * ECC failure. Otherwise we use the corrected buffer.
+                        */
+                       if (i == 0) {
+                               /* The first block includes metadata */
+                               flips = nand_check_erased_ecc_chunk(
+                                               buf + i * nfc_geo->ecc_chunk_size,
+                                               nfc_geo->ecc_chunk_size,
+                                               eccbuf, eccbytes,
+                                               auxiliary_virt,
+                                               nfc_geo->metadata_size,
+                                               nfc_geo->ecc_strength);
+                       } else {
+                               flips = nand_check_erased_ecc_chunk(
+                                               buf + i * nfc_geo->ecc_chunk_size,
+                                               nfc_geo->ecc_chunk_size,
+                                               eccbuf, eccbytes,
+                                               NULL, 0,
+                                               nfc_geo->ecc_strength);
+                       }
+
+                       if (flips > 0) {
+                               max_bitflips = max_t(unsigned int, max_bitflips,
+                                                    flips);
+                               mtd->ecc_stats.corrected += flips;
+                               continue;
+                       }
+
                        mtd->ecc_stats.failed++;
                        continue;
                }
+
                mtd->ecc_stats.corrected += *status;
                max_bitflips = max_t(unsigned int, max_bitflips, *status);
        }
@@ -1064,11 +1164,6 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
                chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0];
        }
 
-       read_page_swap_end(this, buf, nfc_geo->payload_size,
-                       this->payload_virt, this->payload_phys,
-                       nfc_geo->payload_size,
-                       payload_virt, payload_phys);
-
        return max_bitflips;
 }
 
@@ -1327,18 +1422,19 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
 static int
 gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
 {
-       struct nand_oobfree *of = mtd->ecclayout->oobfree;
+       struct mtd_oob_region of = { };
        int status = 0;
 
        /* Do we have available oob area? */
-       if (!of->length)
+       mtd_ooblayout_free(mtd, 0, &of);
+       if (!of.length)
                return -EPERM;
 
        if (!nand_is_slc(chip))
                return -EPERM;
 
-       chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of->offset, page);
-       chip->write_buf(mtd, chip->oob_poi + of->offset, of->length);
+       chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of.offset, page);
+       chip->write_buf(mtd, chip->oob_poi + of.offset, of.length);
        chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
 
        status = chip->waitfunc(mtd, chip);
@@ -1840,6 +1936,7 @@ static void gpmi_nand_exit(struct gpmi_nand_data *this)
 static int gpmi_init_last(struct gpmi_nand_data *this)
 {
        struct nand_chip *chip = &this->nand;
+       struct mtd_info *mtd = nand_to_mtd(chip);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        struct bch_geometry *bch_geo = &this->bch_geometry;
        int ret;
@@ -1861,7 +1958,7 @@ static int gpmi_init_last(struct gpmi_nand_data *this)
        ecc->mode       = NAND_ECC_HW;
        ecc->size       = bch_geo->ecc_chunk_size;
        ecc->strength   = bch_geo->ecc_strength;
-       ecc->layout     = &gpmi_hw_ecclayout;
+       mtd_set_ooblayout(mtd, &gpmi_ooblayout_ops);
 
        /*
         * We only enable the subpage read when:
@@ -1914,16 +2011,6 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
        /* Set up swap_block_mark, must be set before the gpmi_set_geometry() */
        this->swap_block_mark = !GPMI_IS_MX23(this);
 
-       if (of_get_nand_on_flash_bbt(this->dev->of_node)) {
-               chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
-
-               if (of_property_read_bool(this->dev->of_node,
-                                               "fsl,no-blockmark-swap"))
-                       this->swap_block_mark = false;
-       }
-       dev_dbg(this->dev, "Blockmark swapping %sabled\n",
-               this->swap_block_mark ? "en" : "dis");
-
        /*
         * Allocate a temporary DMA buffer for reading ID in the
         * nand_scan_ident().
@@ -1938,6 +2025,16 @@ static int gpmi_nand_init(struct gpmi_nand_data *this)
        if (ret)
                goto err_out;
 
+       if (chip->bbt_options & NAND_BBT_USE_FLASH) {
+               chip->bbt_options |= NAND_BBT_NO_OOB;
+
+               if (of_property_read_bool(this->dev->of_node,
+                                               "fsl,no-blockmark-swap"))
+                       this->swap_block_mark = false;
+       }
+       dev_dbg(this->dev, "Blockmark swapping %sabled\n",
+               this->swap_block_mark ? "en" : "dis");
+
        ret = gpmi_init_last(this);
        if (ret)
                goto err_out;
index 96502b624cfbd73ae4db0b679f2cda3893f61743..9432546f4cd47051e742f03699c4f6058b4915c4 100644 (file)
@@ -19,7 +19,6 @@
  * GNU General Public License for more details.
  */
 #include <linux/of.h>
-#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/sizes.h>
 #include <linux/clk.h>
@@ -631,8 +630,28 @@ static void hisi_nfc_host_init(struct hinfc_host *host)
        hinfc_write(host, HINFC504_INTEN_DMA, HINFC504_INTEN);
 }
 
-static struct nand_ecclayout nand_ecc_2K_16bits = {
-       .oobfree = { {2, 6} },
+static int hisi_ooblayout_ecc(struct mtd_info *mtd, int section,
+                             struct mtd_oob_region *oobregion)
+{
+       /* FIXME: add ECC bytes position */
+       return -ENOTSUPP;
+}
+
+static int hisi_ooblayout_free(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 2;
+       oobregion->length = 6;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops hisi_ooblayout_ops = {
+       .ecc = hisi_ooblayout_ecc,
+       .free = hisi_ooblayout_free,
 };
 
 static int hisi_nfc_ecc_probe(struct hinfc_host *host)
@@ -642,10 +661,9 @@ static int hisi_nfc_ecc_probe(struct hinfc_host *host)
        struct device *dev = host->dev;
        struct nand_chip *chip = &host->chip;
        struct mtd_info *mtd = nand_to_mtd(chip);
-       struct device_node *np = host->dev->of_node;
 
-       size = of_get_nand_ecc_step_size(np);
-       strength = of_get_nand_ecc_strength(np);
+       size = chip->ecc.size;
+       strength = chip->ecc.strength;
        if (size != 1024) {
                dev_err(dev, "error ecc size: %d\n", size);
                return -EINVAL;
@@ -668,7 +686,7 @@ static int hisi_nfc_ecc_probe(struct hinfc_host *host)
        case 16:
                ecc_bits = 6;
                if (mtd->writesize == 2048)
-                       chip->ecc.layout = &nand_ecc_2K_16bits;
+                       mtd_set_ooblayout(mtd, &hisi_ooblayout_ops);
 
                /* TODO: add more page size support */
                break;
@@ -695,7 +713,7 @@ static int hisi_nfc_ecc_probe(struct hinfc_host *host)
 
 static int hisi_nfc_probe(struct platform_device *pdev)
 {
-       int ret = 0, irq, buswidth, flag, max_chips = HINFC504_MAX_CHIP;
+       int ret = 0, irq, flag, max_chips = HINFC504_MAX_CHIP;
        struct device *dev = &pdev->dev;
        struct hinfc_host *host;
        struct nand_chip  *chip;
@@ -747,12 +765,6 @@ static int hisi_nfc_probe(struct platform_device *pdev)
        chip->read_buf          = hisi_nfc_read_buf;
        chip->chip_delay        = HINFC504_CHIP_DELAY;
 
-       chip->ecc.mode = of_get_nand_ecc_mode(np);
-
-       buswidth = of_get_nand_bus_width(np);
-       if (buswidth == 16)
-               chip->options |= NAND_BUSWIDTH_16;
-
        hisi_nfc_host_init(host);
 
        ret = devm_request_irq(dev, irq, hinfc_irq_handle, 0x0, "nandc", host);
index 673ceb2a0b44b677231e030aa8a0f23a5d412e3a..5551c36adbdf173b7df20629c36b065551f9d4ba 100644 (file)
@@ -221,7 +221,6 @@ static int jz_nand_correct_ecc_rs(struct mtd_info *mtd, uint8_t *dat,
        struct jz_nand *nand = mtd_to_jz_nand(mtd);
        int i, error_count, index;
        uint32_t reg, status, error;
-       uint32_t t;
        unsigned int timeout = 1000;
 
        for (i = 0; i < 9; ++i)
@@ -476,7 +475,7 @@ static int jz_nand_probe(struct platform_device *pdev)
        }
 
        if (pdata && pdata->ident_callback) {
-               pdata->ident_callback(pdev, chip, &pdata->partitions,
+               pdata->ident_callback(pdev, mtd, &pdata->partitions,
                                        &pdata->num_partitions);
        }
 
index 755499c6650e4e69614b4d342f9299fce9295b39..d74f4ba4a6f49b45859de1b04e0a3654ca5f2d7d 100644 (file)
@@ -287,7 +287,6 @@ static struct jz4780_bch *jz4780_bch_get(struct device_node *np)
        bch = platform_get_drvdata(pdev);
        clk_prepare_enable(bch->clk);
 
-       bch->dev = &pdev->dev;
        return bch;
 }
 
index e1c016c9d32d2caaf90d3800cf0b4e83d2d55c8c..daf3c4217f4deb034a4e952cb75a237f07c7bf43 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/gpio/consumer.h>
-#include <linux/of_mtd.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/mtd/mtd.h>
@@ -56,8 +55,6 @@ struct jz4780_nand_chip {
        struct nand_chip chip;
        struct list_head chip_list;
 
-       struct nand_ecclayout ecclayout;
-
        struct gpio_desc *busy_gpio;
        struct gpio_desc *wp_gpio;
        unsigned int reading: 1;
@@ -165,8 +162,7 @@ static int jz4780_nand_init_ecc(struct jz4780_nand_chip *nand, struct device *de
        struct nand_chip *chip = &nand->chip;
        struct mtd_info *mtd = nand_to_mtd(chip);
        struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(chip->controller);
-       struct nand_ecclayout *layout = &nand->ecclayout;
-       u32 start, i;
+       int eccbytes;
 
        chip->ecc.bytes = fls((1 + 8) * chip->ecc.size) *
                                (chip->ecc.strength / 8);
@@ -183,7 +179,6 @@ static int jz4780_nand_init_ecc(struct jz4780_nand_chip *nand, struct device *de
                chip->ecc.correct = jz4780_nand_ecc_correct;
                /* fall through */
        case NAND_ECC_SOFT:
-       case NAND_ECC_SOFT_BCH:
                dev_info(dev, "using %s (strength %d, size %d, bytes %d)\n",
                        (nfc->bch) ? "hardware BCH" : "software ECC",
                        chip->ecc.strength, chip->ecc.size, chip->ecc.bytes);
@@ -201,23 +196,17 @@ static int jz4780_nand_init_ecc(struct jz4780_nand_chip *nand, struct device *de
                return 0;
 
        /* Generate ECC layout. ECC codes are right aligned in the OOB area. */
-       layout->eccbytes = mtd->writesize / chip->ecc.size * chip->ecc.bytes;
+       eccbytes = mtd->writesize / chip->ecc.size * chip->ecc.bytes;
 
-       if (layout->eccbytes > mtd->oobsize - 2) {
+       if (eccbytes > mtd->oobsize - 2) {
                dev_err(dev,
                        "invalid ECC config: required %d ECC bytes, but only %d are available",
-                       layout->eccbytes, mtd->oobsize - 2);
+                       eccbytes, mtd->oobsize - 2);
                return -EINVAL;
        }
 
-       start = mtd->oobsize - layout->eccbytes;
-       for (i = 0; i < layout->eccbytes; i++)
-               layout->eccpos[i] = start + i;
-
-       layout->oobfree[0].offset = 2;
-       layout->oobfree[0].length = mtd->oobsize - layout->eccbytes - 2;
+       mtd->ooblayout = &nand_ooblayout_lp_ops;
 
-       chip->ecc.layout = layout;
        return 0;
 }
 
index d8c3e7afcc0bfa74c5d0a87e580ca53a6b28e916..852388171f2033320e7cba102c3be24d312c0f03 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/completion.h>
 #include <linux/interrupt.h>
 #include <linux/of.h>
-#include <linux/of_mtd.h>
 #include <linux/of_gpio.h>
 #include <linux/mtd/lpc32xx_mlc.h>
 #include <linux/io.h>
@@ -139,22 +138,37 @@ struct lpc32xx_nand_cfg_mlc {
        unsigned num_parts;
 };
 
-static struct nand_ecclayout lpc32xx_nand_oob = {
-       .eccbytes = 40,
-       .eccpos = { 6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
-                  22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-                  38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-                  54, 55, 56, 57, 58, 59, 60, 61, 62, 63 },
-       .oobfree = {
-               { .offset = 0,
-                 .length = 6, },
-               { .offset = 16,
-                 .length = 6, },
-               { .offset = 32,
-                 .length = 6, },
-               { .offset = 48,
-                 .length = 6, },
-               },
+static int lpc32xx_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+
+       if (section >= nand_chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = ((section + 1) * 16) - nand_chip->ecc.bytes;
+       oobregion->length = nand_chip->ecc.bytes;
+
+       return 0;
+}
+
+static int lpc32xx_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+
+       if (section >= nand_chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = 16 * section;
+       oobregion->length = 16 - nand_chip->ecc.bytes;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops lpc32xx_ooblayout_ops = {
+       .ecc = lpc32xx_ooblayout_ecc,
+       .free = lpc32xx_ooblayout_free,
 };
 
 static struct nand_bbt_descr lpc32xx_nand_bbt = {
@@ -713,6 +727,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
        nand_chip->ecc.write_oob = lpc32xx_write_oob;
        nand_chip->ecc.read_oob = lpc32xx_read_oob;
        nand_chip->ecc.strength = 4;
+       nand_chip->ecc.bytes = 10;
        nand_chip->waitfunc = lpc32xx_waitfunc;
 
        nand_chip->options = NAND_NO_SUBPAGE_WRITE;
@@ -751,7 +766,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
 
        nand_chip->ecc.mode = NAND_ECC_HW;
        nand_chip->ecc.size = 512;
-       nand_chip->ecc.layout = &lpc32xx_nand_oob;
+       mtd_set_ooblayout(mtd, &lpc32xx_ooblayout_ops);
        host->mlcsubpages = mtd->writesize / 512;
 
        /* initially clear interrupt status */
index 3b8f3735f3e86324f36b0bd4484aab2cda571fb9..8d3edc34958e7b356431c92b0b9ad43c89ac062c 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/mtd/nand_ecc.h>
 #include <linux/gpio.h>
 #include <linux/of.h>
-#include <linux/of_mtd.h>
 #include <linux/of_gpio.h>
 #include <linux/mtd/lpc32xx_slc.h>
 
  * NAND ECC Layout for small page NAND devices
  * Note: For large and huge page devices, the default layouts are used
  */
-static struct nand_ecclayout lpc32xx_nand_oob_16 = {
-       .eccbytes = 6,
-       .eccpos = {10, 11, 12, 13, 14, 15},
-       .oobfree = {
-               { .offset = 0, .length = 4 },
-               { .offset = 6, .length = 4 },
-       },
+static int lpc32xx_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = 6;
+       oobregion->offset = 10;
+
+       return 0;
+}
+
+static int lpc32xx_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       if (!section) {
+               oobregion->offset = 0;
+               oobregion->length = 4;
+       } else {
+               oobregion->offset = 6;
+               oobregion->length = 4;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops lpc32xx_ooblayout_ops = {
+       .ecc = lpc32xx_ooblayout_ecc,
+       .free = lpc32xx_ooblayout_free,
 };
 
 static u8 bbt_pattern[] = {'B', 'b', 't', '0' };
@@ -194,7 +218,6 @@ struct lpc32xx_nand_cfg_slc {
        uint32_t rwidth;
        uint32_t rhold;
        uint32_t rsetup;
-       bool use_bbt;
        int wp_gpio;
        struct mtd_partition *parts;
        unsigned num_parts;
@@ -604,7 +627,8 @@ static int lpc32xx_nand_read_page_syndrome(struct mtd_info *mtd,
                                           int oob_required, int page)
 {
        struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
-       int stat, i, status;
+       struct mtd_oob_region oobregion = { };
+       int stat, i, status, error;
        uint8_t *oobecc, tmpecc[LPC32XX_ECC_SAVE_SIZE];
 
        /* Issue read command */
@@ -620,7 +644,11 @@ static int lpc32xx_nand_read_page_syndrome(struct mtd_info *mtd,
        lpc32xx_slc_ecc_copy(tmpecc, (uint32_t *) host->ecc_buf, chip->ecc.steps);
 
        /* Pointer to ECC data retrieved from NAND spare area */
-       oobecc = chip->oob_poi + chip->ecc.layout->eccpos[0];
+       error = mtd_ooblayout_ecc(mtd, 0, &oobregion);
+       if (error)
+               return error;
+
+       oobecc = chip->oob_poi + oobregion.offset;
 
        for (i = 0; i < chip->ecc.steps; i++) {
                stat = chip->ecc.correct(mtd, buf, oobecc,
@@ -666,7 +694,8 @@ static int lpc32xx_nand_write_page_syndrome(struct mtd_info *mtd,
                                            int oob_required, int page)
 {
        struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
-       uint8_t *pb = chip->oob_poi + chip->ecc.layout->eccpos[0];
+       struct mtd_oob_region oobregion = { };
+       uint8_t *pb;
        int error;
 
        /* Write data, calculate ECC on outbound data */
@@ -678,6 +707,11 @@ static int lpc32xx_nand_write_page_syndrome(struct mtd_info *mtd,
         * The calculated ECC needs some manual work done to it before
         * committing it to NAND. Process the calculated ECC and place
         * the resultant values directly into the OOB buffer. */
+       error = mtd_ooblayout_ecc(mtd, 0, &oobregion);
+       if (error)
+               return error;
+
+       pb = chip->oob_poi + oobregion.offset;
        lpc32xx_slc_ecc_copy(pb, (uint32_t *)host->ecc_buf, chip->ecc.steps);
 
        /* Write ECC data to device */
@@ -747,7 +781,6 @@ static struct lpc32xx_nand_cfg_slc *lpc32xx_parse_dt(struct device *dev)
                return NULL;
        }
 
-       ncfg->use_bbt = of_get_nand_on_flash_bbt(np);
        ncfg->wp_gpio = of_get_named_gpio(np, "gpios", 0);
 
        return ncfg;
@@ -875,26 +908,22 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
         * custom BBT marker layout.
         */
        if (mtd->writesize <= 512)
-               chip->ecc.layout = &lpc32xx_nand_oob_16;
+               mtd_set_ooblayout(mtd, &lpc32xx_ooblayout_ops);
 
        /* These sizes remain the same regardless of page size */
        chip->ecc.size = 256;
        chip->ecc.bytes = LPC32XX_SLC_DEV_ECC_BYTES;
        chip->ecc.prepad = chip->ecc.postpad = 0;
 
-       /* Avoid extra scan if using BBT, setup BBT support */
-       if (host->ncfg->use_bbt) {
-               chip->bbt_options |= NAND_BBT_USE_FLASH;
-
-               /*
-                * Use a custom BBT marker setup for small page FLASH that
-                * won't interfere with the ECC layout. Large and huge page
-                * FLASH use the standard layout.
-                */
-               if (mtd->writesize <= 512) {
-                       chip->bbt_td = &bbt_smallpage_main_descr;
-                       chip->bbt_md = &bbt_smallpage_mirror_descr;
-               }
+       /*
+        * Use a custom BBT marker setup for small page FLASH that
+        * won't interfere with the ECC layout. Large and huge page
+        * FLASH use the standard layout.
+        */
+       if ((chip->bbt_options & NAND_BBT_USE_FLASH) &&
+           mtd->writesize <= 512) {
+               chip->bbt_td = &bbt_smallpage_main_descr;
+               chip->bbt_md = &bbt_smallpage_mirror_descr;
        }
 
        /*
index 5d7843ffff6ac0c85c8a5cc9a11901eb603fdd1b..7eacb2f545f50366cc8996d48d3f46aaf9ed195c 100644 (file)
@@ -710,6 +710,7 @@ static int mpc5121_nfc_probe(struct platform_device *op)
        chip->select_chip = mpc5121_nfc_select_chip;
        chip->bbt_options = NAND_BBT_USE_FLASH;
        chip->ecc.mode = NAND_ECC_SOFT;
+       chip->ecc.algo = NAND_ECC_HAMMING;
 
        /* Support external chip-select logic on ADS5121 board */
        if (of_machine_is_compatible("fsl,mpc5121ads")) {
index 854c832597aa69c52121f7f39e777e36db9ce764..5173fadc9a4e637f01817ed040a42b72af1d7a68 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/completion.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_mtd.h>
 
 #include <asm/mach/flash.h>
 #include <linux/platform_data/mtd-mxc_nand.h>
@@ -149,7 +148,7 @@ struct mxc_nand_devtype_data {
        int (*check_int)(struct mxc_nand_host *);
        void (*irq_control)(struct mxc_nand_host *, int);
        u32 (*get_ecc_status)(struct mxc_nand_host *);
-       struct nand_ecclayout *ecclayout_512, *ecclayout_2k, *ecclayout_4k;
+       const struct mtd_ooblayout_ops *ooblayout;
        void (*select_chip)(struct mtd_info *mtd, int chip);
        int (*correct_data)(struct mtd_info *mtd, u_char *dat,
                        u_char *read_ecc, u_char *calc_ecc);
@@ -200,73 +199,6 @@ struct mxc_nand_host {
        struct mxc_nand_platform_data pdata;
 };
 
-/* OOB placement block for use with hardware ecc generation */
-static struct nand_ecclayout nandv1_hw_eccoob_smallpage = {
-       .eccbytes = 5,
-       .eccpos = {6, 7, 8, 9, 10},
-       .oobfree = {{0, 5}, {12, 4}, }
-};
-
-static struct nand_ecclayout nandv1_hw_eccoob_largepage = {
-       .eccbytes = 20,
-       .eccpos = {6, 7, 8, 9, 10, 22, 23, 24, 25, 26,
-                  38, 39, 40, 41, 42, 54, 55, 56, 57, 58},
-       .oobfree = {{2, 4}, {11, 10}, {27, 10}, {43, 10}, {59, 5}, }
-};
-
-/* OOB description for 512 byte pages with 16 byte OOB */
-static struct nand_ecclayout nandv2_hw_eccoob_smallpage = {
-       .eccbytes = 1 * 9,
-       .eccpos = {
-                7,  8,  9, 10, 11, 12, 13, 14, 15
-       },
-       .oobfree = {
-               {.offset = 0, .length = 5}
-       }
-};
-
-/* OOB description for 2048 byte pages with 64 byte OOB */
-static struct nand_ecclayout nandv2_hw_eccoob_largepage = {
-       .eccbytes = 4 * 9,
-       .eccpos = {
-                7,  8,  9, 10, 11, 12, 13, 14, 15,
-               23, 24, 25, 26, 27, 28, 29, 30, 31,
-               39, 40, 41, 42, 43, 44, 45, 46, 47,
-               55, 56, 57, 58, 59, 60, 61, 62, 63
-       },
-       .oobfree = {
-               {.offset = 2, .length = 4},
-               {.offset = 16, .length = 7},
-               {.offset = 32, .length = 7},
-               {.offset = 48, .length = 7}
-       }
-};
-
-/* OOB description for 4096 byte pages with 128 byte OOB */
-static struct nand_ecclayout nandv2_hw_eccoob_4k = {
-       .eccbytes = 8 * 9,
-       .eccpos = {
-               7,  8,  9, 10, 11, 12, 13, 14, 15,
-               23, 24, 25, 26, 27, 28, 29, 30, 31,
-               39, 40, 41, 42, 43, 44, 45, 46, 47,
-               55, 56, 57, 58, 59, 60, 61, 62, 63,
-               71, 72, 73, 74, 75, 76, 77, 78, 79,
-               87, 88, 89, 90, 91, 92, 93, 94, 95,
-               103, 104, 105, 106, 107, 108, 109, 110, 111,
-               119, 120, 121, 122, 123, 124, 125, 126, 127,
-       },
-       .oobfree = {
-               {.offset = 2, .length = 4},
-               {.offset = 16, .length = 7},
-               {.offset = 32, .length = 7},
-               {.offset = 48, .length = 7},
-               {.offset = 64, .length = 7},
-               {.offset = 80, .length = 7},
-               {.offset = 96, .length = 7},
-               {.offset = 112, .length = 7},
-       }
-};
-
 static const char * const part_probes[] = {
        "cmdlinepart", "RedBoot", "ofpart", NULL };
 
@@ -942,6 +874,99 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
        }
 }
 
+static int mxc_v1_ooblayout_ecc(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+
+       if (section >= nand_chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 6;
+       oobregion->length = nand_chip->ecc.bytes;
+
+       return 0;
+}
+
+static int mxc_v1_ooblayout_free(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+
+       if (section > nand_chip->ecc.steps)
+               return -ERANGE;
+
+       if (!section) {
+               if (mtd->writesize <= 512) {
+                       oobregion->offset = 0;
+                       oobregion->length = 5;
+               } else {
+                       oobregion->offset = 2;
+                       oobregion->length = 4;
+               }
+       } else {
+               oobregion->offset = ((section - 1) * 16) +
+                                   nand_chip->ecc.bytes + 6;
+               if (section < nand_chip->ecc.steps)
+                       oobregion->length = (section * 16) + 6 -
+                                           oobregion->offset;
+               else
+                       oobregion->length = mtd->oobsize - oobregion->offset;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops mxc_v1_ooblayout_ops = {
+       .ecc = mxc_v1_ooblayout_ecc,
+       .free = mxc_v1_ooblayout_free,
+};
+
+static int mxc_v2_ooblayout_ecc(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       int stepsize = nand_chip->ecc.bytes == 9 ? 16 : 26;
+
+       if (section >= nand_chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = (section * stepsize) + 7;
+       oobregion->length = nand_chip->ecc.bytes;
+
+       return 0;
+}
+
+static int mxc_v2_ooblayout_free(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand_chip = mtd_to_nand(mtd);
+       int stepsize = nand_chip->ecc.bytes == 9 ? 16 : 26;
+
+       if (section > nand_chip->ecc.steps)
+               return -ERANGE;
+
+       if (!section) {
+               if (mtd->writesize <= 512) {
+                       oobregion->offset = 0;
+                       oobregion->length = 5;
+               } else {
+                       oobregion->offset = 2;
+                       oobregion->length = 4;
+               }
+       } else {
+               oobregion->offset = section * stepsize;
+               oobregion->length = 7;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops mxc_v2_ooblayout_ops = {
+       .ecc = mxc_v2_ooblayout_ecc,
+       .free = mxc_v2_ooblayout_free,
+};
+
 /*
  * v2 and v3 type controllers can do 4bit or 8bit ecc depending
  * on how much oob the nand chip has. For 8bit ecc we need at least
@@ -959,23 +984,6 @@ static int get_eccsize(struct mtd_info *mtd)
                return 8;
 }
 
-static void ecc_8bit_layout_4k(struct nand_ecclayout *layout)
-{
-       int i, j;
-
-       layout->eccbytes = 8*18;
-       for (i = 0; i < 8; i++)
-               for (j = 0; j < 18; j++)
-                       layout->eccpos[i*18 + j] = i*26 + j + 7;
-
-       layout->oobfree[0].offset = 2;
-       layout->oobfree[0].length = 4;
-       for (i = 1; i < 8; i++) {
-               layout->oobfree[i].offset = i*26;
-               layout->oobfree[i].length = 7;
-       }
-}
-
 static void preset_v1(struct mtd_info *mtd)
 {
        struct nand_chip *nand_chip = mtd_to_nand(mtd);
@@ -1269,9 +1277,7 @@ static const struct mxc_nand_devtype_data imx21_nand_devtype_data = {
        .check_int = check_int_v1_v2,
        .irq_control = irq_control_v1_v2,
        .get_ecc_status = get_ecc_status_v1,
-       .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
-       .ecclayout_2k = &nandv1_hw_eccoob_largepage,
-       .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
+       .ooblayout = &mxc_v1_ooblayout_ops,
        .select_chip = mxc_nand_select_chip_v1_v3,
        .correct_data = mxc_nand_correct_data_v1,
        .irqpending_quirk = 1,
@@ -1294,9 +1300,7 @@ static const struct mxc_nand_devtype_data imx27_nand_devtype_data = {
        .check_int = check_int_v1_v2,
        .irq_control = irq_control_v1_v2,
        .get_ecc_status = get_ecc_status_v1,
-       .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
-       .ecclayout_2k = &nandv1_hw_eccoob_largepage,
-       .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
+       .ooblayout = &mxc_v1_ooblayout_ops,
        .select_chip = mxc_nand_select_chip_v1_v3,
        .correct_data = mxc_nand_correct_data_v1,
        .irqpending_quirk = 0,
@@ -1320,9 +1324,7 @@ static const struct mxc_nand_devtype_data imx25_nand_devtype_data = {
        .check_int = check_int_v1_v2,
        .irq_control = irq_control_v1_v2,
        .get_ecc_status = get_ecc_status_v2,
-       .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
-       .ecclayout_2k = &nandv2_hw_eccoob_largepage,
-       .ecclayout_4k = &nandv2_hw_eccoob_4k,
+       .ooblayout = &mxc_v2_ooblayout_ops,
        .select_chip = mxc_nand_select_chip_v2,
        .correct_data = mxc_nand_correct_data_v2_v3,
        .irqpending_quirk = 0,
@@ -1346,9 +1348,7 @@ static const struct mxc_nand_devtype_data imx51_nand_devtype_data = {
        .check_int = check_int_v3,
        .irq_control = irq_control_v3,
        .get_ecc_status = get_ecc_status_v3,
-       .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
-       .ecclayout_2k = &nandv2_hw_eccoob_largepage,
-       .ecclayout_4k = &nandv2_hw_eccoob_smallpage, /* XXX: needs fix */
+       .ooblayout = &mxc_v2_ooblayout_ops,
        .select_chip = mxc_nand_select_chip_v1_v3,
        .correct_data = mxc_nand_correct_data_v2_v3,
        .irqpending_quirk = 0,
@@ -1373,9 +1373,7 @@ static const struct mxc_nand_devtype_data imx53_nand_devtype_data = {
        .check_int = check_int_v3,
        .irq_control = irq_control_v3,
        .get_ecc_status = get_ecc_status_v3,
-       .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
-       .ecclayout_2k = &nandv2_hw_eccoob_largepage,
-       .ecclayout_4k = &nandv2_hw_eccoob_smallpage, /* XXX: needs fix */
+       .ooblayout = &mxc_v2_ooblayout_ops,
        .select_chip = mxc_nand_select_chip_v1_v3,
        .correct_data = mxc_nand_correct_data_v2_v3,
        .irqpending_quirk = 0,
@@ -1461,25 +1459,12 @@ MODULE_DEVICE_TABLE(of, mxcnd_dt_ids);
 static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
 {
        struct device_node *np = host->dev->of_node;
-       struct mxc_nand_platform_data *pdata = &host->pdata;
        const struct of_device_id *of_id =
                of_match_device(mxcnd_dt_ids, host->dev);
-       int buswidth;
 
        if (!np)
                return 1;
 
-       if (of_get_nand_ecc_mode(np) >= 0)
-               pdata->hw_ecc = 1;
-
-       pdata->flash_bbt = of_get_nand_on_flash_bbt(np);
-
-       buswidth = of_get_nand_bus_width(np);
-       if (buswidth < 0)
-               return buswidth;
-
-       pdata->width = buswidth / 8;
-
        host->devtype_data = of_id->data;
 
        return 0;
@@ -1576,27 +1561,22 @@ static int mxcnd_probe(struct platform_device *pdev)
 
        this->select_chip = host->devtype_data->select_chip;
        this->ecc.size = 512;
-       this->ecc.layout = host->devtype_data->ecclayout_512;
+       mtd_set_ooblayout(mtd, host->devtype_data->ooblayout);
 
        if (host->pdata.hw_ecc) {
-               this->ecc.calculate = mxc_nand_calculate_ecc;
-               this->ecc.hwctl = mxc_nand_enable_hwecc;
-               this->ecc.correct = host->devtype_data->correct_data;
                this->ecc.mode = NAND_ECC_HW;
        } else {
                this->ecc.mode = NAND_ECC_SOFT;
+               this->ecc.algo = NAND_ECC_HAMMING;
        }
 
        /* NAND bus width determines access functions used by upper layer */
        if (host->pdata.width == 2)
                this->options |= NAND_BUSWIDTH_16;
 
-       if (host->pdata.flash_bbt) {
-               this->bbt_td = &bbt_main_descr;
-               this->bbt_md = &bbt_mirror_descr;
-               /* update flash based bbt */
+       /* update flash based bbt */
+       if (host->pdata.flash_bbt)
                this->bbt_options |= NAND_BBT_USE_FLASH;
-       }
 
        init_completion(&host->op_completion);
 
@@ -1637,6 +1617,26 @@ static int mxcnd_probe(struct platform_device *pdev)
                goto escan;
        }
 
+       switch (this->ecc.mode) {
+       case NAND_ECC_HW:
+               this->ecc.calculate = mxc_nand_calculate_ecc;
+               this->ecc.hwctl = mxc_nand_enable_hwecc;
+               this->ecc.correct = host->devtype_data->correct_data;
+               break;
+
+       case NAND_ECC_SOFT:
+               break;
+
+       default:
+               err = -EINVAL;
+               goto escan;
+       }
+
+       if (this->bbt_options & NAND_BBT_USE_FLASH) {
+               this->bbt_td = &bbt_main_descr;
+               this->bbt_md = &bbt_mirror_descr;
+       }
+
        /* allocate the right size buffer now */
        devm_kfree(&pdev->dev, (void *)host->data_buf);
        host->data_buf = devm_kzalloc(&pdev->dev, mtd->writesize + mtd->oobsize,
@@ -1649,12 +1649,11 @@ static int mxcnd_probe(struct platform_device *pdev)
        /* Call preset again, with correct writesize this time */
        host->devtype_data->preset(mtd);
 
-       if (mtd->writesize == 2048)
-               this->ecc.layout = host->devtype_data->ecclayout_2k;
-       else if (mtd->writesize == 4096) {
-               this->ecc.layout = host->devtype_data->ecclayout_4k;
-               if (get_eccsize(mtd) == 8)
-                       ecc_8bit_layout_4k(this->ecc.layout);
+       if (!this->ecc.bytes) {
+               if (host->eccsize == 8)
+                       this->ecc.bytes = 18;
+               else if (host->eccsize == 4)
+                       this->ecc.bytes = 9;
        }
 
        /*
index ba4f603e05375b32de7bf01f3bde05967bc0268e..0b0dc29d2af78b59ca36bb7f706b1139e065f55a 100644 (file)
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/mtd/partitions.h>
-#include <linux/of_mtd.h>
+#include <linux/of.h>
+
+static int nand_get_device(struct mtd_info *mtd, int new_state);
+
+static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
+                            struct mtd_oob_ops *ops);
 
 /* Define default oob placement schemes for large and small page devices */
-static struct nand_ecclayout nand_oob_8 = {
-       .eccbytes = 3,
-       .eccpos = {0, 1, 2},
-       .oobfree = {
-               {.offset = 3,
-                .length = 2},
-               {.offset = 6,
-                .length = 2} }
-};
+static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
 
-static struct nand_ecclayout nand_oob_16 = {
-       .eccbytes = 6,
-       .eccpos = {0, 1, 2, 3, 6, 7},
-       .oobfree = {
-               {.offset = 8,
-                . length = 8} }
-};
+       if (section > 1)
+               return -ERANGE;
 
-static struct nand_ecclayout nand_oob_64 = {
-       .eccbytes = 24,
-       .eccpos = {
-                  40, 41, 42, 43, 44, 45, 46, 47,
-                  48, 49, 50, 51, 52, 53, 54, 55,
-                  56, 57, 58, 59, 60, 61, 62, 63},
-       .oobfree = {
-               {.offset = 2,
-                .length = 38} }
-};
+       if (!section) {
+               oobregion->offset = 0;
+               oobregion->length = 4;
+       } else {
+               oobregion->offset = 6;
+               oobregion->length = ecc->total - 4;
+       }
+
+       return 0;
+}
+
+static int nand_ooblayout_free_sp(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       if (mtd->oobsize == 16) {
+               if (section)
+                       return -ERANGE;
+
+               oobregion->length = 8;
+               oobregion->offset = 8;
+       } else {
+               oobregion->length = 2;
+               if (!section)
+                       oobregion->offset = 3;
+               else
+                       oobregion->offset = 6;
+       }
+
+       return 0;
+}
 
-static struct nand_ecclayout nand_oob_128 = {
-       .eccbytes = 48,
-       .eccpos = {
-                  80, 81, 82, 83, 84, 85, 86, 87,
-                  88, 89, 90, 91, 92, 93, 94, 95,
-                  96, 97, 98, 99, 100, 101, 102, 103,
-                  104, 105, 106, 107, 108, 109, 110, 111,
-                  112, 113, 114, 115, 116, 117, 118, 119,
-                  120, 121, 122, 123, 124, 125, 126, 127},
-       .oobfree = {
-               {.offset = 2,
-                .length = 78} }
+const struct mtd_ooblayout_ops nand_ooblayout_sp_ops = {
+       .ecc = nand_ooblayout_ecc_sp,
+       .free = nand_ooblayout_free_sp,
 };
+EXPORT_SYMBOL_GPL(nand_ooblayout_sp_ops);
 
-static int nand_get_device(struct mtd_info *mtd, int new_state);
+static int nand_ooblayout_ecc_lp(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
 
-static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
-                            struct mtd_oob_ops *ops);
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = ecc->total;
+       oobregion->offset = mtd->oobsize - oobregion->length;
+
+       return 0;
+}
+
+static int nand_ooblayout_free_lp(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = mtd->oobsize - ecc->total - 2;
+       oobregion->offset = 2;
+
+       return 0;
+}
+
+const struct mtd_ooblayout_ops nand_ooblayout_lp_ops = {
+       .ecc = nand_ooblayout_ecc_lp,
+       .free = nand_ooblayout_free_lp,
+};
+EXPORT_SYMBOL_GPL(nand_ooblayout_lp_ops);
 
 static int check_offs_len(struct mtd_info *mtd,
                                        loff_t ofs, uint64_t len)
@@ -1279,13 +1321,12 @@ static int nand_read_page_raw_syndrome(struct mtd_info *mtd,
 static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
                                uint8_t *buf, int oob_required, int page)
 {
-       int i, eccsize = chip->ecc.size;
+       int i, eccsize = chip->ecc.size, ret;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        uint8_t *ecc_code = chip->buffers->ecccode;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
        unsigned int max_bitflips = 0;
 
        chip->ecc.read_page_raw(mtd, chip, buf, 1, page);
@@ -1293,8 +1334,10 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       for (i = 0; i < chip->ecc.total; i++)
-               ecc_code[i] = chip->oob_poi[eccpos[i]];
+       ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        eccsteps = chip->ecc.steps;
        p = buf;
@@ -1326,14 +1369,14 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
                        uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi,
                        int page)
 {
-       int start_step, end_step, num_steps;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
+       int start_step, end_step, num_steps, ret;
        uint8_t *p;
        int data_col_addr, i, gaps = 0;
        int datafrag_len, eccfrag_len, aligned_len, aligned_pos;
        int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1;
-       int index;
+       int index, section = 0;
        unsigned int max_bitflips = 0;
+       struct mtd_oob_region oobregion = { };
 
        /* Column address within the page aligned to ECC size (256bytes) */
        start_step = data_offs / chip->ecc.size;
@@ -1361,12 +1404,13 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
         * The performance is faster if we position offsets according to
         * ecc.pos. Let's make sure that there are no gaps in ECC positions.
         */
-       for (i = 0; i < eccfrag_len - 1; i++) {
-               if (eccpos[i + index] + 1 != eccpos[i + index + 1]) {
-                       gaps = 1;
-                       break;
-               }
-       }
+       ret = mtd_ooblayout_find_eccregion(mtd, index, &section, &oobregion);
+       if (ret)
+               return ret;
+
+       if (oobregion.length < eccfrag_len)
+               gaps = 1;
+
        if (gaps) {
                chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
                chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -1375,20 +1419,23 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
                 * Send the command to read the particular ECC bytes take care
                 * about buswidth alignment in read_buf.
                 */
-               aligned_pos = eccpos[index] & ~(busw - 1);
+               aligned_pos = oobregion.offset & ~(busw - 1);
                aligned_len = eccfrag_len;
-               if (eccpos[index] & (busw - 1))
+               if (oobregion.offset & (busw - 1))
                        aligned_len++;
-               if (eccpos[index + (num_steps * chip->ecc.bytes)] & (busw - 1))
+               if ((oobregion.offset + (num_steps * chip->ecc.bytes)) &
+                   (busw - 1))
                        aligned_len++;
 
                chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
-                                       mtd->writesize + aligned_pos, -1);
+                             mtd->writesize + aligned_pos, -1);
                chip->read_buf(mtd, &chip->oob_poi[aligned_pos], aligned_len);
        }
 
-       for (i = 0; i < eccfrag_len; i++)
-               chip->buffers->ecccode[i] = chip->oob_poi[eccpos[i + index]];
+       ret = mtd_ooblayout_get_eccbytes(mtd, chip->buffers->ecccode,
+                                        chip->oob_poi, index, eccfrag_len);
+       if (ret)
+               return ret;
 
        p = bufpoi + data_col_addr;
        for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) {
@@ -1429,13 +1476,12 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
 static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                                uint8_t *buf, int oob_required, int page)
 {
-       int i, eccsize = chip->ecc.size;
+       int i, eccsize = chip->ecc.size, ret;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        uint8_t *ecc_code = chip->buffers->ecccode;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
        unsigned int max_bitflips = 0;
 
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
@@ -1445,8 +1491,10 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
        }
        chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
 
-       for (i = 0; i < chip->ecc.total; i++)
-               ecc_code[i] = chip->oob_poi[eccpos[i]];
+       ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        eccsteps = chip->ecc.steps;
        p = buf;
@@ -1491,12 +1539,11 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
        struct nand_chip *chip, uint8_t *buf, int oob_required, int page)
 {
-       int i, eccsize = chip->ecc.size;
+       int i, eccsize = chip->ecc.size, ret;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
        uint8_t *p = buf;
        uint8_t *ecc_code = chip->buffers->ecccode;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        unsigned int max_bitflips = 0;
 
@@ -1505,8 +1552,10 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
        chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
        chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
 
-       for (i = 0; i < chip->ecc.total; i++)
-               ecc_code[i] = chip->oob_poi[eccpos[i]];
+       ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
                int stat;
@@ -1607,14 +1656,17 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
 
 /**
  * nand_transfer_oob - [INTERN] Transfer oob to client buffer
- * @chip: nand chip structure
+ * @mtd: mtd info structure
  * @oob: oob destination address
  * @ops: oob ops structure
  * @len: size of oob to transfer
  */
-static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
+static uint8_t *nand_transfer_oob(struct mtd_info *mtd, uint8_t *oob,
                                  struct mtd_oob_ops *ops, size_t len)
 {
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       int ret;
+
        switch (ops->mode) {
 
        case MTD_OPS_PLACE_OOB:
@@ -1622,31 +1674,12 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob,
                memcpy(oob, chip->oob_poi + ops->ooboffs, len);
                return oob + len;
 
-       case MTD_OPS_AUTO_OOB: {
-               struct nand_oobfree *free = chip->ecc.layout->oobfree;
-               uint32_t boffs = 0, roffs = ops->ooboffs;
-               size_t bytes = 0;
-
-               for (; free->length && len; free++, len -= bytes) {
-                       /* Read request not from offset 0? */
-                       if (unlikely(roffs)) {
-                               if (roffs >= free->length) {
-                                       roffs -= free->length;
-                                       continue;
-                               }
-                               boffs = free->offset + roffs;
-                               bytes = min_t(size_t, len,
-                                             (free->length - roffs));
-                               roffs = 0;
-                       } else {
-                               bytes = min_t(size_t, len, free->length);
-                               boffs = free->offset;
-                       }
-                       memcpy(oob, chip->oob_poi + boffs, bytes);
-                       oob += bytes;
-               }
-               return oob;
-       }
+       case MTD_OPS_AUTO_OOB:
+               ret = mtd_ooblayout_get_databytes(mtd, oob, chip->oob_poi,
+                                                 ops->ooboffs, len);
+               BUG_ON(ret);
+               return oob + len;
+
        default:
                BUG();
        }
@@ -1780,7 +1813,7 @@ read_retry:
                                int toread = min(oobreadlen, max_oobsize);
 
                                if (toread) {
-                                       oob = nand_transfer_oob(chip,
+                                       oob = nand_transfer_oob(mtd,
                                                oob, ops, toread);
                                        oobreadlen -= toread;
                                }
@@ -1893,13 +1926,13 @@ static int nand_read(struct mtd_info *mtd, loff_t from, size_t len,
  * @chip: nand chip info structure
  * @page: page number to read
  */
-static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
-                            int page)
+int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page)
 {
        chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
        chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
        return 0;
 }
+EXPORT_SYMBOL(nand_read_oob_std);
 
 /**
  * nand_read_oob_syndrome - [REPLACEABLE] OOB data read function for HW ECC
@@ -1908,8 +1941,8 @@ static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
  * @chip: nand chip info structure
  * @page: page number to read
  */
-static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
-                                 int page)
+int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
+                          int page)
 {
        int length = mtd->oobsize;
        int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -1937,6 +1970,7 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
 
        return 0;
 }
+EXPORT_SYMBOL(nand_read_oob_syndrome);
 
 /**
  * nand_write_oob_std - [REPLACEABLE] the most common OOB data write function
@@ -1944,8 +1978,7 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
  * @chip: nand chip info structure
  * @page: page number to write
  */
-static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
-                             int page)
+int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page)
 {
        int status = 0;
        const uint8_t *buf = chip->oob_poi;
@@ -1960,6 +1993,7 @@ static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
 
        return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
+EXPORT_SYMBOL(nand_write_oob_std);
 
 /**
  * nand_write_oob_syndrome - [REPLACEABLE] OOB data write function for HW ECC
@@ -1968,8 +2002,8 @@ static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
  * @chip: nand chip info structure
  * @page: page number to write
  */
-static int nand_write_oob_syndrome(struct mtd_info *mtd,
-                                  struct nand_chip *chip, int page)
+int nand_write_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
+                           int page)
 {
        int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
        int eccsize = chip->ecc.size, length = mtd->oobsize;
@@ -2019,6 +2053,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd,
 
        return status & NAND_STATUS_FAIL ? -EIO : 0;
 }
+EXPORT_SYMBOL(nand_write_oob_syndrome);
 
 /**
  * nand_do_read_oob - [INTERN] NAND read out-of-band
@@ -2078,7 +2113,7 @@ static int nand_do_read_oob(struct mtd_info *mtd, loff_t from,
                        break;
 
                len = min(len, readlen);
-               buf = nand_transfer_oob(chip, buf, ops, len);
+               buf = nand_transfer_oob(mtd, buf, ops, len);
 
                if (chip->options & NAND_NEED_READRDY) {
                        /* Apply delay or wait for ready/busy pin */
@@ -2237,19 +2272,20 @@ static int nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
                                 const uint8_t *buf, int oob_required,
                                 int page)
 {
-       int i, eccsize = chip->ecc.size;
+       int i, eccsize = chip->ecc.size, ret;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        const uint8_t *p = buf;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
 
        /* Software ECC calculation */
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-       for (i = 0; i < chip->ecc.total; i++)
-               chip->oob_poi[eccpos[i]] = ecc_calc[i];
+       ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        return chip->ecc.write_page_raw(mtd, chip, buf, 1, page);
 }
@@ -2266,12 +2302,11 @@ static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                                  const uint8_t *buf, int oob_required,
                                  int page)
 {
-       int i, eccsize = chip->ecc.size;
+       int i, eccsize = chip->ecc.size, ret;
        int eccbytes = chip->ecc.bytes;
        int eccsteps = chip->ecc.steps;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        const uint8_t *p = buf;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
 
        for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
                chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
@@ -2279,8 +2314,10 @@ static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                chip->ecc.calculate(mtd, p, &ecc_calc[i]);
        }
 
-       for (i = 0; i < chip->ecc.total; i++)
-               chip->oob_poi[eccpos[i]] = ecc_calc[i];
+       ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
 
@@ -2308,11 +2345,10 @@ static int nand_write_subpage_hwecc(struct mtd_info *mtd,
        int ecc_size      = chip->ecc.size;
        int ecc_bytes     = chip->ecc.bytes;
        int ecc_steps     = chip->ecc.steps;
-       uint32_t *eccpos  = chip->ecc.layout->eccpos;
        uint32_t start_step = offset / ecc_size;
        uint32_t end_step   = (offset + data_len - 1) / ecc_size;
        int oob_bytes       = mtd->oobsize / ecc_steps;
-       int step, i;
+       int step, ret;
 
        for (step = 0; step < ecc_steps; step++) {
                /* configure controller for WRITE access */
@@ -2340,8 +2376,10 @@ static int nand_write_subpage_hwecc(struct mtd_info *mtd,
        /* copy calculated ECC for whole page to chip->buffer->oob */
        /* this include masked-value(0xFF) for unwritten subpages */
        ecc_calc = chip->buffers->ecccalc;
-       for (i = 0; i < chip->ecc.total; i++)
-               chip->oob_poi[eccpos[i]] = ecc_calc[i];
+       ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        /* write OOB buffer to NAND device */
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -2478,6 +2516,7 @@ static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
                              struct mtd_oob_ops *ops)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
+       int ret;
 
        /*
         * Initialise to all 0xFF, to avoid the possibility of left over OOB
@@ -2492,31 +2531,12 @@ static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len,
                memcpy(chip->oob_poi + ops->ooboffs, oob, len);
                return oob + len;
 
-       case MTD_OPS_AUTO_OOB: {
-               struct nand_oobfree *free = chip->ecc.layout->oobfree;
-               uint32_t boffs = 0, woffs = ops->ooboffs;
-               size_t bytes = 0;
-
-               for (; free->length && len; free++, len -= bytes) {
-                       /* Write request not from offset 0? */
-                       if (unlikely(woffs)) {
-                               if (woffs >= free->length) {
-                                       woffs -= free->length;
-                                       continue;
-                               }
-                               boffs = free->offset + woffs;
-                               bytes = min_t(size_t, len,
-                                             (free->length - woffs));
-                               woffs = 0;
-                       } else {
-                               bytes = min_t(size_t, len, free->length);
-                               boffs = free->offset;
-                       }
-                       memcpy(chip->oob_poi + boffs, oob, bytes);
-                       oob += bytes;
-               }
-               return oob;
-       }
+       case MTD_OPS_AUTO_OOB:
+               ret = mtd_ooblayout_set_databytes(mtd, oob, chip->oob_poi,
+                                                 ops->ooboffs, len);
+               BUG_ON(ret);
+               return oob + len;
+
        default:
                BUG();
        }
@@ -3951,10 +3971,115 @@ ident_done:
        return type;
 }
 
+static const char * const nand_ecc_modes[] = {
+       [NAND_ECC_NONE]         = "none",
+       [NAND_ECC_SOFT]         = "soft",
+       [NAND_ECC_HW]           = "hw",
+       [NAND_ECC_HW_SYNDROME]  = "hw_syndrome",
+       [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
+};
+
+static int of_get_nand_ecc_mode(struct device_node *np)
+{
+       const char *pm;
+       int err, i;
+
+       err = of_property_read_string(np, "nand-ecc-mode", &pm);
+       if (err < 0)
+               return err;
+
+       for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
+               if (!strcasecmp(pm, nand_ecc_modes[i]))
+                       return i;
+
+       /*
+        * For backward compatibility we support few obsoleted values that don't
+        * have their mappings into nand_ecc_modes_t anymore (they were merged
+        * with other enums).
+        */
+       if (!strcasecmp(pm, "soft_bch"))
+               return NAND_ECC_SOFT;
+
+       return -ENODEV;
+}
+
+static const char * const nand_ecc_algos[] = {
+       [NAND_ECC_HAMMING]      = "hamming",
+       [NAND_ECC_BCH]          = "bch",
+};
+
+static int of_get_nand_ecc_algo(struct device_node *np)
+{
+       const char *pm;
+       int err, i;
+
+       err = of_property_read_string(np, "nand-ecc-algo", &pm);
+       if (!err) {
+               for (i = NAND_ECC_HAMMING; i < ARRAY_SIZE(nand_ecc_algos); i++)
+                       if (!strcasecmp(pm, nand_ecc_algos[i]))
+                               return i;
+               return -ENODEV;
+       }
+
+       /*
+        * For backward compatibility we also read "nand-ecc-mode" checking
+        * for some obsoleted values that were specifying ECC algorithm.
+        */
+       err = of_property_read_string(np, "nand-ecc-mode", &pm);
+       if (err < 0)
+               return err;
+
+       if (!strcasecmp(pm, "soft"))
+               return NAND_ECC_HAMMING;
+       else if (!strcasecmp(pm, "soft_bch"))
+               return NAND_ECC_BCH;
+
+       return -ENODEV;
+}
+
+static int of_get_nand_ecc_step_size(struct device_node *np)
+{
+       int ret;
+       u32 val;
+
+       ret = of_property_read_u32(np, "nand-ecc-step-size", &val);
+       return ret ? ret : val;
+}
+
+static int of_get_nand_ecc_strength(struct device_node *np)
+{
+       int ret;
+       u32 val;
+
+       ret = of_property_read_u32(np, "nand-ecc-strength", &val);
+       return ret ? ret : val;
+}
+
+static int of_get_nand_bus_width(struct device_node *np)
+{
+       u32 val;
+
+       if (of_property_read_u32(np, "nand-bus-width", &val))
+               return 8;
+
+       switch (val) {
+       case 8:
+       case 16:
+               return val;
+       default:
+               return -EIO;
+       }
+}
+
+static bool of_get_nand_on_flash_bbt(struct device_node *np)
+{
+       return of_property_read_bool(np, "nand-on-flash-bbt");
+}
+
 static int nand_dt_init(struct nand_chip *chip)
 {
        struct device_node *dn = nand_get_flash_node(chip);
-       int ecc_mode, ecc_strength, ecc_step;
+       int ecc_mode, ecc_algo, ecc_strength, ecc_step;
 
        if (!dn)
                return 0;
@@ -3966,6 +4091,7 @@ static int nand_dt_init(struct nand_chip *chip)
                chip->bbt_options |= NAND_BBT_USE_FLASH;
 
        ecc_mode = of_get_nand_ecc_mode(dn);
+       ecc_algo = of_get_nand_ecc_algo(dn);
        ecc_strength = of_get_nand_ecc_strength(dn);
        ecc_step = of_get_nand_ecc_step_size(dn);
 
@@ -3978,6 +4104,9 @@ static int nand_dt_init(struct nand_chip *chip)
        if (ecc_mode >= 0)
                chip->ecc.mode = ecc_mode;
 
+       if (ecc_algo >= 0)
+               chip->ecc.algo = ecc_algo;
+
        if (ecc_strength >= 0)
                chip->ecc.strength = ecc_strength;
 
@@ -4054,6 +4183,82 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
 }
 EXPORT_SYMBOL(nand_scan_ident);
 
+static int nand_set_ecc_soft_ops(struct mtd_info *mtd)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+       if (WARN_ON(ecc->mode != NAND_ECC_SOFT))
+               return -EINVAL;
+
+       switch (ecc->algo) {
+       case NAND_ECC_HAMMING:
+               ecc->calculate = nand_calculate_ecc;
+               ecc->correct = nand_correct_data;
+               ecc->read_page = nand_read_page_swecc;
+               ecc->read_subpage = nand_read_subpage;
+               ecc->write_page = nand_write_page_swecc;
+               ecc->read_page_raw = nand_read_page_raw;
+               ecc->write_page_raw = nand_write_page_raw;
+               ecc->read_oob = nand_read_oob_std;
+               ecc->write_oob = nand_write_oob_std;
+               if (!ecc->size)
+                       ecc->size = 256;
+               ecc->bytes = 3;
+               ecc->strength = 1;
+               return 0;
+       case NAND_ECC_BCH:
+               if (!mtd_nand_has_bch()) {
+                       WARN(1, "CONFIG_MTD_NAND_ECC_BCH not enabled\n");
+                       return -EINVAL;
+               }
+               ecc->calculate = nand_bch_calculate_ecc;
+               ecc->correct = nand_bch_correct_data;
+               ecc->read_page = nand_read_page_swecc;
+               ecc->read_subpage = nand_read_subpage;
+               ecc->write_page = nand_write_page_swecc;
+               ecc->read_page_raw = nand_read_page_raw;
+               ecc->write_page_raw = nand_write_page_raw;
+               ecc->read_oob = nand_read_oob_std;
+               ecc->write_oob = nand_write_oob_std;
+               /*
+               * Board driver should supply ecc.size and ecc.strength
+               * values to select how many bits are correctable.
+               * Otherwise, default to 4 bits for large page devices.
+               */
+               if (!ecc->size && (mtd->oobsize >= 64)) {
+                       ecc->size = 512;
+                       ecc->strength = 4;
+               }
+
+               /*
+                * if no ecc placement scheme was provided pickup the default
+                * large page one.
+                */
+               if (!mtd->ooblayout) {
+                       /* handle large page devices only */
+                       if (mtd->oobsize < 64) {
+                               WARN(1, "OOB layout is required when using software BCH on small pages\n");
+                               return -EINVAL;
+                       }
+
+                       mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
+               }
+
+               /* See nand_bch_init() for details. */
+               ecc->bytes = 0;
+               ecc->priv = nand_bch_init(mtd);
+               if (!ecc->priv) {
+                       WARN(1, "BCH ECC initialization failed!\n");
+                       return -EINVAL;
+               }
+               return 0;
+       default:
+               WARN(1, "Unsupported ECC algorithm!\n");
+               return -EINVAL;
+       }
+}
+
 /*
  * Check if the chip configuration meet the datasheet requirements.
 
@@ -4098,14 +4303,15 @@ static bool nand_ecc_strength_good(struct mtd_info *mtd)
  */
 int nand_scan_tail(struct mtd_info *mtd)
 {
-       int i;
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        struct nand_buffers *nbuf;
+       int ret;
 
        /* New bad blocks should be marked in OOB, flash-based BBT, or both */
-       BUG_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
-                       !(chip->bbt_options & NAND_BBT_USE_FLASH));
+       if (WARN_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) &&
+                  !(chip->bbt_options & NAND_BBT_USE_FLASH)))
+               return -EINVAL;
 
        if (!(chip->options & NAND_OWN_BUFFERS)) {
                nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
@@ -4128,24 +4334,22 @@ int nand_scan_tail(struct mtd_info *mtd)
        /*
         * If no default placement scheme is given, select an appropriate one.
         */
-       if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
+       if (!mtd->ooblayout &&
+           !(ecc->mode == NAND_ECC_SOFT && ecc->algo == NAND_ECC_BCH)) {
                switch (mtd->oobsize) {
                case 8:
-                       ecc->layout = &nand_oob_8;
-                       break;
                case 16:
-                       ecc->layout = &nand_oob_16;
+                       mtd_set_ooblayout(mtd, &nand_ooblayout_sp_ops);
                        break;
                case 64:
-                       ecc->layout = &nand_oob_64;
-                       break;
                case 128:
-                       ecc->layout = &nand_oob_128;
+                       mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
                        break;
                default:
-                       pr_warn("No oob scheme defined for oobsize %d\n",
-                                  mtd->oobsize);
-                       BUG();
+                       WARN(1, "No oob scheme defined for oobsize %d\n",
+                               mtd->oobsize);
+                       ret = -EINVAL;
+                       goto err_free;
                }
        }
 
@@ -4161,8 +4365,9 @@ int nand_scan_tail(struct mtd_info *mtd)
        case NAND_ECC_HW_OOB_FIRST:
                /* Similar to NAND_ECC_HW, but a separate read_page handle */
                if (!ecc->calculate || !ecc->correct || !ecc->hwctl) {
-                       pr_warn("No ECC functions supplied; hardware ECC not possible\n");
-                       BUG();
+                       WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
+                       ret = -EINVAL;
+                       goto err_free;
                }
                if (!ecc->read_page)
                        ecc->read_page = nand_read_page_hwecc_oob_first;
@@ -4192,8 +4397,9 @@ int nand_scan_tail(struct mtd_info *mtd)
                     ecc->read_page == nand_read_page_hwecc ||
                     !ecc->write_page ||
                     ecc->write_page == nand_write_page_hwecc)) {
-                       pr_warn("No ECC functions supplied; hardware ECC not possible\n");
-                       BUG();
+                       WARN(1, "No ECC functions supplied; hardware ECC not possible\n");
+                       ret = -EINVAL;
+                       goto err_free;
                }
                /* Use standard syndrome read/write page function? */
                if (!ecc->read_page)
@@ -4211,61 +4417,22 @@ int nand_scan_tail(struct mtd_info *mtd)
 
                if (mtd->writesize >= ecc->size) {
                        if (!ecc->strength) {
-                               pr_warn("Driver must set ecc.strength when using hardware ECC\n");
-                               BUG();
+                               WARN(1, "Driver must set ecc.strength when using hardware ECC\n");
+                               ret = -EINVAL;
+                               goto err_free;
                        }
                        break;
                }
                pr_warn("%d byte HW ECC not possible on %d byte page size, fallback to SW ECC\n",
                        ecc->size, mtd->writesize);
                ecc->mode = NAND_ECC_SOFT;
+               ecc->algo = NAND_ECC_HAMMING;
 
        case NAND_ECC_SOFT:
-               ecc->calculate = nand_calculate_ecc;
-               ecc->correct = nand_correct_data;
-               ecc->read_page = nand_read_page_swecc;
-               ecc->read_subpage = nand_read_subpage;
-               ecc->write_page = nand_write_page_swecc;
-               ecc->read_page_raw = nand_read_page_raw;
-               ecc->write_page_raw = nand_write_page_raw;
-               ecc->read_oob = nand_read_oob_std;
-               ecc->write_oob = nand_write_oob_std;
-               if (!ecc->size)
-                       ecc->size = 256;
-               ecc->bytes = 3;
-               ecc->strength = 1;
-               break;
-
-       case NAND_ECC_SOFT_BCH:
-               if (!mtd_nand_has_bch()) {
-                       pr_warn("CONFIG_MTD_NAND_ECC_BCH not enabled\n");
-                       BUG();
-               }
-               ecc->calculate = nand_bch_calculate_ecc;
-               ecc->correct = nand_bch_correct_data;
-               ecc->read_page = nand_read_page_swecc;
-               ecc->read_subpage = nand_read_subpage;
-               ecc->write_page = nand_write_page_swecc;
-               ecc->read_page_raw = nand_read_page_raw;
-               ecc->write_page_raw = nand_write_page_raw;
-               ecc->read_oob = nand_read_oob_std;
-               ecc->write_oob = nand_write_oob_std;
-               /*
-                * Board driver should supply ecc.size and ecc.strength values
-                * to select how many bits are correctable. Otherwise, default
-                * to 4 bits for large page devices.
-                */
-               if (!ecc->size && (mtd->oobsize >= 64)) {
-                       ecc->size = 512;
-                       ecc->strength = 4;
-               }
-
-               /* See nand_bch_init() for details. */
-               ecc->bytes = 0;
-               ecc->priv = nand_bch_init(mtd);
-               if (!ecc->priv) {
-                       pr_warn("BCH ECC initialization failed!\n");
-                       BUG();
+               ret = nand_set_ecc_soft_ops(mtd);
+               if (ret) {
+                       ret = -EINVAL;
+                       goto err_free;
                }
                break;
 
@@ -4283,8 +4450,9 @@ int nand_scan_tail(struct mtd_info *mtd)
                break;
 
        default:
-               pr_warn("Invalid NAND_ECC_MODE %d\n", ecc->mode);
-               BUG();
+               WARN(1, "Invalid NAND_ECC_MODE %d\n", ecc->mode);
+               ret = -EINVAL;
+               goto err_free;
        }
 
        /* For many systems, the standard OOB write also works for raw */
@@ -4293,20 +4461,9 @@ int nand_scan_tail(struct mtd_info *mtd)
        if (!ecc->write_oob_raw)
                ecc->write_oob_raw = ecc->write_oob;
 
-       /*
-        * The number of bytes available for a client to place data into
-        * the out of band area.
-        */
-       mtd->oobavail = 0;
-       if (ecc->layout) {
-               for (i = 0; ecc->layout->oobfree[i].length; i++)
-                       mtd->oobavail += ecc->layout->oobfree[i].length;
-       }
-
-       /* ECC sanity check: warn if it's too weak */
-       if (!nand_ecc_strength_good(mtd))
-               pr_warn("WARNING: %s: the ECC used on your system is too weak compared to the one required by the NAND chip\n",
-                       mtd->name);
+       /* propagate ecc info to mtd_info */
+       mtd->ecc_strength = ecc->strength;
+       mtd->ecc_step_size = ecc->size;
 
        /*
         * Set the number of read / write steps for one page depending on ECC
@@ -4314,11 +4471,27 @@ int nand_scan_tail(struct mtd_info *mtd)
         */
        ecc->steps = mtd->writesize / ecc->size;
        if (ecc->steps * ecc->size != mtd->writesize) {
-               pr_warn("Invalid ECC parameters\n");
-               BUG();
+               WARN(1, "Invalid ECC parameters\n");
+               ret = -EINVAL;
+               goto err_free;
        }
        ecc->total = ecc->steps * ecc->bytes;
 
+       /*
+        * The number of bytes available for a client to place data into
+        * the out of band area.
+        */
+       ret = mtd_ooblayout_count_freebytes(mtd);
+       if (ret < 0)
+               ret = 0;
+
+       mtd->oobavail = ret;
+
+       /* ECC sanity check: warn if it's too weak */
+       if (!nand_ecc_strength_good(mtd))
+               pr_warn("WARNING: %s: the ECC used on your system is too weak compared to the one required by the NAND chip\n",
+                       mtd->name);
+
        /* Allow subpage writes up to ecc.steps. Not possible for MLC flash */
        if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) {
                switch (ecc->steps) {
@@ -4343,7 +4516,6 @@ int nand_scan_tail(struct mtd_info *mtd)
        /* Large page NAND with SOFT_ECC should support subpage reads */
        switch (ecc->mode) {
        case NAND_ECC_SOFT:
-       case NAND_ECC_SOFT_BCH:
                if (chip->page_shift > 9)
                        chip->options |= NAND_SUBPAGE_READ;
                break;
@@ -4375,10 +4547,6 @@ int nand_scan_tail(struct mtd_info *mtd)
        mtd->_block_markbad = nand_block_markbad;
        mtd->writebufsize = mtd->writesize;
 
-       /* propagate ecc info to mtd_info */
-       mtd->ecclayout = ecc->layout;
-       mtd->ecc_strength = ecc->strength;
-       mtd->ecc_step_size = ecc->size;
        /*
         * Initialize bitflip_threshold to its default prior scan_bbt() call.
         * scan_bbt() might invoke mtd_read(), thus bitflip_threshold must be
@@ -4393,6 +4561,10 @@ int nand_scan_tail(struct mtd_info *mtd)
 
        /* Build bad block table */
        return chip->scan_bbt(mtd);
+err_free:
+       if (!(chip->options & NAND_OWN_BUFFERS))
+               kfree(chip->buffers);
+       return ret;
 }
 EXPORT_SYMBOL(nand_scan_tail);
 
@@ -4436,7 +4608,8 @@ void nand_release(struct mtd_info *mtd)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
 
-       if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
+       if (chip->ecc.mode == NAND_ECC_SOFT &&
+           chip->ecc.algo == NAND_ECC_BCH)
                nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
 
        mtd_device_unregister(mtd);
index b585bae379290f9993b127087d52fc9dc753eda8..44763f87eae494eccd65241d5b6774aba4527cf4 100644 (file)
 /**
  * struct nand_bch_control - private NAND BCH control structure
  * @bch:       BCH control structure
- * @ecclayout: private ecc layout for this BCH configuration
  * @errloc:    error location array
  * @eccmask:   XOR ecc mask, allows erased pages to be decoded as valid
  */
 struct nand_bch_control {
        struct bch_control   *bch;
-       struct nand_ecclayout ecclayout;
        unsigned int         *errloc;
        unsigned char        *eccmask;
 };
@@ -124,7 +122,6 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 {
        struct nand_chip *nand = mtd_to_nand(mtd);
        unsigned int m, t, eccsteps, i;
-       struct nand_ecclayout *layout = nand->ecc.layout;
        struct nand_bch_control *nbc = NULL;
        unsigned char *erased_page;
        unsigned int eccsize = nand->ecc.size;
@@ -161,34 +158,10 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
 
        eccsteps = mtd->writesize/eccsize;
 
-       /* if no ecc placement scheme was provided, build one */
-       if (!layout) {
-
-               /* handle large page devices only */
-               if (mtd->oobsize < 64) {
-                       printk(KERN_WARNING "must provide an oob scheme for "
-                              "oobsize %d\n", mtd->oobsize);
-                       goto fail;
-               }
-
-               layout = &nbc->ecclayout;
-               layout->eccbytes = eccsteps*eccbytes;
-
-               /* reserve 2 bytes for bad block marker */
-               if (layout->eccbytes+2 > mtd->oobsize) {
-                       printk(KERN_WARNING "no suitable oob scheme available "
-                              "for oobsize %d eccbytes %u\n", mtd->oobsize,
-                              eccbytes);
-                       goto fail;
-               }
-               /* put ecc bytes at oob tail */
-               for (i = 0; i < layout->eccbytes; i++)
-                       layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
-
-               layout->oobfree[0].offset = 2;
-               layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
-
-               nand->ecc.layout = layout;
+       /* Check that we have an oob layout description. */
+       if (!mtd->ooblayout) {
+               pr_warn("missing oob scheme");
+               goto fail;
        }
 
        /* sanity checks */
@@ -196,7 +169,18 @@ struct nand_bch_control *nand_bch_init(struct mtd_info *mtd)
                printk(KERN_WARNING "eccsize %u is too large\n", eccsize);
                goto fail;
        }
-       if (layout->eccbytes != (eccsteps*eccbytes)) {
+
+       /*
+        * ecc->steps and ecc->total might be used by mtd->ooblayout->ecc(),
+        * which is called by mtd_ooblayout_count_eccbytes().
+        * Make sure they are properly initialized before calling
+        * mtd_ooblayout_count_eccbytes().
+        * FIXME: we should probably rework the sequencing in nand_scan_tail()
+        * to avoid setting those fields twice.
+        */
+       nand->ecc.steps = eccsteps;
+       nand->ecc.total = eccsteps * eccbytes;
+       if (mtd_ooblayout_count_eccbytes(mtd) != (eccsteps*eccbytes)) {
                printk(KERN_WARNING "invalid ecc layout\n");
                goto fail;
        }
index a58169a28741e7e0f3db85b77170594de299fd87..1eb934414eb5804978994a382dbb1d782ca59e53 100644 (file)
@@ -569,7 +569,7 @@ static void nandsim_debugfs_remove(struct nandsim *ns)
  *
  * RETURNS: 0 if success, -ENOMEM if memory alloc fails.
  */
-static int alloc_device(struct nandsim *ns)
+static int __init alloc_device(struct nandsim *ns)
 {
        struct file *cfile;
        int i, err;
@@ -654,7 +654,7 @@ static void free_device(struct nandsim *ns)
        }
 }
 
-static char *get_partition_name(int i)
+static char __init *get_partition_name(int i)
 {
        return kasprintf(GFP_KERNEL, "NAND simulator partition %d", i);
 }
@@ -664,7 +664,7 @@ static char *get_partition_name(int i)
  *
  * RETURNS: 0 if success, -ERRNO if failure.
  */
-static int init_nandsim(struct mtd_info *mtd)
+static int __init init_nandsim(struct mtd_info *mtd)
 {
        struct nand_chip *chip = mtd_to_nand(mtd);
        struct nandsim   *ns   = nand_get_controller_data(chip);
@@ -2261,6 +2261,7 @@ static int __init ns_init_module(void)
        chip->read_buf   = ns_nand_read_buf;
        chip->read_word  = ns_nand_read_word;
        chip->ecc.mode   = NAND_ECC_SOFT;
+       chip->ecc.algo   = NAND_ECC_HAMMING;
        /* The NAND_SKIP_BBTSCAN option is necessary for 'overridesize' */
        /* and 'badblocks' parameters to work */
        chip->options   |= NAND_SKIP_BBTSCAN;
@@ -2338,7 +2339,8 @@ static int __init ns_init_module(void)
                        retval = -EINVAL;
                        goto error;
                }
-               chip->ecc.mode = NAND_ECC_SOFT_BCH;
+               chip->ecc.mode = NAND_ECC_SOFT;
+               chip->ecc.algo = NAND_ECC_BCH;
                chip->ecc.size = 512;
                chip->ecc.strength = bch;
                chip->ecc.bytes = eccbytes;
index dbc5b571c2bbcca6a570e5855d2907009abd9b0f..8f64011d32ef2a2791a0380b003c10ab3dc63f0b 100644 (file)
@@ -261,6 +261,7 @@ static int nuc900_nand_probe(struct platform_device *pdev)
        chip->chip_delay        = 50;
        chip->options           = 0;
        chip->ecc.mode          = NAND_ECC_SOFT;
+       chip->ecc.algo          = NAND_ECC_HAMMING;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        nuc900_nand->reg = devm_ioremap_resource(&pdev->dev, res);
index 0749ca1a145681552bf2e42b2be96c7d4e09eb4f..08e158895635cddda0bbea4e6973cfb8dd727e74 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
 #include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/jiffies.h>
@@ -28,6 +29,7 @@
 #include <linux/mtd/nand_bch.h>
 #include <linux/platform_data/elm.h>
 
+#include <linux/omap-gpmc.h>
 #include <linux/platform_data/mtd-nand-omap2.h>
 
 #define        DRIVER_NAME     "omap2-nand"
@@ -151,13 +153,17 @@ static struct nand_hw_control omap_gpmc_controller = {
 };
 
 struct omap_nand_info {
-       struct omap_nand_platform_data  *pdata;
        struct nand_chip                nand;
        struct platform_device          *pdev;
 
        int                             gpmc_cs;
-       unsigned long                   phys_base;
+       bool                            dev_ready;
+       enum nand_io                    xfer_type;
+       int                             devsize;
        enum omap_ecc                   ecc_opt;
+       struct device_node              *elm_of_node;
+
+       unsigned long                   phys_base;
        struct completion               comp;
        struct dma_chan                 *dma;
        int                             gpmc_irq_fifo;
@@ -168,12 +174,14 @@ struct omap_nand_info {
        } iomode;
        u_char                          *buf;
        int                                     buf_len;
+       /* Interface to GPMC */
        struct gpmc_nand_regs           reg;
-       /* generated at runtime depending on ECC algorithm and layout selected */
-       struct nand_ecclayout           oobinfo;
+       struct gpmc_nand_ops            *ops;
+       bool                            flash_bbt;
        /* fields specific for BCHx_HW ECC scheme */
        struct device                   *elm_dev;
-       struct device_node              *of_node;
+       /* NAND ready gpio */
+       struct gpio_desc                *ready_gpiod;
 };
 
 static inline struct omap_nand_info *mtd_to_omap(struct mtd_info *mtd)
@@ -208,7 +216,7 @@ static int omap_prefetch_enable(int cs, int fifo_th, int dma_mode,
         */
        val = ((cs << PREFETCH_CONFIG1_CS_SHIFT) |
                PREFETCH_FIFOTHRESHOLD(fifo_th) | ENABLE_PREFETCH |
-               (dma_mode << DMA_MPU_MODE_SHIFT) | (0x1 & is_write));
+               (dma_mode << DMA_MPU_MODE_SHIFT) | (is_write & 0x1));
        writel(val, info->reg.gpmc_prefetch_config1);
 
        /*  Start the prefetch engine */
@@ -288,14 +296,13 @@ static void omap_write_buf8(struct mtd_info *mtd, const u_char *buf, int len)
 {
        struct omap_nand_info *info = mtd_to_omap(mtd);
        u_char *p = (u_char *)buf;
-       u32     status = 0;
+       bool status;
 
        while (len--) {
                iowrite8(*p++, info->nand.IO_ADDR_W);
                /* wait until buffer is available for write */
                do {
-                       status = readl(info->reg.gpmc_status) &
-                                       STATUS_BUFF_EMPTY;
+                       status = info->ops->nand_writebuffer_empty();
                } while (!status);
        }
 }
@@ -323,7 +330,7 @@ static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
 {
        struct omap_nand_info *info = mtd_to_omap(mtd);
        u16 *p = (u16 *) buf;
-       u32     status = 0;
+       bool status;
        /* FIXME try bursts of writesw() or DMA ... */
        len >>= 1;
 
@@ -331,8 +338,7 @@ static void omap_write_buf16(struct mtd_info *mtd, const u_char * buf, int len)
                iowrite16(*p++, info->nand.IO_ADDR_W);
                /* wait until buffer is available for write */
                do {
-                       status = readl(info->reg.gpmc_status) &
-                                       STATUS_BUFF_EMPTY;
+                       status = info->ops->nand_writebuffer_empty();
                } while (!status);
        }
 }
@@ -467,17 +473,8 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
        int ret;
        u32 val;
 
-       if (addr >= high_memory) {
-               struct page *p1;
-
-               if (((size_t)addr & PAGE_MASK) !=
-                       ((size_t)(addr + len - 1) & PAGE_MASK))
-                       goto out_copy;
-               p1 = vmalloc_to_page(addr);
-               if (!p1)
-                       goto out_copy;
-               addr = page_address(p1) + ((size_t)addr & ~PAGE_MASK);
-       }
+       if (!virt_addr_valid(addr))
+               goto out_copy;
 
        sg_init_one(&sg, addr, len);
        n = dma_map_sg(info->dma->device->dev, &sg, 1, dir);
@@ -497,6 +494,11 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
        tx->callback_param = &info->comp;
        dmaengine_submit(tx);
 
+       init_completion(&info->comp);
+
+       /* setup and start DMA using dma_addr */
+       dma_async_issue_pending(info->dma);
+
        /*  configure and start prefetch transfer */
        ret = omap_prefetch_enable(info->gpmc_cs,
                PREFETCH_FIFOTHRESHOLD_MAX, 0x1, len, is_write, info);
@@ -504,10 +506,6 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
                /* PFPW engine is busy, use cpu copy method */
                goto out_copy_unmap;
 
-       init_completion(&info->comp);
-       dma_async_issue_pending(info->dma);
-
-       /* setup and start DMA using dma_addr */
        wait_for_completion(&info->comp);
        tim = 0;
        limit = (loops_per_jiffy * msecs_to_jiffies(OMAP_NAND_TIMEOUT_MS));
@@ -1017,21 +1015,16 @@ static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
 }
 
 /**
- * omap_dev_ready - calls the platform specific dev_ready function
+ * omap_dev_ready - checks the NAND Ready GPIO line
  * @mtd: MTD device structure
+ *
+ * Returns true if ready and false if busy.
  */
 static int omap_dev_ready(struct mtd_info *mtd)
 {
-       unsigned int val = 0;
        struct omap_nand_info *info = mtd_to_omap(mtd);
 
-       val = readl(info->reg.gpmc_status);
-
-       if ((val & 0x100) == 0x100) {
-               return 1;
-       } else {
-               return 0;
-       }
+       return gpiod_get_value(info->ready_gpiod);
 }
 
 /**
@@ -1495,9 +1488,8 @@ static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data,
 static int omap_write_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
                               const uint8_t *buf, int oob_required, int page)
 {
-       int i;
+       int ret;
        uint8_t *ecc_calc = chip->buffers->ecccalc;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
 
        /* Enable GPMC ecc engine */
        chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
@@ -1508,8 +1500,10 @@ static int omap_write_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
        /* Update ecc vector from GPMC result registers */
        chip->ecc.calculate(mtd, buf, &ecc_calc[0]);
 
-       for (i = 0; i < chip->ecc.total; i++)
-               chip->oob_poi[eccpos[i]] = ecc_calc[i];
+       ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        /* Write ecc vector to OOB area */
        chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
@@ -1536,10 +1530,7 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 {
        uint8_t *ecc_calc = chip->buffers->ecccalc;
        uint8_t *ecc_code = chip->buffers->ecccode;
-       uint32_t *eccpos = chip->ecc.layout->eccpos;
-       uint8_t *oob = &chip->oob_poi[eccpos[0]];
-       uint32_t oob_pos = mtd->writesize + chip->ecc.layout->eccpos[0];
-       int stat;
+       int stat, ret;
        unsigned int max_bitflips = 0;
 
        /* Enable GPMC ecc engine */
@@ -1549,13 +1540,18 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
        chip->read_buf(mtd, buf, mtd->writesize);
 
        /* Read oob bytes */
-       chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
-       chip->read_buf(mtd, oob, chip->ecc.total);
+       chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
+                     mtd->writesize + BADBLOCK_MARKER_LENGTH, -1);
+       chip->read_buf(mtd, chip->oob_poi + BADBLOCK_MARKER_LENGTH,
+                      chip->ecc.total);
 
        /* Calculate ecc bytes */
        chip->ecc.calculate(mtd, buf, ecc_calc);
 
-       memcpy(ecc_code, &chip->oob_poi[eccpos[0]], chip->ecc.total);
+       ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
+                                        chip->ecc.total);
+       if (ret)
+               return ret;
 
        stat = chip->ecc.correct(mtd, buf, ecc_code, ecc_calc);
 
@@ -1630,7 +1626,7 @@ static bool omap2_nand_ecc_check(struct omap_nand_info *info,
                        "CONFIG_MTD_NAND_OMAP_BCH not enabled\n");
                return false;
        }
-       if (ecc_needs_elm && !is_elm_present(info, pdata->elm_of_node)) {
+       if (ecc_needs_elm && !is_elm_present(info, info->elm_of_node)) {
                dev_err(&info->pdev->dev, "ELM not available\n");
                return false;
        }
@@ -1638,43 +1634,227 @@ static bool omap2_nand_ecc_check(struct omap_nand_info *info,
        return true;
 }
 
+static const char * const nand_xfer_types[] = {
+       [NAND_OMAP_PREFETCH_POLLED] = "prefetch-polled",
+       [NAND_OMAP_POLLED] = "polled",
+       [NAND_OMAP_PREFETCH_DMA] = "prefetch-dma",
+       [NAND_OMAP_PREFETCH_IRQ] = "prefetch-irq",
+};
+
+static int omap_get_dt_info(struct device *dev, struct omap_nand_info *info)
+{
+       struct device_node *child = dev->of_node;
+       int i;
+       const char *s;
+       u32 cs;
+
+       if (of_property_read_u32(child, "reg", &cs) < 0) {
+               dev_err(dev, "reg not found in DT\n");
+               return -EINVAL;
+       }
+
+       info->gpmc_cs = cs;
+
+       /* detect availability of ELM module. Won't be present pre-OMAP4 */
+       info->elm_of_node = of_parse_phandle(child, "ti,elm-id", 0);
+       if (!info->elm_of_node)
+               dev_dbg(dev, "ti,elm-id not in DT\n");
+
+       /* select ecc-scheme for NAND */
+       if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) {
+               dev_err(dev, "ti,nand-ecc-opt not found\n");
+               return -EINVAL;
+       }
+
+       if (!strcmp(s, "sw")) {
+               info->ecc_opt = OMAP_ECC_HAM1_CODE_SW;
+       } else if (!strcmp(s, "ham1") ||
+                  !strcmp(s, "hw") || !strcmp(s, "hw-romcode")) {
+               info->ecc_opt = OMAP_ECC_HAM1_CODE_HW;
+       } else if (!strcmp(s, "bch4")) {
+               if (info->elm_of_node)
+                       info->ecc_opt = OMAP_ECC_BCH4_CODE_HW;
+               else
+                       info->ecc_opt = OMAP_ECC_BCH4_CODE_HW_DETECTION_SW;
+       } else if (!strcmp(s, "bch8")) {
+               if (info->elm_of_node)
+                       info->ecc_opt = OMAP_ECC_BCH8_CODE_HW;
+               else
+                       info->ecc_opt = OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
+       } else if (!strcmp(s, "bch16")) {
+               info->ecc_opt = OMAP_ECC_BCH16_CODE_HW;
+       } else {
+               dev_err(dev, "unrecognized value for ti,nand-ecc-opt\n");
+               return -EINVAL;
+       }
+
+       /* select data transfer mode */
+       if (!of_property_read_string(child, "ti,nand-xfer-type", &s)) {
+               for (i = 0; i < ARRAY_SIZE(nand_xfer_types); i++) {
+                       if (!strcasecmp(s, nand_xfer_types[i])) {
+                               info->xfer_type = i;
+                               return 0;
+                       }
+               }
+
+               dev_err(dev, "unrecognized value for ti,nand-xfer-type\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int omap_ooblayout_ecc(struct mtd_info *mtd, int section,
+                             struct mtd_oob_region *oobregion)
+{
+       struct omap_nand_info *info = mtd_to_omap(mtd);
+       struct nand_chip *chip = &info->nand;
+       int off = BADBLOCK_MARKER_LENGTH;
+
+       if (info->ecc_opt == OMAP_ECC_HAM1_CODE_HW &&
+           !(chip->options & NAND_BUSWIDTH_16))
+               off = 1;
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = off;
+       oobregion->length = chip->ecc.total;
+
+       return 0;
+}
+
+static int omap_ooblayout_free(struct mtd_info *mtd, int section,
+                              struct mtd_oob_region *oobregion)
+{
+       struct omap_nand_info *info = mtd_to_omap(mtd);
+       struct nand_chip *chip = &info->nand;
+       int off = BADBLOCK_MARKER_LENGTH;
+
+       if (info->ecc_opt == OMAP_ECC_HAM1_CODE_HW &&
+           !(chip->options & NAND_BUSWIDTH_16))
+               off = 1;
+
+       if (section)
+               return -ERANGE;
+
+       off += chip->ecc.total;
+       if (off >= mtd->oobsize)
+               return -ERANGE;
+
+       oobregion->offset = off;
+       oobregion->length = mtd->oobsize - off;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops omap_ooblayout_ops = {
+       .ecc = omap_ooblayout_ecc,
+       .free = omap_ooblayout_free,
+};
+
+static int omap_sw_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       int off = BADBLOCK_MARKER_LENGTH;
+
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
+
+       /*
+        * When SW correction is employed, one OMAP specific marker byte is
+        * reserved after each ECC step.
+        */
+       oobregion->offset = off + (section * (chip->ecc.bytes + 1));
+       oobregion->length = chip->ecc.bytes;
+
+       return 0;
+}
+
+static int omap_sw_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       int off = BADBLOCK_MARKER_LENGTH;
+
+       if (section)
+               return -ERANGE;
+
+       /*
+        * When SW correction is employed, one OMAP specific marker byte is
+        * reserved after each ECC step.
+        */
+       off += ((chip->ecc.bytes + 1) * chip->ecc.steps);
+       if (off >= mtd->oobsize)
+               return -ERANGE;
+
+       oobregion->offset = off;
+       oobregion->length = mtd->oobsize - off;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops omap_sw_ooblayout_ops = {
+       .ecc = omap_sw_ooblayout_ecc,
+       .free = omap_sw_ooblayout_free,
+};
+
 static int omap_nand_probe(struct platform_device *pdev)
 {
        struct omap_nand_info           *info;
-       struct omap_nand_platform_data  *pdata;
+       struct omap_nand_platform_data  *pdata = NULL;
        struct mtd_info                 *mtd;
        struct nand_chip                *nand_chip;
-       struct nand_ecclayout           *ecclayout;
        int                             err;
-       int                             i;
        dma_cap_mask_t                  mask;
        unsigned                        sig;
-       unsigned                        oob_index;
        struct resource                 *res;
-
-       pdata = dev_get_platdata(&pdev->dev);
-       if (pdata == NULL) {
-               dev_err(&pdev->dev, "platform data missing\n");
-               return -ENODEV;
-       }
+       struct device                   *dev = &pdev->dev;
+       int                             min_oobbytes = BADBLOCK_MARKER_LENGTH;
+       int                             oobbytes_per_step;
 
        info = devm_kzalloc(&pdev->dev, sizeof(struct omap_nand_info),
                                GFP_KERNEL);
        if (!info)
                return -ENOMEM;
 
+       info->pdev = pdev;
+
+       if (dev->of_node) {
+               if (omap_get_dt_info(dev, info))
+                       return -EINVAL;
+       } else {
+               pdata = dev_get_platdata(&pdev->dev);
+               if (!pdata) {
+                       dev_err(&pdev->dev, "platform data missing\n");
+                       return -EINVAL;
+               }
+
+               info->gpmc_cs = pdata->cs;
+               info->reg = pdata->reg;
+               info->ecc_opt = pdata->ecc_opt;
+               if (pdata->dev_ready)
+                       dev_info(&pdev->dev, "pdata->dev_ready is deprecated\n");
+
+               info->xfer_type = pdata->xfer_type;
+               info->devsize = pdata->devsize;
+               info->elm_of_node = pdata->elm_of_node;
+               info->flash_bbt = pdata->flash_bbt;
+       }
+
        platform_set_drvdata(pdev, info);
+       info->ops = gpmc_omap_get_nand_ops(&info->reg, info->gpmc_cs);
+       if (!info->ops) {
+               dev_err(&pdev->dev, "Failed to get GPMC->NAND interface\n");
+               return -ENODEV;
+       }
 
-       info->pdev              = pdev;
-       info->gpmc_cs           = pdata->cs;
-       info->reg               = pdata->reg;
-       info->of_node           = pdata->of_node;
-       info->ecc_opt           = pdata->ecc_opt;
        nand_chip               = &info->nand;
        mtd                     = nand_to_mtd(nand_chip);
        mtd->dev.parent         = &pdev->dev;
        nand_chip->ecc.priv     = NULL;
-       nand_set_flash_node(nand_chip, pdata->of_node);
+       nand_set_flash_node(nand_chip, dev->of_node);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
@@ -1688,6 +1868,13 @@ static int omap_nand_probe(struct platform_device *pdev)
        nand_chip->IO_ADDR_W = nand_chip->IO_ADDR_R;
        nand_chip->cmd_ctrl  = omap_hwcontrol;
 
+       info->ready_gpiod = devm_gpiod_get_optional(&pdev->dev, "rb",
+                                                   GPIOD_IN);
+       if (IS_ERR(info->ready_gpiod)) {
+               dev_err(dev, "failed to get ready gpio\n");
+               return PTR_ERR(info->ready_gpiod);
+       }
+
        /*
         * If RDY/BSY line is connected to OMAP then use the omap ready
         * function and the generic nand_wait function which reads the status
@@ -1695,7 +1882,7 @@ static int omap_nand_probe(struct platform_device *pdev)
         * chip delay which is slightly more than tR (AC Timing) of the NAND
         * device and read status register until you get a failure or success
         */
-       if (pdata->dev_ready) {
+       if (info->ready_gpiod) {
                nand_chip->dev_ready = omap_dev_ready;
                nand_chip->chip_delay = 0;
        } else {
@@ -1703,21 +1890,25 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->chip_delay = 50;
        }
 
-       if (pdata->flash_bbt)
-               nand_chip->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
-       else
-               nand_chip->options |= NAND_SKIP_BBTSCAN;
+       if (info->flash_bbt)
+               nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
 
        /* scan NAND device connected to chip controller */
-       nand_chip->options |= pdata->devsize & NAND_BUSWIDTH_16;
+       nand_chip->options |= info->devsize & NAND_BUSWIDTH_16;
        if (nand_scan_ident(mtd, 1, NULL)) {
-               dev_err(&info->pdev->dev, "scan failed, may be bus-width mismatch\n");
+               dev_err(&info->pdev->dev,
+                       "scan failed, may be bus-width mismatch\n");
                err = -ENXIO;
                goto return_error;
        }
 
+       if (nand_chip->bbt_options & NAND_BBT_USE_FLASH)
+               nand_chip->bbt_options |= NAND_BBT_NO_OOB;
+       else
+               nand_chip->options |= NAND_SKIP_BBTSCAN;
+
        /* re-populate low-level callbacks based on xfer modes */
-       switch (pdata->xfer_type) {
+       switch (info->xfer_type) {
        case NAND_OMAP_PREFETCH_POLLED:
                nand_chip->read_buf   = omap_read_buf_pref;
                nand_chip->write_buf  = omap_write_buf_pref;
@@ -1797,7 +1988,7 @@ static int omap_nand_probe(struct platform_device *pdev)
 
        default:
                dev_err(&pdev->dev,
-                       "xfer_type(%d) not supported!\n", pdata->xfer_type);
+                       "xfer_type(%d) not supported!\n", info->xfer_type);
                err = -EINVAL;
                goto return_error;
        }
@@ -1809,16 +2000,15 @@ static int omap_nand_probe(struct platform_device *pdev)
 
        /*
         * Bail out earlier to let NAND_ECC_SOFT code create its own
-        * ecclayout instead of using ours.
+        * ooblayout instead of using ours.
         */
        if (info->ecc_opt == OMAP_ECC_HAM1_CODE_SW) {
                nand_chip->ecc.mode = NAND_ECC_SOFT;
+               nand_chip->ecc.algo = NAND_ECC_HAMMING;
                goto scan_tail;
        }
 
        /* populate MTD interface based on ECC scheme */
-       ecclayout               = &info->oobinfo;
-       nand_chip->ecc.layout   = ecclayout;
        switch (info->ecc_opt) {
        case OMAP_ECC_HAM1_CODE_HW:
                pr_info("nand: using OMAP_ECC_HAM1_CODE_HW\n");
@@ -1829,19 +2019,12 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.calculate        = omap_calculate_ecc;
                nand_chip->ecc.hwctl            = omap_enable_hwecc;
                nand_chip->ecc.correct          = omap_correct_data;
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               if (nand_chip->options & NAND_BUSWIDTH_16)
-                       oob_index               = BADBLOCK_MARKER_LENGTH;
-               else
-                       oob_index               = 1;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
-                       ecclayout->eccpos[i]    = oob_index;
-               /* no reserved-marker in ecclayout for this ecc-scheme */
-               ecclayout->oobfree->offset      =
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+               mtd_set_ooblayout(mtd, &omap_ooblayout_ops);
+               oobbytes_per_step               = nand_chip->ecc.bytes;
+
+               if (!(nand_chip->options & NAND_BUSWIDTH_16))
+                       min_oobbytes            = 1;
+
                break;
 
        case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
@@ -1853,19 +2036,9 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.hwctl            = omap_enable_hwecc_bch;
                nand_chip->ecc.correct          = nand_bch_correct_data;
                nand_chip->ecc.calculate        = omap_calculate_ecc_bch;
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               oob_index                       = BADBLOCK_MARKER_LENGTH;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
-                       ecclayout->eccpos[i] = oob_index;
-                       if (((i + 1) % nand_chip->ecc.bytes) == 0)
-                               oob_index++;
-               }
-               /* include reserved-marker in ecclayout->oobfree calculation */
-               ecclayout->oobfree->offset      = 1 +
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+               mtd_set_ooblayout(mtd, &omap_sw_ooblayout_ops);
+               /* Reserve one byte for the OMAP marker */
+               oobbytes_per_step               = nand_chip->ecc.bytes + 1;
                /* software bch library is used for locating errors */
                nand_chip->ecc.priv             = nand_bch_init(mtd);
                if (!nand_chip->ecc.priv) {
@@ -1887,16 +2060,8 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.calculate        = omap_calculate_ecc_bch;
                nand_chip->ecc.read_page        = omap_read_page_bch;
                nand_chip->ecc.write_page       = omap_write_page_bch;
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               oob_index                       = BADBLOCK_MARKER_LENGTH;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
-                       ecclayout->eccpos[i]    = oob_index;
-               /* reserved marker already included in ecclayout->eccbytes */
-               ecclayout->oobfree->offset      =
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+               mtd_set_ooblayout(mtd, &omap_ooblayout_ops);
+               oobbytes_per_step               = nand_chip->ecc.bytes;
 
                err = elm_config(info->elm_dev, BCH4_ECC,
                                 mtd->writesize / nand_chip->ecc.size,
@@ -1914,19 +2079,9 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.hwctl            = omap_enable_hwecc_bch;
                nand_chip->ecc.correct          = nand_bch_correct_data;
                nand_chip->ecc.calculate        = omap_calculate_ecc_bch;
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               oob_index                       = BADBLOCK_MARKER_LENGTH;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++) {
-                       ecclayout->eccpos[i] = oob_index;
-                       if (((i + 1) % nand_chip->ecc.bytes) == 0)
-                               oob_index++;
-               }
-               /* include reserved-marker in ecclayout->oobfree calculation */
-               ecclayout->oobfree->offset      = 1 +
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+               mtd_set_ooblayout(mtd, &omap_sw_ooblayout_ops);
+               /* Reserve one byte for the OMAP marker */
+               oobbytes_per_step               = nand_chip->ecc.bytes + 1;
                /* software bch library is used for locating errors */
                nand_chip->ecc.priv             = nand_bch_init(mtd);
                if (!nand_chip->ecc.priv) {
@@ -1948,6 +2103,8 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.calculate        = omap_calculate_ecc_bch;
                nand_chip->ecc.read_page        = omap_read_page_bch;
                nand_chip->ecc.write_page       = omap_write_page_bch;
+               mtd_set_ooblayout(mtd, &omap_ooblayout_ops);
+               oobbytes_per_step               = nand_chip->ecc.bytes;
 
                err = elm_config(info->elm_dev, BCH8_ECC,
                                 mtd->writesize / nand_chip->ecc.size,
@@ -1955,16 +2112,6 @@ static int omap_nand_probe(struct platform_device *pdev)
                if (err < 0)
                        goto return_error;
 
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               oob_index                       = BADBLOCK_MARKER_LENGTH;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
-                       ecclayout->eccpos[i]    = oob_index;
-               /* reserved marker already included in ecclayout->eccbytes */
-               ecclayout->oobfree->offset      =
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
                break;
 
        case OMAP_ECC_BCH16_CODE_HW:
@@ -1978,6 +2125,8 @@ static int omap_nand_probe(struct platform_device *pdev)
                nand_chip->ecc.calculate        = omap_calculate_ecc_bch;
                nand_chip->ecc.read_page        = omap_read_page_bch;
                nand_chip->ecc.write_page       = omap_write_page_bch;
+               mtd_set_ooblayout(mtd, &omap_ooblayout_ops);
+               oobbytes_per_step               = nand_chip->ecc.bytes;
 
                err = elm_config(info->elm_dev, BCH16_ECC,
                                 mtd->writesize / nand_chip->ecc.size,
@@ -1985,16 +2134,6 @@ static int omap_nand_probe(struct platform_device *pdev)
                if (err < 0)
                        goto return_error;
 
-               /* define ECC layout */
-               ecclayout->eccbytes             = nand_chip->ecc.bytes *
-                                                       (mtd->writesize /
-                                                       nand_chip->ecc.size);
-               oob_index                       = BADBLOCK_MARKER_LENGTH;
-               for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
-                       ecclayout->eccpos[i]    = oob_index;
-               /* reserved marker already included in ecclayout->eccbytes */
-               ecclayout->oobfree->offset      =
-                               ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
                break;
        default:
                dev_err(&info->pdev->dev, "invalid or unsupported ECC scheme\n");
@@ -2002,13 +2141,13 @@ static int omap_nand_probe(struct platform_device *pdev)
                goto return_error;
        }
 
-       /* all OOB bytes from oobfree->offset till end off OOB are free */
-       ecclayout->oobfree->length = mtd->oobsize - ecclayout->oobfree->offset;
        /* check if NAND device's OOB is enough to store ECC signatures */
-       if (mtd->oobsize < (ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH)) {
+       min_oobbytes += (oobbytes_per_step *
+                        (mtd->writesize / nand_chip->ecc.size));
+       if (mtd->oobsize < min_oobbytes) {
                dev_err(&info->pdev->dev,
                        "not enough OOB bytes required = %d, available=%d\n",
-                       ecclayout->eccbytes, mtd->oobsize);
+                       min_oobbytes, mtd->oobsize);
                err = -EINVAL;
                goto return_error;
        }
@@ -2020,7 +2159,10 @@ scan_tail:
                goto return_error;
        }
 
-       mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
+       if (dev->of_node)
+               mtd_device_register(mtd, NULL, 0);
+       else
+               mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
 
        platform_set_drvdata(pdev, mtd);
 
@@ -2051,11 +2193,17 @@ static int omap_nand_remove(struct platform_device *pdev)
        return 0;
 }
 
+static const struct of_device_id omap_nand_ids[] = {
+       { .compatible = "ti,omap2-nand", },
+       {},
+};
+
 static struct platform_driver omap_nand_driver = {
        .probe          = omap_nand_probe,
        .remove         = omap_nand_remove,
        .driver         = {
                .name   = DRIVER_NAME,
+               .of_match_table = of_match_ptr(omap_nand_ids),
        },
 };
 
index d4614bfbfed6c1c63b95fec88c2af2c96dedd182..40a7c4a2cf0d44c8f407dc6c170d44cc8d768510 100644 (file)
@@ -130,6 +130,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
        nc->cmd_ctrl = orion_nand_cmd_ctrl;
        nc->read_buf = orion_nand_read_buf;
        nc->ecc.mode = NAND_ECC_SOFT;
+       nc->ecc.algo = NAND_ECC_HAMMING;
 
        if (board->chip_delay)
                nc->chip_delay = board->chip_delay;
index 3ab53ca53cca231c2e3431cc20f3d1932000601f..5de7591b05106bcbf172ad3bc3c6c8013c8b4c32 100644 (file)
@@ -92,8 +92,9 @@ int pasemi_device_ready(struct mtd_info *mtd)
 
 static int pasemi_nand_probe(struct platform_device *ofdev)
 {
+       struct device *dev = &ofdev->dev;
        struct pci_dev *pdev;
-       struct device_node *np = ofdev->dev.of_node;
+       struct device_node *np = dev->of_node;
        struct resource res;
        struct nand_chip *chip;
        int err = 0;
@@ -107,13 +108,11 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
        if (pasemi_nand_mtd)
                return -ENODEV;
 
-       pr_debug("pasemi_nand at %pR\n", &res);
+       dev_dbg(dev, "pasemi_nand at %pR\n", &res);
 
        /* Allocate memory for MTD device structure and private data */
        chip = kzalloc(sizeof(struct nand_chip), GFP_KERNEL);
        if (!chip) {
-               printk(KERN_WARNING
-                      "Unable to allocate PASEMI NAND MTD device structure\n");
                err = -ENOMEM;
                goto out;
        }
@@ -121,7 +120,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
        pasemi_nand_mtd = nand_to_mtd(chip);
 
        /* Link the private data with the MTD structure */
-       pasemi_nand_mtd->dev.parent = &ofdev->dev;
+       pasemi_nand_mtd->dev.parent = dev;
 
        chip->IO_ADDR_R = of_iomap(np, 0);
        chip->IO_ADDR_W = chip->IO_ADDR_R;
@@ -151,6 +150,7 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
        chip->write_buf = pasemi_write_buf;
        chip->chip_delay = 0;
        chip->ecc.mode = NAND_ECC_SOFT;
+       chip->ecc.algo = NAND_ECC_HAMMING;
 
        /* Enable the following for a flash based bad block table */
        chip->bbt_options = NAND_BBT_USE_FLASH;
@@ -162,13 +162,13 @@ static int pasemi_nand_probe(struct platform_device *ofdev)
        }
 
        if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) {
-               printk(KERN_ERR "pasemi_nand: Unable to register MTD device\n");
+               dev_err(dev, "Unable to register MTD device\n");
                err = -ENODEV;
                goto out_lpc;
        }
 
-       printk(KERN_INFO "PA Semi NAND flash at %08llx, control at I/O %x\n",
-              res.start, lpcctl);
+       dev_info(dev, "PA Semi NAND flash at %pR, control at I/O %x\n", &res,
+                lpcctl);
 
        return 0;
 
index e4e50da30444fc2dc2a4c6d936680f74525dac53..415a53a0deeb306bb5baeaf3f5ad6638fd41d103 100644 (file)
@@ -74,6 +74,7 @@ static int plat_nand_probe(struct platform_device *pdev)
 
        data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
        data->chip.ecc.mode = NAND_ECC_SOFT;
+       data->chip.ecc.algo = NAND_ECC_HAMMING;
 
        platform_set_drvdata(pdev, data);
 
index d6508856da9937a433947a57dedce0d8fbd9d0e6..436dd6dc11f4a810e838059c3ed0c5254a7cb07e 100644 (file)
@@ -29,7 +29,6 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_mtd.h>
 #include <linux/platform_data/mtd-nand-pxa3xx.h>
 
 #define        CHIP_DELAY_TIMEOUT      msecs_to_jiffies(200)
@@ -324,6 +323,62 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = {
        { 0xba20, 16, 16, &timing[3] },
 };
 
+static int pxa3xx_ooblayout_ecc(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
+       struct pxa3xx_nand_info *info = host->info_data;
+       int nchunks = mtd->writesize / info->chunk_size;
+
+       if (section >= nchunks)
+               return -ERANGE;
+
+       oobregion->offset = ((info->ecc_size + info->spare_size) * section) +
+                           info->spare_size;
+       oobregion->length = info->ecc_size;
+
+       return 0;
+}
+
+static int pxa3xx_ooblayout_free(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct pxa3xx_nand_host *host = nand_get_controller_data(chip);
+       struct pxa3xx_nand_info *info = host->info_data;
+       int nchunks = mtd->writesize / info->chunk_size;
+
+       if (section >= nchunks)
+               return -ERANGE;
+
+       if (!info->spare_size)
+               return 0;
+
+       oobregion->offset = section * (info->ecc_size + info->spare_size);
+       oobregion->length = info->spare_size;
+       if (!section) {
+               /*
+                * Bootrom looks in bytes 0 & 5 for bad blocks for the
+                * 4KB page / 4bit BCH combination.
+                */
+               if (mtd->writesize == 4096 && info->chunk_size == 2048) {
+                       oobregion->offset += 6;
+                       oobregion->length -= 6;
+               } else {
+                       oobregion->offset += 2;
+                       oobregion->length -= 2;
+               }
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops pxa3xx_ooblayout_ops = {
+       .ecc = pxa3xx_ooblayout_ecc,
+       .free = pxa3xx_ooblayout_free,
+};
+
 static u8 bbt_pattern[] = {'M', 'V', 'B', 'b', 't', '0' };
 static u8 bbt_mirror_pattern[] = {'1', 't', 'b', 'B', 'V', 'M' };
 
@@ -347,41 +402,6 @@ static struct nand_bbt_descr bbt_mirror_descr = {
        .pattern = bbt_mirror_pattern
 };
 
-static struct nand_ecclayout ecc_layout_2KB_bch4bit = {
-       .eccbytes = 32,
-       .eccpos = {
-               32, 33, 34, 35, 36, 37, 38, 39,
-               40, 41, 42, 43, 44, 45, 46, 47,
-               48, 49, 50, 51, 52, 53, 54, 55,
-               56, 57, 58, 59, 60, 61, 62, 63},
-       .oobfree = { {2, 30} }
-};
-
-static struct nand_ecclayout ecc_layout_4KB_bch4bit = {
-       .eccbytes = 64,
-       .eccpos = {
-               32,  33,  34,  35,  36,  37,  38,  39,
-               40,  41,  42,  43,  44,  45,  46,  47,
-               48,  49,  50,  51,  52,  53,  54,  55,
-               56,  57,  58,  59,  60,  61,  62,  63,
-               96,  97,  98,  99,  100, 101, 102, 103,
-               104, 105, 106, 107, 108, 109, 110, 111,
-               112, 113, 114, 115, 116, 117, 118, 119,
-               120, 121, 122, 123, 124, 125, 126, 127},
-       /* Bootrom looks in bytes 0 & 5 for bad blocks */
-       .oobfree = { {6, 26}, { 64, 32} }
-};
-
-static struct nand_ecclayout ecc_layout_4KB_bch8bit = {
-       .eccbytes = 128,
-       .eccpos = {
-               32,  33,  34,  35,  36,  37,  38,  39,
-               40,  41,  42,  43,  44,  45,  46,  47,
-               48,  49,  50,  51,  52,  53,  54,  55,
-               56,  57,  58,  59,  60,  61,  62,  63},
-       .oobfree = { }
-};
-
 #define NDTR0_tCH(c)   (min((c), 7) << 19)
 #define NDTR0_tCS(c)   (min((c), 7) << 16)
 #define NDTR0_tWH(c)   (min((c), 7) << 11)
@@ -1546,9 +1566,12 @@ static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info)
 }
 
 static int pxa_ecc_init(struct pxa3xx_nand_info *info,
-                       struct nand_ecc_ctrl *ecc,
+                       struct mtd_info *mtd,
                        int strength, int ecc_stepsize, int page_size)
 {
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+
        if (strength == 1 && ecc_stepsize == 512 && page_size == 2048) {
                info->nfullchunks = 1;
                info->ntotalchunks = 1;
@@ -1582,7 +1605,7 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,
                info->ecc_size = 32;
                ecc->mode = NAND_ECC_HW;
                ecc->size = info->chunk_size;
-               ecc->layout = &ecc_layout_2KB_bch4bit;
+               mtd_set_ooblayout(mtd, &pxa3xx_ooblayout_ops);
                ecc->strength = 16;
 
        } else if (strength == 4 && ecc_stepsize == 512 && page_size == 4096) {
@@ -1594,7 +1617,7 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,
                info->ecc_size = 32;
                ecc->mode = NAND_ECC_HW;
                ecc->size = info->chunk_size;
-               ecc->layout = &ecc_layout_4KB_bch4bit;
+               mtd_set_ooblayout(mtd, &pxa3xx_ooblayout_ops);
                ecc->strength = 16;
 
        /*
@@ -1612,7 +1635,7 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,
                info->ecc_size = 32;
                ecc->mode = NAND_ECC_HW;
                ecc->size = info->chunk_size;
-               ecc->layout = &ecc_layout_4KB_bch8bit;
+               mtd_set_ooblayout(mtd, &pxa3xx_ooblayout_ops);
                ecc->strength = 16;
        } else {
                dev_err(&info->pdev->dev,
@@ -1651,6 +1674,12 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
        if (info->variant == PXA3XX_NAND_VARIANT_ARMADA370)
                nand_writel(info, NDECCCTRL, 0x0);
 
+       if (pdata->flash_bbt)
+               chip->bbt_options |= NAND_BBT_USE_FLASH;
+
+       chip->ecc.strength = pdata->ecc_strength;
+       chip->ecc.size = pdata->ecc_step_size;
+
        if (nand_scan_ident(mtd, 1, NULL))
                return -ENODEV;
 
@@ -1663,13 +1692,12 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
                }
        }
 
-       if (pdata->flash_bbt) {
+       if (chip->bbt_options & NAND_BBT_USE_FLASH) {
                /*
                 * We'll use a bad block table stored in-flash and don't
                 * allow writing the bad block marker to the flash.
                 */
-               chip->bbt_options |= NAND_BBT_USE_FLASH |
-                                    NAND_BBT_NO_OOB_BBM;
+               chip->bbt_options |= NAND_BBT_NO_OOB_BBM;
                chip->bbt_td = &bbt_main_descr;
                chip->bbt_md = &bbt_mirror_descr;
        }
@@ -1689,10 +1717,9 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
                }
        }
 
-       if (pdata->ecc_strength && pdata->ecc_step_size) {
-               ecc_strength = pdata->ecc_strength;
-               ecc_step = pdata->ecc_step_size;
-       } else {
+       ecc_strength = chip->ecc.strength;
+       ecc_step = chip->ecc.size;
+       if (!ecc_strength || !ecc_step) {
                ecc_strength = chip->ecc_strength_ds;
                ecc_step = chip->ecc_step_ds;
        }
@@ -1703,7 +1730,7 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd)
                ecc_step = 512;
        }
 
-       ret = pxa_ecc_init(info, &chip->ecc, ecc_strength,
+       ret = pxa_ecc_init(info, mtd, ecc_strength,
                           ecc_step, mtd->writesize);
        if (ret)
                return ret;
@@ -1903,15 +1930,6 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)
        if (of_get_property(np, "marvell,nand-keep-config", NULL))
                pdata->keep_config = 1;
        of_property_read_u32(np, "num-cs", &pdata->num_cs);
-       pdata->flash_bbt = of_get_nand_on_flash_bbt(np);
-
-       pdata->ecc_strength = of_get_nand_ecc_strength(np);
-       if (pdata->ecc_strength < 0)
-               pdata->ecc_strength = 0;
-
-       pdata->ecc_step_size = of_get_nand_ecc_step_size(np);
-       if (pdata->ecc_step_size < 0)
-               pdata->ecc_step_size = 0;
 
        pdev->dev.platform_data = pdata;
 
index f550a57e6eea237dacc7b3ca3ceda3914d8a481b..de7d28e62d4e5aeee107894b8f9a11c66f63ed66 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/mtd/partitions.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_mtd.h>
 #include <linux/delay.h>
 
 /* NANDc reg offsets */
@@ -1437,7 +1436,6 @@ static int qcom_nandc_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
        struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
        u8 *oob = chip->oob_poi;
-       int free_boff;
        int data_size, oob_size;
        int ret, status = 0;
 
@@ -1451,12 +1449,11 @@ static int qcom_nandc_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
 
        /* calculate the data and oob size for the last codeword/step */
        data_size = ecc->size - ((ecc->steps - 1) << 2);
-       oob_size = ecc->steps << 2;
-
-       free_boff = ecc->layout->oobfree[0].offset;
+       oob_size = mtd->oobavail;
 
        /* override new oob content to last codeword */
-       memcpy(nandc->data_buffer + data_size, oob + free_boff, oob_size);
+       mtd_ooblayout_get_databytes(mtd, nandc->data_buffer + data_size, oob,
+                                   0, mtd->oobavail);
 
        set_address(host, host->cw_size * (ecc->steps - 1), page);
        update_rw_regs(host, 1, false);
@@ -1710,61 +1707,52 @@ static void qcom_nandc_select_chip(struct mtd_info *mtd, int chipnr)
  * This layout is read as is when ECC is disabled. When ECC is enabled, the
  * inaccessible Bad Block byte(s) are ignored when we write to a page/oob,
  * and assumed as 0xffs when we read a page/oob. The ECC, unused and
- * dummy/real bad block bytes are grouped as ecc bytes in nand_ecclayout (i.e,
- * ecc->bytes is the sum of the three).
+ * dummy/real bad block bytes are grouped as ecc bytes (i.e, ecc->bytes is
+ * the sum of the three).
  */
-
-static struct nand_ecclayout *
-qcom_nand_create_layout(struct qcom_nand_host *host)
+static int qcom_nand_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                  struct mtd_oob_region *oobregion)
 {
-       struct nand_chip *chip = &host->chip;
-       struct mtd_info *mtd = nand_to_mtd(chip);
-       struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct qcom_nand_host *host = to_qcom_nand_host(chip);
        struct nand_ecc_ctrl *ecc = &chip->ecc;
-       struct nand_ecclayout *layout;
-       int i, j, steps, pos = 0, shift = 0;
 
-       layout = devm_kzalloc(nandc->dev, sizeof(*layout), GFP_KERNEL);
-       if (!layout)
-               return NULL;
-
-       steps = mtd->writesize / ecc->size;
-       layout->eccbytes = steps * ecc->bytes;
+       if (section > 1)
+               return -ERANGE;
 
-       layout->oobfree[0].offset = (steps - 1) * ecc->bytes + host->bbm_size;
-       layout->oobfree[0].length = steps << 2;
-
-       /*
-        * the oob bytes in the first n - 1 codewords are all grouped together
-        * in the format:
-        * DUMMY_BBM + UNUSED + ECC
-        */
-       for (i = 0; i < steps - 1; i++) {
-               for (j = 0; j < ecc->bytes; j++)
-                       layout->eccpos[pos++] = i * ecc->bytes + j;
+       if (!section) {
+               oobregion->length = (ecc->bytes * (ecc->steps - 1)) +
+                                   host->bbm_size;
+               oobregion->offset = 0;
+       } else {
+               oobregion->length = host->ecc_bytes_hw + host->spare_bytes;
+               oobregion->offset = mtd->oobsize - oobregion->length;
        }
 
-       /*
-        * the oob bytes in the last codeword are grouped in the format:
-        * BBM + FREE OOB + UNUSED + ECC
-        */
+       return 0;
+}
 
-       /* fill up the bbm positions */
-       for (j = 0; j < host->bbm_size; j++)
-               layout->eccpos[pos++] = i * ecc->bytes + j;
+static int qcom_nand_ooblayout_free(struct mtd_info *mtd, int section,
+                                    struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+       struct qcom_nand_host *host = to_qcom_nand_host(chip);
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
 
-       /*
-        * fill up the ecc and reserved positions, their indices are offseted
-        * by the free oob region
-        */
-       shift = layout->oobfree[0].length + host->bbm_size;
+       if (section)
+               return -ERANGE;
 
-       for (j = 0; j < (host->ecc_bytes_hw + host->spare_bytes); j++)
-               layout->eccpos[pos++] = i * ecc->bytes + shift + j;
+       oobregion->length = ecc->steps * 4;
+       oobregion->offset = ((ecc->steps - 1) * ecc->bytes) + host->bbm_size;
 
-       return layout;
+       return 0;
 }
 
+static const struct mtd_ooblayout_ops qcom_nand_ooblayout_ops = {
+       .ecc = qcom_nand_ooblayout_ecc,
+       .free = qcom_nand_ooblayout_free,
+};
+
 static int qcom_nand_host_setup(struct qcom_nand_host *host)
 {
        struct nand_chip *chip = &host->chip;
@@ -1851,9 +1839,7 @@ static int qcom_nand_host_setup(struct qcom_nand_host *host)
 
        ecc->mode = NAND_ECC_HW;
 
-       ecc->layout = qcom_nand_create_layout(host);
-       if (!ecc->layout)
-               return -ENOMEM;
+       mtd_set_ooblayout(mtd, &qcom_nand_ooblayout_ops);
 
        cwperpage = mtd->writesize / ecc->size;
 
index 9c9397b54b2ca9a826e27fc7625108100ae2fb87..d9309cf0ce2ec3cd6b76f3d61c4fb0433d32b213 100644 (file)
 
 /* new oob placement block for use with hardware ecc generation
  */
+static int s3c2410_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 0;
+       oobregion->length = 3;
+
+       return 0;
+}
+
+static int s3c2410_ooblayout_free(struct mtd_info *mtd, int section,
+                                 struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 8;
+       oobregion->length = 8;
+
+       return 0;
+}
 
-static struct nand_ecclayout nand_hw_eccoob = {
-       .eccbytes = 3,
-       .eccpos = {0, 1, 2},
-       .oobfree = {{8, 8}}
+static const struct mtd_ooblayout_ops s3c2410_ooblayout_ops = {
+       .ecc = s3c2410_ooblayout_ecc,
+       .free = s3c2410_ooblayout_free,
 };
 
 /* controller and mtd information */
@@ -542,7 +564,8 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
        diff0 |= (diff1 << 8);
        diff0 |= (diff2 << 16);
 
-       if ((diff0 & ~(1<<fls(diff0))) == 0)
+       /* equal to "(diff0 & ~(1 << __ffs(diff0)))" */
+       if ((diff0 & (diff0 - 1)) == 0)
                return 1;
 
        return -1;
@@ -859,6 +882,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
        }
 #else
        chip->ecc.mode      = NAND_ECC_SOFT;
+       chip->ecc.algo  = NAND_ECC_HAMMING;
 #endif
 
        if (set->disable_ecc)
@@ -919,7 +943,7 @@ static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
        } else {
                chip->ecc.size      = 512;
                chip->ecc.bytes     = 3;
-               chip->ecc.layout    = &nand_hw_eccoob;
+               mtd_set_ooblayout(nand_to_mtd(chip), &s3c2410_ooblayout_ops);
        }
 }
 
index 4814402902f96df8ff10e370c34aefdde8dcf4f1..6fa3bcd59769946f7b342ed97eebe51e625d5b0a 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/io.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include <linux/of_mtd.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/sh_dma.h>
 #include <linux/mtd/partitions.h>
 #include <linux/mtd/sh_flctl.h>
 
-static struct nand_ecclayout flctl_4secc_oob_16 = {
-       .eccbytes = 10,
-       .eccpos = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
-       .oobfree = {
-               {.offset = 12,
-               . length = 4} },
+static int flctl_4secc_ooblayout_sp_ecc(struct mtd_info *mtd, int section,
+                                       struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 0;
+       oobregion->length = chip->ecc.bytes;
+
+       return 0;
+}
+
+static int flctl_4secc_ooblayout_sp_free(struct mtd_info *mtd, int section,
+                                        struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->offset = 12;
+       oobregion->length = 4;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops flctl_4secc_oob_smallpage_ops = {
+       .ecc = flctl_4secc_ooblayout_sp_ecc,
+       .free = flctl_4secc_ooblayout_sp_free,
 };
 
-static struct nand_ecclayout flctl_4secc_oob_64 = {
-       .eccbytes = 4 * 10,
-       .eccpos = {
-                6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
-               22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-               38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-               54, 55, 56, 57, 58, 59, 60, 61, 62, 63 },
-       .oobfree = {
-               {.offset =  2, .length = 4},
-               {.offset = 16, .length = 6},
-               {.offset = 32, .length = 6},
-               {.offset = 48, .length = 6} },
+static int flctl_4secc_ooblayout_lp_ecc(struct mtd_info *mtd, int section,
+                                       struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 6;
+       oobregion->length = chip->ecc.bytes;
+
+       return 0;
+}
+
+static int flctl_4secc_ooblayout_lp_free(struct mtd_info *mtd, int section,
+                                        struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *chip = mtd_to_nand(mtd);
+
+       if (section >= chip->ecc.steps)
+               return -ERANGE;
+
+       oobregion->offset = section * 16;
+       oobregion->length = 6;
+
+       if (!section) {
+               oobregion->offset += 2;
+               oobregion->length -= 2;
+       }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops flctl_4secc_oob_largepage_ops = {
+       .ecc = flctl_4secc_ooblayout_lp_ecc,
+       .free = flctl_4secc_ooblayout_lp_free,
 };
 
 static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
@@ -987,10 +1033,10 @@ static int flctl_chip_init_tail(struct mtd_info *mtd)
 
        if (flctl->hwecc) {
                if (mtd->writesize == 512) {
-                       chip->ecc.layout = &flctl_4secc_oob_16;
+                       mtd_set_ooblayout(mtd, &flctl_4secc_oob_smallpage_ops);
                        chip->badblock_pattern = &flctl_4secc_smallpage;
                } else {
-                       chip->ecc.layout = &flctl_4secc_oob_64;
+                       mtd_set_ooblayout(mtd, &flctl_4secc_oob_largepage_ops);
                        chip->badblock_pattern = &flctl_4secc_largepage;
                }
 
@@ -1005,6 +1051,7 @@ static int flctl_chip_init_tail(struct mtd_info *mtd)
                flctl->flcmncr_base |= _4ECCEN;
        } else {
                chip->ecc.mode = NAND_ECC_SOFT;
+               chip->ecc.algo = NAND_ECC_HAMMING;
        }
 
        return 0;
@@ -1044,8 +1091,6 @@ static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev)
        const struct of_device_id *match;
        struct flctl_soc_config *config;
        struct sh_flctl_platform_data *pdata;
-       struct device_node *dn = dev->of_node;
-       int ret;
 
        match = of_match_device(of_flctl_match, dev);
        if (match)
@@ -1065,15 +1110,6 @@ static struct sh_flctl_platform_data *flctl_parse_dt(struct device *dev)
        pdata->has_hwecc = config->has_hwecc;
        pdata->use_holden = config->use_holden;
 
-       /* parse user defined options */
-       ret = of_get_nand_bus_width(dn);
-       if (ret == 16)
-               pdata->flcmncr_val |= SEL_16BIT;
-       else if (ret != 8) {
-               dev_err(dev, "%s: invalid bus width\n", __func__);
-               return NULL;
-       }
-
        return pdata;
 }
 
@@ -1136,15 +1172,14 @@ static int flctl_probe(struct platform_device *pdev)
        nand->chip_delay = 20;
 
        nand->read_byte = flctl_read_byte;
+       nand->read_word = flctl_read_word;
        nand->write_buf = flctl_write_buf;
        nand->read_buf = flctl_read_buf;
        nand->select_chip = flctl_select_chip;
        nand->cmdfunc = flctl_cmdfunc;
 
-       if (pdata->flcmncr_val & SEL_16BIT) {
+       if (pdata->flcmncr_val & SEL_16BIT)
                nand->options |= NAND_BUSWIDTH_16;
-               nand->read_word = flctl_read_word;
-       }
 
        pm_runtime_enable(&pdev->dev);
        pm_runtime_resume(&pdev->dev);
@@ -1155,6 +1190,16 @@ static int flctl_probe(struct platform_device *pdev)
        if (ret)
                goto err_chip;
 
+       if (nand->options & NAND_BUSWIDTH_16) {
+               /*
+                * NAND_BUSWIDTH_16 may have been set by nand_scan_ident().
+                * Add the SEL_16BIT flag in pdata->flcmncr_val and re-assign
+                * flctl->flcmncr_base to pdata->flcmncr_val.
+                */
+               pdata->flcmncr_val |= SEL_16BIT;
+               flctl->flcmncr_base = pdata->flcmncr_val;
+       }
+
        ret = flctl_chip_init_tail(flctl_mtd);
        if (ret)
                goto err_chip;
index b7d1b55a160b4ebbbbc0fb52d80d8ee99da6612d..064ca1757589ac8d8cba8b536f72ff30632efcfe 100644 (file)
@@ -148,6 +148,7 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
        /* Link the private data with the MTD structure */
        mtd = nand_to_mtd(this);
        mtd->dev.parent = &pdev->dev;
+       mtd_set_ooblayout(mtd, data->ecc_layout);
 
        platform_set_drvdata(pdev, sharpsl);
 
@@ -170,7 +171,6 @@ static int sharpsl_nand_probe(struct platform_device *pdev)
        this->ecc.bytes = 3;
        this->ecc.strength = 1;
        this->badblock_pattern = data->badblock_pattern;
-       this->ecc.layout = data->ecc_layout;
        this->ecc.hwctl = sharpsl_nand_enable_hwecc;
        this->ecc.calculate = sharpsl_nand_calculate_ecc;
        this->ecc.correct = nand_correct_data;
index c514740f9a8330449af7a453adc5565d086933e2..5939dff253c28a65ae7bc40705c9a9874e58356f 100644 (file)
 #include <linux/sizes.h>
 #include "sm_common.h"
 
-static struct nand_ecclayout nand_oob_sm = {
-       .eccbytes = 6,
-       .eccpos = {8, 9, 10, 13, 14, 15},
-       .oobfree = {
-               {.offset = 0 , .length = 4}, /* reserved */
-               {.offset = 6 , .length = 2}, /* LBA1 */
-               {.offset = 11, .length = 2}  /* LBA2 */
+static int oob_sm_ooblayout_ecc(struct mtd_info *mtd, int section,
+                               struct mtd_oob_region *oobregion)
+{
+       if (section > 1)
+               return -ERANGE;
+
+       oobregion->length = 3;
+       oobregion->offset = ((section + 1) * 8) - 3;
+
+       return 0;
+}
+
+static int oob_sm_ooblayout_free(struct mtd_info *mtd, int section,
+                                struct mtd_oob_region *oobregion)
+{
+       switch (section) {
+       case 0:
+               /* reserved */
+               oobregion->offset = 0;
+               oobregion->length = 4;
+               break;
+       case 1:
+               /* LBA1 */
+               oobregion->offset = 6;
+               oobregion->length = 2;
+               break;
+       case 2:
+               /* LBA2 */
+               oobregion->offset = 11;
+               oobregion->length = 2;
+               break;
+       default:
+               return -ERANGE;
        }
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops oob_sm_ops = {
+       .ecc = oob_sm_ooblayout_ecc,
+       .free = oob_sm_ooblayout_free,
 };
 
 /* NOTE: This layout is is not compatabable with SmartMedia, */
@@ -28,15 +61,43 @@ static struct nand_ecclayout nand_oob_sm = {
 /* If you use smftl, it will bypass this and work correctly */
 /* If you not, then you break SmartMedia compliance anyway */
 
-static struct nand_ecclayout nand_oob_sm_small = {
-       .eccbytes = 3,
-       .eccpos = {0, 1, 2},
-       .oobfree = {
-               {.offset = 3 , .length = 2}, /* reserved */
-               {.offset = 6 , .length = 2}, /* LBA1 */
+static int oob_sm_small_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                     struct mtd_oob_region *oobregion)
+{
+       if (section)
+               return -ERANGE;
+
+       oobregion->length = 3;
+       oobregion->offset = 0;
+
+       return 0;
+}
+
+static int oob_sm_small_ooblayout_free(struct mtd_info *mtd, int section,
+                                      struct mtd_oob_region *oobregion)
+{
+       switch (section) {
+       case 0:
+               /* reserved */
+               oobregion->offset = 3;
+               oobregion->length = 2;
+               break;
+       case 1:
+               /* LBA1 */
+               oobregion->offset = 6;
+               oobregion->length = 2;
+               break;
+       default:
+               return -ERANGE;
        }
-};
 
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops oob_sm_small_ops = {
+       .ecc = oob_sm_small_ooblayout_ecc,
+       .free = oob_sm_small_ooblayout_free,
+};
 
 static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs)
 {
@@ -121,9 +182,9 @@ int sm_register_device(struct mtd_info *mtd, int smartmedia)
 
        /* ECC layout */
        if (mtd->writesize == SM_SECTOR_SIZE)
-               chip->ecc.layout = &nand_oob_sm;
+               mtd_set_ooblayout(mtd, &oob_sm_ops);
        else if (mtd->writesize == SM_SMALL_PAGE)
-               chip->ecc.layout = &nand_oob_sm_small;
+               mtd_set_ooblayout(mtd, &oob_sm_small_ops);
        else
                return -ENODEV;
 
index e3305f9dd6fb97808abcb4b4dc6cb17db4ba994f..888fd314c62a234b7a43e3c922a3d4dbb14e36c9 100644 (file)
@@ -180,6 +180,7 @@ static int socrates_nand_probe(struct platform_device *ofdev)
        nand_chip->dev_ready = socrates_nand_device_ready;
 
        nand_chip->ecc.mode = NAND_ECC_SOFT;    /* enable ECC */
+       nand_chip->ecc.algo = NAND_ECC_HAMMING;
 
        /* TODO: I have no idea what real delay is. */
        nand_chip->chip_delay = 20;             /* 20us command delay time */
index 1c03eee44f3d6fe8ab02d8e6255f7c68fe42ece0..a83a690688b45067a318ef14ed97970c588bb018 100644 (file)
@@ -30,7 +30,6 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_gpio.h>
-#include <linux/of_mtd.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
@@ -39,7 +38,7 @@
 #include <linux/dmaengine.h>
 #include <linux/gpio.h>
 #include <linux/interrupt.h>
-#include <linux/io.h>
+#include <linux/iopoll.h>
 
 #define NFC_REG_CTL            0x0000
 #define NFC_REG_ST             0x0004
 /* define bit use in NFC_ECC_ST */
 #define NFC_ECC_ERR(x)         BIT(x)
 #define NFC_ECC_PAT_FOUND(x)   BIT(x + 16)
-#define NFC_ECC_ERR_CNT(b, x)  (((x) >> ((b) * 8)) & 0xff)
+#define NFC_ECC_ERR_CNT(b, x)  (((x) >> (((b) % 4) * 8)) & 0xff)
 
 #define NFC_DEFAULT_TIMEOUT_MS 1000
 
@@ -212,12 +211,9 @@ struct sunxi_nand_chip_sel {
  * sunxi HW ECC infos: stores information related to HW ECC support
  *
  * @mode:      the sunxi ECC mode field deduced from ECC requirements
- * @layout:    the OOB layout depending on the ECC requirements and the
- *             selected ECC mode
  */
 struct sunxi_nand_hw_ecc {
        int mode;
-       struct nand_ecclayout layout;
 };
 
 /*
@@ -239,6 +235,10 @@ struct sunxi_nand_chip {
        u32 timing_cfg;
        u32 timing_ctl;
        int selected;
+       int addr_cycles;
+       u32 addr[2];
+       int cmd_cycles;
+       u8 cmd[2];
        int nsels;
        struct sunxi_nand_chip_sel sels[0];
 };
@@ -298,54 +298,71 @@ static irqreturn_t sunxi_nfc_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-static int sunxi_nfc_wait_int(struct sunxi_nfc *nfc, u32 flags,
-                             unsigned int timeout_ms)
+static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events,
+                                bool use_polling, unsigned int timeout_ms)
 {
-       init_completion(&nfc->complete);
+       int ret;
 
-       writel(flags, nfc->regs + NFC_REG_INT);
+       if (events & ~NFC_INT_MASK)
+               return -EINVAL;
 
        if (!timeout_ms)
                timeout_ms = NFC_DEFAULT_TIMEOUT_MS;
 
-       if (!wait_for_completion_timeout(&nfc->complete,
-                                        msecs_to_jiffies(timeout_ms))) {
-               dev_err(nfc->dev, "wait interrupt timedout\n");
-               return -ETIMEDOUT;
+       if (!use_polling) {
+               init_completion(&nfc->complete);
+
+               writel(events, nfc->regs + NFC_REG_INT);
+
+               ret = wait_for_completion_timeout(&nfc->complete,
+                                               msecs_to_jiffies(timeout_ms));
+
+               writel(0, nfc->regs + NFC_REG_INT);
+       } else {
+               u32 status;
+
+               ret = readl_poll_timeout(nfc->regs + NFC_REG_ST, status,
+                                        (status & events) == events, 1,
+                                        timeout_ms * 1000);
        }
 
-       return 0;
+       writel(events & NFC_INT_MASK, nfc->regs + NFC_REG_ST);
+
+       if (ret)
+               dev_err(nfc->dev, "wait interrupt timedout\n");
+
+       return ret;
 }
 
 static int sunxi_nfc_wait_cmd_fifo_empty(struct sunxi_nfc *nfc)
 {
-       unsigned long timeout = jiffies +
-                               msecs_to_jiffies(NFC_DEFAULT_TIMEOUT_MS);
+       u32 status;
+       int ret;
 
-       do {
-               if (!(readl(nfc->regs + NFC_REG_ST) & NFC_CMD_FIFO_STATUS))
-                       return 0;
-       } while (time_before(jiffies, timeout));
+       ret = readl_poll_timeout(nfc->regs + NFC_REG_ST, status,
+                                !(status & NFC_CMD_FIFO_STATUS), 1,
+                                NFC_DEFAULT_TIMEOUT_MS * 1000);
+       if (ret)
+               dev_err(nfc->dev, "wait for empty cmd FIFO timedout\n");
 
-       dev_err(nfc->dev, "wait for empty cmd FIFO timedout\n");
-       return -ETIMEDOUT;
+       return ret;
 }
 
 static int sunxi_nfc_rst(struct sunxi_nfc *nfc)
 {
-       unsigned long timeout = jiffies +
-                               msecs_to_jiffies(NFC_DEFAULT_TIMEOUT_MS);
+       u32 ctl;
+       int ret;
 
        writel(0, nfc->regs + NFC_REG_ECC_CTL);
        writel(NFC_RESET, nfc->regs + NFC_REG_CTL);
 
-       do {
-               if (!(readl(nfc->regs + NFC_REG_CTL) & NFC_RESET))
-                       return 0;
-       } while (time_before(jiffies, timeout));
+       ret = readl_poll_timeout(nfc->regs + NFC_REG_CTL, ctl,
+                                !(ctl & NFC_RESET), 1,
+                                NFC_DEFAULT_TIMEOUT_MS * 1000);
+       if (ret)
+               dev_err(nfc->dev, "wait for NAND controller reset timedout\n");
 
-       dev_err(nfc->dev, "wait for NAND controller reset timedout\n");
-       return -ETIMEDOUT;
+       return ret;
 }
 
 static int sunxi_nfc_dev_ready(struct mtd_info *mtd)
@@ -354,7 +371,6 @@ static int sunxi_nfc_dev_ready(struct mtd_info *mtd)
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        struct sunxi_nand_rb *rb;
-       unsigned long timeo = (sunxi_nand->nand.state == FL_ERASING ? 400 : 20);
        int ret;
 
        if (sunxi_nand->selected < 0)
@@ -364,12 +380,6 @@ static int sunxi_nfc_dev_ready(struct mtd_info *mtd)
 
        switch (rb->type) {
        case RB_NATIVE:
-               ret = !!(readl(nfc->regs + NFC_REG_ST) &
-                        NFC_RB_STATE(rb->info.nativeid));
-               if (ret)
-                       break;
-
-               sunxi_nfc_wait_int(nfc, NFC_RB_B2R, timeo);
                ret = !!(readl(nfc->regs + NFC_REG_ST) &
                         NFC_RB_STATE(rb->info.nativeid));
                break;
@@ -407,7 +417,7 @@ static void sunxi_nfc_select_chip(struct mtd_info *mtd, int chip)
                sel = &sunxi_nand->sels[chip];
 
                ctl |= NFC_CE_SEL(sel->cs) | NFC_EN |
-                      NFC_PAGE_SHIFT(nand->page_shift - 10);
+                      NFC_PAGE_SHIFT(nand->page_shift);
                if (sel->rb.type == RB_NONE) {
                        nand->dev_ready = NULL;
                } else {
@@ -452,7 +462,7 @@ static void sunxi_nfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
                tmp = NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD;
                writel(tmp, nfc->regs + NFC_REG_CMD);
 
-               ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0);
+               ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, true, 0);
                if (ret)
                        break;
 
@@ -487,7 +497,7 @@ static void sunxi_nfc_write_buf(struct mtd_info *mtd, const uint8_t *buf,
                      NFC_ACCESS_DIR;
                writel(tmp, nfc->regs + NFC_REG_CMD);
 
-               ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0);
+               ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, true, 0);
                if (ret)
                        break;
 
@@ -511,32 +521,54 @@ static void sunxi_nfc_cmd_ctrl(struct mtd_info *mtd, int dat,
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        int ret;
-       u32 tmp;
 
        ret = sunxi_nfc_wait_cmd_fifo_empty(nfc);
        if (ret)
                return;
 
-       if (ctrl & NAND_CTRL_CHANGE) {
-               tmp = readl(nfc->regs + NFC_REG_CTL);
-               if (ctrl & NAND_NCE)
-                       tmp |= NFC_CE_CTL;
-               else
-                       tmp &= ~NFC_CE_CTL;
-               writel(tmp, nfc->regs + NFC_REG_CTL);
-       }
+       if (dat == NAND_CMD_NONE && (ctrl & NAND_NCE) &&
+           !(ctrl & (NAND_CLE | NAND_ALE))) {
+               u32 cmd = 0;
 
-       if (dat == NAND_CMD_NONE)
-               return;
+               if (!sunxi_nand->addr_cycles && !sunxi_nand->cmd_cycles)
+                       return;
 
-       if (ctrl & NAND_CLE) {
-               writel(NFC_SEND_CMD1 | dat, nfc->regs + NFC_REG_CMD);
-       } else {
-               writel(dat, nfc->regs + NFC_REG_ADDR_LOW);
-               writel(NFC_SEND_ADR, nfc->regs + NFC_REG_CMD);
+               if (sunxi_nand->cmd_cycles--)
+                       cmd |= NFC_SEND_CMD1 | sunxi_nand->cmd[0];
+
+               if (sunxi_nand->cmd_cycles--) {
+                       cmd |= NFC_SEND_CMD2;
+                       writel(sunxi_nand->cmd[1],
+                              nfc->regs + NFC_REG_RCMD_SET);
+               }
+
+               sunxi_nand->cmd_cycles = 0;
+
+               if (sunxi_nand->addr_cycles) {
+                       cmd |= NFC_SEND_ADR |
+                              NFC_ADR_NUM(sunxi_nand->addr_cycles);
+                       writel(sunxi_nand->addr[0],
+                              nfc->regs + NFC_REG_ADDR_LOW);
+               }
+
+               if (sunxi_nand->addr_cycles > 4)
+                       writel(sunxi_nand->addr[1],
+                              nfc->regs + NFC_REG_ADDR_HIGH);
+
+               writel(cmd, nfc->regs + NFC_REG_CMD);
+               sunxi_nand->addr[0] = 0;
+               sunxi_nand->addr[1] = 0;
+               sunxi_nand->addr_cycles = 0;
+               sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, true, 0);
        }
 
-       sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0);
+       if (ctrl & NAND_CLE) {
+               sunxi_nand->cmd[sunxi_nand->cmd_cycles++] = dat;
+       } else if (ctrl & NAND_ALE) {
+               sunxi_nand->addr[sunxi_nand->addr_cycles / 4] |=
+                               dat << ((sunxi_nand->addr_cycles % 4) * 8);
+               sunxi_nand->addr_cycles++;
+       }
 }
 
 /* These seed values have been extracted from Allwinner's BSP */
@@ -717,7 +749,8 @@ static void sunxi_nfc_hw_ecc_enable(struct mtd_info *mtd)
        ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL);
        ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE |
                     NFC_ECC_BLOCK_SIZE_MSK);
-       ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(data->mode) | NFC_ECC_EXCEPTION;
+       ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(data->mode) | NFC_ECC_EXCEPTION |
+                  NFC_ECC_PIPELINE;
 
        writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL);
 }
@@ -739,18 +772,106 @@ static inline void sunxi_nfc_user_data_to_buf(u32 user_data, u8 *buf)
        buf[3] = user_data >> 24;
 }
 
+static inline u32 sunxi_nfc_buf_to_user_data(const u8 *buf)
+{
+       return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+}
+
+static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct mtd_info *mtd, u8 *oob,
+                                               int step, bool bbm, int page)
+{
+       struct nand_chip *nand = mtd_to_nand(mtd);
+       struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
+
+       sunxi_nfc_user_data_to_buf(readl(nfc->regs + NFC_REG_USER_DATA(step)),
+                                  oob);
+
+       /* De-randomize the Bad Block Marker. */
+       if (bbm && (nand->options & NAND_NEED_SCRAMBLING))
+               sunxi_nfc_randomize_bbm(mtd, page, oob);
+}
+
+static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct mtd_info *mtd,
+                                               const u8 *oob, int step,
+                                               bool bbm, int page)
+{
+       struct nand_chip *nand = mtd_to_nand(mtd);
+       struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
+       u8 user_data[4];
+
+       /* Randomize the Bad Block Marker. */
+       if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) {
+               memcpy(user_data, oob, sizeof(user_data));
+               sunxi_nfc_randomize_bbm(mtd, page, user_data);
+               oob = user_data;
+       }
+
+       writel(sunxi_nfc_buf_to_user_data(oob),
+              nfc->regs + NFC_REG_USER_DATA(step));
+}
+
+static void sunxi_nfc_hw_ecc_update_stats(struct mtd_info *mtd,
+                                         unsigned int *max_bitflips, int ret)
+{
+       if (ret < 0) {
+               mtd->ecc_stats.failed++;
+       } else {
+               mtd->ecc_stats.corrected += ret;
+               *max_bitflips = max_t(unsigned int, *max_bitflips, ret);
+       }
+}
+
+static int sunxi_nfc_hw_ecc_correct(struct mtd_info *mtd, u8 *data, u8 *oob,
+                                   int step, bool *erased)
+{
+       struct nand_chip *nand = mtd_to_nand(mtd);
+       struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
+       struct nand_ecc_ctrl *ecc = &nand->ecc;
+       u32 status, tmp;
+
+       *erased = false;
+
+       status = readl(nfc->regs + NFC_REG_ECC_ST);
+
+       if (status & NFC_ECC_ERR(step))
+               return -EBADMSG;
+
+       if (status & NFC_ECC_PAT_FOUND(step)) {
+               u8 pattern;
+
+               if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1))) {
+                       pattern = 0x0;
+               } else {
+                       pattern = 0xff;
+                       *erased = true;
+               }
+
+               if (data)
+                       memset(data, pattern, ecc->size);
+
+               if (oob)
+                       memset(oob, pattern, ecc->bytes + 4);
+
+               return 0;
+       }
+
+       tmp = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(step));
+
+       return NFC_ECC_ERR_CNT(step, tmp);
+}
+
 static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                                       u8 *data, int data_off,
                                       u8 *oob, int oob_off,
                                       int *cur_off,
                                       unsigned int *max_bitflips,
-                                      bool bbm, int page)
+                                      bool bbm, bool oob_required, int page)
 {
        struct nand_chip *nand = mtd_to_nand(mtd);
        struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
        struct nand_ecc_ctrl *ecc = &nand->ecc;
        int raw_mode = 0;
-       u32 status;
+       bool erased;
        int ret;
 
        if (*cur_off != data_off)
@@ -769,34 +890,19 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
        writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP,
               nfc->regs + NFC_REG_CMD);
 
-       ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0);
+       ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, true, 0);
        sunxi_nfc_randomizer_disable(mtd);
        if (ret)
                return ret;
 
        *cur_off = oob_off + ecc->bytes + 4;
 
-       status = readl(nfc->regs + NFC_REG_ECC_ST);
-       if (status & NFC_ECC_PAT_FOUND(0)) {
-               u8 pattern = 0xff;
-
-               if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1)))
-                       pattern = 0x0;
-
-               memset(data, pattern, ecc->size);
-               memset(oob, pattern, ecc->bytes + 4);
-
+       ret = sunxi_nfc_hw_ecc_correct(mtd, data, oob_required ? oob : NULL, 0,
+                                      &erased);
+       if (erased)
                return 1;
-       }
-
-       ret = NFC_ECC_ERR_CNT(0, readl(nfc->regs + NFC_REG_ECC_ERR_CNT(0)));
-
-       memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size);
-
-       nand->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_off, -1);
-       sunxi_nfc_randomizer_read_buf(mtd, oob, ecc->bytes + 4, true, page);
 
-       if (status & NFC_ECC_ERR(0)) {
+       if (ret < 0) {
                /*
                 * Re-read the data with the randomizer disabled to identify
                 * bitflips in erased pages.
@@ -804,35 +910,34 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct mtd_info *mtd,
                if (nand->options & NAND_NEED_SCRAMBLING) {
                        nand->cmdfunc(mtd, NAND_CMD_RNDOUT, data_off, -1);
                        nand->read_buf(mtd, data, ecc->size);
-                       nand->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_off, -1);
-                       nand->read_buf(mtd, oob, ecc->bytes + 4);
+               } else {
+                       memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE,
+                                     ecc->size);
                }
 
+               nand->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_off, -1);
+               nand->read_buf(mtd, oob, ecc->bytes + 4);
+
                ret = nand_check_erased_ecc_chunk(data, ecc->size,
                                                  oob, ecc->bytes + 4,
                                                  NULL, 0, ecc->strength);
                if (ret >= 0)
                        raw_mode = 1;
        } else {
-               /*
-                * The engine protects 4 bytes of OOB data per chunk.
-                * Retrieve the corrected OOB bytes.
-                */
-               sunxi_nfc_user_data_to_buf(readl(nfc->regs + NFC_REG_USER_DATA(0)),
-                                          oob);
+               memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size);
 
-               /* De-randomize the Bad Block Marker. */
-               if (bbm && nand->options & NAND_NEED_SCRAMBLING)
-                       sunxi_nfc_randomize_bbm(mtd, page, oob);
-       }
+               if (oob_required) {
+                       nand->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_off, -1);
+                       sunxi_nfc_randomizer_read_buf(mtd, oob, ecc->bytes + 4,
+                                                     true, page);
 
-       if (ret < 0) {
-               mtd->ecc_stats.failed++;
-       } else {
-               mtd->ecc_stats.corrected += ret;
-               *max_bitflips = max_t(unsigned int, *max_bitflips, ret);
+                       sunxi_nfc_hw_ecc_get_prot_oob_bytes(mtd, oob, 0,
+                                                           bbm, page);
+               }
        }
 
+       sunxi_nfc_hw_ecc_update_stats(mtd, max_bitflips, ret);
+
        return raw_mode;
 }
 
@@ -848,7 +953,7 @@ static void sunxi_nfc_hw_ecc_read_extra_oob(struct mtd_info *mtd,
        if (len <= 0)
                return;
 
-       if (*cur_off != offset)
+       if (!cur_off || *cur_off != offset)
                nand->cmdfunc(mtd, NAND_CMD_RNDOUT,
                              offset + mtd->writesize, -1);
 
@@ -858,12 +963,8 @@ static void sunxi_nfc_hw_ecc_read_extra_oob(struct mtd_info *mtd,
                sunxi_nfc_randomizer_read_buf(mtd, oob + offset, len,
                                              false, page);
 
-       *cur_off = mtd->oobsize + mtd->writesize;
-}
-
-static inline u32 sunxi_nfc_buf_to_user_data(const u8 *buf)
-{
-       return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
+       if (cur_off)
+               *cur_off = mtd->oobsize + mtd->writesize;
 }
 
 static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
@@ -882,19 +983,6 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
 
        sunxi_nfc_randomizer_write_buf(mtd, data, ecc->size, false, page);
 
-       /* Fill OOB data in */
-       if ((nand->options & NAND_NEED_SCRAMBLING) && bbm) {
-               u8 user_data[4];
-
-               memcpy(user_data, oob, 4);
-               sunxi_nfc_randomize_bbm(mtd, page, user_data);
-               writel(sunxi_nfc_buf_to_user_data(user_data),
-                      nfc->regs + NFC_REG_USER_DATA(0));
-       } else {
-               writel(sunxi_nfc_buf_to_user_data(oob),
-                      nfc->regs + NFC_REG_USER_DATA(0));
-       }
-
        if (data_off + ecc->size != oob_off)
                nand->cmdfunc(mtd, NAND_CMD_RNDIN, oob_off, -1);
 
@@ -903,11 +991,13 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct mtd_info *mtd,
                return ret;
 
        sunxi_nfc_randomizer_enable(mtd);
+       sunxi_nfc_hw_ecc_set_prot_oob_bytes(mtd, oob, 0, bbm, page);
+
        writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD |
               NFC_ACCESS_DIR | NFC_ECC_OP,
               nfc->regs + NFC_REG_CMD);
 
-       ret = sunxi_nfc_wait_int(nfc, NFC_CMD_INT_FLAG, 0);
+       ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, true, 0);
        sunxi_nfc_randomizer_disable(mtd);
        if (ret)
                return ret;
@@ -929,13 +1019,14 @@ static void sunxi_nfc_hw_ecc_write_extra_oob(struct mtd_info *mtd,
        if (len <= 0)
                return;
 
-       if (*cur_off != offset)
+       if (!cur_off || *cur_off != offset)
                nand->cmdfunc(mtd, NAND_CMD_RNDIN,
                              offset + mtd->writesize, -1);
 
        sunxi_nfc_randomizer_write_buf(mtd, oob + offset, len, false, page);
 
-       *cur_off = mtd->oobsize + mtd->writesize;
+       if (cur_off)
+               *cur_off = mtd->oobsize + mtd->writesize;
 }
 
 static int sunxi_nfc_hw_ecc_read_page(struct mtd_info *mtd,
@@ -958,7 +1049,7 @@ static int sunxi_nfc_hw_ecc_read_page(struct mtd_info *mtd,
                ret = sunxi_nfc_hw_ecc_read_chunk(mtd, data, data_off, oob,
                                                  oob_off + mtd->writesize,
                                                  &cur_off, &max_bitflips,
-                                                 !i, page);
+                                                 !i, oob_required, page);
                if (ret < 0)
                        return ret;
                else if (ret)
@@ -974,6 +1065,39 @@ static int sunxi_nfc_hw_ecc_read_page(struct mtd_info *mtd,
        return max_bitflips;
 }
 
+static int sunxi_nfc_hw_ecc_read_subpage(struct mtd_info *mtd,
+                                        struct nand_chip *chip,
+                                        u32 data_offs, u32 readlen,
+                                        u8 *bufpoi, int page)
+{
+       struct nand_ecc_ctrl *ecc = &chip->ecc;
+       int ret, i, cur_off = 0;
+       unsigned int max_bitflips = 0;
+
+       sunxi_nfc_hw_ecc_enable(mtd);
+
+       chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
+       for (i = data_offs / ecc->size;
+            i < DIV_ROUND_UP(data_offs + readlen, ecc->size); i++) {
+               int data_off = i * ecc->size;
+               int oob_off = i * (ecc->bytes + 4);
+               u8 *data = bufpoi + data_off;
+               u8 *oob = chip->oob_poi + oob_off;
+
+               ret = sunxi_nfc_hw_ecc_read_chunk(mtd, data, data_off,
+                                                 oob,
+                                                 oob_off + mtd->writesize,
+                                                 &cur_off, &max_bitflips, !i,
+                                                 false, page);
+               if (ret < 0)
+                       return ret;
+       }
+
+       sunxi_nfc_hw_ecc_disable(mtd);
+
+       return max_bitflips;
+}
+
 static int sunxi_nfc_hw_ecc_write_page(struct mtd_info *mtd,
                                       struct nand_chip *chip,
                                       const uint8_t *buf, int oob_required,
@@ -1026,7 +1150,9 @@ static int sunxi_nfc_hw_syndrome_ecc_read_page(struct mtd_info *mtd,
 
                ret = sunxi_nfc_hw_ecc_read_chunk(mtd, data, data_off, oob,
                                                  oob_off, &cur_off,
-                                                 &max_bitflips, !i, page);
+                                                 &max_bitflips, !i,
+                                                 oob_required,
+                                                 page);
                if (ret < 0)
                        return ret;
                else if (ret)
@@ -1074,6 +1200,40 @@ static int sunxi_nfc_hw_syndrome_ecc_write_page(struct mtd_info *mtd,
        return 0;
 }
 
+static int sunxi_nfc_hw_common_ecc_read_oob(struct mtd_info *mtd,
+                                           struct nand_chip *chip,
+                                           int page)
+{
+       chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
+
+       chip->pagebuf = -1;
+
+       return chip->ecc.read_page(mtd, chip, chip->buffers->databuf, 1, page);
+}
+
+static int sunxi_nfc_hw_common_ecc_write_oob(struct mtd_info *mtd,
+                                            struct nand_chip *chip,
+                                            int page)
+{
+       int ret, status;
+
+       chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page);
+
+       chip->pagebuf = -1;
+
+       memset(chip->buffers->databuf, 0xff, mtd->writesize);
+       ret = chip->ecc.write_page(mtd, chip, chip->buffers->databuf, 1, page);
+       if (ret)
+               return ret;
+
+       /* Send command to program the OOB data */
+       chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
+
+       status = chip->waitfunc(mtd, chip);
+
+       return status & NAND_STATUS_FAIL ? -EIO : 0;
+}
+
 static const s32 tWB_lut[] = {6, 12, 16, 20};
 static const s32 tRHW_lut[] = {4, 8, 12, 20};
 
@@ -1101,6 +1261,7 @@ static int sunxi_nand_chip_set_timings(struct sunxi_nand_chip *chip,
        struct sunxi_nfc *nfc = to_sunxi_nfc(chip->nand.controller);
        u32 min_clk_period = 0;
        s32 tWB, tADL, tWHR, tRHW, tCAD;
+       long real_clk_rate;
 
        /* T1 <=> tCLS */
        if (timings->tCLS_min > min_clk_period)
@@ -1163,6 +1324,18 @@ static int sunxi_nand_chip_set_timings(struct sunxi_nand_chip *chip,
                min_clk_period = DIV_ROUND_UP(timings->tWC_min, 2);
 
        /* T16 - T19 + tCAD */
+       if (timings->tWB_max > (min_clk_period * 20))
+               min_clk_period = DIV_ROUND_UP(timings->tWB_max, 20);
+
+       if (timings->tADL_min > (min_clk_period * 32))
+               min_clk_period = DIV_ROUND_UP(timings->tADL_min, 32);
+
+       if (timings->tWHR_min > (min_clk_period * 32))
+               min_clk_period = DIV_ROUND_UP(timings->tWHR_min, 32);
+
+       if (timings->tRHW_min > (min_clk_period * 20))
+               min_clk_period = DIV_ROUND_UP(timings->tRHW_min, 20);
+
        tWB  = sunxi_nand_lookup_timing(tWB_lut, timings->tWB_max,
                                        min_clk_period);
        if (tWB < 0) {
@@ -1198,23 +1371,26 @@ static int sunxi_nand_chip_set_timings(struct sunxi_nand_chip *chip,
        /* TODO: A83 has some more bits for CDQSS, CS, CLHZ, CCS, WC */
        chip->timing_cfg = NFC_TIMING_CFG(tWB, tADL, tWHR, tRHW, tCAD);
 
-       /*
-        * ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data
-        * output cycle timings shall be used if the host drives tRC less than
-        * 30 ns.
-        */
-       chip->timing_ctl = (timings->tRC_min < 30000) ? NFC_TIMING_CTL_EDO : 0;
-
        /* Convert min_clk_period from picoseconds to nanoseconds */
        min_clk_period = DIV_ROUND_UP(min_clk_period, 1000);
 
        /*
-        * Convert min_clk_period into a clk frequency, then get the
-        * appropriate rate for the NAND controller IP given this formula
-        * (specified in the datasheet):
-        * nand clk_rate = 2 * min_clk_rate
+        * Unlike what is stated in Allwinner datasheet, the clk_rate should
+        * be set to (1 / min_clk_period), and not (2 / min_clk_period).
+        * This new formula was verified with a scope and validated by
+        * Allwinner engineers.
         */
-       chip->clk_rate = (2 * NSEC_PER_SEC) / min_clk_period;
+       chip->clk_rate = NSEC_PER_SEC / min_clk_period;
+       real_clk_rate = clk_round_rate(nfc->mod_clk, chip->clk_rate);
+
+       /*
+        * ONFI specification 3.1, paragraph 4.15.2 dictates that EDO data
+        * output cycle timings shall be used if the host drives tRC less than
+        * 30 ns.
+        */
+       min_clk_period = NSEC_PER_SEC / real_clk_rate;
+       chip->timing_ctl = ((min_clk_period * 2) < 30) ?
+                          NFC_TIMING_CTL_EDO : 0;
 
        return 0;
 }
@@ -1257,6 +1433,57 @@ static int sunxi_nand_chip_init_timings(struct sunxi_nand_chip *chip,
        return sunxi_nand_chip_set_timings(chip, timings);
 }
 
+static int sunxi_nand_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                   struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &nand->ecc;
+
+       if (section >= ecc->steps)
+               return -ERANGE;
+
+       oobregion->offset = section * (ecc->bytes + 4) + 4;
+       oobregion->length = ecc->bytes;
+
+       return 0;
+}
+
+static int sunxi_nand_ooblayout_free(struct mtd_info *mtd, int section,
+                                    struct mtd_oob_region *oobregion)
+{
+       struct nand_chip *nand = mtd_to_nand(mtd);
+       struct nand_ecc_ctrl *ecc = &nand->ecc;
+
+       if (section > ecc->steps)
+               return -ERANGE;
+
+       /*
+        * The first 2 bytes are used for BB markers, hence we
+        * only have 2 bytes available in the first user data
+        * section.
+        */
+       if (!section && ecc->mode == NAND_ECC_HW) {
+               oobregion->offset = 2;
+               oobregion->length = 2;
+
+               return 0;
+       }
+
+       oobregion->offset = section * (ecc->bytes + 4);
+
+       if (section < ecc->steps)
+               oobregion->length = 4;
+       else
+               oobregion->offset = mtd->oobsize - oobregion->offset;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops sunxi_nand_ooblayout_ops = {
+       .ecc = sunxi_nand_ooblayout_ecc,
+       .free = sunxi_nand_ooblayout_free,
+};
+
 static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
                                              struct nand_ecc_ctrl *ecc,
                                              struct device_node *np)
@@ -1266,7 +1493,6 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
        struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
        struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
        struct sunxi_nand_hw_ecc *data;
-       struct nand_ecclayout *layout;
        int nsectors;
        int ret;
        int i;
@@ -1295,7 +1521,6 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
        /* HW ECC always work with even numbers of ECC bytes */
        ecc->bytes = ALIGN(ecc->bytes, 2);
 
-       layout = &data->layout;
        nsectors = mtd->writesize / ecc->size;
 
        if (mtd->oobsize < ((ecc->bytes + 4) * nsectors)) {
@@ -1303,9 +1528,9 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
                goto err;
        }
 
-       layout->eccbytes = (ecc->bytes * nsectors);
-
-       ecc->layout = layout;
+       ecc->read_oob = sunxi_nfc_hw_common_ecc_read_oob;
+       ecc->write_oob = sunxi_nfc_hw_common_ecc_write_oob;
+       mtd_set_ooblayout(mtd, &sunxi_nand_ooblayout_ops);
        ecc->priv = data;
 
        return 0;
@@ -1325,9 +1550,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
                                       struct nand_ecc_ctrl *ecc,
                                       struct device_node *np)
 {
-       struct nand_ecclayout *layout;
-       int nsectors;
-       int i, j;
        int ret;
 
        ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np);
@@ -1336,40 +1558,9 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct mtd_info *mtd,
 
        ecc->read_page = sunxi_nfc_hw_ecc_read_page;
        ecc->write_page = sunxi_nfc_hw_ecc_write_page;
-       layout = ecc->layout;
-       nsectors = mtd->writesize / ecc->size;
-
-       for (i = 0; i < nsectors; i++) {
-               if (i) {
-                       layout->oobfree[i].offset =
-                               layout->oobfree[i - 1].offset +
-                               layout->oobfree[i - 1].length +
-                               ecc->bytes;
-                       layout->oobfree[i].length = 4;
-               } else {
-                       /*
-                        * The first 2 bytes are used for BB markers, hence we
-                        * only have 2 bytes available in the first user data
-                        * section.
-                        */
-                       layout->oobfree[i].length = 2;
-                       layout->oobfree[i].offset = 2;
-               }
-
-               for (j = 0; j < ecc->bytes; j++)
-                       layout->eccpos[(ecc->bytes * i) + j] =
-                                       layout->oobfree[i].offset +
-                                       layout->oobfree[i].length + j;
-       }
-
-       if (mtd->oobsize > (ecc->bytes + 4) * nsectors) {
-               layout->oobfree[nsectors].offset =
-                               layout->oobfree[nsectors - 1].offset +
-                               layout->oobfree[nsectors - 1].length +
-                               ecc->bytes;
-               layout->oobfree[nsectors].length = mtd->oobsize -
-                               ((ecc->bytes + 4) * nsectors);
-       }
+       ecc->read_oob_raw = nand_read_oob_std;
+       ecc->write_oob_raw = nand_write_oob_std;
+       ecc->read_subpage = sunxi_nfc_hw_ecc_read_subpage;
 
        return 0;
 }
@@ -1378,9 +1569,6 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
                                                struct nand_ecc_ctrl *ecc,
                                                struct device_node *np)
 {
-       struct nand_ecclayout *layout;
-       int nsectors;
-       int i;
        int ret;
 
        ret = sunxi_nand_hw_common_ecc_ctrl_init(mtd, ecc, np);
@@ -1390,15 +1578,8 @@ static int sunxi_nand_hw_syndrome_ecc_ctrl_init(struct mtd_info *mtd,
        ecc->prepad = 4;
        ecc->read_page = sunxi_nfc_hw_syndrome_ecc_read_page;
        ecc->write_page = sunxi_nfc_hw_syndrome_ecc_write_page;
-
-       layout = ecc->layout;
-       nsectors = mtd->writesize / ecc->size;
-
-       for (i = 0; i < (ecc->bytes * nsectors); i++)
-               layout->eccpos[i] = i;
-
-       layout->oobfree[0].length = mtd->oobsize - i;
-       layout->oobfree[0].offset = i;
+       ecc->read_oob_raw = nand_read_oob_syndrome;
+       ecc->write_oob_raw = nand_write_oob_syndrome;
 
        return 0;
 }
@@ -1411,7 +1592,6 @@ static void sunxi_nand_ecc_cleanup(struct nand_ecc_ctrl *ecc)
                sunxi_nand_hw_common_ecc_ctrl_cleanup(ecc);
                break;
        case NAND_ECC_NONE:
-               kfree(ecc->layout);
        default:
                break;
        }
@@ -1432,8 +1612,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
                return -EINVAL;
 
        switch (ecc->mode) {
-       case NAND_ECC_SOFT_BCH:
-               break;
        case NAND_ECC_HW:
                ret = sunxi_nand_hw_ecc_ctrl_init(mtd, ecc, np);
                if (ret)
@@ -1445,10 +1623,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
                        return ret;
                break;
        case NAND_ECC_NONE:
-               ecc->layout = kzalloc(sizeof(*ecc->layout), GFP_KERNEL);
-               if (!ecc->layout)
-                       return -ENOMEM;
-               ecc->layout->oobfree[0].length = mtd->oobsize;
        case NAND_ECC_SOFT:
                break;
        default:
@@ -1536,21 +1710,6 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
                }
        }
 
-       timings = onfi_async_timing_mode_to_sdr_timings(0);
-       if (IS_ERR(timings)) {
-               ret = PTR_ERR(timings);
-               dev_err(dev,
-                       "could not retrieve timings for ONFI mode 0: %d\n",
-                       ret);
-               return ret;
-       }
-
-       ret = sunxi_nand_chip_set_timings(chip, timings);
-       if (ret) {
-               dev_err(dev, "could not configure chip timings: %d\n", ret);
-               return ret;
-       }
-
        nand = &chip->nand;
        /* Default tR value specified in the ONFI spec (chapter 4.15.1) */
        nand->chip_delay = 200;
@@ -1570,6 +1729,21 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
        mtd = nand_to_mtd(nand);
        mtd->dev.parent = dev;
 
+       timings = onfi_async_timing_mode_to_sdr_timings(0);
+       if (IS_ERR(timings)) {
+               ret = PTR_ERR(timings);
+               dev_err(dev,
+                       "could not retrieve timings for ONFI mode 0: %d\n",
+                       ret);
+               return ret;
+       }
+
+       ret = sunxi_nand_chip_set_timings(chip, timings);
+       if (ret) {
+               dev_err(dev, "could not configure chip timings: %d\n", ret);
+               return ret;
+       }
+
        ret = nand_scan_ident(mtd, nsels, NULL);
        if (ret)
                return ret;
@@ -1580,6 +1754,8 @@ static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc,
        if (nand->options & NAND_NEED_SCRAMBLING)
                nand->options |= NAND_NO_SUBPAGE_WRITE;
 
+       nand->options |= NAND_SUBPAGE_READ;
+
        ret = sunxi_nand_chip_init_timings(chip, np);
        if (ret) {
                dev_err(dev, "could not configure chip timings: %d\n", ret);
@@ -1728,6 +1904,8 @@ static int sunxi_nfc_remove(struct platform_device *pdev)
        struct sunxi_nfc *nfc = platform_get_drvdata(pdev);
 
        sunxi_nand_chips_cleanup(nfc);
+       clk_disable_unprepare(nfc->mod_clk);
+       clk_disable_unprepare(nfc->ahb_clk);
 
        return 0;
 }
index 293feb19b0b149c7add9d4e2bf7dc0f2a8313275..3ad514c44dcb71a008e816a37e53af8183d6295a 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
-#include <linux/of_mtd.h>
 #include <linux/of_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
@@ -175,34 +174,6 @@ static inline struct vf610_nfc *mtd_to_nfc(struct mtd_info *mtd)
        return container_of(mtd_to_nand(mtd), struct vf610_nfc, chip);
 }
 
-static struct nand_ecclayout vf610_nfc_ecc45 = {
-       .eccbytes = 45,
-       .eccpos = {19, 20, 21, 22, 23,
-                  24, 25, 26, 27, 28, 29, 30, 31,
-                  32, 33, 34, 35, 36, 37, 38, 39,
-                  40, 41, 42, 43, 44, 45, 46, 47,
-                  48, 49, 50, 51, 52, 53, 54, 55,
-                  56, 57, 58, 59, 60, 61, 62, 63},
-       .oobfree = {
-               {.offset = 2,
-                .length = 17} }
-};
-
-static struct nand_ecclayout vf610_nfc_ecc60 = {
-       .eccbytes = 60,
-       .eccpos = { 4,  5,  6,  7,  8,  9, 10, 11,
-                  12, 13, 14, 15, 16, 17, 18, 19,
-                  20, 21, 22, 23, 24, 25, 26, 27,
-                  28, 29, 30, 31, 32, 33, 34, 35,
-                  36, 37, 38, 39, 40, 41, 42, 43,
-                  44, 45, 46, 47, 48, 49, 50, 51,
-                  52, 53, 54, 55, 56, 57, 58, 59,
-                  60, 61, 62, 63 },
-       .oobfree = {
-               {.offset = 2,
-                .length = 2} }
-};
-
 static inline u32 vf610_nfc_read(struct vf610_nfc *nfc, uint reg)
 {
        return readl(nfc->regs + reg);
@@ -781,14 +752,16 @@ static int vf610_nfc_probe(struct platform_device *pdev)
                if (mtd->oobsize > 64)
                        mtd->oobsize = 64;
 
+               /*
+                * mtd->ecclayout is not specified here because we're using the
+                * default large page ECC layout defined in NAND core.
+                */
                if (chip->ecc.strength == 32) {
                        nfc->ecc_mode = ECC_60_BYTE;
                        chip->ecc.bytes = 60;
-                       chip->ecc.layout = &vf610_nfc_ecc60;
                } else if (chip->ecc.strength == 24) {
                        nfc->ecc_mode = ECC_45_BYTE;
                        chip->ecc.bytes = 45;
-                       chip->ecc.layout = &vf610_nfc_ecc45;
                } else {
                        dev_err(nfc->dev, "Unsupported ECC strength\n");
                        err = -ENXIO;
index af28bb3ae7cfc56ccd68e0b0a9d6d05fc5e6296e..a4b029a417f04edf9740e29d286659b9e19712aa 100644 (file)
@@ -68,21 +68,33 @@ MODULE_PARM_DESC(otp,       "Corresponding behaviour of OneNAND in OTP"
  * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
  * For now, we expose only 64 out of 80 ecc bytes
  */
-static struct nand_ecclayout flexonenand_oob_128 = {
-       .eccbytes       = 64,
-       .eccpos         = {
-               6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-               22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-               38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-               54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-               70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-               86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-               102, 103, 104, 105
-               },
-       .oobfree        = {
-               {2, 4}, {18, 4}, {34, 4}, {50, 4},
-               {66, 4}, {82, 4}, {98, 4}, {114, 4}
-       }
+static int flexonenand_ooblayout_ecc(struct mtd_info *mtd, int section,
+                                    struct mtd_oob_region *oobregion)
+{
+       if (section > 7)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 6;
+       oobregion->length = 10;
+
+       return 0;
+}
+
+static int flexonenand_ooblayout_free(struct mtd_info *mtd, int section,
+                                     struct mtd_oob_region *oobregion)
+{
+       if (section > 7)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 2;
+       oobregion->length = 4;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops flexonenand_ooblayout_ops = {
+       .ecc = flexonenand_ooblayout_ecc,
+       .free = flexonenand_ooblayout_free,
 };
 
 /*
@@ -91,56 +103,77 @@ static struct nand_ecclayout flexonenand_oob_128 = {
  * Based on specification:
  * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
  *
- * For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout)
- *
- * oobfree uses the spare area fields marked as
- * "Managed by internal ECC logic for Logical Sector Number area"
  */
-static struct nand_ecclayout onenand_oob_128 = {
-       .eccbytes       = 64,
-       .eccpos         = {
-               7, 8, 9, 10, 11, 12, 13, 14, 15,
-               23, 24, 25, 26, 27, 28, 29, 30, 31,
-               39, 40, 41, 42, 43, 44, 45, 46, 47,
-               55, 56, 57, 58, 59, 60, 61, 62, 63,
-               71, 72, 73, 74, 75, 76, 77, 78, 79,
-               87, 88, 89, 90, 91, 92, 93, 94, 95,
-               103, 104, 105, 106, 107, 108, 109, 110, 111,
-               119
-       },
-       .oobfree        = {
-               {2, 3}, {18, 3}, {34, 3}, {50, 3},
-               {66, 3}, {82, 3}, {98, 3}, {114, 3}
-       }
+static int onenand_ooblayout_128_ecc(struct mtd_info *mtd, int section,
+                                    struct mtd_oob_region *oobregion)
+{
+       if (section > 7)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 7;
+       oobregion->length = 9;
+
+       return 0;
+}
+
+static int onenand_ooblayout_128_free(struct mtd_info *mtd, int section,
+                                     struct mtd_oob_region *oobregion)
+{
+       if (section >= 8)
+               return -ERANGE;
+
+       /*
+        * free bytes are using the spare area fields marked as
+        * "Managed by internal ECC logic for Logical Sector Number area"
+        */
+       oobregion->offset = (section * 16) + 2;
+       oobregion->length = 3;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops onenand_oob_128_ooblayout_ops = {
+       .ecc = onenand_ooblayout_128_ecc,
+       .free = onenand_ooblayout_128_free,
 };
 
 /**
- * onenand_oob_64 - oob info for large (2KB) page
+ * onenand_oob_32_64 - oob info for large (2KB) page
  */
-static struct nand_ecclayout onenand_oob_64 = {
-       .eccbytes       = 20,
-       .eccpos         = {
-               8, 9, 10, 11, 12,
-               24, 25, 26, 27, 28,
-               40, 41, 42, 43, 44,
-               56, 57, 58, 59, 60,
-               },
-       .oobfree        = {
-               {2, 3}, {14, 2}, {18, 3}, {30, 2},
-               {34, 3}, {46, 2}, {50, 3}, {62, 2}
+static int onenand_ooblayout_32_64_ecc(struct mtd_info *mtd, int section,
+                                      struct mtd_oob_region *oobregion)
+{
+       if (section > 3)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 8;
+       oobregion->length = 5;
+
+       return 0;
+}
+
+static int onenand_ooblayout_32_64_free(struct mtd_info *mtd, int section,
+                                       struct mtd_oob_region *oobregion)
+{
+       int sections = (mtd->oobsize / 32) * 2;
+
+       if (section >= sections)
+               return -ERANGE;
+
+       if (section & 1) {
+               oobregion->offset = ((section - 1) * 16) + 14;
+               oobregion->length = 2;
+       } else  {
+               oobregion->offset = (section * 16) + 2;
+               oobregion->length = 3;
        }
-};
 
-/**
- * onenand_oob_32 - oob info for middle (1KB) page
- */
-static struct nand_ecclayout onenand_oob_32 = {
-       .eccbytes       = 10,
-       .eccpos         = {
-               8, 9, 10, 11, 12,
-               24, 25, 26, 27, 28,
-               },
-       .oobfree        = { {2, 3}, {14, 2}, {18, 3}, {30, 2} }
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops onenand_oob_32_64_ooblayout_ops = {
+       .ecc = onenand_ooblayout_32_64_ecc,
+       .free = onenand_ooblayout_32_64_free,
 };
 
 static const unsigned char ffchars[] = {
@@ -1024,34 +1057,15 @@ static int onenand_transfer_auto_oob(struct mtd_info *mtd, uint8_t *buf, int col
                                int thislen)
 {
        struct onenand_chip *this = mtd->priv;
-       struct nand_oobfree *free;
-       int readcol = column;
-       int readend = column + thislen;
-       int lastgap = 0;
-       unsigned int i;
-       uint8_t *oob_buf = this->oob_buf;
-
-       free = this->ecclayout->oobfree;
-       for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && free->length; i++, free++) {
-               if (readcol >= lastgap)
-                       readcol += free->offset - lastgap;
-               if (readend >= lastgap)
-                       readend += free->offset - lastgap;
-               lastgap = free->offset + free->length;
-       }
-       this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize);
-       free = this->ecclayout->oobfree;
-       for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && free->length; i++, free++) {
-               int free_end = free->offset + free->length;
-               if (free->offset < readend && free_end > readcol) {
-                       int st = max_t(int,free->offset,readcol);
-                       int ed = min_t(int,free_end,readend);
-                       int n = ed - st;
-                       memcpy(buf, oob_buf + st, n);
-                       buf += n;
-               } else if (column == 0)
-                       break;
-       }
+       int ret;
+
+       this->read_bufferram(mtd, ONENAND_SPARERAM, this->oob_buf, 0,
+                            mtd->oobsize);
+       ret = mtd_ooblayout_get_databytes(mtd, buf, this->oob_buf,
+                                         column, thislen);
+       if (ret)
+               return ret;
+
        return 0;
 }
 
@@ -1808,34 +1822,7 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
 static int onenand_fill_auto_oob(struct mtd_info *mtd, u_char *oob_buf,
                                  const u_char *buf, int column, int thislen)
 {
-       struct onenand_chip *this = mtd->priv;
-       struct nand_oobfree *free;
-       int writecol = column;
-       int writeend = column + thislen;
-       int lastgap = 0;
-       unsigned int i;
-
-       free = this->ecclayout->oobfree;
-       for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && free->length; i++, free++) {
-               if (writecol >= lastgap)
-                       writecol += free->offset - lastgap;
-               if (writeend >= lastgap)
-                       writeend += free->offset - lastgap;
-               lastgap = free->offset + free->length;
-       }
-       free = this->ecclayout->oobfree;
-       for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES && free->length; i++, free++) {
-               int free_end = free->offset + free->length;
-               if (free->offset < writeend && free_end > writecol) {
-                       int st = max_t(int,free->offset,writecol);
-                       int ed = min_t(int,free_end,writeend);
-                       int n = ed - st;
-                       memcpy(oob_buf + st, buf, n);
-                       buf += n;
-               } else if (column == 0)
-                       break;
-       }
-       return 0;
+       return mtd_ooblayout_set_databytes(mtd, buf, oob_buf, column, thislen);
 }
 
 /**
@@ -4003,22 +3990,22 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
        switch (mtd->oobsize) {
        case 128:
                if (FLEXONENAND(this)) {
-                       this->ecclayout = &flexonenand_oob_128;
+                       mtd_set_ooblayout(mtd, &flexonenand_ooblayout_ops);
                        mtd->subpage_sft = 0;
                } else {
-                       this->ecclayout = &onenand_oob_128;
+                       mtd_set_ooblayout(mtd, &onenand_oob_128_ooblayout_ops);
                        mtd->subpage_sft = 2;
                }
                if (ONENAND_IS_NOP_1(this))
                        mtd->subpage_sft = 0;
                break;
        case 64:
-               this->ecclayout = &onenand_oob_64;
+               mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
                mtd->subpage_sft = 2;
                break;
 
        case 32:
-               this->ecclayout = &onenand_oob_32;
+               mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
                mtd->subpage_sft = 1;
                break;
 
@@ -4027,7 +4014,7 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
                        __func__, mtd->oobsize);
                mtd->subpage_sft = 0;
                /* To prevent kernel oops */
-               this->ecclayout = &onenand_oob_32;
+               mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops);
                break;
        }
 
@@ -4037,12 +4024,12 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
         * The number of bytes available for a client to place data into
         * the out of band area
         */
-       mtd->oobavail = 0;
-       for (i = 0; i < MTD_MAX_OOBFREE_ENTRIES &&
-           this->ecclayout->oobfree[i].length; i++)
-               mtd->oobavail += this->ecclayout->oobfree[i].length;
+       ret = mtd_ooblayout_count_freebytes(mtd);
+       if (ret < 0)
+               ret = 0;
+
+       mtd->oobavail = ret;
 
-       mtd->ecclayout = this->ecclayout;
        mtd->ecc_strength = 1;
 
        /* Fill in remaining MTD driver data */
index 157841dc3e99e87826639f6418d3701f84632968..c52e45594bfd6e78775f6250314c9cf26a049e2a 100644 (file)
@@ -832,6 +832,7 @@ static const struct flash_info spi_nor_ids[] = {
        /* GigaDevice */
        { "gd25q32", INFO(0xc84016, 0, 64 * 1024,  64, SECT_4K) },
        { "gd25q64", INFO(0xc84017, 0, 64 * 1024, 128, SECT_4K) },
+       { "gd25lq64c", INFO(0xc86017, 0, 64 * 1024, 128, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) },
        { "gd25q128", INFO(0xc84018, 0, 64 * 1024, 256, SECT_4K) },
 
        /* Intel/Numonyx -- xxxs33b */
index bee3fa96b981461778e3d5ee8ee3380f8dea2d71..d7efd9d458aab4554139e93c72a1688aa0eeef6a 100644 (file)
@@ -10,7 +10,6 @@ obj-$(CONFIG_OF_UNITTEST) += unittest.o
 obj-$(CONFIG_OF_MDIO)  += of_mdio.o
 obj-$(CONFIG_OF_PCI)   += of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
-obj-$(CONFIG_OF_MTD)   += of_mtd.o
 obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o
 obj-$(CONFIG_OF_RESOLVE)  += resolver.o
 obj-$(CONFIG_OF_OVERLAY) += overlay.o
diff --git a/drivers/of/of_mtd.c b/drivers/of/of_mtd.c
deleted file mode 100644 (file)
index b7361ed..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
- *
- * OF helpers for mtd.
- *
- * This file is released under the GPLv2
- *
- */
-#include <linux/kernel.h>
-#include <linux/of_mtd.h>
-#include <linux/mtd/nand.h>
-#include <linux/export.h>
-
-/**
- * It maps 'enum nand_ecc_modes_t' found in include/linux/mtd/nand.h
- * into the device tree binding of 'nand-ecc', so that MTD
- * device driver can get nand ecc from device tree.
- */
-static const char *nand_ecc_modes[] = {
-       [NAND_ECC_NONE]         = "none",
-       [NAND_ECC_SOFT]         = "soft",
-       [NAND_ECC_HW]           = "hw",
-       [NAND_ECC_HW_SYNDROME]  = "hw_syndrome",
-       [NAND_ECC_HW_OOB_FIRST] = "hw_oob_first",
-       [NAND_ECC_SOFT_BCH]     = "soft_bch",
-};
-
-/**
- * of_get_nand_ecc_mode - Get nand ecc mode for given device_node
- * @np:        Pointer to the given device_node
- *
- * The function gets ecc mode string from property 'nand-ecc-mode',
- * and return its index in nand_ecc_modes table, or errno in error case.
- */
-int of_get_nand_ecc_mode(struct device_node *np)
-{
-       const char *pm;
-       int err, i;
-
-       err = of_property_read_string(np, "nand-ecc-mode", &pm);
-       if (err < 0)
-               return err;
-
-       for (i = 0; i < ARRAY_SIZE(nand_ecc_modes); i++)
-               if (!strcasecmp(pm, nand_ecc_modes[i]))
-                       return i;
-
-       return -ENODEV;
-}
-EXPORT_SYMBOL_GPL(of_get_nand_ecc_mode);
-
-/**
- * of_get_nand_ecc_step_size - Get ECC step size associated to
- * the required ECC strength (see below).
- * @np:        Pointer to the given device_node
- *
- * return the ECC step size, or errno in error case.
- */
-int of_get_nand_ecc_step_size(struct device_node *np)
-{
-       int ret;
-       u32 val;
-
-       ret = of_property_read_u32(np, "nand-ecc-step-size", &val);
-       return ret ? ret : val;
-}
-EXPORT_SYMBOL_GPL(of_get_nand_ecc_step_size);
-
-/**
- * of_get_nand_ecc_strength - Get required ECC strength over the
- * correspnding step size as defined by 'nand-ecc-size'
- * @np:        Pointer to the given device_node
- *
- * return the ECC strength, or errno in error case.
- */
-int of_get_nand_ecc_strength(struct device_node *np)
-{
-       int ret;
-       u32 val;
-
-       ret = of_property_read_u32(np, "nand-ecc-strength", &val);
-       return ret ? ret : val;
-}
-EXPORT_SYMBOL_GPL(of_get_nand_ecc_strength);
-
-/**
- * of_get_nand_bus_width - Get nand bus witdh for given device_node
- * @np:        Pointer to the given device_node
- *
- * return bus width option, or errno in error case.
- */
-int of_get_nand_bus_width(struct device_node *np)
-{
-       u32 val;
-
-       if (of_property_read_u32(np, "nand-bus-width", &val))
-               return 8;
-
-       switch(val) {
-       case 8:
-       case 16:
-               return val;
-       default:
-               return -EIO;
-       }
-}
-EXPORT_SYMBOL_GPL(of_get_nand_bus_width);
-
-/**
- * of_get_nand_on_flash_bbt - Get nand on flash bbt for given device_node
- * @np:        Pointer to the given device_node
- *
- * return true if present false other wise
- */
-bool of_get_nand_on_flash_bbt(struct device_node *np)
-{
-       return of_property_read_bool(np, "nand-on-flash-bbt");
-}
-EXPORT_SYMBOL_GPL(of_get_nand_on_flash_bbt);
index 3c3e56df526efb251cff6d859867d6484884c904..a003ba26ca6e7ec6b0bfadaeb2932d504381419b 100644 (file)
@@ -1059,7 +1059,7 @@ static const struct pmic_wrapper_type pwrap_mt2701 = {
        .regs = mt2701_regs,
        .type = PWRAP_MT2701,
        .arb_en_all = 0x3f,
-       .int_en_all = ~(BIT(31) | BIT(2)),
+       .int_en_all = ~(u32)(BIT(31) | BIT(2)),
        .spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW,
        .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
        .has_bridge = 0,
@@ -1071,7 +1071,7 @@ static struct pmic_wrapper_type pwrap_mt8135 = {
        .regs = mt8135_regs,
        .type = PWRAP_MT8135,
        .arb_en_all = 0x1ff,
-       .int_en_all = ~(BIT(31) | BIT(1)),
+       .int_en_all = ~(u32)(BIT(31) | BIT(1)),
        .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
        .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
        .has_bridge = 1,
@@ -1083,7 +1083,7 @@ static struct pmic_wrapper_type pwrap_mt8173 = {
        .regs = mt8173_regs,
        .type = PWRAP_MT8173,
        .arb_en_all = 0x3f,
-       .int_en_all = ~(BIT(31) | BIT(1)),
+       .int_en_all = ~(u32)(BIT(31) | BIT(1)),
        .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
        .wdt_src = PWRAP_WDT_SRC_MASK_NO_STAUPD,
        .has_bridge = 0,
index 9d8c84bb15446a75153d64f94a5900ab165193ac..4b931ec8d90b610f498a3e317e0523e9d1aa6900 100644 (file)
@@ -410,7 +410,6 @@ config SPI_OMAP_UWIRE
 config SPI_OMAP24XX
        tristate "McSPI driver for OMAP"
        depends on HAS_DMA
-       depends on ARM || ARM64 || AVR32 || HEXAGON || MIPS || SUPERH
        depends on ARCH_OMAP2PLUS || COMPILE_TEST
        help
          SPI master controller for OMAP24XX and later Multichannel SPI
@@ -432,10 +431,23 @@ config SPI_OMAP_100K
 
 config SPI_ORION
        tristate "Orion SPI master"
-       depends on PLAT_ORION || COMPILE_TEST
+       depends on PLAT_ORION || ARCH_MVEBU || COMPILE_TEST
        help
          This enables using the SPI master controller on the Orion chips.
 
+config SPI_PIC32
+       tristate "Microchip PIC32 series SPI"
+       depends on MACH_PIC32 || COMPILE_TEST
+       help
+         SPI driver for Microchip PIC32 SPI master controller.
+
+config SPI_PIC32_SQI
+       tristate "Microchip PIC32 Quad SPI driver"
+       depends on MACH_PIC32 || COMPILE_TEST
+       depends on HAS_DMA
+       help
+         SPI driver for PIC32 Quad SPI controller.
+
 config SPI_PL022
        tristate "ARM AMBA PL022 SSP controller"
        depends on ARM_AMBA
@@ -469,7 +481,6 @@ config SPI_PXA2XX_PCI
 
 config SPI_ROCKCHIP
        tristate "Rockchip SPI controller driver"
-       depends on ARM || ARM64 || AVR32 || HEXAGON || MIPS || SUPERH
        help
          This selects a driver for Rockchip SPI controller.
 
@@ -569,7 +580,7 @@ config SPI_SIRF
 
 config SPI_ST_SSC4
        tristate "STMicroelectronics SPI SSC-based driver"
-       depends on ARCH_STI
+       depends on ARCH_STI || COMPILE_TEST
        help
          STMicroelectronics SoCs support for SPI. If you say yes to
          this option, support will be included for the SSC driven SPI.
@@ -656,7 +667,7 @@ config SPI_XILINX
 
 config SPI_XLP
        tristate "Netlogic XLP SPI controller driver"
-       depends on CPU_XLP || COMPILE_TEST
+       depends on CPU_XLP || ARCH_VULCAN || COMPILE_TEST
        help
          Enable support for the SPI controller on the Netlogic XLP SoCs.
          Currently supported XLP variants are XLP8XX, XLP3XX, XLP2XX, XLP9XX
index fbb255c5a608d270ccdb10f1d7ea8f2bd3e24c45..3c74d003535bb9fb922392901c0a9905dd9cdcbd 100644 (file)
@@ -62,6 +62,8 @@ obj-$(CONFIG_SPI_OMAP_100K)           += spi-omap-100k.o
 obj-$(CONFIG_SPI_OMAP24XX)             += spi-omap2-mcspi.o
 obj-$(CONFIG_SPI_TI_QSPI)              += spi-ti-qspi.o
 obj-$(CONFIG_SPI_ORION)                        += spi-orion.o
+obj-$(CONFIG_SPI_PIC32)                        += spi-pic32.o
+obj-$(CONFIG_SPI_PIC32_SQI)            += spi-pic32-sqi.o
 obj-$(CONFIG_SPI_PL022)                        += spi-pl022.o
 obj-$(CONFIG_SPI_PPC4xx)               += spi-ppc4xx.o
 spi-pxa2xx-platform-objs               := spi-pxa2xx.o spi-pxa2xx-dma.o
index c968ab210a5157482f199f23328d7fb22c27e0c7..2b1456e5e2219c19cf5ab83c2b2cd61d987e118f 100644 (file)
@@ -525,7 +525,6 @@ static int spi_engine_probe(struct platform_device *pdev)
        if (ret)
                goto err_ref_clk_disable;
 
-       master->dev.parent = &pdev->dev;
        master->dev.of_node = pdev->dev.of_node;
        master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE;
        master->bits_per_word_mask = SPI_BPW_MASK(8);
index cc3f938f0a6b67632515ee0606f67417779043e9..afb51699dbb5a6953821189ed03a9bfbfa8d9b7a 100644 (file)
@@ -10,6 +10,7 @@
 #include "spi-bcm53xx.h"
 
 #define BCM53XXSPI_MAX_SPI_BAUD        13500000        /* 216 MHz? */
+#define BCM53XXSPI_FLASH_WINDOW        SZ_32M
 
 /* The longest observed required wait was 19 ms */
 #define BCM53XXSPI_SPE_TIMEOUT_MS      80
 struct bcm53xxspi {
        struct bcma_device *core;
        struct spi_master *master;
+       void __iomem *mmio_base;
 
        size_t read_offset;
+       bool bspi;                              /* Boot SPI mode with memory mapping */
 };
 
 static inline u32 bcm53xxspi_read(struct bcm53xxspi *b53spi, u16 offset)
@@ -32,6 +35,50 @@ static inline void bcm53xxspi_write(struct bcm53xxspi *b53spi, u16 offset,
        bcma_write32(b53spi->core, offset, value);
 }
 
+static void bcm53xxspi_disable_bspi(struct bcm53xxspi *b53spi)
+{
+       struct device *dev = &b53spi->core->dev;
+       unsigned long deadline;
+       u32 tmp;
+
+       if (!b53spi->bspi)
+               return;
+
+       tmp = bcm53xxspi_read(b53spi, B53SPI_BSPI_MAST_N_BOOT_CTRL);
+       if (tmp & 0x1)
+               return;
+
+       deadline = jiffies + usecs_to_jiffies(200);
+       do {
+               tmp = bcm53xxspi_read(b53spi, B53SPI_BSPI_BUSY_STATUS);
+               if (!(tmp & 0x1)) {
+                       bcm53xxspi_write(b53spi, B53SPI_BSPI_MAST_N_BOOT_CTRL,
+                                        0x1);
+                       ndelay(200);
+                       b53spi->bspi = false;
+                       return;
+               }
+               udelay(1);
+       } while (!time_after_eq(jiffies, deadline));
+
+       dev_warn(dev, "Timeout disabling BSPI\n");
+}
+
+static void bcm53xxspi_enable_bspi(struct bcm53xxspi *b53spi)
+{
+       u32 tmp;
+
+       if (b53spi->bspi)
+               return;
+
+       tmp = bcm53xxspi_read(b53spi, B53SPI_BSPI_MAST_N_BOOT_CTRL);
+       if (!(tmp & 0x1))
+               return;
+
+       bcm53xxspi_write(b53spi, B53SPI_BSPI_MAST_N_BOOT_CTRL, 0x0);
+       b53spi->bspi = true;
+}
+
 static inline unsigned int bcm53xxspi_calc_timeout(size_t len)
 {
        /* Do some magic calculation based on length and buad. Add 10% and 1. */
@@ -176,6 +223,8 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,
        u8 *buf;
        size_t left;
 
+       bcm53xxspi_disable_bspi(b53spi);
+
        if (t->tx_buf) {
                buf = (u8 *)t->tx_buf;
                left = t->len;
@@ -206,6 +255,22 @@ static int bcm53xxspi_transfer_one(struct spi_master *master,
        return 0;
 }
 
+static int bcm53xxspi_flash_read(struct spi_device *spi,
+                                struct spi_flash_read_message *msg)
+{
+       struct bcm53xxspi *b53spi = spi_master_get_devdata(spi->master);
+       int ret = 0;
+
+       if (msg->from + msg->len > BCM53XXSPI_FLASH_WINDOW)
+               return -EINVAL;
+
+       bcm53xxspi_enable_bspi(b53spi);
+       memcpy_fromio(msg->buf, b53spi->mmio_base + msg->from, msg->len);
+       msg->retlen = msg->len;
+
+       return ret;
+}
+
 /**************************************************
  * BCMA
  **************************************************/
@@ -222,6 +287,7 @@ MODULE_DEVICE_TABLE(bcma, bcm53xxspi_bcma_tbl);
 
 static int bcm53xxspi_bcma_probe(struct bcma_device *core)
 {
+       struct device *dev = &core->dev;
        struct bcm53xxspi *b53spi;
        struct spi_master *master;
        int err;
@@ -231,7 +297,7 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core)
                return -ENOTSUPP;
        }
 
-       master = spi_alloc_master(&core->dev, sizeof(*b53spi));
+       master = spi_alloc_master(dev, sizeof(*b53spi));
        if (!master)
                return -ENOMEM;
 
@@ -239,11 +305,19 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core)
        b53spi->master = master;
        b53spi->core = core;
 
+       if (core->addr_s[0])
+               b53spi->mmio_base = devm_ioremap(dev, core->addr_s[0],
+                                                BCM53XXSPI_FLASH_WINDOW);
+       b53spi->bspi = true;
+       bcm53xxspi_disable_bspi(b53spi);
+
        master->transfer_one = bcm53xxspi_transfer_one;
+       if (b53spi->mmio_base)
+               master->spi_flash_read = bcm53xxspi_flash_read;
 
        bcma_set_drvdata(core, b53spi);
 
-       err = devm_spi_register_master(&core->dev, master);
+       err = devm_spi_register_master(dev, master);
        if (err) {
                spi_master_put(master);
                bcma_set_drvdata(core, NULL);
index 121a4135b5401b4dbe025f822c927d0f4d1b2947..1c57ce64abba029a209fca1caf5495f294c5fa85 100644 (file)
 #include <linux/of_irq.h>
 #include <linux/of_address.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/spi/spi.h>
 
 /* Name of this driver */
 #define CDNS_SPI_NAME          "cdns-spi"
 
 /* Register offset definitions */
-#define CDNS_SPI_CR_OFFSET     0x00 /* Configuration  Register, RW */
-#define CDNS_SPI_ISR_OFFSET    0x04 /* Interrupt Status Register, RO */
-#define CDNS_SPI_IER_OFFSET    0x08 /* Interrupt Enable Register, WO */
-#define CDNS_SPI_IDR_OFFSET    0x0c /* Interrupt Disable Register, WO */
-#define CDNS_SPI_IMR_OFFSET    0x10 /* Interrupt Enabled Mask Register, RO */
-#define CDNS_SPI_ER_OFFSET     0x14 /* Enable/Disable Register, RW */
-#define CDNS_SPI_DR_OFFSET     0x18 /* Delay Register, RW */
-#define CDNS_SPI_TXD_OFFSET    0x1C /* Data Transmit Register, WO */
-#define CDNS_SPI_RXD_OFFSET    0x20 /* Data Receive Register, RO */
-#define CDNS_SPI_SICR_OFFSET   0x24 /* Slave Idle Count Register, RW */
-#define CDNS_SPI_THLD_OFFSET   0x28 /* Transmit FIFO Watermark Register,RW */
-
+#define CDNS_SPI_CR    0x00 /* Configuration  Register, RW */
+#define CDNS_SPI_ISR   0x04 /* Interrupt Status Register, RO */
+#define CDNS_SPI_IER   0x08 /* Interrupt Enable Register, WO */
+#define CDNS_SPI_IDR   0x0c /* Interrupt Disable Register, WO */
+#define CDNS_SPI_IMR   0x10 /* Interrupt Enabled Mask Register, RO */
+#define CDNS_SPI_ER    0x14 /* Enable/Disable Register, RW */
+#define CDNS_SPI_DR    0x18 /* Delay Register, RW */
+#define CDNS_SPI_TXD   0x1C /* Data Transmit Register, WO */
+#define CDNS_SPI_RXD   0x20 /* Data Receive Register, RO */
+#define CDNS_SPI_SICR  0x24 /* Slave Idle Count Register, RW */
+#define CDNS_SPI_THLD  0x28 /* Transmit FIFO Watermark Register,RW */
+
+#define SPI_AUTOSUSPEND_TIMEOUT                3000
 /*
  * SPI Configuration Register bit Masks
  *
  * This register contains various control bits that affect the operation
  * of the SPI controller
  */
-#define CDNS_SPI_CR_MANSTRT_MASK       0x00010000 /* Manual TX Start */
-#define CDNS_SPI_CR_CPHA_MASK          0x00000004 /* Clock Phase Control */
-#define CDNS_SPI_CR_CPOL_MASK          0x00000002 /* Clock Polarity Control */
-#define CDNS_SPI_CR_SSCTRL_MASK                0x00003C00 /* Slave Select Mask */
-#define CDNS_SPI_CR_PERI_SEL_MASK      0x00000200 /* Peripheral Select Decode */
-#define CDNS_SPI_CR_BAUD_DIV_MASK      0x00000038 /* Baud Rate Divisor Mask */
-#define CDNS_SPI_CR_MSTREN_MASK                0x00000001 /* Master Enable Mask */
-#define CDNS_SPI_CR_MANSTRTEN_MASK     0x00008000 /* Manual TX Enable Mask */
-#define CDNS_SPI_CR_SSFORCE_MASK       0x00004000 /* Manual SS Enable Mask */
-#define CDNS_SPI_CR_BAUD_DIV_4_MASK    0x00000008 /* Default Baud Div Mask */
-#define CDNS_SPI_CR_DEFAULT_MASK       (CDNS_SPI_CR_MSTREN_MASK | \
-                                       CDNS_SPI_CR_SSCTRL_MASK | \
-                                       CDNS_SPI_CR_SSFORCE_MASK | \
-                                       CDNS_SPI_CR_BAUD_DIV_4_MASK)
+#define CDNS_SPI_CR_MANSTRT    0x00010000 /* Manual TX Start */
+#define CDNS_SPI_CR_CPHA               0x00000004 /* Clock Phase Control */
+#define CDNS_SPI_CR_CPOL               0x00000002 /* Clock Polarity Control */
+#define CDNS_SPI_CR_SSCTRL             0x00003C00 /* Slave Select Mask */
+#define CDNS_SPI_CR_PERI_SEL   0x00000200 /* Peripheral Select Decode */
+#define CDNS_SPI_CR_BAUD_DIV   0x00000038 /* Baud Rate Divisor Mask */
+#define CDNS_SPI_CR_MSTREN             0x00000001 /* Master Enable Mask */
+#define CDNS_SPI_CR_MANSTRTEN  0x00008000 /* Manual TX Enable Mask */
+#define CDNS_SPI_CR_SSFORCE    0x00004000 /* Manual SS Enable Mask */
+#define CDNS_SPI_CR_BAUD_DIV_4 0x00000008 /* Default Baud Div Mask */
+#define CDNS_SPI_CR_DEFAULT    (CDNS_SPI_CR_MSTREN | \
+                                       CDNS_SPI_CR_SSCTRL | \
+                                       CDNS_SPI_CR_SSFORCE | \
+                                       CDNS_SPI_CR_BAUD_DIV_4)
 
 /*
  * SPI Configuration Register - Baud rate and slave select
  * All the four interrupt registers (Status/Mask/Enable/Disable) have the same
  * bit definitions.
  */
-#define CDNS_SPI_IXR_TXOW_MASK 0x00000004 /* SPI TX FIFO Overwater */
-#define CDNS_SPI_IXR_MODF_MASK 0x00000002 /* SPI Mode Fault */
-#define CDNS_SPI_IXR_RXNEMTY_MASK 0x00000010 /* SPI RX FIFO Not Empty */
-#define CDNS_SPI_IXR_DEFAULT_MASK      (CDNS_SPI_IXR_TXOW_MASK | \
-                                       CDNS_SPI_IXR_MODF_MASK)
-#define CDNS_SPI_IXR_TXFULL_MASK       0x00000008 /* SPI TX Full */
-#define CDNS_SPI_IXR_ALL_MASK  0x0000007F /* SPI all interrupts */
+#define CDNS_SPI_IXR_TXOW      0x00000004 /* SPI TX FIFO Overwater */
+#define CDNS_SPI_IXR_MODF      0x00000002 /* SPI Mode Fault */
+#define CDNS_SPI_IXR_RXNEMTY 0x00000010 /* SPI RX FIFO Not Empty */
+#define CDNS_SPI_IXR_DEFAULT   (CDNS_SPI_IXR_TXOW | \
+                                       CDNS_SPI_IXR_MODF)
+#define CDNS_SPI_IXR_TXFULL    0x00000008 /* SPI TX Full */
+#define CDNS_SPI_IXR_ALL       0x0000007F /* SPI all interrupts */
 
 /*
  * SPI Enable Register bit Masks
  *
  * This register is used to enable or disable the SPI controller
  */
-#define CDNS_SPI_ER_ENABLE_MASK        0x00000001 /* SPI Enable Bit Mask */
-#define CDNS_SPI_ER_DISABLE_MASK       0x0 /* SPI Disable Bit Mask */
+#define CDNS_SPI_ER_ENABLE     0x00000001 /* SPI Enable Bit Mask */
+#define CDNS_SPI_ER_DISABLE    0x0 /* SPI Disable Bit Mask */
 
 /* SPI FIFO depth in bytes */
 #define CDNS_SPI_FIFO_DEPTH    128
@@ -149,56 +151,51 @@ static inline void cdns_spi_write(struct cdns_spi *xspi, u32 offset, u32 val)
  */
 static void cdns_spi_init_hw(struct cdns_spi *xspi)
 {
-       u32 ctrl_reg = CDNS_SPI_CR_DEFAULT_MASK;
+       u32 ctrl_reg = CDNS_SPI_CR_DEFAULT;
 
        if (xspi->is_decoded_cs)
-               ctrl_reg |= CDNS_SPI_CR_PERI_SEL_MASK;
+               ctrl_reg |= CDNS_SPI_CR_PERI_SEL;
 
-       cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                      CDNS_SPI_ER_DISABLE_MASK);
-       cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET,
-                      CDNS_SPI_IXR_ALL_MASK);
+       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
+       cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_ALL);
 
        /* Clear the RX FIFO */
-       while (cdns_spi_read(xspi, CDNS_SPI_ISR_OFFSET) &
-              CDNS_SPI_IXR_RXNEMTY_MASK)
-               cdns_spi_read(xspi, CDNS_SPI_RXD_OFFSET);
-
-       cdns_spi_write(xspi, CDNS_SPI_ISR_OFFSET,
-                      CDNS_SPI_IXR_ALL_MASK);
-       cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg);
-       cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                      CDNS_SPI_ER_ENABLE_MASK);
+       while (cdns_spi_read(xspi, CDNS_SPI_ISR) & CDNS_SPI_IXR_RXNEMTY)
+               cdns_spi_read(xspi, CDNS_SPI_RXD);
+
+       cdns_spi_write(xspi, CDNS_SPI_ISR, CDNS_SPI_IXR_ALL);
+       cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg);
+       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE);
 }
 
 /**
  * cdns_spi_chipselect - Select or deselect the chip select line
  * @spi:       Pointer to the spi_device structure
- * @is_on:     Select(0) or deselect (1) the chip select line
+ * @is_high:   Select(0) or deselect (1) the chip select line
  */
 static void cdns_spi_chipselect(struct spi_device *spi, bool is_high)
 {
        struct cdns_spi *xspi = spi_master_get_devdata(spi->master);
        u32 ctrl_reg;
 
-       ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET);
+       ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
 
        if (is_high) {
                /* Deselect the slave */
-               ctrl_reg |= CDNS_SPI_CR_SSCTRL_MASK;
+               ctrl_reg |= CDNS_SPI_CR_SSCTRL;
        } else {
                /* Select the slave */
-               ctrl_reg &= ~CDNS_SPI_CR_SSCTRL_MASK;
+               ctrl_reg &= ~CDNS_SPI_CR_SSCTRL;
                if (!(xspi->is_decoded_cs))
                        ctrl_reg |= ((~(CDNS_SPI_SS0 << spi->chip_select)) <<
                                     CDNS_SPI_SS_SHIFT) &
-                                    CDNS_SPI_CR_SSCTRL_MASK;
+                                    CDNS_SPI_CR_SSCTRL;
                else
                        ctrl_reg |= (spi->chip_select << CDNS_SPI_SS_SHIFT) &
-                                    CDNS_SPI_CR_SSCTRL_MASK;
+                                    CDNS_SPI_CR_SSCTRL;
        }
 
-       cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg);
+       cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg);
 }
 
 /**
@@ -212,14 +209,15 @@ static void cdns_spi_config_clock_mode(struct spi_device *spi)
        struct cdns_spi *xspi = spi_master_get_devdata(spi->master);
        u32 ctrl_reg, new_ctrl_reg;
 
-       new_ctrl_reg = ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET);
+       new_ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
+       ctrl_reg = new_ctrl_reg;
 
        /* Set the SPI clock phase and clock polarity */
-       new_ctrl_reg &= ~(CDNS_SPI_CR_CPHA_MASK | CDNS_SPI_CR_CPOL_MASK);
+       new_ctrl_reg &= ~(CDNS_SPI_CR_CPHA | CDNS_SPI_CR_CPOL);
        if (spi->mode & SPI_CPHA)
-               new_ctrl_reg |= CDNS_SPI_CR_CPHA_MASK;
+               new_ctrl_reg |= CDNS_SPI_CR_CPHA;
        if (spi->mode & SPI_CPOL)
-               new_ctrl_reg |= CDNS_SPI_CR_CPOL_MASK;
+               new_ctrl_reg |= CDNS_SPI_CR_CPOL;
 
        if (new_ctrl_reg != ctrl_reg) {
                /*
@@ -228,11 +226,9 @@ static void cdns_spi_config_clock_mode(struct spi_device *spi)
                 * polarity as it will cause the SPI slave to see spurious clock
                 * transitions. To workaround the issue toggle the ER register.
                 */
-               cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                                  CDNS_SPI_ER_DISABLE_MASK);
-               cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, new_ctrl_reg);
-               cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                                  CDNS_SPI_ER_ENABLE_MASK);
+               cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
+               cdns_spi_write(xspi, CDNS_SPI_CR, new_ctrl_reg);
+               cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE);
        }
 }
 
@@ -251,7 +247,7 @@ static void cdns_spi_config_clock_mode(struct spi_device *spi)
  * controller.
  */
 static void cdns_spi_config_clock_freq(struct spi_device *spi,
-                                 struct spi_transfer *transfer)
+                                      struct spi_transfer *transfer)
 {
        struct cdns_spi *xspi = spi_master_get_devdata(spi->master);
        u32 ctrl_reg, baud_rate_val;
@@ -259,7 +255,7 @@ static void cdns_spi_config_clock_freq(struct spi_device *spi,
 
        frequency = clk_get_rate(xspi->ref_clk);
 
-       ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR_OFFSET);
+       ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
 
        /* Set the clock frequency */
        if (xspi->speed_hz != transfer->speed_hz) {
@@ -269,12 +265,12 @@ static void cdns_spi_config_clock_freq(struct spi_device *spi,
                       (frequency / (2 << baud_rate_val)) > transfer->speed_hz)
                        baud_rate_val++;
 
-               ctrl_reg &= ~CDNS_SPI_CR_BAUD_DIV_MASK;
+               ctrl_reg &= ~CDNS_SPI_CR_BAUD_DIV;
                ctrl_reg |= baud_rate_val << CDNS_SPI_BAUD_DIV_SHIFT;
 
                xspi->speed_hz = frequency / (2 << baud_rate_val);
        }
-       cdns_spi_write(xspi, CDNS_SPI_CR_OFFSET, ctrl_reg);
+       cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg);
 }
 
 /**
@@ -313,10 +309,9 @@ static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi)
        while ((trans_cnt < CDNS_SPI_FIFO_DEPTH) &&
               (xspi->tx_bytes > 0)) {
                if (xspi->txbuf)
-                       cdns_spi_write(xspi, CDNS_SPI_TXD_OFFSET,
-                                      *xspi->txbuf++);
+                       cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++);
                else
-                       cdns_spi_write(xspi, CDNS_SPI_TXD_OFFSET, 0);
+                       cdns_spi_write(xspi, CDNS_SPI_TXD, 0);
 
                xspi->tx_bytes--;
                trans_cnt++;
@@ -344,19 +339,18 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
        u32 intr_status, status;
 
        status = IRQ_NONE;
-       intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR_OFFSET);
-       cdns_spi_write(xspi, CDNS_SPI_ISR_OFFSET, intr_status);
+       intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR);
+       cdns_spi_write(xspi, CDNS_SPI_ISR, intr_status);
 
-       if (intr_status & CDNS_SPI_IXR_MODF_MASK) {
+       if (intr_status & CDNS_SPI_IXR_MODF) {
                /* Indicate that transfer is completed, the SPI subsystem will
                 * identify the error as the remaining bytes to be
                 * transferred is non-zero
                 */
-               cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET,
-                              CDNS_SPI_IXR_DEFAULT_MASK);
+               cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT);
                spi_finalize_current_transfer(master);
                status = IRQ_HANDLED;
-       } else if (intr_status & CDNS_SPI_IXR_TXOW_MASK) {
+       } else if (intr_status & CDNS_SPI_IXR_TXOW) {
                unsigned long trans_cnt;
 
                trans_cnt = xspi->rx_bytes - xspi->tx_bytes;
@@ -365,7 +359,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
                while (trans_cnt) {
                        u8 data;
 
-                       data = cdns_spi_read(xspi, CDNS_SPI_RXD_OFFSET);
+                       data = cdns_spi_read(xspi, CDNS_SPI_RXD);
                        if (xspi->rxbuf)
                                *xspi->rxbuf++ = data;
 
@@ -378,8 +372,8 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
                        cdns_spi_fill_tx_fifo(xspi);
                } else {
                        /* Transfer is completed */
-                       cdns_spi_write(xspi, CDNS_SPI_IDR_OFFSET,
-                                      CDNS_SPI_IXR_DEFAULT_MASK);
+                       cdns_spi_write(xspi, CDNS_SPI_IDR,
+                                      CDNS_SPI_IXR_DEFAULT);
                        spi_finalize_current_transfer(master);
                }
                status = IRQ_HANDLED;
@@ -387,6 +381,7 @@ static irqreturn_t cdns_spi_irq(int irq, void *dev_id)
 
        return status;
 }
+
 static int cdns_prepare_message(struct spi_master *master,
                                struct spi_message *msg)
 {
@@ -421,8 +416,7 @@ static int cdns_transfer_one(struct spi_master *master,
 
        cdns_spi_fill_tx_fifo(xspi);
 
-       cdns_spi_write(xspi, CDNS_SPI_IER_OFFSET,
-                      CDNS_SPI_IXR_DEFAULT_MASK);
+       cdns_spi_write(xspi, CDNS_SPI_IER, CDNS_SPI_IXR_DEFAULT);
        return transfer->len;
 }
 
@@ -439,8 +433,7 @@ static int cdns_prepare_transfer_hardware(struct spi_master *master)
 {
        struct cdns_spi *xspi = spi_master_get_devdata(master);
 
-       cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                      CDNS_SPI_ER_ENABLE_MASK);
+       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE);
 
        return 0;
 }
@@ -458,8 +451,7 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master)
 {
        struct cdns_spi *xspi = spi_master_get_devdata(master);
 
-       cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                      CDNS_SPI_ER_DISABLE_MASK);
+       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
        return 0;
 }
@@ -481,7 +473,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
        u32 num_cs;
 
        master = spi_alloc_master(&pdev->dev, sizeof(*xspi));
-       if (master == NULL)
+       if (!master)
                return -ENOMEM;
 
        xspi = spi_master_get_devdata(master);
@@ -521,6 +513,11 @@ static int cdns_spi_probe(struct platform_device *pdev)
                goto clk_dis_apb;
        }
 
+       pm_runtime_enable(&pdev->dev);
+       pm_runtime_use_autosuspend(&pdev->dev);
+       pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
+       pm_runtime_set_active(&pdev->dev);
+
        ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
        if (ret < 0)
                master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS;
@@ -535,11 +532,14 @@ static int cdns_spi_probe(struct platform_device *pdev)
        /* SPI controller initializations */
        cdns_spi_init_hw(xspi);
 
+       pm_runtime_mark_last_busy(&pdev->dev);
+       pm_runtime_put_autosuspend(&pdev->dev);
+
        irq = platform_get_irq(pdev, 0);
        if (irq <= 0) {
                ret = -ENXIO;
                dev_err(&pdev->dev, "irq number is invalid\n");
-               goto remove_master;
+               goto clk_dis_all;
        }
 
        ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq,
@@ -547,7 +547,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
        if (ret != 0) {
                ret = -ENXIO;
                dev_err(&pdev->dev, "request_irq failed\n");
-               goto remove_master;
+               goto clk_dis_all;
        }
 
        master->prepare_transfer_hardware = cdns_prepare_transfer_hardware;
@@ -555,6 +555,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
        master->transfer_one = cdns_transfer_one;
        master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware;
        master->set_cs = cdns_spi_chipselect;
+       master->auto_runtime_pm = true;
        master->mode_bits = SPI_CPOL | SPI_CPHA;
 
        /* Set to default valid value */
@@ -572,6 +573,8 @@ static int cdns_spi_probe(struct platform_device *pdev)
        return ret;
 
 clk_dis_all:
+       pm_runtime_set_suspended(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
        clk_disable_unprepare(xspi->ref_clk);
 clk_dis_apb:
        clk_disable_unprepare(xspi->pclk);
@@ -595,11 +598,12 @@ static int cdns_spi_remove(struct platform_device *pdev)
        struct spi_master *master = platform_get_drvdata(pdev);
        struct cdns_spi *xspi = spi_master_get_devdata(master);
 
-       cdns_spi_write(xspi, CDNS_SPI_ER_OFFSET,
-                      CDNS_SPI_ER_DISABLE_MASK);
+       cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
        clk_disable_unprepare(xspi->ref_clk);
        clk_disable_unprepare(xspi->pclk);
+       pm_runtime_set_suspended(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
 
        spi_unregister_master(master);
 
@@ -613,21 +617,14 @@ static int cdns_spi_remove(struct platform_device *pdev)
  * This function disables the SPI controller and
  * changes the driver state to "suspend"
  *
- * Return:     Always 0
+ * Return:     0 on success and error value on error
  */
 static int __maybe_unused cdns_spi_suspend(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct spi_master *master = platform_get_drvdata(pdev);
-       struct cdns_spi *xspi = spi_master_get_devdata(master);
-
-       spi_master_suspend(master);
-
-       clk_disable_unprepare(xspi->ref_clk);
-
-       clk_disable_unprepare(xspi->pclk);
 
-       return 0;
+       return spi_master_suspend(master);
 }
 
 /**
@@ -642,8 +639,23 @@ static int __maybe_unused cdns_spi_resume(struct device *dev)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct spi_master *master = platform_get_drvdata(pdev);
+
+       return spi_master_resume(master);
+}
+
+/**
+ * cdns_spi_runtime_resume - Runtime resume method for the SPI driver
+ * @dev:       Address of the platform_device structure
+ *
+ * This function enables the clocks
+ *
+ * Return:     0 on success and error value on error
+ */
+static int __maybe_unused cnds_runtime_resume(struct device *dev)
+{
+       struct spi_master *master = dev_get_drvdata(dev);
        struct cdns_spi *xspi = spi_master_get_devdata(master);
-       int ret = 0;
+       int ret;
 
        ret = clk_prepare_enable(xspi->pclk);
        if (ret) {
@@ -657,13 +669,33 @@ static int __maybe_unused cdns_spi_resume(struct device *dev)
                clk_disable(xspi->pclk);
                return ret;
        }
-       spi_master_resume(master);
+       return 0;
+}
+
+/**
+ * cdns_spi_runtime_suspend - Runtime suspend method for the SPI driver
+ * @dev:       Address of the platform_device structure
+ *
+ * This function disables the clocks
+ *
+ * Return:     Always 0
+ */
+static int __maybe_unused cnds_runtime_suspend(struct device *dev)
+{
+       struct spi_master *master = dev_get_drvdata(dev);
+       struct cdns_spi *xspi = spi_master_get_devdata(master);
+
+       clk_disable_unprepare(xspi->ref_clk);
+       clk_disable_unprepare(xspi->pclk);
 
        return 0;
 }
 
-static SIMPLE_DEV_PM_OPS(cdns_spi_dev_pm_ops, cdns_spi_suspend,
-                        cdns_spi_resume);
+static const struct dev_pm_ops cdns_spi_dev_pm_ops = {
+       SET_RUNTIME_PM_OPS(cnds_runtime_suspend,
+                          cnds_runtime_resume, NULL)
+       SET_SYSTEM_SLEEP_PM_OPS(cdns_spi_suspend, cdns_spi_resume)
+};
 
 static const struct of_device_id cdns_spi_of_match[] = {
        { .compatible = "xlnx,zynq-spi-r1p6" },
index fddb7a3be322be41041013282624fd866a573400..d36c11b73a35ca656ab04e9c5ef0492f96950b32 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/clk.h>
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
-#include <linux/edma.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_gpio.h>
@@ -33,8 +32,6 @@
 
 #include <linux/platform_data/spi-davinci.h>
 
-#define SPI_NO_RESOURCE                ((resource_size_t)-1)
-
 #define CS_DEFAULT     0xFF
 
 #define SPIFMT_PHASE_MASK      BIT(16)
@@ -130,8 +127,6 @@ struct davinci_spi {
 
        struct dma_chan         *dma_rx;
        struct dma_chan         *dma_tx;
-       int                     dma_rx_chnum;
-       int                     dma_tx_chnum;
 
        struct davinci_spi_platform_data pdata;
 
@@ -797,35 +792,19 @@ static irqreturn_t davinci_spi_irq(s32 irq, void *data)
 
 static int davinci_spi_request_dma(struct davinci_spi *dspi)
 {
-       dma_cap_mask_t mask;
        struct device *sdev = dspi->bitbang.master->dev.parent;
-       int r;
-
-       dma_cap_zero(mask);
-       dma_cap_set(DMA_SLAVE, mask);
 
-       dspi->dma_rx = dma_request_channel(mask, edma_filter_fn,
-                                          &dspi->dma_rx_chnum);
-       if (!dspi->dma_rx) {
-               dev_err(sdev, "request RX DMA channel failed\n");
-               r = -ENODEV;
-               goto rx_dma_failed;
-       }
+       dspi->dma_rx = dma_request_chan(sdev, "rx");
+       if (IS_ERR(dspi->dma_rx))
+               return PTR_ERR(dspi->dma_rx);
 
-       dspi->dma_tx = dma_request_channel(mask, edma_filter_fn,
-                                          &dspi->dma_tx_chnum);
-       if (!dspi->dma_tx) {
-               dev_err(sdev, "request TX DMA channel failed\n");
-               r = -ENODEV;
-               goto tx_dma_failed;
+       dspi->dma_tx = dma_request_chan(sdev, "tx");
+       if (IS_ERR(dspi->dma_tx)) {
+               dma_release_channel(dspi->dma_rx);
+               return PTR_ERR(dspi->dma_tx);
        }
 
        return 0;
-
-tx_dma_failed:
-       dma_release_channel(dspi->dma_rx);
-rx_dma_failed:
-       return r;
 }
 
 #if defined(CONFIG_OF)
@@ -936,8 +915,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
        struct davinci_spi *dspi;
        struct davinci_spi_platform_data *pdata;
        struct resource *r;
-       resource_size_t dma_rx_chan = SPI_NO_RESOURCE;
-       resource_size_t dma_tx_chan = SPI_NO_RESOURCE;
        int ret = 0;
        u32 spipc0;
 
@@ -1044,27 +1021,15 @@ static int davinci_spi_probe(struct platform_device *pdev)
                }
        }
 
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-       if (r)
-               dma_rx_chan = r->start;
-       r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-       if (r)
-               dma_tx_chan = r->start;
-
        dspi->bitbang.txrx_bufs = davinci_spi_bufs;
-       if (dma_rx_chan != SPI_NO_RESOURCE &&
-           dma_tx_chan != SPI_NO_RESOURCE) {
-               dspi->dma_rx_chnum = dma_rx_chan;
-               dspi->dma_tx_chnum = dma_tx_chan;
-
-               ret = davinci_spi_request_dma(dspi);
-               if (ret)
-                       goto free_clk;
-
-               dev_info(&pdev->dev, "DMA: supported\n");
-               dev_info(&pdev->dev, "DMA: RX channel: %pa, TX channel: %pa, event queue: %d\n",
-                               &dma_rx_chan, &dma_tx_chan,
-                               pdata->dma_event_q);
+
+       ret = davinci_spi_request_dma(dspi);
+       if (ret == -EPROBE_DEFER) {
+               goto free_clk;
+       } else if (ret) {
+               dev_info(&pdev->dev, "DMA is not supported (%d)\n", ret);
+               dspi->dma_rx = NULL;
+               dspi->dma_tx = NULL;
        }
 
        dspi->get_rx = davinci_spi_rx_buf_u8;
@@ -1102,8 +1067,10 @@ static int davinci_spi_probe(struct platform_device *pdev)
        return ret;
 
 free_dma:
-       dma_release_channel(dspi->dma_rx);
-       dma_release_channel(dspi->dma_tx);
+       if (dspi->dma_rx) {
+               dma_release_channel(dspi->dma_rx);
+               dma_release_channel(dspi->dma_tx);
+       }
 free_clk:
        clk_disable_unprepare(dspi->clk);
 free_master:
@@ -1134,6 +1101,11 @@ static int davinci_spi_remove(struct platform_device *pdev)
        clk_disable_unprepare(dspi->clk);
        spi_master_put(master);
 
+       if (dspi->dma_rx) {
+               dma_release_channel(dspi->dma_rx);
+               dma_release_channel(dspi->dma_tx);
+       }
+
        return 0;
 }
 
index 3b7d91d94feace23ea2b0c9070a5d22a77aa9685..b62a99caacc0648ff24a116417f220ccb1a63b45 100644 (file)
@@ -683,6 +683,7 @@ static int dln2_spi_probe(struct platform_device *pdev)
        struct spi_master *master;
        struct dln2_spi *dln2;
        struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev);
+       struct device *dev = &pdev->dev;
        int ret;
 
        master = spi_alloc_master(&pdev->dev, sizeof(*dln2));
@@ -700,6 +701,7 @@ static int dln2_spi_probe(struct platform_device *pdev)
        }
 
        dln2->master = master;
+       dln2->master->dev.of_node = dev->of_node;
        dln2->pdev = pdev;
        dln2->port = pdata->port;
        /* cs/mode can never be 0xff, so the first transfer will set them */
index 332ccb0539a77710e3c4783cf2468acd25a8c04f..ef7db75c92c13b34af62dd6c0377d3aa16bfcabd 100644 (file)
@@ -67,7 +67,7 @@ static int spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        dws->irq = pdev->irq;
 
        /*
-        * Specific handling for paltforms, like dma setup,
+        * Specific handling for platforms, like dma setup,
         * clock rate, FIFO depth.
         */
        if (desc) {
index c1a2d747b24686cb835541c68bb2f20f2304d009..9e9dadb52b3db0bea2f1d23eee12c3479e0dc925 100644 (file)
@@ -121,18 +121,22 @@ enum dspi_trans_mode {
 
 struct fsl_dspi_devtype_data {
        enum dspi_trans_mode trans_mode;
+       u8 max_clock_factor;
 };
 
 static const struct fsl_dspi_devtype_data vf610_data = {
        .trans_mode = DSPI_EOQ_MODE,
+       .max_clock_factor = 2,
 };
 
 static const struct fsl_dspi_devtype_data ls1021a_v1_data = {
        .trans_mode = DSPI_TCFQ_MODE,
+       .max_clock_factor = 8,
 };
 
 static const struct fsl_dspi_devtype_data ls2085a_data = {
        .trans_mode = DSPI_TCFQ_MODE,
+       .max_clock_factor = 8,
 };
 
 struct fsl_dspi {
@@ -726,6 +730,9 @@ static int dspi_probe(struct platform_device *pdev)
        }
        clk_prepare_enable(dspi->clk);
 
+       master->max_speed_hz =
+               clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor;
+
        init_waitqueue_head(&dspi->waitq);
        platform_set_drvdata(pdev, master);
 
index 7cb0c1921495959dcb6c919c3cb9f1811a5e90bb..8d85a3c343dab635811cf4b6a871a841977fa09f 100644 (file)
@@ -245,7 +245,12 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
        if (ret)
                return ret;
 
-       wait_for_completion(&mpc8xxx_spi->done);
+       /* Won't hang up forever, SPI bus sometimes got lost interrupts... */
+       ret = wait_for_completion_timeout(&mpc8xxx_spi->done, 2 * HZ);
+       if (ret == 0)
+               dev_err(mpc8xxx_spi->dev,
+                       "Transaction hanging up (left %d bytes)\n",
+                       mpc8xxx_spi->count);
 
        /* disable rx ints */
        mpc8xxx_spi_write_reg(&reg_base->mask, 0);
@@ -539,16 +544,31 @@ void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
        if (events & SPIE_NE) {
                u32 rx_data, tmp;
                u8 rx_data_8;
+               int rx_nr_bytes = 4;
+               int ret;
 
                /* Spin until RX is done */
-               while (SPIE_RXCNT(events) < min(4, mspi->len)) {
-                       cpu_relax();
-                       events = mpc8xxx_spi_read_reg(&reg_base->event);
+               if (SPIE_RXCNT(events) < min(4, mspi->len)) {
+                       ret = spin_event_timeout(
+                               !(SPIE_RXCNT(events =
+                               mpc8xxx_spi_read_reg(&reg_base->event)) <
+                                               min(4, mspi->len)),
+                                               10000, 0); /* 10 msec */
+                       if (!ret)
+                               dev_err(mspi->dev,
+                                        "tired waiting for SPIE_RXCNT\n");
                }
 
                if (mspi->len >= 4) {
                        rx_data = mpc8xxx_spi_read_reg(&reg_base->receive);
+               } else if (mspi->len <= 0) {
+                       dev_err(mspi->dev,
+                               "unexpected RX(SPIE_NE) interrupt occurred,\n"
+                               "(local rxlen %d bytes, reg rxlen %d bytes)\n",
+                               min(4, mspi->len), SPIE_RXCNT(events));
+                       rx_nr_bytes = 0;
                } else {
+                       rx_nr_bytes = mspi->len;
                        tmp = mspi->len;
                        rx_data = 0;
                        while (tmp--) {
@@ -559,7 +579,7 @@ void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
                        rx_data <<= (4 - mspi->len) * 8;
                }
 
-               mspi->len -= 4;
+               mspi->len -= rx_nr_bytes;
 
                if (mspi->rx)
                        mspi->get_rx(rx_data, mspi);
index 07e4ce8273df56533aee2e8adf563c6026a956c0..3b170093989fcc35cf312a842fa095038d0c649d 100644 (file)
@@ -175,6 +175,7 @@ err:
 static int octeon_spi_probe(struct platform_device *pdev)
 {
        struct resource *res_mem;
+       void __iomem *reg_base;
        struct spi_master *master;
        struct octeon_spi *p;
        int err = -ENOENT;
@@ -186,19 +187,13 @@ static int octeon_spi_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, master);
 
        res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-
-       if (res_mem == NULL) {
-               dev_err(&pdev->dev, "found no memory resource\n");
-               err = -ENXIO;
-               goto fail;
-       }
-       if (!devm_request_mem_region(&pdev->dev, res_mem->start,
-                                    resource_size(res_mem), res_mem->name)) {
-               dev_err(&pdev->dev, "request_mem_region failed\n");
+       reg_base = devm_ioremap_resource(&pdev->dev, res_mem);
+       if (IS_ERR(reg_base)) {
+               err = PTR_ERR(reg_base);
                goto fail;
        }
-       p->register_base = (u64)devm_ioremap(&pdev->dev, res_mem->start,
-                                            resource_size(res_mem));
+
+       p->register_base = (u64)reg_base;
 
        master->num_chipselect = 4;
        master->mode_bits = SPI_CPHA |
index 0caa3c8bef46c46e0ed66bf89f518cc5c5236449..1d237e93a2895c3f05ecca846df0d1c1db99ba5a 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/delay.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
-#include <linux/omap-dma.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/err.h>
@@ -103,9 +102,6 @@ struct omap2_mcspi_dma {
        struct dma_chan *dma_tx;
        struct dma_chan *dma_rx;
 
-       int dma_tx_sync_dev;
-       int dma_rx_sync_dev;
-
        struct completion dma_tx_completion;
        struct completion dma_rx_completion;
 
@@ -964,8 +960,7 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
        struct spi_master       *master = spi->master;
        struct omap2_mcspi      *mcspi;
        struct omap2_mcspi_dma  *mcspi_dma;
-       dma_cap_mask_t mask;
-       unsigned sig;
+       int ret = 0;
 
        mcspi = spi_master_get_devdata(master);
        mcspi_dma = mcspi->dma_channels + spi->chip_select;
@@ -973,34 +968,25 @@ static int omap2_mcspi_request_dma(struct spi_device *spi)
        init_completion(&mcspi_dma->dma_rx_completion);
        init_completion(&mcspi_dma->dma_tx_completion);
 
-       dma_cap_zero(mask);
-       dma_cap_set(DMA_SLAVE, mask);
-       sig = mcspi_dma->dma_rx_sync_dev;
-
-       mcspi_dma->dma_rx =
-               dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
-                                                &sig, &master->dev,
-                                                mcspi_dma->dma_rx_ch_name);
-       if (!mcspi_dma->dma_rx)
+       mcspi_dma->dma_rx = dma_request_chan(&master->dev,
+                                            mcspi_dma->dma_rx_ch_name);
+       if (IS_ERR(mcspi_dma->dma_rx)) {
+               ret = PTR_ERR(mcspi_dma->dma_rx);
+               mcspi_dma->dma_rx = NULL;
                goto no_dma;
+       }
 
-       sig = mcspi_dma->dma_tx_sync_dev;
-       mcspi_dma->dma_tx =
-               dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
-                                                &sig, &master->dev,
-                                                mcspi_dma->dma_tx_ch_name);
-
-       if (!mcspi_dma->dma_tx) {
+       mcspi_dma->dma_tx = dma_request_chan(&master->dev,
+                                            mcspi_dma->dma_tx_ch_name);
+       if (IS_ERR(mcspi_dma->dma_tx)) {
+               ret = PTR_ERR(mcspi_dma->dma_tx);
+               mcspi_dma->dma_tx = NULL;
                dma_release_channel(mcspi_dma->dma_rx);
                mcspi_dma->dma_rx = NULL;
-               goto no_dma;
        }
 
-       return 0;
-
 no_dma:
-       dev_warn(&spi->dev, "not using DMA for McSPI\n");
-       return -EAGAIN;
+       return ret;
 }
 
 static int omap2_mcspi_setup(struct spi_device *spi)
@@ -1039,8 +1025,9 @@ static int omap2_mcspi_setup(struct spi_device *spi)
 
        if (!mcspi_dma->dma_rx || !mcspi_dma->dma_tx) {
                ret = omap2_mcspi_request_dma(spi);
-               if (ret < 0 && ret != -EAGAIN)
-                       return ret;
+               if (ret)
+                       dev_warn(&spi->dev, "not using DMA for McSPI (%d)\n",
+                                ret);
        }
 
        ret = pm_runtime_get_sync(mcspi->dev);
@@ -1434,42 +1421,8 @@ static int omap2_mcspi_probe(struct platform_device *pdev)
        }
 
        for (i = 0; i < master->num_chipselect; i++) {
-               char *dma_rx_ch_name = mcspi->dma_channels[i].dma_rx_ch_name;
-               char *dma_tx_ch_name = mcspi->dma_channels[i].dma_tx_ch_name;
-               struct resource *dma_res;
-
-               sprintf(dma_rx_ch_name, "rx%d", i);
-               if (!pdev->dev.of_node) {
-                       dma_res =
-                               platform_get_resource_byname(pdev,
-                                                            IORESOURCE_DMA,
-                                                            dma_rx_ch_name);
-                       if (!dma_res) {
-                               dev_dbg(&pdev->dev,
-                                       "cannot get DMA RX channel\n");
-                               status = -ENODEV;
-                               break;
-                       }
-
-                       mcspi->dma_channels[i].dma_rx_sync_dev =
-                               dma_res->start;
-               }
-               sprintf(dma_tx_ch_name, "tx%d", i);
-               if (!pdev->dev.of_node) {
-                       dma_res =
-                               platform_get_resource_byname(pdev,
-                                                            IORESOURCE_DMA,
-                                                            dma_tx_ch_name);
-                       if (!dma_res) {
-                               dev_dbg(&pdev->dev,
-                                       "cannot get DMA TX channel\n");
-                               status = -ENODEV;
-                               break;
-                       }
-
-                       mcspi->dma_channels[i].dma_tx_sync_dev =
-                               dma_res->start;
-               }
+               sprintf(mcspi->dma_channels[i].dma_rx_ch_name, "rx%d", i);
+               sprintf(mcspi->dma_channels[i].dma_tx_ch_name, "tx%d", i);
        }
 
        if (status < 0)
diff --git a/drivers/spi/spi-pic32-sqi.c b/drivers/spi/spi-pic32-sqi.c
new file mode 100644 (file)
index 0000000..ca3c8d9
--- /dev/null
@@ -0,0 +1,727 @@
+/*
+ * PIC32 Quad SPI controller driver.
+ *
+ * Purna Chandra Mandal <purna.mandal@microchip.com>
+ * Copyright (c) 2016, Microchip Technology Inc.
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/spi/spi.h>
+
+/* SQI registers */
+#define PESQI_XIP_CONF1_REG    0x00
+#define PESQI_XIP_CONF2_REG    0x04
+#define PESQI_CONF_REG         0x08
+#define PESQI_CTRL_REG         0x0C
+#define PESQI_CLK_CTRL_REG     0x10
+#define PESQI_CMD_THRES_REG    0x14
+#define PESQI_INT_THRES_REG    0x18
+#define PESQI_INT_ENABLE_REG   0x1C
+#define PESQI_INT_STAT_REG     0x20
+#define PESQI_TX_DATA_REG      0x24
+#define PESQI_RX_DATA_REG      0x28
+#define PESQI_STAT1_REG                0x2C
+#define PESQI_STAT2_REG                0x30
+#define PESQI_BD_CTRL_REG      0x34
+#define PESQI_BD_CUR_ADDR_REG  0x38
+#define PESQI_BD_BASE_ADDR_REG 0x40
+#define PESQI_BD_STAT_REG      0x44
+#define PESQI_BD_POLL_CTRL_REG 0x48
+#define PESQI_BD_TX_DMA_STAT_REG       0x4C
+#define PESQI_BD_RX_DMA_STAT_REG       0x50
+#define PESQI_THRES_REG                0x54
+#define PESQI_INT_SIGEN_REG    0x58
+
+/* PESQI_CONF_REG fields */
+#define PESQI_MODE             0x7
+#define  PESQI_MODE_BOOT       0
+#define  PESQI_MODE_PIO                1
+#define  PESQI_MODE_DMA                2
+#define  PESQI_MODE_XIP                3
+#define PESQI_MODE_SHIFT       0
+#define PESQI_CPHA             BIT(3)
+#define PESQI_CPOL             BIT(4)
+#define PESQI_LSBF             BIT(5)
+#define PESQI_RXLATCH          BIT(7)
+#define PESQI_SERMODE          BIT(8)
+#define PESQI_WP_EN            BIT(9)
+#define PESQI_HOLD_EN          BIT(10)
+#define PESQI_BURST_EN         BIT(12)
+#define PESQI_CS_CTRL_HW       BIT(15)
+#define PESQI_SOFT_RESET       BIT(16)
+#define PESQI_LANES_SHIFT      20
+#define  PESQI_SINGLE_LANE     0
+#define  PESQI_DUAL_LANE       1
+#define  PESQI_QUAD_LANE       2
+#define PESQI_CSEN_SHIFT       24
+#define PESQI_EN               BIT(23)
+
+/* PESQI_CLK_CTRL_REG fields */
+#define PESQI_CLK_EN           BIT(0)
+#define PESQI_CLK_STABLE       BIT(1)
+#define PESQI_CLKDIV_SHIFT     8
+#define PESQI_CLKDIV           0xff
+
+/* PESQI_INT_THR/CMD_THR_REG */
+#define PESQI_TXTHR_MASK       0x1f
+#define PESQI_TXTHR_SHIFT      8
+#define PESQI_RXTHR_MASK       0x1f
+#define PESQI_RXTHR_SHIFT      0
+
+/* PESQI_INT_EN/INT_STAT/INT_SIG_EN_REG */
+#define PESQI_TXEMPTY          BIT(0)
+#define PESQI_TXFULL           BIT(1)
+#define PESQI_TXTHR            BIT(2)
+#define PESQI_RXEMPTY          BIT(3)
+#define PESQI_RXFULL           BIT(4)
+#define PESQI_RXTHR            BIT(5)
+#define PESQI_BDDONE           BIT(9)  /* BD processing complete */
+#define PESQI_PKTCOMP          BIT(10) /* packet processing complete */
+#define PESQI_DMAERR           BIT(11) /* error */
+
+/* PESQI_BD_CTRL_REG */
+#define PESQI_DMA_EN           BIT(0) /* enable DMA engine */
+#define PESQI_POLL_EN          BIT(1) /* enable polling */
+#define PESQI_BDP_START                BIT(2) /* start BD processor */
+
+/* PESQI controller buffer descriptor */
+struct buf_desc {
+       u32 bd_ctrl;    /* control */
+       u32 bd_status;  /* reserved */
+       u32 bd_addr;    /* DMA buffer addr */
+       u32 bd_nextp;   /* next item in chain */
+};
+
+/* bd_ctrl */
+#define BD_BUFLEN              0x1ff
+#define BD_CBD_INT_EN          BIT(16) /* Current BD is processed */
+#define BD_PKT_INT_EN          BIT(17) /* All BDs of PKT processed */
+#define BD_LIFM                        BIT(18) /* last data of pkt */
+#define BD_LAST                        BIT(19) /* end of list */
+#define BD_DATA_RECV           BIT(20) /* receive data */
+#define BD_DDR                 BIT(21) /* DDR mode */
+#define BD_DUAL                        BIT(22) /* Dual SPI */
+#define BD_QUAD                        BIT(23) /* Quad SPI */
+#define BD_LSBF                        BIT(25) /* LSB First */
+#define BD_STAT_CHECK          BIT(27) /* Status poll */
+#define BD_DEVSEL_SHIFT                28      /* CS */
+#define BD_CS_DEASSERT         BIT(30) /* de-assert CS after current BD */
+#define BD_EN                  BIT(31) /* BD owned by H/W */
+
+/**
+ * struct ring_desc - Representation of SQI ring descriptor
+ * @list:      list element to add to free or used list.
+ * @bd:                PESQI controller buffer descriptor
+ * @bd_dma:    DMA address of PESQI controller buffer descriptor
+ * @xfer_len:  transfer length
+ */
+struct ring_desc {
+       struct list_head list;
+       struct buf_desc *bd;
+       dma_addr_t bd_dma;
+       u32 xfer_len;
+};
+
+/* Global constants */
+#define PESQI_BD_BUF_LEN_MAX   256
+#define PESQI_BD_COUNT         256 /* max 64KB data per spi message */
+
+struct pic32_sqi {
+       void __iomem            *regs;
+       struct clk              *sys_clk;
+       struct clk              *base_clk; /* drives spi clock */
+       struct spi_master       *master;
+       int                     irq;
+       struct completion       xfer_done;
+       struct ring_desc        *ring;
+       void                    *bd;
+       dma_addr_t              bd_dma;
+       struct list_head        bd_list_free; /* free */
+       struct list_head        bd_list_used; /* allocated */
+       struct spi_device       *cur_spi;
+       u32                     cur_speed;
+       u8                      cur_mode;
+};
+
+static inline void pic32_setbits(void __iomem *reg, u32 set)
+{
+       writel(readl(reg) | set, reg);
+}
+
+static inline void pic32_clrbits(void __iomem *reg, u32 clr)
+{
+       writel(readl(reg) & ~clr, reg);
+}
+
+static int pic32_sqi_set_clk_rate(struct pic32_sqi *sqi, u32 sck)
+{
+       u32 val, div;
+
+       /* div = base_clk / (2 * spi_clk) */
+       div = clk_get_rate(sqi->base_clk) / (2 * sck);
+       div &= PESQI_CLKDIV;
+
+       val = readl(sqi->regs + PESQI_CLK_CTRL_REG);
+       /* apply new divider */
+       val &= ~(PESQI_CLK_STABLE | (PESQI_CLKDIV << PESQI_CLKDIV_SHIFT));
+       val |= div << PESQI_CLKDIV_SHIFT;
+       writel(val, sqi->regs + PESQI_CLK_CTRL_REG);
+
+       /* wait for stability */
+       return readl_poll_timeout(sqi->regs + PESQI_CLK_CTRL_REG, val,
+                                 val & PESQI_CLK_STABLE, 1, 5000);
+}
+
+static inline void pic32_sqi_enable_int(struct pic32_sqi *sqi)
+{
+       u32 mask = PESQI_DMAERR | PESQI_BDDONE | PESQI_PKTCOMP;
+
+       writel(mask, sqi->regs + PESQI_INT_ENABLE_REG);
+       /* INT_SIGEN works as interrupt-gate to INTR line */
+       writel(mask, sqi->regs + PESQI_INT_SIGEN_REG);
+}
+
+static inline void pic32_sqi_disable_int(struct pic32_sqi *sqi)
+{
+       writel(0, sqi->regs + PESQI_INT_ENABLE_REG);
+       writel(0, sqi->regs + PESQI_INT_SIGEN_REG);
+}
+
+static irqreturn_t pic32_sqi_isr(int irq, void *dev_id)
+{
+       struct pic32_sqi *sqi = dev_id;
+       u32 enable, status;
+
+       enable = readl(sqi->regs + PESQI_INT_ENABLE_REG);
+       status = readl(sqi->regs + PESQI_INT_STAT_REG);
+
+       /* check spurious interrupt */
+       if (!status)
+               return IRQ_NONE;
+
+       if (status & PESQI_DMAERR) {
+               enable = 0;
+               goto irq_done;
+       }
+
+       if (status & PESQI_TXTHR)
+               enable &= ~(PESQI_TXTHR | PESQI_TXFULL | PESQI_TXEMPTY);
+
+       if (status & PESQI_RXTHR)
+               enable &= ~(PESQI_RXTHR | PESQI_RXFULL | PESQI_RXEMPTY);
+
+       if (status & PESQI_BDDONE)
+               enable &= ~PESQI_BDDONE;
+
+       /* packet processing completed */
+       if (status & PESQI_PKTCOMP) {
+               /* mask all interrupts */
+               enable = 0;
+               /* complete trasaction */
+               complete(&sqi->xfer_done);
+       }
+
+irq_done:
+       /* interrupts are sticky, so mask when handled */
+       writel(enable, sqi->regs + PESQI_INT_ENABLE_REG);
+
+       return IRQ_HANDLED;
+}
+
+static struct ring_desc *ring_desc_get(struct pic32_sqi *sqi)
+{
+       struct ring_desc *rdesc;
+
+       if (list_empty(&sqi->bd_list_free))
+               return NULL;
+
+       rdesc = list_first_entry(&sqi->bd_list_free, struct ring_desc, list);
+       list_del(&rdesc->list);
+       list_add_tail(&rdesc->list, &sqi->bd_list_used);
+       return rdesc;
+}
+
+static void ring_desc_put(struct pic32_sqi *sqi, struct ring_desc *rdesc)
+{
+       list_del(&rdesc->list);
+       list_add(&rdesc->list, &sqi->bd_list_free);
+}
+
+static int pic32_sqi_one_transfer(struct pic32_sqi *sqi,
+                                 struct spi_message *mesg,
+                                 struct spi_transfer *xfer)
+{
+       struct spi_device *spi = mesg->spi;
+       struct scatterlist *sg, *sgl;
+       struct ring_desc *rdesc;
+       struct buf_desc *bd;
+       int nents, i;
+       u32 bd_ctrl;
+       u32 nbits;
+
+       /* Device selection */
+       bd_ctrl = spi->chip_select << BD_DEVSEL_SHIFT;
+
+       /* half-duplex: select transfer buffer, direction and lane */
+       if (xfer->rx_buf) {
+               bd_ctrl |= BD_DATA_RECV;
+               nbits = xfer->rx_nbits;
+               sgl = xfer->rx_sg.sgl;
+               nents = xfer->rx_sg.nents;
+       } else {
+               nbits = xfer->tx_nbits;
+               sgl = xfer->tx_sg.sgl;
+               nents = xfer->tx_sg.nents;
+       }
+
+       if (nbits & SPI_NBITS_QUAD)
+               bd_ctrl |= BD_QUAD;
+       else if (nbits & SPI_NBITS_DUAL)
+               bd_ctrl |= BD_DUAL;
+
+       /* LSB first */
+       if (spi->mode & SPI_LSB_FIRST)
+               bd_ctrl |= BD_LSBF;
+
+       /* ownership to hardware */
+       bd_ctrl |= BD_EN;
+
+       for_each_sg(sgl, sg, nents, i) {
+               /* get ring descriptor */
+               rdesc = ring_desc_get(sqi);
+               if (!rdesc)
+                       break;
+
+               bd = rdesc->bd;
+
+               /* BD CTRL: length */
+               rdesc->xfer_len = sg_dma_len(sg);
+               bd->bd_ctrl = bd_ctrl;
+               bd->bd_ctrl |= rdesc->xfer_len;
+
+               /* BD STAT */
+               bd->bd_status = 0;
+
+               /* BD BUFFER ADDRESS */
+               bd->bd_addr = sg->dma_address;
+       }
+
+       return 0;
+}
+
+static int pic32_sqi_prepare_hardware(struct spi_master *master)
+{
+       struct pic32_sqi *sqi = spi_master_get_devdata(master);
+
+       /* enable spi interface */
+       pic32_setbits(sqi->regs + PESQI_CONF_REG, PESQI_EN);
+       /* enable spi clk */
+       pic32_setbits(sqi->regs + PESQI_CLK_CTRL_REG, PESQI_CLK_EN);
+
+       return 0;
+}
+
+static bool pic32_sqi_can_dma(struct spi_master *master,
+                             struct spi_device *spi,
+                             struct spi_transfer *x)
+{
+       /* Do DMA irrespective of transfer size */
+       return true;
+}
+
+static int pic32_sqi_one_message(struct spi_master *master,
+                                struct spi_message *msg)
+{
+       struct spi_device *spi = msg->spi;
+       struct ring_desc *rdesc, *next;
+       struct spi_transfer *xfer;
+       struct pic32_sqi *sqi;
+       int ret = 0, mode;
+       u32 val;
+
+       sqi = spi_master_get_devdata(master);
+
+       reinit_completion(&sqi->xfer_done);
+       msg->actual_length = 0;
+
+       /* We can't handle spi_transfer specific "speed_hz", "bits_per_word"
+        * and "delay_usecs". But spi_device specific speed and mode change
+        * can be handled at best during spi chip-select switch.
+        */
+       if (sqi->cur_spi != spi) {
+               /* set spi speed */
+               if (sqi->cur_speed != spi->max_speed_hz) {
+                       sqi->cur_speed = spi->max_speed_hz;
+                       ret = pic32_sqi_set_clk_rate(sqi, spi->max_speed_hz);
+                       if (ret)
+                               dev_warn(&spi->dev, "set_clk, %d\n", ret);
+               }
+
+               /* set spi mode */
+               mode = spi->mode & (SPI_MODE_3 | SPI_LSB_FIRST);
+               if (sqi->cur_mode != mode) {
+                       val = readl(sqi->regs + PESQI_CONF_REG);
+                       val &= ~(PESQI_CPOL | PESQI_CPHA | PESQI_LSBF);
+                       if (mode & SPI_CPOL)
+                               val |= PESQI_CPOL;
+                       if (mode & SPI_LSB_FIRST)
+                               val |= PESQI_LSBF;
+                       val |= PESQI_CPHA;
+                       writel(val, sqi->regs + PESQI_CONF_REG);
+
+                       sqi->cur_mode = mode;
+               }
+               sqi->cur_spi = spi;
+       }
+
+       /* prepare hardware desc-list(BD) for transfer(s) */
+       list_for_each_entry(xfer, &msg->transfers, transfer_list) {
+               ret = pic32_sqi_one_transfer(sqi, msg, xfer);
+               if (ret) {
+                       dev_err(&spi->dev, "xfer %p err\n", xfer);
+                       goto xfer_out;
+               }
+       }
+
+       /* BDs are prepared and chained. Now mark LAST_BD, CS_DEASSERT at last
+        * element of the list.
+        */
+       rdesc = list_last_entry(&sqi->bd_list_used, struct ring_desc, list);
+       rdesc->bd->bd_ctrl |= BD_LAST | BD_CS_DEASSERT |
+                             BD_LIFM | BD_PKT_INT_EN;
+
+       /* set base address BD list for DMA engine */
+       rdesc = list_first_entry(&sqi->bd_list_used, struct ring_desc, list);
+       writel(rdesc->bd_dma, sqi->regs + PESQI_BD_BASE_ADDR_REG);
+
+       /* enable interrupt */
+       pic32_sqi_enable_int(sqi);
+
+       /* enable DMA engine */
+       val = PESQI_DMA_EN | PESQI_POLL_EN | PESQI_BDP_START;
+       writel(val, sqi->regs + PESQI_BD_CTRL_REG);
+
+       /* wait for xfer completion */
+       ret = wait_for_completion_timeout(&sqi->xfer_done, 5 * HZ);
+       if (ret <= 0) {
+               dev_err(&sqi->master->dev, "wait timedout/interrupted\n");
+               ret = -EIO;
+               msg->status = ret;
+       } else {
+               /* success */
+               msg->status = 0;
+               ret = 0;
+       }
+
+       /* disable DMA */
+       writel(0, sqi->regs + PESQI_BD_CTRL_REG);
+
+       pic32_sqi_disable_int(sqi);
+
+xfer_out:
+       list_for_each_entry_safe_reverse(rdesc, next,
+                                        &sqi->bd_list_used, list) {
+               /* Update total byte transferred */
+               msg->actual_length += rdesc->xfer_len;
+               /* release ring descr */
+               ring_desc_put(sqi, rdesc);
+       }
+       spi_finalize_current_message(spi->master);
+
+       return ret;
+}
+
+static int pic32_sqi_unprepare_hardware(struct spi_master *master)
+{
+       struct pic32_sqi *sqi = spi_master_get_devdata(master);
+
+       /* disable clk */
+       pic32_clrbits(sqi->regs + PESQI_CLK_CTRL_REG, PESQI_CLK_EN);
+       /* disable spi */
+       pic32_clrbits(sqi->regs + PESQI_CONF_REG, PESQI_EN);
+
+       return 0;
+}
+
+static int ring_desc_ring_alloc(struct pic32_sqi *sqi)
+{
+       struct ring_desc *rdesc;
+       struct buf_desc *bd;
+       int i;
+
+       /* allocate coherent DMAable memory for hardware buffer descriptors. */
+       sqi->bd = dma_zalloc_coherent(&sqi->master->dev,
+                                     sizeof(*bd) * PESQI_BD_COUNT,
+                                     &sqi->bd_dma, GFP_DMA32);
+       if (!sqi->bd) {
+               dev_err(&sqi->master->dev, "failed allocating dma buffer\n");
+               return -ENOMEM;
+       }
+
+       /* allocate software ring descriptors */
+       sqi->ring = kcalloc(PESQI_BD_COUNT, sizeof(*rdesc), GFP_KERNEL);
+       if (!sqi->ring) {
+               dma_free_coherent(&sqi->master->dev,
+                                 sizeof(*bd) * PESQI_BD_COUNT,
+                                 sqi->bd, sqi->bd_dma);
+               return -ENOMEM;
+       }
+
+       bd = (struct buf_desc *)sqi->bd;
+
+       INIT_LIST_HEAD(&sqi->bd_list_free);
+       INIT_LIST_HEAD(&sqi->bd_list_used);
+
+       /* initialize ring-desc */
+       for (i = 0, rdesc = sqi->ring; i < PESQI_BD_COUNT; i++, rdesc++) {
+               INIT_LIST_HEAD(&rdesc->list);
+               rdesc->bd = &bd[i];
+               rdesc->bd_dma = sqi->bd_dma + (void *)&bd[i] - (void *)bd;
+               list_add_tail(&rdesc->list, &sqi->bd_list_free);
+       }
+
+       /* Prepare BD: chain to next BD(s) */
+       for (i = 0, rdesc = sqi->ring; i < PESQI_BD_COUNT - 1; i++)
+               bd[i].bd_nextp = rdesc[i + 1].bd_dma;
+       bd[PESQI_BD_COUNT - 1].bd_nextp = 0;
+
+       return 0;
+}
+
+static void ring_desc_ring_free(struct pic32_sqi *sqi)
+{
+       dma_free_coherent(&sqi->master->dev,
+                         sizeof(struct buf_desc) * PESQI_BD_COUNT,
+                         sqi->bd, sqi->bd_dma);
+       kfree(sqi->ring);
+}
+
+static void pic32_sqi_hw_init(struct pic32_sqi *sqi)
+{
+       unsigned long flags;
+       u32 val;
+
+       /* Soft-reset of PESQI controller triggers interrupt.
+        * We are not yet ready to handle them so disable CPU
+        * interrupt for the time being.
+        */
+       local_irq_save(flags);
+
+       /* assert soft-reset */
+       writel(PESQI_SOFT_RESET, sqi->regs + PESQI_CONF_REG);
+
+       /* wait until clear */
+       readl_poll_timeout_atomic(sqi->regs + PESQI_CONF_REG, val,
+                                 !(val & PESQI_SOFT_RESET), 1, 5000);
+
+       /* disable all interrupts */
+       pic32_sqi_disable_int(sqi);
+
+       /* Now it is safe to enable back CPU interrupt */
+       local_irq_restore(flags);
+
+       /* tx and rx fifo interrupt threshold */
+       val = readl(sqi->regs + PESQI_CMD_THRES_REG);
+       val &= ~(PESQI_TXTHR_MASK << PESQI_TXTHR_SHIFT);
+       val &= ~(PESQI_RXTHR_MASK << PESQI_RXTHR_SHIFT);
+       val |= (1U << PESQI_TXTHR_SHIFT) | (1U << PESQI_RXTHR_SHIFT);
+       writel(val, sqi->regs + PESQI_CMD_THRES_REG);
+
+       val = readl(sqi->regs + PESQI_INT_THRES_REG);
+       val &= ~(PESQI_TXTHR_MASK << PESQI_TXTHR_SHIFT);
+       val &= ~(PESQI_RXTHR_MASK << PESQI_RXTHR_SHIFT);
+       val |= (1U << PESQI_TXTHR_SHIFT) | (1U << PESQI_RXTHR_SHIFT);
+       writel(val, sqi->regs + PESQI_INT_THRES_REG);
+
+       /* default configuration */
+       val = readl(sqi->regs + PESQI_CONF_REG);
+
+       /* set mode: DMA */
+       val &= ~PESQI_MODE;
+       val |= PESQI_MODE_DMA << PESQI_MODE_SHIFT;
+       writel(val, sqi->regs + PESQI_CONF_REG);
+
+       /* DATAEN - SQIID0-ID3 */
+       val |= PESQI_QUAD_LANE << PESQI_LANES_SHIFT;
+
+       /* burst/INCR4 enable */
+       val |= PESQI_BURST_EN;
+
+       /* CSEN - all CS */
+       val |= 3U << PESQI_CSEN_SHIFT;
+       writel(val, sqi->regs + PESQI_CONF_REG);
+
+       /* write poll count */
+       writel(0, sqi->regs + PESQI_BD_POLL_CTRL_REG);
+
+       sqi->cur_speed = 0;
+       sqi->cur_mode = -1;
+}
+
+static int pic32_sqi_probe(struct platform_device *pdev)
+{
+       struct spi_master *master;
+       struct pic32_sqi *sqi;
+       struct resource *reg;
+       int ret;
+
+       master = spi_alloc_master(&pdev->dev, sizeof(*sqi));
+       if (!master)
+               return -ENOMEM;
+
+       sqi = spi_master_get_devdata(master);
+       sqi->master = master;
+
+       reg = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       sqi->regs = devm_ioremap_resource(&pdev->dev, reg);
+       if (IS_ERR(sqi->regs)) {
+               ret = PTR_ERR(sqi->regs);
+               goto err_free_master;
+       }
+
+       /* irq */
+       sqi->irq = platform_get_irq(pdev, 0);
+       if (sqi->irq < 0) {
+               dev_err(&pdev->dev, "no irq found\n");
+               ret = sqi->irq;
+               goto err_free_master;
+       }
+
+       /* clocks */
+       sqi->sys_clk = devm_clk_get(&pdev->dev, "reg_ck");
+       if (IS_ERR(sqi->sys_clk)) {
+               ret = PTR_ERR(sqi->sys_clk);
+               dev_err(&pdev->dev, "no sys_clk ?\n");
+               goto err_free_master;
+       }
+
+       sqi->base_clk = devm_clk_get(&pdev->dev, "spi_ck");
+       if (IS_ERR(sqi->base_clk)) {
+               ret = PTR_ERR(sqi->base_clk);
+               dev_err(&pdev->dev, "no base clk ?\n");
+               goto err_free_master;
+       }
+
+       ret = clk_prepare_enable(sqi->sys_clk);
+       if (ret) {
+               dev_err(&pdev->dev, "sys clk enable failed\n");
+               goto err_free_master;
+       }
+
+       ret = clk_prepare_enable(sqi->base_clk);
+       if (ret) {
+               dev_err(&pdev->dev, "base clk enable failed\n");
+               clk_disable_unprepare(sqi->sys_clk);
+               goto err_free_master;
+       }
+
+       init_completion(&sqi->xfer_done);
+
+       /* initialize hardware */
+       pic32_sqi_hw_init(sqi);
+
+       /* allocate buffers & descriptors */
+       ret = ring_desc_ring_alloc(sqi);
+       if (ret) {
+               dev_err(&pdev->dev, "ring alloc failed\n");
+               goto err_disable_clk;
+       }
+
+       /* install irq handlers */
+       ret = request_irq(sqi->irq, pic32_sqi_isr, 0,
+                         dev_name(&pdev->dev), sqi);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "request_irq(%d), failed\n", sqi->irq);
+               goto err_free_ring;
+       }
+
+       /* register master */
+       master->num_chipselect  = 2;
+       master->max_speed_hz    = clk_get_rate(sqi->base_clk);
+       master->dma_alignment   = 32;
+       master->max_dma_len     = PESQI_BD_BUF_LEN_MAX;
+       master->dev.of_node     = of_node_get(pdev->dev.of_node);
+       master->mode_bits       = SPI_MODE_3 | SPI_MODE_0 | SPI_TX_DUAL |
+                                 SPI_RX_DUAL | SPI_TX_QUAD | SPI_RX_QUAD;
+       master->flags           = SPI_MASTER_HALF_DUPLEX;
+       master->can_dma         = pic32_sqi_can_dma;
+       master->bits_per_word_mask      = SPI_BPW_RANGE_MASK(8, 32);
+       master->transfer_one_message    = pic32_sqi_one_message;
+       master->prepare_transfer_hardware       = pic32_sqi_prepare_hardware;
+       master->unprepare_transfer_hardware     = pic32_sqi_unprepare_hardware;
+
+       ret = devm_spi_register_master(&pdev->dev, master);
+       if (ret) {
+               dev_err(&master->dev, "failed registering spi master\n");
+               free_irq(sqi->irq, sqi);
+               goto err_free_ring;
+       }
+
+       platform_set_drvdata(pdev, sqi);
+
+       return 0;
+
+err_free_ring:
+       ring_desc_ring_free(sqi);
+
+err_disable_clk:
+       clk_disable_unprepare(sqi->base_clk);
+       clk_disable_unprepare(sqi->sys_clk);
+
+err_free_master:
+       spi_master_put(master);
+       return ret;
+}
+
+static int pic32_sqi_remove(struct platform_device *pdev)
+{
+       struct pic32_sqi *sqi = platform_get_drvdata(pdev);
+
+       /* release resources */
+       free_irq(sqi->irq, sqi);
+       ring_desc_ring_free(sqi);
+
+       /* disable clk */
+       clk_disable_unprepare(sqi->base_clk);
+       clk_disable_unprepare(sqi->sys_clk);
+
+       return 0;
+}
+
+static const struct of_device_id pic32_sqi_of_ids[] = {
+       {.compatible = "microchip,pic32mzda-sqi",},
+       {},
+};
+MODULE_DEVICE_TABLE(of, pic32_sqi_of_ids);
+
+static struct platform_driver pic32_sqi_driver = {
+       .driver = {
+               .name = "sqi-pic32",
+               .of_match_table = of_match_ptr(pic32_sqi_of_ids),
+       },
+       .probe = pic32_sqi_probe,
+       .remove = pic32_sqi_remove,
+};
+
+module_platform_driver(pic32_sqi_driver);
+
+MODULE_AUTHOR("Purna Chandra Mandal <purna.mandal@microchip.com>");
+MODULE_DESCRIPTION("Microchip SPI driver for PIC32 SQI controller.");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/spi/spi-pic32.c b/drivers/spi/spi-pic32.c
new file mode 100644 (file)
index 0000000..73db87f
--- /dev/null
@@ -0,0 +1,878 @@
+/*
+ * Microchip PIC32 SPI controller driver.
+ *
+ * Purna Chandra Mandal <purna.mandal@microchip.com>
+ * Copyright (c) 2016, Microchip Technology Inc.
+ *
+ * This program is free software; you can distribute it and/or modify it
+ * under the terms of the GNU General Public License (Version 2) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/delay.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/highmem.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_gpio.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+
+/* SPI controller registers */
+struct pic32_spi_regs {
+       u32 ctrl;
+       u32 ctrl_clr;
+       u32 ctrl_set;
+       u32 ctrl_inv;
+       u32 status;
+       u32 status_clr;
+       u32 status_set;
+       u32 status_inv;
+       u32 buf;
+       u32 dontuse[3];
+       u32 baud;
+       u32 dontuse2[3];
+       u32 ctrl2;
+       u32 ctrl2_clr;
+       u32 ctrl2_set;
+       u32 ctrl2_inv;
+};
+
+/* Bit fields of SPI Control Register */
+#define CTRL_RX_INT_SHIFT      0  /* Rx interrupt generation */
+#define  RX_FIFO_EMTPY         0
+#define  RX_FIFO_NOT_EMPTY     1 /* not empty */
+#define  RX_FIFO_HALF_FULL     2 /* full by half or more */
+#define  RX_FIFO_FULL          3 /* completely full */
+
+#define CTRL_TX_INT_SHIFT      2  /* TX interrupt generation */
+#define  TX_FIFO_ALL_EMPTY     0 /* completely empty */
+#define  TX_FIFO_EMTPY         1 /* empty */
+#define  TX_FIFO_HALF_EMPTY    2 /* empty by half or more */
+#define  TX_FIFO_NOT_FULL      3 /* atleast one empty */
+
+#define CTRL_MSTEN     BIT(5) /* enable master mode */
+#define CTRL_CKP       BIT(6) /* active low */
+#define CTRL_CKE       BIT(8) /* Tx on falling edge */
+#define CTRL_SMP       BIT(9) /* Rx at middle or end of tx */
+#define CTRL_BPW_MASK  0x03   /* bits per word/sample */
+#define CTRL_BPW_SHIFT 10
+#define  PIC32_BPW_8   0
+#define  PIC32_BPW_16  1
+#define  PIC32_BPW_32  2
+#define CTRL_SIDL      BIT(13) /* sleep when idle */
+#define CTRL_ON                BIT(15) /* enable macro */
+#define CTRL_ENHBUF    BIT(16) /* enable enhanced buffering */
+#define CTRL_MCLKSEL   BIT(23) /* select clock source */
+#define CTRL_MSSEN     BIT(28) /* macro driven /SS */
+#define CTRL_FRMEN     BIT(31) /* enable framing mode */
+
+/* Bit fields of SPI Status Register */
+#define STAT_RF_EMPTY  BIT(5) /* RX Fifo empty */
+#define STAT_RX_OV     BIT(6) /* err, s/w needs to clear */
+#define STAT_TX_UR     BIT(8) /* UR in Framed SPI modes */
+#define STAT_FRM_ERR   BIT(12) /* Multiple Frame Sync pulse */
+#define STAT_TF_LVL_MASK       0x1F
+#define STAT_TF_LVL_SHIFT      16
+#define STAT_RF_LVL_MASK       0x1F
+#define STAT_RF_LVL_SHIFT      24
+
+/* Bit fields of SPI Baud Register */
+#define BAUD_MASK              0x1ff
+
+/* Bit fields of SPI Control2 Register */
+#define CTRL2_TX_UR_EN         BIT(10) /* Enable int on Tx under-run */
+#define CTRL2_RX_OV_EN         BIT(11) /* Enable int on Rx over-run */
+#define CTRL2_FRM_ERR_EN       BIT(12) /* Enable frame err int */
+
+/* Minimum DMA transfer size */
+#define PIC32_DMA_LEN_MIN      64
+
+struct pic32_spi {
+       dma_addr_t              dma_base;
+       struct pic32_spi_regs __iomem *regs;
+       int                     fault_irq;
+       int                     rx_irq;
+       int                     tx_irq;
+       u32                     fifo_n_byte; /* FIFO depth in bytes */
+       struct clk              *clk;
+       struct spi_master       *master;
+       /* Current controller setting */
+       u32                     speed_hz; /* spi-clk rate */
+       u32                     mode;
+       u32                     bits_per_word;
+       u32                     fifo_n_elm; /* FIFO depth in words */
+#define PIC32F_DMA_PREP                0 /* DMA chnls configured */
+       unsigned long           flags;
+       /* Current transfer state */
+       struct completion       xfer_done;
+       /* PIO transfer specific */
+       const void              *tx;
+       const void              *tx_end;
+       const void              *rx;
+       const void              *rx_end;
+       int                     len;
+       void (*rx_fifo)(struct pic32_spi *);
+       void (*tx_fifo)(struct pic32_spi *);
+};
+
+static inline void pic32_spi_enable(struct pic32_spi *pic32s)
+{
+       writel(CTRL_ON | CTRL_SIDL, &pic32s->regs->ctrl_set);
+}
+
+static inline void pic32_spi_disable(struct pic32_spi *pic32s)
+{
+       writel(CTRL_ON | CTRL_SIDL, &pic32s->regs->ctrl_clr);
+
+       /* avoid SPI registers read/write at immediate next CPU clock */
+       ndelay(20);
+}
+
+static void pic32_spi_set_clk_rate(struct pic32_spi *pic32s, u32 spi_ck)
+{
+       u32 div;
+
+       /* div = (clk_in / 2 * spi_ck) - 1 */
+       div = DIV_ROUND_CLOSEST(clk_get_rate(pic32s->clk), 2 * spi_ck) - 1;
+
+       writel(div & BAUD_MASK, &pic32s->regs->baud);
+}
+
+static inline u32 pic32_rx_fifo_level(struct pic32_spi *pic32s)
+{
+       u32 sr = readl(&pic32s->regs->status);
+
+       return (sr >> STAT_RF_LVL_SHIFT) & STAT_RF_LVL_MASK;
+}
+
+static inline u32 pic32_tx_fifo_level(struct pic32_spi *pic32s)
+{
+       u32 sr = readl(&pic32s->regs->status);
+
+       return (sr >> STAT_TF_LVL_SHIFT) & STAT_TF_LVL_MASK;
+}
+
+/* Return the max entries we can fill into tx fifo */
+static u32 pic32_tx_max(struct pic32_spi *pic32s, int n_bytes)
+{
+       u32 tx_left, tx_room, rxtx_gap;
+
+       tx_left = (pic32s->tx_end - pic32s->tx) / n_bytes;
+       tx_room = pic32s->fifo_n_elm - pic32_tx_fifo_level(pic32s);
+
+       /*
+        * Another concern is about the tx/rx mismatch, we
+        * though to use (pic32s->fifo_n_byte - rxfl - txfl) as
+        * one maximum value for tx, but it doesn't cover the
+        * data which is out of tx/rx fifo and inside the
+        * shift registers. So a ctrl from sw point of
+        * view is taken.
+        */
+       rxtx_gap = ((pic32s->rx_end - pic32s->rx) -
+                   (pic32s->tx_end - pic32s->tx)) / n_bytes;
+       return min3(tx_left, tx_room, (u32)(pic32s->fifo_n_elm - rxtx_gap));
+}
+
+/* Return the max entries we should read out of rx fifo */
+static u32 pic32_rx_max(struct pic32_spi *pic32s, int n_bytes)
+{
+       u32 rx_left = (pic32s->rx_end - pic32s->rx) / n_bytes;
+
+       return min_t(u32, rx_left, pic32_rx_fifo_level(pic32s));
+}
+
+#define BUILD_SPI_FIFO_RW(__name, __type, __bwl)               \
+static void pic32_spi_rx_##__name(struct pic32_spi *pic32s)    \
+{                                                              \
+       __type v;                                               \
+       u32 mx = pic32_rx_max(pic32s, sizeof(__type));          \
+       for (; mx; mx--) {                                      \
+               v = read##__bwl(&pic32s->regs->buf);            \
+               if (pic32s->rx_end - pic32s->len)               \
+                       *(__type *)(pic32s->rx) = v;            \
+               pic32s->rx += sizeof(__type);                   \
+       }                                                       \
+}                                                              \
+                                                               \
+static void pic32_spi_tx_##__name(struct pic32_spi *pic32s)    \
+{                                                              \
+       __type v;                                               \
+       u32 mx = pic32_tx_max(pic32s, sizeof(__type));          \
+       for (; mx ; mx--) {                                     \
+               v = (__type)~0U;                                \
+               if (pic32s->tx_end - pic32s->len)               \
+                       v = *(__type *)(pic32s->tx);            \
+               write##__bwl(v, &pic32s->regs->buf);            \
+               pic32s->tx += sizeof(__type);                   \
+       }                                                       \
+}
+
+BUILD_SPI_FIFO_RW(byte, u8, b);
+BUILD_SPI_FIFO_RW(word, u16, w);
+BUILD_SPI_FIFO_RW(dword, u32, l);
+
+static void pic32_err_stop(struct pic32_spi *pic32s, const char *msg)
+{
+       /* disable all interrupts */
+       disable_irq_nosync(pic32s->fault_irq);
+       disable_irq_nosync(pic32s->rx_irq);
+       disable_irq_nosync(pic32s->tx_irq);
+
+       /* Show err message and abort xfer with err */
+       dev_err(&pic32s->master->dev, "%s\n", msg);
+       if (pic32s->master->cur_msg)
+               pic32s->master->cur_msg->status = -EIO;
+       complete(&pic32s->xfer_done);
+}
+
+static irqreturn_t pic32_spi_fault_irq(int irq, void *dev_id)
+{
+       struct pic32_spi *pic32s = dev_id;
+       u32 status;
+
+       status = readl(&pic32s->regs->status);
+
+       /* Error handling */
+       if (status & (STAT_RX_OV | STAT_TX_UR)) {
+               writel(STAT_RX_OV, &pic32s->regs->status_clr);
+               writel(STAT_TX_UR, &pic32s->regs->status_clr);
+               pic32_err_stop(pic32s, "err_irq: fifo ov/ur-run\n");
+               return IRQ_HANDLED;
+       }
+
+       if (status & STAT_FRM_ERR) {
+               pic32_err_stop(pic32s, "err_irq: frame error");
+               return IRQ_HANDLED;
+       }
+
+       if (!pic32s->master->cur_msg) {
+               pic32_err_stop(pic32s, "err_irq: no mesg");
+               return IRQ_NONE;
+       }
+
+       return IRQ_NONE;
+}
+
+static irqreturn_t pic32_spi_rx_irq(int irq, void *dev_id)
+{
+       struct pic32_spi *pic32s = dev_id;
+
+       pic32s->rx_fifo(pic32s);
+
+       /* rx complete ? */
+       if (pic32s->rx_end == pic32s->rx) {
+               /* disable all interrupts */
+               disable_irq_nosync(pic32s->fault_irq);
+               disable_irq_nosync(pic32s->rx_irq);
+
+               /* complete current xfer */
+               complete(&pic32s->xfer_done);
+       }
+
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t pic32_spi_tx_irq(int irq, void *dev_id)
+{
+       struct pic32_spi *pic32s = dev_id;
+
+       pic32s->tx_fifo(pic32s);
+
+       /* tx complete? disable tx interrupt */
+       if (pic32s->tx_end == pic32s->tx)
+               disable_irq_nosync(pic32s->tx_irq);
+
+       return IRQ_HANDLED;
+}
+
+static void pic32_spi_dma_rx_notify(void *data)
+{
+       struct pic32_spi *pic32s = data;
+
+       complete(&pic32s->xfer_done);
+}
+
+static int pic32_spi_dma_transfer(struct pic32_spi *pic32s,
+                                 struct spi_transfer *xfer)
+{
+       struct spi_master *master = pic32s->master;
+       struct dma_async_tx_descriptor *desc_rx;
+       struct dma_async_tx_descriptor *desc_tx;
+       dma_cookie_t cookie;
+       int ret;
+
+       if (!master->dma_rx || !master->dma_tx)
+               return -ENODEV;
+
+       desc_rx = dmaengine_prep_slave_sg(master->dma_rx,
+                                         xfer->rx_sg.sgl,
+                                         xfer->rx_sg.nents,
+                                         DMA_FROM_DEVICE,
+                                         DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+       if (!desc_rx) {
+               ret = -EINVAL;
+               goto err_dma;
+       }
+
+       desc_tx = dmaengine_prep_slave_sg(master->dma_tx,
+                                         xfer->tx_sg.sgl,
+                                         xfer->tx_sg.nents,
+                                         DMA_TO_DEVICE,
+                                         DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+       if (!desc_tx) {
+               ret = -EINVAL;
+               goto err_dma;
+       }
+
+       /* Put callback on the RX transfer, that should finish last */
+       desc_rx->callback = pic32_spi_dma_rx_notify;
+       desc_rx->callback_param = pic32s;
+
+       cookie = dmaengine_submit(desc_rx);
+       ret = dma_submit_error(cookie);
+       if (ret)
+               goto err_dma;
+
+       cookie = dmaengine_submit(desc_tx);
+       ret = dma_submit_error(cookie);
+       if (ret)
+               goto err_dma_tx;
+
+       dma_async_issue_pending(master->dma_rx);
+       dma_async_issue_pending(master->dma_tx);
+
+       return 0;
+
+err_dma_tx:
+       dmaengine_terminate_all(master->dma_rx);
+err_dma:
+       return ret;
+}
+
+static int pic32_spi_dma_config(struct pic32_spi *pic32s, u32 dma_width)
+{
+       int buf_offset = offsetof(struct pic32_spi_regs, buf);
+       struct spi_master *master = pic32s->master;
+       struct dma_slave_config cfg;
+       int ret;
+
+       cfg.device_fc = true;
+       cfg.src_addr = pic32s->dma_base + buf_offset;
+       cfg.dst_addr = pic32s->dma_base + buf_offset;
+       cfg.src_maxburst = pic32s->fifo_n_elm / 2; /* fill one-half */
+       cfg.dst_maxburst = pic32s->fifo_n_elm / 2; /* drain one-half */
+       cfg.src_addr_width = dma_width;
+       cfg.dst_addr_width = dma_width;
+       /* tx channel */
+       cfg.slave_id = pic32s->tx_irq;
+       cfg.direction = DMA_MEM_TO_DEV;
+       ret = dmaengine_slave_config(master->dma_tx, &cfg);
+       if (ret) {
+               dev_err(&master->dev, "tx channel setup failed\n");
+               return ret;
+       }
+       /* rx channel */
+       cfg.slave_id = pic32s->rx_irq;
+       cfg.direction = DMA_DEV_TO_MEM;
+       ret = dmaengine_slave_config(master->dma_rx, &cfg);
+       if (ret)
+               dev_err(&master->dev, "rx channel setup failed\n");
+
+       return ret;
+}
+
+static int pic32_spi_set_word_size(struct pic32_spi *pic32s, u8 bits_per_word)
+{
+       enum dma_slave_buswidth dmawidth;
+       u32 buswidth, v;
+
+       switch (bits_per_word) {
+       case 8:
+               pic32s->rx_fifo = pic32_spi_rx_byte;
+               pic32s->tx_fifo = pic32_spi_tx_byte;
+               buswidth = PIC32_BPW_8;
+               dmawidth = DMA_SLAVE_BUSWIDTH_1_BYTE;
+               break;
+       case 16:
+               pic32s->rx_fifo = pic32_spi_rx_word;
+               pic32s->tx_fifo = pic32_spi_tx_word;
+               buswidth = PIC32_BPW_16;
+               dmawidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
+               break;
+       case 32:
+               pic32s->rx_fifo = pic32_spi_rx_dword;
+               pic32s->tx_fifo = pic32_spi_tx_dword;
+               buswidth = PIC32_BPW_32;
+               dmawidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
+               break;
+       default:
+               /* not supported */
+               return -EINVAL;
+       }
+
+       /* calculate maximum number of words fifos can hold */
+       pic32s->fifo_n_elm = DIV_ROUND_UP(pic32s->fifo_n_byte,
+                                         bits_per_word / 8);
+       /* set word size */
+       v = readl(&pic32s->regs->ctrl);
+       v &= ~(CTRL_BPW_MASK << CTRL_BPW_SHIFT);
+       v |= buswidth << CTRL_BPW_SHIFT;
+       writel(v, &pic32s->regs->ctrl);
+
+       /* re-configure dma width, if required */
+       if (test_bit(PIC32F_DMA_PREP, &pic32s->flags))
+               pic32_spi_dma_config(pic32s, dmawidth);
+
+       return 0;
+}
+
+static int pic32_spi_prepare_hardware(struct spi_master *master)
+{
+       struct pic32_spi *pic32s = spi_master_get_devdata(master);
+
+       pic32_spi_enable(pic32s);
+
+       return 0;
+}
+
+static int pic32_spi_prepare_message(struct spi_master *master,
+                                    struct spi_message *msg)
+{
+       struct pic32_spi *pic32s = spi_master_get_devdata(master);
+       struct spi_device *spi = msg->spi;
+       u32 val;
+
+       /* set device specific bits_per_word */
+       if (pic32s->bits_per_word != spi->bits_per_word) {
+               pic32_spi_set_word_size(pic32s, spi->bits_per_word);
+               pic32s->bits_per_word = spi->bits_per_word;
+       }
+
+       /* device specific speed change */
+       if (pic32s->speed_hz != spi->max_speed_hz) {
+               pic32_spi_set_clk_rate(pic32s, spi->max_speed_hz);
+               pic32s->speed_hz = spi->max_speed_hz;
+       }
+
+       /* device specific mode change */
+       if (pic32s->mode != spi->mode) {
+               val = readl(&pic32s->regs->ctrl);
+               /* active low */
+               if (spi->mode & SPI_CPOL)
+                       val |= CTRL_CKP;
+               else
+                       val &= ~CTRL_CKP;
+               /* tx on rising edge */
+               if (spi->mode & SPI_CPHA)
+                       val &= ~CTRL_CKE;
+               else
+                       val |= CTRL_CKE;
+
+               /* rx at end of tx */
+               val |= CTRL_SMP;
+               writel(val, &pic32s->regs->ctrl);
+               pic32s->mode = spi->mode;
+       }
+
+       return 0;
+}
+
+static bool pic32_spi_can_dma(struct spi_master *master,
+                             struct spi_device *spi,
+                             struct spi_transfer *xfer)
+{
+       struct pic32_spi *pic32s = spi_master_get_devdata(master);
+
+       /* skip using DMA on small size transfer to avoid overhead.*/
+       return (xfer->len >= PIC32_DMA_LEN_MIN) &&
+              test_bit(PIC32F_DMA_PREP, &pic32s->flags);
+}
+
+static int pic32_spi_one_transfer(struct spi_master *master,
+                                 struct spi_device *spi,
+                                 struct spi_transfer *transfer)
+{
+       struct pic32_spi *pic32s;
+       bool dma_issued = false;
+       int ret;
+
+       pic32s = spi_master_get_devdata(master);
+
+       /* handle transfer specific word size change */
+       if (transfer->bits_per_word &&
+           (transfer->bits_per_word != pic32s->bits_per_word)) {
+               ret = pic32_spi_set_word_size(pic32s, transfer->bits_per_word);
+               if (ret)
+                       return ret;
+               pic32s->bits_per_word = transfer->bits_per_word;
+       }
+
+       /* handle transfer specific speed change */
+       if (transfer->speed_hz && (transfer->speed_hz != pic32s->speed_hz)) {
+               pic32_spi_set_clk_rate(pic32s, transfer->speed_hz);
+               pic32s->speed_hz = transfer->speed_hz;
+       }
+
+       reinit_completion(&pic32s->xfer_done);
+
+       /* transact by DMA mode */
+       if (transfer->rx_sg.nents && transfer->tx_sg.nents) {
+               ret = pic32_spi_dma_transfer(pic32s, transfer);
+               if (ret) {
+                       dev_err(&spi->dev, "dma submit error\n");
+                       return ret;
+               }
+
+               /* DMA issued */
+               dma_issued = true;
+       } else {
+               /* set current transfer information */
+               pic32s->tx = (const void *)transfer->tx_buf;
+               pic32s->rx = (const void *)transfer->rx_buf;
+               pic32s->tx_end = pic32s->tx + transfer->len;
+               pic32s->rx_end = pic32s->rx + transfer->len;
+               pic32s->len = transfer->len;
+
+               /* transact by interrupt driven PIO */
+               enable_irq(pic32s->fault_irq);
+               enable_irq(pic32s->rx_irq);
+               enable_irq(pic32s->tx_irq);
+       }
+
+       /* wait for completion */
+       ret = wait_for_completion_timeout(&pic32s->xfer_done, 2 * HZ);
+       if (ret <= 0) {
+               dev_err(&spi->dev, "wait error/timedout\n");
+               if (dma_issued) {
+                       dmaengine_terminate_all(master->dma_rx);
+                       dmaengine_terminate_all(master->dma_rx);
+               }
+               ret = -ETIMEDOUT;
+       } else {
+               ret = 0;
+       }
+
+       return ret;
+}
+
+static int pic32_spi_unprepare_message(struct spi_master *master,
+                                      struct spi_message *msg)
+{
+       /* nothing to do */
+       return 0;
+}
+
+static int pic32_spi_unprepare_hardware(struct spi_master *master)
+{
+       struct pic32_spi *pic32s = spi_master_get_devdata(master);
+
+       pic32_spi_disable(pic32s);
+
+       return 0;
+}
+
+/* This may be called multiple times by same spi dev */
+static int pic32_spi_setup(struct spi_device *spi)
+{
+       if (!spi->max_speed_hz) {
+               dev_err(&spi->dev, "No max speed HZ parameter\n");
+               return -EINVAL;
+       }
+
+       /* PIC32 spi controller can drive /CS during transfer depending
+        * on tx fifo fill-level. /CS will stay asserted as long as TX
+        * fifo is non-empty, else will be deasserted indicating
+        * completion of the ongoing transfer. This might result into
+        * unreliable/erroneous SPI transactions.
+        * To avoid that we will always handle /CS by toggling GPIO.
+        */
+       if (!gpio_is_valid(spi->cs_gpio))
+               return -EINVAL;
+
+       gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
+
+       return 0;
+}
+
+static void pic32_spi_cleanup(struct spi_device *spi)
+{
+       /* de-activate cs-gpio */
+       gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
+}
+
+static void pic32_spi_dma_prep(struct pic32_spi *pic32s, struct device *dev)
+{
+       struct spi_master *master = pic32s->master;
+       dma_cap_mask_t mask;
+
+       dma_cap_zero(mask);
+       dma_cap_set(DMA_SLAVE, mask);
+
+       master->dma_rx = dma_request_slave_channel_compat(mask, NULL, NULL,
+                                                         dev, "spi-rx");
+       if (!master->dma_rx) {
+               dev_warn(dev, "RX channel not found.\n");
+               goto out_err;
+       }
+
+       master->dma_tx = dma_request_slave_channel_compat(mask, NULL, NULL,
+                                                         dev, "spi-tx");
+       if (!master->dma_tx) {
+               dev_warn(dev, "TX channel not found.\n");
+               goto out_err;
+       }
+
+       if (pic32_spi_dma_config(pic32s, DMA_SLAVE_BUSWIDTH_1_BYTE))
+               goto out_err;
+
+       /* DMA chnls allocated and prepared */
+       set_bit(PIC32F_DMA_PREP, &pic32s->flags);
+
+       return;
+
+out_err:
+       if (master->dma_rx)
+               dma_release_channel(master->dma_rx);
+
+       if (master->dma_tx)
+               dma_release_channel(master->dma_tx);
+}
+
+static void pic32_spi_dma_unprep(struct pic32_spi *pic32s)
+{
+       if (!test_bit(PIC32F_DMA_PREP, &pic32s->flags))
+               return;
+
+       clear_bit(PIC32F_DMA_PREP, &pic32s->flags);
+       if (pic32s->master->dma_rx)
+               dma_release_channel(pic32s->master->dma_rx);
+
+       if (pic32s->master->dma_tx)
+               dma_release_channel(pic32s->master->dma_tx);
+}
+
+static void pic32_spi_hw_init(struct pic32_spi *pic32s)
+{
+       u32 ctrl;
+
+       /* disable hardware */
+       pic32_spi_disable(pic32s);
+
+       ctrl = readl(&pic32s->regs->ctrl);
+       /* enable enhanced fifo of 128bit deep */
+       ctrl |= CTRL_ENHBUF;
+       pic32s->fifo_n_byte = 16;
+
+       /* disable framing mode */
+       ctrl &= ~CTRL_FRMEN;
+
+       /* enable master mode while disabled */
+       ctrl |= CTRL_MSTEN;
+
+       /* set tx fifo threshold interrupt */
+       ctrl &= ~(0x3 << CTRL_TX_INT_SHIFT);
+       ctrl |= (TX_FIFO_HALF_EMPTY << CTRL_TX_INT_SHIFT);
+
+       /* set rx fifo threshold interrupt */
+       ctrl &= ~(0x3 << CTRL_RX_INT_SHIFT);
+       ctrl |= (RX_FIFO_NOT_EMPTY << CTRL_RX_INT_SHIFT);
+
+       /* select clk source */
+       ctrl &= ~CTRL_MCLKSEL;
+
+       /* set manual /CS mode */
+       ctrl &= ~CTRL_MSSEN;
+
+       writel(ctrl, &pic32s->regs->ctrl);
+
+       /* enable error reporting */
+       ctrl = CTRL2_TX_UR_EN | CTRL2_RX_OV_EN | CTRL2_FRM_ERR_EN;
+       writel(ctrl, &pic32s->regs->ctrl2_set);
+}
+
+static int pic32_spi_hw_probe(struct platform_device *pdev,
+                             struct pic32_spi *pic32s)
+{
+       struct resource *mem;
+       int ret;
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       pic32s->regs = devm_ioremap_resource(&pdev->dev, mem);
+       if (IS_ERR(pic32s->regs))
+               return PTR_ERR(pic32s->regs);
+
+       pic32s->dma_base = mem->start;
+
+       /* get irq resources: err-irq, rx-irq, tx-irq */
+       pic32s->fault_irq = platform_get_irq_byname(pdev, "fault");
+       if (pic32s->fault_irq < 0) {
+               dev_err(&pdev->dev, "fault-irq not found\n");
+               return pic32s->fault_irq;
+       }
+
+       pic32s->rx_irq = platform_get_irq_byname(pdev, "rx");
+       if (pic32s->rx_irq < 0) {
+               dev_err(&pdev->dev, "rx-irq not found\n");
+               return pic32s->rx_irq;
+       }
+
+       pic32s->tx_irq = platform_get_irq_byname(pdev, "tx");
+       if (pic32s->tx_irq < 0) {
+               dev_err(&pdev->dev, "tx-irq not found\n");
+               return pic32s->tx_irq;
+       }
+
+       /* get clock */
+       pic32s->clk = devm_clk_get(&pdev->dev, "mck0");
+       if (IS_ERR(pic32s->clk)) {
+               dev_err(&pdev->dev, "clk not found\n");
+               ret = PTR_ERR(pic32s->clk);
+               goto err_unmap_mem;
+       }
+
+       ret = clk_prepare_enable(pic32s->clk);
+       if (ret)
+               goto err_unmap_mem;
+
+       pic32_spi_hw_init(pic32s);
+
+       return 0;
+
+err_unmap_mem:
+       dev_err(&pdev->dev, "%s failed, err %d\n", __func__, ret);
+       return ret;
+}
+
+static int pic32_spi_probe(struct platform_device *pdev)
+{
+       struct spi_master *master;
+       struct pic32_spi *pic32s;
+       int ret;
+
+       master = spi_alloc_master(&pdev->dev, sizeof(*pic32s));
+       if (!master)
+               return -ENOMEM;
+
+       pic32s = spi_master_get_devdata(master);
+       pic32s->master = master;
+
+       ret = pic32_spi_hw_probe(pdev, pic32s);
+       if (ret)
+               goto err_master;
+
+       master->dev.of_node     = of_node_get(pdev->dev.of_node);
+       master->mode_bits       = SPI_MODE_3 | SPI_MODE_0 | SPI_CS_HIGH;
+       master->num_chipselect  = 1; /* single chip-select */
+       master->max_speed_hz    = clk_get_rate(pic32s->clk);
+       master->setup           = pic32_spi_setup;
+       master->cleanup         = pic32_spi_cleanup;
+       master->flags           = SPI_MASTER_MUST_TX | SPI_MASTER_MUST_RX;
+       master->bits_per_word_mask      = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
+                                         SPI_BPW_MASK(32);
+       master->transfer_one            = pic32_spi_one_transfer;
+       master->prepare_message         = pic32_spi_prepare_message;
+       master->unprepare_message       = pic32_spi_unprepare_message;
+       master->prepare_transfer_hardware       = pic32_spi_prepare_hardware;
+       master->unprepare_transfer_hardware     = pic32_spi_unprepare_hardware;
+
+       /* optional DMA support */
+       pic32_spi_dma_prep(pic32s, &pdev->dev);
+       if (test_bit(PIC32F_DMA_PREP, &pic32s->flags))
+               master->can_dma = pic32_spi_can_dma;
+
+       init_completion(&pic32s->xfer_done);
+       pic32s->mode = -1;
+
+       /* install irq handlers (with irq-disabled) */
+       irq_set_status_flags(pic32s->fault_irq, IRQ_NOAUTOEN);
+       ret = devm_request_irq(&pdev->dev, pic32s->fault_irq,
+                              pic32_spi_fault_irq, IRQF_NO_THREAD,
+                              dev_name(&pdev->dev), pic32s);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "request fault-irq %d\n", pic32s->rx_irq);
+               goto err_bailout;
+       }
+
+       /* receive interrupt handler */
+       irq_set_status_flags(pic32s->rx_irq, IRQ_NOAUTOEN);
+       ret = devm_request_irq(&pdev->dev, pic32s->rx_irq,
+                              pic32_spi_rx_irq, IRQF_NO_THREAD,
+                              dev_name(&pdev->dev), pic32s);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "request rx-irq %d\n", pic32s->rx_irq);
+               goto err_bailout;
+       }
+
+       /* transmit interrupt handler */
+       irq_set_status_flags(pic32s->tx_irq, IRQ_NOAUTOEN);
+       ret = devm_request_irq(&pdev->dev, pic32s->tx_irq,
+                              pic32_spi_tx_irq, IRQF_NO_THREAD,
+                              dev_name(&pdev->dev), pic32s);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "request tx-irq %d\n", pic32s->tx_irq);
+               goto err_bailout;
+       }
+
+       /* register master */
+       ret = devm_spi_register_master(&pdev->dev, master);
+       if (ret) {
+               dev_err(&master->dev, "failed registering spi master\n");
+               goto err_bailout;
+       }
+
+       platform_set_drvdata(pdev, pic32s);
+
+       return 0;
+
+err_bailout:
+       clk_disable_unprepare(pic32s->clk);
+err_master:
+       spi_master_put(master);
+       return ret;
+}
+
+static int pic32_spi_remove(struct platform_device *pdev)
+{
+       struct pic32_spi *pic32s;
+
+       pic32s = platform_get_drvdata(pdev);
+       pic32_spi_disable(pic32s);
+       clk_disable_unprepare(pic32s->clk);
+       pic32_spi_dma_unprep(pic32s);
+
+       return 0;
+}
+
+static const struct of_device_id pic32_spi_of_match[] = {
+       {.compatible = "microchip,pic32mzda-spi",},
+       {},
+};
+MODULE_DEVICE_TABLE(of, pic32_spi_of_match);
+
+static struct platform_driver pic32_spi_driver = {
+       .driver = {
+               .name = "spi-pic32",
+               .of_match_table = of_match_ptr(pic32_spi_of_match),
+       },
+       .probe = pic32_spi_probe,
+       .remove = pic32_spi_remove,
+};
+
+module_platform_driver(pic32_spi_driver);
+
+MODULE_AUTHOR("Purna Chandra Mandal <purna.mandal@microchip.com>");
+MODULE_DESCRIPTION("Microchip SPI driver for PIC32 SPI controller.");
+MODULE_LICENSE("GPL v2");
index 365fc22c35729372e22dee90271dc3a37820d27c..a18a03d0afb709a51eb9515cfee7d8acf181d2e6 100644 (file)
@@ -33,12 +33,10 @@ static int pxa2xx_spi_map_dma_buffer(struct driver_data *drv_data,
                dmadev = drv_data->tx_chan->device->dev;
                sgt = &drv_data->tx_sgt;
                buf = drv_data->tx;
-               drv_data->tx_map_len = len;
        } else {
                dmadev = drv_data->rx_chan->device->dev;
                sgt = &drv_data->rx_sgt;
                buf = drv_data->rx;
-               drv_data->rx_map_len = len;
        }
 
        nents = DIV_ROUND_UP(len, SZ_2K);
@@ -55,11 +53,7 @@ static int pxa2xx_spi_map_dma_buffer(struct driver_data *drv_data,
        for_each_sg(sgt->sgl, sg, sgt->nents, i) {
                size_t bytes = min_t(size_t, len, SZ_2K);
 
-               if (buf)
-                       sg_set_buf(sg, pbuf, bytes);
-               else
-                       sg_set_buf(sg, drv_data->dummy, bytes);
-
+               sg_set_buf(sg, pbuf, bytes);
                pbuf += bytes;
                len -= bytes;
        }
@@ -133,9 +127,6 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
                if (!error) {
                        pxa2xx_spi_unmap_dma_buffers(drv_data);
 
-                       drv_data->tx += drv_data->tx_map_len;
-                       drv_data->rx += drv_data->rx_map_len;
-
                        msg->actual_length += drv_data->len;
                        msg->state = pxa2xx_spi_next_transfer(drv_data);
                } else {
@@ -267,19 +258,22 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
 int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst)
 {
        struct dma_async_tx_descriptor *tx_desc, *rx_desc;
+       int err = 0;
 
        tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV);
        if (!tx_desc) {
                dev_err(&drv_data->pdev->dev,
                        "failed to get DMA TX descriptor\n");
-               return -EBUSY;
+               err = -EBUSY;
+               goto err_tx;
        }
 
        rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM);
        if (!rx_desc) {
                dev_err(&drv_data->pdev->dev,
                        "failed to get DMA RX descriptor\n");
-               return -EBUSY;
+               err = -EBUSY;
+               goto err_rx;
        }
 
        /* We are ready when RX completes */
@@ -289,6 +283,12 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst)
        dmaengine_submit(rx_desc);
        dmaengine_submit(tx_desc);
        return 0;
+
+err_rx:
+       dmaengine_terminate_async(drv_data->tx_chan);
+err_tx:
+       pxa2xx_spi_unmap_dma_buffers(drv_data);
+       return err;
 }
 
 void pxa2xx_spi_dma_start(struct driver_data *drv_data)
@@ -308,10 +308,6 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
        dma_cap_zero(mask);
        dma_cap_set(DMA_SLAVE, mask);
 
-       drv_data->dummy = devm_kzalloc(dev, SZ_2K, GFP_KERNEL);
-       if (!drv_data->dummy)
-               return -ENOMEM;
-
        drv_data->tx_chan = dma_request_slave_channel_compat(mask,
                                pdata->dma_filter, pdata->tx_param, dev, "tx");
        if (!drv_data->tx_chan)
index 4fd7f9802f1b12fa1d21788f490aa185eb3cbd3e..5202de94f792c4bf8e38bf0d6c1da94586ae26f9 100644 (file)
@@ -173,8 +173,8 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
        ssp->type = c->type;
 
        snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
-       ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL,
-                                       CLK_IS_ROOT, c->max_clk_rate);
+       ssp->clk = clk_register_fixed_rate(&dev->dev, buf , NULL, 0,
+                                          c->max_clk_rate);
         if (IS_ERR(ssp->clk))
                return PTR_ERR(ssp->clk);
 
index 86138e4101b07f990634d06af60b4c5a63ce4607..fe07c0592b44c9eac5faf22409203392cdbc9e3a 100644 (file)
@@ -570,9 +570,8 @@ static void giveback(struct driver_data *drv_data)
                /* see if the next and current messages point
                 * to the same chip
                 */
-               if (next_msg && next_msg->spi != msg->spi)
-                       next_msg = NULL;
-               if (!next_msg || msg->state == ERROR_STATE)
+               if ((next_msg && next_msg->spi != msg->spi) ||
+                   msg->state == ERROR_STATE)
                        cs_deassert(drv_data);
        }
 
@@ -928,6 +927,7 @@ static void pump_transfers(unsigned long data)
        u32 dma_thresh = drv_data->cur_chip->dma_threshold;
        u32 dma_burst = drv_data->cur_chip->dma_burst_size;
        u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data);
+       int err;
 
        /* Get current state information */
        message = drv_data->cur_msg;
@@ -1047,7 +1047,12 @@ static void pump_transfers(unsigned long data)
                /* Ensure we have the correct interrupt handler */
                drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
 
-               pxa2xx_spi_dma_prepare(drv_data, dma_burst);
+               err = pxa2xx_spi_dma_prepare(drv_data, dma_burst);
+               if (err) {
+                       message->status = err;
+                       giveback(drv_data);
+                       return;
+               }
 
                /* Clear status and start DMA engine */
                cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
@@ -1543,7 +1548,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
        drv_data->pdev = pdev;
        drv_data->ssp = ssp;
 
-       master->dev.parent = &pdev->dev;
        master->dev.of_node = pdev->dev.of_node;
        /* the spi->mode bits understood by this driver: */
        master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
@@ -1556,6 +1560,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
        master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
        master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
        master->auto_runtime_pm = true;
+       master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX;
 
        drv_data->ssp_type = ssp->type;
 
index a1ef889481447fd4eeeca749bba063014bddc3f6..e6b09000ff145f072f0b7e12aaf11a8eeba7624f 100644 (file)
@@ -56,7 +56,6 @@ struct driver_data {
        struct sg_table tx_sgt;
        int rx_nents;
        int tx_nents;
-       void *dummy;
        atomic_t dma_running;
 
        /* Current message transfer state info */
@@ -69,8 +68,6 @@ struct driver_data {
        void *rx;
        void *rx_end;
        int dma_mapped;
-       size_t rx_map_len;
-       size_t tx_map_len;
        u8 n_bytes;
        int (*write)(struct driver_data *drv_data);
        int (*read)(struct driver_data *drv_data);
index 810a7fae347988a7d9dc1101586234b8ef8efc77..c338ef1136f6c6052b72b9394f74ef89b58273a5 100644 (file)
@@ -937,6 +937,10 @@ static int spi_qup_pm_suspend_runtime(struct device *device)
        config = readl(controller->base + QUP_CONFIG);
        config |= QUP_CONFIG_CLOCK_AUTO_GATE;
        writel_relaxed(config, controller->base + QUP_CONFIG);
+
+       clk_disable_unprepare(controller->cclk);
+       clk_disable_unprepare(controller->iclk);
+
        return 0;
 }
 
@@ -945,6 +949,15 @@ static int spi_qup_pm_resume_runtime(struct device *device)
        struct spi_master *master = dev_get_drvdata(device);
        struct spi_qup *controller = spi_master_get_devdata(master);
        u32 config;
+       int ret;
+
+       ret = clk_prepare_enable(controller->iclk);
+       if (ret)
+               return ret;
+
+       ret = clk_prepare_enable(controller->cclk);
+       if (ret)
+               return ret;
 
        /* Disable clocks auto gaiting */
        config = readl_relaxed(controller->base + QUP_CONFIG);
@@ -1017,6 +1030,8 @@ static int spi_qup_remove(struct platform_device *pdev)
 
        pm_runtime_put_noidle(&pdev->dev);
        pm_runtime_disable(&pdev->dev);
+       spi_master_put(master);
+
        return 0;
 }
 
index 6c6c0013ec7a92732d2540ade876c561359f8d70..cd89682065b98d7a06a7d7064ec30aff2a5e7fef 100644 (file)
@@ -744,10 +744,8 @@ static int rockchip_spi_probe(struct platform_device *pdev)
        rs->dma_rx.ch = dma_request_chan(rs->dev, "rx");
        if (IS_ERR(rs->dma_rx.ch)) {
                if (PTR_ERR(rs->dma_rx.ch) == -EPROBE_DEFER) {
-                       dma_release_channel(rs->dma_tx.ch);
-                       rs->dma_tx.ch = NULL;
                        ret = -EPROBE_DEFER;
-                       goto err_get_fifo_len;
+                       goto err_free_dma_tx;
                }
                dev_warn(rs->dev, "Failed to request RX DMA channel\n");
                rs->dma_rx.ch = NULL;
@@ -775,10 +773,11 @@ static int rockchip_spi_probe(struct platform_device *pdev)
 
 err_register_master:
        pm_runtime_disable(&pdev->dev);
-       if (rs->dma_tx.ch)
-               dma_release_channel(rs->dma_tx.ch);
        if (rs->dma_rx.ch)
                dma_release_channel(rs->dma_rx.ch);
+err_free_dma_tx:
+       if (rs->dma_tx.ch)
+               dma_release_channel(rs->dma_tx.ch);
 err_get_fifo_len:
        clk_disable_unprepare(rs->spiclk);
 err_spiclk_enable:
index f17c0abe299f418697774fa9351e724600442d51..d5adf9f31602385e764f50980dd93786812967b6 100644 (file)
@@ -345,12 +345,13 @@ static int spi_st_probe(struct platform_device *pdev)
        spi_st->clk = devm_clk_get(&pdev->dev, "ssc");
        if (IS_ERR(spi_st->clk)) {
                dev_err(&pdev->dev, "Unable to request clock\n");
-               return PTR_ERR(spi_st->clk);
+               ret = PTR_ERR(spi_st->clk);
+               goto put_master;
        }
 
        ret = spi_st_clk_enable(spi_st);
        if (ret)
-               return ret;
+               goto put_master;
 
        init_completion(&spi_st->done);
 
@@ -408,7 +409,8 @@ static int spi_st_probe(struct platform_device *pdev)
 
 clk_disable:
        spi_st_clk_disable(spi_st);
-
+put_master:
+       spi_master_put(master);
        return ret;
 }
 
index aab9b492c627ada109f4cb5ac9840b5b79cdf2f6..18aeaceee2862017f4cd4bb13a5e3c6bd36f6ea7 100644 (file)
@@ -360,7 +360,7 @@ static int zynqmp_prepare_transfer_hardware(struct spi_master *master)
 
        ret = clk_enable(xqspi->refclk);
        if (ret)
-               goto clk_err;
+               return ret;
 
        ret = clk_enable(xqspi->pclk);
        if (ret)
@@ -369,6 +369,7 @@ static int zynqmp_prepare_transfer_hardware(struct spi_master *master)
        zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK);
        return 0;
 clk_err:
+       clk_disable(xqspi->refclk);
        return ret;
 }
 
index 0239b45eed928697d9ccb10c2a83c1ef51958c16..77e6e45951f4c5e1c69a81b6d4ddf370d7f1a075 100644 (file)
@@ -717,9 +717,11 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
        if (vmalloced_buf) {
                desc_len = min_t(int, max_seg_size, PAGE_SIZE);
                sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
-       } else {
+       } else if (virt_addr_valid(buf)) {
                desc_len = min_t(int, max_seg_size, master->max_dma_len);
                sgs = DIV_ROUND_UP(len, desc_len);
+       } else {
+               return -EINVAL;
        }
 
        ret = sg_alloc_table(sgt, sgs, GFP_KERNEL);
@@ -933,7 +935,7 @@ static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
  * spi_transfer_one_message - Default implementation of transfer_one_message()
  *
  * This is a standard implementation of transfer_one_message() for
- * drivers which impelment a transfer_one() operation.  It provides
+ * drivers which implement a transfer_one() operation.  It provides
  * standard handling of delays and chip select management.
  */
 static int spi_transfer_one_message(struct spi_master *master,
@@ -1764,6 +1766,7 @@ struct spi_master *spi_alloc_master(struct device *dev, unsigned size)
        master->num_chipselect = 1;
        master->dev.class = &spi_master_class;
        master->dev.parent = dev;
+       pm_suspend_ignore_children(&master->dev, true);
        spi_master_set_devdata(master, &master[1]);
 
        return master;
index 163f21a1298d89bcf21ccac195805b45e1f2adac..e389009fca42c0caa447dc8f9b37360e3565a456 100644 (file)
@@ -42,23 +42,33 @@ static inline struct spinand_state *mtd_to_state(struct mtd_info *mtd)
 static int enable_hw_ecc;
 static int enable_read_hw_ecc;
 
-static struct nand_ecclayout spinand_oob_64 = {
-       .eccbytes = 24,
-       .eccpos = {
-               1, 2, 3, 4, 5, 6,
-               17, 18, 19, 20, 21, 22,
-               33, 34, 35, 36, 37, 38,
-               49, 50, 51, 52, 53, 54, },
-       .oobfree = {
-               {.offset = 8,
-                       .length = 8},
-               {.offset = 24,
-                       .length = 8},
-               {.offset = 40,
-                       .length = 8},
-               {.offset = 56,
-                       .length = 8},
-       }
+static int spinand_ooblayout_64_ecc(struct mtd_info *mtd, int section,
+                                   struct mtd_oob_region *oobregion)
+{
+       if (section > 3)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 1;
+       oobregion->length = 6;
+
+       return 0;
+}
+
+static int spinand_ooblayout_64_free(struct mtd_info *mtd, int section,
+                                    struct mtd_oob_region *oobregion)
+{
+       if (section > 3)
+               return -ERANGE;
+
+       oobregion->offset = (section * 16) + 8;
+       oobregion->length = 8;
+
+       return 0;
+}
+
+static const struct mtd_ooblayout_ops spinand_oob_64_ops = {
+       .ecc = spinand_ooblayout_64_ecc,
+       .free = spinand_ooblayout_64_free,
 };
 #endif
 
@@ -886,11 +896,11 @@ static int spinand_probe(struct spi_device *spi_nand)
 
        chip->ecc.strength = 1;
        chip->ecc.total = chip->ecc.steps * chip->ecc.bytes;
-       chip->ecc.layout = &spinand_oob_64;
        chip->ecc.read_page = spinand_read_page_hwecc;
        chip->ecc.write_page = spinand_write_page_hwecc;
 #else
        chip->ecc.mode  = NAND_ECC_SOFT;
+       chip->ecc.algo  = NAND_ECC_HAMMING;
        if (spinand_disable_ecc(spi_nand) < 0)
                dev_info(&spi_nand->dev, "%s: disable ecc failed!\n",
                         __func__);
@@ -912,6 +922,9 @@ static int spinand_probe(struct spi_device *spi_nand)
 
        mtd->dev.parent = &spi_nand->dev;
        mtd->oobsize = 64;
+#ifdef CONFIG_MTD_SPINAND_ONDIEECC
+       mtd_set_ooblayout(mtd, &spinand_oob_64_ops);
+#endif
 
        if (nand_scan(mtd, 1))
                return -ENXIO;
index 7b6d74f0c72f630835f52c370f2fb3c5a113e612..476c0e3a7150694b258e40787f303d6b46c29c17 100644 (file)
@@ -75,7 +75,7 @@ struct virtio_balloon {
 
        /* The array of pfns we tell the Host about. */
        unsigned int num_pfns;
-       u32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
+       __virtio32 pfns[VIRTIO_BALLOON_ARRAY_PFNS_MAX];
 
        /* Memory statistics */
        struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR];
@@ -127,14 +127,16 @@ static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
 
 }
 
-static void set_page_pfns(u32 pfns[], struct page *page)
+static void set_page_pfns(struct virtio_balloon *vb,
+                         __virtio32 pfns[], struct page *page)
 {
        unsigned int i;
 
        /* Set balloon pfns pointing at this page.
         * Note that the first pfn points at start of the page. */
        for (i = 0; i < VIRTIO_BALLOON_PAGES_PER_PAGE; i++)
-               pfns[i] = page_to_balloon_pfn(page) + i;
+               pfns[i] = cpu_to_virtio32(vb->vdev,
+                                         page_to_balloon_pfn(page) + i);
 }
 
 static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
@@ -158,7 +160,7 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
                        msleep(200);
                        break;
                }
-               set_page_pfns(vb->pfns + vb->num_pfns, page);
+               set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
                vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
                if (!virtio_has_feature(vb->vdev,
                                        VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
@@ -177,10 +179,12 @@ static unsigned fill_balloon(struct virtio_balloon *vb, size_t num)
 static void release_pages_balloon(struct virtio_balloon *vb)
 {
        unsigned int i;
+       struct page *page;
 
        /* Find pfns pointing at start of each page, get pages and free them. */
        for (i = 0; i < vb->num_pfns; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
-               struct page *page = balloon_pfn_to_page(vb->pfns[i]);
+               page = balloon_pfn_to_page(virtio32_to_cpu(vb->vdev,
+                                                          vb->pfns[i]));
                if (!virtio_has_feature(vb->vdev,
                                        VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
                        adjust_managed_page_count(page, 1);
@@ -203,7 +207,7 @@ static unsigned leak_balloon(struct virtio_balloon *vb, size_t num)
                page = balloon_page_dequeue(vb_dev_info);
                if (!page)
                        break;
-               set_page_pfns(vb->pfns + vb->num_pfns, page);
+               set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
                vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
        }
 
@@ -471,13 +475,13 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
        __count_vm_event(BALLOON_MIGRATE);
        spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
        vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
-       set_page_pfns(vb->pfns, newpage);
+       set_page_pfns(vb, vb->pfns, newpage);
        tell_host(vb, vb->inflate_vq);
 
        /* balloon's page migration 2nd step -- deflate "page" */
        balloon_page_delete(page);
        vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
-       set_page_pfns(vb->pfns, page);
+       set_page_pfns(vb, vb->pfns, page);
        tell_host(vb, vb->deflate_vq);
 
        mutex_unlock(&vb->balloon_lock);
index 9b7a35c9e51ddd5a9d3bdb3319cfb9f1a35ff627..030e91b38e32bcf077713e31b7cc56a5a35e5924 100644 (file)
@@ -8,6 +8,7 @@ nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_features.o                      := $(nostackp)
 
 CFLAGS_efi.o                           += -fshort-wchar
+LDFLAGS                                        += $(call ld-option, --no-wchar-size-warning)
 
 dom0-$(CONFIG_PCI) += pci.o
 dom0-$(CONFIG_USB_SUPPORT) += dbgp.o
index cb7138c97c692da92b71af1e6adc6539020702b4..71d49a95f8c0244f30c937b5d9275f0a4caede28 100644 (file)
@@ -487,7 +487,8 @@ static void eoi_pirq(struct irq_data *data)
        if (!VALID_EVTCHN(evtchn))
                return;
 
-       if (unlikely(irqd_is_setaffinity_pending(data))) {
+       if (unlikely(irqd_is_setaffinity_pending(data)) &&
+           likely(!irqd_irq_disabled(data))) {
                int masked = test_and_set_mask(evtchn);
 
                clear_evtchn(evtchn);
@@ -1370,7 +1371,8 @@ static void ack_dynirq(struct irq_data *data)
        if (!VALID_EVTCHN(evtchn))
                return;
 
-       if (unlikely(irqd_is_setaffinity_pending(data))) {
+       if (unlikely(irqd_is_setaffinity_pending(data)) &&
+           likely(!irqd_irq_disabled(data))) {
                int masked = test_and_set_mask(evtchn);
 
                clear_evtchn(evtchn);
index dc495383ad7335b2022f65df051700ca180de7d3..67939578cd6d0744bfc800e92bfc8f642b2cc7f5 100644 (file)
@@ -748,7 +748,7 @@ static long gntdev_ioctl_notify(struct gntdev_priv *priv, void __user *u)
        return rc;
 }
 
-#define GNTDEV_COPY_BATCH 24
+#define GNTDEV_COPY_BATCH 16
 
 struct gntdev_copy_batch {
        struct gnttab_copy ops[GNTDEV_COPY_BATCH];
index 8754e9aa14ad2ee9b37598ffd517235a9266b572..be6e48b0a46c269d55b4befcdedaf1750e1e233f 100644 (file)
@@ -936,6 +936,8 @@ static int compat_filldir(struct dir_context *ctx, const char *name, int namlen,
        }
        dirent = buf->previous;
        if (dirent) {
+               if (signal_pending(current))
+                       return -EINTR;
                if (__put_user(offset, &dirent->d_off))
                        goto efault;
        }
@@ -1020,6 +1022,8 @@ static int compat_filldir64(struct dir_context *ctx, const char *name,
        dirent = buf->previous;
 
        if (dirent) {
+               if (signal_pending(current))
+                       return -EINTR;
                if (__put_user_unaligned(offset, &dirent->d_off))
                        goto efault;
        }
index a345c168acaae4956dad1cba8707061b5d22f534..7d9df93b3a149588fa7a51da453607f01fa7e634 100644 (file)
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -676,7 +676,7 @@ int __dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf,
        if (error)
                goto unlock_page;
 
-       if (!buffer_mapped(&bh) && !buffer_unwritten(&bh) && !vmf->cow_page) {
+       if (!buffer_mapped(&bh) && !vmf->cow_page) {
                if (vmf->flags & FAULT_FLAG_WRITE) {
                        error = get_block(inode, block, &bh, 1);
                        count_vm_event(PGMAJFAULT);
index fe1f50fe764ff9238354e2e30491c6e1e6d149b9..3020fd70c392d1f2b55913e374ed11831b2aa967 100644 (file)
@@ -610,7 +610,8 @@ int ext4_should_retry_alloc(struct super_block *sb, int *retries)
 
        jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
 
-       return jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
+       jbd2_journal_force_commit_nested(EXT4_SB(sb)->s_journal);
+       return 1;
 }
 
 /*
index 5d00bf0602545f9e60e7b27790df2bd868285dbc..68323e3da3fa889fdbfa6e3e0b6e8736da11ca36 100644 (file)
@@ -150,6 +150,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
        while (ctx->pos < inode->i_size) {
                struct ext4_map_blocks map;
 
+               if (fatal_signal_pending(current)) {
+                       err = -ERESTARTSYS;
+                       goto errout;
+               }
+               cond_resched();
                map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb);
                map.m_len = 1;
                err = ext4_map_blocks(NULL, inode, &map, 0);
index 72f4c9e00e975974c7a20a4e24ff9b9ea2f8e03d..b84aa1ca480a9564e51d61bc2a0d782c8de104ef 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/ratelimit.h>
 #include <crypto/hash.h>
 #include <linux/falloc.h>
+#include <linux/percpu-rwsem.h>
 #ifdef __KERNEL__
 #include <linux/compat.h>
 #endif
@@ -581,6 +582,9 @@ enum {
 #define EXT4_GET_BLOCKS_ZERO                   0x0200
 #define EXT4_GET_BLOCKS_CREATE_ZERO            (EXT4_GET_BLOCKS_CREATE |\
                                        EXT4_GET_BLOCKS_ZERO)
+       /* Caller will submit data before dropping transaction handle. This
+        * allows jbd2 to avoid submitting data before commit. */
+#define EXT4_GET_BLOCKS_IO_SUBMIT              0x0400
 
 /*
  * The bit position of these flags must not overlap with any of the
@@ -1505,6 +1509,9 @@ struct ext4_sb_info {
        struct ratelimit_state s_err_ratelimit_state;
        struct ratelimit_state s_warning_ratelimit_state;
        struct ratelimit_state s_msg_ratelimit_state;
+
+       /* Barrier between changing inodes' journal flags and writepages ops. */
+       struct percpu_rw_semaphore s_journal_flag_rwsem;
 };
 
 static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
@@ -1549,7 +1556,6 @@ enum {
        EXT4_STATE_DIOREAD_LOCK,        /* Disable support for dio read
                                           nolocking */
        EXT4_STATE_MAY_INLINE_DATA,     /* may have in-inode data */
-       EXT4_STATE_ORDERED_MODE,        /* data=ordered mode */
        EXT4_STATE_EXT_PRECACHED,       /* extents have been precached */
 };
 
@@ -2521,8 +2527,8 @@ struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
 struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
 int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
                             struct buffer_head *bh_result, int create);
-int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
-                           struct buffer_head *bh_result, int create);
+int ext4_dax_get_block(struct inode *inode, sector_t iblock,
+                      struct buffer_head *bh_result, int create);
 int ext4_get_block(struct inode *inode, sector_t iblock,
                   struct buffer_head *bh_result, int create);
 int ext4_dio_get_block(struct inode *inode, sector_t iblock,
@@ -2581,7 +2587,6 @@ extern int ext4_get_next_extent(struct inode *inode, ext4_lblk_t lblk,
 /* indirect.c */
 extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
                                struct ext4_map_blocks *map, int flags);
-extern ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter);
 extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
 extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
 extern void ext4_ind_truncate(handle_t *, struct inode *inode);
@@ -3329,6 +3334,13 @@ static inline void ext4_clear_io_unwritten_flag(ext4_io_end_t *io_end)
        }
 }
 
+static inline bool ext4_aligned_io(struct inode *inode, loff_t off, loff_t len)
+{
+       int blksize = 1 << inode->i_blkbits;
+
+       return IS_ALIGNED(off, blksize) && IS_ALIGNED(len, blksize);
+}
+
 #endif /* __KERNEL__ */
 
 #define EFSBADCRC      EBADMSG         /* Bad CRC detected */
index 5f58462110953dc61c9bd85101acd69c33a51331..09c1ef38cbe6aaff2c03185b31da20255df8990b 100644 (file)
@@ -359,10 +359,21 @@ static inline int ext4_journal_force_commit(journal_t *journal)
        return 0;
 }
 
-static inline int ext4_jbd2_file_inode(handle_t *handle, struct inode *inode)
+static inline int ext4_jbd2_inode_add_write(handle_t *handle,
+                                           struct inode *inode)
 {
        if (ext4_handle_valid(handle))
-               return jbd2_journal_file_inode(handle, EXT4_I(inode)->jinode);
+               return jbd2_journal_inode_add_write(handle,
+                                                   EXT4_I(inode)->jinode);
+       return 0;
+}
+
+static inline int ext4_jbd2_inode_add_wait(handle_t *handle,
+                                          struct inode *inode)
+{
+       if (ext4_handle_valid(handle))
+               return jbd2_journal_inode_add_wait(handle,
+                                                  EXT4_I(inode)->jinode);
        return 0;
 }
 
index 95bf4679ac5485ef35240495806a034b1fdf86bf..2a2eef9c14e4b66212597b651bd87aa9f3ed6b7c 100644 (file)
@@ -120,9 +120,14 @@ static int ext4_ext_truncate_extend_restart(handle_t *handle,
 
        if (!ext4_handle_valid(handle))
                return 0;
-       if (handle->h_buffer_credits > needed)
+       if (handle->h_buffer_credits >= needed)
                return 0;
-       err = ext4_journal_extend(handle, needed);
+       /*
+        * If we need to extend the journal get a few extra blocks
+        * while we're at it for efficiency's sake.
+        */
+       needed += 3;
+       err = ext4_journal_extend(handle, needed - handle->h_buffer_credits);
        if (err <= 0)
                return err;
        err = ext4_truncate_restart_trans(handle, inode, needed);
@@ -907,13 +912,6 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
 
                eh = ext_block_hdr(bh);
                ppos++;
-               if (unlikely(ppos > depth)) {
-                       put_bh(bh);
-                       EXT4_ERROR_INODE(inode,
-                                        "ppos %d > depth %d", ppos, depth);
-                       ret = -EFSCORRUPTED;
-                       goto err;
-               }
                path[ppos].p_bh = bh;
                path[ppos].p_hdr = eh;
        }
@@ -2583,7 +2581,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
                }
        } else
                ext4_error(sbi->s_sb, "strange request: removal(2) "
-                          "%u-%u from %u:%u\n",
+                          "%u-%u from %u:%u",
                           from, to, le32_to_cpu(ex->ee_block), ee_len);
        return 0;
 }
@@ -3738,7 +3736,7 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle,
        if (ee_block != map->m_lblk || ee_len > map->m_len) {
 #ifdef EXT4_DEBUG
                ext4_warning("Inode (%ld) finished: extent logical block %llu,"
-                            " len %u; IO logical block %llu, len %u\n",
+                            " len %u; IO logical block %llu, len %u",
                             inode->i_ino, (unsigned long long)ee_block, ee_len,
                             (unsigned long long)map->m_lblk, map->m_len);
 #endif
index e38b987ac7f5f709abb8ea1c8fb9f83ca32ce723..37e059202cd2fa333dff053b327d8faf85f9d4ac 100644 (file)
@@ -707,7 +707,7 @@ int ext4_es_insert_extent(struct inode *inode, ext4_lblk_t lblk,
            (status & EXTENT_STATUS_WRITTEN)) {
                ext4_warning(inode->i_sb, "Inserting extent [%u/%u] as "
                                " delayed and written which can potentially "
-                               " cause data loss.\n", lblk, len);
+                               " cause data loss.", lblk, len);
                WARN_ON(1);
        }
 
index 00ff6912adb305f1b939e695257abd10f74a3616..d478110c32a619fcdf0e63095e3929bdd55e6299 100644 (file)
@@ -202,7 +202,7 @@ static int ext4_dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        if (IS_ERR(handle))
                result = VM_FAULT_SIGBUS;
        else
-               result = __dax_fault(vma, vmf, ext4_dax_mmap_get_block, NULL);
+               result = __dax_fault(vma, vmf, ext4_dax_get_block, NULL);
 
        if (write) {
                if (!IS_ERR(handle))
@@ -238,7 +238,7 @@ static int ext4_dax_pmd_fault(struct vm_area_struct *vma, unsigned long addr,
                result = VM_FAULT_SIGBUS;
        else
                result = __dax_pmd_fault(vma, addr, pmd, flags,
-                               ext4_dax_mmap_get_block, NULL);
+                                        ext4_dax_get_block, NULL);
 
        if (write) {
                if (!IS_ERR(handle))
@@ -373,7 +373,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
        if (ext4_encrypted_inode(d_inode(dir)) &&
            !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {
                ext4_warning(inode->i_sb,
-                            "Inconsistent encryption contexts: %lu/%lu\n",
+                            "Inconsistent encryption contexts: %lu/%lu",
                             (unsigned long) d_inode(dir)->i_ino,
                             (unsigned long) inode->i_ino);
                dput(dir);
index 237b877d316d1174687341abb34d49f05b56b127..3da4cf8d18b68ccae8b93984ee1d0d154903a863 100644 (file)
@@ -1150,25 +1150,20 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
        unsigned long max_ino = le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count);
        ext4_group_t block_group;
        int bit;
-       struct buffer_head *bitmap_bh;
+       struct buffer_head *bitmap_bh = NULL;
        struct inode *inode = NULL;
-       long err = -EIO;
+       int err = -EFSCORRUPTED;
 
-       /* Error cases - e2fsck has already cleaned up for us */
-       if (ino > max_ino) {
-               ext4_warning(sb, "bad orphan ino %lu!  e2fsck was run?", ino);
-               err = -EFSCORRUPTED;
-               goto error;
-       }
+       if (ino < EXT4_FIRST_INO(sb) || ino > max_ino)
+               goto bad_orphan;
 
        block_group = (ino - 1) / EXT4_INODES_PER_GROUP(sb);
        bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
        bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
        if (IS_ERR(bitmap_bh)) {
-               err = PTR_ERR(bitmap_bh);
-               ext4_warning(sb, "inode bitmap error %ld for orphan %lu",
-                            ino, err);
-               goto error;
+               ext4_error(sb, "inode bitmap error %ld for orphan %lu",
+                          ino, PTR_ERR(bitmap_bh));
+               return (struct inode *) bitmap_bh;
        }
 
        /* Having the inode bit set should be a 100% indicator that this
@@ -1179,15 +1174,21 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
                goto bad_orphan;
 
        inode = ext4_iget(sb, ino);
-       if (IS_ERR(inode))
-               goto iget_failed;
+       if (IS_ERR(inode)) {
+               err = PTR_ERR(inode);
+               ext4_error(sb, "couldn't read orphan inode %lu (err %d)",
+                          ino, err);
+               return inode;
+       }
 
        /*
-        * If the orphans has i_nlinks > 0 then it should be able to be
-        * truncated, otherwise it won't be removed from the orphan list
-        * during processing and an infinite loop will result.
+        * If the orphans has i_nlinks > 0 then it should be able to
+        * be truncated, otherwise it won't be removed from the orphan
+        * list during processing and an infinite loop will result.
+        * Similarly, it must not be a bad inode.
         */
-       if (inode->i_nlink && !ext4_can_truncate(inode))
+       if ((inode->i_nlink && !ext4_can_truncate(inode)) ||
+           is_bad_inode(inode))
                goto bad_orphan;
 
        if (NEXT_ORPHAN(inode) > max_ino)
@@ -1195,29 +1196,25 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
        brelse(bitmap_bh);
        return inode;
 
-iget_failed:
-       err = PTR_ERR(inode);
-       inode = NULL;
 bad_orphan:
-       ext4_warning(sb, "bad orphan inode %lu!  e2fsck was run?", ino);
-       printk(KERN_WARNING "ext4_test_bit(bit=%d, block=%llu) = %d\n",
-              bit, (unsigned long long)bitmap_bh->b_blocknr,
-              ext4_test_bit(bit, bitmap_bh->b_data));
-       printk(KERN_WARNING "inode=%p\n", inode);
+       ext4_error(sb, "bad orphan inode %lu", ino);
+       if (bitmap_bh)
+               printk(KERN_ERR "ext4_test_bit(bit=%d, block=%llu) = %d\n",
+                      bit, (unsigned long long)bitmap_bh->b_blocknr,
+                      ext4_test_bit(bit, bitmap_bh->b_data));
        if (inode) {
-               printk(KERN_WARNING "is_bad_inode(inode)=%d\n",
+               printk(KERN_ERR "is_bad_inode(inode)=%d\n",
                       is_bad_inode(inode));
-               printk(KERN_WARNING "NEXT_ORPHAN(inode)=%u\n",
+               printk(KERN_ERR "NEXT_ORPHAN(inode)=%u\n",
                       NEXT_ORPHAN(inode));
-               printk(KERN_WARNING "max_ino=%lu\n", max_ino);
-               printk(KERN_WARNING "i_nlink=%u\n", inode->i_nlink);
+               printk(KERN_ERR "max_ino=%lu\n", max_ino);
+               printk(KERN_ERR "i_nlink=%u\n", inode->i_nlink);
                /* Avoid freeing blocks if we got a bad deleted inode */
                if (inode->i_nlink == 0)
                        inode->i_blocks = 0;
                iput(inode);
        }
        brelse(bitmap_bh);
-error:
        return ERR_PTR(err);
 }
 
index 627b7e8f9ef3714b4ed310c4fd98faae03869dee..bc15c2c17633079a54de855baf1272b0124f19eb 100644 (file)
@@ -648,133 +648,6 @@ out:
        return err;
 }
 
-/*
- * O_DIRECT for ext3 (or indirect map) based files
- *
- * If the O_DIRECT write will extend the file then add this inode to the
- * orphan list.  So recovery will truncate it back to the original size
- * if the machine crashes during the write.
- *
- * If the O_DIRECT write is intantiating holes inside i_size and the machine
- * crashes then stale disk data _may_ be exposed inside the file. But current
- * VFS code falls back into buffered path in that case so we are safe.
- */
-ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
-{
-       struct file *file = iocb->ki_filp;
-       struct inode *inode = file->f_mapping->host;
-       struct ext4_inode_info *ei = EXT4_I(inode);
-       loff_t offset = iocb->ki_pos;
-       handle_t *handle;
-       ssize_t ret;
-       int orphan = 0;
-       size_t count = iov_iter_count(iter);
-       int retries = 0;
-
-       if (iov_iter_rw(iter) == WRITE) {
-               loff_t final_size = offset + count;
-
-               if (final_size > inode->i_size) {
-                       /* Credits for sb + inode write */
-                       handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
-                       if (IS_ERR(handle)) {
-                               ret = PTR_ERR(handle);
-                               goto out;
-                       }
-                       ret = ext4_orphan_add(handle, inode);
-                       if (ret) {
-                               ext4_journal_stop(handle);
-                               goto out;
-                       }
-                       orphan = 1;
-                       ei->i_disksize = inode->i_size;
-                       ext4_journal_stop(handle);
-               }
-       }
-
-retry:
-       if (iov_iter_rw(iter) == READ && ext4_should_dioread_nolock(inode)) {
-               /*
-                * Nolock dioread optimization may be dynamically disabled
-                * via ext4_inode_block_unlocked_dio(). Check inode's state
-                * while holding extra i_dio_count ref.
-                */
-               inode_dio_begin(inode);
-               smp_mb();
-               if (unlikely(ext4_test_inode_state(inode,
-                                                   EXT4_STATE_DIOREAD_LOCK))) {
-                       inode_dio_end(inode);
-                       goto locked;
-               }
-               if (IS_DAX(inode))
-                       ret = dax_do_io(iocb, inode, iter,
-                                       ext4_dio_get_block, NULL, 0);
-               else
-                       ret = __blockdev_direct_IO(iocb, inode,
-                                                  inode->i_sb->s_bdev, iter,
-                                                  ext4_dio_get_block,
-                                                  NULL, NULL, 0);
-               inode_dio_end(inode);
-       } else {
-locked:
-               if (IS_DAX(inode))
-                       ret = dax_do_io(iocb, inode, iter,
-                                       ext4_dio_get_block, NULL, DIO_LOCKING);
-               else
-                       ret = blockdev_direct_IO(iocb, inode, iter,
-                                                ext4_dio_get_block);
-
-               if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
-                       loff_t isize = i_size_read(inode);
-                       loff_t end = offset + count;
-
-                       if (end > isize)
-                               ext4_truncate_failed_write(inode);
-               }
-       }
-       if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
-               goto retry;
-
-       if (orphan) {
-               int err;
-
-               /* Credits for sb + inode write */
-               handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
-               if (IS_ERR(handle)) {
-                       /* This is really bad luck. We've written the data
-                        * but cannot extend i_size. Bail out and pretend
-                        * the write failed... */
-                       ret = PTR_ERR(handle);
-                       if (inode->i_nlink)
-                               ext4_orphan_del(NULL, inode);
-
-                       goto out;
-               }
-               if (inode->i_nlink)
-                       ext4_orphan_del(handle, inode);
-               if (ret > 0) {
-                       loff_t end = offset + ret;
-                       if (end > inode->i_size) {
-                               ei->i_disksize = end;
-                               i_size_write(inode, end);
-                               /*
-                                * We're going to return a positive `ret'
-                                * here due to non-zero-length I/O, so there's
-                                * no way of reporting error returns from
-                                * ext4_mark_inode_dirty() to userspace.  So
-                                * ignore it.
-                                */
-                               ext4_mark_inode_dirty(handle, inode);
-                       }
-               }
-               err = ext4_journal_stop(handle);
-               if (ret == 0)
-                       ret = err;
-       }
-out:
-       return ret;
-}
-
 /*
  * Calculate the number of metadata blocks need to reserve
  * to allocate a new block at @lblocks for non extent file based file
index 7bc6c855cc18ca992ac3830d3b3010e63597bc5d..ff7538c26992ea34f429de3d4d38a9a7f8f61262 100644 (file)
@@ -1780,7 +1780,7 @@ int empty_inline_dir(struct inode *dir, int *has_inline_data)
                        ext4_warning(dir->i_sb,
                                     "bad inline directory (dir #%lu) - "
                                     "inode %u, rec_len %u, name_len %d"
-                                    "inline size %d\n",
+                                    "inline size %d",
                                     dir->i_ino, le32_to_cpu(de->inode),
                                     le16_to_cpu(de->rec_len), de->name_len,
                                     inline_size);
index 79b298d397b43b1fadabe82fdeebe2cf3e0cb735..f7140ca66e3bf2751eb8103a37f249b49521b6ff 100644 (file)
@@ -684,6 +684,24 @@ out_sem:
                ret = check_block_validity(inode, map);
                if (ret != 0)
                        return ret;
+
+               /*
+                * Inodes with freshly allocated blocks where contents will be
+                * visible after transaction commit must be on transaction's
+                * ordered data list.
+                */
+               if (map->m_flags & EXT4_MAP_NEW &&
+                   !(map->m_flags & EXT4_MAP_UNWRITTEN) &&
+                   !(flags & EXT4_GET_BLOCKS_ZERO) &&
+                   !IS_NOQUOTA(inode) &&
+                   ext4_should_order_data(inode)) {
+                       if (flags & EXT4_GET_BLOCKS_IO_SUBMIT)
+                               ret = ext4_jbd2_inode_add_wait(handle, inode);
+                       else
+                               ret = ext4_jbd2_inode_add_write(handle, inode);
+                       if (ret)
+                               return ret;
+               }
        }
        return retval;
 }
@@ -1289,15 +1307,6 @@ static int ext4_write_end(struct file *file,
        int i_size_changed = 0;
 
        trace_ext4_write_end(inode, pos, len, copied);
-       if (ext4_test_inode_state(inode, EXT4_STATE_ORDERED_MODE)) {
-               ret = ext4_jbd2_file_inode(handle, inode);
-               if (ret) {
-                       unlock_page(page);
-                       put_page(page);
-                       goto errout;
-               }
-       }
-
        if (ext4_has_inline_data(inode)) {
                ret = ext4_write_inline_data_end(inode, pos, len,
                                                 copied, page);
@@ -2313,7 +2322,8 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd)
         * the data was copied into the page cache.
         */
        get_blocks_flags = EXT4_GET_BLOCKS_CREATE |
-                          EXT4_GET_BLOCKS_METADATA_NOFAIL;
+                          EXT4_GET_BLOCKS_METADATA_NOFAIL |
+                          EXT4_GET_BLOCKS_IO_SUBMIT;
        dioread_nolock = ext4_should_dioread_nolock(inode);
        if (dioread_nolock)
                get_blocks_flags |= EXT4_GET_BLOCKS_IO_CREATE_EXT;
@@ -2602,11 +2612,14 @@ static int ext4_writepages(struct address_space *mapping,
        struct blk_plug plug;
        bool give_up_on_write = false;
 
+       percpu_down_read(&sbi->s_journal_flag_rwsem);
        trace_ext4_writepages(inode, wbc);
 
-       if (dax_mapping(mapping))
-               return dax_writeback_mapping_range(mapping, inode->i_sb->s_bdev,
-                                                  wbc);
+       if (dax_mapping(mapping)) {
+               ret = dax_writeback_mapping_range(mapping, inode->i_sb->s_bdev,
+                                                 wbc);
+               goto out_writepages;
+       }
 
        /*
         * No pages to write? This is mainly a kludge to avoid starting
@@ -2776,6 +2789,7 @@ retry:
 out_writepages:
        trace_ext4_writepages_result(inode, wbc, ret,
                                     nr_to_write - wbc->nr_to_write);
+       percpu_up_read(&sbi->s_journal_flag_rwsem);
        return ret;
 }
 
@@ -3215,75 +3229,52 @@ static int ext4_releasepage(struct page *page, gfp_t wait)
 }
 
 #ifdef CONFIG_FS_DAX
-int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
-                           struct buffer_head *bh_result, int create)
+/*
+ * Get block function for DAX IO and mmap faults. It takes care of converting
+ * unwritten extents to written ones and initializes new / converted blocks
+ * to zeros.
+ */
+int ext4_dax_get_block(struct inode *inode, sector_t iblock,
+                      struct buffer_head *bh_result, int create)
 {
-       int ret, err;
-       int credits;
-       struct ext4_map_blocks map;
-       handle_t *handle = NULL;
-       int flags = 0;
-
-       ext4_debug("ext4_dax_mmap_get_block: inode %lu, create flag %d\n",
-                  inode->i_ino, create);
-       map.m_lblk = iblock;
-       map.m_len = bh_result->b_size >> inode->i_blkbits;
-       credits = ext4_chunk_trans_blocks(inode, map.m_len);
-       if (create) {
-               flags |= EXT4_GET_BLOCKS_PRE_IO | EXT4_GET_BLOCKS_CREATE_ZERO;
-               handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, credits);
-               if (IS_ERR(handle)) {
-                       ret = PTR_ERR(handle);
-                       return ret;
-               }
-       }
+       int ret;
 
-       ret = ext4_map_blocks(handle, inode, &map, flags);
-       if (create) {
-               err = ext4_journal_stop(handle);
-               if (ret >= 0 && err < 0)
-                       ret = err;
-       }
-       if (ret <= 0)
-               goto out;
-       if (map.m_flags & EXT4_MAP_UNWRITTEN) {
-               int err2;
+       ext4_debug("inode %lu, create flag %d\n", inode->i_ino, create);
+       if (!create)
+               return _ext4_get_block(inode, iblock, bh_result, 0);
 
-               /*
-                * We are protected by i_mmap_sem so we know block cannot go
-                * away from under us even though we dropped i_data_sem.
-                * Convert extent to written and write zeros there.
-                *
-                * Note: We may get here even when create == 0.
-                */
-               handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, credits);
-               if (IS_ERR(handle)) {
-                       ret = PTR_ERR(handle);
-                       goto out;
-               }
+       ret = ext4_get_block_trans(inode, iblock, bh_result,
+                                  EXT4_GET_BLOCKS_PRE_IO |
+                                  EXT4_GET_BLOCKS_CREATE_ZERO);
+       if (ret < 0)
+               return ret;
 
-               err = ext4_map_blocks(handle, inode, &map,
-                     EXT4_GET_BLOCKS_CONVERT | EXT4_GET_BLOCKS_CREATE_ZERO);
-               if (err < 0)
-                       ret = err;
-               err2 = ext4_journal_stop(handle);
-               if (err2 < 0 && ret > 0)
-                       ret = err2;
-       }
-out:
-       WARN_ON_ONCE(ret == 0 && create);
-       if (ret > 0) {
-               map_bh(bh_result, inode->i_sb, map.m_pblk);
+       if (buffer_unwritten(bh_result)) {
                /*
-                * At least for now we have to clear BH_New so that DAX code
-                * doesn't attempt to zero blocks again in a racy way.
+                * We are protected by i_mmap_sem or i_mutex so we know block
+                * cannot go away from under us even though we dropped
+                * i_data_sem. Convert extent to written and write zeros there.
                 */
-               map.m_flags &= ~EXT4_MAP_NEW;
-               ext4_update_bh_state(bh_result, map.m_flags);
-               bh_result->b_size = map.m_len << inode->i_blkbits;
-               ret = 0;
+               ret = ext4_get_block_trans(inode, iblock, bh_result,
+                                          EXT4_GET_BLOCKS_CONVERT |
+                                          EXT4_GET_BLOCKS_CREATE_ZERO);
+               if (ret < 0)
+                       return ret;
        }
-       return ret;
+       /*
+        * At least for now we have to clear BH_New so that DAX code
+        * doesn't attempt to zero blocks again in a racy way.
+        */
+       clear_buffer_new(bh_result);
+       return 0;
+}
+#else
+/* Just define empty function, it will never get called. */
+int ext4_dax_get_block(struct inode *inode, sector_t iblock,
+                      struct buffer_head *bh_result, int create)
+{
+       BUG();
+       return 0;
 }
 #endif
 
@@ -3316,7 +3307,9 @@ static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
 }
 
 /*
- * For ext4 extent files, ext4 will do direct-io write to holes,
+ * Handling of direct IO writes.
+ *
+ * For ext4 extent files, ext4 will do direct-io write even to holes,
  * preallocated extents, and those write extend the file, no need to
  * fall back to buffered IO.
  *
@@ -3334,10 +3327,11 @@ static int ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
  * if the machine crashes during the write.
  *
  */
-static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
+static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter)
 {
        struct file *file = iocb->ki_filp;
        struct inode *inode = file->f_mapping->host;
+       struct ext4_inode_info *ei = EXT4_I(inode);
        ssize_t ret;
        loff_t offset = iocb->ki_pos;
        size_t count = iov_iter_count(iter);
@@ -3345,10 +3339,25 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
        get_block_t *get_block_func = NULL;
        int dio_flags = 0;
        loff_t final_size = offset + count;
+       int orphan = 0;
+       handle_t *handle;
 
-       /* Use the old path for reads and writes beyond i_size. */
-       if (iov_iter_rw(iter) != WRITE || final_size > inode->i_size)
-               return ext4_ind_direct_IO(iocb, iter);
+       if (final_size > inode->i_size) {
+               /* Credits for sb + inode write */
+               handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
+               if (IS_ERR(handle)) {
+                       ret = PTR_ERR(handle);
+                       goto out;
+               }
+               ret = ext4_orphan_add(handle, inode);
+               if (ret) {
+                       ext4_journal_stop(handle);
+                       goto out;
+               }
+               orphan = 1;
+               ei->i_disksize = inode->i_size;
+               ext4_journal_stop(handle);
+       }
 
        BUG_ON(iocb->private == NULL);
 
@@ -3357,8 +3366,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
         * conversion. This also disallows race between truncate() and
         * overwrite DIO as i_dio_count needs to be incremented under i_mutex.
         */
-       if (iov_iter_rw(iter) == WRITE)
-               inode_dio_begin(inode);
+       inode_dio_begin(inode);
 
        /* If we do a overwrite dio, i_mutex locking can be released */
        overwrite = *((int *)iocb->private);
@@ -3367,7 +3375,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
                inode_unlock(inode);
 
        /*
-        * We could direct write to holes and fallocate.
+        * For extent mapped files we could direct write to holes and fallocate.
         *
         * Allocated blocks to fill the hole are marked as unwritten to prevent
         * parallel buffered read to expose the stale data before DIO complete
@@ -3389,7 +3397,23 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
        iocb->private = NULL;
        if (overwrite)
                get_block_func = ext4_dio_get_block_overwrite;
-       else if (is_sync_kiocb(iocb)) {
+       else if (IS_DAX(inode)) {
+               /*
+                * We can avoid zeroing for aligned DAX writes beyond EOF. Other
+                * writes need zeroing either because they can race with page
+                * faults or because they use partial blocks.
+                */
+               if (round_down(offset, 1<<inode->i_blkbits) >= inode->i_size &&
+                   ext4_aligned_io(inode, offset, count))
+                       get_block_func = ext4_dio_get_block;
+               else
+                       get_block_func = ext4_dax_get_block;
+               dio_flags = DIO_LOCKING;
+       } else if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS) ||
+                  round_down(offset, 1 << inode->i_blkbits) >= inode->i_size) {
+               get_block_func = ext4_dio_get_block;
+               dio_flags = DIO_LOCKING | DIO_SKIP_HOLES;
+       } else if (is_sync_kiocb(iocb)) {
                get_block_func = ext4_dio_get_block_unwritten_sync;
                dio_flags = DIO_LOCKING;
        } else {
@@ -3399,10 +3423,10 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
 #ifdef CONFIG_EXT4_FS_ENCRYPTION
        BUG_ON(ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode));
 #endif
-       if (IS_DAX(inode))
+       if (IS_DAX(inode)) {
                ret = dax_do_io(iocb, inode, iter, get_block_func,
                                ext4_end_io_dio, dio_flags);
-       else
+       else
                ret = __blockdev_direct_IO(iocb, inode,
                                           inode->i_sb->s_bdev, iter,
                                           get_block_func,
@@ -3422,12 +3446,86 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
                ext4_clear_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
        }
 
-       if (iov_iter_rw(iter) == WRITE)
-               inode_dio_end(inode);
+       inode_dio_end(inode);
        /* take i_mutex locking again if we do a ovewrite dio */
        if (overwrite)
                inode_lock(inode);
 
+       if (ret < 0 && final_size > inode->i_size)
+               ext4_truncate_failed_write(inode);
+
+       /* Handle extending of i_size after direct IO write */
+       if (orphan) {
+               int err;
+
+               /* Credits for sb + inode write */
+               handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
+               if (IS_ERR(handle)) {
+                       /* This is really bad luck. We've written the data
+                        * but cannot extend i_size. Bail out and pretend
+                        * the write failed... */
+                       ret = PTR_ERR(handle);
+                       if (inode->i_nlink)
+                               ext4_orphan_del(NULL, inode);
+
+                       goto out;
+               }
+               if (inode->i_nlink)
+                       ext4_orphan_del(handle, inode);
+               if (ret > 0) {
+                       loff_t end = offset + ret;
+                       if (end > inode->i_size) {
+                               ei->i_disksize = end;
+                               i_size_write(inode, end);
+                               /*
+                                * We're going to return a positive `ret'
+                                * here due to non-zero-length I/O, so there's
+                                * no way of reporting error returns from
+                                * ext4_mark_inode_dirty() to userspace.  So
+                                * ignore it.
+                                */
+                               ext4_mark_inode_dirty(handle, inode);
+                       }
+               }
+               err = ext4_journal_stop(handle);
+               if (ret == 0)
+                       ret = err;
+       }
+out:
+       return ret;
+}
+
+static ssize_t ext4_direct_IO_read(struct kiocb *iocb, struct iov_iter *iter)
+{
+       int unlocked = 0;
+       struct inode *inode = iocb->ki_filp->f_mapping->host;
+       ssize_t ret;
+
+       if (ext4_should_dioread_nolock(inode)) {
+               /*
+                * Nolock dioread optimization may be dynamically disabled
+                * via ext4_inode_block_unlocked_dio(). Check inode's state
+                * while holding extra i_dio_count ref.
+                */
+               inode_dio_begin(inode);
+               smp_mb();
+               if (unlikely(ext4_test_inode_state(inode,
+                                                   EXT4_STATE_DIOREAD_LOCK)))
+                       inode_dio_end(inode);
+               else
+                       unlocked = 1;
+       }
+       if (IS_DAX(inode)) {
+               ret = dax_do_io(iocb, inode, iter, ext4_dio_get_block,
+                               NULL, unlocked ? 0 : DIO_LOCKING);
+       } else {
+               ret = __blockdev_direct_IO(iocb, inode, inode->i_sb->s_bdev,
+                                          iter, ext4_dio_get_block,
+                                          NULL, NULL,
+                                          unlocked ? 0 : DIO_LOCKING);
+       }
+       if (unlocked)
+               inode_dio_end(inode);
        return ret;
 }
 
@@ -3455,10 +3553,10 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
                return 0;
 
        trace_ext4_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
-       if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
-               ret = ext4_ext_direct_IO(iocb, iter);
+       if (iov_iter_rw(iter) == READ)
+               ret = ext4_direct_IO_read(iocb, iter);
        else
-               ret = ext4_ind_direct_IO(iocb, iter);
+               ret = ext4_direct_IO_write(iocb, iter);
        trace_ext4_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), ret);
        return ret;
 }
@@ -3534,10 +3632,7 @@ void ext4_set_aops(struct inode *inode)
 {
        switch (ext4_inode_journal_mode(inode)) {
        case EXT4_INODE_ORDERED_DATA_MODE:
-               ext4_set_inode_state(inode, EXT4_STATE_ORDERED_MODE);
-               break;
        case EXT4_INODE_WRITEBACK_DATA_MODE:
-               ext4_clear_inode_state(inode, EXT4_STATE_ORDERED_MODE);
                break;
        case EXT4_INODE_JOURNAL_DATA_MODE:
                inode->i_mapping->a_ops = &ext4_journalled_aops;
@@ -3630,8 +3725,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
        } else {
                err = 0;
                mark_buffer_dirty(bh);
-               if (ext4_test_inode_state(inode, EXT4_STATE_ORDERED_MODE))
-                       err = ext4_jbd2_file_inode(handle, inode);
+               if (ext4_should_order_data(inode))
+                       err = ext4_jbd2_inode_add_write(handle, inode);
        }
 
 unlock:
@@ -5429,6 +5524,7 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
        journal_t *journal;
        handle_t *handle;
        int err;
+       struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
 
        /*
         * We have to be very careful here: changing a data block's
@@ -5445,22 +5541,30 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
                return 0;
        if (is_journal_aborted(journal))
                return -EROFS;
-       /* We have to allocate physical blocks for delalloc blocks
-        * before flushing journal. otherwise delalloc blocks can not
-        * be allocated any more. even more truncate on delalloc blocks
-        * could trigger BUG by flushing delalloc blocks in journal.
-        * There is no delalloc block in non-journal data mode.
-        */
-       if (val && test_opt(inode->i_sb, DELALLOC)) {
-               err = ext4_alloc_da_blocks(inode);
-               if (err < 0)
-                       return err;
-       }
 
        /* Wait for all existing dio workers */
        ext4_inode_block_unlocked_dio(inode);
        inode_dio_wait(inode);
 
+       /*
+        * Before flushing the journal and switching inode's aops, we have
+        * to flush all dirty data the inode has. There can be outstanding
+        * delayed allocations, there can be unwritten extents created by
+        * fallocate or buffered writes in dioread_nolock mode covered by
+        * dirty data which can be converted only after flushing the dirty
+        * data (and journalled aops don't know how to handle these cases).
+        */
+       if (val) {
+               down_write(&EXT4_I(inode)->i_mmap_sem);
+               err = filemap_write_and_wait(inode->i_mapping);
+               if (err < 0) {
+                       up_write(&EXT4_I(inode)->i_mmap_sem);
+                       ext4_inode_resume_unlocked_dio(inode);
+                       return err;
+               }
+       }
+
+       percpu_down_write(&sbi->s_journal_flag_rwsem);
        jbd2_journal_lock_updates(journal);
 
        /*
@@ -5477,6 +5581,7 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
                err = jbd2_journal_flush(journal);
                if (err < 0) {
                        jbd2_journal_unlock_updates(journal);
+                       percpu_up_write(&sbi->s_journal_flag_rwsem);
                        ext4_inode_resume_unlocked_dio(inode);
                        return err;
                }
@@ -5485,6 +5590,10 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
        ext4_set_aops(inode);
 
        jbd2_journal_unlock_updates(journal);
+       percpu_up_write(&sbi->s_journal_flag_rwsem);
+
+       if (val)
+               up_write(&EXT4_I(inode)->i_mmap_sem);
        ext4_inode_resume_unlocked_dio(inode);
 
        /* Finally we can mark the inode as dirty. */
index 7497f50cb29336add4aa7ef17ddf5176193493d1..28cc412852afba41650ffeee2e713e2345b60511 100644 (file)
@@ -365,7 +365,7 @@ static int ext4_ioctl_setproject(struct file *filp, __u32 projid)
                struct dquot *transfer_to[MAXQUOTAS] = { };
 
                transfer_to[PRJQUOTA] = dqget(sb, make_kqid_projid(kprojid));
-               if (transfer_to[PRJQUOTA]) {
+               if (!IS_ERR(transfer_to[PRJQUOTA])) {
                        err = __dquot_transfer(inode, transfer_to);
                        dqput(transfer_to[PRJQUOTA]);
                        if (err)
index eeeade76012ecf66f59340332d6838451b4e6eda..c1ab3ec30423f65878789c6602cb63dc82b6746f 100644 (file)
@@ -1266,6 +1266,7 @@ static void ext4_mb_unload_buddy(struct ext4_buddy *e4b)
 static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
 {
        int order = 1;
+       int bb_incr = 1 << (e4b->bd_blkbits - 1);
        void *bb;
 
        BUG_ON(e4b->bd_bitmap == e4b->bd_buddy);
@@ -1278,7 +1279,8 @@ static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
                        /* this block is part of buddy of order 'order' */
                        return order;
                }
-               bb += 1 << (e4b->bd_blkbits - order);
+               bb += bb_incr;
+               bb_incr >>= 1;
                order++;
        }
        return 0;
@@ -2583,7 +2585,7 @@ int ext4_mb_init(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        unsigned i, j;
-       unsigned offset;
+       unsigned offset, offset_incr;
        unsigned max;
        int ret;
 
@@ -2612,11 +2614,13 @@ int ext4_mb_init(struct super_block *sb)
 
        i = 1;
        offset = 0;
+       offset_incr = 1 << (sb->s_blocksize_bits - 1);
        max = sb->s_blocksize << 2;
        do {
                sbi->s_mb_offsets[i] = offset;
                sbi->s_mb_maxs[i] = max;
-               offset += 1 << (sb->s_blocksize_bits - i);
+               offset += offset_incr;
+               offset_incr = offset_incr >> 1;
                max = max >> 1;
                i++;
        } while (i <= sb->s_blocksize_bits + 1);
@@ -4935,7 +4939,7 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
         * boundary.
         */
        if (bit + count > EXT4_BLOCKS_PER_GROUP(sb)) {
-               ext4_warning(sb, "too much blocks added to group %u\n",
+               ext4_warning(sb, "too much blocks added to group %u",
                             block_group);
                err = -EINVAL;
                goto error_return;
index 24445275d330e07cb38623e0d548989a2a7621c4..23d436d6f8b8fe1c0e69cbe2a957dcd141448abb 100644 (file)
@@ -121,7 +121,7 @@ void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
        __ext4_warning(sb, function, line, "%s", msg);
        __ext4_warning(sb, function, line,
                       "MMP failure info: last update time: %llu, last update "
-                      "node: %s, last update device: %s\n",
+                      "node: %s, last update device: %s",
                       (long long unsigned int) le64_to_cpu(mmp->mmp_time),
                       mmp->mmp_nodename, mmp->mmp_bdevname);
 }
@@ -353,7 +353,7 @@ skip:
         * wait for MMP interval and check mmp_seq.
         */
        if (schedule_timeout_interruptible(HZ * wait_time) != 0) {
-               ext4_warning(sb, "MMP startup interrupted, failing mount\n");
+               ext4_warning(sb, "MMP startup interrupted, failing mount");
                goto failed;
        }
 
index 325cef48b39a8d23788dc17ef056ccf79a7b58f6..a920c5d29fac0a5b5ef83c9cca18feeb3dcc0fe7 100644 (file)
@@ -400,7 +400,7 @@ data_copy:
 
        /* Even in case of data=writeback it is reasonable to pin
         * inode to transaction, to prevent unexpected data loss */
-       *err = ext4_jbd2_file_inode(handle, orig_inode);
+       *err = ext4_jbd2_inode_add_write(handle, orig_inode);
 
 unlock_pages:
        unlock_page(pagep[0]);
index 5611ec9348d7368abe2574b28899311375202118..ec4c39952e847462c9a4a62f7d4bcc1afb74fd37 100644 (file)
@@ -1107,6 +1107,11 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
        }
 
        while (1) {
+               if (fatal_signal_pending(current)) {
+                       err = -ERESTARTSYS;
+                       goto errout;
+               }
+               cond_resched();
                block = dx_get_block(frame->at);
                ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
                                             start_hash, start_minor_hash);
@@ -1613,7 +1618,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
                        if (nokey)
                                return ERR_PTR(-ENOKEY);
                        ext4_warning(inode->i_sb,
-                                    "Inconsistent encryption contexts: %lu/%lu\n",
+                                    "Inconsistent encryption contexts: %lu/%lu",
                                     (unsigned long) dir->i_ino,
                                     (unsigned long) inode->i_ino);
                        return ERR_PTR(-EPERM);
@@ -2828,7 +2833,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
                         * list entries can cause panics at unmount time.
                         */
                        mutex_lock(&sbi->s_orphan_lock);
-                       list_del(&EXT4_I(inode)->i_orphan);
+                       list_del_init(&EXT4_I(inode)->i_orphan);
                        mutex_unlock(&sbi->s_orphan_lock);
                }
        }
index e4fc8ea45d7888fe3677f052e1af8dff39d443ab..2a01df9cc1c3214ee0e106eee262e7a3d1cee284 100644 (file)
@@ -342,9 +342,7 @@ void ext4_io_submit(struct ext4_io_submit *io)
        if (bio) {
                int io_op = io->io_wbc->sync_mode == WB_SYNC_ALL ?
                            WRITE_SYNC : WRITE;
-               bio_get(io->io_bio);
                submit_bio(io_op, io->io_bio);
-               bio_put(io->io_bio);
        }
        io->io_bio = NULL;
 }
index 34038e3598d59fa2b4bcaf2304d31602e803d5e0..cf681004b1965fba00be6e97ee9a4cbe57eb3654 100644 (file)
@@ -41,7 +41,7 @@ int ext4_resize_begin(struct super_block *sb)
         */
        if (EXT4_SB(sb)->s_mount_state & EXT4_ERROR_FS) {
                ext4_warning(sb, "There are errors in the filesystem, "
-                            "so online resizing is not allowed\n");
+                            "so online resizing is not allowed");
                return -EPERM;
        }
 
index 304c712dbe12e8ba7d5c5abfaca30f7ef3f5e5a6..20c5d52253b4924c9c1d0cf27110a566e5e3f234 100644 (file)
@@ -859,6 +859,7 @@ static void ext4_put_super(struct super_block *sb)
        percpu_counter_destroy(&sbi->s_freeinodes_counter);
        percpu_counter_destroy(&sbi->s_dirs_counter);
        percpu_counter_destroy(&sbi->s_dirtyclusters_counter);
+       percpu_free_rwsem(&sbi->s_journal_flag_rwsem);
        brelse(sbi->s_sbh);
 #ifdef CONFIG_QUOTA
        for (i = 0; i < EXT4_MAXQUOTAS; i++)
@@ -3930,6 +3931,9 @@ no_journal:
        if (!err)
                err = percpu_counter_init(&sbi->s_dirtyclusters_counter, 0,
                                          GFP_KERNEL);
+       if (!err)
+               err = percpu_init_rwsem(&sbi->s_journal_flag_rwsem);
+
        if (err) {
                ext4_msg(sb, KERN_ERR, "insufficient memory");
                goto failed_mount6;
index 2ad98d6e19f43c369d9eb1f65640374e1e133b80..70078096117d3e956e86be7ba358b724286989d9 100644 (file)
@@ -219,6 +219,8 @@ static int journal_submit_data_buffers(journal_t *journal,
 
        spin_lock(&journal->j_list_lock);
        list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
+               if (!(jinode->i_flags & JI_WRITE_DATA))
+                       continue;
                mapping = jinode->i_vfs_inode->i_mapping;
                jinode->i_flags |= JI_COMMIT_RUNNING;
                spin_unlock(&journal->j_list_lock);
@@ -256,6 +258,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
        /* For locking, see the comment in journal_submit_data_buffers() */
        spin_lock(&journal->j_list_lock);
        list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
+               if (!(jinode->i_flags & JI_WAIT_DATA))
+                       continue;
                jinode->i_flags |= JI_COMMIT_RUNNING;
                spin_unlock(&journal->j_list_lock);
                err = filemap_fdatawait(jinode->i_vfs_inode->i_mapping);
index 435f0b26ac2038e4f8037b5b1f2e4d15dbc9b2d2..b31852f76f46585137021df6266a18ba743b8528 100644 (file)
@@ -94,7 +94,8 @@ EXPORT_SYMBOL(jbd2_journal_blocks_per_page);
 EXPORT_SYMBOL(jbd2_journal_invalidatepage);
 EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
 EXPORT_SYMBOL(jbd2_journal_force_commit);
-EXPORT_SYMBOL(jbd2_journal_file_inode);
+EXPORT_SYMBOL(jbd2_journal_inode_add_write);
+EXPORT_SYMBOL(jbd2_journal_inode_add_wait);
 EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
 EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
 EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
index 2c56c3e3219463b165828c7c9c1d2a4ab8ef608e..1749519b362fa6ca7385de310d5c67096746278d 100644 (file)
@@ -2462,7 +2462,8 @@ void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
 /*
  * File inode in the inode list of the handle's transaction
  */
-int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
+static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode,
+                                  unsigned long flags)
 {
        transaction_t *transaction = handle->h_transaction;
        journal_t *journal;
@@ -2487,12 +2488,14 @@ int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode)
         * and if jinode->i_next_transaction == transaction, commit code
         * will only file the inode where we want it.
         */
-       if (jinode->i_transaction == transaction ||
-           jinode->i_next_transaction == transaction)
+       if ((jinode->i_transaction == transaction ||
+           jinode->i_next_transaction == transaction) &&
+           (jinode->i_flags & flags) == flags)
                return 0;
 
        spin_lock(&journal->j_list_lock);
-
+       jinode->i_flags |= flags;
+       /* Is inode already attached where we need it? */
        if (jinode->i_transaction == transaction ||
            jinode->i_next_transaction == transaction)
                goto done;
@@ -2523,6 +2526,17 @@ done:
        return 0;
 }
 
+int jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *jinode)
+{
+       return jbd2_journal_file_inode(handle, jinode,
+                                      JI_WRITE_DATA | JI_WAIT_DATA);
+}
+
+int jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *jinode)
+{
+       return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA);
+}
+
 /*
  * File truncate and transaction commit interact with each other in a
  * non-trivial way.  If a transaction writing data block A is
index 93d5853f8c99b84e5b0c530eeaf044396699ecc6..dba2ff8eaa68e3365deac3d61df3da5641099d9e 100644 (file)
@@ -379,7 +379,7 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
         */
        hdr = (void*)p - rqstp->rq_arg.head[0].iov_base;
        dlen = rqstp->rq_arg.head[0].iov_len + rqstp->rq_arg.page_len
-               - hdr;
+               + rqstp->rq_arg.tail[0].iov_len - hdr;
        /*
         * Round the length of the data which was specified up to
         * the next multiple of XDR units and then compare that
index 825c7bc8d789716749138583953c26e630294a93..953c0755cb37e23697a2308800ccaf7bf85232cf 100644 (file)
@@ -289,7 +289,7 @@ nfsd4_preprocess_layout_stateid(struct svc_rqst *rqstp,
 
                status = nfserr_bad_stateid;
                mutex_lock(&ls->ls_mutex);
-               if (stateid->si_generation > stid->sc_stateid.si_generation)
+               if (nfsd4_stateid_generation_after(stateid, &stid->sc_stateid))
                        goto out_unlock_stid;
                if (layout_type != ls->ls_layout_type)
                        goto out_unlock_stid;
index 0462eeddfff9997f9de2fa0fb53a100deeff941d..f5f82e145018059bbeb265cd42a279a3009dfd6b 100644 (file)
@@ -4651,12 +4651,6 @@ grace_disallows_io(struct net *net, struct inode *inode)
        return opens_in_grace(net) && mandatory_lock(inode);
 }
 
-/* Returns true iff a is later than b: */
-static bool stateid_generation_after(stateid_t *a, stateid_t *b)
-{
-       return (s32)(a->si_generation - b->si_generation) > 0;
-}
-
 static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
 {
        /*
@@ -4670,7 +4664,7 @@ static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_s
                return nfs_ok;
 
        /* If the client sends us a stateid from the future, it's buggy: */
-       if (stateid_generation_after(in, ref))
+       if (nfsd4_stateid_generation_after(in, ref))
                return nfserr_bad_stateid;
        /*
         * However, we could see a stateid from the past, even from a
index c050c53036a62f5dfd596755b426d5fbd5538501..986e51e5ceac882f703e1d0262fdc66d356a453f 100644 (file)
@@ -573,6 +573,11 @@ enum nfsd4_cb_op {
        NFSPROC4_CLNT_CB_SEQUENCE,
 };
 
+/* Returns true iff a is later than b: */
+static inline bool nfsd4_stateid_generation_after(stateid_t *a, stateid_t *b)
+{
+       return (s32)(a->si_generation - b->si_generation) > 0;
+}
 
 struct nfsd4_compound_state;
 struct nfsd_net;
index f4cd3c3e9fb70d708d57a3d8dc15f92492e4ea12..497a4171ef61f6209a32303530b79c72439962cf 100644 (file)
@@ -619,7 +619,7 @@ static inline int ocfs2_calc_tree_trunc_credits(struct super_block *sb,
 
 static inline int ocfs2_jbd2_file_inode(handle_t *handle, struct inode *inode)
 {
-       return jbd2_journal_file_inode(handle, &OCFS2_I(inode)->ip_jinode);
+       return jbd2_journal_inode_add_write(handle, &OCFS2_I(inode)->ip_jinode);
 }
 
 static inline int ocfs2_begin_ordered_truncate(struct inode *inode,
index a86c6c04b9bcf06797e27e17075b4cc6112d0e62..68ef06efe6bc4a530133d54e57833330a1b40470 100644 (file)
@@ -182,6 +182,8 @@ static int filldir(struct dir_context *ctx, const char *name, int namlen,
        }
        dirent = buf->previous;
        if (dirent) {
+               if (signal_pending(current))
+                       return -EINTR;
                if (__put_user(offset, &dirent->d_off))
                        goto efault;
        }
@@ -261,6 +263,8 @@ static int filldir64(struct dir_context *ctx, const char *name, int namlen,
                return -EINVAL;
        dirent = buf->previous;
        if (dirent) {
+               if (signal_pending(current))
+                       return -EINTR;
                if (__put_user(offset, &dirent->d_off))
                        goto efault;
        }
index 846513c73606bd96997015eb115f55fc59e3e39d..a5ac2cad5cb77424ff699429c006e34a0c7da784 100644 (file)
@@ -587,7 +587,6 @@ struct mtd_info;
 
 struct bcma_sflash {
        bool present;
-       u32 window;
        u32 blocksize;
        u16 numblocks;
        u32 size;
index 0023088b253b4d928669f9841a1f08dbeaf5307a..3f9778cbc79d0b1bb3b73e0a12695b722fa7a179 100644 (file)
 #define FSL_IFC_VERSION_MASK   0x0F0F0000
 #define FSL_IFC_VERSION_1_0_0  0x01000000
 #define FSL_IFC_VERSION_1_1_0  0x01010000
+#define FSL_IFC_VERSION_2_0_0  0x02000000
+
+#define PGOFFSET_64K   (64*1024)
+#define PGOFFSET_4K    (4*1024)
 
 /*
  * CSPR - Chip Select Property Register
@@ -723,20 +727,26 @@ struct fsl_ifc_nand {
        __be32 nand_evter_en;
        u32 res17[0x2];
        __be32 nand_evter_intr_en;
-       u32 res18[0x2];
+       __be32 nand_vol_addr_stat;
+       u32 res18;
        __be32 nand_erattr0;
        __be32 nand_erattr1;
        u32 res19[0x10];
        __be32 nand_fsr;
-       u32 res20;
-       __be32 nand_eccstat[4];
-       u32 res21[0x20];
+       u32 res20[0x3];
+       __be32 nand_eccstat[6];
+       u32 res21[0x1c];
        __be32 nanndcr;
        u32 res22[0x2];
        __be32 nand_autoboot_trgr;
        u32 res23;
        __be32 nand_mdr;
-       u32 res24[0x5C];
+       u32 res24[0x1C];
+       __be32 nand_dll_lowcfg0;
+       __be32 nand_dll_lowcfg1;
+       u32 res25;
+       __be32 nand_dll_lowstat;
+       u32 res26[0x3c];
 };
 
 /*
@@ -771,13 +781,12 @@ struct fsl_ifc_gpcm {
        __be32 gpcm_erattr1;
        __be32 gpcm_erattr2;
        __be32 gpcm_stat;
-       u32 res4[0x1F3];
 };
 
 /*
  * IFC Controller Registers
  */
-struct fsl_ifc_regs {
+struct fsl_ifc_global {
        __be32 ifc_rev;
        u32 res1[0x2];
        struct {
@@ -803,21 +812,26 @@ struct fsl_ifc_regs {
        } ftim_cs[FSL_IFC_BANK_COUNT];
        u32 res9[0x30];
        __be32 rb_stat;
-       u32 res10[0x2];
+       __be32 rb_map;
+       __be32 wb_map;
        __be32 ifc_gcr;
-       u32 res11[0x2];
+       u32 res10[0x2];
        __be32 cm_evter_stat;
-       u32 res12[0x2];
+       u32 res11[0x2];
        __be32 cm_evter_en;
-       u32 res13[0x2];
+       u32 res12[0x2];
        __be32 cm_evter_intr_en;
-       u32 res14[0x2];
+       u32 res13[0x2];
        __be32 cm_erattr0;
        __be32 cm_erattr1;
-       u32 res15[0x2];
+       u32 res14[0x2];
        __be32 ifc_ccr;
        __be32 ifc_csr;
-       u32 res16[0x2EB];
+       __be32 ddr_ccr_low;
+};
+
+
+struct fsl_ifc_runtime {
        struct fsl_ifc_nand ifc_nand;
        struct fsl_ifc_nor ifc_nor;
        struct fsl_ifc_gpcm ifc_gpcm;
@@ -831,7 +845,8 @@ extern int fsl_ifc_find(phys_addr_t addr_base);
 struct fsl_ifc_ctrl {
        /* device info */
        struct device                   *dev;
-       struct fsl_ifc_regs __iomem     *regs;
+       struct fsl_ifc_global __iomem   *gregs;
+       struct fsl_ifc_runtime __iomem  *rregs;
        int                             irq;
        int                             nand_irq;
        spinlock_t                      lock;
index fd1083c46c61f0f2163287f4b873968d4778aa07..efb232c5f66867851053da799c83428e576ebb57 100644 (file)
@@ -403,11 +403,19 @@ static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
 
 /* Flags in jbd_inode->i_flags */
 #define __JI_COMMIT_RUNNING 0
-/* Commit of the inode data in progress. We use this flag to protect us from
+#define __JI_WRITE_DATA 1
+#define __JI_WAIT_DATA 2
+
+/*
+ * Commit of the inode data in progress. We use this flag to protect us from
  * concurrent deletion of inode. We cannot use reference to inode for this
  * since we cannot afford doing last iput() on behalf of kjournald
  */
 #define JI_COMMIT_RUNNING (1 << __JI_COMMIT_RUNNING)
+/* Write allocated dirty buffers in this inode before commit */
+#define JI_WRITE_DATA (1 << __JI_WRITE_DATA)
+/* Wait for outstanding data writes for this inode before commit */
+#define JI_WAIT_DATA (1 << __JI_WAIT_DATA)
 
 /**
  * struct jbd_inode is the structure linking inodes in ordered mode
@@ -781,9 +789,6 @@ jbd2_time_diff(unsigned long start, unsigned long end)
  * @j_wbufsize: maximum number of buffer_heads allowed in j_wbuf, the
  *     number that will fit in j_blocksize
  * @j_last_sync_writer: most recent pid which did a synchronous write
- * @j_history: Buffer storing the transactions statistics history
- * @j_history_max: Maximum number of transactions in the statistics history
- * @j_history_cur: Current number of transactions in the statistics history
  * @j_history_lock: Protect the transactions statistics history
  * @j_proc_entry: procfs entry for the jbd statistics directory
  * @j_stats: Overall statistics
@@ -1270,7 +1275,8 @@ extern int           jbd2_journal_clear_err  (journal_t *);
 extern int        jbd2_journal_bmap(journal_t *, unsigned long, unsigned long long *);
 extern int        jbd2_journal_force_commit(journal_t *);
 extern int        jbd2_journal_force_commit_nested(journal_t *);
-extern int        jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *inode);
+extern int        jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *inode);
+extern int        jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *inode);
 extern int        jbd2_journal_begin_ordered_truncate(journal_t *journal,
                                struct jbd2_inode *inode, loff_t new_size);
 extern void       jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode);
index c8be32e9fc49507702d187a33893f8f3870a38ef..ad3c3488073c7fa77f1fac02927ad1f7c5a9a0dc 100644 (file)
 
 #define FSMC_BUSY_WAIT_TIMEOUT (1 * HZ)
 
-/*
- * There are 13 bytes of ecc for every 512 byte block in FSMC version 8
- * and it has to be read consecutively and immediately after the 512
- * byte data block for hardware to generate the error bit offsets
- * Managing the ecc bytes in the following way is easier. This way is
- * similar to oobfree structure maintained already in u-boot nand driver
- */
-#define MAX_ECCPLACE_ENTRIES   32
-
-struct fsmc_nand_eccplace {
-       uint8_t offset;
-       uint8_t length;
-};
-
-struct fsmc_eccplace {
-       struct fsmc_nand_eccplace eccplace[MAX_ECCPLACE_ENTRIES];
-};
-
 struct fsmc_nand_timings {
        uint8_t tclr;
        uint8_t tar;
index 5e0eb7ccabd4213a948338c7a86198fa1f9429eb..3aa56e3104bb747da8fedd70da2d3570cfa54103 100644 (file)
 #endif
 
 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
-# ifdef map_bankwidth
-#  undef map_bankwidth
-#  define map_bankwidth(map) ((map)->bankwidth)
-#  undef map_bankwidth_is_large
-#  define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
-#  undef map_words
-#  define map_words(map) map_calc_words(map)
-# else
-#  define map_bankwidth(map) 32
-#  define map_bankwidth_is_large(map) (1)
-#  define map_words(map) map_calc_words(map)
-# endif
+/* always use indirect access for 256-bit to preserve kernel stack */
+# undef map_bankwidth
+# define map_bankwidth(map) ((map)->bankwidth)
+# undef map_bankwidth_is_large
+# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
+# undef map_words
+# define map_words(map) map_calc_words(map)
 #define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
 #undef MAX_MAP_BANKWIDTH
 #define MAX_MAP_BANKWIDTH 32
index ef9fea4fc40080dd5832d70405bbd87e2a605339..29a1706122035b74a52e77bfa3a1f6b60f115ee2 100644 (file)
@@ -96,16 +96,35 @@ struct mtd_oob_ops {
 
 #define MTD_MAX_OOBFREE_ENTRIES_LARGE  32
 #define MTD_MAX_ECCPOS_ENTRIES_LARGE   640
+/**
+ * struct mtd_oob_region - oob region definition
+ * @offset: region offset
+ * @length: region length
+ *
+ * This structure describes a region of the OOB area, and is used
+ * to retrieve ECC or free bytes sections.
+ * Each section is defined by an offset within the OOB area and a
+ * length.
+ */
+struct mtd_oob_region {
+       u32 offset;
+       u32 length;
+};
+
 /*
- * Internal ECC layout control structure. For historical reasons, there is a
- * similar, smaller struct nand_ecclayout_user (in mtd-abi.h) that is retained
- * for export to user-space via the ECCGETLAYOUT ioctl.
- * nand_ecclayout should be expandable in the future simply by the above macros.
+ * struct mtd_ooblayout_ops - NAND OOB layout operations
+ * @ecc: function returning an ECC region in the OOB area.
+ *      Should return -ERANGE if %section exceeds the total number of
+ *      ECC sections.
+ * @free: function returning a free region in the OOB area.
+ *       Should return -ERANGE if %section exceeds the total number of
+ *       free sections.
  */
-struct nand_ecclayout {
-       __u32 eccbytes;
-       __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES_LARGE];
-       struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES_LARGE];
+struct mtd_ooblayout_ops {
+       int (*ecc)(struct mtd_info *mtd, int section,
+                  struct mtd_oob_region *oobecc);
+       int (*free)(struct mtd_info *mtd, int section,
+                   struct mtd_oob_region *oobfree);
 };
 
 struct module; /* only needed for owner field in mtd_info */
@@ -166,8 +185,8 @@ struct mtd_info {
        const char *name;
        int index;
 
-       /* ECC layout structure pointer - read only! */
-       struct nand_ecclayout *ecclayout;
+       /* OOB layout description */
+       const struct mtd_ooblayout_ops *ooblayout;
 
        /* the ecc step size. */
        unsigned int ecc_step_size;
@@ -253,6 +272,30 @@ struct mtd_info {
        int usecount;
 };
 
+int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
+                     struct mtd_oob_region *oobecc);
+int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
+                                int *section,
+                                struct mtd_oob_region *oobregion);
+int mtd_ooblayout_get_eccbytes(struct mtd_info *mtd, u8 *eccbuf,
+                              const u8 *oobbuf, int start, int nbytes);
+int mtd_ooblayout_set_eccbytes(struct mtd_info *mtd, const u8 *eccbuf,
+                              u8 *oobbuf, int start, int nbytes);
+int mtd_ooblayout_free(struct mtd_info *mtd, int section,
+                      struct mtd_oob_region *oobfree);
+int mtd_ooblayout_get_databytes(struct mtd_info *mtd, u8 *databuf,
+                               const u8 *oobbuf, int start, int nbytes);
+int mtd_ooblayout_set_databytes(struct mtd_info *mtd, const u8 *databuf,
+                               u8 *oobbuf, int start, int nbytes);
+int mtd_ooblayout_count_freebytes(struct mtd_info *mtd);
+int mtd_ooblayout_count_eccbytes(struct mtd_info *mtd);
+
+static inline void mtd_set_ooblayout(struct mtd_info *mtd,
+                                    const struct mtd_ooblayout_ops *ooblayout)
+{
+       mtd->ooblayout = ooblayout;
+}
+
 static inline void mtd_set_of_node(struct mtd_info *mtd,
                                   struct device_node *np)
 {
index 56574ba36555260fda145a059b5346836947e17d..fbe8e164a4ee93db99fab879c7284721546204e8 100644 (file)
@@ -116,9 +116,14 @@ typedef enum {
        NAND_ECC_HW,
        NAND_ECC_HW_SYNDROME,
        NAND_ECC_HW_OOB_FIRST,
-       NAND_ECC_SOFT_BCH,
 } nand_ecc_modes_t;
 
+enum nand_ecc_algo {
+       NAND_ECC_UNKNOWN,
+       NAND_ECC_HAMMING,
+       NAND_ECC_BCH,
+};
+
 /*
  * Constants for Hardware ECC
  */
@@ -458,6 +463,7 @@ struct nand_hw_control {
 /**
  * struct nand_ecc_ctrl - Control structure for ECC
  * @mode:      ECC mode
+ * @algo:      ECC algorithm
  * @steps:     number of ECC steps per page
  * @size:      data bytes per ECC step
  * @bytes:     ECC bytes per step
@@ -466,7 +472,6 @@ struct nand_hw_control {
  * @prepad:    padding information for syndrome based ECC generators
  * @postpad:   padding information for syndrome based ECC generators
  * @options:   ECC specific options (see NAND_ECC_XXX flags defined above)
- * @layout:    ECC layout control struct pointer
  * @priv:      pointer to private ECC control data
  * @hwctl:     function to control hardware ECC generator. Must only
  *             be provided if an hardware ECC is available
@@ -508,6 +513,7 @@ struct nand_hw_control {
  */
 struct nand_ecc_ctrl {
        nand_ecc_modes_t mode;
+       enum nand_ecc_algo algo;
        int steps;
        int size;
        int bytes;
@@ -516,7 +522,6 @@ struct nand_ecc_ctrl {
        int prepad;
        int postpad;
        unsigned int options;
-       struct nand_ecclayout   *layout;
        void *priv;
        void (*hwctl)(struct mtd_info *mtd, int mode);
        int (*calculate)(struct mtd_info *mtd, const uint8_t *dat,
@@ -740,6 +745,9 @@ struct nand_chip {
        void *priv;
 };
 
+extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
+extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
+
 static inline void nand_set_flash_node(struct nand_chip *chip,
                                       struct device_node *np)
 {
@@ -1070,4 +1078,18 @@ int nand_check_erased_ecc_chunk(void *data, int datalen,
                                void *ecc, int ecclen,
                                void *extraoob, int extraooblen,
                                int threshold);
+
+/* Default write_oob implementation */
+int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
+
+/* Default write_oob syndrome implementation */
+int nand_write_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
+                           int page);
+
+/* Default read_oob implementation */
+int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, int page);
+
+/* Default read_oob syndrome implementation */
+int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
+                          int page);
 #endif /* __LINUX_MTD_NAND_H */
index 4596503c9da9e0952d4953fa856572898aabc9be..0aaa98b219a461711306913674d5d582b40a617b 100644 (file)
@@ -80,7 +80,6 @@ struct onenand_bufferram {
  * @page_buf:          [INTERN] page main data buffer
  * @oob_buf:           [INTERN] page oob data buffer
  * @subpagesize:       [INTERN] holds the subpagesize
- * @ecclayout:         [REPLACEABLE] the default ecc placement scheme
  * @bbm:               [REPLACEABLE] pointer to Bad Block Management
  * @priv:              [OPTIONAL] pointer to private chip date
  */
@@ -134,7 +133,6 @@ struct onenand_chip {
 #endif
 
        int                     subpagesize;
-       struct nand_ecclayout   *ecclayout;
 
        void                    *bbm;
 
index 25f4d2a845c1a95f81185be9d12a2c4a540f21bd..65e91d0fa9817b8d66d126754ccec5ec3f3b40c0 100644 (file)
@@ -14,7 +14,7 @@
 
 struct sharpsl_nand_platform_data {
        struct nand_bbt_descr   *badblock_pattern;
-       struct nand_ecclayout   *ecc_layout;
+       const struct mtd_ooblayout_ops *ecc_layout;
        struct mtd_partition    *partitions;
        unsigned int            nr_partitions;
 };
index 3c36113a88e1d8e57f4a27032bb17130b3df3f7a..7f041bd88b8244f8fa243c71d508e55dd08b4160 100644 (file)
@@ -21,6 +21,7 @@
  * Sometimes these are the same as CFI IDs, but sometimes they aren't.
  */
 #define SNOR_MFR_ATMEL         CFI_MFR_ATMEL
+#define SNOR_MFR_GIGADEVICE    0xc8
 #define SNOR_MFR_INTEL         CFI_MFR_INTEL
 #define SNOR_MFR_MICRON                CFI_MFR_ST /* ST Micro <--> Micron */
 #define SNOR_MFR_MACRONIX      CFI_MFR_MACRONIX
diff --git a/include/linux/of_mtd.h b/include/linux/of_mtd.h
deleted file mode 100644 (file)
index e266caa..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
- *
- * OF helpers for mtd.
- *
- * This file is released under the GPLv2
- */
-
-#ifndef __LINUX_OF_MTD_H
-#define __LINUX_OF_MTD_H
-
-#ifdef CONFIG_OF_MTD
-
-#include <linux/of.h>
-int of_get_nand_ecc_mode(struct device_node *np);
-int of_get_nand_ecc_step_size(struct device_node *np);
-int of_get_nand_ecc_strength(struct device_node *np);
-int of_get_nand_bus_width(struct device_node *np);
-bool of_get_nand_on_flash_bbt(struct device_node *np);
-
-#else /* CONFIG_OF_MTD */
-
-static inline int of_get_nand_ecc_mode(struct device_node *np)
-{
-       return -ENOSYS;
-}
-
-static inline int of_get_nand_ecc_step_size(struct device_node *np)
-{
-       return -ENOSYS;
-}
-
-static inline int of_get_nand_ecc_strength(struct device_node *np)
-{
-       return -ENOSYS;
-}
-
-static inline int of_get_nand_bus_width(struct device_node *np)
-{
-       return -ENOSYS;
-}
-
-static inline bool of_get_nand_on_flash_bbt(struct device_node *np)
-{
-       return false;
-}
-
-#endif /* CONFIG_OF_MTD */
-
-#endif /* __LINUX_OF_MTD_H */
index d833eb4dd44633da82623df4e09564e934e6fa19..9e9d79e8efa5fd7cd3e38e6aa7d74bb5abb52809 100644 (file)
  *  option) any later version.
  */
 
-/* Maximum Number of Chip Selects */
-#define GPMC_CS_NUM            8
+#include <linux/platform_data/gpmc-omap.h>
 
 #define GPMC_CONFIG_WP         0x00000005
 
-#define GPMC_IRQ_FIFOEVENTENABLE       0x01
-#define GPMC_IRQ_COUNT_EVENT           0x02
-
-#define GPMC_BURST_4                   4       /* 4 word burst */
-#define GPMC_BURST_8                   8       /* 8 word burst */
-#define GPMC_BURST_16                  16      /* 16 word burst */
-#define GPMC_DEVWIDTH_8BIT             1       /* 8-bit device width */
-#define GPMC_DEVWIDTH_16BIT            2       /* 16-bit device width */
-#define GPMC_MUX_AAD                   1       /* Addr-Addr-Data multiplex */
-#define GPMC_MUX_AD                    2       /* Addr-Data multiplex */
-
-/* bool type time settings */
-struct gpmc_bool_timings {
-       bool cycle2cyclediffcsen;
-       bool cycle2cyclesamecsen;
-       bool we_extra_delay;
-       bool oe_extra_delay;
-       bool adv_extra_delay;
-       bool cs_extra_delay;
-       bool time_para_granularity;
-};
+/* IRQ numbers in GPMC IRQ domain for legacy boot use */
+#define GPMC_IRQ_FIFOEVENTENABLE       0
+#define GPMC_IRQ_COUNT_EVENT           1
 
-/*
- * Note that all values in this struct are in nanoseconds except sync_clk
- * (which is in picoseconds), while the register values are in gpmc_fck cycles.
+/**
+ * gpmc_nand_ops - Interface between NAND and GPMC
+ * @nand_write_buffer_empty: get the NAND write buffer empty status.
  */
-struct gpmc_timings {
-       /* Minimum clock period for synchronous mode (in picoseconds) */
-       u32 sync_clk;
-
-       /* Chip-select signal timings corresponding to GPMC_CS_CONFIG2 */
-       u32 cs_on;              /* Assertion time */
-       u32 cs_rd_off;          /* Read deassertion time */
-       u32 cs_wr_off;          /* Write deassertion time */
-
-       /* ADV signal timings corresponding to GPMC_CONFIG3 */
-       u32 adv_on;             /* Assertion time */
-       u32 adv_rd_off;         /* Read deassertion time */
-       u32 adv_wr_off;         /* Write deassertion time */
-       u32 adv_aad_mux_on;     /* ADV assertion time for AAD */
-       u32 adv_aad_mux_rd_off; /* ADV read deassertion time for AAD */
-       u32 adv_aad_mux_wr_off; /* ADV write deassertion time for AAD */
-
-       /* WE signals timings corresponding to GPMC_CONFIG4 */
-       u32 we_on;              /* WE assertion time */
-       u32 we_off;             /* WE deassertion time */
-
-       /* OE signals timings corresponding to GPMC_CONFIG4 */
-       u32 oe_on;              /* OE assertion time */
-       u32 oe_off;             /* OE deassertion time */
-       u32 oe_aad_mux_on;      /* OE assertion time for AAD */
-       u32 oe_aad_mux_off;     /* OE deassertion time for AAD */
-
-       /* Access time and cycle time timings corresponding to GPMC_CONFIG5 */
-       u32 page_burst_access;  /* Multiple access word delay */
-       u32 access;             /* Start-cycle to first data valid delay */
-       u32 rd_cycle;           /* Total read cycle time */
-       u32 wr_cycle;           /* Total write cycle time */
-
-       u32 bus_turnaround;
-       u32 cycle2cycle_delay;
-
-       u32 wait_monitoring;
-       u32 clk_activation;
-
-       /* The following are only on OMAP3430 */
-       u32 wr_access;          /* WRACCESSTIME */
-       u32 wr_data_mux_bus;    /* WRDATAONADMUXBUS */
-
-       struct gpmc_bool_timings bool_timings;
+struct gpmc_nand_ops {
+       bool (*nand_writebuffer_empty)(void);
 };
 
-/* Device timings in picoseconds */
-struct gpmc_device_timings {
-       u32 t_ceasu;    /* address setup to CS valid */
-       u32 t_avdasu;   /* address setup to ADV valid */
-       /* XXX: try to combine t_avdp_r & t_avdp_w. Issue is
-        * of tusb using these timings even for sync whilst
-        * ideally for adv_rd/(wr)_off it should have considered
-        * t_avdh instead. This indirectly necessitates r/w
-        * variations of t_avdp as it is possible to have one
-        * sync & other async
-        */
-       u32 t_avdp_r;   /* ADV low time (what about t_cer ?) */
-       u32 t_avdp_w;
-       u32 t_aavdh;    /* address hold time */
-       u32 t_oeasu;    /* address setup to OE valid */
-       u32 t_aa;       /* access time from ADV assertion */
-       u32 t_iaa;      /* initial access time */
-       u32 t_oe;       /* access time from OE assertion */
-       u32 t_ce;       /* access time from CS asertion */
-       u32 t_rd_cycle; /* read cycle time */
-       u32 t_cez_r;    /* read CS deassertion to high Z */
-       u32 t_cez_w;    /* write CS deassertion to high Z */
-       u32 t_oez;      /* OE deassertion to high Z */
-       u32 t_weasu;    /* address setup to WE valid */
-       u32 t_wpl;      /* write assertion time */
-       u32 t_wph;      /* write deassertion time */
-       u32 t_wr_cycle; /* write cycle time */
-
-       u32 clk;
-       u32 t_bacc;     /* burst access valid clock to output delay */
-       u32 t_ces;      /* CS setup time to clk */
-       u32 t_avds;     /* ADV setup time to clk */
-       u32 t_avdh;     /* ADV hold time from clk */
-       u32 t_ach;      /* address hold time from clk */
-       u32 t_rdyo;     /* clk to ready valid */
-
-       u32 t_ce_rdyz;  /* XXX: description ?, or use t_cez instead */
-       u32 t_ce_avd;   /* CS on to ADV on delay */
-
-       /* XXX: check the possibility of combining
-        * cyc_aavhd_oe & cyc_aavdh_we
-        */
-       u8 cyc_aavdh_oe;/* read address hold time in cycles */
-       u8 cyc_aavdh_we;/* write address hold time in cycles */
-       u8 cyc_oe;      /* access time from OE assertion in cycles */
-       u8 cyc_wpl;     /* write deassertion time in cycles */
-       u32 cyc_iaa;    /* initial access time in cycles */
-
-       /* extra delays */
-       bool ce_xdelay;
-       bool avd_xdelay;
-       bool oe_xdelay;
-       bool we_xdelay;
-};
+struct gpmc_nand_regs;
 
-struct gpmc_settings {
-       bool burst_wrap;        /* enables wrap bursting */
-       bool burst_read;        /* enables read page/burst mode */
-       bool burst_write;       /* enables write page/burst mode */
-       bool device_nand;       /* device is NAND */
-       bool sync_read;         /* enables synchronous reads */
-       bool sync_write;        /* enables synchronous writes */
-       bool wait_on_read;      /* monitor wait on reads */
-       bool wait_on_write;     /* monitor wait on writes */
-       u32 burst_len;          /* page/burst length */
-       u32 device_width;       /* device bus width (8 or 16 bit) */
-       u32 mux_add_data;       /* multiplex address & data */
-       u32 wait_pin;           /* wait-pin to be used */
-};
+#if IS_ENABLED(CONFIG_OMAP_GPMC)
+struct gpmc_nand_ops *gpmc_omap_get_nand_ops(struct gpmc_nand_regs *regs,
+                                            int cs);
+#else
+static inline gpmc_nand_ops *gpmc_omap_get_nand_ops(struct gpmc_nand_regs *regs,
+                                                   int cs)
+{
+       return NULL;
+}
+#endif /* CONFIG_OMAP_GPMC */
+
+/*--------------------------------*/
+
+/* deprecated APIs */
+#if IS_ENABLED(CONFIG_OMAP_GPMC)
+void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs);
+#else
+static inline void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs)
+{
+}
+#endif /* CONFIG_OMAP_GPMC */
+/*--------------------------------*/
 
 extern int gpmc_calc_timings(struct gpmc_timings *gpmc_t,
                             struct gpmc_settings *gpmc_s,
                             struct gpmc_device_timings *dev_t);
 
-struct gpmc_nand_regs;
 struct device_node;
 
-extern void gpmc_update_nand_reg(struct gpmc_nand_regs *reg, int cs);
 extern int gpmc_get_client_irq(unsigned irq_config);
 
 extern unsigned int gpmc_ticks_to_ns(unsigned int ticks);
diff --git a/include/linux/platform_data/gpmc-omap.h b/include/linux/platform_data/gpmc-omap.h
new file mode 100644 (file)
index 0000000..67ccdb0
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * OMAP GPMC Platform data
+ *
+ * Copyright (C) 2014 Texas Instruments, Inc. - http://www.ti.com
+ *     Roger Quadros <rogerq@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ */
+
+#ifndef _GPMC_OMAP_H_
+#define _GPMC_OMAP_H_
+
+/* Maximum Number of Chip Selects */
+#define GPMC_CS_NUM            8
+
+/* bool type time settings */
+struct gpmc_bool_timings {
+       bool cycle2cyclediffcsen;
+       bool cycle2cyclesamecsen;
+       bool we_extra_delay;
+       bool oe_extra_delay;
+       bool adv_extra_delay;
+       bool cs_extra_delay;
+       bool time_para_granularity;
+};
+
+/*
+ * Note that all values in this struct are in nanoseconds except sync_clk
+ * (which is in picoseconds), while the register values are in gpmc_fck cycles.
+ */
+struct gpmc_timings {
+       /* Minimum clock period for synchronous mode (in picoseconds) */
+       u32 sync_clk;
+
+       /* Chip-select signal timings corresponding to GPMC_CS_CONFIG2 */
+       u32 cs_on;              /* Assertion time */
+       u32 cs_rd_off;          /* Read deassertion time */
+       u32 cs_wr_off;          /* Write deassertion time */
+
+       /* ADV signal timings corresponding to GPMC_CONFIG3 */
+       u32 adv_on;             /* Assertion time */
+       u32 adv_rd_off;         /* Read deassertion time */
+       u32 adv_wr_off;         /* Write deassertion time */
+       u32 adv_aad_mux_on;     /* ADV assertion time for AAD */
+       u32 adv_aad_mux_rd_off; /* ADV read deassertion time for AAD */
+       u32 adv_aad_mux_wr_off; /* ADV write deassertion time for AAD */
+
+       /* WE signals timings corresponding to GPMC_CONFIG4 */
+       u32 we_on;              /* WE assertion time */
+       u32 we_off;             /* WE deassertion time */
+
+       /* OE signals timings corresponding to GPMC_CONFIG4 */
+       u32 oe_on;              /* OE assertion time */
+       u32 oe_off;             /* OE deassertion time */
+       u32 oe_aad_mux_on;      /* OE assertion time for AAD */
+       u32 oe_aad_mux_off;     /* OE deassertion time for AAD */
+
+       /* Access time and cycle time timings corresponding to GPMC_CONFIG5 */
+       u32 page_burst_access;  /* Multiple access word delay */
+       u32 access;             /* Start-cycle to first data valid delay */
+       u32 rd_cycle;           /* Total read cycle time */
+       u32 wr_cycle;           /* Total write cycle time */
+
+       u32 bus_turnaround;
+       u32 cycle2cycle_delay;
+
+       u32 wait_monitoring;
+       u32 clk_activation;
+
+       /* The following are only on OMAP3430 */
+       u32 wr_access;          /* WRACCESSTIME */
+       u32 wr_data_mux_bus;    /* WRDATAONADMUXBUS */
+
+       struct gpmc_bool_timings bool_timings;
+};
+
+/* Device timings in picoseconds */
+struct gpmc_device_timings {
+       u32 t_ceasu;    /* address setup to CS valid */
+       u32 t_avdasu;   /* address setup to ADV valid */
+       /* XXX: try to combine t_avdp_r & t_avdp_w. Issue is
+        * of tusb using these timings even for sync whilst
+        * ideally for adv_rd/(wr)_off it should have considered
+        * t_avdh instead. This indirectly necessitates r/w
+        * variations of t_avdp as it is possible to have one
+        * sync & other async
+        */
+       u32 t_avdp_r;   /* ADV low time (what about t_cer ?) */
+       u32 t_avdp_w;
+       u32 t_aavdh;    /* address hold time */
+       u32 t_oeasu;    /* address setup to OE valid */
+       u32 t_aa;       /* access time from ADV assertion */
+       u32 t_iaa;      /* initial access time */
+       u32 t_oe;       /* access time from OE assertion */
+       u32 t_ce;       /* access time from CS asertion */
+       u32 t_rd_cycle; /* read cycle time */
+       u32 t_cez_r;    /* read CS deassertion to high Z */
+       u32 t_cez_w;    /* write CS deassertion to high Z */
+       u32 t_oez;      /* OE deassertion to high Z */
+       u32 t_weasu;    /* address setup to WE valid */
+       u32 t_wpl;      /* write assertion time */
+       u32 t_wph;      /* write deassertion time */
+       u32 t_wr_cycle; /* write cycle time */
+
+       u32 clk;
+       u32 t_bacc;     /* burst access valid clock to output delay */
+       u32 t_ces;      /* CS setup time to clk */
+       u32 t_avds;     /* ADV setup time to clk */
+       u32 t_avdh;     /* ADV hold time from clk */
+       u32 t_ach;      /* address hold time from clk */
+       u32 t_rdyo;     /* clk to ready valid */
+
+       u32 t_ce_rdyz;  /* XXX: description ?, or use t_cez instead */
+       u32 t_ce_avd;   /* CS on to ADV on delay */
+
+       /* XXX: check the possibility of combining
+        * cyc_aavhd_oe & cyc_aavdh_we
+        */
+       u8 cyc_aavdh_oe;/* read address hold time in cycles */
+       u8 cyc_aavdh_we;/* write address hold time in cycles */
+       u8 cyc_oe;      /* access time from OE assertion in cycles */
+       u8 cyc_wpl;     /* write deassertion time in cycles */
+       u32 cyc_iaa;    /* initial access time in cycles */
+
+       /* extra delays */
+       bool ce_xdelay;
+       bool avd_xdelay;
+       bool oe_xdelay;
+       bool we_xdelay;
+};
+
+#define GPMC_BURST_4                   4       /* 4 word burst */
+#define GPMC_BURST_8                   8       /* 8 word burst */
+#define GPMC_BURST_16                  16      /* 16 word burst */
+#define GPMC_DEVWIDTH_8BIT             1       /* 8-bit device width */
+#define GPMC_DEVWIDTH_16BIT            2       /* 16-bit device width */
+#define GPMC_MUX_AAD                   1       /* Addr-Addr-Data multiplex */
+#define GPMC_MUX_AD                    2       /* Addr-Data multiplex */
+
+struct gpmc_settings {
+       bool burst_wrap;        /* enables wrap bursting */
+       bool burst_read;        /* enables read page/burst mode */
+       bool burst_write;       /* enables write page/burst mode */
+       bool device_nand;       /* device is NAND */
+       bool sync_read;         /* enables synchronous reads */
+       bool sync_write;        /* enables synchronous writes */
+       bool wait_on_read;      /* monitor wait on reads */
+       bool wait_on_write;     /* monitor wait on writes */
+       u32 burst_len;          /* page/burst length */
+       u32 device_width;       /* device bus width (8 or 16 bit) */
+       u32 mux_add_data;       /* multiplex address & data */
+       u32 wait_pin;           /* wait-pin to be used */
+};
+
+/* Data for each chip select */
+struct gpmc_omap_cs_data {
+       bool valid;                     /* data is valid */
+       bool is_nand;                   /* device within this CS is NAND */
+       struct gpmc_settings *settings;
+       struct gpmc_device_timings *device_timings;
+       struct gpmc_timings *gpmc_timings;
+       struct platform_device *pdev;   /* device within this CS region */
+       unsigned int pdata_size;
+};
+
+struct gpmc_omap_platform_data {
+       struct gpmc_omap_cs_data cs[GPMC_CS_NUM];
+};
+
+#endif /* _GPMC_OMAP_H */
index 090bbab0130a3d31b226b8fce8b50f9f6b231be9..17d57a18bac575b94f8aac1a372e642160b0b684 100644 (file)
@@ -45,7 +45,6 @@ enum omap_ecc {
 };
 
 struct gpmc_nand_regs {
-       void __iomem    *gpmc_status;
        void __iomem    *gpmc_nand_command;
        void __iomem    *gpmc_nand_address;
        void __iomem    *gpmc_nand_data;
@@ -64,21 +63,24 @@ struct gpmc_nand_regs {
        void __iomem    *gpmc_bch_result4[GPMC_BCH_NUM_REMAINDER];
        void __iomem    *gpmc_bch_result5[GPMC_BCH_NUM_REMAINDER];
        void __iomem    *gpmc_bch_result6[GPMC_BCH_NUM_REMAINDER];
+       /* Deprecated. Do not use */
+       void __iomem    *gpmc_status;
 };
 
 struct omap_nand_platform_data {
        int                     cs;
        struct mtd_partition    *parts;
        int                     nr_parts;
-       bool                    dev_ready;
        bool                    flash_bbt;
        enum nand_io            xfer_type;
        int                     devsize;
        enum omap_ecc           ecc_opt;
-       struct gpmc_nand_regs   reg;
 
-       /* for passing the partitions */
-       struct device_node      *of_node;
        struct device_node      *elm_of_node;
+
+       /* deprecated */
+       struct gpmc_nand_regs   reg;
+       struct device_node      *of_node;
+       bool                    dev_ready;
 };
 #endif
index 857a9a1d82b58ad3569c7daeb9fffb17f690926a..1f03483f61e5714b1c07708fee2fe3d7ffa946e3 100644 (file)
@@ -372,6 +372,7 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
  * @unprepare_message: undo any work done by prepare_message().
  * @spi_flash_read: to support spi-controller hardwares that provide
  *                  accelerated interface to read from flash devices.
+ * @flash_read_supported: spi device supports flash read
  * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
  *     number. Any individual value may be -ENOENT for CS lines that
  *     are not GPIOs (driven by the SPI controller itself).
@@ -529,6 +530,7 @@ struct spi_master {
                                 struct spi_message *message);
        int (*spi_flash_read)(struct  spi_device *spi,
                              struct spi_flash_read_message *msg);
+       bool (*flash_read_supported)(struct spi_device *spi);
 
        /*
         * These hooks are for drivers that use a generic implementation
@@ -1158,7 +1160,9 @@ struct spi_flash_read_message {
 /* SPI core interface for flash read support */
 static inline bool spi_flash_read_supported(struct spi_device *spi)
 {
-       return spi->master->spi_flash_read ? true : false;
+       return spi->master->spi_flash_read &&
+              (!spi->master->flash_read_supported ||
+              spi->master->flash_read_supported(spi));
 }
 
 int spi_flash_read(struct spi_device *spi,
index 3081339968c3b7e3224248e9bd91745bf2ec72b5..d6917b896d3a75bfb4f26652903d710471a4726b 100644 (file)
@@ -199,7 +199,7 @@ extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt,
                                    struct xdr_buf *rcvbuf);
 
 /* svc_rdma_marshal.c */
-extern int svc_rdma_xdr_decode_req(struct rpcrdma_msg *, struct svc_rqst *);
+extern int svc_rdma_xdr_decode_req(struct xdr_buf *);
 extern int svc_rdma_xdr_encode_error(struct svcxprt_rdma *,
                                     struct rpcrdma_msg *,
                                     enum rpcrdma_errcode, __be32 *);
index c51afb71bfabc658b16be2773ad5a0e78ca1d09b..a26415b5151ce1866e805129de53331c76724813 100644 (file)
@@ -127,8 +127,11 @@ __SYSCALL(__NR_unlinkat, sys_unlinkat)
 __SYSCALL(__NR_symlinkat, sys_symlinkat)
 #define __NR_linkat 37
 __SYSCALL(__NR_linkat, sys_linkat)
+#ifdef __ARCH_WANT_RENAMEAT
+/* renameat is superseded with flags by renameat2 */
 #define __NR_renameat 38
 __SYSCALL(__NR_renameat, sys_renameat)
+#endif /* __ARCH_WANT_RENAMEAT */
 
 /* fs/namespace.c */
 #define __NR_umount2 39
index 763bb6950402ba44ac2d2375589f5c4c08a37a58..0ec1da2ef6521658adc2656f120508242348042b 100644 (file)
@@ -228,7 +228,7 @@ struct nand_oobfree {
  * complete set of ECC information. The ioctl truncates the larger internal
  * structure to retain binary compatibility with the static declaration of the
  * ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of
- * the user struct, not the MAX size of the internal struct nand_ecclayout.
+ * the user struct, not the MAX size of the internal OOB layout representation.
  */
 struct nand_ecclayout_user {
        __u32 eccbytes;
index f231e0bb311ce0827d281d34f737a3a06405c072..bec0b647f9cc5291df0211c6532edd5ffe167eb2 100644 (file)
@@ -37,6 +37,7 @@ void percpu_free_rwsem(struct percpu_rw_semaphore *brw)
        free_percpu(brw->fast_read_ctr);
        brw->fast_read_ctr = NULL; /* catch use after free bugs */
 }
+EXPORT_SYMBOL_GPL(percpu_free_rwsem);
 
 /*
  * This is the fast-path for down_read/up_read. If it succeeds we rely
index 1095be9c80ab809900d2bf0afbde9c63b6034a9d..e085f5ae1548194603de4af635388624daec6516 100644 (file)
@@ -569,10 +569,9 @@ gss_svc_searchbyctx(struct cache_detail *cd, struct xdr_netobj *handle)
        struct rsc *found;
 
        memset(&rsci, 0, sizeof(rsci));
-       if (dup_to_netobj(&rsci.handle, handle->data, handle->len))
-               return NULL;
+       rsci.handle.data = handle->data;
+       rsci.handle.len = handle->len;
        found = rsc_lookup(cd, &rsci);
-       rsc_free(&rsci);
        if (!found)
                return NULL;
        if (cache_check(cd, &found->h, NULL))
@@ -857,8 +856,8 @@ unwrap_integ_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct g
                goto out;
        if (svc_getnl(&buf->head[0]) != seq)
                goto out;
-       /* trim off the mic at the end before returning */
-       xdr_buf_trim(buf, mic.len + 4);
+       /* trim off the mic and padding at the end before returning */
+       xdr_buf_trim(buf, round_up_to_quad(mic.len) + 4);
        stat = 0;
 out:
        kfree(mic.data);
index 7422f28818b24de5e7b36eca01ac2e91f9a7cd4f..f5572e31d518f85b2afbbb9ec1b8e89d36448803 100644 (file)
@@ -244,13 +244,12 @@ void svc_add_new_perm_xprt(struct svc_serv *serv, struct svc_xprt *new)
        svc_xprt_received(new);
 }
 
-int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
+int _svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
                    struct net *net, const int family,
                    const unsigned short port, int flags)
 {
        struct svc_xprt_class *xcl;
 
-       dprintk("svc: creating transport %s[%d]\n", xprt_name, port);
        spin_lock(&svc_xprt_class_lock);
        list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
                struct svc_xprt *newxprt;
@@ -274,12 +273,28 @@ int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
        }
  err:
        spin_unlock(&svc_xprt_class_lock);
-       dprintk("svc: transport %s not found\n", xprt_name);
-
        /* This errno is exposed to user space.  Provide a reasonable
         * perror msg for a bad transport. */
        return -EPROTONOSUPPORT;
 }
+
+int svc_create_xprt(struct svc_serv *serv, const char *xprt_name,
+                   struct net *net, const int family,
+                   const unsigned short port, int flags)
+{
+       int err;
+
+       dprintk("svc: creating transport %s[%d]\n", xprt_name, port);
+       err = _svc_create_xprt(serv, xprt_name, net, family, port, flags);
+       if (err == -EPROTONOSUPPORT) {
+               request_module("svc%s", xprt_name);
+               err = _svc_create_xprt(serv, xprt_name, net, family, port, flags);
+       }
+       if (err)
+               dprintk("svc: transport %s not found, err %d\n",
+                       xprt_name, err);
+       return err;
+}
 EXPORT_SYMBOL_GPL(svc_create_xprt);
 
 /*
index 765bca47c74d7e9f28ad1be961ce86dacc30dd81..0ba9887f3e22bab9a1e3e809df5c4e2c23a510fe 100644 (file)
@@ -145,19 +145,32 @@ static __be32 *decode_reply_array(__be32 *va, __be32 *vaend)
        return (__be32 *)&ary->wc_array[nchunks];
 }
 
-int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
+/**
+ * svc_rdma_xdr_decode_req - Parse incoming RPC-over-RDMA header
+ * @rq_arg: Receive buffer
+ *
+ * On entry, xdr->head[0].iov_base points to first byte in the
+ * RPC-over-RDMA header.
+ *
+ * On successful exit, head[0] points to first byte past the
+ * RPC-over-RDMA header. For RDMA_MSG, this is the RPC message.
+ * The length of the RPC-over-RDMA header is returned.
+ */
+int svc_rdma_xdr_decode_req(struct xdr_buf *rq_arg)
 {
+       struct rpcrdma_msg *rmsgp;
        __be32 *va, *vaend;
        unsigned int len;
        u32 hdr_len;
 
        /* Verify that there's enough bytes for header + something */
-       if (rqstp->rq_arg.len <= RPCRDMA_HDRLEN_ERR) {
+       if (rq_arg->len <= RPCRDMA_HDRLEN_ERR) {
                dprintk("svcrdma: header too short = %d\n",
-                       rqstp->rq_arg.len);
+                       rq_arg->len);
                return -EINVAL;
        }
 
+       rmsgp = (struct rpcrdma_msg *)rq_arg->head[0].iov_base;
        if (rmsgp->rm_vers != rpcrdma_version) {
                dprintk("%s: bad version %u\n", __func__,
                        be32_to_cpu(rmsgp->rm_vers));
@@ -189,10 +202,10 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
                        be32_to_cpu(rmsgp->rm_body.rm_padded.rm_thresh);
 
                va = &rmsgp->rm_body.rm_padded.rm_pempty[4];
-               rqstp->rq_arg.head[0].iov_base = va;
+               rq_arg->head[0].iov_base = va;
                len = (u32)((unsigned long)va - (unsigned long)rmsgp);
-               rqstp->rq_arg.head[0].iov_len -= len;
-               if (len > rqstp->rq_arg.len)
+               rq_arg->head[0].iov_len -= len;
+               if (len > rq_arg->len)
                        return -EINVAL;
                return len;
        default:
@@ -205,7 +218,7 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
         * chunk list and a reply chunk list.
         */
        va = &rmsgp->rm_body.rm_chunks[0];
-       vaend = (__be32 *)((unsigned long)rmsgp + rqstp->rq_arg.len);
+       vaend = (__be32 *)((unsigned long)rmsgp + rq_arg->len);
        va = decode_read_list(va, vaend);
        if (!va) {
                dprintk("svcrdma: failed to decode read list\n");
@@ -222,10 +235,9 @@ int svc_rdma_xdr_decode_req(struct rpcrdma_msg *rmsgp, struct svc_rqst *rqstp)
                return -EINVAL;
        }
 
-       rqstp->rq_arg.head[0].iov_base = va;
+       rq_arg->head[0].iov_base = va;
        hdr_len = (unsigned long)va - (unsigned long)rmsgp;
-       rqstp->rq_arg.head[0].iov_len -= hdr_len;
-
+       rq_arg->head[0].iov_len -= hdr_len;
        return hdr_len;
 }
 
index fbe7444e7de6ab05ee1c6e91d09b03eca7ba1f3f..2c25606f25614da9fb181ead55c6c6d7a1546b62 100644 (file)
@@ -447,10 +447,8 @@ static int rdma_read_chunks(struct svcxprt_rdma *xprt,
        head->arg.len = rqstp->rq_arg.len;
        head->arg.buflen = rqstp->rq_arg.buflen;
 
-       ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
-       position = be32_to_cpu(ch->rc_position);
-
        /* RDMA_NOMSG: RDMA READ data should land just after RDMA RECV data */
+       position = be32_to_cpu(ch->rc_position);
        if (position == 0) {
                head->arg.pages = &head->pages[0];
                page_offset = head->byte_len;
@@ -488,7 +486,7 @@ static int rdma_read_chunks(struct svcxprt_rdma *xprt,
        if (page_offset & 3) {
                u32 pad = 4 - (page_offset & 3);
 
-               head->arg.page_len += pad;
+               head->arg.tail[0].iov_len += pad;
                head->arg.len += pad;
                head->arg.buflen += pad;
                page_offset += pad;
@@ -510,11 +508,10 @@ static int rdma_read_chunks(struct svcxprt_rdma *xprt,
        return ret;
 }
 
-static int rdma_read_complete(struct svc_rqst *rqstp,
-                             struct svc_rdma_op_ctxt *head)
+static void rdma_read_complete(struct svc_rqst *rqstp,
+                              struct svc_rdma_op_ctxt *head)
 {
        int page_no;
-       int ret;
 
        /* Copy RPC pages */
        for (page_no = 0; page_no < head->count; page_no++) {
@@ -550,23 +547,6 @@ static int rdma_read_complete(struct svc_rqst *rqstp,
        rqstp->rq_arg.tail[0] = head->arg.tail[0];
        rqstp->rq_arg.len = head->arg.len;
        rqstp->rq_arg.buflen = head->arg.buflen;
-
-       /* Free the context */
-       svc_rdma_put_context(head, 0);
-
-       /* XXX: What should this be? */
-       rqstp->rq_prot = IPPROTO_MAX;
-       svc_xprt_copy_addrs(rqstp, rqstp->rq_xprt);
-
-       ret = rqstp->rq_arg.head[0].iov_len
-               + rqstp->rq_arg.page_len
-               + rqstp->rq_arg.tail[0].iov_len;
-       dprintk("svcrdma: deferred read ret=%d, rq_arg.len=%u, "
-               "rq_arg.head[0].iov_base=%p, rq_arg.head[0].iov_len=%zu\n",
-               ret, rqstp->rq_arg.len, rqstp->rq_arg.head[0].iov_base,
-               rqstp->rq_arg.head[0].iov_len);
-
-       return ret;
 }
 
 /* By convention, backchannel calls arrive via rdma_msg type
@@ -624,7 +604,8 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
                                  dto_q);
                list_del_init(&ctxt->dto_q);
                spin_unlock_bh(&rdma_xprt->sc_rq_dto_lock);
-               return rdma_read_complete(rqstp, ctxt);
+               rdma_read_complete(rqstp, ctxt);
+               goto complete;
        } else if (!list_empty(&rdma_xprt->sc_rq_dto_q)) {
                ctxt = list_entry(rdma_xprt->sc_rq_dto_q.next,
                                  struct svc_rdma_op_ctxt,
@@ -655,7 +636,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
 
        /* Decode the RDMA header. */
        rmsgp = (struct rpcrdma_msg *)rqstp->rq_arg.head[0].iov_base;
-       ret = svc_rdma_xdr_decode_req(rmsgp, rqstp);
+       ret = svc_rdma_xdr_decode_req(&rqstp->rq_arg);
        if (ret < 0)
                goto out_err;
        if (ret == 0)
@@ -682,6 +663,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
                return 0;
        }
 
+complete:
        ret = rqstp->rq_arg.head[0].iov_len
                + rqstp->rq_arg.page_len
                + rqstp->rq_arg.tail[0].iov_len;
index 4f1b1c4f45f9d11d1ca3df8767ea76e6b07d99ae..54d53330062030b682fcd8f267e7d79448c6a5ef 100644 (file)
@@ -463,25 +463,21 @@ static int send_reply(struct svcxprt_rdma *rdma,
                      struct svc_rqst *rqstp,
                      struct page *page,
                      struct rpcrdma_msg *rdma_resp,
-                     struct svc_rdma_op_ctxt *ctxt,
                      struct svc_rdma_req_map *vec,
                      int byte_count)
 {
+       struct svc_rdma_op_ctxt *ctxt;
        struct ib_send_wr send_wr;
        u32 xdr_off;
        int sge_no;
        int sge_bytes;
        int page_no;
        int pages;
-       int ret;
-
-       ret = svc_rdma_repost_recv(rdma, GFP_KERNEL);
-       if (ret) {
-               svc_rdma_put_context(ctxt, 0);
-               return -ENOTCONN;
-       }
+       int ret = -EIO;
 
        /* Prepare the context */
+       ctxt = svc_rdma_get_context(rdma);
+       ctxt->direction = DMA_TO_DEVICE;
        ctxt->pages[0] = page;
        ctxt->count = 1;
 
@@ -565,8 +561,7 @@ static int send_reply(struct svcxprt_rdma *rdma,
  err:
        svc_rdma_unmap_dma(ctxt);
        svc_rdma_put_context(ctxt, 1);
-       pr_err("svcrdma: failed to send reply, rc=%d\n", ret);
-       return -EIO;
+       return ret;
 }
 
 void svc_rdma_prep_reply_hdr(struct svc_rqst *rqstp)
@@ -585,7 +580,6 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        int ret;
        int inline_bytes;
        struct page *res_page;
-       struct svc_rdma_op_ctxt *ctxt;
        struct svc_rdma_req_map *vec;
 
        dprintk("svcrdma: sending response for rqstp=%p\n", rqstp);
@@ -598,8 +592,6 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        rp_ary = svc_rdma_get_reply_array(rdma_argp, wr_ary);
 
        /* Build an req vec for the XDR */
-       ctxt = svc_rdma_get_context(rdma);
-       ctxt->direction = DMA_TO_DEVICE;
        vec = svc_rdma_get_req_map(rdma);
        ret = svc_rdma_map_xdr(rdma, &rqstp->rq_res, vec, wr_ary != NULL);
        if (ret)
@@ -635,7 +627,12 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
                inline_bytes -= ret;
        }
 
-       ret = send_reply(rdma, rqstp, res_page, rdma_resp, ctxt, vec,
+       /* Post a fresh Receive buffer _before_ sending the reply */
+       ret = svc_rdma_post_recv(rdma, GFP_KERNEL);
+       if (ret)
+               goto err1;
+
+       ret = send_reply(rdma, rqstp, res_page, rdma_resp, vec,
                         inline_bytes);
        if (ret < 0)
                goto err1;
@@ -648,7 +645,8 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        put_page(res_page);
  err0:
        svc_rdma_put_req_map(rdma, vec);
-       svc_rdma_put_context(ctxt, 0);
+       pr_err("svcrdma: Could not send reply, err=%d. Closing transport.\n",
+              ret);
        set_bit(XPT_CLOSE, &rdma->sc_xprt.xpt_flags);
        return -ENOTCONN;
 }
index 90668969d5596b199c9fad0c188a3d72dccc99e6..dd9440137834c7b1a55b433a1a91bb52efa26acc 100644 (file)
@@ -789,7 +789,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
        int ret;
 
        dprintk("svcrdma: Creating RDMA socket\n");
-       if (sa->sa_family != AF_INET) {
+       if ((sa->sa_family != AF_INET) && (sa->sa_family != AF_INET6)) {
                dprintk("svcrdma: Address family %d is not supported.\n", sa->sa_family);
                return ERR_PTR(-EAFNOSUPPORT);
        }
@@ -805,6 +805,16 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
                goto err0;
        }
 
+       /* Allow both IPv4 and IPv6 sockets to bind a single port
+        * at the same time.
+        */
+#if IS_ENABLED(CONFIG_IPV6)
+       ret = rdma_set_afonly(listen_id, 1);
+       if (ret) {
+               dprintk("svcrdma: rdma_set_afonly failed = %d\n", ret);
+               goto err1;
+       }
+#endif
        ret = rdma_bind_addr(listen_id, sa);
        if (ret) {
                dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
@@ -1073,7 +1083,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
                newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_READ_W_INV;
 
        /* Post receive buffers */
-       for (i = 0; i < newxprt->sc_rq_depth; i++) {
+       for (i = 0; i < newxprt->sc_max_requests; i++) {
                ret = svc_rdma_post_recv(newxprt, GFP_KERNEL);
                if (ret) {
                        dprintk("svcrdma: failure posting receive buffers\n");
@@ -1170,6 +1180,9 @@ static void __svc_rdma_free(struct work_struct *work)
 
        dprintk("svcrdma: %s(%p)\n", __func__, rdma);
 
+       if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
+               ib_drain_qp(rdma->sc_qp);
+
        /* We should only be called from kref_put */
        if (atomic_read(&xprt->xpt_ref.refcount) != 0)
                pr_err("svcrdma: sc_xprt still in use? (%d)\n",
index 7947e568e0576905265e58a19caf6886633acaac..2e58549b2f0211ac11747d35b71c05145e81fbe7 100644 (file)
@@ -1234,6 +1234,10 @@ TEST_F(TRACE_poke, getpid_runs_normally)
 # define ARCH_REGS     struct user_pt_regs
 # define SYSCALL_NUM   regs[8]
 # define SYSCALL_RET   regs[0]
+#elif defined(__hppa__)
+# define ARCH_REGS     struct user_regs_struct
+# define SYSCALL_NUM   gr[20]
+# define SYSCALL_RET   gr[28]
 #elif defined(__powerpc__)
 # define ARCH_REGS     struct pt_regs
 # define SYSCALL_NUM   gpr[0]
@@ -1303,7 +1307,7 @@ void change_syscall(struct __test_metadata *_metadata,
        EXPECT_EQ(0, ret);
 
 #if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
-    defined(__s390__)
+    defined(__s390__) || defined(__hppa__)
        {
                regs.SYSCALL_NUM = syscall;
        }
@@ -1505,6 +1509,8 @@ TEST_F(TRACE_syscall, syscall_dropped)
 #  define __NR_seccomp 383
 # elif defined(__aarch64__)
 #  define __NR_seccomp 277
+# elif defined(__hppa__)
+#  define __NR_seccomp 338
 # elif defined(__powerpc__)
 #  define __NR_seccomp 358
 # elif defined(__s390__)
index c87957295f74ae6830f6348ea0482427901c4493..0bc737a75150bf225f6b3508182341536b66c88e 100644 (file)
@@ -30,7 +30,9 @@
 #define MAP_HUGE_1GB    (30 << MAP_HUGE_SHIFT)
 #define MAP_HUGE_SHIFT  26
 #define MAP_HUGE_MASK   0x3f
+#if !defined(MAP_HUGETLB)
 #define MAP_HUGETLB    0x40000
+#endif
 
 #define SHM_HUGETLB     04000   /* segment will use huge TLB pages */
 #define SHM_HUGE_SHIFT  26
index feaa64ac463018f03b9a80e4270281127e9b96c1..6ba7455298338988f1e4454b0fec3c41bb61bc89 100644 (file)
@@ -1,6 +1,6 @@
 all:
 
-all: ring virtio_ring_0_9 virtio_ring_poll
+all: ring virtio_ring_0_9 virtio_ring_poll virtio_ring_inorder
 
 CFLAGS += -Wall
 CFLAGS += -pthread -O2 -ggdb
@@ -10,13 +10,16 @@ main.o: main.c main.h
 ring.o: ring.c main.h
 virtio_ring_0_9.o: virtio_ring_0_9.c main.h
 virtio_ring_poll.o: virtio_ring_poll.c virtio_ring_0_9.c main.h
+virtio_ring_inorder.o: virtio_ring_inorder.c virtio_ring_0_9.c main.h
 ring: ring.o main.o
 virtio_ring_0_9: virtio_ring_0_9.o main.o
 virtio_ring_poll: virtio_ring_poll.o main.o
+virtio_ring_inorder: virtio_ring_inorder.o main.o
 clean:
        -rm main.o
        -rm ring.o ring
        -rm virtio_ring_0_9.o virtio_ring_0_9
        -rm virtio_ring_poll.o virtio_ring_poll
+       -rm virtio_ring_inorder.o virtio_ring_inorder
 
 .PHONY: all clean
index 3a5ff438bd62f62296f6cbe5cf3a42e7f5bb1078..147abb452a6ccc098bf50338e0c353f4b8896f8a 100644 (file)
@@ -115,7 +115,7 @@ static void run_guest(void)
                do {
                        if (started < bufs &&
                            started - completed < max_outstanding) {
-                               r = add_inbuf(0, NULL, "Hello, world!");
+                               r = add_inbuf(0, "Buffer\n", "Hello, world!");
                                if (__builtin_expect(r == 0, true)) {
                                        ++started;
                                        if (!--tokick) {
index 47c9a1a18d361fa7b72c5ef67545f719327addb6..761866212aacf1149d03ef1151ac7727c944db72 100644 (file)
@@ -26,6 +26,14 @@ struct vring ring;
  * high bits of ring id ^ 0x8000).
  */
 /* #ifdef RING_POLL */
+/* enabling the below activates experimental in-order code
+ * (which skips ring updates and reads and writes len in descriptor).
+ */
+/* #ifdef INORDER */
+
+#if defined(RING_POLL) && defined(INORDER)
+#error "RING_POLL and INORDER are mutually exclusive"
+#endif
 
 /* how much padding is needed to avoid false cache sharing */
 #define HOST_GUEST_PADDING 0x80
@@ -35,7 +43,11 @@ struct guest {
        unsigned short last_used_idx;
        unsigned short num_free;
        unsigned short kicked_avail_idx;
+#ifndef INORDER
        unsigned short free_head;
+#else
+       unsigned short reserved_free_head;
+#endif
        unsigned char reserved[HOST_GUEST_PADDING - 10];
 } guest;
 
@@ -66,8 +78,10 @@ void alloc_ring(void)
        guest.avail_idx = 0;
        guest.kicked_avail_idx = -1;
        guest.last_used_idx = 0;
+#ifndef INORDER
        /* Put everything in free lists. */
        guest.free_head = 0;
+#endif
        for (i = 0; i < ring_size - 1; i++)
                ring.desc[i].next = i + 1;
        host.used_idx = 0;
@@ -84,13 +98,20 @@ void alloc_ring(void)
 /* guest side */
 int add_inbuf(unsigned len, void *buf, void *datap)
 {
-       unsigned head, avail;
+       unsigned head;
+#ifndef INORDER
+       unsigned avail;
+#endif
        struct vring_desc *desc;
 
        if (!guest.num_free)
                return -1;
 
+#ifdef INORDER
+       head = (ring_size - 1) & (guest.avail_idx++);
+#else
        head = guest.free_head;
+#endif
        guest.num_free--;
 
        desc = ring.desc;
@@ -102,7 +123,9 @@ int add_inbuf(unsigned len, void *buf, void *datap)
         * descriptors.
         */
        desc[head].flags &= ~VRING_DESC_F_NEXT;
+#ifndef INORDER
        guest.free_head = desc[head].next;
+#endif
 
        data[head].data = datap;
 
@@ -113,8 +136,12 @@ int add_inbuf(unsigned len, void *buf, void *datap)
        ring.avail->ring[avail & (ring_size - 1)] =
                (head | (avail & ~(ring_size - 1))) ^ 0x8000;
 #else
+#ifndef INORDER
+       /* Barrier A (for pairing) */
+       smp_release();
        avail = (ring_size - 1) & (guest.avail_idx++);
        ring.avail->ring[avail] = head;
+#endif
        /* Barrier A (for pairing) */
        smp_release();
 #endif
@@ -141,15 +168,27 @@ void *get_buf(unsigned *lenp, void **bufp)
                return NULL;
        /* Barrier B (for pairing) */
        smp_acquire();
+#ifdef INORDER
+       head = (ring_size - 1) & guest.last_used_idx;
+       index = head;
+#else
        head = (ring_size - 1) & guest.last_used_idx;
        index = ring.used->ring[head].id;
 #endif
+
+#endif
+#ifdef INORDER
+       *lenp = ring.desc[index].len;
+#else
        *lenp = ring.used->ring[head].len;
+#endif
        datap = data[index].data;
        *bufp = (void*)(unsigned long)ring.desc[index].addr;
        data[index].data = NULL;
+#ifndef INORDER
        ring.desc[index].next = guest.free_head;
        guest.free_head = index;
+#endif
        guest.num_free++;
        guest.last_used_idx++;
        return datap;
@@ -283,16 +322,24 @@ bool use_buf(unsigned *lenp, void **bufp)
        smp_acquire();
 
        used_idx &= ring_size - 1;
+#ifdef INORDER
+       head = used_idx;
+#else
        head = ring.avail->ring[used_idx];
+#endif
        desc = &ring.desc[head];
 #endif
 
        *lenp = desc->len;
        *bufp = (void *)(unsigned long)desc->addr;
 
+#ifdef INORDER
+       desc->len = desc->len - 1;
+#else
        /* now update used ring */
        ring.used->ring[used_idx].id = head;
        ring.used->ring[used_idx].len = desc->len - 1;
+#endif
        /* Barrier B (for pairing) */
        smp_release();
        host.used_idx++;
diff --git a/tools/virtio/ringtest/virtio_ring_inorder.c b/tools/virtio/ringtest/virtio_ring_inorder.c
new file mode 100644 (file)
index 0000000..2438ca5
--- /dev/null
@@ -0,0 +1,2 @@
+#define INORDER 1
+#include "virtio_ring_0_9.c"