···11+# SPDX-License-Identifier: (GPL-2.0-or-later)22+%YAML 1.233+---44+$id: http://devicetree.org/schemas/fsi/ibm,fsi2spi.yaml#55+$schema: http://devicetree.org/meta-schemas/core.yaml#66+77+title: IBM FSI-attached SPI controllers88+99+maintainers:1010+ - Eddie James <eajames@linux.ibm.com>1111+1212+description: |1313+ This binding describes an FSI CFAM engine called the FSI2SPI. Therefore this1414+ node will always be a child of an FSI CFAM node; see fsi.txt for details on1515+ FSI slave and CFAM nodes. This FSI2SPI engine provides access to a number of1616+ SPI controllers.1717+1818+properties:1919+ compatible:2020+ enum:2121+ - ibm,fsi2spi2222+2323+ reg:2424+ items:2525+ - description: FSI slave address2626+2727+required:2828+ - compatible2929+ - reg3030+3131+examples:3232+ - |3333+ fsi2spi@1c00 {3434+ compatible = "ibm,fsi2spi";3535+ reg = <0x1c00 0x400>;3636+ };
···11-* Serial NOR flash controller for MediaTek SoCs11+* Serial NOR flash controller for MediaTek ARM SoCs2233Required properties:44- compatible: For mt8173, compatible should be "mediatek,mt8173-nor",···1313 "mediatek,mt7629-nor", "mediatek,mt8173-nor"1414 "mediatek,mt8173-nor"1515- reg: physical base address and length of the controller's register1616+- interrupts: Interrupt number used by the controller.1617- clocks: the phandle of the clocks needed by the nor controller1718- clock-names: the names of the clocks1819 the clocks should be named "spi" and "sf". "spi" is used for spi bus,···2322- #address-cells: should be <1>2423- #size-cells: should be <0>25242626-The SPI flash must be a child of the nor_flash node and must have a2727-compatible property. Also see jedec,spi-nor.txt.2828-2929-Required properties:3030-- compatible: May include a device-specific string consisting of the manufacturer3131- and name of the chip. Must also include "jedec,spi-nor" for any3232- SPI NOR flash that can be identified by the JEDEC READ ID opcode (0x9F).3333-- reg : Chip-Select number2525+There should be only one spi slave device following generic spi bindings.2626+It's not recommended to use this controller for devices other than SPI NOR2727+flash due to limited transfer capability of this controller.34283529Example:36303731nor_flash: spi@1100d000 {3832 compatible = "mediatek,mt8173-nor";3933 reg = <0 0x1100d000 0 0xe0>;3434+ interrupts = <&spi_flash_irq>;4035 clocks = <&pericfg CLK_PERI_SPI>,4136 <&topckgen CLK_TOP_SPINFI_IFR_SEL>;4237 clock-names = "spi", "sf";
···1010 - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX351111 - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX511212 - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc1313- - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8M1313+ - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8MQ1414+ - "fsl,imx8mm-ecspi" for SPI compatible with the one integrated on i.MX8MM1515+ - "fsl,imx8mn-ecspi" for SPI compatible with the one integrated on i.MX8MN1616+ - "fsl,imx8mp-ecspi" for SPI compatible with the one integrated on i.MX8MP1417- reg : Offset and length of the register set for the device1518- interrupts : Should contain CSPI/eCSPI interrupt1619- clocks : Clock specifiers for both ipg and per clocks.
···5252 description:5353 The SPI controller acts as a slave, instead of a master.54545555+oneOf:5656+ - required:5757+ - "#address-cells"5858+ - required:5959+ - spi-slave6060+5561patternProperties:5662 "^slave$":5763 type: object···120114 - enum: [ 1, 2, 4, 8 ]121115 - default: 1122116 description:123123- Bus width to the SPI bus used for MISO.117117+ Bus width to the SPI bus used for read transfers.124118125119 spi-rx-delay-us:126120 description:···132126 - enum: [ 1, 2, 4, 8 ]133127 - default: 1134128 description:135135- Bus width to the SPI bus used for MOSI.129129+ Bus width to the SPI bus used for write transfers.136130137131 spi-tx-delay-us:138132 description:
···11ARM Freescale DSPI controller2233Required properties:44-- compatible : "fsl,vf610-dspi", "fsl,ls1021a-v1.0-dspi",55- "fsl,ls2085a-dspi"66- or77- "fsl,ls2080a-dspi" followed by "fsl,ls2085a-dspi"88- "fsl,ls1012a-dspi" followed by "fsl,ls1021a-v1.0-dspi"99- "fsl,ls1088a-dspi" followed by "fsl,ls1021a-v1.0-dspi"44+- compatible : must be one of:55+ "fsl,vf610-dspi",66+ "fsl,ls1021a-v1.0-dspi",77+ "fsl,ls1012a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"),88+ "fsl,ls1028a-dspi",99+ "fsl,ls1043a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"),1010+ "fsl,ls1046a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"),1111+ "fsl,ls1088a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"),1212+ "fsl,ls2080a-dspi" (optionally followed by "fsl,ls2085a-dspi"),1313+ "fsl,ls2085a-dspi",1414+ "fsl,lx2160a-dspi",1015- reg : Offset and length of the register set for the device1116- interrupts : Should contain SPI controller interrupt1217- clocks: from common clock binding: handle to dspi clock.···1914- pinctrl-0: pin control group to be used for this controller.2015- pinctrl-names: must contain a "default" entry.2116- spi-num-chipselects : the number of the chipselect signals.2222-- bus-num : the slave chip chipselect signal number.23172418Optional property:2519- big-endian: If present the dspi device's registers are implemented2620 in big endian mode.2121+- bus-num : the slave chip chipselect signal number.27222823Optional SPI slave node properties:2924- fsl,spi-cs-sck-delay: a delay in nanoseconds between activating chip
···2233Required properties:44 - compatible : Should be "nxp,lx2160a-fspi"55+ "nxp,imx8qxp-fspi"66+ "nxp,imx8mm-fspi"77+58 - reg : First contains the register location and length,69 Second contains the memory mapping address and length710 - reg-names : Should contain the resource reg names:
···11-* Rockchip SPI Controller22-33-The Rockchip SPI controller is used to interface with various devices such as flash44-and display controllers using the SPI communication interface.55-66-Required Properties:77-88-- compatible: should be one of the following.99- "rockchip,rv1108-spi" for rv1108 SoCs.1010- "rockchip,px30-spi", "rockchip,rk3066-spi" for px30 SoCs.1111- "rockchip,rk3036-spi" for rk3036 SoCS.1212- "rockchip,rk3066-spi" for rk3066 SoCs.1313- "rockchip,rk3188-spi" for rk3188 SoCs.1414- "rockchip,rk3228-spi" for rk3228 SoCS.1515- "rockchip,rk3288-spi" for rk3288 SoCs.1616- "rockchip,rk3368-spi" for rk3368 SoCs.1717- "rockchip,rk3399-spi" for rk3399 SoCs.1818-- reg: physical base address of the controller and length of memory mapped1919- region.2020-- interrupts: The interrupt number to the cpu. The interrupt specifier format2121- depends on the interrupt controller.2222-- clocks: Must contain an entry for each entry in clock-names.2323-- clock-names: Shall be "spiclk" for the transfer-clock, and "apb_pclk" for2424- the peripheral clock.2525-- #address-cells: should be 1.2626-- #size-cells: should be 0.2727-2828-Optional Properties:2929-3030-- dmas: DMA specifiers for tx and rx dma. See the DMA client binding,3131- Documentation/devicetree/bindings/dma/dma.txt3232-- dma-names: DMA request names should include "tx" and "rx" if present.3333-- rx-sample-delay-ns: nanoseconds to delay after the SCLK edge before sampling3434- Rx data (may need to be fine tuned for high capacitance lines).3535- No delay (0) by default.3636-- pinctrl-names: Names for the pin configuration(s); may be "default" or3737- "sleep", where the "sleep" configuration may describe the state3838- the pins should be in during system suspend. See also3939- pinctrl/pinctrl-bindings.txt.4040-4141-4242-Example:4343-4444- spi0: spi@ff110000 {4545- compatible = "rockchip,rk3066-spi";4646- reg = <0xff110000 0x1000>;4747- dmas = <&pdma1 11>, <&pdma1 12>;4848- dma-names = "tx", "rx";4949- rx-sample-delay-ns = <10>;5050- #address-cells = <1>;5151- #size-cells = <0>;5252- interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>;5353- clocks = <&cru SCLK_SPI0>, <&cru PCLK_SPI0>;5454- clock-names = "spiclk", "apb_pclk";5555- pinctrl-0 = <&spi1_pins>;5656- pinctrl-1 = <&spi1_sleep>;5757- pinctrl-names = "default", "sleep";5858- };
···11+# SPDX-License-Identifier: GPL-2.022+%YAML 1.233+---44+$id: http://devicetree.org/schemas/spi/spi-rockchip.yaml#55+$schema: http://devicetree.org/meta-schemas/core.yaml#66+77+title: Rockchip SPI Controller88+99+description:1010+ The Rockchip SPI controller is used to interface with various devices such1111+ as flash and display controllers using the SPI communication interface.1212+1313+allOf:1414+ - $ref: "spi-controller.yaml#"1515+1616+maintainers:1717+ - Heiko Stuebner <heiko@sntech.de>1818+1919+# Everything else is described in the common file2020+properties:2121+ compatible:2222+ oneOf:2323+ - const: rockchip,rk3036-spi2424+ - const: rockchip,rk3066-spi2525+ - const: rockchip,rk3228-spi2626+ - const: rockchip,rv1108-spi2727+ - items:2828+ - enum:2929+ - rockchip,px30-spi3030+ - rockchip,rk3188-spi3131+ - rockchip,rk3288-spi3232+ - rockchip,rk3308-spi3333+ - rockchip,rk3328-spi3434+ - rockchip,rk3368-spi3535+ - rockchip,rk3399-spi3636+ - const: rockchip,rk3066-spi3737+3838+ reg:3939+ maxItems: 14040+4141+ interrupts:4242+ maxItems: 14343+4444+ clocks:4545+ items:4646+ - description: transfer-clock4747+ - description: peripheral clock4848+4949+ clock-names:5050+ items:5151+ - const: spiclk5252+ - const: apb_pclk5353+5454+ dmas:5555+ items:5656+ - description: TX DMA Channel5757+ - description: RX DMA Channel5858+5959+ dma-names:6060+ items:6161+ - const: tx6262+ - const: rx6363+6464+ rx-sample-delay-ns:6565+ default: 06666+ description:6767+ Nano seconds to delay after the SCLK edge before sampling Rx data6868+ (may need to be fine tuned for high capacitance lines).6969+ If not specified 0 will be used.7070+7171+ pinctrl-names:7272+ minItems: 17373+ items:7474+ - const: default7575+ - const: sleep7676+ description:7777+ Names for the pin configuration(s); may be "default" or "sleep",7878+ where the "sleep" configuration may describe the state7979+ the pins should be in during system suspend.8080+8181+required:8282+ - compatible8383+ - reg8484+ - interrupts8585+ - clocks8686+ - clock-names8787+8888+examples:8989+ - |9090+ #include <dt-bindings/clock/rk3188-cru-common.h>9191+ #include <dt-bindings/interrupt-controller/arm-gic.h>9292+ #include <dt-bindings/interrupt-controller/irq.h>9393+ spi0: spi@ff110000 {9494+ compatible = "rockchip,rk3066-spi";9595+ reg = <0xff110000 0x1000>;9696+ interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>;9797+ clocks = <&cru SCLK_SPI0>, <&cru PCLK_SPI0>;9898+ clock-names = "spiclk", "apb_pclk";9999+ dmas = <&pdma1 11>, <&pdma1 12>;100100+ dma-names = "tx", "rx";101101+ pinctrl-0 = <&spi1_pins>;102102+ pinctrl-1 = <&spi1_sleep>;103103+ pinctrl-names = "default", "sleep";104104+ rx-sample-delay-ns = <10>;105105+ #address-cells = <1>;106106+ #size-cells = <0>;107107+ };
+10-1
MAINTAINERS
···22762276S: Maintained22772277F: Documentation/devicetree/bindings/i2c/i2c-rk3x.txt22782278F: Documentation/devicetree/bindings/mmc/rockchip-dw-mshc.yaml22792279+F: Documentation/devicetree/bindings/spi/spi-rockchip.yaml22792280F: arch/arm/boot/dts/rk3*22802281F: arch/arm/boot/dts/rv1108*22812282F: arch/arm/mach-rockchip/···68596858F: drivers/i2c/busses/i2c-fsi.c68606859F: Documentation/devicetree/bindings/i2c/i2c-fsi.txt6861686068616861+FSI-ATTACHED SPI DRIVER68626862+M: Eddie James <eajames@linux.ibm.com>68636863+L: linux-spi@vger.kernel.org68646864+S: Maintained68656865+F: drivers/spi/spi-fsi.c68666866+F: Documentation/devicetree/bindings/fsi/ibm,fsi2spi.yaml68676867+68626868FSNOTIFY: FILESYSTEM NOTIFICATION INFRASTRUCTURE68636869M: Jan Kara <jack@suse.cz>68646870R: Amir Goldstein <amir73il@gmail.com>···1126411256MONOLITHIC POWER SYSTEM PMIC DRIVER1126511257M: Saravanan Sekar <sravanhome@gmail.com>1126611258S: Maintained1126711267-F: Documentation/devicetree/bindings/regulator/mpq7920.yaml1125911259+F: Documentation/devicetree/bindings/regulator/mps,mp*.yaml1126011260+F: drivers/regulator/mp5416.c1126811261F: drivers/regulator/mpq7920.c1126911262F: drivers/regulator/mpq7920.h1127011263
-8
drivers/mtd/spi-nor/Kconfig
···5252 help5353 This enables support for HiSilicon FMC SPI-NOR flash controller.54545555-config SPI_MTK_QUADSPI5656- tristate "MediaTek Quad SPI controller"5757- depends on HAS_IOMEM5858- help5959- This enables support for the Quad SPI controller in master mode.6060- This controller does not support generic SPI. It only supports6161- SPI NOR.6262-6355config SPI_NXP_SPIFI6456 tristate "NXP SPI Flash Interface (SPIFI)"6557 depends on OF && (ARCH_LPC18XX || COMPILE_TEST)
···11-// SPDX-License-Identifier: GPL-2.0-only22-/*33- * Copyright (c) 2015 MediaTek Inc.44- * Author: Bayi Cheng <bayi.cheng@mediatek.com>55- */66-77-#include <linux/clk.h>88-#include <linux/delay.h>99-#include <linux/device.h>1010-#include <linux/init.h>1111-#include <linux/io.h>1212-#include <linux/iopoll.h>1313-#include <linux/ioport.h>1414-#include <linux/math64.h>1515-#include <linux/module.h>1616-#include <linux/mutex.h>1717-#include <linux/of.h>1818-#include <linux/of_device.h>1919-#include <linux/platform_device.h>2020-#include <linux/slab.h>2121-#include <linux/mtd/mtd.h>2222-#include <linux/mtd/partitions.h>2323-#include <linux/mtd/spi-nor.h>2424-2525-#define MTK_NOR_CMD_REG 0x002626-#define MTK_NOR_CNT_REG 0x042727-#define MTK_NOR_RDSR_REG 0x082828-#define MTK_NOR_RDATA_REG 0x0c2929-#define MTK_NOR_RADR0_REG 0x103030-#define MTK_NOR_RADR1_REG 0x143131-#define MTK_NOR_RADR2_REG 0x183232-#define MTK_NOR_WDATA_REG 0x1c3333-#define MTK_NOR_PRGDATA0_REG 0x203434-#define MTK_NOR_PRGDATA1_REG 0x243535-#define MTK_NOR_PRGDATA2_REG 0x283636-#define MTK_NOR_PRGDATA3_REG 0x2c3737-#define MTK_NOR_PRGDATA4_REG 0x303838-#define MTK_NOR_PRGDATA5_REG 0x343939-#define MTK_NOR_SHREG0_REG 0x384040-#define MTK_NOR_SHREG1_REG 0x3c4141-#define MTK_NOR_SHREG2_REG 0x404242-#define MTK_NOR_SHREG3_REG 0x444343-#define MTK_NOR_SHREG4_REG 0x484444-#define MTK_NOR_SHREG5_REG 0x4c4545-#define MTK_NOR_SHREG6_REG 0x504646-#define MTK_NOR_SHREG7_REG 0x544747-#define MTK_NOR_SHREG8_REG 0x584848-#define MTK_NOR_SHREG9_REG 0x5c4949-#define MTK_NOR_CFG1_REG 0x605050-#define MTK_NOR_CFG2_REG 0x645151-#define MTK_NOR_CFG3_REG 0x685252-#define MTK_NOR_STATUS0_REG 0x705353-#define MTK_NOR_STATUS1_REG 0x745454-#define MTK_NOR_STATUS2_REG 0x785555-#define MTK_NOR_STATUS3_REG 0x7c5656-#define MTK_NOR_FLHCFG_REG 0x845757-#define MTK_NOR_TIME_REG 0x945858-#define MTK_NOR_PP_DATA_REG 0x985959-#define MTK_NOR_PREBUF_STUS_REG 0x9c6060-#define MTK_NOR_DELSEL0_REG 0xa06161-#define MTK_NOR_DELSEL1_REG 0xa46262-#define MTK_NOR_INTRSTUS_REG 0xa86363-#define MTK_NOR_INTREN_REG 0xac6464-#define MTK_NOR_CHKSUM_CTL_REG 0xb86565-#define MTK_NOR_CHKSUM_REG 0xbc6666-#define MTK_NOR_CMD2_REG 0xc06767-#define MTK_NOR_WRPROT_REG 0xc46868-#define MTK_NOR_RADR3_REG 0xc86969-#define MTK_NOR_DUAL_REG 0xcc7070-#define MTK_NOR_DELSEL2_REG 0xd07171-#define MTK_NOR_DELSEL3_REG 0xd47272-#define MTK_NOR_DELSEL4_REG 0xd87373-7474-/* commands for mtk nor controller */7575-#define MTK_NOR_READ_CMD 0x07676-#define MTK_NOR_RDSR_CMD 0x27777-#define MTK_NOR_PRG_CMD 0x47878-#define MTK_NOR_WR_CMD 0x107979-#define MTK_NOR_PIO_WR_CMD 0x908080-#define MTK_NOR_WRSR_CMD 0x208181-#define MTK_NOR_PIO_READ_CMD 0x818282-#define MTK_NOR_WR_BUF_ENABLE 0x18383-#define MTK_NOR_WR_BUF_DISABLE 0x08484-#define MTK_NOR_ENABLE_SF_CMD 0x308585-#define MTK_NOR_DUAD_ADDR_EN 0x88686-#define MTK_NOR_QUAD_READ_EN 0x48787-#define MTK_NOR_DUAL_ADDR_EN 0x28888-#define MTK_NOR_DUAL_READ_EN 0x18989-#define MTK_NOR_DUAL_DISABLE 0x09090-#define MTK_NOR_FAST_READ 0x19191-9292-#define SFLASH_WRBUF_SIZE 1289393-9494-/* Can shift up to 48 bits (6 bytes) of TX/RX */9595-#define MTK_NOR_MAX_RX_TX_SHIFT 69696-/* can shift up to 56 bits (7 bytes) transfer by MTK_NOR_PRG_CMD */9797-#define MTK_NOR_MAX_SHIFT 79898-/* nor controller 4-byte address mode enable bit */9999-#define MTK_NOR_4B_ADDR_EN BIT(4)100100-101101-/* Helpers for accessing the program data / shift data registers */102102-#define MTK_NOR_PRG_REG(n) (MTK_NOR_PRGDATA0_REG + 4 * (n))103103-#define MTK_NOR_SHREG(n) (MTK_NOR_SHREG0_REG + 4 * (n))104104-105105-struct mtk_nor {106106- struct spi_nor nor;107107- struct device *dev;108108- void __iomem *base; /* nor flash base address */109109- struct clk *spi_clk;110110- struct clk *nor_clk;111111-};112112-113113-static void mtk_nor_set_read_mode(struct mtk_nor *mtk_nor)114114-{115115- struct spi_nor *nor = &mtk_nor->nor;116116-117117- switch (nor->read_proto) {118118- case SNOR_PROTO_1_1_1:119119- writeb(nor->read_opcode, mtk_nor->base +120120- MTK_NOR_PRGDATA3_REG);121121- writeb(MTK_NOR_FAST_READ, mtk_nor->base +122122- MTK_NOR_CFG1_REG);123123- break;124124- case SNOR_PROTO_1_1_2:125125- writeb(nor->read_opcode, mtk_nor->base +126126- MTK_NOR_PRGDATA3_REG);127127- writeb(MTK_NOR_DUAL_READ_EN, mtk_nor->base +128128- MTK_NOR_DUAL_REG);129129- break;130130- case SNOR_PROTO_1_1_4:131131- writeb(nor->read_opcode, mtk_nor->base +132132- MTK_NOR_PRGDATA4_REG);133133- writeb(MTK_NOR_QUAD_READ_EN, mtk_nor->base +134134- MTK_NOR_DUAL_REG);135135- break;136136- default:137137- writeb(MTK_NOR_DUAL_DISABLE, mtk_nor->base +138138- MTK_NOR_DUAL_REG);139139- break;140140- }141141-}142142-143143-static int mtk_nor_execute_cmd(struct mtk_nor *mtk_nor, u8 cmdval)144144-{145145- int reg;146146- u8 val = cmdval & 0x1f;147147-148148- writeb(cmdval, mtk_nor->base + MTK_NOR_CMD_REG);149149- return readl_poll_timeout(mtk_nor->base + MTK_NOR_CMD_REG, reg,150150- !(reg & val), 100, 10000);151151-}152152-153153-static int mtk_nor_do_tx_rx(struct mtk_nor *mtk_nor, u8 op,154154- const u8 *tx, size_t txlen, u8 *rx, size_t rxlen)155155-{156156- size_t len = 1 + txlen + rxlen;157157- int i, ret, idx;158158-159159- if (len > MTK_NOR_MAX_SHIFT)160160- return -EINVAL;161161-162162- writeb(len * 8, mtk_nor->base + MTK_NOR_CNT_REG);163163-164164- /* start at PRGDATA5, go down to PRGDATA0 */165165- idx = MTK_NOR_MAX_RX_TX_SHIFT - 1;166166-167167- /* opcode */168168- writeb(op, mtk_nor->base + MTK_NOR_PRG_REG(idx));169169- idx--;170170-171171- /* program TX data */172172- for (i = 0; i < txlen; i++, idx--)173173- writeb(tx[i], mtk_nor->base + MTK_NOR_PRG_REG(idx));174174-175175- /* clear out rest of TX registers */176176- while (idx >= 0) {177177- writeb(0, mtk_nor->base + MTK_NOR_PRG_REG(idx));178178- idx--;179179- }180180-181181- ret = mtk_nor_execute_cmd(mtk_nor, MTK_NOR_PRG_CMD);182182- if (ret)183183- return ret;184184-185185- /* restart at first RX byte */186186- idx = rxlen - 1;187187-188188- /* read out RX data */189189- for (i = 0; i < rxlen; i++, idx--)190190- rx[i] = readb(mtk_nor->base + MTK_NOR_SHREG(idx));191191-192192- return 0;193193-}194194-195195-/* Do a WRSR (Write Status Register) command */196196-static int mtk_nor_wr_sr(struct mtk_nor *mtk_nor, const u8 sr)197197-{198198- writeb(sr, mtk_nor->base + MTK_NOR_PRGDATA5_REG);199199- writeb(8, mtk_nor->base + MTK_NOR_CNT_REG);200200- return mtk_nor_execute_cmd(mtk_nor, MTK_NOR_WRSR_CMD);201201-}202202-203203-static int mtk_nor_write_buffer_enable(struct mtk_nor *mtk_nor)204204-{205205- u8 reg;206206-207207- /* the bit0 of MTK_NOR_CFG2_REG is pre-fetch buffer208208- * 0: pre-fetch buffer use for read209209- * 1: pre-fetch buffer use for page program210210- */211211- writel(MTK_NOR_WR_BUF_ENABLE, mtk_nor->base + MTK_NOR_CFG2_REG);212212- return readb_poll_timeout(mtk_nor->base + MTK_NOR_CFG2_REG, reg,213213- 0x01 == (reg & 0x01), 100, 10000);214214-}215215-216216-static int mtk_nor_write_buffer_disable(struct mtk_nor *mtk_nor)217217-{218218- u8 reg;219219-220220- writel(MTK_NOR_WR_BUF_DISABLE, mtk_nor->base + MTK_NOR_CFG2_REG);221221- return readb_poll_timeout(mtk_nor->base + MTK_NOR_CFG2_REG, reg,222222- MTK_NOR_WR_BUF_DISABLE == (reg & 0x1), 100,223223- 10000);224224-}225225-226226-static void mtk_nor_set_addr_width(struct mtk_nor *mtk_nor)227227-{228228- u8 val;229229- struct spi_nor *nor = &mtk_nor->nor;230230-231231- val = readb(mtk_nor->base + MTK_NOR_DUAL_REG);232232-233233- switch (nor->addr_width) {234234- case 3:235235- val &= ~MTK_NOR_4B_ADDR_EN;236236- break;237237- case 4:238238- val |= MTK_NOR_4B_ADDR_EN;239239- break;240240- default:241241- dev_warn(mtk_nor->dev, "Unexpected address width %u.\n",242242- nor->addr_width);243243- break;244244- }245245-246246- writeb(val, mtk_nor->base + MTK_NOR_DUAL_REG);247247-}248248-249249-static void mtk_nor_set_addr(struct mtk_nor *mtk_nor, u32 addr)250250-{251251- int i;252252-253253- mtk_nor_set_addr_width(mtk_nor);254254-255255- for (i = 0; i < 3; i++) {256256- writeb(addr & 0xff, mtk_nor->base + MTK_NOR_RADR0_REG + i * 4);257257- addr >>= 8;258258- }259259- /* Last register is non-contiguous */260260- writeb(addr & 0xff, mtk_nor->base + MTK_NOR_RADR3_REG);261261-}262262-263263-static ssize_t mtk_nor_read(struct spi_nor *nor, loff_t from, size_t length,264264- u_char *buffer)265265-{266266- int i, ret;267267- int addr = (int)from;268268- u8 *buf = (u8 *)buffer;269269- struct mtk_nor *mtk_nor = nor->priv;270270-271271- /* set mode for fast read mode ,dual mode or quad mode */272272- mtk_nor_set_read_mode(mtk_nor);273273- mtk_nor_set_addr(mtk_nor, addr);274274-275275- for (i = 0; i < length; i++) {276276- ret = mtk_nor_execute_cmd(mtk_nor, MTK_NOR_PIO_READ_CMD);277277- if (ret < 0)278278- return ret;279279- buf[i] = readb(mtk_nor->base + MTK_NOR_RDATA_REG);280280- }281281- return length;282282-}283283-284284-static int mtk_nor_write_single_byte(struct mtk_nor *mtk_nor,285285- int addr, int length, u8 *data)286286-{287287- int i, ret;288288-289289- mtk_nor_set_addr(mtk_nor, addr);290290-291291- for (i = 0; i < length; i++) {292292- writeb(*data++, mtk_nor->base + MTK_NOR_WDATA_REG);293293- ret = mtk_nor_execute_cmd(mtk_nor, MTK_NOR_PIO_WR_CMD);294294- if (ret < 0)295295- return ret;296296- }297297- return 0;298298-}299299-300300-static int mtk_nor_write_buffer(struct mtk_nor *mtk_nor, int addr,301301- const u8 *buf)302302-{303303- int i, bufidx, data;304304-305305- mtk_nor_set_addr(mtk_nor, addr);306306-307307- bufidx = 0;308308- for (i = 0; i < SFLASH_WRBUF_SIZE; i += 4) {309309- data = buf[bufidx + 3]<<24 | buf[bufidx + 2]<<16 |310310- buf[bufidx + 1]<<8 | buf[bufidx];311311- bufidx += 4;312312- writel(data, mtk_nor->base + MTK_NOR_PP_DATA_REG);313313- }314314- return mtk_nor_execute_cmd(mtk_nor, MTK_NOR_WR_CMD);315315-}316316-317317-static ssize_t mtk_nor_write(struct spi_nor *nor, loff_t to, size_t len,318318- const u_char *buf)319319-{320320- int ret;321321- struct mtk_nor *mtk_nor = nor->priv;322322- size_t i;323323-324324- ret = mtk_nor_write_buffer_enable(mtk_nor);325325- if (ret < 0) {326326- dev_warn(mtk_nor->dev, "write buffer enable failed!\n");327327- return ret;328328- }329329-330330- for (i = 0; i + SFLASH_WRBUF_SIZE <= len; i += SFLASH_WRBUF_SIZE) {331331- ret = mtk_nor_write_buffer(mtk_nor, to, buf);332332- if (ret < 0) {333333- dev_err(mtk_nor->dev, "write buffer failed!\n");334334- return ret;335335- }336336- to += SFLASH_WRBUF_SIZE;337337- buf += SFLASH_WRBUF_SIZE;338338- }339339- ret = mtk_nor_write_buffer_disable(mtk_nor);340340- if (ret < 0) {341341- dev_warn(mtk_nor->dev, "write buffer disable failed!\n");342342- return ret;343343- }344344-345345- if (i < len) {346346- ret = mtk_nor_write_single_byte(mtk_nor, to,347347- (int)(len - i), (u8 *)buf);348348- if (ret < 0) {349349- dev_err(mtk_nor->dev, "write single byte failed!\n");350350- return ret;351351- }352352- }353353-354354- return len;355355-}356356-357357-static int mtk_nor_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, size_t len)358358-{359359- int ret;360360- struct mtk_nor *mtk_nor = nor->priv;361361-362362- switch (opcode) {363363- case SPINOR_OP_RDSR:364364- ret = mtk_nor_execute_cmd(mtk_nor, MTK_NOR_RDSR_CMD);365365- if (ret < 0)366366- return ret;367367- if (len == 1)368368- *buf = readb(mtk_nor->base + MTK_NOR_RDSR_REG);369369- else370370- dev_err(mtk_nor->dev, "len should be 1 for read status!\n");371371- break;372372- default:373373- ret = mtk_nor_do_tx_rx(mtk_nor, opcode, NULL, 0, buf, len);374374- break;375375- }376376- return ret;377377-}378378-379379-static int mtk_nor_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf,380380- size_t len)381381-{382382- int ret;383383- struct mtk_nor *mtk_nor = nor->priv;384384-385385- switch (opcode) {386386- case SPINOR_OP_WRSR:387387- /* We only handle 1 byte */388388- ret = mtk_nor_wr_sr(mtk_nor, *buf);389389- break;390390- default:391391- ret = mtk_nor_do_tx_rx(mtk_nor, opcode, buf, len, NULL, 0);392392- if (ret)393393- dev_warn(mtk_nor->dev, "write reg failure!\n");394394- break;395395- }396396- return ret;397397-}398398-399399-static void mtk_nor_disable_clk(struct mtk_nor *mtk_nor)400400-{401401- clk_disable_unprepare(mtk_nor->spi_clk);402402- clk_disable_unprepare(mtk_nor->nor_clk);403403-}404404-405405-static int mtk_nor_enable_clk(struct mtk_nor *mtk_nor)406406-{407407- int ret;408408-409409- ret = clk_prepare_enable(mtk_nor->spi_clk);410410- if (ret)411411- return ret;412412-413413- ret = clk_prepare_enable(mtk_nor->nor_clk);414414- if (ret) {415415- clk_disable_unprepare(mtk_nor->spi_clk);416416- return ret;417417- }418418-419419- return 0;420420-}421421-422422-static const struct spi_nor_controller_ops mtk_controller_ops = {423423- .read_reg = mtk_nor_read_reg,424424- .write_reg = mtk_nor_write_reg,425425- .read = mtk_nor_read,426426- .write = mtk_nor_write,427427-};428428-429429-static int mtk_nor_init(struct mtk_nor *mtk_nor,430430- struct device_node *flash_node)431431-{432432- const struct spi_nor_hwcaps hwcaps = {433433- .mask = SNOR_HWCAPS_READ |434434- SNOR_HWCAPS_READ_FAST |435435- SNOR_HWCAPS_READ_1_1_2 |436436- SNOR_HWCAPS_PP,437437- };438438- int ret;439439- struct spi_nor *nor;440440-441441- /* initialize controller to accept commands */442442- writel(MTK_NOR_ENABLE_SF_CMD, mtk_nor->base + MTK_NOR_WRPROT_REG);443443-444444- nor = &mtk_nor->nor;445445- nor->dev = mtk_nor->dev;446446- nor->priv = mtk_nor;447447- spi_nor_set_flash_node(nor, flash_node);448448- nor->controller_ops = &mtk_controller_ops;449449-450450- nor->mtd.name = "mtk_nor";451451- /* initialized with NULL */452452- ret = spi_nor_scan(nor, NULL, &hwcaps);453453- if (ret)454454- return ret;455455-456456- return mtd_device_register(&nor->mtd, NULL, 0);457457-}458458-459459-static int mtk_nor_drv_probe(struct platform_device *pdev)460460-{461461- struct device_node *flash_np;462462- struct resource *res;463463- int ret;464464- struct mtk_nor *mtk_nor;465465-466466- if (!pdev->dev.of_node) {467467- dev_err(&pdev->dev, "No DT found\n");468468- return -EINVAL;469469- }470470-471471- mtk_nor = devm_kzalloc(&pdev->dev, sizeof(*mtk_nor), GFP_KERNEL);472472- if (!mtk_nor)473473- return -ENOMEM;474474- platform_set_drvdata(pdev, mtk_nor);475475-476476- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);477477- mtk_nor->base = devm_ioremap_resource(&pdev->dev, res);478478- if (IS_ERR(mtk_nor->base))479479- return PTR_ERR(mtk_nor->base);480480-481481- mtk_nor->spi_clk = devm_clk_get(&pdev->dev, "spi");482482- if (IS_ERR(mtk_nor->spi_clk))483483- return PTR_ERR(mtk_nor->spi_clk);484484-485485- mtk_nor->nor_clk = devm_clk_get(&pdev->dev, "sf");486486- if (IS_ERR(mtk_nor->nor_clk))487487- return PTR_ERR(mtk_nor->nor_clk);488488-489489- mtk_nor->dev = &pdev->dev;490490-491491- ret = mtk_nor_enable_clk(mtk_nor);492492- if (ret)493493- return ret;494494-495495- /* only support one attached flash */496496- flash_np = of_get_next_available_child(pdev->dev.of_node, NULL);497497- if (!flash_np) {498498- dev_err(&pdev->dev, "no SPI flash device to configure\n");499499- ret = -ENODEV;500500- goto nor_free;501501- }502502- ret = mtk_nor_init(mtk_nor, flash_np);503503-504504-nor_free:505505- if (ret)506506- mtk_nor_disable_clk(mtk_nor);507507-508508- return ret;509509-}510510-511511-static int mtk_nor_drv_remove(struct platform_device *pdev)512512-{513513- struct mtk_nor *mtk_nor = platform_get_drvdata(pdev);514514-515515- mtk_nor_disable_clk(mtk_nor);516516-517517- return 0;518518-}519519-520520-#ifdef CONFIG_PM_SLEEP521521-static int mtk_nor_suspend(struct device *dev)522522-{523523- struct mtk_nor *mtk_nor = dev_get_drvdata(dev);524524-525525- mtk_nor_disable_clk(mtk_nor);526526-527527- return 0;528528-}529529-530530-static int mtk_nor_resume(struct device *dev)531531-{532532- struct mtk_nor *mtk_nor = dev_get_drvdata(dev);533533-534534- return mtk_nor_enable_clk(mtk_nor);535535-}536536-537537-static const struct dev_pm_ops mtk_nor_dev_pm_ops = {538538- .suspend = mtk_nor_suspend,539539- .resume = mtk_nor_resume,540540-};541541-542542-#define MTK_NOR_DEV_PM_OPS (&mtk_nor_dev_pm_ops)543543-#else544544-#define MTK_NOR_DEV_PM_OPS NULL545545-#endif546546-547547-static const struct of_device_id mtk_nor_of_ids[] = {548548- { .compatible = "mediatek,mt8173-nor"},549549- { /* sentinel */ }550550-};551551-MODULE_DEVICE_TABLE(of, mtk_nor_of_ids);552552-553553-static struct platform_driver mtk_nor_driver = {554554- .probe = mtk_nor_drv_probe,555555- .remove = mtk_nor_drv_remove,556556- .driver = {557557- .name = "mtk-nor",558558- .pm = MTK_NOR_DEV_PM_OPS,559559- .of_match_table = mtk_nor_of_ids,560560- },561561-};562562-563563-module_platform_driver(mtk_nor_driver);564564-MODULE_LICENSE("GPL v2");565565-MODULE_DESCRIPTION("MediaTek SPI NOR Flash Driver");
+11
drivers/regulator/Kconfig
···107107108108config REGULATOR_ANATOP109109 tristate "Freescale i.MX on-chip ANATOP LDO regulators"110110+ depends on ARCH_MXC || COMPILE_TEST110111 depends on MFD_SYSCON111112 help112113 Say y here to support Freescale i.MX on-chip ANATOP LDOs···613612 basic operations (get/set voltage, get/set operating mode)614613 through the regulator interface. In addition it enables615614 suspend-to-ram/standby transition.615615+616616+config REGULATOR_MP5416617617+ tristate "Monolithic MP5416 PMIC"618618+ depends on I2C && OF619619+ select REGMAP_I2C620620+ help621621+ Say y here to support the MP5416 PMIC. This will enable supports622622+ the software controllable 4 buck and 4 LDO regulators.623623+ Say M here if you want to include support for the regulator as a624624+ module.616625617626config REGULATOR_MP8859618627 tristate "MPS MP8859 regulator driver"
···7373 int irq_ldo_lim;7474 unsigned n_regulators;7575 /* Array size to be defined during init. Keep at end. */7676- struct da9062_regulator regulator[0];7676+ struct da9062_regulator regulator[];7777};78787979/* Regulator operations */
+37-29
drivers/regulator/da9063-regulator.c
···6666};67676868struct da9063_regulators_pdata {6969- unsigned n_regulators;6969+ unsigned int n_regulators;7070 struct da9063_regulator_data *regulator_data;7171};7272···131131/* Defines asignment of regulators info table to chip model */132132struct da9063_dev_model {133133 const struct da9063_regulator_info *regulator_info;134134- unsigned n_regulators;134134+ unsigned int n_regulators;135135 enum da9063_type type;136136};137137···150150151151/* Encapsulates all information for the regulators driver */152152struct da9063_regulators {153153- unsigned n_regulators;153153+ unsigned int n_regulators;154154 /* Array size to be defined during init. Keep at end. */155155- struct da9063_regulator regulator[0];155155+ struct da9063_regulator regulator[];156156};157157158158/* BUCK modes for DA9063 */···165165166166/* Regulator operations */167167168168-/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.169169- Entry indexes corresponds to register values. */168168+/*169169+ * Current limits array (in uA) for BCORE1, BCORE2, BPRO.170170+ * Entry indexes corresponds to register values.171171+ */170172static const unsigned int da9063_buck_a_limits[] = {171173 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,172174 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000173175};174176175175-/* Current limits array (in uA) for BMEM, BIO, BPERI.176176- Entry indexes corresponds to register values. */177177+/*178178+ * Current limits array (in uA) for BMEM, BIO, BPERI.179179+ * Entry indexes corresponds to register values.180180+ */177181static const unsigned int da9063_buck_b_limits[] = {178182 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,179183 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000180184};181185182182-/* Current limits array (in uA) for merged BCORE1 and BCORE2.183183- Entry indexes corresponds to register values. */186186+/*187187+ * Current limits array (in uA) for merged BCORE1 and BCORE2.188188+ * Entry indexes corresponds to register values.189189+ */184190static const unsigned int da9063_bcores_merged_limits[] = {185191 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,186192 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000187193};188194189189-/* Current limits array (in uA) for merged BMEM and BIO.190190- Entry indexes corresponds to register values. */195195+/*196196+ * Current limits array (in uA) for merged BMEM and BIO.197197+ * Entry indexes corresponds to register values.198198+ */191199static const unsigned int da9063_bmem_bio_merged_limits[] = {192200 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,193201 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000194202};195203196196-static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)204204+static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)197205{198206 struct da9063_regulator *regl = rdev_get_drvdata(rdev);199199- unsigned val;207207+ unsigned int val;200208201209 switch (mode) {202210 case REGULATOR_MODE_FAST:···229221 * There are 3 modes to map to: FAST, NORMAL, and STANDBY.230222 */231223232232-static unsigned da9063_buck_get_mode(struct regulator_dev *rdev)224224+static unsigned int da9063_buck_get_mode(struct regulator_dev *rdev)233225{234226 struct da9063_regulator *regl = rdev_get_drvdata(rdev);235227 struct regmap_field *field;···279271 * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.280272 */281273282282-static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)274274+static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)283275{284276 struct da9063_regulator *regl = rdev_get_drvdata(rdev);285285- unsigned val;277277+ unsigned int val;286278287279 switch (mode) {288280 case REGULATOR_MODE_NORMAL:···298290 return regmap_field_write(regl->sleep, val);299291}300292301301-static unsigned da9063_ldo_get_mode(struct regulator_dev *rdev)293293+static unsigned int da9063_ldo_get_mode(struct regulator_dev *rdev)302294{303295 struct da9063_regulator *regl = rdev_get_drvdata(rdev);304296 struct regmap_field *field;···391383 return regmap_field_write(regl->suspend, 0);392384}393385394394-static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)386386+static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev,387387+ unsigned int mode)395388{396389 struct da9063_regulator *regl = rdev_get_drvdata(rdev);397390 int val;···414405 return regmap_field_write(regl->mode, val);415406}416407417417-static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)408408+static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev,409409+ unsigned int mode)418410{419411 struct da9063_regulator *regl = rdev_get_drvdata(rdev);420420- unsigned val;412412+ unsigned int val;421413422414 switch (mode) {423415 case REGULATOR_MODE_NORMAL:···603593 struct da9063_regulators *regulators = data;604594 struct da9063 *hw = regulators->regulator[0].hw;605595 struct da9063_regulator *regl;606606- int bits, i , ret;596596+ int bits, i, ret;607597608598 ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits);609599 if (ret < 0)···615605 continue;616606617607 if (BIT(regl->info->oc_event.lsb) & bits) {618618- regulator_lock(regl->rdev);608608+ regulator_lock(regl->rdev);619609 regulator_notifier_call_chain(regl->rdev,620610 REGULATOR_EVENT_OVER_CURRENT, NULL);621621- regulator_unlock(regl->rdev);611611+ regulator_unlock(regl->rdev);622612 }623613 }624614···843833844834 if (regl->info->suspend_sleep.reg) {845835 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev,846846- da9063->regmap, regl->info->suspend_sleep);836836+ da9063->regmap, regl->info->suspend_sleep);847837 if (IS_ERR(regl->suspend_sleep))848838 return PTR_ERR(regl->suspend_sleep);849839 }···877867 NULL, da9063_ldo_lim_event,878868 IRQF_TRIGGER_LOW | IRQF_ONESHOT,879869 "LDO_LIM", regulators);880880- if (ret) {870870+ if (ret)881871 dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ.\n");882882- return ret;883883- }884872885885- return 0;873873+ return ret;886874}887875888876static struct platform_driver da9063_regulator_driver = {
···354354 drvdata->pwm = devm_pwm_get(&pdev->dev, NULL);355355 if (IS_ERR(drvdata->pwm)) {356356 ret = PTR_ERR(drvdata->pwm);357357- dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);357357+ if (ret == -EPROBE_DEFER)358358+ dev_dbg(&pdev->dev,359359+ "Failed to get PWM, deferring probe\n");360360+ else361361+ dev_err(&pdev->dev, "Failed to get PWM: %d\n", ret);358362 return ret;359363 }360364
···6262 help6363 This is the driver for the Altera SPI Controller.64646565+config SPI_AR934X6666+ tristate "Qualcomm Atheros AR934X/QCA95XX SPI controller driver"6767+ depends on ATH79 || COMPILE_TEST6868+ help6969+ This enables support for the SPI controller present on the7070+ Qualcomm Atheros AR934X/QCA95XX SoCs.7171+6572config SPI_ATH796673 tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver"6774 depends on ATH79 || COMPILE_TEST···271264 has only been tested with m25p80 type chips. The hardware has no272265 support for other types of SPI peripherals.273266267267+config SPI_FSI268268+ tristate "FSI SPI driver"269269+ depends on FSI270270+ help271271+ This enables support for the driver for FSI bus attached SPI272272+ controllers.273273+274274config SPI_FSL_LPSPI275275 tristate "Freescale i.MX LPSPI controller"276276 depends on ARCH_MXC || COMPILE_TEST···299285 tristate "HiSilicon SPI-NOR Flash Controller for Hi16XX chipsets"300286 depends on (ARM64 && ACPI) || COMPILE_TEST301287 depends on HAS_IOMEM302302- select CONFIG_MTD_SPI_NOR303288 help304289 This enables support for HiSilicon v3xx SPI-NOR flash controller305290 found in hi16xx chipsets.···428415429416config SPI_MESON_SPICC430417 tristate "Amlogic Meson SPICC controller"418418+ depends on COMMON_CLK431419 depends on ARCH_MESON || COMPILE_TEST432420 help433421 This enables master mode support for the SPICC (SPI communication···456442 depends on RALINK || COMPILE_TEST457443 help458444 This selects a driver for the MediaTek MT7621 SPI Controller.445445+446446+config SPI_MTK_NOR447447+ tristate "MediaTek SPI NOR controller"448448+ depends on ARCH_MEDIATEK || COMPILE_TEST449449+ help450450+ This enables support for SPI NOR controller found on MediaTek451451+ ARM SoCs. This is a controller specifically for SPI-NOR flash.452452+ It can perform generic SPI transfers up to 6 bytes via generic453453+ SPI interface as well as several SPI-NOR specific instructions454454+ via SPI MEM interface.459455460456config SPI_NPCM_FIU461457 tristate "Nuvoton NPCM FLASH Interface Unit"···913889#914890# Add new SPI master controllers in alphabetical order above this line915891#892892+893893+comment "SPI Multiplexer support"894894+895895+config SPI_MUX896896+ tristate "SPI multiplexer support"897897+ select MULTIPLEXER898898+ help899899+ This adds support for SPI multiplexers. Each SPI mux will be900900+ accessible as a SPI controller, the devices behind the mux will appear901901+ to be chip selects on this controller. It is still necessary to902902+ select one or more specific mux-controller drivers.916903917904#918905# There are lots of SPI device types, with sensors and memory
···418418 struct spi_controller *ctlr = mem->spi->controller;419419 size_t len;420420421421- len = sizeof(op->cmd.opcode) + op->addr.nbytes + op->dummy.nbytes;422422-423421 if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size)424422 return ctlr->mem_ops->adjust_op_size(mem, op);425423426424 if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) {425425+ len = sizeof(op->cmd.opcode) + op->addr.nbytes +426426+ op->dummy.nbytes;427427+427428 if (len > spi_max_transfer_size(mem->spi))428429 return -EINVAL;429430···488487 * This function is creating a direct mapping descriptor which can then be used489488 * to access the memory using spi_mem_dirmap_read() or spi_mem_dirmap_write().490489 * If the SPI controller driver does not support direct mapping, this function491491- * fallback to an implementation using spi_mem_exec_op(), so that the caller490490+ * falls back to an implementation using spi_mem_exec_op(), so that the caller492491 * doesn't have to bother implementing a fallback on his own.493492 *494493 * Return: a valid pointer in case of success, and ERR_PTR() otherwise.
···11+// SPDX-License-Identifier: GPL-2.022+//33+// General Purpose SPI multiplexer44+55+#include <linux/err.h>66+#include <linux/kernel.h>77+#include <linux/module.h>88+#include <linux/mux/consumer.h>99+#include <linux/slab.h>1010+#include <linux/spi/spi.h>1111+1212+#define SPI_MUX_NO_CS ((unsigned int)-1)1313+1414+/**1515+ * DOC: Driver description1616+ *1717+ * This driver supports a MUX on an SPI bus. This can be useful when you need1818+ * more chip selects than the hardware peripherals support, or than are1919+ * available in a particular board setup.2020+ *2121+ * The driver will create an additional SPI controller. Devices added under the2222+ * mux will be handled as 'chip selects' on this controller.2323+ */2424+2525+/**2626+ * struct spi_mux_priv - the basic spi_mux structure2727+ * @spi: pointer to the device struct attached to the parent2828+ * spi controller2929+ * @current_cs: The current chip select set in the mux3030+ * @child_msg_complete: The mux replaces the complete callback in the child's3131+ * message to its own callback; this field is used by the3232+ * driver to store the child's callback during a transfer3333+ * @child_msg_context: Used to store the child's context to the callback3434+ * @child_msg_dev: Used to store the spi_device pointer to the child3535+ * @mux: mux_control structure used to provide chip selects for3636+ * downstream spi devices3737+ */3838+struct spi_mux_priv {3939+ struct spi_device *spi;4040+ unsigned int current_cs;4141+4242+ void (*child_msg_complete)(void *context);4343+ void *child_msg_context;4444+ struct spi_device *child_msg_dev;4545+ struct mux_control *mux;4646+};4747+4848+/* should not get called when the parent controller is doing a transfer */4949+static int spi_mux_select(struct spi_device *spi)5050+{5151+ struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller);5252+ int ret;5353+5454+ if (priv->current_cs == spi->chip_select)5555+ return 0;5656+5757+ dev_dbg(&priv->spi->dev, "setting up the mux for cs %d\n",5858+ spi->chip_select);5959+6060+ /* copy the child device's settings except for the cs */6161+ priv->spi->max_speed_hz = spi->max_speed_hz;6262+ priv->spi->mode = spi->mode;6363+ priv->spi->bits_per_word = spi->bits_per_word;6464+6565+ ret = mux_control_select(priv->mux, spi->chip_select);6666+ if (ret)6767+ return ret;6868+6969+ priv->current_cs = spi->chip_select;7070+7171+ return 0;7272+}7373+7474+static int spi_mux_setup(struct spi_device *spi)7575+{7676+ struct spi_mux_priv *priv = spi_controller_get_devdata(spi->controller);7777+7878+ /*7979+ * can be called multiple times, won't do a valid setup now but we will8080+ * change the settings when we do a transfer (necessary because we8181+ * can't predict from which device it will be anyway)8282+ */8383+ return spi_setup(priv->spi);8484+}8585+8686+static void spi_mux_complete_cb(void *context)8787+{8888+ struct spi_mux_priv *priv = (struct spi_mux_priv *)context;8989+ struct spi_controller *ctlr = spi_get_drvdata(priv->spi);9090+ struct spi_message *m = ctlr->cur_msg;9191+9292+ m->complete = priv->child_msg_complete;9393+ m->context = priv->child_msg_context;9494+ m->spi = priv->child_msg_dev;9595+ spi_finalize_current_message(ctlr);9696+ mux_control_deselect(priv->mux);9797+}9898+9999+static int spi_mux_transfer_one_message(struct spi_controller *ctlr,100100+ struct spi_message *m)101101+{102102+ struct spi_mux_priv *priv = spi_controller_get_devdata(ctlr);103103+ struct spi_device *spi = m->spi;104104+ int ret;105105+106106+ ret = spi_mux_select(spi);107107+ if (ret)108108+ return ret;109109+110110+ /*111111+ * Replace the complete callback, context and spi_device with our own112112+ * pointers. Save originals113113+ */114114+ priv->child_msg_complete = m->complete;115115+ priv->child_msg_context = m->context;116116+ priv->child_msg_dev = m->spi;117117+118118+ m->complete = spi_mux_complete_cb;119119+ m->context = priv;120120+ m->spi = priv->spi;121121+122122+ /* do the transfer */123123+ return spi_async(priv->spi, m);124124+}125125+126126+static int spi_mux_probe(struct spi_device *spi)127127+{128128+ struct spi_controller *ctlr;129129+ struct spi_mux_priv *priv;130130+ int ret;131131+132132+ ctlr = spi_alloc_master(&spi->dev, sizeof(*priv));133133+ if (!ctlr)134134+ return -ENOMEM;135135+136136+ spi_set_drvdata(spi, ctlr);137137+ priv = spi_controller_get_devdata(ctlr);138138+ priv->spi = spi;139139+140140+ priv->mux = devm_mux_control_get(&spi->dev, NULL);141141+ if (IS_ERR(priv->mux)) {142142+ ret = PTR_ERR(priv->mux);143143+ if (ret != -EPROBE_DEFER)144144+ dev_err(&spi->dev, "failed to get control-mux\n");145145+ goto err_put_ctlr;146146+ }147147+148148+ priv->current_cs = SPI_MUX_NO_CS;149149+150150+ /* supported modes are the same as our parent's */151151+ ctlr->mode_bits = spi->controller->mode_bits;152152+ ctlr->flags = spi->controller->flags;153153+ ctlr->transfer_one_message = spi_mux_transfer_one_message;154154+ ctlr->setup = spi_mux_setup;155155+ ctlr->num_chipselect = mux_control_states(priv->mux);156156+ ctlr->bus_num = -1;157157+ ctlr->dev.of_node = spi->dev.of_node;158158+159159+ ret = devm_spi_register_controller(&spi->dev, ctlr);160160+ if (ret)161161+ goto err_put_ctlr;162162+163163+ return 0;164164+165165+err_put_ctlr:166166+ spi_controller_put(ctlr);167167+168168+ return ret;169169+}170170+171171+static const struct of_device_id spi_mux_of_match[] = {172172+ { .compatible = "spi-mux" },173173+ { }174174+};175175+176176+static struct spi_driver spi_mux_driver = {177177+ .probe = spi_mux_probe,178178+ .driver = {179179+ .name = "spi-mux",180180+ .of_match_table = spi_mux_of_match,181181+ },182182+};183183+184184+module_spi_driver(spi_mux_driver);185185+186186+MODULE_DESCRIPTION("SPI multiplexer");187187+MODULE_LICENSE("GPL");
···565565 qspi->io_base = devm_ioremap_resource(dev, res);566566 if (IS_ERR(qspi->io_base)) {567567 ret = PTR_ERR(qspi->io_base);568568- goto err;568568+ goto err_master_put;569569 }570570571571 qspi->phys_base = res->start;···574574 qspi->mm_base = devm_ioremap_resource(dev, res);575575 if (IS_ERR(qspi->mm_base)) {576576 ret = PTR_ERR(qspi->mm_base);577577- goto err;577577+ goto err_master_put;578578 }579579580580 qspi->mm_size = resource_size(res);581581 if (qspi->mm_size > STM32_QSPI_MAX_MMAP_SZ) {582582 ret = -EINVAL;583583- goto err;583583+ goto err_master_put;584584 }585585586586 irq = platform_get_irq(pdev, 0);587587- if (irq < 0)588588- return irq;587587+ if (irq < 0) {588588+ ret = irq;589589+ goto err_master_put;590590+ }589591590592 ret = devm_request_irq(dev, irq, stm32_qspi_irq, 0,591593 dev_name(dev), qspi);592594 if (ret) {593595 dev_err(dev, "failed to request irq\n");594594- goto err;596596+ goto err_master_put;595597 }596598597599 init_completion(&qspi->data_completion);···601599 qspi->clk = devm_clk_get(dev, NULL);602600 if (IS_ERR(qspi->clk)) {603601 ret = PTR_ERR(qspi->clk);604604- goto err;602602+ goto err_master_put;605603 }606604607605 qspi->clk_rate = clk_get_rate(qspi->clk);608606 if (!qspi->clk_rate) {609607 ret = -EINVAL;610610- goto err;608608+ goto err_master_put;611609 }612610613611 ret = clk_prepare_enable(qspi->clk);614612 if (ret) {615613 dev_err(dev, "can not enable the clock\n");616616- goto err;614614+ goto err_master_put;617615 }618616619617 rstc = devm_reset_control_get_exclusive(dev, NULL);620620- if (!IS_ERR(rstc)) {618618+ if (IS_ERR(rstc)) {619619+ ret = PTR_ERR(rstc);620620+ if (ret == -EPROBE_DEFER)621621+ goto err_qspi_release;622622+ } else {621623 reset_control_assert(rstc);622624 udelay(2);623625 reset_control_deassert(rstc);···631625 platform_set_drvdata(pdev, qspi);632626 ret = stm32_qspi_dma_setup(qspi);633627 if (ret)634634- goto err;628628+ goto err_qspi_release;635629636630 mutex_init(&qspi->lock);637631···647641 if (!ret)648642 return 0;649643650650-err:644644+err_qspi_release:651645 stm32_qspi_release(qspi);646646+err_master_put:652647 spi_master_put(qspi->ctrl);653648654649 return ret;
+45-17
drivers/spi/spi-stm32.c
···175175#define SPI_DMA_MIN_BYTES 16176176177177/**178178- * stm32_spi_reg - stm32 SPI register & bitfield desc178178+ * struct stm32_spi_reg - stm32 SPI register & bitfield desc179179 * @reg: register offset180180 * @mask: bitfield mask181181 * @shift: left shift···187187};188188189189/**190190- * stm32_spi_regspec - stm32 registers definition, compatible dependent data191191- * en: enable register and SPI enable bit192192- * dma_rx_en: SPI DMA RX enable register end SPI DMA RX enable bit193193- * dma_tx_en: SPI DMA TX enable register end SPI DMA TX enable bit194194- * cpol: clock polarity register and polarity bit195195- * cpha: clock phase register and phase bit196196- * lsb_first: LSB transmitted first register and bit197197- * br: baud rate register and bitfields198198- * rx: SPI RX data register199199- * tx: SPI TX data register190190+ * struct stm32_spi_regspec - stm32 registers definition, compatible dependent data191191+ * @en: enable register and SPI enable bit192192+ * @dma_rx_en: SPI DMA RX enable register end SPI DMA RX enable bit193193+ * @dma_tx_en: SPI DMA TX enable register end SPI DMA TX enable bit194194+ * @cpol: clock polarity register and polarity bit195195+ * @cpha: clock phase register and phase bit196196+ * @lsb_first: LSB transmitted first register and bit197197+ * @br: baud rate register and bitfields198198+ * @rx: SPI RX data register199199+ * @tx: SPI TX data register200200 */201201struct stm32_spi_regspec {202202 const struct stm32_spi_reg en;···213213struct stm32_spi;214214215215/**216216- * stm32_spi_cfg - stm32 compatible configuration data216216+ * struct stm32_spi_cfg - stm32 compatible configuration data217217 * @regs: registers descriptions218218 * @get_fifo_size: routine to get fifo size219219 * @get_bpw_mask: routine to get bits per word mask···223223 * @set_mode: routine to configure registers to desired mode224224 * @set_data_idleness: optional routine to configure registers to desired idle225225 * time between frames (if driver has this functionality)226226- * set_number_of_data: optional routine to configure registers to desired226226+ * @set_number_of_data: optional routine to configure registers to desired227227 * number of data (if driver has this functionality)228228 * @can_dma: routine to determine if the transfer is eligible for DMA use229229 * @transfer_one_dma_start: routine to start transfer a single spi_transfer230230 * using DMA231231- * @dma_rx cb: routine to call after DMA RX channel operation is complete232232- * @dma_tx cb: routine to call after DMA TX channel operation is complete231231+ * @dma_rx_cb: routine to call after DMA RX channel operation is complete232232+ * @dma_tx_cb: routine to call after DMA TX channel operation is complete233233 * @transfer_one_irq: routine to configure interrupts for driver234234 * @irq_handler_event: Interrupt handler for SPI controller events235235 * @irq_handler_thread: thread of interrupt handler for SPI controller···587587/**588588 * stm32h7_spi_read_rxfifo - Read bytes in Receive Data Register589589 * @spi: pointer to the spi controller data structure590590+ * @flush: boolean indicating that FIFO should be flushed590591 *591592 * Write in rx_buf depends on remaining bytes to avoid to write beyond592593 * rx_buf end.···757756758757/**759758 * stm32_spi_can_dma - Determine if the transfer is eligible for DMA use759759+ * @master: controller master interface760760+ * @spi_dev: pointer to the spi device761761+ * @transfer: pointer to spi transfer760762 *761763 * If driver has fifo and the current transfer size is greater than fifo size,762764 * use DMA. Otherwise use DMA for transfer longer than defined DMA min bytes.···978974979975/**980976 * stm32_spi_prepare_msg - set up the controller to transfer a single message977977+ * @master: controller master interface978978+ * @msg: pointer to spi message981979 */982980static int stm32_spi_prepare_msg(struct spi_master *master,983981 struct spi_message *msg)···1032102610331027/**10341028 * stm32f4_spi_dma_tx_cb - dma callback10291029+ * @data: pointer to the spi controller data structure10351030 *10361031 * DMA callback is called when the transfer is complete for DMA TX channel.10371032 */···1048104110491042/**10501043 * stm32f4_spi_dma_rx_cb - dma callback10441044+ * @data: pointer to the spi controller data structure10511045 *10521046 * DMA callback is called when the transfer is complete for DMA RX channel.10531047 */···1062105410631055/**10641056 * stm32h7_spi_dma_cb - dma callback10571057+ * @data: pointer to the spi controller data structure10651058 *10661059 * DMA callback is called when the transfer is complete or when an error10671060 * occurs. If the transfer is complete, EOT flag is raised.···10881079/**10891080 * stm32_spi_dma_config - configure dma slave channel depending on current10901081 * transfer bits_per_word.10821082+ * @spi: pointer to the spi controller data structure10831083+ * @dma_conf: pointer to the dma_slave_config structure10841084+ * @dir: direction of the dma transfer10911085 */10921086static void stm32_spi_dma_config(struct stm32_spi *spi,10931087 struct dma_slave_config *dma_conf,···11381126/**11391127 * stm32f4_spi_transfer_one_irq - transfer a single spi_transfer using11401128 * interrupts11291129+ * @spi: pointer to the spi controller data structure11411130 *11421131 * It must returns 0 if the transfer is finished or 1 if the transfer is still11431132 * in progress.···11791166/**11801167 * stm32h7_spi_transfer_one_irq - transfer a single spi_transfer using11811168 * interrupts11691169+ * @spi: pointer to the spi controller data structure11821170 *11831171 * It must returns 0 if the transfer is finished or 1 if the transfer is still11841172 * in progress.···12211207/**12221208 * stm32f4_spi_transfer_one_dma_start - Set SPI driver registers to start12231209 * transfer using DMA12101210+ * @spi: pointer to the spi controller data structure12241211 */12251212static void stm32f4_spi_transfer_one_dma_start(struct stm32_spi *spi)12261213{···12421227/**12431228 * stm32h7_spi_transfer_one_dma_start - Set SPI driver registers to start12441229 * transfer using DMA12301230+ * @spi: pointer to the spi controller data structure12451231 */12461232static void stm32h7_spi_transfer_one_dma_start(struct stm32_spi *spi)12471233{···1259124312601244/**12611245 * stm32_spi_transfer_one_dma - transfer a single spi_transfer using DMA12461246+ * @spi: pointer to the spi controller data structure12471247+ * @xfer: pointer to the spi_transfer structure12621248 *12631249 * It must returns 0 if the transfer is finished or 1 if the transfer is still12641250 * in progress.···14231405/**14241406 * stm32_spi_communication_type - return transfer communication type14251407 * @spi_dev: pointer to the spi device14261426- * transfer: pointer to spi transfer14081408+ * @transfer: pointer to spi transfer14271409 */14281410static unsigned int stm32_spi_communication_type(struct spi_device *spi_dev,14291411 struct spi_transfer *transfer)···15401522/**15411523 * stm32h7_spi_number_of_data - configure number of data at current transfer15421524 * @spi: pointer to the spi controller data structure15431543- * @len: transfer length15251525+ * @nb_words: transfer length (in words)15441526 */15451527static int stm32h7_spi_number_of_data(struct stm32_spi *spi, u32 nb_words)15461528{···15641546 * stm32_spi_transfer_one_setup - common setup to transfer a single15651547 * spi_transfer either using DMA or15661548 * interrupts.15491549+ * @spi: pointer to the spi controller data structure15501550+ * @spi_dev: pointer to the spi device15511551+ * @transfer: pointer to spi transfer15671552 */15681553static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,15691554 struct spi_device *spi_dev,···1646162516471626/**16481627 * stm32_spi_transfer_one - transfer a single spi_transfer16281628+ * @master: controller master interface16291629+ * @spi_dev: pointer to the spi device16301630+ * @transfer: pointer to spi transfer16491631 *16501632 * It must return 0 if the transfer is finished or 1 if the transfer is still16511633 * in progress.···1682165816831659/**16841660 * stm32_spi_unprepare_msg - relax the hardware16611661+ * @master: controller master interface16621662+ * @msg: pointer to the spi message16851663 */16861664static int stm32_spi_unprepare_msg(struct spi_master *master,16871665 struct spi_message *msg)···1697167116981672/**16991673 * stm32f4_spi_config - Configure SPI controller as SPI master16741674+ * @spi: pointer to the spi controller data structure17001675 */17011676static int stm32f4_spi_config(struct stm32_spi *spi)17021677{···1728170117291702/**17301703 * stm32h7_spi_config - Configure SPI controller as SPI master17041704+ * @spi: pointer to the spi controller data structure17311705 */17321706static int stm32h7_spi_config(struct stm32_spi *spi)17331707{
+13-21
drivers/spi/spi.c
···510510 spi->dev.bus = &spi_bus_type;511511 spi->dev.release = spidev_release;512512 spi->cs_gpio = -ENOENT;513513+ spi->mode = ctlr->buswidth_override_bits;513514514515 spin_lock_init(&spi->statistics.lock);515516···15151514 if (!xfer->ptp_sts)15161515 return;1517151615181518- if (xfer->timestamped_pre)15171517+ if (xfer->timestamped)15191518 return;1520151915211521- if (progress < xfer->ptp_sts_word_pre)15201520+ if (progress > xfer->ptp_sts_word_pre)15221521 return;1523152215241523 /* Capture the resolution of the timestamp */15251524 xfer->ptp_sts_word_pre = progress;15261526-15271527- xfer->timestamped_pre = true;1528152515291526 if (irqs_off) {15301527 local_irq_save(ctlr->irq_flags);···15521553 if (!xfer->ptp_sts)15531554 return;1554155515551555- if (xfer->timestamped_post)15561556+ if (xfer->timestamped)15561557 return;1557155815581559 if (progress < xfer->ptp_sts_word_post)···15681569 /* Capture the resolution of the timestamp */15691570 xfer->ptp_sts_word_post = progress;1570157115711571- xfer->timestamped_post = true;15721572+ xfer->timestamped = true;15721573}15731574EXPORT_SYMBOL_GPL(spi_take_timestamp_post);15741575···16731674 }16741675 }1675167616761676- if (unlikely(ctlr->ptp_sts_supported)) {16771677- list_for_each_entry(xfer, &mesg->transfers, transfer_list) {16781678- WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped_pre);16791679- WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped_post);16801680- }16811681- }16771677+ if (unlikely(ctlr->ptp_sts_supported))16781678+ list_for_each_entry(xfer, &mesg->transfers, transfer_list)16791679+ WARN_ON_ONCE(xfer->ptp_sts && !xfer->timestamped);1682168016831681 spi_unmap_msg(ctlr, mesg);16841682···19511955 spi->mode |= SPI_CS_HIGH;1952195619531957 /* Device speed */19541954- rc = of_property_read_u32(nc, "spi-max-frequency", &value);19551955- if (rc) {19561956- dev_err(&ctlr->dev,19571957- "%pOF has no valid 'spi-max-frequency' property (%d)\n", nc, rc);19581958- return rc;19591959- }19601960- spi->max_speed_hz = value;19581958+ if (!of_property_read_u32(nc, "spi-max-frequency", &value))19591959+ spi->max_speed_hz = value;1961196019621961 return 0;19631962}···21722181 return AE_NO_MEMORY;21732182 }2174218321842184+21752185 ACPI_COMPANION_SET(&spi->dev, adev);21762186 spi->max_speed_hz = lookup.max_speed_hz;21772177- spi->mode = lookup.mode;21872187+ spi->mode |= lookup.mode;21782188 spi->irq = lookup.irq;21792189 spi->bits_per_word = lookup.bits_per_word;21802190 spi->chip_select = lookup.chip_select;···40264034 struct device *dev;4027403540284036 dev = bus_find_device_by_acpi_dev(&spi_bus_type, adev);40294029- return dev ? to_spi_device(dev) : NULL;40374037+ return to_spi_device(dev);40304038}4031403940324040static int acpi_spi_notify(struct notifier_block *nb, unsigned long value,
···135135 * @modalias: Name of the driver to use with this device, or an alias136136 * for that name. This appears in the sysfs "modalias" attribute137137 * for driver coldplugging, and in uevents used for hotplugging138138+ * @driver_override: If the name of a driver is written to this attribute, then139139+ * the device will bind to the named driver and only the named driver.138140 * @cs_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when139141 * not using a GPIO line) use cs_gpiod in new drivers by opting in on140142 * the spi_master.···445443 * @spi_transfer->ptp_sts_word_post were transmitted.446444 * If the driver does not set this, the SPI core takes the snapshot as447445 * close to the driver hand-over as possible.446446+ * @irq_flags: Interrupt enable state during PTP system timestamping448447 *449448 * Each SPI controller can communicate with one or more @spi_device450449 * children. These make a small bus, sharing MOSI, MISO and SCK signals···483480484481 /* spi_device.mode flags understood by this controller driver */485482 u32 mode_bits;483483+484484+ /* spi_device.mode flags override flags for this controller */485485+ u32 buswidth_override_bits;486486487487 /* bitmask of supported bits_per_word for transfers */488488 u32 bits_per_word_mask;···936930937931 struct ptp_system_timestamp *ptp_sts;938932939939- bool timestamped_pre;940940- bool timestamped_post;933933+ bool timestamped;941934942935 struct list_head transfer_list;943936};