Pull spi updates from Mark Brown: "A fairly quiet release for SPI, the biggest thing is the conversion to use GPIO descriptors which is now 90% done but still needs some stragglers converting. Summary: - Support for inter-word delays - Conversion of the core and most drivers to use GPIO descriptors for GPIO controlled chip selects - New drivers for NXP FlexSPI and QuadSPI, SiFive and Spreadtrum" * tag 'spi-v5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (104 commits) spi: sh-msiof: Restrict bits per word to 8/16/24/32 on R-Car Gen2/3 spi: sifive: Remove redundant dev_err call in sifive_spi_probe() spi: sifive: Remove spi_master_put in sifive_spi_remove() spi: spi-gpio: fix SPI_CS_HIGH capability spi: pxa2xx: Setup maximum supported DMA transfer length spi: sifive: Add driver for the SiFive SPI controller spi: sifive: Add DT documentation for SiFive SPI controller spi: sprd: Add a prefix for SPI DMA channel macros spi: sprd: spi: sprd: Add DMA mode support dt-bindings: spi: Add the DMA properties for the SPI dma mode spi: sprd: Add the SPI irq function for the SPI DMA mode dt-bindings: spi: imx: Add an entry for the i.MX8QM compatible spi: use gpio[d]_set_value_cansleep for setting chipselect GPIO spi: gpio: Advertise support for SPI_CS_HIGH spi: sh-msiof: Replace spi_master by spi_controller spi: sh-hspi: Replace spi_master by spi_controller spi: rspi: Replace spi_master by spi_controller spi: atmel-quadspi: add support for sam9x60 qspi controller dt-bindings: spi: atmel-quadspi: QuadSPI driver for Microchip SAM9X60 spi: atmel-quadspi: add support for named peripheral clock ...
Unified · Split
| @@ -1,14 +1,19 @@ | ||
| 1 | 1 | * Atmel Quad Serial Peripheral Interface (QSPI) |
| 2 | 2 | |
| 3 | 3 | Required properties: |
| 4 | −- compatible: Should be "atmel,sama5d2-qspi". | |
| 4 | +- compatible: Should be one of the following: | |
| 5 | + - "atmel,sama5d2-qspi" | |
| 6 | + - "microchip,sam9x60-qspi" | |
| 5 | 7 | - reg: Should contain the locations and lengths of the base registers |
| 6 | 8 | and the mapped memory. |
| 7 | 9 | - reg-names: Should contain the resource reg names: |
| 8 | 10 | - qspi_base: configuration register address space |
| 9 | 11 | - qspi_mmap: memory mapped address space |
| 10 | 12 | - interrupts: Should contain the interrupt for the device. |
| 11 | −- clocks: The phandle of the clock needed by the QSPI controller. | |
| 13 | +- clocks: Should reference the peripheral clock and the QSPI system | |
| 14 | + clock if available. | |
| 15 | +- clock-names: Should contain "pclk" for the peripheral clock and "qspick" | |
| 16 | + for the system clock when available. | |
| 12 | 17 | - #address-cells: Should be <1>. |
| 13 | 18 | - #size-cells: Should be <0>. |
| 14 | 19 | |
| @@ -19,7 +24,8 @@ spi@f0020000 { · 4 unmodified lines | ||
| 19 | 24 | reg = <0xf0020000 0x100>, <0xd0000000 0x8000000>; |
| 20 | 25 | reg-names = "qspi_base", "qspi_mmap"; |
| 21 | 26 | interrupts = <52 IRQ_TYPE_LEVEL_HIGH 7>; |
| 22 | − clocks = <&spi0_clk>; | |
| 27 | + clocks = <&pmc PMC_TYPE_PERIPHERAL 52>; | |
| 28 | + clock-names = "pclk"; | |
| 23 | 29 | #address-cells = <1>; |
| 24 | 30 | #size-cells = <0>; |
| 25 | 31 | pinctrl-names = "default"; |
| @@ -10,6 +10,7 @@ Required properties: · 9 unmodified lines | ||
| 10 | 10 | - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35 |
| 11 | 11 | - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51 |
| 12 | 12 | - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc |
| 13 | + - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8M | |
| 13 | 14 | - reg : Offset and length of the register set for the device |
| 14 | 15 | - interrupts : Should contain CSPI/eCSPI interrupt |
| 15 | 16 | - clocks : Clock specifiers for both ipg and per clocks. |
| @@ -14,15 +14,13 @@ Required properties: · 13 unmodified lines | ||
| 14 | 14 | - clocks : The clocks needed by the QuadSPI controller |
| 15 | 15 | - clock-names : Should contain the name of the clocks: "qspi_en" and "qspi". |
| 16 | 16 | |
| 17 | −Optional properties: | |
| 18 | − - fsl,qspi-has-second-chip: The controller has two buses, bus A and bus B. | |
| 19 | − Each bus can be connected with two NOR flashes. | |
| 20 | − Most of the time, each bus only has one NOR flash | |
| 21 | − connected, this is the default case. | |
| 22 | − But if there are two NOR flashes connected to the | |
| 23 | − bus, you should enable this property. | |
| 24 | − (Please check the board's schematic.) | |
| 25 | − - big-endian : That means the IP register is big endian | |
| 17 | +Required SPI slave node properties: | |
| 18 | + - reg: There are two buses (A and B) with two chip selects each. | |
| 19 | + This encodes to which bus and CS the flash is connected: | |
| 20 | + <0>: Bus A, CS 0 | |
| 21 | + <1>: Bus A, CS 1 | |
| 22 | + <2>: Bus B, CS 0 | |
| 23 | + <3>: Bus B, CS 1 | |
| 26 | 24 | |
| 27 | 25 | Example: |
| 28 | 26 | |
| @@ -40,7 +38,7 @@ qspi0: quadspi@40044000 { · 11 unmodified lines | ||
| 40 | 38 | }; |
| 41 | 39 | }; |
| 42 | 40 | |
| 43 | −Example showing the usage of two SPI NOR devices: | |
| 41 | +Example showing the usage of two SPI NOR devices on bus A: | |
| 44 | 42 | |
| 45 | 43 | &qspi2 { |
| 46 | 44 | pinctrl-names = "default"; |
| @@ -0,0 +1,39 @@ | ||
| 1 | +* NXP Flex Serial Peripheral Interface (FSPI) | |
| 2 | + | |
| 3 | +Required properties: | |
| 4 | + - compatible : Should be "nxp,lx2160a-fspi" | |
| 5 | + - reg : First contains the register location and length, | |
| 6 | + Second contains the memory mapping address and length | |
| 7 | + - reg-names : Should contain the resource reg names: | |
| 8 | + - fspi_base: configuration register address space | |
| 9 | + - fspi_mmap: memory mapped address space | |
| 10 | + - interrupts : Should contain the interrupt for the device | |
| 11 | + | |
| 12 | +Required SPI slave node properties: | |
| 13 | + - reg : There are two buses (A and B) with two chip selects each. | |
| 14 | + This encodes to which bus and CS the flash is connected: | |
| 15 | + - <0>: Bus A, CS 0 | |
| 16 | + - <1>: Bus A, CS 1 | |
| 17 | + - <2>: Bus B, CS 0 | |
| 18 | + - <3>: Bus B, CS 1 | |
| 19 | + | |
| 20 | +Example showing the usage of two SPI NOR slave devices on bus A: | |
| 21 | + | |
| 22 | +fspi0: spi@20c0000 { | |
| 23 | + compatible = "nxp,lx2160a-fspi"; | |
| 24 | + reg = <0x0 0x20c0000 0x0 0x10000>, <0x0 0x20000000 0x0 0x10000000>; | |
| 25 | + reg-names = "fspi_base", "fspi_mmap"; | |
| 26 | + interrupts = <0 25 0x4>; /* Level high type */ | |
| 27 | + clocks = <&clockgen 4 3>, <&clockgen 4 3>; | |
| 28 | + clock-names = "fspi_en", "fspi"; | |
| 29 | + | |
| 30 | + mt35xu512aba0: flash@0 { | |
| 31 | + reg = <0>; | |
| 32 | + .... | |
| 33 | + }; | |
| 34 | + | |
| 35 | + mt35xu512aba1: flash@1 { | |
| 36 | + reg = <1>; | |
| 37 | + .... | |
| 38 | + }; | |
| 39 | +}; | |
| @@ -0,0 +1,37 @@ | ||
| 1 | +SiFive SPI controller Device Tree Bindings | |
| 2 | +------------------------------------------ | |
| 3 | + | |
| 4 | +Required properties: | |
| 5 | +- compatible : Should be "sifive,<chip>-spi" and "sifive,spi<version>". | |
| 6 | + Supported compatible strings are: | |
| 7 | + "sifive,fu540-c000-spi" for the SiFive SPI v0 as integrated | |
| 8 | + onto the SiFive FU540 chip, and "sifive,spi0" for the SiFive | |
| 9 | + SPI v0 IP block with no chip integration tweaks. | |
| 10 | + Please refer to sifive-blocks-ip-versioning.txt for details | |
| 11 | +- reg : Physical base address and size of SPI registers map | |
| 12 | + A second (optional) range can indicate memory mapped flash | |
| 13 | +- interrupts : Must contain one entry | |
| 14 | +- interrupt-parent : Must be core interrupt controller | |
| 15 | +- clocks : Must reference the frequency given to the controller | |
| 16 | +- #address-cells : Must be '1', indicating which CS to use | |
| 17 | +- #size-cells : Must be '0' | |
| 18 | + | |
| 19 | +Optional properties: | |
| 20 | +- sifive,fifo-depth : Depth of hardware queues; defaults to 8 | |
| 21 | +- sifive,max-bits-per-word : Maximum bits per word; defaults to 8 | |
| 22 | + | |
| 23 | +SPI RTL that corresponds to the IP block version numbers can be found here: | |
| 24 | +https://github.com/sifive/sifive-blocks/tree/master/src/main/scala/devices/spi | |
| 25 | + | |
| 26 | +Example: | |
| 27 | + spi: spi@10040000 { | |
| 28 | + compatible = "sifive,fu540-c000-spi", "sifive,spi0"; | |
| 29 | + reg = <0x0 0x10040000 0x0 0x1000 0x0 0x20000000 0x0 0x10000000>; | |
| 30 | + interrupt-parent = <&plic>; | |
| 31 | + interrupts = <51>; | |
| 32 | + clocks = <&tlclk>; | |
| 33 | + #address-cells = <1>; | |
| 34 | + #size-cells = <0>; | |
| 35 | + sifive,fifo-depth = <8>; | |
| 36 | + sifive,max-bits-per-word = <8>; | |
| 37 | + }; | |
| @@ -14,6 +14,11 @@ Required properties: · 13 unmodified lines | ||
| 14 | 14 | address on the SPI bus. Should be set to 1. |
| 15 | 15 | - #size-cells: Should be set to 0. |
| 16 | 16 | |
| 17 | +Optional properties: | |
| 18 | +dma-names: Should contain names of the SPI used DMA channel. | |
| 19 | +dmas: Should contain DMA channels and DMA slave ids which the SPI used | |
| 20 | + sorted in the same order as the dma-names property. | |
| 21 | + | |
| 17 | 22 | Example: |
| 18 | 23 | spi0: spi@70a00000{ |
| 19 | 24 | compatible = "sprd,sc9860-spi"; |
| @@ -21,6 +26,8 @@ spi0: spi@70a00000{ · 1 unmodified line | ||
| 21 | 26 | interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>; |
| 22 | 27 | clock-names = "spi", "source","enable"; |
| 23 | 28 | clocks = <&clk_spi0>, <&ext_26m>, <&clk_ap_apb_gates 5>; |
| 29 | + dma-names = "rx_chn", "tx_chn"; | |
| 30 | + dmas = <&apdma 11 11>, <&apdma 12 12>; | |
| 24 | 31 | #address-cells = <1>; |
| 25 | 32 | #size-cells = <0>; |
| 26 | 33 | }; |
| @@ -7,7 +7,9 @@ from 4 to 32-bit data size. Although it can be configured as master or slave, · 6 unmodified lines | ||
| 7 | 7 | only master is supported by the driver. |
| 8 | 8 | |
| 9 | 9 | Required properties: |
| 10 | −- compatible: Must be "st,stm32h7-spi". | |
| 10 | +- compatible: Should be one of: | |
| 11 | + "st,stm32h7-spi" | |
| 12 | + "st,stm32f4-spi" | |
| 11 | 13 | - reg: Offset and length of the device's register set. |
| 12 | 14 | - interrupts: Must contain the interrupt id. |
| 13 | 15 | - clocks: Must contain an entry for spiclk (which feeds the internal clock |
| @@ -30,8 +32,9 @@ Child nodes represent devices on the SPI bus · 16 unmodified lines | ||
| 30 | 32 | See ../spi/spi-bus.txt |
| 31 | 33 | |
| 32 | 34 | Optional properties: |
| 33 | −- st,spi-midi-ns: (Master Inter-Data Idleness) minimum time delay in | |
| 34 | − nanoseconds inserted between two consecutive data frames. | |
| 35 | +- st,spi-midi-ns: Only for STM32H7, (Master Inter-Data Idleness) minimum time | |
| 36 | + delay in nanoseconds inserted between two consecutive data | |
| 37 | + frames. | |
| 35 | 38 | |
| 36 | 39 | |
| 37 | 40 | Example: |
| @@ -21,15 +21,15 @@ Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a · 20 unmodified lines | ||
| 21 | 21 | "platform device". The master configuration is passed to the driver via a table |
| 22 | 22 | found in include/linux/spi/pxa2xx_spi.h: |
| 23 | 23 | |
| 24 | −struct pxa2xx_spi_master { | |
| 24 | +struct pxa2xx_spi_controller { | |
| 25 | 25 | u16 num_chipselect; |
| 26 | 26 | u8 enable_dma; |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | −The "pxa2xx_spi_master.num_chipselect" field is used to determine the number of | |
| 29 | +The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of | |
| 30 | 30 | slave device (chips) attached to this SPI master. |
| 31 | 31 | |
| 32 | −The "pxa2xx_spi_master.enable_dma" field informs the driver that SSP DMA should | |
| 32 | +The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should | |
| 33 | 33 | be used. This caused the driver to acquire two DMA channels: rx_channel and |
| 34 | 34 | tx_channel. The rx_channel has a higher DMA service priority the tx_channel. |
| 35 | 35 | See the "PXA2xx Developer Manual" section "DMA Controller". |
| @@ -51,7 +51,7 @@ static struct resource pxa_spi_nssp_resources[] = { · 15 unmodified lines | ||
| 51 | 51 | }, |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | −static struct pxa2xx_spi_master pxa_nssp_master_info = { | |
| 54 | +static struct pxa2xx_spi_controller pxa_nssp_master_info = { | |
| 55 | 55 | .num_chipselect = 1, /* Matches the number of chips attached to NSSP */ |
| 56 | 56 | .enable_dma = 1, /* Enables NSSP DMA */ |
| 57 | 57 | }; |
| @@ -206,7 +206,7 @@ DMA and PIO I/O Support · 148 unmodified lines | ||
| 206 | 206 | ----------------------- |
| 207 | 207 | The pxa2xx_spi driver supports both DMA and interrupt driven PIO message |
| 208 | 208 | transfers. The driver defaults to PIO mode and DMA transfers must be enabled |
| 209 | −by setting the "enable_dma" flag in the "pxa2xx_spi_master" structure. The DMA | |
| 209 | +by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA | |
| 210 | 210 | mode supports both coherent and stream based DMA mappings. |
| 211 | 211 | |
| 212 | 212 | The following logic is used to determine the type of I/O to be used on |
| @@ -6105,9 +6105,9 @@ F: Documentation/devicetree/bindings/ptp/ptp-qoriq.txt · 6104 unmodified lines | ||
| 6105 | 6105 | |
| 6106 | 6106 | FREESCALE QUAD SPI DRIVER |
| 6107 | 6107 | M: Han Xu <han.xu@nxp.com> |
| 6108 | −L: linux-mtd@lists.infradead.org | |
| 6108 | +L: linux-spi@vger.kernel.org | |
| 6109 | 6109 | S: Maintained |
| 6110 | −F: drivers/mtd/spi-nor/fsl-quadspi.c | |
| 6110 | +F: drivers/spi/spi-fsl-qspi.c | |
| 6111 | 6111 | |
| 6112 | 6112 | FREESCALE QUICC ENGINE LIBRARY |
| 6113 | 6113 | M: Qiang Zhao <qiang.zhao@nxp.com> |
| @@ -10952,6 +10952,14 @@ F: lib/objagg.c · 4838 unmodified lines | ||
| 10952 | 10952 | F: lib/test_objagg.c |
| 10953 | 10953 | F: include/linux/objagg.h |
| 10954 | 10954 | |
| 10955 | +NXP FSPI DRIVER | |
| 10956 | +R: Yogesh Gaur <yogeshgaur.83@gmail.com> | |
| 10957 | +M: Ashish Kumar <ashish.kumar@nxp.com> | |
| 10958 | +L: linux-spi@vger.kernel.org | |
| 10959 | +S: Maintained | |
| 10960 | +F: drivers/spi/spi-nxp-fspi.c | |
| 10961 | +F: Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt | |
| 10962 | + | |
| 10955 | 10963 | OBJTOOL |
| 10956 | 10964 | M: Josh Poimboeuf <jpoimboe@redhat.com> |
| 10957 | 10965 | M: Peter Zijlstra <peterz@infradead.org> |
| @@ -98,7 +98,7 @@ static unsigned long cmx255_pin_config[] = { · 97 unmodified lines | ||
| 98 | 98 | }; |
| 99 | 99 | |
| 100 | 100 | #if defined(CONFIG_SPI_PXA2XX) |
| 101 | −static struct pxa2xx_spi_master pxa_ssp_master_info = { | |
| 101 | +static struct pxa2xx_spi_controller pxa_ssp_master_info = { | |
| 102 | 102 | .num_chipselect = 1, |
| 103 | 103 | }; |
| 104 | 104 | |
| @@ -313,7 +313,7 @@ static inline void cmx270_init_mmc(void) {} · 312 unmodified lines | ||
| 313 | 313 | #endif |
| 314 | 314 | |
| 315 | 315 | #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) |
| 316 | −static struct pxa2xx_spi_master cm_x270_spi_info = { | |
| 316 | +static struct pxa2xx_spi_controller cm_x270_spi_info = { | |
| 317 | 317 | .num_chipselect = 1, |
| 318 | 318 | .enable_dma = 1, |
| 319 | 319 | }; |
| @@ -530,7 +530,7 @@ static struct pxa2xx_udc_mach_info udc_info __initdata = { · 529 unmodified lines | ||
| 530 | 530 | }; |
| 531 | 531 | |
| 532 | 532 | #if IS_ENABLED(CONFIG_SPI_PXA2XX) |
| 533 | −static struct pxa2xx_spi_master corgi_spi_info = { | |
| 533 | +static struct pxa2xx_spi_controller corgi_spi_info = { | |
| 534 | 534 | .num_chipselect = 3, |
| 535 | 535 | }; |
| 536 | 536 | |
| @@ -1065,7 +1065,7 @@ struct platform_device pxa93x_device_gpio = { · 1064 unmodified lines | ||
| 1065 | 1065 | |
| 1066 | 1066 | /* pxa2xx-spi platform-device ID equals respective SSP platform-device ID + 1. |
| 1067 | 1067 | * See comment in arch/arm/mach-pxa/ssp.c::ssp_probe() */ |
| 1068 | −void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info) | |
| 1068 | +void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info) | |
| 1069 | 1069 | { |
| 1070 | 1070 | struct platform_device *pd; |
| 1071 | 1071 | |
| @@ -689,7 +689,7 @@ static inline void em_x270_init_lcd(void) {} · 688 unmodified lines | ||
| 689 | 689 | #endif |
| 690 | 690 | |
| 691 | 691 | #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) |
| 692 | −static struct pxa2xx_spi_master em_x270_spi_info = { | |
| 692 | +static struct pxa2xx_spi_controller em_x270_spi_info = { | |
| 693 | 693 | .num_chipselect = 1, |
| 694 | 694 | }; |
| 695 | 695 | |
| @@ -703,7 +703,7 @@ static struct tdo24m_platform_data em_x270_tdo24m_pdata = { · 7 unmodified lines | ||
| 703 | 703 | .model = TDO35S, |
| 704 | 704 | }; |
| 705 | 705 | |
| 706 | −static struct pxa2xx_spi_master em_x270_spi_2_info = { | |
| 706 | +static struct pxa2xx_spi_controller em_x270_spi_2_info = { | |
| 707 | 707 | .num_chipselect = 1, |
| 708 | 708 | .enable_dma = 1, |
| 709 | 709 | }; |
| @@ -630,7 +630,7 @@ static struct spi_board_info tsc2046_board_info[] __initdata = { · 629 unmodified lines | ||
| 630 | 630 | }, |
| 631 | 631 | }; |
| 632 | 632 | |
| 633 | −static struct pxa2xx_spi_master pxa_ssp2_master_info = { | |
| 633 | +static struct pxa2xx_spi_controller pxa_ssp2_master_info = { | |
| 634 | 634 | .num_chipselect = 1, |
| 635 | 635 | .enable_dma = 1, |
| 636 | 636 | }; |
| @@ -115,12 +115,12 @@ static struct spi_board_info mcp251x_board_info[] = { · 114 unmodified lines | ||
| 115 | 115 | } |
| 116 | 116 | }; |
| 117 | 117 | |
| 118 | −static struct pxa2xx_spi_master pxa_ssp3_spi_master_info = { | |
| 118 | +static struct pxa2xx_spi_controller pxa_ssp3_spi_master_info = { | |
| 119 | 119 | .num_chipselect = 2, |
| 120 | 120 | .enable_dma = 1 |
| 121 | 121 | }; |
| 122 | 122 | |
| 123 | −static struct pxa2xx_spi_master pxa_ssp4_spi_master_info = { | |
| 123 | +static struct pxa2xx_spi_controller pxa_ssp4_spi_master_info = { | |
| 124 | 124 | .num_chipselect = 2, |
| 125 | 125 | .enable_dma = 1 |
| 126 | 126 | }; |
| @@ -191,7 +191,7 @@ static inline void littleton_init_lcd(void) {}; · 190 unmodified lines | ||
| 191 | 191 | #endif /* CONFIG_FB_PXA || CONFIG_FB_PXA_MODULE */ |
| 192 | 192 | |
| 193 | 193 | #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) |
| 194 | −static struct pxa2xx_spi_master littleton_spi_info = { | |
| 194 | +static struct pxa2xx_spi_controller littleton_spi_info = { | |
| 195 | 195 | .num_chipselect = 1, |
| 196 | 196 | }; |
| 197 | 197 | |
| @@ -197,7 +197,7 @@ static struct platform_device sa1111_device = { · 196 unmodified lines | ||
| 197 | 197 | * (to J5) and poking board registers (as done below). Else it's only useful |
| 198 | 198 | * for the temperature sensors. |
| 199 | 199 | */ |
| 200 | −static struct pxa2xx_spi_master pxa_ssp_master_info = { | |
| 200 | +static struct pxa2xx_spi_controller pxa_ssp_master_info = { | |
| 201 | 201 | .num_chipselect = 1, |
| 202 | 202 | }; |
| 203 | 203 | |
| @@ -940,7 +940,7 @@ struct pxa2xx_spi_chip tsc2046_chip_info = { · 939 unmodified lines | ||
| 940 | 940 | .gpio_cs = GPIO14_MAGICIAN_TSC2046_CS, |
| 941 | 941 | }; |
| 942 | 942 | |
| 943 | −static struct pxa2xx_spi_master magician_spi_info = { | |
| 943 | +static struct pxa2xx_spi_controller magician_spi_info = { | |
| 944 | 944 | .num_chipselect = 1, |
| 945 | 945 | .enable_dma = 1, |
| 946 | 946 | }; |
| @@ -132,7 +132,7 @@ static struct platform_device smc91x_device = { · 131 unmodified lines | ||
| 132 | 132 | /* |
| 133 | 133 | * SPI host and devices |
| 134 | 134 | */ |
| 135 | −static struct pxa2xx_spi_master pxa_ssp_master_info = { | |
| 135 | +static struct pxa2xx_spi_controller pxa_ssp_master_info = { | |
| 136 | 136 | .num_chipselect = 1, |
| 137 | 137 | }; |
| 138 | 138 | |
| @@ -196,7 +196,7 @@ struct platform_device poodle_locomo_device = { · 195 unmodified lines | ||
| 196 | 196 | EXPORT_SYMBOL(poodle_locomo_device); |
| 197 | 197 | |
| 198 | 198 | #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE) |
| 199 | −static struct pxa2xx_spi_master poodle_spi_info = { | |
| 199 | +static struct pxa2xx_spi_controller poodle_spi_info = { | |
| 200 | 200 | .num_chipselect = 1, |
| 201 | 201 | }; |
| 202 | 202 | |
| @@ -572,7 +572,7 @@ static struct spi_board_info spitz_spi_devices[] = { · 571 unmodified lines | ||
| 572 | 572 | }, |
| 573 | 573 | }; |
| 574 | 574 | |
| 575 | −static struct pxa2xx_spi_master spitz_spi_info = { | |
| 575 | +static struct pxa2xx_spi_controller spitz_spi_info = { | |
| 576 | 576 | .num_chipselect = 3, |
| 577 | 577 | }; |
| 578 | 578 | |
| @@ -337,15 +337,15 @@ static struct platform_device stargate2_flash_device = { · 336 unmodified lines | ||
| 337 | 337 | .num_resources = 1, |
| 338 | 338 | }; |
| 339 | 339 | |
| 340 | −static struct pxa2xx_spi_master pxa_ssp_master_0_info = { | |
| 340 | +static struct pxa2xx_spi_controller pxa_ssp_master_0_info = { | |
| 341 | 341 | .num_chipselect = 1, |
| 342 | 342 | }; |
| 343 | 343 | |
| 344 | −static struct pxa2xx_spi_master pxa_ssp_master_1_info = { | |
| 344 | +static struct pxa2xx_spi_controller pxa_ssp_master_1_info = { | |
| 345 | 345 | .num_chipselect = 1, |
| 346 | 346 | }; |
| 347 | 347 | |
| 348 | −static struct pxa2xx_spi_master pxa_ssp_master_2_info = { | |
| 348 | +static struct pxa2xx_spi_controller pxa_ssp_master_2_info = { | |
| 349 | 349 | .num_chipselect = 1, |
| 350 | 350 | }; |
| 351 | 351 | |
| @@ -813,7 +813,7 @@ static struct platform_device tosa_bt_device = { · 812 unmodified lines | ||
| 813 | 813 | .dev.platform_data = &tosa_bt_data, |
| 814 | 814 | }; |
| 815 | 815 | |
| 816 | −static struct pxa2xx_spi_master pxa_ssp_master_info = { | |
| 816 | +static struct pxa2xx_spi_controller pxa_ssp_master_info = { | |
| 817 | 817 | .num_chipselect = 1, |
| 818 | 818 | }; |
| 819 | 819 | |
| @@ -607,12 +607,12 @@ static struct spi_board_info spi_board_info[] __initdata = { · 606 unmodified lines | ||
| 607 | 607 | }, |
| 608 | 608 | }; |
| 609 | 609 | |
| 610 | −static struct pxa2xx_spi_master pxa_ssp1_master_info = { | |
| 610 | +static struct pxa2xx_spi_controller pxa_ssp1_master_info = { | |
| 611 | 611 | .num_chipselect = 1, |
| 612 | 612 | .enable_dma = 1, |
| 613 | 613 | }; |
| 614 | 614 | |
| 615 | −static struct pxa2xx_spi_master pxa_ssp2_master_info = { | |
| 615 | +static struct pxa2xx_spi_controller pxa_ssp2_master_info = { | |
| 616 | 616 | .num_chipselect = 1, |
| 617 | 617 | }; |
| 618 | 618 | |
| @@ -391,7 +391,7 @@ static struct platform_device zeus_sram_device = { · 390 unmodified lines | ||
| 391 | 391 | }; |
| 392 | 392 | |
| 393 | 393 | /* SPI interface on SSP3 */ |
| 394 | −static struct pxa2xx_spi_master pxa2xx_spi_ssp3_master_info = { | |
| 394 | +static struct pxa2xx_spi_controller pxa2xx_spi_ssp3_master_info = { | |
| 395 | 395 | .num_chipselect = 1, |
| 396 | 396 | .enable_dma = 1, |
| 397 | 397 | }; |
| @@ -13,7 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #define _ATH79_DEV_SPI_H |
| 14 | 14 | |
| 15 | 15 | #include <linux/spi/spi.h> |
| 16 | −#include <asm/mach-ath79/ath79_spi_platform.h> | |
| 16 | +#include <linux/platform_data/spi-ath79.h> | |
| 17 | 17 | |
| 18 | 18 | void ath79_register_spi(struct ath79_spi_platform_data *pdata, |
| 19 | 19 | struct spi_board_info const *info, |
| @@ -125,7 +125,7 @@ static void of_gpio_flags_quirks(struct device_node *np, · 124 unmodified lines | ||
| 125 | 125 | |
| 126 | 126 | for_each_child_of_node(np, child) { |
| 127 | 127 | ret = of_property_read_u32(child, "reg", &cs); |
| 128 | − if (!ret) | |
| 128 | + if (ret) | |
| 129 | 129 | continue; |
| 130 | 130 | if (cs == index) { |
| 131 | 131 | /* |
| @@ -42,15 +42,6 @@ config SPI_CADENCE_QUADSPI · 41 unmodified lines | ||
| 42 | 42 | device with a Cadence QSPI controller and want to access the |
| 43 | 43 | Flash as an MTD device. |
| 44 | 44 | |
| 45 | −config SPI_FSL_QUADSPI | |
| 46 | − tristate "Freescale Quad SPI controller" | |
| 47 | − depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST | |
| 48 | − depends on HAS_IOMEM | |
| 49 | − help | |
| 50 | − This enables support for the Quad SPI controller in master mode. | |
| 51 | − This controller does not support generic SPI. It only supports | |
| 52 | − SPI NOR. | |
| 53 | − | |
| 54 | 45 | config SPI_HISI_SFC |
| 55 | 46 | tristate "Hisilicon SPI-NOR Flash Controller(SFC)" |
| 56 | 47 | depends on ARCH_HISI || COMPILE_TEST |
| @@ -2,7 +2,6 @@ · 1 unmodified line | ||
| 2 | 2 | obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o |
| 3 | 3 | obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o |
| 4 | 4 | obj-$(CONFIG_SPI_CADENCE_QUADSPI) += cadence-quadspi.o |
| 5 | −obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o | |
| 6 | 5 | obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o |
| 7 | 6 | obj-$(CONFIG_SPI_MTK_QUADSPI) += mtk-quadspi.o |
| 8 | 7 | obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o |
| @@ -1,1224 +0,0 @@ | ||
| 1 | −/* | |
| 2 | − * Freescale QuadSPI driver. | |
| 3 | − * | |
| 4 | − * Copyright (C) 2013 Freescale Semiconductor, Inc. | |
| 5 | − * | |
| 6 | − * This program is free software; you can redistribute it and/or modify | |
| 7 | − * it under the terms of the GNU General Public License as published by | |
| 8 | − * the Free Software Foundation; either version 2 of the License, or | |
| 9 | − * (at your option) any later version. | |
| 10 | − */ | |
| 11 | −#include <linux/kernel.h> | |
| 12 | −#include <linux/module.h> | |
| 13 | −#include <linux/interrupt.h> | |
| 14 | −#include <linux/errno.h> | |
| 15 | −#include <linux/platform_device.h> | |
| 16 | −#include <linux/sched.h> | |
| 17 | −#include <linux/delay.h> | |
| 18 | −#include <linux/io.h> | |
| 19 | −#include <linux/clk.h> | |
| 20 | −#include <linux/err.h> | |
| 21 | −#include <linux/of.h> | |
| 22 | −#include <linux/of_device.h> | |
| 23 | −#include <linux/timer.h> | |
| 24 | −#include <linux/jiffies.h> | |
| 25 | −#include <linux/completion.h> | |
| 26 | −#include <linux/mtd/mtd.h> | |
| 27 | −#include <linux/mtd/partitions.h> | |
| 28 | −#include <linux/mtd/spi-nor.h> | |
| 29 | −#include <linux/mutex.h> | |
| 30 | −#include <linux/pm_qos.h> | |
| 31 | −#include <linux/sizes.h> | |
| 32 | − | |
| 33 | −/* Controller needs driver to swap endian */ | |
| 34 | −#define QUADSPI_QUIRK_SWAP_ENDIAN (1 << 0) | |
| 35 | −/* Controller needs 4x internal clock */ | |
| 36 | −#define QUADSPI_QUIRK_4X_INT_CLK (1 << 1) | |
| 37 | −/* | |
| 38 | − * TKT253890, Controller needs driver to fill txfifo till 16 byte to | |
| 39 | − * trigger data transfer even though extern data will not transferred. | |
| 40 | − */ | |
| 41 | −#define QUADSPI_QUIRK_TKT253890 (1 << 2) | |
| 42 | −/* Controller cannot wake up from wait mode, TKT245618 */ | |
| 43 | −#define QUADSPI_QUIRK_TKT245618 (1 << 3) | |
| 44 | − | |
| 45 | −/* The registers */ | |
| 46 | −#define QUADSPI_MCR 0x00 | |
| 47 | −#define QUADSPI_MCR_RESERVED_SHIFT 16 | |
| 48 | −#define QUADSPI_MCR_RESERVED_MASK (0xF << QUADSPI_MCR_RESERVED_SHIFT) | |
| 49 | −#define QUADSPI_MCR_MDIS_SHIFT 14 | |
| 50 | −#define QUADSPI_MCR_MDIS_MASK (1 << QUADSPI_MCR_MDIS_SHIFT) | |
| 51 | −#define QUADSPI_MCR_CLR_TXF_SHIFT 11 | |
| 52 | −#define QUADSPI_MCR_CLR_TXF_MASK (1 << QUADSPI_MCR_CLR_TXF_SHIFT) | |
| 53 | −#define QUADSPI_MCR_CLR_RXF_SHIFT 10 | |
| 54 | −#define QUADSPI_MCR_CLR_RXF_MASK (1 << QUADSPI_MCR_CLR_RXF_SHIFT) | |
| 55 | −#define QUADSPI_MCR_DDR_EN_SHIFT 7 | |
| 56 | −#define QUADSPI_MCR_DDR_EN_MASK (1 << QUADSPI_MCR_DDR_EN_SHIFT) | |
| 57 | −#define QUADSPI_MCR_END_CFG_SHIFT 2 | |
| 58 | −#define QUADSPI_MCR_END_CFG_MASK (3 << QUADSPI_MCR_END_CFG_SHIFT) | |
| 59 | −#define QUADSPI_MCR_SWRSTHD_SHIFT 1 | |
| 60 | −#define QUADSPI_MCR_SWRSTHD_MASK (1 << QUADSPI_MCR_SWRSTHD_SHIFT) | |
| 61 | −#define QUADSPI_MCR_SWRSTSD_SHIFT 0 | |
| 62 | −#define QUADSPI_MCR_SWRSTSD_MASK (1 << QUADSPI_MCR_SWRSTSD_SHIFT) | |
| 63 | − | |
| 64 | −#define QUADSPI_IPCR 0x08 | |
| 65 | −#define QUADSPI_IPCR_SEQID_SHIFT 24 | |
| 66 | −#define QUADSPI_IPCR_SEQID_MASK (0xF << QUADSPI_IPCR_SEQID_SHIFT) | |
| 67 | − | |
| 68 | −#define QUADSPI_BUF0CR 0x10 | |
| 69 | −#define QUADSPI_BUF1CR 0x14 | |
| 70 | −#define QUADSPI_BUF2CR 0x18 | |
| 71 | −#define QUADSPI_BUFXCR_INVALID_MSTRID 0xe | |
| 72 | − | |
| 73 | −#define QUADSPI_BUF3CR 0x1c | |
| 74 | −#define QUADSPI_BUF3CR_ALLMST_SHIFT 31 | |
| 75 | −#define QUADSPI_BUF3CR_ALLMST_MASK (1 << QUADSPI_BUF3CR_ALLMST_SHIFT) | |
| 76 | −#define QUADSPI_BUF3CR_ADATSZ_SHIFT 8 | |
| 77 | −#define QUADSPI_BUF3CR_ADATSZ_MASK (0xFF << QUADSPI_BUF3CR_ADATSZ_SHIFT) | |
| 78 | − | |
| 79 | −#define QUADSPI_BFGENCR 0x20 | |
| 80 | −#define QUADSPI_BFGENCR_PAR_EN_SHIFT 16 | |
| 81 | −#define QUADSPI_BFGENCR_PAR_EN_MASK (1 << (QUADSPI_BFGENCR_PAR_EN_SHIFT)) | |
| 82 | −#define QUADSPI_BFGENCR_SEQID_SHIFT 12 | |
| 83 | −#define QUADSPI_BFGENCR_SEQID_MASK (0xF << QUADSPI_BFGENCR_SEQID_SHIFT) | |
| 84 | − | |
| 85 | −#define QUADSPI_BUF0IND 0x30 | |
| 86 | −#define QUADSPI_BUF1IND 0x34 | |
| 87 | −#define QUADSPI_BUF2IND 0x38 | |
| 88 | −#define QUADSPI_SFAR 0x100 | |
| 89 | − | |
| 90 | −#define QUADSPI_SMPR 0x108 | |
| 91 | −#define QUADSPI_SMPR_DDRSMP_SHIFT 16 | |
| 92 | −#define QUADSPI_SMPR_DDRSMP_MASK (7 << QUADSPI_SMPR_DDRSMP_SHIFT) | |
| 93 | −#define QUADSPI_SMPR_FSDLY_SHIFT 6 | |
| 94 | −#define QUADSPI_SMPR_FSDLY_MASK (1 << QUADSPI_SMPR_FSDLY_SHIFT) | |
| 95 | −#define QUADSPI_SMPR_FSPHS_SHIFT 5 | |
| 96 | −#define QUADSPI_SMPR_FSPHS_MASK (1 << QUADSPI_SMPR_FSPHS_SHIFT) | |
| 97 | −#define QUADSPI_SMPR_HSENA_SHIFT 0 | |
| 98 | −#define QUADSPI_SMPR_HSENA_MASK (1 << QUADSPI_SMPR_HSENA_SHIFT) | |
| 99 | − | |
| 100 | −#define QUADSPI_RBSR 0x10c | |
| 101 | −#define QUADSPI_RBSR_RDBFL_SHIFT 8 | |
| 102 | −#define QUADSPI_RBSR_RDBFL_MASK (0x3F << QUADSPI_RBSR_RDBFL_SHIFT) | |
| 103 | − | |
| 104 | −#define QUADSPI_RBCT 0x110 | |
| 105 | −#define QUADSPI_RBCT_WMRK_MASK 0x1F | |
| 106 | −#define QUADSPI_RBCT_RXBRD_SHIFT 8 | |
| 107 | −#define QUADSPI_RBCT_RXBRD_USEIPS (0x1 << QUADSPI_RBCT_RXBRD_SHIFT) | |
| 108 | − | |
| 109 | −#define QUADSPI_TBSR 0x150 | |
| 110 | −#define QUADSPI_TBDR 0x154 | |
| 111 | −#define QUADSPI_SR 0x15c | |
| 112 | −#define QUADSPI_SR_IP_ACC_SHIFT 1 | |
| 113 | −#define QUADSPI_SR_IP_ACC_MASK (0x1 << QUADSPI_SR_IP_ACC_SHIFT) | |
| 114 | −#define QUADSPI_SR_AHB_ACC_SHIFT 2 | |
| 115 | −#define QUADSPI_SR_AHB_ACC_MASK (0x1 << QUADSPI_SR_AHB_ACC_SHIFT) | |
| 116 | − | |
| 117 | −#define QUADSPI_FR 0x160 | |
| 118 | −#define QUADSPI_FR_TFF_MASK 0x1 | |
| 119 | − | |
| 120 | −#define QUADSPI_SFA1AD 0x180 | |
| 121 | −#define QUADSPI_SFA2AD 0x184 | |
| 122 | −#define QUADSPI_SFB1AD 0x188 | |
| 123 | −#define QUADSPI_SFB2AD 0x18c | |
| 124 | −#define QUADSPI_RBDR 0x200 | |
| 125 | − | |
| 126 | −#define QUADSPI_LUTKEY 0x300 | |
| 127 | −#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0 | |
| 128 | − | |
| 129 | −#define QUADSPI_LCKCR 0x304 | |
| 130 | −#define QUADSPI_LCKER_LOCK 0x1 | |
| 131 | −#define QUADSPI_LCKER_UNLOCK 0x2 | |
| 132 | − | |
| 133 | −#define QUADSPI_RSER 0x164 | |
| 134 | −#define QUADSPI_RSER_TFIE (0x1 << 0) | |
| 135 | − | |
| 136 | −#define QUADSPI_LUT_BASE 0x310 | |
| 137 | − | |
| 138 | −/* | |
| 139 | − * The definition of the LUT register shows below: | |
| 140 | − * | |
| 141 | − * --------------------------------------------------- | |
| 142 | − * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 | | |
| 143 | − * --------------------------------------------------- | |
| 144 | − */ | |
| 145 | −#define OPRND0_SHIFT 0 | |
| 146 | −#define PAD0_SHIFT 8 | |
| 147 | −#define INSTR0_SHIFT 10 | |
| 148 | −#define OPRND1_SHIFT 16 | |
| 149 | − | |
| 150 | −/* Instruction set for the LUT register. */ | |
| 151 | −#define LUT_STOP 0 | |
| 152 | −#define LUT_CMD 1 | |
| 153 | −#define LUT_ADDR 2 | |
| 154 | −#define LUT_DUMMY 3 | |
| 155 | −#define LUT_MODE 4 | |
| 156 | −#define LUT_MODE2 5 | |
| 157 | −#define LUT_MODE4 6 | |
| 158 | −#define LUT_FSL_READ 7 | |
| 159 | −#define LUT_FSL_WRITE 8 | |
| 160 | −#define LUT_JMP_ON_CS 9 | |
| 161 | −#define LUT_ADDR_DDR 10 | |
| 162 | −#define LUT_MODE_DDR 11 | |
| 163 | −#define LUT_MODE2_DDR 12 | |
| 164 | −#define LUT_MODE4_DDR 13 | |
| 165 | −#define LUT_FSL_READ_DDR 14 | |
| 166 | −#define LUT_FSL_WRITE_DDR 15 | |
| 167 | −#define LUT_DATA_LEARN 16 | |
| 168 | − | |
| 169 | −/* | |
| 170 | − * The PAD definitions for LUT register. | |
| 171 | − * | |
| 172 | − * The pad stands for the lines number of IO[0:3]. | |
| 173 | − * For example, the Quad read need four IO lines, so you should | |
| 174 | − * set LUT_PAD4 which means we use four IO lines. | |
| 175 | − */ | |
| 176 | −#define LUT_PAD1 0 | |
| 177 | −#define LUT_PAD2 1 | |
| 178 | −#define LUT_PAD4 2 | |
| 179 | − | |
| 180 | −/* Oprands for the LUT register. */ | |
| 181 | −#define ADDR24BIT 0x18 | |
| 182 | −#define ADDR32BIT 0x20 | |
| 183 | − | |
| 184 | −/* Macros for constructing the LUT register. */ | |
| 185 | −#define LUT0(ins, pad, opr) \ | |
| 186 | − (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \ | |
| 187 | − ((LUT_##ins) << INSTR0_SHIFT)) | |
| 188 | − | |
| 189 | −#define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT) | |
| 190 | − | |
| 191 | −/* other macros for LUT register. */ | |
| 192 | −#define QUADSPI_LUT(x) (QUADSPI_LUT_BASE + (x) * 4) | |
| 193 | −#define QUADSPI_LUT_NUM 64 | |
| 194 | − | |
| 195 | −/* SEQID -- we can have 16 seqids at most. */ | |
| 196 | −#define SEQID_READ 0 | |
| 197 | −#define SEQID_WREN 1 | |
| 198 | −#define SEQID_WRDI 2 | |
| 199 | −#define SEQID_RDSR 3 | |
| 200 | −#define SEQID_SE 4 | |
| 201 | −#define SEQID_CHIP_ERASE 5 | |
| 202 | −#define SEQID_PP 6 | |
| 203 | −#define SEQID_RDID 7 | |
| 204 | −#define SEQID_WRSR 8 | |
| 205 | −#define SEQID_RDCR 9 | |
| 206 | −#define SEQID_EN4B 10 | |
| 207 | −#define SEQID_BRWR 11 | |
| 208 | − | |
| 209 | −#define QUADSPI_MIN_IOMAP SZ_4M | |
| 210 | − | |
| 211 | −enum fsl_qspi_devtype { | |
| 212 | − FSL_QUADSPI_VYBRID, | |
| 213 | − FSL_QUADSPI_IMX6SX, | |
| 214 | − FSL_QUADSPI_IMX7D, | |
| 215 | − FSL_QUADSPI_IMX6UL, | |
| 216 | − FSL_QUADSPI_LS1021A, | |
| 217 | − FSL_QUADSPI_LS2080A, | |
| 218 | −}; | |
| 219 | − | |
| 220 | −struct fsl_qspi_devtype_data { | |
| 221 | − enum fsl_qspi_devtype devtype; | |
| 222 | − int rxfifo; | |
| 223 | − int txfifo; | |
| 224 | − int ahb_buf_size; | |
| 225 | − int driver_data; | |
| 226 | −}; | |
| 227 | − | |
| 228 | −static const struct fsl_qspi_devtype_data vybrid_data = { | |
| 229 | − .devtype = FSL_QUADSPI_VYBRID, | |
| 230 | − .rxfifo = 128, | |
| 231 | − .txfifo = 64, | |
| 232 | − .ahb_buf_size = 1024, | |
| 233 | − .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN, | |
| 234 | −}; | |
| 235 | − | |
| 236 | −static const struct fsl_qspi_devtype_data imx6sx_data = { | |
| 237 | − .devtype = FSL_QUADSPI_IMX6SX, | |
| 238 | − .rxfifo = 128, | |
| 239 | − .txfifo = 512, | |
| 240 | − .ahb_buf_size = 1024, | |
| 241 | − .driver_data = QUADSPI_QUIRK_4X_INT_CLK | |
| 242 | − | QUADSPI_QUIRK_TKT245618, | |
| 243 | −}; | |
| 244 | − | |
| 245 | −static const struct fsl_qspi_devtype_data imx7d_data = { | |
| 246 | − .devtype = FSL_QUADSPI_IMX7D, | |
| 247 | − .rxfifo = 512, | |
| 248 | − .txfifo = 512, | |
| 249 | − .ahb_buf_size = 1024, | |
| 250 | − .driver_data = QUADSPI_QUIRK_TKT253890 | |
| 251 | − | QUADSPI_QUIRK_4X_INT_CLK, | |
| 252 | −}; | |
| 253 | − | |
| 254 | −static const struct fsl_qspi_devtype_data imx6ul_data = { | |
| 255 | − .devtype = FSL_QUADSPI_IMX6UL, | |
| 256 | − .rxfifo = 128, | |
| 257 | − .txfifo = 512, | |
| 258 | − .ahb_buf_size = 1024, | |
| 259 | − .driver_data = QUADSPI_QUIRK_TKT253890 | |
| 260 | − | QUADSPI_QUIRK_4X_INT_CLK, | |
| 261 | −}; | |
| 262 | − | |
| 263 | −static struct fsl_qspi_devtype_data ls1021a_data = { | |
| 264 | − .devtype = FSL_QUADSPI_LS1021A, | |
| 265 | − .rxfifo = 128, | |
| 266 | − .txfifo = 64, | |
| 267 | − .ahb_buf_size = 1024, | |
| 268 | − .driver_data = 0, | |
| 269 | −}; | |
| 270 | − | |
| 271 | −static const struct fsl_qspi_devtype_data ls2080a_data = { | |
| 272 | − .devtype = FSL_QUADSPI_LS2080A, | |
| 273 | − .rxfifo = 128, | |
| 274 | − .txfifo = 64, | |
| 275 | − .ahb_buf_size = 1024, | |
| 276 | − .driver_data = QUADSPI_QUIRK_TKT253890, | |
| 277 | −}; | |
| 278 | − | |
| 279 | − | |
| 280 | −#define FSL_QSPI_MAX_CHIP 4 | |
| 281 | −struct fsl_qspi { | |
| 282 | − struct spi_nor nor[FSL_QSPI_MAX_CHIP]; | |
| 283 | − void __iomem *iobase; | |
| 284 | − void __iomem *ahb_addr; | |
| 285 | − u32 memmap_phy; | |
| 286 | − u32 memmap_offs; | |
| 287 | − u32 memmap_len; | |
| 288 | − struct clk *clk, *clk_en; | |
| 289 | − struct device *dev; | |
| 290 | − struct completion c; | |
| 291 | − const struct fsl_qspi_devtype_data *devtype_data; | |
| 292 | − u32 nor_size; | |
| 293 | − u32 nor_num; | |
| 294 | − u32 clk_rate; | |
| 295 | − unsigned int chip_base_addr; /* We may support two chips. */ | |
| 296 | − bool has_second_chip; | |
| 297 | − bool big_endian; | |
| 298 | − struct mutex lock; | |
| 299 | − struct pm_qos_request pm_qos_req; | |
| 300 | −}; | |
| 301 | − | |
| 302 | −static inline int needs_swap_endian(struct fsl_qspi *q) | |
| 303 | −{ | |
| 304 | − return q->devtype_data->driver_data & QUADSPI_QUIRK_SWAP_ENDIAN; | |
| 305 | −} | |
| 306 | − | |
| 307 | −static inline int needs_4x_clock(struct fsl_qspi *q) | |
| 308 | −{ | |
| 309 | − return q->devtype_data->driver_data & QUADSPI_QUIRK_4X_INT_CLK; | |
| 310 | −} | |
| 311 | − | |
| 312 | −static inline int needs_fill_txfifo(struct fsl_qspi *q) | |
| 313 | −{ | |
| 314 | − return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT253890; | |
| 315 | −} | |
| 316 | − | |
| 317 | −static inline int needs_wakeup_wait_mode(struct fsl_qspi *q) | |
| 318 | −{ | |
| 319 | − return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618; | |
| 320 | −} | |
| 321 | − | |
| 322 | −/* | |
| 323 | − * R/W functions for big- or little-endian registers: | |
| 324 | − * The qSPI controller's endian is independent of the CPU core's endian. | |
| 325 | − * So far, although the CPU core is little-endian but the qSPI have two | |
| 326 | − * versions for big-endian and little-endian. | |
| 327 | − */ | |
| 328 | −static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr) | |
| 329 | −{ | |
| 330 | − if (q->big_endian) | |
| 331 | − iowrite32be(val, addr); | |
| 332 | − else | |
| 333 | − iowrite32(val, addr); | |
| 334 | −} | |
| 335 | − | |
| 336 | −static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr) | |
| 337 | −{ | |
| 338 | − if (q->big_endian) | |
| 339 | − return ioread32be(addr); | |
| 340 | − else | |
| 341 | − return ioread32(addr); | |
| 342 | −} | |
| 343 | − | |
| 344 | −/* | |
| 345 | − * An IC bug makes us to re-arrange the 32-bit data. | |
| 346 | − * The following chips, such as IMX6SLX, have fixed this bug. | |
| 347 | − */ | |
| 348 | −static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a) | |
| 349 | −{ | |
| 350 | − return needs_swap_endian(q) ? __swab32(a) : a; | |
| 351 | −} | |
| 352 | − | |
| 353 | −static inline void fsl_qspi_unlock_lut(struct fsl_qspi *q) | |
| 354 | −{ | |
| 355 | − qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); | |
| 356 | − qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR); | |
| 357 | −} | |
| 358 | − | |
| 359 | −static inline void fsl_qspi_lock_lut(struct fsl_qspi *q) | |
| 360 | −{ | |
| 361 | − qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); | |
| 362 | − qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR); | |
| 363 | −} | |
| 364 | − | |
| 365 | −static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id) | |
| 366 | −{ | |
| 367 | − struct fsl_qspi *q = dev_id; | |
| 368 | − u32 reg; | |
| 369 | − | |
| 370 | − /* clear interrupt */ | |
| 371 | − reg = qspi_readl(q, q->iobase + QUADSPI_FR); | |
| 372 | − qspi_writel(q, reg, q->iobase + QUADSPI_FR); | |
| 373 | − | |
| 374 | − if (reg & QUADSPI_FR_TFF_MASK) | |
| 375 | − complete(&q->c); | |
| 376 | − | |
| 377 | − dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", q->chip_base_addr, reg); | |
| 378 | − return IRQ_HANDLED; | |
| 379 | −} | |
| 380 | − | |
| 381 | −static void fsl_qspi_init_lut(struct fsl_qspi *q) | |
| 382 | −{ | |
| 383 | − void __iomem *base = q->iobase; | |
| 384 | − int rxfifo = q->devtype_data->rxfifo; | |
| 385 | − u32 lut_base; | |
| 386 | − int i; | |
| 387 | − | |
| 388 | − struct spi_nor *nor = &q->nor[0]; | |
| 389 | − u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT; | |
| 390 | − u8 read_op = nor->read_opcode; | |
| 391 | − u8 read_dm = nor->read_dummy; | |
| 392 | − | |
| 393 | − fsl_qspi_unlock_lut(q); | |
| 394 | − | |
| 395 | − /* Clear all the LUT table */ | |
| 396 | − for (i = 0; i < QUADSPI_LUT_NUM; i++) | |
| 397 | − qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4); | |
| 398 | − | |
| 399 | − /* Read */ | |
| 400 | − lut_base = SEQID_READ * 4; | |
| 401 | − | |
| 402 | − qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen), | |
| 403 | − base + QUADSPI_LUT(lut_base)); | |
| 404 | − qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) | | |
| 405 | − LUT1(FSL_READ, PAD4, rxfifo), | |
| 406 | − base + QUADSPI_LUT(lut_base + 1)); | |
| 407 | − | |
| 408 | − /* Write enable */ | |
| 409 | − lut_base = SEQID_WREN * 4; | |
| 410 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN), | |
| 411 | − base + QUADSPI_LUT(lut_base)); | |
| 412 | − | |
| 413 | − /* Page Program */ | |
| 414 | − lut_base = SEQID_PP * 4; | |
| 415 | − | |
| 416 | − qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) | | |
| 417 | − LUT1(ADDR, PAD1, addrlen), | |
| 418 | − base + QUADSPI_LUT(lut_base)); | |
| 419 | − qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0), | |
| 420 | − base + QUADSPI_LUT(lut_base + 1)); | |
| 421 | − | |
| 422 | − /* Read Status */ | |
| 423 | − lut_base = SEQID_RDSR * 4; | |
| 424 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDSR) | | |
| 425 | − LUT1(FSL_READ, PAD1, 0x1), | |
| 426 | − base + QUADSPI_LUT(lut_base)); | |
| 427 | − | |
| 428 | − /* Erase a sector */ | |
| 429 | − lut_base = SEQID_SE * 4; | |
| 430 | − | |
| 431 | − qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) | | |
| 432 | − LUT1(ADDR, PAD1, addrlen), | |
| 433 | − base + QUADSPI_LUT(lut_base)); | |
| 434 | − | |
| 435 | − /* Erase the whole chip */ | |
| 436 | − lut_base = SEQID_CHIP_ERASE * 4; | |
| 437 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE), | |
| 438 | − base + QUADSPI_LUT(lut_base)); | |
| 439 | − | |
| 440 | − /* READ ID */ | |
| 441 | − lut_base = SEQID_RDID * 4; | |
| 442 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDID) | | |
| 443 | − LUT1(FSL_READ, PAD1, 0x8), | |
| 444 | − base + QUADSPI_LUT(lut_base)); | |
| 445 | − | |
| 446 | − /* Write Register */ | |
| 447 | − lut_base = SEQID_WRSR * 4; | |
| 448 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRSR) | | |
| 449 | − LUT1(FSL_WRITE, PAD1, 0x2), | |
| 450 | − base + QUADSPI_LUT(lut_base)); | |
| 451 | − | |
| 452 | − /* Read Configuration Register */ | |
| 453 | − lut_base = SEQID_RDCR * 4; | |
| 454 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDCR) | | |
| 455 | − LUT1(FSL_READ, PAD1, 0x1), | |
| 456 | − base + QUADSPI_LUT(lut_base)); | |
| 457 | − | |
| 458 | − /* Write disable */ | |
| 459 | − lut_base = SEQID_WRDI * 4; | |
| 460 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRDI), | |
| 461 | − base + QUADSPI_LUT(lut_base)); | |
| 462 | − | |
| 463 | − /* Enter 4 Byte Mode (Micron) */ | |
| 464 | − lut_base = SEQID_EN4B * 4; | |
| 465 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_EN4B), | |
| 466 | − base + QUADSPI_LUT(lut_base)); | |
| 467 | − | |
| 468 | − /* Enter 4 Byte Mode (Spansion) */ | |
| 469 | − lut_base = SEQID_BRWR * 4; | |
| 470 | − qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR), | |
| 471 | − base + QUADSPI_LUT(lut_base)); | |
| 472 | − | |
| 473 | − fsl_qspi_lock_lut(q); | |
| 474 | −} | |
| 475 | − | |
| 476 | −/* Get the SEQID for the command */ | |
| 477 | −static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd) | |
| 478 | −{ | |
| 479 | − switch (cmd) { | |
| 480 | − case SPINOR_OP_READ_1_1_4: | |
| 481 | − case SPINOR_OP_READ_1_1_4_4B: | |
| 482 | − return SEQID_READ; | |
| 483 | − case SPINOR_OP_WREN: | |
| 484 | − return SEQID_WREN; | |
| 485 | − case SPINOR_OP_WRDI: | |
| 486 | − return SEQID_WRDI; | |
| 487 | − case SPINOR_OP_RDSR: | |
| 488 | − return SEQID_RDSR; | |
| 489 | − case SPINOR_OP_SE: | |
| 490 | − return SEQID_SE; | |
| 491 | − case SPINOR_OP_CHIP_ERASE: | |
| 492 | − return SEQID_CHIP_ERASE; | |
| 493 | − case SPINOR_OP_PP: | |
| 494 | − return SEQID_PP; | |
| 495 | − case SPINOR_OP_RDID: | |
| 496 | − return SEQID_RDID; | |
| 497 | − case SPINOR_OP_WRSR: | |
| 498 | − return SEQID_WRSR; | |
| 499 | − case SPINOR_OP_RDCR: | |
| 500 | − return SEQID_RDCR; | |
| 501 | − case SPINOR_OP_EN4B: | |
| 502 | − return SEQID_EN4B; | |
| 503 | − case SPINOR_OP_BRWR: | |
| 504 | − return SEQID_BRWR; | |
| 505 | − default: | |
| 506 | − if (cmd == q->nor[0].erase_opcode) | |
| 507 | − return SEQID_SE; | |
| 508 | − dev_err(q->dev, "Unsupported cmd 0x%.2x\n", cmd); | |
| 509 | − break; | |
| 510 | − } | |
| 511 | − return -EINVAL; | |
| 512 | −} | |
| 513 | − | |
| 514 | −static int | |
| 515 | −fsl_qspi_runcmd(struct fsl_qspi *q, u8 cmd, unsigned int addr, int len) | |
| 516 | −{ | |
| 517 | − void __iomem *base = q->iobase; | |
| 518 | − int seqid; | |
| 519 | − u32 reg, reg2; | |
| 520 | − int err; | |
| 521 | − | |
| 522 | − init_completion(&q->c); | |
| 523 | − dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n", | |
| 524 | − q->chip_base_addr, addr, len, cmd); | |
| 525 | − | |
| 526 | − /* save the reg */ | |
| 527 | − reg = qspi_readl(q, base + QUADSPI_MCR); | |
| 528 | − | |
| 529 | − qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr, | |
| 530 | − base + QUADSPI_SFAR); | |
| 531 | − qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS, | |
| 532 | − base + QUADSPI_RBCT); | |
| 533 | − qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR); | |
| 534 | − | |
| 535 | − do { | |
| 536 | − reg2 = qspi_readl(q, base + QUADSPI_SR); | |
| 537 | − if (reg2 & (QUADSPI_SR_IP_ACC_MASK | QUADSPI_SR_AHB_ACC_MASK)) { | |
| 538 | − udelay(1); | |
| 539 | − dev_dbg(q->dev, "The controller is busy, 0x%x\n", reg2); | |
| 540 | − continue; | |
| 541 | − } | |
| 542 | − break; | |
| 543 | − } while (1); | |
| 544 | − | |
| 545 | − /* trigger the LUT now */ | |
| 546 | − seqid = fsl_qspi_get_seqid(q, cmd); | |
| 547 | − if (seqid < 0) | |
| 548 | − return seqid; | |
| 549 | − | |
| 550 | − qspi_writel(q, (seqid << QUADSPI_IPCR_SEQID_SHIFT) | len, | |
| 551 | − base + QUADSPI_IPCR); | |
| 552 | − | |
| 553 | − /* Wait for the interrupt. */ | |
| 554 | − if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000))) { | |
| 555 | − dev_err(q->dev, | |
| 556 | − "cmd 0x%.2x timeout, addr@%.8x, FR:0x%.8x, SR:0x%.8x\n", | |
| 557 | − cmd, addr, qspi_readl(q, base + QUADSPI_FR), | |
| 558 | − qspi_readl(q, base + QUADSPI_SR)); | |
| 559 | − err = -ETIMEDOUT; | |
| 560 | − } else { | |
| 561 | − err = 0; | |
| 562 | − } | |
| 563 | − | |
| 564 | − /* restore the MCR */ | |
| 565 | − qspi_writel(q, reg, base + QUADSPI_MCR); | |
| 566 | − | |
| 567 | − return err; | |
| 568 | −} | |
| 569 | − | |
| 570 | −/* Read out the data from the QUADSPI_RBDR buffer registers. */ | |
| 571 | −static void fsl_qspi_read_data(struct fsl_qspi *q, int len, u8 *rxbuf) | |
| 572 | −{ | |
| 573 | − u32 tmp; | |
| 574 | − int i = 0; | |
| 575 | − | |
| 576 | − while (len > 0) { | |
| 577 | − tmp = qspi_readl(q, q->iobase + QUADSPI_RBDR + i * 4); | |
| 578 | − tmp = fsl_qspi_endian_xchg(q, tmp); | |
| 579 | − dev_dbg(q->dev, "chip addr:0x%.8x, rcv:0x%.8x\n", | |
| 580 | − q->chip_base_addr, tmp); | |
| 581 | − | |
| 582 | − if (len >= 4) { | |
| 583 | − *((u32 *)rxbuf) = tmp; | |
| 584 | − rxbuf += 4; | |
| 585 | − } else { | |
| 586 | − memcpy(rxbuf, &tmp, len); | |
| 587 | − break; | |
| 588 | − } | |
| 589 | − | |
| 590 | − len -= 4; | |
| 591 | − i++; | |
| 592 | − } | |
| 593 | −} | |
| 594 | − | |
| 595 | −/* | |
| 596 | − * If we have changed the content of the flash by writing or erasing, | |
| 597 | − * we need to invalidate the AHB buffer. If we do not do so, we may read out | |
| 598 | − * the wrong data. The spec tells us reset the AHB domain and Serial Flash | |
| 599 | − * domain at the same time. | |
| 600 | − */ | |
| 601 | −static inline void fsl_qspi_invalid(struct fsl_qspi *q) | |
| 602 | −{ | |
| 603 | − u32 reg; | |
| 604 | − | |
| 605 | − reg = qspi_readl(q, q->iobase + QUADSPI_MCR); | |
| 606 | − reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK; | |
| 607 | − qspi_writel(q, reg, q->iobase + QUADSPI_MCR); | |
| 608 | − | |
| 609 | − /* | |
| 610 | − * The minimum delay : 1 AHB + 2 SFCK clocks. | |
| 611 | − * Delay 1 us is enough. | |
| 612 | − */ | |
| 613 | − udelay(1); | |
| 614 | − | |
| 615 | − reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK); | |
| 616 | − qspi_writel(q, reg, q->iobase + QUADSPI_MCR); | |
| 617 | −} | |
| 618 | − | |
| 619 | −static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor, | |
| 620 | − u8 opcode, unsigned int to, u32 *txbuf, | |
| 621 | − unsigned count) | |
| 622 | −{ | |
| 623 | − int ret, i, j; | |
| 624 | − u32 tmp; | |
| 625 | − | |
| 626 | − dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n", | |
| 627 | − q->chip_base_addr, to, count); | |
| 628 | − | |
| 629 | − /* clear the TX FIFO. */ | |
| 630 | − tmp = qspi_readl(q, q->iobase + QUADSPI_MCR); | |
| 631 | − qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR); | |
| 632 | − | |
| 633 | − /* fill the TX data to the FIFO */ | |
| 634 | − for (j = 0, i = ((count + 3) / 4); j < i; j++) { | |
| 635 | − tmp = fsl_qspi_endian_xchg(q, *txbuf); | |
| 636 | − qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR); | |
| 637 | − txbuf++; | |
| 638 | − } | |
| 639 | − | |
| 640 | − /* fill the TXFIFO upto 16 bytes for i.MX7d */ | |
| 641 | − if (needs_fill_txfifo(q)) | |
| 642 | − for (; i < 4; i++) | |
| 643 | − qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR); | |
| 644 | − | |
| 645 | − /* Trigger it */ | |
| 646 | − ret = fsl_qspi_runcmd(q, opcode, to, count); | |
| 647 | − | |
| 648 | − if (ret == 0) | |
| 649 | − return count; | |
| 650 | − | |
| 651 | − return ret; | |
| 652 | −} | |
| 653 | − | |
| 654 | −static void fsl_qspi_set_map_addr(struct fsl_qspi *q) | |
| 655 | −{ | |
| 656 | − int nor_size = q->nor_size; | |
| 657 | − void __iomem *base = q->iobase; | |
| 658 | − | |
| 659 | − qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD); | |
| 660 | − qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD); | |
| 661 | − qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD); | |
| 662 | − qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD); | |
| 663 | −} | |
| 664 | − | |
| 665 | −/* | |
| 666 | − * There are two different ways to read out the data from the flash: | |
| 667 | − * the "IP Command Read" and the "AHB Command Read". | |
| 668 | − * | |
| 669 | − * The IC guy suggests we use the "AHB Command Read" which is faster | |
| 670 | − * then the "IP Command Read". (What's more is that there is a bug in | |
| 671 | − * the "IP Command Read" in the Vybrid.) | |
| 672 | − * | |
| 673 | − * After we set up the registers for the "AHB Command Read", we can use | |
| 674 | − * the memcpy to read the data directly. A "missed" access to the buffer | |
| 675 | − * causes the controller to clear the buffer, and use the sequence pointed | |
| 676 | − * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash. | |
| 677 | − */ | |
| 678 | −static int fsl_qspi_init_ahb_read(struct fsl_qspi *q) | |
| 679 | −{ | |
| 680 | − void __iomem *base = q->iobase; | |
| 681 | − int seqid; | |
| 682 | − | |
| 683 | − /* AHB configuration for access buffer 0/1/2 .*/ | |
| 684 | − qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF0CR); | |
| 685 | − qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF1CR); | |
| 686 | − qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF2CR); | |
| 687 | − /* | |
| 688 | − * Set ADATSZ with the maximum AHB buffer size to improve the | |
| 689 | − * read performance. | |
| 690 | − */ | |
| 691 | − qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK | | |
| 692 | − ((q->devtype_data->ahb_buf_size / 8) | |
| 693 | − << QUADSPI_BUF3CR_ADATSZ_SHIFT), | |
| 694 | − base + QUADSPI_BUF3CR); | |
| 695 | − | |
| 696 | − /* We only use the buffer3 */ | |
| 697 | − qspi_writel(q, 0, base + QUADSPI_BUF0IND); | |
| 698 | − qspi_writel(q, 0, base + QUADSPI_BUF1IND); | |
| 699 | − qspi_writel(q, 0, base + QUADSPI_BUF2IND); | |
| 700 | − | |
| 701 | − /* Set the default lut sequence for AHB Read. */ | |
| 702 | − seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode); | |
| 703 | − if (seqid < 0) | |
| 704 | − return seqid; | |
| 705 | − | |
| 706 | − qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT, | |
| 707 | − q->iobase + QUADSPI_BFGENCR); | |
| 708 | − | |
| 709 | − return 0; | |
| 710 | −} | |
| 711 | − | |
| 712 | −/* This function was used to prepare and enable QSPI clock */ | |
| 713 | −static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q) | |
| 714 | −{ | |
| 715 | − int ret; | |
| 716 | − | |
| 717 | − ret = clk_prepare_enable(q->clk_en); | |
| 718 | − if (ret) | |
| 719 | − return ret; | |
| 720 | − | |
| 721 | − ret = clk_prepare_enable(q->clk); | |
| 722 | − if (ret) { | |
| 723 | − clk_disable_unprepare(q->clk_en); | |
| 724 | − return ret; | |
| 725 | − } | |
| 726 | − | |
| 727 | − if (needs_wakeup_wait_mode(q)) | |
| 728 | − pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0); | |
| 729 | − | |
| 730 | − return 0; | |
| 731 | −} | |
| 732 | − | |
| 733 | −/* This function was used to disable and unprepare QSPI clock */ | |
| 734 | −static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q) | |
| 735 | −{ | |
| 736 | − if (needs_wakeup_wait_mode(q)) | |
| 737 | − pm_qos_remove_request(&q->pm_qos_req); | |
| 738 | − | |
| 739 | − clk_disable_unprepare(q->clk); | |
| 740 | − clk_disable_unprepare(q->clk_en); | |
| 741 | − | |
| 742 | −} | |
| 743 | − | |
| 744 | −/* We use this function to do some basic init for spi_nor_scan(). */ | |
| 745 | −static int fsl_qspi_nor_setup(struct fsl_qspi *q) | |
| 746 | −{ | |
| 747 | − void __iomem *base = q->iobase; | |
| 748 | − u32 reg; | |
| 749 | − int ret; | |
| 750 | − | |
| 751 | − /* disable and unprepare clock to avoid glitch pass to controller */ | |
| 752 | − fsl_qspi_clk_disable_unprep(q); | |
| 753 | − | |
| 754 | − /* the default frequency, we will change it in the future. */ | |
| 755 | − ret = clk_set_rate(q->clk, 66000000); | |
| 756 | − if (ret) | |
| 757 | − return ret; | |
| 758 | − | |
| 759 | − ret = fsl_qspi_clk_prep_enable(q); | |
| 760 | − if (ret) | |
| 761 | − return ret; | |
| 762 | − | |
| 763 | − /* Reset the module */ | |
| 764 | − qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK, | |
| 765 | − base + QUADSPI_MCR); | |
| 766 | − udelay(1); | |
| 767 | − | |
| 768 | − /* Init the LUT table. */ | |
| 769 | − fsl_qspi_init_lut(q); | |
| 770 | − | |
| 771 | − /* Disable the module */ | |
| 772 | − qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK, | |
| 773 | − base + QUADSPI_MCR); | |
| 774 | − | |
| 775 | − reg = qspi_readl(q, base + QUADSPI_SMPR); | |
| 776 | − qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK | |
| 777 | − | QUADSPI_SMPR_FSPHS_MASK | |
| 778 | − | QUADSPI_SMPR_HSENA_MASK | |
| 779 | − | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR); | |
| 780 | − | |
| 781 | − /* Enable the module */ | |
| 782 | − qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK, | |
| 783 | − base + QUADSPI_MCR); | |
| 784 | − | |
| 785 | − /* clear all interrupt status */ | |
| 786 | − qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR); | |
| 787 | − | |
| 788 | − /* enable the interrupt */ | |
| 789 | − qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER); | |
| 790 | − | |
| 791 | − return 0; | |
| 792 | −} | |
| 793 | − | |
| 794 | −static int fsl_qspi_nor_setup_last(struct fsl_qspi *q) | |
| 795 | −{ | |
| 796 | − unsigned long rate = q->clk_rate; | |
| 797 | − int ret; | |
| 798 | − | |
| 799 | − if (needs_4x_clock(q)) | |
| 800 | − rate *= 4; | |
| 801 | − | |
| 802 | − /* disable and unprepare clock to avoid glitch pass to controller */ | |
| 803 | − fsl_qspi_clk_disable_unprep(q); | |
| 804 | − | |
| 805 | − ret = clk_set_rate(q->clk, rate); | |
| 806 | − if (ret) | |
| 807 | − return ret; | |
| 808 | − | |
| 809 | − ret = fsl_qspi_clk_prep_enable(q); | |
| 810 | − if (ret) | |
| 811 | − return ret; | |
| 812 | − | |
| 813 | − /* Init the LUT table again. */ | |
| 814 | − fsl_qspi_init_lut(q); | |
| 815 | − | |
| 816 | − /* Init for AHB read */ | |
| 817 | − return fsl_qspi_init_ahb_read(q); | |
| 818 | −} | |
| 819 | − | |
| 820 | −static const struct of_device_id fsl_qspi_dt_ids[] = { | |
| 821 | − { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, }, | |
| 822 | − { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, }, | |
| 823 | − { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, }, | |
| 824 | − { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, }, | |
| 825 | − { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, }, | |
| 826 | − { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, }, | |
| 827 | − { /* sentinel */ } | |
| 828 | −}; | |
| 829 | −MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids); | |
| 830 | − | |
| 831 | −static void fsl_qspi_set_base_addr(struct fsl_qspi *q, struct spi_nor *nor) | |
| 832 | −{ | |
| 833 | − q->chip_base_addr = q->nor_size * (nor - q->nor); | |
| 834 | −} | |
| 835 | − | |
| 836 | −static int fsl_qspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) | |
| 837 | −{ | |
| 838 | − int ret; | |
| 839 | − struct fsl_qspi *q = nor->priv; | |
| 840 | − | |
| 841 | − ret = fsl_qspi_runcmd(q, opcode, 0, len); | |
| 842 | − if (ret) | |
| 843 | − return ret; | |
| 844 | − | |
| 845 | − fsl_qspi_read_data(q, len, buf); | |
| 846 | − return 0; | |
| 847 | −} | |
| 848 | − | |
| 849 | −static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len) | |
| 850 | −{ | |
| 851 | − struct fsl_qspi *q = nor->priv; | |
| 852 | − int ret; | |
| 853 | − | |
| 854 | − if (!buf) { | |
| 855 | − ret = fsl_qspi_runcmd(q, opcode, 0, 1); | |
| 856 | − if (ret) | |
| 857 | − return ret; | |
| 858 | − | |
| 859 | − if (opcode == SPINOR_OP_CHIP_ERASE) | |
| 860 | − fsl_qspi_invalid(q); | |
| 861 | − | |
| 862 | − } else if (len > 0) { | |
| 863 | − ret = fsl_qspi_nor_write(q, nor, opcode, 0, | |
| 864 | − (u32 *)buf, len); | |
| 865 | − if (ret > 0) | |
| 866 | − return 0; | |
| 867 | − } else { | |
| 868 | − dev_err(q->dev, "invalid cmd %d\n", opcode); | |
| 869 | − ret = -EINVAL; | |
| 870 | − } | |
| 871 | − | |
| 872 | − return ret; | |
| 873 | −} | |
| 874 | − | |
| 875 | −static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to, | |
| 876 | − size_t len, const u_char *buf) | |
| 877 | −{ | |
| 878 | − struct fsl_qspi *q = nor->priv; | |
| 879 | − ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to, | |
| 880 | − (u32 *)buf, len); | |
| 881 | − | |
| 882 | − /* invalid the data in the AHB buffer. */ | |
| 883 | − fsl_qspi_invalid(q); | |
| 884 | − return ret; | |
| 885 | −} | |
| 886 | − | |
| 887 | −static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from, | |
| 888 | − size_t len, u_char *buf) | |
| 889 | −{ | |
| 890 | − struct fsl_qspi *q = nor->priv; | |
| 891 | − u8 cmd = nor->read_opcode; | |
| 892 | − | |
| 893 | − /* if necessary,ioremap buffer before AHB read, */ | |
| 894 | − if (!q->ahb_addr) { | |
| 895 | − q->memmap_offs = q->chip_base_addr + from; | |
| 896 | − q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP; | |
| 897 | − | |
| 898 | − q->ahb_addr = ioremap_nocache( | |
| 899 | − q->memmap_phy + q->memmap_offs, | |
| 900 | − q->memmap_len); | |
| 901 | − if (!q->ahb_addr) { | |
| 902 | − dev_err(q->dev, "ioremap failed\n"); | |
| 903 | − return -ENOMEM; | |
| 904 | − } | |
| 905 | − /* ioremap if the data requested is out of range */ | |
| 906 | − } else if (q->chip_base_addr + from < q->memmap_offs | |
| 907 | − || q->chip_base_addr + from + len > | |
| 908 | − q->memmap_offs + q->memmap_len) { | |
| 909 | − iounmap(q->ahb_addr); | |
| 910 | − | |
| 911 | − q->memmap_offs = q->chip_base_addr + from; | |
| 912 | − q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP; | |
| 913 | − q->ahb_addr = ioremap_nocache( | |
| 914 | − q->memmap_phy + q->memmap_offs, | |
| 915 | − q->memmap_len); | |
| 916 | − if (!q->ahb_addr) { | |
| 917 | − dev_err(q->dev, "ioremap failed\n"); | |
| 918 | − return -ENOMEM; | |
| 919 | − } | |
| 920 | − } | |
| 921 | − | |
| 922 | − dev_dbg(q->dev, "cmd [%x],read from %p, len:%zd\n", | |
| 923 | − cmd, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs, | |
| 924 | − len); | |
| 925 | − | |
| 926 | − /* Read out the data directly from the AHB buffer.*/ | |
| 927 | − memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs, | |
| 928 | − len); | |
| 929 | − | |
| 930 | − return len; | |
| 931 | −} | |
| 932 | − | |
| 933 | −static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs) | |
| 934 | −{ | |
| 935 | − struct fsl_qspi *q = nor->priv; | |
| 936 | − int ret; | |
| 937 | − | |
| 938 | − dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n", | |
| 939 | − nor->mtd.erasesize / 1024, q->chip_base_addr, (u32)offs); | |
| 940 | − | |
| 941 | − ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0); | |
| 942 | − if (ret) | |
| 943 | − return ret; | |
| 944 | − | |
| 945 | − fsl_qspi_invalid(q); | |
| 946 | − return 0; | |
| 947 | −} | |
| 948 | − | |
| 949 | −static int fsl_qspi_prep(struct spi_nor *nor, enum spi_nor_ops ops) | |
| 950 | −{ | |
| 951 | − struct fsl_qspi *q = nor->priv; | |
| 952 | − int ret; | |
| 953 | − | |
| 954 | − mutex_lock(&q->lock); | |
| 955 | − | |
| 956 | − ret = fsl_qspi_clk_prep_enable(q); | |
| 957 | − if (ret) | |
| 958 | − goto err_mutex; | |
| 959 | − | |
| 960 | − fsl_qspi_set_base_addr(q, nor); | |
| 961 | − return 0; | |
| 962 | − | |
| 963 | −err_mutex: | |
| 964 | − mutex_unlock(&q->lock); | |
| 965 | − return ret; | |
| 966 | −} | |
| 967 | − | |
| 968 | −static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops) | |
| 969 | −{ | |
| 970 | − struct fsl_qspi *q = nor->priv; | |
| 971 | − | |
| 972 | − fsl_qspi_clk_disable_unprep(q); | |
| 973 | − mutex_unlock(&q->lock); | |
| 974 | −} | |
| 975 | − | |
| 976 | −static int fsl_qspi_probe(struct platform_device *pdev) | |
| 977 | −{ | |
| 978 | − const struct spi_nor_hwcaps hwcaps = { | |
| 979 | − .mask = SNOR_HWCAPS_READ_1_1_4 | | |
| 980 | − SNOR_HWCAPS_PP, | |
| 981 | − }; | |
| 982 | − struct device_node *np = pdev->dev.of_node; | |
| 983 | − struct device *dev = &pdev->dev; | |
| 984 | − struct fsl_qspi *q; | |
| 985 | − struct resource *res; | |
| 986 | − struct spi_nor *nor; | |
| 987 | − struct mtd_info *mtd; | |
| 988 | − int ret, i = 0; | |
| 989 | − | |
| 990 | − q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL); | |
| 991 | − if (!q) | |
| 992 | − return -ENOMEM; | |
| 993 | − | |
| 994 | − q->nor_num = of_get_child_count(dev->of_node); | |
| 995 | − if (!q->nor_num || q->nor_num > FSL_QSPI_MAX_CHIP) | |
| 996 | − return -ENODEV; | |
| 997 | − | |
| 998 | − q->dev = dev; | |
| 999 | − q->devtype_data = of_device_get_match_data(dev); | |
| 1000 | − if (!q->devtype_data) | |
| 1001 | − return -ENODEV; | |
| 1002 | − platform_set_drvdata(pdev, q); | |
| 1003 | − | |
| 1004 | − /* find the resources */ | |
| 1005 | − res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI"); | |
| 1006 | − q->iobase = devm_ioremap_resource(dev, res); | |
| 1007 | − if (IS_ERR(q->iobase)) | |
| 1008 | − return PTR_ERR(q->iobase); | |
| 1009 | − | |
| 1010 | − q->big_endian = of_property_read_bool(np, "big-endian"); | |
| 1011 | − res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | |
| 1012 | − "QuadSPI-memory"); | |
| 1013 | − if (!devm_request_mem_region(dev, res->start, resource_size(res), | |
| 1014 | − res->name)) { | |
| 1015 | − dev_err(dev, "can't request region for resource %pR\n", res); | |
| 1016 | − return -EBUSY; | |
| 1017 | − } | |
| 1018 | − | |
| 1019 | − q->memmap_phy = res->start; | |
| 1020 | − | |
| 1021 | − /* find the clocks */ | |
| 1022 | − q->clk_en = devm_clk_get(dev, "qspi_en"); | |
| 1023 | − if (IS_ERR(q->clk_en)) | |
| 1024 | − return PTR_ERR(q->clk_en); | |
| 1025 | − | |
| 1026 | − q->clk = devm_clk_get(dev, "qspi"); | |
| 1027 | − if (IS_ERR(q->clk)) | |
| 1028 | − return PTR_ERR(q->clk); | |
| 1029 | − | |
| 1030 | − ret = fsl_qspi_clk_prep_enable(q); | |
| 1031 | − if (ret) { | |
| 1032 | − dev_err(dev, "can not enable the clock\n"); | |
| 1033 | − goto clk_failed; | |
| 1034 | − } | |
| 1035 | − | |
| 1036 | − /* find the irq */ | |
| 1037 | − ret = platform_get_irq(pdev, 0); | |
| 1038 | − if (ret < 0) { | |
| 1039 | − dev_err(dev, "failed to get the irq: %d\n", ret); | |
| 1040 | − goto irq_failed; | |
| 1041 | − } | |
| 1042 | − | |
| 1043 | − ret = devm_request_irq(dev, ret, | |
| 1044 | − fsl_qspi_irq_handler, 0, pdev->name, q); | |
| 1045 | − if (ret) { | |
| 1046 | − dev_err(dev, "failed to request irq: %d\n", ret); | |
| 1047 | − goto irq_failed; | |
| 1048 | − } | |
| 1049 | − | |
| 1050 | − ret = fsl_qspi_nor_setup(q); | |
| 1051 | − if (ret) | |
| 1052 | − goto irq_failed; | |
| 1053 | − | |
| 1054 | − if (of_get_property(np, "fsl,qspi-has-second-chip", NULL)) | |
| 1055 | − q->has_second_chip = true; | |
| 1056 | − | |
| 1057 | − mutex_init(&q->lock); | |
| 1058 | − | |
| 1059 | − /* iterate the subnodes. */ | |
| 1060 | − for_each_available_child_of_node(dev->of_node, np) { | |
| 1061 | − /* skip the holes */ | |
| 1062 | − if (!q->has_second_chip) | |
| 1063 | − i *= 2; | |
| 1064 | − | |
| 1065 | − nor = &q->nor[i]; | |
| 1066 | − mtd = &nor->mtd; | |
| 1067 | − | |
| 1068 | − nor->dev = dev; | |
| 1069 | − spi_nor_set_flash_node(nor, np); | |
| 1070 | − nor->priv = q; | |
| 1071 | − | |
| 1072 | − if (q->nor_num > 1 && !mtd->name) { | |
| 1073 | − int spiflash_idx; | |
| 1074 | − | |
| 1075 | − ret = of_property_read_u32(np, "reg", &spiflash_idx); | |
| 1076 | − if (!ret) { | |
| 1077 | − mtd->name = devm_kasprintf(dev, GFP_KERNEL, | |
| 1078 | − "%s-%d", | |
| 1079 | − dev_name(dev), | |
| 1080 | − spiflash_idx); | |
| 1081 | − if (!mtd->name) { | |
| 1082 | − ret = -ENOMEM; | |
| 1083 | − goto mutex_failed; | |
| 1084 | − } | |
| 1085 | − } else { | |
| 1086 | − dev_warn(dev, "reg property is missing\n"); | |
| 1087 | − } | |
| 1088 | − } | |
| 1089 | − | |
| 1090 | − /* fill the hooks */ | |
| 1091 | − nor->read_reg = fsl_qspi_read_reg; | |
| 1092 | − nor->write_reg = fsl_qspi_write_reg; | |
| 1093 | − nor->read = fsl_qspi_read; | |
| 1094 | − nor->write = fsl_qspi_write; | |
| 1095 | − nor->erase = fsl_qspi_erase; | |
| 1096 | − | |
| 1097 | − nor->prepare = fsl_qspi_prep; | |
| 1098 | − nor->unprepare = fsl_qspi_unprep; | |
| 1099 | − | |
| 1100 | − ret = of_property_read_u32(np, "spi-max-frequency", | |
| 1101 | − &q->clk_rate); | |
| 1102 | − if (ret < 0) | |
| 1103 | − goto mutex_failed; | |
| 1104 | − | |
| 1105 | − /* set the chip address for READID */ | |
| 1106 | − fsl_qspi_set_base_addr(q, nor); | |
| 1107 | − | |
| 1108 | − ret = spi_nor_scan(nor, NULL, &hwcaps); | |
| 1109 | − if (ret) | |
| 1110 | − goto mutex_failed; | |
| 1111 | − | |
| 1112 | − ret = mtd_device_register(mtd, NULL, 0); | |
| 1113 | − if (ret) | |
| 1114 | − goto mutex_failed; | |
| 1115 | − | |
| 1116 | − /* Set the correct NOR size now. */ | |
| 1117 | − if (q->nor_size == 0) { | |
| 1118 | − q->nor_size = mtd->size; | |
| 1119 | − | |
| 1120 | − /* Map the SPI NOR to accessiable address */ | |
| 1121 | − fsl_qspi_set_map_addr(q); | |
| 1122 | − } | |
| 1123 | − | |
| 1124 | − /* | |
| 1125 | − * The TX FIFO is 64 bytes in the Vybrid, but the Page Program | |
| 1126 | − * may writes 265 bytes per time. The write is working in the | |
| 1127 | − * unit of the TX FIFO, not in the unit of the SPI NOR's page | |
| 1128 | − * size. | |
| 1129 | − * | |
| 1130 | − * So shrink the spi_nor->page_size if it is larger then the | |
| 1131 | − * TX FIFO. | |
| 1132 | − */ | |
| 1133 | − if (nor->page_size > q->devtype_data->txfifo) | |
| 1134 | − nor->page_size = q->devtype_data->txfifo; | |
| 1135 | − | |
| 1136 | − i++; | |
| 1137 | − } | |
| 1138 | − | |
| 1139 | − /* finish the rest init. */ | |
| 1140 | − ret = fsl_qspi_nor_setup_last(q); | |
| 1141 | − if (ret) | |
| 1142 | − goto last_init_failed; | |
| 1143 | − | |
| 1144 | − fsl_qspi_clk_disable_unprep(q); | |
| 1145 | − return 0; | |
| 1146 | − | |
| 1147 | −last_init_failed: | |
| 1148 | − for (i = 0; i < q->nor_num; i++) { | |
| 1149 | − /* skip the holes */ | |
| 1150 | − if (!q->has_second_chip) | |
| 1151 | − i *= 2; | |
| 1152 | − mtd_device_unregister(&q->nor[i].mtd); | |
| 1153 | − } | |
| 1154 | −mutex_failed: | |
| 1155 | − mutex_destroy(&q->lock); | |
| 1156 | −irq_failed: | |
| 1157 | − fsl_qspi_clk_disable_unprep(q); | |
| 1158 | −clk_failed: | |
| 1159 | − dev_err(dev, "Freescale QuadSPI probe failed\n"); | |
| 1160 | − return ret; | |
| 1161 | −} | |
| 1162 | − | |
| 1163 | −static int fsl_qspi_remove(struct platform_device *pdev) | |
| 1164 | −{ | |
| 1165 | − struct fsl_qspi *q = platform_get_drvdata(pdev); | |
| 1166 | − int i; | |
| 1167 | − | |
| 1168 | − for (i = 0; i < q->nor_num; i++) { | |
| 1169 | − /* skip the holes */ | |
| 1170 | − if (!q->has_second_chip) | |
| 1171 | − i *= 2; | |
| 1172 | − mtd_device_unregister(&q->nor[i].mtd); | |
| 1173 | − } | |
| 1174 | − | |
| 1175 | − /* disable the hardware */ | |
| 1176 | − qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR); | |
| 1177 | − qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER); | |
| 1178 | − | |
| 1179 | − mutex_destroy(&q->lock); | |
| 1180 | − | |
| 1181 | − if (q->ahb_addr) | |
| 1182 | − iounmap(q->ahb_addr); | |
| 1183 | − | |
| 1184 | − return 0; | |
| 1185 | −} | |
| 1186 | − | |
| 1187 | −static int fsl_qspi_suspend(struct platform_device *pdev, pm_message_t state) | |
| 1188 | −{ | |
| 1189 | − return 0; | |
| 1190 | −} | |
| 1191 | − | |
| 1192 | −static int fsl_qspi_resume(struct platform_device *pdev) | |
| 1193 | −{ | |
| 1194 | − int ret; | |
| 1195 | − struct fsl_qspi *q = platform_get_drvdata(pdev); | |
| 1196 | − | |
| 1197 | − ret = fsl_qspi_clk_prep_enable(q); | |
| 1198 | − if (ret) | |
| 1199 | − return ret; | |
| 1200 | − | |
| 1201 | − fsl_qspi_nor_setup(q); | |
| 1202 | − fsl_qspi_set_map_addr(q); | |
| 1203 | − fsl_qspi_nor_setup_last(q); | |
| 1204 | − | |
| 1205 | − fsl_qspi_clk_disable_unprep(q); | |
| 1206 | − | |
| 1207 | − return 0; | |
| 1208 | −} | |
| 1209 | − | |
| 1210 | −static struct platform_driver fsl_qspi_driver = { | |
| 1211 | − .driver = { | |
| 1212 | − .name = "fsl-quadspi", | |
| 1213 | − .of_match_table = fsl_qspi_dt_ids, | |
| 1214 | − }, | |
| 1215 | − .probe = fsl_qspi_probe, | |
| 1216 | − .remove = fsl_qspi_remove, | |
| 1217 | − .suspend = fsl_qspi_suspend, | |
| 1218 | − .resume = fsl_qspi_resume, | |
| 1219 | −}; | |
| 1220 | −module_platform_driver(fsl_qspi_driver); | |
| 1221 | − | |
| 1222 | −MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver"); | |
| 1223 | −MODULE_AUTHOR("Freescale Semiconductor Inc."); | |
| 1224 | −MODULE_LICENSE("GPL v2"); | |
| @@ -63,7 +63,7 @@ config SPI_ALTERA · 62 unmodified lines | ||
| 63 | 63 | |
| 64 | 64 | config SPI_ATH79 |
| 65 | 65 | tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver" |
| 66 | − depends on ATH79 && GPIOLIB | |
| 66 | + depends on ATH79 || COMPILE_TEST | |
| 67 | 67 | select SPI_BITBANG |
| 68 | 68 | help |
| 69 | 69 | This enables support for the SPI controller present on the |
| @@ -268,6 +268,27 @@ config SPI_FSL_LPSPI · 198 unmodified lines | ||
| 268 | 268 | help |
| 269 | 269 | This enables Freescale i.MX LPSPI controllers in master mode. |
| 270 | 270 | |
| 271 | +config SPI_FSL_QUADSPI | |
| 272 | + tristate "Freescale QSPI controller" | |
| 273 | + depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST | |
| 274 | + depends on HAS_IOMEM | |
| 275 | + help | |
| 276 | + This enables support for the Quad SPI controller in master mode. | |
| 277 | + Up to four flash chips can be connected on two buses with two | |
| 278 | + chipselects each. | |
| 279 | + This controller does not support generic SPI messages. It only | |
| 280 | + supports the high-level SPI memory interface. | |
| 281 | + | |
| 282 | +config SPI_NXP_FLEXSPI | |
| 283 | + tristate "NXP Flex SPI controller" | |
| 284 | + depends on ARCH_LAYERSCAPE || HAS_IOMEM | |
| 285 | + help | |
| 286 | + This enables support for the Flex SPI controller in master mode. | |
| 287 | + Up to four slave devices can be connected on two buses with two | |
| 288 | + chipselects each. | |
| 289 | + This controller does not support generic SPI messages and only | |
| 290 | + supports the high-level SPI memory interface. | |
| 291 | + | |
| 271 | 292 | config SPI_GPIO |
| 272 | 293 | tristate "GPIO-based bitbanging SPI Master" |
| 273 | 294 | depends on GPIOLIB || COMPILE_TEST |
| @@ -296,8 +317,7 @@ config SPI_IMX · 22 unmodified lines | ||
| 296 | 317 | depends on ARCH_MXC || COMPILE_TEST |
| 297 | 318 | select SPI_BITBANG |
| 298 | 319 | help |
| 299 | − This enables using the Freescale i.MX SPI controllers in master | |
| 300 | − mode. | |
| 320 | + This enables support for the Freescale i.MX SPI controllers. | |
| 301 | 321 | |
| 302 | 322 | config SPI_JCORE |
| 303 | 323 | tristate "J-Core SPI Master" |
| @@ -372,7 +392,7 @@ config SPI_FSL_DSPI · 68 unmodified lines | ||
| 372 | 392 | depends on SOC_VF610 || SOC_LS1021A || ARCH_LAYERSCAPE || M5441x || COMPILE_TEST |
| 373 | 393 | help |
| 374 | 394 | This enables support for the Freescale DSPI controller in master |
| 375 | − mode. VF610 platform uses the controller. | |
| 395 | + mode. VF610, LS1021A and ColdFire platforms uses the controller. | |
| 376 | 396 | |
| 377 | 397 | config SPI_FSL_ESPI |
| 378 | 398 | tristate "Freescale eSPI controller" |
| @@ -631,6 +651,12 @@ config SPI_SH_HSPI · 252 unmodified lines | ||
| 631 | 651 | help |
| 632 | 652 | SPI driver for SuperH HSPI blocks. |
| 633 | 653 | |
| 654 | +config SPI_SIFIVE | |
| 655 | + tristate "SiFive SPI controller" | |
| 656 | + depends on HAS_IOMEM | |
| 657 | + help | |
| 658 | + This exposes the SPI controller IP from SiFive. | |
| 659 | + | |
| 634 | 660 | config SPI_SIRF |
| 635 | 661 | tristate "CSR SiRFprimaII SPI controller" |
| 636 | 662 | depends on SIRF_DMA |
| @@ -665,7 +691,7 @@ config SPI_STM32 · 28 unmodified lines | ||
| 665 | 691 | tristate "STMicroelectronics STM32 SPI controller" |
| 666 | 692 | depends on ARCH_STM32 || COMPILE_TEST |
| 667 | 693 | help |
| 668 | − SPI driver for STMicroelectonics STM32 SoCs. | |
| 694 | + SPI driver for STMicroelectronics STM32 SoCs. | |
| 669 | 695 | |
| 670 | 696 | STM32 SPI controller supports DMA and PIO modes. When DMA |
| 671 | 697 | is not available, the driver automatically falls back to |
| @@ -45,6 +45,7 @@ obj-$(CONFIG_SPI_FSL_DSPI) += spi-fsl-dspi.o · 44 unmodified lines | ||
| 45 | 45 | obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o |
| 46 | 46 | obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o |
| 47 | 47 | obj-$(CONFIG_SPI_FSL_LPSPI) += spi-fsl-lpspi.o |
| 48 | +obj-$(CONFIG_SPI_FSL_QUADSPI) += spi-fsl-qspi.o | |
| 48 | 49 | obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o |
| 49 | 50 | obj-$(CONFIG_SPI_GPIO) += spi-gpio.o |
| 50 | 51 | obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o |
| @@ -63,6 +64,7 @@ obj-$(CONFIG_SPI_MXIC) += spi-mxic.o · 12 unmodified lines | ||
| 63 | 64 | obj-$(CONFIG_SPI_MXS) += spi-mxs.o |
| 64 | 65 | obj-$(CONFIG_SPI_NPCM_PSPI) += spi-npcm-pspi.o |
| 65 | 66 | obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o |
| 67 | +obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o | |
| 66 | 68 | obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o |
| 67 | 69 | spi-octeon-objs := spi-cavium.o spi-cavium-octeon.o |
| 68 | 70 | obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o |
| @@ -93,6 +95,7 @@ obj-$(CONFIG_SPI_SH) += spi-sh.o · 24 unmodified lines | ||
| 93 | 95 | obj-$(CONFIG_SPI_SH_HSPI) += spi-sh-hspi.o |
| 94 | 96 | obj-$(CONFIG_SPI_SH_MSIOF) += spi-sh-msiof.o |
| 95 | 97 | obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o |
| 98 | +obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o | |
| 96 | 99 | obj-$(CONFIG_SPI_SIRF) += spi-sirf.o |
| 97 | 100 | obj-$(CONFIG_SPI_SLAVE_MT27XX) += spi-slave-mt27xx.o |
| 98 | 101 | obj-$(CONFIG_SPI_SPRD) += spi-sprd.o |
| @@ -1,3 +1,4 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 1 | 2 | /* |
| 2 | 3 | * Driver for Atmel QSPI Controller |
| 3 | 4 | * |
| @@ -7,31 +8,19 @@ · 3 unmodified lines | ||
| 7 | 8 | * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com> |
| 8 | 9 | * Author: Piotr Bugalski <bugalski.piotr@gmail.com> |
| 9 | 10 | * |
| 10 | − * This program is free software; you can redistribute it and/or modify | |
| 11 | − * it under the terms of the GNU General Public License version 2 as | |
| 12 | − * published by the Free Software Foundation. | |
| 13 | − * | |
| 14 | − * This program is distributed in the hope that it will be useful, but WITHOUT | |
| 15 | − * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 16 | − * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
| 17 | − * more details. | |
| 18 | − * | |
| 19 | − * You should have received a copy of the GNU General Public License along with | |
| 20 | − * this program. If not, see <http://www.gnu.org/licenses/>. | |
| 21 | − * | |
| 22 | 11 | * This driver is based on drivers/mtd/spi-nor/fsl-quadspi.c from Freescale. |
| 23 | 12 | */ |
| 24 | 13 | |
| 25 | −#include <linux/kernel.h> | |
| 26 | 14 | #include <linux/clk.h> |
| 27 | −#include <linux/module.h> | |
| 28 | −#include <linux/platform_device.h> | |
| 29 | 15 | #include <linux/delay.h> |
| 30 | 16 | #include <linux/err.h> |
| 31 | 17 | #include <linux/interrupt.h> |
| 32 | −#include <linux/of.h> | |
| 33 | − | |
| 34 | 18 | #include <linux/io.h> |
| 19 | +#include <linux/kernel.h> | |
| 20 | +#include <linux/module.h> | |
| 21 | +#include <linux/of.h> | |
| 22 | +#include <linux/of_platform.h> | |
| 23 | +#include <linux/platform_device.h> | |
| 35 | 24 | #include <linux/spi/spi-mem.h> |
| 36 | 25 | |
| 37 | 26 | /* QSPI register offsets */ |
| @@ -47,7 +36,9 @@ · 9 unmodified lines | ||
| 47 | 36 | |
| 48 | 37 | #define QSPI_IAR 0x0030 /* Instruction Address Register */ |
| 49 | 38 | #define QSPI_ICR 0x0034 /* Instruction Code Register */ |
| 39 | +#define QSPI_WICR 0x0034 /* Write Instruction Code Register */ | |
| 50 | 40 | #define QSPI_IFR 0x0038 /* Instruction Frame Register */ |
| 41 | +#define QSPI_RICR 0x003C /* Read Instruction Code Register */ | |
| 51 | 42 | |
| 52 | 43 | #define QSPI_SMR 0x0040 /* Scrambling Mode Register */ |
| 53 | 44 | #define QSPI_SKR 0x0044 /* Scrambling Key Register */ |
| @@ -100,7 +91,7 @@ · 46 unmodified lines | ||
| 100 | 91 | #define QSPI_SCR_DLYBS_MASK GENMASK(23, 16) |
| 101 | 92 | #define QSPI_SCR_DLYBS(n) (((n) << 16) & QSPI_SCR_DLYBS_MASK) |
| 102 | 93 | |
| 103 | −/* Bitfields in QSPI_ICR (Instruction Code Register) */ | |
| 94 | +/* Bitfields in QSPI_ICR (Read/Write Instruction Code Register) */ | |
| 104 | 95 | #define QSPI_ICR_INST_MASK GENMASK(7, 0) |
| 105 | 96 | #define QSPI_ICR_INST(inst) (((inst) << 0) & QSPI_ICR_INST_MASK) |
| 106 | 97 | #define QSPI_ICR_OPT_MASK GENMASK(23, 16) |
| @@ -125,14 +116,12 @@ · 18 unmodified lines | ||
| 125 | 116 | #define QSPI_IFR_OPTL_4BIT (2 << 8) |
| 126 | 117 | #define QSPI_IFR_OPTL_8BIT (3 << 8) |
| 127 | 118 | #define QSPI_IFR_ADDRL BIT(10) |
| 128 | −#define QSPI_IFR_TFRTYP_MASK GENMASK(13, 12) | |
| 129 | −#define QSPI_IFR_TFRTYP_TRSFR_READ (0 << 12) | |
| 130 | −#define QSPI_IFR_TFRTYP_TRSFR_READ_MEM (1 << 12) | |
| 131 | −#define QSPI_IFR_TFRTYP_TRSFR_WRITE (2 << 12) | |
| 132 | −#define QSPI_IFR_TFRTYP_TRSFR_WRITE_MEM (3 << 13) | |
| 119 | +#define QSPI_IFR_TFRTYP_MEM BIT(12) | |
| 120 | +#define QSPI_IFR_SAMA5D2_WRITE_TRSFR BIT(13) | |
| 133 | 121 | #define QSPI_IFR_CRM BIT(14) |
| 134 | 122 | #define QSPI_IFR_NBDUM_MASK GENMASK(20, 16) |
| 135 | 123 | #define QSPI_IFR_NBDUM(n) (((n) << 16) & QSPI_IFR_NBDUM_MASK) |
| 124 | +#define QSPI_IFR_APBTFRTYP_READ BIT(24) /* Defined in SAM9X60 */ | |
| 136 | 125 | |
| 137 | 126 | /* Bitfields in QSPI_SMR (Scrambling Mode Register) */ |
| 138 | 127 | #define QSPI_SMR_SCREN BIT(0) |
| @@ -148,24 +137,31 @@ · 9 unmodified lines | ||
| 148 | 137 | #define QSPI_WPSR_WPVSRC_MASK GENMASK(15, 8) |
| 149 | 138 | #define QSPI_WPSR_WPVSRC(src) (((src) << 8) & QSPI_WPSR_WPVSRC) |
| 150 | 139 | |
| 140 | +struct atmel_qspi_caps { | |
| 141 | + bool has_qspick; | |
| 142 | + bool has_ricr; | |
| 143 | +}; | |
| 151 | 144 | |
| 152 | 145 | struct atmel_qspi { |
| 153 | 146 | void __iomem *regs; |
| 154 | 147 | void __iomem *mem; |
| 155 | − struct clk *clk; | |
| 148 | + struct clk *pclk; | |
| 149 | + struct clk *qspick; | |
| 156 | 150 | struct platform_device *pdev; |
| 151 | + const struct atmel_qspi_caps *caps; | |
| 157 | 152 | u32 pending; |
| 153 | + u32 mr; | |
| 158 | 154 | struct completion cmd_completion; |
| 159 | 155 | }; |
| 160 | 156 | |
| 161 | −struct qspi_mode { | |
| 157 | +struct atmel_qspi_mode { | |
| 162 | 158 | u8 cmd_buswidth; |
| 163 | 159 | u8 addr_buswidth; |
| 164 | 160 | u8 data_buswidth; |
| 165 | 161 | u32 config; |
| 166 | 162 | }; |
| 167 | 163 | |
| 168 | −static const struct qspi_mode sama5d2_qspi_modes[] = { | |
| 164 | +static const struct atmel_qspi_mode atmel_qspi_modes[] = { | |
| 169 | 165 | { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI }, |
| 170 | 166 | { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT }, |
| 171 | 167 | { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT }, |
| @@ -175,19 +171,8 @@ static const struct qspi_mode sama5d2_qspi_modes[] = { · 3 unmodified lines | ||
| 175 | 171 | { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD }, |
| 176 | 172 | }; |
| 177 | 173 | |
| 178 | −/* Register access functions */ | |
| 179 | −static inline u32 qspi_readl(struct atmel_qspi *aq, u32 reg) | |
| 180 | −{ | |
| 181 | − return readl_relaxed(aq->regs + reg); | |
| 182 | −} | |
| 183 | − | |
| 184 | −static inline void qspi_writel(struct atmel_qspi *aq, u32 reg, u32 value) | |
| 185 | −{ | |
| 186 | − writel_relaxed(value, aq->regs + reg); | |
| 187 | −} | |
| 188 | − | |
| 189 | −static inline bool is_compatible(const struct spi_mem_op *op, | |
| 190 | − const struct qspi_mode *mode) | |
| 174 | +static inline bool atmel_qspi_is_compatible(const struct spi_mem_op *op, | |
| 175 | + const struct atmel_qspi_mode *mode) | |
| 191 | 176 | { |
| 192 | 177 | if (op->cmd.buswidth != mode->cmd_buswidth) |
| 193 | 178 | return false; |
| @@ -201,21 +186,21 @@ static inline bool is_compatible(const struct spi_mem_op *op, · 7 unmodified lines | ||
| 201 | 186 | return true; |
| 202 | 187 | } |
| 203 | 188 | |
| 204 | −static int find_mode(const struct spi_mem_op *op) | |
| 189 | +static int atmel_qspi_find_mode(const struct spi_mem_op *op) | |
| 205 | 190 | { |
| 206 | 191 | u32 i; |
| 207 | 192 | |
| 208 | − for (i = 0; i < ARRAY_SIZE(sama5d2_qspi_modes); i++) | |
| 209 | − if (is_compatible(op, &sama5d2_qspi_modes[i])) | |
| 193 | + for (i = 0; i < ARRAY_SIZE(atmel_qspi_modes); i++) | |
| 194 | + if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i])) | |
| 210 | 195 | return i; |
| 211 | 196 | |
| 212 | − return -1; | |
| 197 | + return -ENOTSUPP; | |
| 213 | 198 | } |
| 214 | 199 | |
| 215 | 200 | static bool atmel_qspi_supports_op(struct spi_mem *mem, |
| 216 | 201 | const struct spi_mem_op *op) |
| 217 | 202 | { |
| 218 | − if (find_mode(op) < 0) | |
| 203 | + if (atmel_qspi_find_mode(op) < 0) | |
| 219 | 204 | return false; |
| 220 | 205 | |
| 221 | 206 | /* special case not supported by hardware */ |
| @@ -226,29 +211,37 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem, · 4 unmodified lines | ||
| 226 | 211 | return true; |
| 227 | 212 | } |
| 228 | 213 | |
| 229 | −static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) | |
| 214 | +static int atmel_qspi_set_cfg(struct atmel_qspi *aq, | |
| 215 | + const struct spi_mem_op *op, u32 *offset) | |
| 230 | 216 | { |
| 231 | − struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master); | |
| 232 | − int mode; | |
| 217 | + u32 iar, icr, ifr; | |
| 233 | 218 | u32 dummy_cycles = 0; |
| 234 | − u32 iar, icr, ifr, sr; | |
| 235 | − int err = 0; | |
| 219 | + int mode; | |
| 236 | 220 | |
| 237 | 221 | iar = 0; |
| 238 | 222 | icr = QSPI_ICR_INST(op->cmd.opcode); |
| 239 | 223 | ifr = QSPI_IFR_INSTEN; |
| 240 | 224 | |
| 241 | − qspi_writel(aq, QSPI_MR, QSPI_MR_SMM); | |
| 242 | − | |
| 243 | − mode = find_mode(op); | |
| 225 | + mode = atmel_qspi_find_mode(op); | |
| 244 | 226 | if (mode < 0) |
| 245 | − return -ENOTSUPP; | |
| 246 | − | |
| 247 | − ifr |= sama5d2_qspi_modes[mode].config; | |
| 227 | + return mode; | |
| 228 | + ifr |= atmel_qspi_modes[mode].config; | |
| 248 | 229 | |
| 249 | 230 | if (op->dummy.buswidth && op->dummy.nbytes) |
| 250 | 231 | dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth; |
| 251 | 232 | |
| 233 | + /* | |
| 234 | + * The controller allows 24 and 32-bit addressing while NAND-flash | |
| 235 | + * requires 16-bit long. Handling 8-bit long addresses is done using | |
| 236 | + * the option field. For the 16-bit addresses, the workaround depends | |
| 237 | + * of the number of requested dummy bits. If there are 8 or more dummy | |
| 238 | + * cycles, the address is shifted and sent with the first dummy byte. | |
| 239 | + * Otherwise opcode is disabled and the first byte of the address | |
| 240 | + * contains the command opcode (works only if the opcode and address | |
| 241 | + * use the same buswidth). The limitation is when the 16-bit address is | |
| 242 | + * used without enough dummy cycles and the opcode is using a different | |
| 243 | + * buswidth than the address. | |
| 244 | + */ | |
| 252 | 245 | if (op->addr.buswidth) { |
| 253 | 246 | switch (op->addr.nbytes) { |
| 254 | 247 | case 0: |
| @@ -282,6 +275,9 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) · 27 unmodified lines | ||
| 282 | 275 | } |
| 283 | 276 | } |
| 284 | 277 | |
| 278 | + /* offset of the data access in the QSPI memory space */ | |
| 279 | + *offset = iar; | |
| 280 | + | |
| 285 | 281 | /* Set number of dummy cycles */ |
| 286 | 282 | if (dummy_cycles) |
| 287 | 283 | ifr |= QSPI_IFR_NBDUM(dummy_cycles); |
| @@ -290,49 +286,82 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) · 2 unmodified lines | ||
| 290 | 286 | if (op->data.nbytes) |
| 291 | 287 | ifr |= QSPI_IFR_DATAEN; |
| 292 | 288 | |
| 293 | − if (op->data.dir == SPI_MEM_DATA_IN && op->data.nbytes) | |
| 294 | − ifr |= QSPI_IFR_TFRTYP_TRSFR_READ; | |
| 295 | − else | |
| 296 | − ifr |= QSPI_IFR_TFRTYP_TRSFR_WRITE; | |
| 289 | + /* | |
| 290 | + * If the QSPI controller is set in regular SPI mode, set it in | |
| 291 | + * Serial Memory Mode (SMM). | |
| 292 | + */ | |
| 293 | + if (aq->mr != QSPI_MR_SMM) { | |
| 294 | + writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR); | |
| 295 | + aq->mr = QSPI_MR_SMM; | |
| 296 | + } | |
| 297 | 297 | |
| 298 | 298 | /* Clear pending interrupts */ |
| 299 | − (void)qspi_readl(aq, QSPI_SR); | |
| 299 | + (void)readl_relaxed(aq->regs + QSPI_SR); | |
| 300 | + | |
| 301 | + if (aq->caps->has_ricr) { | |
| 302 | + if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN) | |
| 303 | + ifr |= QSPI_IFR_APBTFRTYP_READ; | |
| 300 | 304 | |
| 301 | − /* Set QSPI Instruction Frame registers */ | |
| 302 | − qspi_writel(aq, QSPI_IAR, iar); | |
| 303 | − qspi_writel(aq, QSPI_ICR, icr); | |
| 304 | − qspi_writel(aq, QSPI_IFR, ifr); | |
| 305 | + /* Set QSPI Instruction Frame registers */ | |
| 306 | + writel_relaxed(iar, aq->regs + QSPI_IAR); | |
| 307 | + if (op->data.dir == SPI_MEM_DATA_IN) | |
| 308 | + writel_relaxed(icr, aq->regs + QSPI_RICR); | |
| 309 | + else | |
| 310 | + writel_relaxed(icr, aq->regs + QSPI_WICR); | |
| 311 | + writel_relaxed(ifr, aq->regs + QSPI_IFR); | |
| 312 | + } else { | |
| 313 | + if (op->data.dir == SPI_MEM_DATA_OUT) | |
| 314 | + ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR; | |
| 315 | + | |
| 316 | + /* Set QSPI Instruction Frame registers */ | |
| 317 | + writel_relaxed(iar, aq->regs + QSPI_IAR); | |
| 318 | + writel_relaxed(icr, aq->regs + QSPI_ICR); | |
| 319 | + writel_relaxed(ifr, aq->regs + QSPI_IFR); | |
| 320 | + } | |
| 321 | + | |
| 322 | + return 0; | |
| 323 | +} | |
| 324 | + | |
| 325 | +static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) | |
| 326 | +{ | |
| 327 | + struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master); | |
| 328 | + u32 sr, offset; | |
| 329 | + int err; | |
| 330 | + | |
| 331 | + err = atmel_qspi_set_cfg(aq, op, &offset); | |
| 332 | + if (err) | |
| 333 | + return err; | |
| 305 | 334 | |
| 306 | 335 | /* Skip to the final steps if there is no data */ |
| 307 | 336 | if (op->data.nbytes) { |
| 308 | 337 | /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */ |
| 309 | − (void)qspi_readl(aq, QSPI_IFR); | |
| 338 | + (void)readl_relaxed(aq->regs + QSPI_IFR); | |
| 310 | 339 | |
| 311 | 340 | /* Send/Receive data */ |
| 312 | 341 | if (op->data.dir == SPI_MEM_DATA_IN) |
| 313 | − _memcpy_fromio(op->data.buf.in, | |
| 314 | − aq->mem + iar, op->data.nbytes); | |
| 342 | + _memcpy_fromio(op->data.buf.in, aq->mem + offset, | |
| 343 | + op->data.nbytes); | |
| 315 | 344 | else |
| 316 | − _memcpy_toio(aq->mem + iar, | |
| 317 | − op->data.buf.out, op->data.nbytes); | |
| 345 | + _memcpy_toio(aq->mem + offset, op->data.buf.out, | |
| 346 | + op->data.nbytes); | |
| 318 | 347 | |
| 319 | 348 | /* Release the chip-select */ |
| 320 | − qspi_writel(aq, QSPI_CR, QSPI_CR_LASTXFER); | |
| 349 | + writel_relaxed(QSPI_CR_LASTXFER, aq->regs + QSPI_CR); | |
| 321 | 350 | } |
| 322 | 351 | |
| 323 | 352 | /* Poll INSTRuction End status */ |
| 324 | − sr = qspi_readl(aq, QSPI_SR); | |
| 353 | + sr = readl_relaxed(aq->regs + QSPI_SR); | |
| 325 | 354 | if ((sr & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED) |
| 326 | 355 | return err; |
| 327 | 356 | |
| 328 | 357 | /* Wait for INSTRuction End interrupt */ |
| 329 | 358 | reinit_completion(&aq->cmd_completion); |
| 330 | 359 | aq->pending = sr & QSPI_SR_CMD_COMPLETED; |
| 331 | − qspi_writel(aq, QSPI_IER, QSPI_SR_CMD_COMPLETED); | |
| 360 | + writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IER); | |
| 332 | 361 | if (!wait_for_completion_timeout(&aq->cmd_completion, |
| 333 | 362 | msecs_to_jiffies(1000))) |
| 334 | 363 | err = -ETIMEDOUT; |
| 335 | − qspi_writel(aq, QSPI_IDR, QSPI_SR_CMD_COMPLETED); | |
| 364 | + writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IDR); | |
| 336 | 365 | |
| 337 | 366 | return err; |
| 338 | 367 | } |
| @@ -361,7 +390,7 @@ static int atmel_qspi_setup(struct spi_device *spi) · 22 unmodified lines | ||
| 361 | 390 | if (!spi->max_speed_hz) |
| 362 | 391 | return -EINVAL; |
| 363 | 392 | |
| 364 | − src_rate = clk_get_rate(aq->clk); | |
| 393 | + src_rate = clk_get_rate(aq->pclk); | |
| 365 | 394 | if (!src_rate) |
| 366 | 395 | return -EINVAL; |
| 367 | 396 | |
| @@ -371,7 +400,7 @@ static int atmel_qspi_setup(struct spi_device *spi) · 3 unmodified lines | ||
| 371 | 400 | scbr--; |
| 372 | 401 | |
| 373 | 402 | scr = QSPI_SCR_SCBR(scbr); |
| 374 | − qspi_writel(aq, QSPI_SCR, scr); | |
| 403 | + writel_relaxed(scr, aq->regs + QSPI_SCR); | |
| 375 | 404 | |
| 376 | 405 | return 0; |
| 377 | 406 | } |
| @@ -379,21 +408,25 @@ static int atmel_qspi_setup(struct spi_device *spi) · 1 unmodified line | ||
| 379 | 408 | static int atmel_qspi_init(struct atmel_qspi *aq) |
| 380 | 409 | { |
| 381 | 410 | /* Reset the QSPI controller */ |
| 382 | − qspi_writel(aq, QSPI_CR, QSPI_CR_SWRST); | |
| 411 | + writel_relaxed(QSPI_CR_SWRST, aq->regs + QSPI_CR); | |
| 412 | + | |
| 413 | + /* Set the QSPI controller by default in Serial Memory Mode */ | |
| 414 | + writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR); | |
| 415 | + aq->mr = QSPI_MR_SMM; | |
| 383 | 416 | |
| 384 | 417 | /* Enable the QSPI controller */ |
| 385 | − qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIEN); | |
| 418 | + writel_relaxed(QSPI_CR_QSPIEN, aq->regs + QSPI_CR); | |
| 386 | 419 | |
| 387 | 420 | return 0; |
| 388 | 421 | } |
| 389 | 422 | |
| 390 | 423 | static irqreturn_t atmel_qspi_interrupt(int irq, void *dev_id) |
| 391 | 424 | { |
| 392 | − struct atmel_qspi *aq = (struct atmel_qspi *)dev_id; | |
| 425 | + struct atmel_qspi *aq = dev_id; | |
| 393 | 426 | u32 status, mask, pending; |
| 394 | 427 | |
| 395 | − status = qspi_readl(aq, QSPI_SR); | |
| 396 | − mask = qspi_readl(aq, QSPI_IMR); | |
| 428 | + status = readl_relaxed(aq->regs + QSPI_SR); | |
| 429 | + mask = readl_relaxed(aq->regs + QSPI_IMR); | |
| 397 | 430 | pending = status & mask; |
| 398 | 431 | |
| 399 | 432 | if (!pending) |
| @@ -449,44 +482,74 @@ static int atmel_qspi_probe(struct platform_device *pdev) · 49 unmodified lines | ||
| 449 | 482 | } |
| 450 | 483 | |
| 451 | 484 | /* Get the peripheral clock */ |
| 452 | − aq->clk = devm_clk_get(&pdev->dev, NULL); | |
| 453 | − if (IS_ERR(aq->clk)) { | |
| 485 | + aq->pclk = devm_clk_get(&pdev->dev, "pclk"); | |
| 486 | + if (IS_ERR(aq->pclk)) | |
| 487 | + aq->pclk = devm_clk_get(&pdev->dev, NULL); | |
| 488 | + | |
| 489 | + if (IS_ERR(aq->pclk)) { | |
| 454 | 490 | dev_err(&pdev->dev, "missing peripheral clock\n"); |
| 455 | − err = PTR_ERR(aq->clk); | |
| 491 | + err = PTR_ERR(aq->pclk); | |
| 456 | 492 | goto exit; |
| 457 | 493 | } |
| 458 | 494 | |
| 459 | 495 | /* Enable the peripheral clock */ |
| 460 | − err = clk_prepare_enable(aq->clk); | |
| 496 | + err = clk_prepare_enable(aq->pclk); | |
| 461 | 497 | if (err) { |
| 462 | 498 | dev_err(&pdev->dev, "failed to enable the peripheral clock\n"); |
| 463 | 499 | goto exit; |
| 464 | 500 | } |
| 465 | 501 | |
| 502 | + aq->caps = of_device_get_match_data(&pdev->dev); | |
| 503 | + if (!aq->caps) { | |
| 504 | + dev_err(&pdev->dev, "Could not retrieve QSPI caps\n"); | |
| 505 | + err = -EINVAL; | |
| 506 | + goto exit; | |
| 507 | + } | |
| 508 | + | |
| 509 | + if (aq->caps->has_qspick) { | |
| 510 | + /* Get the QSPI system clock */ | |
| 511 | + aq->qspick = devm_clk_get(&pdev->dev, "qspick"); | |
| 512 | + if (IS_ERR(aq->qspick)) { | |
| 513 | + dev_err(&pdev->dev, "missing system clock\n"); | |
| 514 | + err = PTR_ERR(aq->qspick); | |
| 515 | + goto disable_pclk; | |
| 516 | + } | |
| 517 | + | |
| 518 | + /* Enable the QSPI system clock */ | |
| 519 | + err = clk_prepare_enable(aq->qspick); | |
| 520 | + if (err) { | |
| 521 | + dev_err(&pdev->dev, | |
| 522 | + "failed to enable the QSPI system clock\n"); | |
| 523 | + goto disable_pclk; | |
| 524 | + } | |
| 525 | + } | |
| 526 | + | |
| 466 | 527 | /* Request the IRQ */ |
| 467 | 528 | irq = platform_get_irq(pdev, 0); |
| 468 | 529 | if (irq < 0) { |
| 469 | 530 | dev_err(&pdev->dev, "missing IRQ\n"); |
| 470 | 531 | err = irq; |
| 471 | − goto disable_clk; | |
| 532 | + goto disable_qspick; | |
| 472 | 533 | } |
| 473 | 534 | err = devm_request_irq(&pdev->dev, irq, atmel_qspi_interrupt, |
| 474 | 535 | 0, dev_name(&pdev->dev), aq); |
| 475 | 536 | if (err) |
| 476 | − goto disable_clk; | |
| 537 | + goto disable_qspick; | |
| 477 | 538 | |
| 478 | 539 | err = atmel_qspi_init(aq); |
| 479 | 540 | if (err) |
| 480 | − goto disable_clk; | |
| 541 | + goto disable_qspick; | |
| 481 | 542 | |
| 482 | 543 | err = spi_register_controller(ctrl); |
| 483 | 544 | if (err) |
| 484 | − goto disable_clk; | |
| 545 | + goto disable_qspick; | |
| 485 | 546 | |
| 486 | 547 | return 0; |
| 487 | 548 | |
| 488 | −disable_clk: | |
| 489 | − clk_disable_unprepare(aq->clk); | |
| 549 | +disable_qspick: | |
| 550 | + clk_disable_unprepare(aq->qspick); | |
| 551 | +disable_pclk: | |
| 552 | + clk_disable_unprepare(aq->pclk); | |
| 490 | 553 | exit: |
| 491 | 554 | spi_controller_put(ctrl); |
| 492 | 555 | |
| @@ -499,8 +562,9 @@ static int atmel_qspi_remove(struct platform_device *pdev) · 6 unmodified lines | ||
| 499 | 562 | struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); |
| 500 | 563 | |
| 501 | 564 | spi_unregister_controller(ctrl); |
| 502 | − qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIDIS); | |
| 503 | − clk_disable_unprepare(aq->clk); | |
| 565 | + writel_relaxed(QSPI_CR_QSPIDIS, aq->regs + QSPI_CR); | |
| 566 | + clk_disable_unprepare(aq->qspick); | |
| 567 | + clk_disable_unprepare(aq->pclk); | |
| 504 | 568 | return 0; |
| 505 | 569 | } |
| 506 | 570 | |
| @@ -508,7 +572,8 @@ static int __maybe_unused atmel_qspi_suspend(struct device *dev) · 1 unmodified line | ||
| 508 | 572 | { |
| 509 | 573 | struct atmel_qspi *aq = dev_get_drvdata(dev); |
| 510 | 574 | |
| 511 | − clk_disable_unprepare(aq->clk); | |
| 575 | + clk_disable_unprepare(aq->qspick); | |
| 576 | + clk_disable_unprepare(aq->pclk); | |
| 512 | 577 | |
| 513 | 578 | return 0; |
| 514 | 579 | } |
| @@ -517,7 +582,8 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev) · 2 unmodified lines | ||
| 517 | 582 | { |
| 518 | 583 | struct atmel_qspi *aq = dev_get_drvdata(dev); |
| 519 | 584 | |
| 520 | − clk_prepare_enable(aq->clk); | |
| 585 | + clk_prepare_enable(aq->pclk); | |
| 586 | + clk_prepare_enable(aq->qspick); | |
| 521 | 587 | |
| 522 | 588 | return atmel_qspi_init(aq); |
| 523 | 589 | } |
| @@ -525,8 +591,22 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev) · 1 unmodified line | ||
| 525 | 591 | static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend, |
| 526 | 592 | atmel_qspi_resume); |
| 527 | 593 | |
| 594 | +static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {}; | |
| 595 | + | |
| 596 | +static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = { | |
| 597 | + .has_qspick = true, | |
| 598 | + .has_ricr = true, | |
| 599 | +}; | |
| 600 | + | |
| 528 | 601 | static const struct of_device_id atmel_qspi_dt_ids[] = { |
| 529 | − { .compatible = "atmel,sama5d2-qspi" }, | |
| 602 | + { | |
| 603 | + .compatible = "atmel,sama5d2-qspi", | |
| 604 | + .data = &atmel_sama5d2_qspi_caps, | |
| 605 | + }, | |
| 606 | + { | |
| 607 | + .compatible = "microchip,sam9x60-qspi", | |
| 608 | + .data = &atmel_sam9x60_qspi_caps, | |
| 609 | + }, | |
| 530 | 610 | { /* sentinel */ } |
| 531 | 611 | }; |
| 532 | 612 | |
| @@ -21,18 +21,26 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <linux/spi/spi.h> |
| 22 | 22 | #include <linux/spi/spi_bitbang.h> |
| 23 | 23 | #include <linux/bitops.h> |
| 24 | −#include <linux/gpio.h> | |
| 25 | 24 | #include <linux/clk.h> |
| 26 | 25 | #include <linux/err.h> |
| 27 | − | |
| 28 | −#include <asm/mach-ath79/ar71xx_regs.h> | |
| 29 | −#include <asm/mach-ath79/ath79_spi_platform.h> | |
| 26 | +#include <linux/platform_data/spi-ath79.h> | |
| 30 | 27 | |
| 31 | 28 | #define DRV_NAME "ath79-spi" |
| 32 | 29 | |
| 33 | 30 | #define ATH79_SPI_RRW_DELAY_FACTOR 12000 |
| 34 | 31 | #define MHZ (1000 * 1000) |
| 35 | 32 | |
| 33 | +#define AR71XX_SPI_REG_FS 0x00 /* Function Select */ | |
| 34 | +#define AR71XX_SPI_REG_CTRL 0x04 /* SPI Control */ | |
| 35 | +#define AR71XX_SPI_REG_IOC 0x08 /* SPI I/O Control */ | |
| 36 | +#define AR71XX_SPI_REG_RDS 0x0c /* Read Data Shift */ | |
| 37 | + | |
| 38 | +#define AR71XX_SPI_FS_GPIO BIT(0) /* Enable GPIO mode */ | |
| 39 | + | |
| 40 | +#define AR71XX_SPI_IOC_DO BIT(0) /* Data Out pin */ | |
| 41 | +#define AR71XX_SPI_IOC_CLK BIT(8) /* CLK pin */ | |
| 42 | +#define AR71XX_SPI_IOC_CS(n) BIT(16 + (n)) | |
| 43 | + | |
| 36 | 44 | struct ath79_spi { |
| 37 | 45 | struct spi_bitbang bitbang; |
| 38 | 46 | u32 ioc_base; |
| @@ -67,31 +75,14 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active) · 28 unmodified lines | ||
| 67 | 75 | { |
| 68 | 76 | struct ath79_spi *sp = ath79_spidev_to_sp(spi); |
| 69 | 77 | int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active; |
| 78 | + u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); | |
| 70 | 79 | |
| 71 | − if (is_active) { | |
| 72 | − /* set initial clock polarity */ | |
| 73 | − if (spi->mode & SPI_CPOL) | |
| 74 | − sp->ioc_base |= AR71XX_SPI_IOC_CLK; | |
| 75 | − else | |
| 76 | − sp->ioc_base &= ~AR71XX_SPI_IOC_CLK; | |
| 77 | − | |
| 78 | − ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); | |
| 79 | − } | |
| 80 | − | |
| 81 | − if (gpio_is_valid(spi->cs_gpio)) { | |
| 82 | − /* SPI is normally active-low */ | |
| 83 | − gpio_set_value_cansleep(spi->cs_gpio, cs_high); | |
| 84 | − } else { | |
| 85 | − u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); | |
| 86 | − | |
| 87 | − if (cs_high) | |
| 88 | − sp->ioc_base |= cs_bit; | |
| 89 | − else | |
| 90 | − sp->ioc_base &= ~cs_bit; | |
| 91 | − | |
| 92 | − ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); | |
| 93 | − } | |
| 80 | + if (cs_high) | |
| 81 | + sp->ioc_base |= cs_bit; | |
| 82 | + else | |
| 83 | + sp->ioc_base &= ~cs_bit; | |
| 94 | 84 | |
| 85 | + ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); | |
| 95 | 86 | } |
| 96 | 87 | |
| 97 | 88 | static void ath79_spi_enable(struct ath79_spi *sp) |
| @@ -103,6 +94,9 @@ static void ath79_spi_enable(struct ath79_spi *sp) · 5 unmodified lines | ||
| 103 | 94 | sp->reg_ctrl = ath79_spi_rr(sp, AR71XX_SPI_REG_CTRL); |
| 104 | 95 | sp->ioc_base = ath79_spi_rr(sp, AR71XX_SPI_REG_IOC); |
| 105 | 96 | |
| 97 | + /* clear clk and mosi in the base state */ | |
| 98 | + sp->ioc_base &= ~(AR71XX_SPI_IOC_DO | AR71XX_SPI_IOC_CLK); | |
| 99 | + | |
| 106 | 100 | /* TODO: setup speed? */ |
| 107 | 101 | ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43); |
| 108 | 102 | } |
| @@ -115,66 +109,6 @@ static void ath79_spi_disable(struct ath79_spi *sp) · 6 unmodified lines | ||
| 115 | 109 | ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0); |
| 116 | 110 | } |
| 117 | 111 | |
| 118 | −static int ath79_spi_setup_cs(struct spi_device *spi) | |
| 119 | −{ | |
| 120 | − struct ath79_spi *sp = ath79_spidev_to_sp(spi); | |
| 121 | − int status; | |
| 122 | − | |
| 123 | − status = 0; | |
| 124 | − if (gpio_is_valid(spi->cs_gpio)) { | |
| 125 | − unsigned long flags; | |
| 126 | − | |
| 127 | − flags = GPIOF_DIR_OUT; | |
| 128 | − if (spi->mode & SPI_CS_HIGH) | |
| 129 | − flags |= GPIOF_INIT_LOW; | |
| 130 | − else | |
| 131 | − flags |= GPIOF_INIT_HIGH; | |
| 132 | − | |
| 133 | − status = gpio_request_one(spi->cs_gpio, flags, | |
| 134 | − dev_name(&spi->dev)); | |
| 135 | − } else { | |
| 136 | − u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select); | |
| 137 | − | |
| 138 | − if (spi->mode & SPI_CS_HIGH) | |
| 139 | − sp->ioc_base &= ~cs_bit; | |
| 140 | − else | |
| 141 | − sp->ioc_base |= cs_bit; | |
| 142 | − | |
| 143 | − ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base); | |
| 144 | − } | |
| 145 | − | |
| 146 | − return status; | |
| 147 | −} | |
| 148 | − | |
| 149 | −static void ath79_spi_cleanup_cs(struct spi_device *spi) | |
| 150 | −{ | |
| 151 | − if (gpio_is_valid(spi->cs_gpio)) | |
| 152 | − gpio_free(spi->cs_gpio); | |
| 153 | −} | |
| 154 | − | |
| 155 | −static int ath79_spi_setup(struct spi_device *spi) | |
| 156 | −{ | |
| 157 | − int status = 0; | |
| 158 | − | |
| 159 | − if (!spi->controller_state) { | |
| 160 | − status = ath79_spi_setup_cs(spi); | |
| 161 | − if (status) | |
| 162 | − return status; | |
| 163 | − } | |
| 164 | − | |
| 165 | − status = spi_bitbang_setup(spi); | |
| 166 | − if (status && !spi->controller_state) | |
| 167 | − ath79_spi_cleanup_cs(spi); | |
| 168 | − | |
| 169 | − return status; | |
| 170 | −} | |
| 171 | − | |
| 172 | −static void ath79_spi_cleanup(struct spi_device *spi) | |
| 173 | −{ | |
| 174 | − ath79_spi_cleanup_cs(spi); | |
| 175 | − spi_bitbang_cleanup(spi); | |
| 176 | −} | |
| 177 | − | |
| 178 | 112 | static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs, |
| 179 | 113 | u32 word, u8 bits, unsigned flags) |
| 180 | 114 | { |
| @@ -225,9 +159,10 @@ static int ath79_spi_probe(struct platform_device *pdev) · 44 unmodified lines | ||
| 225 | 159 | |
| 226 | 160 | pdata = dev_get_platdata(&pdev->dev); |
| 227 | 161 | |
| 162 | + master->use_gpio_descriptors = true; | |
| 228 | 163 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); |
| 229 | − master->setup = ath79_spi_setup; | |
| 230 | − master->cleanup = ath79_spi_cleanup; | |
| 164 | + master->setup = spi_bitbang_setup; | |
| 165 | + master->cleanup = spi_bitbang_cleanup; | |
| 231 | 166 | if (pdata) { |
| 232 | 167 | master->bus_num = pdata->bus_num; |
| 233 | 168 | master->num_chipselect = pdata->num_chipselect; |
| @@ -236,7 +171,6 @@ static int ath79_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 236 | 171 | sp->bitbang.master = master; |
| 237 | 172 | sp->bitbang.chipselect = ath79_spi_chipselect; |
| 238 | 173 | sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0; |
| 239 | − sp->bitbang.setup_transfer = spi_bitbang_setup_transfer; | |
| 240 | 174 | sp->bitbang.flags = SPI_CS_HIGH; |
| 241 | 175 | |
| 242 | 176 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| @@ -23,8 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | #include <linux/of.h> |
| 24 | 24 | |
| 25 | 25 | #include <linux/io.h> |
| 26 | −#include <linux/gpio.h> | |
| 27 | −#include <linux/of_gpio.h> | |
| 26 | +#include <linux/gpio/consumer.h> | |
| 28 | 27 | #include <linux/pinctrl/consumer.h> |
| 29 | 28 | #include <linux/pm_runtime.h> |
| 30 | 29 | |
| @@ -312,7 +311,7 @@ struct atmel_spi { · 281 unmodified lines | ||
| 312 | 311 | |
| 313 | 312 | /* Controller-specific per-slave state */ |
| 314 | 313 | struct atmel_spi_device { |
| 315 | − unsigned int npcs_pin; | |
| 314 | + struct gpio_desc *npcs_pin; | |
| 316 | 315 | u32 csr; |
| 317 | 316 | }; |
| 318 | 317 | |
| @@ -355,7 +354,6 @@ static bool atmel_spi_is_v2(struct atmel_spi *as) · 36 unmodified lines | ||
| 355 | 354 | static void cs_activate(struct atmel_spi *as, struct spi_device *spi) |
| 356 | 355 | { |
| 357 | 356 | struct atmel_spi_device *asd = spi->controller_state; |
| 358 | − unsigned active = spi->mode & SPI_CS_HIGH; | |
| 359 | 357 | u32 mr; |
| 360 | 358 | |
| 361 | 359 | if (atmel_spi_is_v2(as)) { |
| @@ -379,7 +377,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) · 17 unmodified lines | ||
| 379 | 377 | |
| 380 | 378 | mr = spi_readl(as, MR); |
| 381 | 379 | if (as->use_cs_gpios) |
| 382 | − gpio_set_value(asd->npcs_pin, active); | |
| 380 | + gpiod_set_value(asd->npcs_pin, 1); | |
| 383 | 381 | } else { |
| 384 | 382 | u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0; |
| 385 | 383 | int i; |
| @@ -396,19 +394,16 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) · 10 unmodified lines | ||
| 396 | 394 | mr = spi_readl(as, MR); |
| 397 | 395 | mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr); |
| 398 | 396 | if (as->use_cs_gpios && spi->chip_select != 0) |
| 399 | − gpio_set_value(asd->npcs_pin, active); | |
| 397 | + gpiod_set_value(asd->npcs_pin, 1); | |
| 400 | 398 | spi_writel(as, MR, mr); |
| 401 | 399 | } |
| 402 | 400 | |
| 403 | − dev_dbg(&spi->dev, "activate %u%s, mr %08x\n", | |
| 404 | − asd->npcs_pin, active ? " (high)" : "", | |
| 405 | − mr); | |
| 401 | + dev_dbg(&spi->dev, "activate NPCS, mr %08x\n", mr); | |
| 406 | 402 | } |
| 407 | 403 | |
| 408 | 404 | static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi) |
| 409 | 405 | { |
| 410 | 406 | struct atmel_spi_device *asd = spi->controller_state; |
| 411 | − unsigned active = spi->mode & SPI_CS_HIGH; | |
| 412 | 407 | u32 mr; |
| 413 | 408 | |
| 414 | 409 | /* only deactivate *this* device; sometimes transfers to |
| @@ -420,14 +415,12 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi) · 5 unmodified lines | ||
| 420 | 415 | spi_writel(as, MR, mr); |
| 421 | 416 | } |
| 422 | 417 | |
| 423 | − dev_dbg(&spi->dev, "DEactivate %u%s, mr %08x\n", | |
| 424 | − asd->npcs_pin, active ? " (low)" : "", | |
| 425 | − mr); | |
| 418 | + dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr); | |
| 426 | 419 | |
| 427 | 420 | if (!as->use_cs_gpios) |
| 428 | 421 | spi_writel(as, CR, SPI_BIT(LASTXFER)); |
| 429 | 422 | else if (atmel_spi_is_v2(as) || spi->chip_select != 0) |
| 430 | − gpio_set_value(asd->npcs_pin, !active); | |
| 423 | + gpiod_set_value(asd->npcs_pin, 0); | |
| 431 | 424 | } |
| 432 | 425 | |
| 433 | 426 | static void atmel_spi_lock(struct atmel_spi *as) __acquires(&as->lock) |
| @@ -1188,7 +1181,6 @@ static int atmel_spi_setup(struct spi_device *spi) · 754 unmodified lines | ||
| 1188 | 1181 | struct atmel_spi_device *asd; |
| 1189 | 1182 | u32 csr; |
| 1190 | 1183 | unsigned int bits = spi->bits_per_word; |
| 1191 | − unsigned int npcs_pin; | |
| 1192 | 1184 | |
| 1193 | 1185 | as = spi_master_get_devdata(spi->master); |
| 1194 | 1186 | |
| @@ -1209,21 +1201,14 @@ static int atmel_spi_setup(struct spi_device *spi) · 14 unmodified lines | ||
| 1209 | 1201 | csr |= SPI_BIT(CSAAT); |
| 1210 | 1202 | |
| 1211 | 1203 | /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs. |
| 1212 | − * | |
| 1213 | − * DLYBCT would add delays between words, slowing down transfers. | |
| 1214 | − * It could potentially be useful to cope with DMA bottlenecks, but | |
| 1215 | − * in those cases it's probably best to just use a lower bitrate. | |
| 1216 | 1204 | */ |
| 1217 | 1205 | csr |= SPI_BF(DLYBS, 0); |
| 1218 | − csr |= SPI_BF(DLYBCT, 0); | |
| 1219 | − | |
| 1220 | − /* chipselect must have been muxed as GPIO (e.g. in board setup) */ | |
| 1221 | − npcs_pin = (unsigned long)spi->controller_data; | |
| 1222 | 1206 | |
| 1223 | − if (!as->use_cs_gpios) | |
| 1224 | − npcs_pin = spi->chip_select; | |
| 1225 | − else if (gpio_is_valid(spi->cs_gpio)) | |
| 1226 | − npcs_pin = spi->cs_gpio; | |
| 1207 | + /* DLYBCT adds delays between words. This is useful for slow devices | |
| 1208 | + * that need a bit of time to setup the next transfer. | |
| 1209 | + */ | |
| 1210 | + csr |= SPI_BF(DLYBCT, | |
| 1211 | + (as->spi_clk / 1000000 * spi->word_delay_usecs) >> 5); | |
| 1227 | 1212 | |
| 1228 | 1213 | asd = spi->controller_state; |
| 1229 | 1214 | if (!asd) { |
| @@ -1231,11 +1216,21 @@ static int atmel_spi_setup(struct spi_device *spi) · 1 unmodified line | ||
| 1231 | 1216 | if (!asd) |
| 1232 | 1217 | return -ENOMEM; |
| 1233 | 1218 | |
| 1234 | − if (as->use_cs_gpios) | |
| 1235 | − gpio_direction_output(npcs_pin, | |
| 1236 | − !(spi->mode & SPI_CS_HIGH)); | |
| 1219 | + /* | |
| 1220 | + * If use_cs_gpios is true this means that we have "cs-gpios" | |
| 1221 | + * defined in the device tree node so we should have | |
| 1222 | + * gotten the GPIO lines from the device tree inside the | |
| 1223 | + * SPI core. Warn if this is not the case but continue since | |
| 1224 | + * CS GPIOs are after all optional. | |
| 1225 | + */ | |
| 1226 | + if (as->use_cs_gpios) { | |
| 1227 | + if (!spi->cs_gpiod) { | |
| 1228 | + dev_err(&spi->dev, | |
| 1229 | + "host claims to use CS GPIOs but no CS found in DT by the SPI core\n"); | |
| 1230 | + } | |
| 1231 | + asd->npcs_pin = spi->cs_gpiod; | |
| 1232 | + } | |
| 1237 | 1233 | |
| 1238 | − asd->npcs_pin = npcs_pin; | |
| 1239 | 1234 | spi->controller_state = asd; |
| 1240 | 1235 | } |
| 1241 | 1236 | |
| @@ -1473,41 +1468,6 @@ static void atmel_get_caps(struct atmel_spi *as) · 231 unmodified lines | ||
| 1473 | 1468 | as->caps.has_pdc_support = version < 0x212; |
| 1474 | 1469 | } |
| 1475 | 1470 | |
| 1476 | −/*-------------------------------------------------------------------------*/ | |
| 1477 | −static int atmel_spi_gpio_cs(struct platform_device *pdev) | |
| 1478 | −{ | |
| 1479 | − struct spi_master *master = platform_get_drvdata(pdev); | |
| 1480 | − struct atmel_spi *as = spi_master_get_devdata(master); | |
| 1481 | − struct device_node *np = master->dev.of_node; | |
| 1482 | − int i; | |
| 1483 | − int ret = 0; | |
| 1484 | − int nb = 0; | |
| 1485 | − | |
| 1486 | − if (!as->use_cs_gpios) | |
| 1487 | − return 0; | |
| 1488 | − | |
| 1489 | − if (!np) | |
| 1490 | − return 0; | |
| 1491 | − | |
| 1492 | − nb = of_gpio_named_count(np, "cs-gpios"); | |
| 1493 | − for (i = 0; i < nb; i++) { | |
| 1494 | − int cs_gpio = of_get_named_gpio(pdev->dev.of_node, | |
| 1495 | − "cs-gpios", i); | |
| 1496 | − | |
| 1497 | − if (cs_gpio == -EPROBE_DEFER) | |
| 1498 | − return cs_gpio; | |
| 1499 | − | |
| 1500 | − if (gpio_is_valid(cs_gpio)) { | |
| 1501 | − ret = devm_gpio_request(&pdev->dev, cs_gpio, | |
| 1502 | − dev_name(&pdev->dev)); | |
| 1503 | − if (ret) | |
| 1504 | − return ret; | |
| 1505 | − } | |
| 1506 | − } | |
| 1507 | − | |
| 1508 | − return 0; | |
| 1509 | −} | |
| 1510 | − | |
| 1511 | 1471 | static void atmel_spi_init(struct atmel_spi *as) |
| 1512 | 1472 | { |
| 1513 | 1473 | spi_writel(as, CR, SPI_BIT(SWRST)); |
| @@ -1560,6 +1520,7 @@ static int atmel_spi_probe(struct platform_device *pdev) · 46 unmodified lines | ||
| 1560 | 1520 | goto out_free; |
| 1561 | 1521 | |
| 1562 | 1522 | /* the spi->mode bits understood by this driver: */ |
| 1523 | + master->use_gpio_descriptors = true; | |
| 1563 | 1524 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
| 1564 | 1525 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16); |
| 1565 | 1526 | master->dev.of_node = pdev->dev.of_node; |
| @@ -1592,6 +1553,11 @@ static int atmel_spi_probe(struct platform_device *pdev) · 26 unmodified lines | ||
| 1592 | 1553 | |
| 1593 | 1554 | atmel_get_caps(as); |
| 1594 | 1555 | |
| 1556 | + /* | |
| 1557 | + * If there are chip selects in the device tree, those will be | |
| 1558 | + * discovered by the SPI core when registering the SPI master | |
| 1559 | + * and assigned to each SPI device. | |
| 1560 | + */ | |
| 1595 | 1561 | as->use_cs_gpios = true; |
| 1596 | 1562 | if (atmel_spi_is_v2(as) && |
| 1597 | 1563 | pdev->dev.of_node && |
| @@ -1600,10 +1566,6 @@ static int atmel_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1600 | 1566 | master->num_chipselect = 4; |
| 1601 | 1567 | } |
| 1602 | 1568 | |
| 1603 | − ret = atmel_spi_gpio_cs(pdev); | |
| 1604 | − if (ret) | |
| 1605 | − goto out_unmap_regs; | |
| 1606 | − | |
| 1607 | 1569 | as->use_dma = false; |
| 1608 | 1570 | as->use_pdc = false; |
| 1609 | 1571 | if (as->caps.has_dma_support) { |
| @@ -456,7 +456,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) · 455 unmodified lines | ||
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | bs->clk = devm_clk_get(&pdev->dev, NULL); |
| 459 | − if ((!bs->clk) || (IS_ERR(bs->clk))) { | |
| 459 | + if (IS_ERR(bs->clk)) { | |
| 460 | 460 | err = PTR_ERR(bs->clk); |
| 461 | 461 | dev_err(&pdev->dev, "could not get clk: %d\n", err); |
| 462 | 462 | goto out_master_put; |
| @@ -213,19 +213,6 @@ int spi_bitbang_setup(struct spi_device *spi) · 212 unmodified lines | ||
| 213 | 213 | |
| 214 | 214 | dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); |
| 215 | 215 | |
| 216 | − /* NOTE we _need_ to call chipselect() early, ideally with adapter | |
| 217 | − * setup, unless the hardware defaults cooperate to avoid confusion | |
| 218 | − * between normal (active low) and inverted chipselects. | |
| 219 | − */ | |
| 220 | − | |
| 221 | − /* deselect chip (low or high) */ | |
| 222 | − mutex_lock(&bitbang->lock); | |
| 223 | − if (!bitbang->busy) { | |
| 224 | − bitbang->chipselect(spi, BITBANG_CS_INACTIVE); | |
| 225 | − ndelay(cs->nsecs); | |
| 226 | − } | |
| 227 | − mutex_unlock(&bitbang->lock); | |
| 228 | − | |
| 229 | 216 | return 0; |
| 230 | 217 | } |
| 231 | 218 | EXPORT_SYMBOL_GPL(spi_bitbang_setup); |
| @@ -13,7 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | #include <linux/clk.h> |
| 15 | 15 | #include <linux/delay.h> |
| 16 | −#include <linux/gpio.h> | |
| 16 | +#include <linux/gpio/consumer.h> | |
| 17 | 17 | #include <linux/interrupt.h> |
| 18 | 18 | #include <linux/io.h> |
| 19 | 19 | #include <linux/module.h> |
| @@ -128,10 +128,6 @@ struct cdns_spi { · 108 unmodified lines | ||
| 128 | 128 | u32 is_decoded_cs; |
| 129 | 129 | }; |
| 130 | 130 | |
| 131 | −struct cdns_spi_device_data { | |
| 132 | − bool gpio_requested; | |
| 133 | −}; | |
| 134 | − | |
| 135 | 131 | /* Macros for the SPI controller read/write */ |
| 136 | 132 | static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) |
| 137 | 133 | { |
| @@ -176,16 +172,16 @@ static void cdns_spi_init_hw(struct cdns_spi *xspi) · 38 unmodified lines | ||
| 176 | 172 | /** |
| 177 | 173 | * cdns_spi_chipselect - Select or deselect the chip select line |
| 178 | 174 | * @spi: Pointer to the spi_device structure |
| 179 | − * @is_high: Select(0) or deselect (1) the chip select line | |
| 175 | + * @enable: Select (1) or deselect (0) the chip select line | |
| 180 | 176 | */ |
| 181 | −static void cdns_spi_chipselect(struct spi_device *spi, bool is_high) | |
| 177 | +static void cdns_spi_chipselect(struct spi_device *spi, bool enable) | |
| 182 | 178 | { |
| 183 | 179 | struct cdns_spi *xspi = spi_master_get_devdata(spi->master); |
| 184 | 180 | u32 ctrl_reg; |
| 185 | 181 | |
| 186 | 182 | ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); |
| 187 | 183 | |
| 188 | − if (is_high) { | |
| 184 | + if (!enable) { | |
| 189 | 185 | /* Deselect the slave */ |
| 190 | 186 | ctrl_reg |= CDNS_SPI_CR_SSCTRL; |
| 191 | 187 | } else { |
| @@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master) · 277 unmodified lines | ||
| 469 | 465 | return 0; |
| 470 | 466 | } |
| 471 | 467 | |
| 472 | −static int cdns_spi_setup(struct spi_device *spi) | |
| 473 | −{ | |
| 474 | − | |
| 475 | − int ret = -EINVAL; | |
| 476 | − struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); | |
| 477 | − | |
| 478 | − /* this is a pin managed by the controller, leave it alone */ | |
| 479 | − if (spi->cs_gpio == -ENOENT) | |
| 480 | − return 0; | |
| 481 | − | |
| 482 | − /* this seems to be the first time we're here */ | |
| 483 | − if (!cdns_spi_data) { | |
| 484 | − cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL); | |
| 485 | − if (!cdns_spi_data) | |
| 486 | − return -ENOMEM; | |
| 487 | − cdns_spi_data->gpio_requested = false; | |
| 488 | − spi_set_ctldata(spi, cdns_spi_data); | |
| 489 | − } | |
| 490 | − | |
| 491 | − /* if we haven't done so, grab the gpio */ | |
| 492 | − if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) { | |
| 493 | − ret = gpio_request_one(spi->cs_gpio, | |
| 494 | − (spi->mode & SPI_CS_HIGH) ? | |
| 495 | − GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, | |
| 496 | − dev_name(&spi->dev)); | |
| 497 | − if (ret) | |
| 498 | − dev_err(&spi->dev, "can't request chipselect gpio %d\n", | |
| 499 | − spi->cs_gpio); | |
| 500 | − else | |
| 501 | − cdns_spi_data->gpio_requested = true; | |
| 502 | − } else { | |
| 503 | − if (gpio_is_valid(spi->cs_gpio)) { | |
| 504 | − int mode = ((spi->mode & SPI_CS_HIGH) ? | |
| 505 | − GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH); | |
| 506 | − | |
| 507 | − ret = gpio_direction_output(spi->cs_gpio, mode); | |
| 508 | − if (ret) | |
| 509 | − dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n", | |
| 510 | − spi->cs_gpio, ret); | |
| 511 | − } | |
| 512 | − } | |
| 513 | − | |
| 514 | − return ret; | |
| 515 | −} | |
| 516 | − | |
| 517 | −static void cdns_spi_cleanup(struct spi_device *spi) | |
| 518 | −{ | |
| 519 | − struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi); | |
| 520 | − | |
| 521 | − if (cdns_spi_data) { | |
| 522 | − if (cdns_spi_data->gpio_requested) | |
| 523 | − gpio_free(spi->cs_gpio); | |
| 524 | − kfree(cdns_spi_data); | |
| 525 | − spi_set_ctldata(spi, NULL); | |
| 526 | − } | |
| 527 | − | |
| 528 | −} | |
| 529 | − | |
| 530 | 468 | /** |
| 531 | 469 | * cdns_spi_probe - Probe method for the SPI driver |
| 532 | 470 | * @pdev: Pointer to the platform_device structure |
| @@ -584,11 +522,6 @@ static int cdns_spi_probe(struct platform_device *pdev) · 51 unmodified lines | ||
| 584 | 522 | goto clk_dis_apb; |
| 585 | 523 | } |
| 586 | 524 | |
| 587 | − pm_runtime_use_autosuspend(&pdev->dev); | |
| 588 | − pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); | |
| 589 | − pm_runtime_set_active(&pdev->dev); | |
| 590 | − pm_runtime_enable(&pdev->dev); | |
| 591 | − | |
| 592 | 525 | ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs); |
| 593 | 526 | if (ret < 0) |
| 594 | 527 | master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS; |
| @@ -603,8 +536,10 @@ static int cdns_spi_probe(struct platform_device *pdev) · 8 unmodified lines | ||
| 603 | 536 | /* SPI controller initializations */ |
| 604 | 537 | cdns_spi_init_hw(xspi); |
| 605 | 538 | |
| 606 | − pm_runtime_mark_last_busy(&pdev->dev); | |
| 607 | − pm_runtime_put_autosuspend(&pdev->dev); | |
| 539 | + pm_runtime_set_active(&pdev->dev); | |
| 540 | + pm_runtime_enable(&pdev->dev); | |
| 541 | + pm_runtime_use_autosuspend(&pdev->dev); | |
| 542 | + pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); | |
| 608 | 543 | |
| 609 | 544 | irq = platform_get_irq(pdev, 0); |
| 610 | 545 | if (irq <= 0) { |
| @@ -621,13 +556,12 @@ static int cdns_spi_probe(struct platform_device *pdev) · 10 unmodified lines | ||
| 621 | 556 | goto clk_dis_all; |
| 622 | 557 | } |
| 623 | 558 | |
| 559 | + master->use_gpio_descriptors = true; | |
| 624 | 560 | master->prepare_transfer_hardware = cdns_prepare_transfer_hardware; |
| 625 | 561 | master->prepare_message = cdns_prepare_message; |
| 626 | 562 | master->transfer_one = cdns_transfer_one; |
| 627 | 563 | master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware; |
| 628 | 564 | master->set_cs = cdns_spi_chipselect; |
| 629 | − master->setup = cdns_spi_setup; | |
| 630 | − master->cleanup = cdns_spi_cleanup; | |
| 631 | 565 | master->auto_runtime_pm = true; |
| 632 | 566 | master->mode_bits = SPI_CPOL | SPI_CPHA; |
| 633 | 567 | |
| @@ -11,7 +11,7 @@ · 10 unmodified lines | ||
| 11 | 11 | |
| 12 | 12 | #include <linux/io.h> |
| 13 | 13 | #include <linux/clk.h> |
| 14 | −#include <linux/gpio.h> | |
| 14 | +#include <linux/gpio/consumer.h> | |
| 15 | 15 | #include <linux/module.h> |
| 16 | 16 | #include <linux/interrupt.h> |
| 17 | 17 | #include <linux/platform_device.h> |
| @@ -36,25 +36,6 @@ struct spi_clps711x_data { · 18 unmodified lines | ||
| 36 | 36 | int len; |
| 37 | 37 | }; |
| 38 | 38 | |
| 39 | −static int spi_clps711x_setup(struct spi_device *spi) | |
| 40 | −{ | |
| 41 | − if (!spi->controller_state) { | |
| 42 | − int ret; | |
| 43 | − | |
| 44 | − ret = devm_gpio_request(&spi->master->dev, spi->cs_gpio, | |
| 45 | − dev_name(&spi->master->dev)); | |
| 46 | − if (ret) | |
| 47 | − return ret; | |
| 48 | − | |
| 49 | − spi->controller_state = spi; | |
| 50 | − } | |
| 51 | − | |
| 52 | − /* We are expect that SPI-device is not selected */ | |
| 53 | − gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); | |
| 54 | − | |
| 55 | − return 0; | |
| 56 | −} | |
| 57 | − | |
| 58 | 39 | static int spi_clps711x_prepare_message(struct spi_master *master, |
| 59 | 40 | struct spi_message *msg) |
| 60 | 41 | { |
| @@ -125,11 +106,11 @@ static int spi_clps711x_probe(struct platform_device *pdev) · 64 unmodified lines | ||
| 125 | 106 | if (!master) |
| 126 | 107 | return -ENOMEM; |
| 127 | 108 | |
| 109 | + master->use_gpio_descriptors = true; | |
| 128 | 110 | master->bus_num = -1; |
| 129 | 111 | master->mode_bits = SPI_CPHA | SPI_CS_HIGH; |
| 130 | 112 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8); |
| 131 | 113 | master->dev.of_node = pdev->dev.of_node; |
| 132 | − master->setup = spi_clps711x_setup; | |
| 133 | 114 | master->prepare_message = spi_clps711x_prepare_message; |
| 134 | 115 | master->transfer_one = spi_clps711x_transfer_one; |
| 135 | 116 | |
| @@ -15,7 +15,7 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | #include <linux/interrupt.h> |
| 17 | 17 | #include <linux/io.h> |
| 18 | −#include <linux/gpio.h> | |
| 18 | +#include <linux/gpio/consumer.h> | |
| 19 | 19 | #include <linux/module.h> |
| 20 | 20 | #include <linux/delay.h> |
| 21 | 21 | #include <linux/platform_device.h> |
| @@ -25,7 +25,6 @@ · 3 unmodified lines | ||
| 25 | 25 | #include <linux/dma-mapping.h> |
| 26 | 26 | #include <linux/of.h> |
| 27 | 27 | #include <linux/of_device.h> |
| 28 | −#include <linux/of_gpio.h> | |
| 29 | 28 | #include <linux/spi/spi.h> |
| 30 | 29 | #include <linux/spi/spi_bitbang.h> |
| 31 | 30 | #include <linux/slab.h> |
| @@ -222,12 +221,17 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value) · 190 unmodified lines | ||
| 222 | 221 | * Board specific chip select logic decides the polarity and cs |
| 223 | 222 | * line for the controller |
| 224 | 223 | */ |
| 225 | − if (spi->cs_gpio >= 0) { | |
| 224 | + if (spi->cs_gpiod) { | |
| 225 | + /* | |
| 226 | + * FIXME: is this code ever executed? This host does not | |
| 227 | + * set SPI_MASTER_GPIO_SS so this chipselect callback should | |
| 228 | + * not get called from the SPI core when we are using | |
| 229 | + * GPIOs for chip select. | |
| 230 | + */ | |
| 226 | 231 | if (value == BITBANG_CS_ACTIVE) |
| 227 | − gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH); | |
| 232 | + gpiod_set_value(spi->cs_gpiod, 1); | |
| 228 | 233 | else |
| 229 | − gpio_set_value(spi->cs_gpio, | |
| 230 | − !(spi->mode & SPI_CS_HIGH)); | |
| 234 | + gpiod_set_value(spi->cs_gpiod, 0); | |
| 231 | 235 | } else { |
| 232 | 236 | if (value == BITBANG_CS_ACTIVE) { |
| 233 | 237 | if (!(spi->mode & SPI_CS_WORD)) |
| @@ -418,30 +422,18 @@ static int davinci_spi_of_setup(struct spi_device *spi) · 184 unmodified lines | ||
| 418 | 422 | */ |
| 419 | 423 | static int davinci_spi_setup(struct spi_device *spi) |
| 420 | 424 | { |
| 421 | − int retval = 0; | |
| 422 | 425 | struct davinci_spi *dspi; |
| 423 | − struct spi_master *master = spi->master; | |
| 424 | 426 | struct device_node *np = spi->dev.of_node; |
| 425 | 427 | bool internal_cs = true; |
| 426 | 428 | |
| 427 | 429 | dspi = spi_master_get_devdata(spi->master); |
| 428 | 430 | |
| 429 | 431 | if (!(spi->mode & SPI_NO_CS)) { |
| 430 | − if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) { | |
| 431 | − retval = gpio_direction_output( | |
| 432 | − spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); | |
| 432 | + if (np && spi->cs_gpiod) | |
| 433 | 433 | internal_cs = false; |
| 434 | − } | |
| 435 | − | |
| 436 | − if (retval) { | |
| 437 | − dev_err(&spi->dev, "GPIO %d setup failed (%d)\n", | |
| 438 | − spi->cs_gpio, retval); | |
| 439 | − return retval; | |
| 440 | − } | |
| 441 | 434 | |
| 442 | − if (internal_cs) { | |
| 435 | + if (internal_cs) | |
| 443 | 436 | set_io_bits(dspi->base + SPIPC0, 1 << spi->chip_select); |
| 444 | − } | |
| 445 | 437 | } |
| 446 | 438 | |
| 447 | 439 | if (spi->mode & SPI_READY) |
| @@ -962,6 +954,7 @@ static int davinci_spi_probe(struct platform_device *pdev) · 514 unmodified lines | ||
| 962 | 954 | if (ret) |
| 963 | 955 | goto free_master; |
| 964 | 956 | |
| 957 | + master->use_gpio_descriptors = true; | |
| 965 | 958 | master->dev.of_node = pdev->dev.of_node; |
| 966 | 959 | master->bus_num = pdev->id; |
| 967 | 960 | master->num_chipselect = pdata->num_chipselect; |
| @@ -980,27 +973,6 @@ static int davinci_spi_probe(struct platform_device *pdev) · 12 unmodified lines | ||
| 980 | 973 | if (dspi->version == SPI_VERSION_2) |
| 981 | 974 | dspi->bitbang.flags |= SPI_READY; |
| 982 | 975 | |
| 983 | − if (pdev->dev.of_node) { | |
| 984 | − int i; | |
| 985 | − | |
| 986 | − for (i = 0; i < pdata->num_chipselect; i++) { | |
| 987 | − int cs_gpio = of_get_named_gpio(pdev->dev.of_node, | |
| 988 | − "cs-gpios", i); | |
| 989 | − | |
| 990 | − if (cs_gpio == -EPROBE_DEFER) { | |
| 991 | − ret = cs_gpio; | |
| 992 | − goto free_clk; | |
| 993 | − } | |
| 994 | − | |
| 995 | − if (gpio_is_valid(cs_gpio)) { | |
| 996 | − ret = devm_gpio_request(&pdev->dev, cs_gpio, | |
| 997 | − dev_name(&pdev->dev)); | |
| 998 | − if (ret) | |
| 999 | − goto free_clk; | |
| 1000 | − } | |
| 1001 | − } | |
| 1002 | − } | |
| 1003 | − | |
| 1004 | 976 | dspi->bitbang.txrx_bufs = davinci_spi_bufs; |
| 1005 | 977 | |
| 1006 | 978 | ret = davinci_spi_request_dma(dspi); |
| @@ -18,7 +18,6 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <linux/mfd/syscon.h> |
| 19 | 19 | #include <linux/module.h> |
| 20 | 20 | #include <linux/of.h> |
| 21 | −#include <linux/of_gpio.h> | |
| 22 | 21 | #include <linux/of_platform.h> |
| 23 | 22 | #include <linux/acpi.h> |
| 24 | 23 | #include <linux/property.h> |
| @@ -185,27 +184,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) · 160 unmodified lines | ||
| 185 | 184 | |
| 186 | 185 | dws->num_cs = num_cs; |
| 187 | 186 | |
| 188 | − if (pdev->dev.of_node) { | |
| 189 | − int i; | |
| 190 | − | |
| 191 | − for (i = 0; i < dws->num_cs; i++) { | |
| 192 | − int cs_gpio = of_get_named_gpio(pdev->dev.of_node, | |
| 193 | − "cs-gpios", i); | |
| 194 | − | |
| 195 | − if (cs_gpio == -EPROBE_DEFER) { | |
| 196 | − ret = cs_gpio; | |
| 197 | − goto out; | |
| 198 | − } | |
| 199 | − | |
| 200 | − if (gpio_is_valid(cs_gpio)) { | |
| 201 | − ret = devm_gpio_request(&pdev->dev, cs_gpio, | |
| 202 | − dev_name(&pdev->dev)); | |
| 203 | − if (ret) | |
| 204 | − goto out; | |
| 205 | − } | |
| 206 | − } | |
| 207 | − } | |
| 208 | − | |
| 209 | 187 | init_func = device_get_match_data(&pdev->dev); |
| 210 | 188 | if (init_func) { |
| 211 | 189 | ret = init_func(pdev, dwsmmio); |
| @@ -20,7 +20,6 @@ · 19 unmodified lines | ||
| 20 | 20 | #include <linux/delay.h> |
| 21 | 21 | #include <linux/slab.h> |
| 22 | 22 | #include <linux/spi/spi.h> |
| 23 | −#include <linux/gpio.h> | |
| 24 | 23 | |
| 25 | 24 | #include "spi-dw.h" |
| 26 | 25 | |
| @@ -54,41 +53,41 @@ static ssize_t dw_spi_show_regs(struct file *file, char __user *user_buf, · 27 unmodified lines | ||
| 54 | 53 | if (!buf) |
| 55 | 54 | return 0; |
| 56 | 55 | |
| 57 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 56 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 58 | 57 | "%s registers:\n", dev_name(&dws->master->dev)); |
| 59 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 58 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 60 | 59 | "=================================\n"); |
| 61 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 60 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 62 | 61 | "CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0)); |
| 63 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 62 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 64 | 63 | "CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1)); |
| 65 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 64 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 66 | 65 | "SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR)); |
| 67 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 66 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 68 | 67 | "SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER)); |
| 69 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 68 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 70 | 69 | "BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR)); |
| 71 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 70 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 72 | 71 | "TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR)); |
| 73 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 72 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 74 | 73 | "RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR)); |
| 75 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 74 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 76 | 75 | "TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR)); |
| 77 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 76 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 78 | 77 | "RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR)); |
| 79 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 78 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 80 | 79 | "SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR)); |
| 81 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 80 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 82 | 81 | "IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR)); |
| 83 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 82 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 84 | 83 | "ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR)); |
| 85 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 84 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 86 | 85 | "DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR)); |
| 87 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 86 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 88 | 87 | "DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR)); |
| 89 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 88 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 90 | 89 | "DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR)); |
| 91 | − len += snprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 90 | + len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len, | |
| 92 | 91 | "=================================\n"); |
| 93 | 92 | |
| 94 | 93 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, len); |
| @@ -138,11 +137,10 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable) · 43 unmodified lines | ||
| 138 | 137 | struct dw_spi *dws = spi_controller_get_devdata(spi->controller); |
| 139 | 138 | struct chip_data *chip = spi_get_ctldata(spi); |
| 140 | 139 | |
| 141 | − /* Chip select logic is inverted from spi_set_cs() */ | |
| 142 | 140 | if (chip && chip->cs_control) |
| 143 | − chip->cs_control(!enable); | |
| 141 | + chip->cs_control(enable); | |
| 144 | 142 | |
| 145 | − if (!enable) | |
| 143 | + if (enable) | |
| 146 | 144 | dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select)); |
| 147 | 145 | else if (dws->cs_override) |
| 148 | 146 | dw_writel(dws, DW_SPI_SER, 0); |
| @@ -317,7 +315,8 @@ static int dw_spi_transfer_one(struct spi_controller *master, · 168 unmodified lines | ||
| 317 | 315 | /* Default SPI mode is SCPOL = 0, SCPH = 0 */ |
| 318 | 316 | cr0 = (transfer->bits_per_word - 1) |
| 319 | 317 | | (chip->type << SPI_FRF_OFFSET) |
| 320 | − | (spi->mode << SPI_MODE_OFFSET) | |
| 318 | + | ((((spi->mode & SPI_CPOL) ? 1 : 0) << SPI_SCOL_OFFSET) | | |
| 319 | + (((spi->mode & SPI_CPHA) ? 1 : 0) << SPI_SCPH_OFFSET)) | |
| 321 | 320 | | (chip->tmode << SPI_TMOD_OFFSET); |
| 322 | 321 | |
| 323 | 322 | /* |
| @@ -397,7 +396,6 @@ static int dw_spi_setup(struct spi_device *spi) · 73 unmodified lines | ||
| 397 | 396 | { |
| 398 | 397 | struct dw_spi_chip *chip_info = NULL; |
| 399 | 398 | struct chip_data *chip; |
| 400 | − int ret; | |
| 401 | 399 | |
| 402 | 400 | /* Only alloc on first setup */ |
| 403 | 401 | chip = spi_get_ctldata(spi); |
| @@ -425,13 +423,6 @@ static int dw_spi_setup(struct spi_device *spi) · 21 unmodified lines | ||
| 425 | 423 | |
| 426 | 424 | chip->tmode = SPI_TMOD_TR; |
| 427 | 425 | |
| 428 | − if (gpio_is_valid(spi->cs_gpio)) { | |
| 429 | − ret = gpio_direction_output(spi->cs_gpio, | |
| 430 | − !(spi->mode & SPI_CS_HIGH)); | |
| 431 | − if (ret) | |
| 432 | − return ret; | |
| 433 | − } | |
| 434 | − | |
| 435 | 426 | return 0; |
| 436 | 427 | } |
| 437 | 428 | |
| @@ -496,6 +487,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) · 58 unmodified lines | ||
| 496 | 487 | goto err_free_master; |
| 497 | 488 | } |
| 498 | 489 | |
| 490 | + master->use_gpio_descriptors = true; | |
| 499 | 491 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP; |
| 500 | 492 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
| 501 | 493 | master->bus_num = dws->bus_num; |
| @@ -67,7 +67,7 @@ · 66 unmodified lines | ||
| 67 | 67 | #define SPI_SR 0x2c |
| 68 | 68 | #define SPI_SR_EOQF 0x10000000 |
| 69 | 69 | #define SPI_SR_TCFQF 0x80000000 |
| 70 | −#define SPI_SR_CLEAR 0xdaad0000 | |
| 70 | +#define SPI_SR_CLEAR 0x9aaf0000 | |
| 71 | 71 | |
| 72 | 72 | #define SPI_RSER_TFFFE BIT(25) |
| 73 | 73 | #define SPI_RSER_TFFFD BIT(24) |
| @@ -233,6 +233,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) · 159 unmodified lines | ||
| 233 | 233 | { |
| 234 | 234 | u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi); |
| 235 | 235 | |
| 236 | + if (spi_controller_is_slave(dspi->master)) | |
| 237 | + return data; | |
| 238 | + | |
| 236 | 239 | if (dspi->len > 0) |
| 237 | 240 | cmd |= SPI_PUSHR_CMD_CONT; |
| 238 | 241 | return cmd << 16 | data; |
| @@ -329,6 +332,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) · 90 unmodified lines | ||
| 329 | 332 | dma_async_issue_pending(dma->chan_rx); |
| 330 | 333 | dma_async_issue_pending(dma->chan_tx); |
| 331 | 334 | |
| 335 | + if (spi_controller_is_slave(dspi->master)) { | |
| 336 | + wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete); | |
| 337 | + return 0; | |
| 338 | + } | |
| 339 | + | |
| 332 | 340 | time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete, |
| 333 | 341 | DMA_COMPLETION_TIMEOUT); |
| 334 | 342 | if (time_left == 0) { |
| @@ -798,14 +806,18 @@ static int dspi_setup(struct spi_device *spi) · 463 unmodified lines | ||
| 798 | 806 | ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate); |
| 799 | 807 | |
| 800 | 808 | chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0) |
| 801 | − | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0) | |
| 802 | − | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0) | |
| 803 | − | SPI_CTAR_PCSSCK(pcssck) | |
| 804 | − | SPI_CTAR_CSSCK(cssck) | |
| 805 | − | SPI_CTAR_PASC(pasc) | |
| 806 | − | SPI_CTAR_ASC(asc) | |
| 807 | − | SPI_CTAR_PBR(pbr) | |
| 808 | − | SPI_CTAR_BR(br); | |
| 809 | + | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0); | |
| 810 | + | |
| 811 | + if (!spi_controller_is_slave(dspi->master)) { | |
| 812 | + chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode & | |
| 813 | + SPI_LSB_FIRST ? 1 : 0) | |
| 814 | + | SPI_CTAR_PCSSCK(pcssck) | |
| 815 | + | SPI_CTAR_CSSCK(cssck) | |
| 816 | + | SPI_CTAR_PASC(pasc) | |
| 817 | + | SPI_CTAR_ASC(asc) | |
| 818 | + | SPI_CTAR_PBR(pbr) | |
| 819 | + | SPI_CTAR_BR(br); | |
| 820 | + } | |
| 809 | 821 | |
| 810 | 822 | spi_set_ctldata(spi, chip); |
| 811 | 823 | |
| @@ -970,8 +982,13 @@ static const struct regmap_config dspi_xspi_regmap_config[] = { · 158 unmodified lines | ||
| 970 | 982 | |
| 971 | 983 | static void dspi_init(struct fsl_dspi *dspi) |
| 972 | 984 | { |
| 973 | − regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS | | |
| 974 | − (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0)); | |
| 985 | + unsigned int mcr = SPI_MCR_PCSIS | | |
| 986 | + (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0); | |
| 987 | + | |
| 988 | + if (!spi_controller_is_slave(dspi->master)) | |
| 989 | + mcr |= SPI_MCR_MASTER; | |
| 990 | + | |
| 991 | + regmap_write(dspi->regmap, SPI_MCR, mcr); | |
| 975 | 992 | regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR); |
| 976 | 993 | if (dspi->devtype_data->xspi_mode) |
| 977 | 994 | regmap_write(dspi->regmap, SPI_CTARE(0), |
| @@ -1027,6 +1044,9 @@ static int dspi_probe(struct platform_device *pdev) · 49 unmodified lines | ||
| 1027 | 1044 | } |
| 1028 | 1045 | master->bus_num = bus_num; |
| 1029 | 1046 | |
| 1047 | + if (of_property_read_bool(np, "spi-slave")) | |
| 1048 | + master->slave = true; | |
| 1049 | + | |
| 1030 | 1050 | dspi->devtype_data = of_device_get_match_data(&pdev->dev); |
| 1031 | 1051 | if (!dspi->devtype_data) { |
| 1032 | 1052 | dev_err(&pdev->dev, "can't get devtype_data\n"); |
| @@ -48,10 +48,13 @@ · 47 unmodified lines | ||
| 48 | 48 | #define CR_RTF BIT(8) |
| 49 | 49 | #define CR_RST BIT(1) |
| 50 | 50 | #define CR_MEN BIT(0) |
| 51 | +#define SR_MBF BIT(24) | |
| 51 | 52 | #define SR_TCF BIT(10) |
| 53 | +#define SR_FCF BIT(9) | |
| 52 | 54 | #define SR_RDF BIT(1) |
| 53 | 55 | #define SR_TDF BIT(0) |
| 54 | 56 | #define IER_TCIE BIT(10) |
| 57 | +#define IER_FCIE BIT(9) | |
| 55 | 58 | #define IER_RDIE BIT(1) |
| 56 | 59 | #define IER_TDIE BIT(0) |
| 57 | 60 | #define CFGR1_PCSCFG BIT(27) |
| @@ -59,6 +62,7 @@ · 1 unmodified line | ||
| 59 | 62 | #define CFGR1_PCSPOL BIT(8) |
| 60 | 63 | #define CFGR1_NOSTALL BIT(3) |
| 61 | 64 | #define CFGR1_MASTER BIT(0) |
| 65 | +#define FSR_RXCOUNT (BIT(16)|BIT(17)|BIT(18)) | |
| 62 | 66 | #define RSR_RXEMPTY BIT(1) |
| 63 | 67 | #define TCR_CPOL BIT(31) |
| 64 | 68 | #define TCR_CPHA BIT(30) |
| @@ -161,28 +165,10 @@ static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller) · 96 unmodified lines | ||
| 161 | 165 | return 0; |
| 162 | 166 | } |
| 163 | 167 | |
| 164 | −static int fsl_lpspi_txfifo_empty(struct fsl_lpspi_data *fsl_lpspi) | |
| 165 | −{ | |
| 166 | − u32 txcnt; | |
| 167 | − unsigned long orig_jiffies = jiffies; | |
| 168 | − | |
| 169 | − do { | |
| 170 | − txcnt = readl(fsl_lpspi->base + IMX7ULP_FSR) & 0xff; | |
| 171 | − | |
| 172 | − if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { | |
| 173 | − dev_dbg(fsl_lpspi->dev, "txfifo empty timeout\n"); | |
| 174 | − return -ETIMEDOUT; | |
| 175 | − } | |
| 176 | − cond_resched(); | |
| 177 | − | |
| 178 | − } while (txcnt); | |
| 179 | − | |
| 180 | − return 0; | |
| 181 | −} | |
| 182 | − | |
| 183 | 168 | static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi) |
| 184 | 169 | { |
| 185 | 170 | u8 txfifo_cnt; |
| 171 | + u32 temp; | |
| 186 | 172 | |
| 187 | 173 | txfifo_cnt = readl(fsl_lpspi->base + IMX7ULP_FSR) & 0xff; |
| 188 | 174 | |
| @@ -193,9 +179,15 @@ static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi) · 4 unmodified lines | ||
| 193 | 179 | txfifo_cnt++; |
| 194 | 180 | } |
| 195 | 181 | |
| 196 | − if (!fsl_lpspi->remain && (txfifo_cnt < fsl_lpspi->txfifosize)) | |
| 197 | − writel(0, fsl_lpspi->base + IMX7ULP_TDR); | |
| 198 | − else | |
| 182 | + if (txfifo_cnt < fsl_lpspi->txfifosize) { | |
| 183 | + if (!fsl_lpspi->is_slave) { | |
| 184 | + temp = readl(fsl_lpspi->base + IMX7ULP_TCR); | |
| 185 | + temp &= ~TCR_CONTC; | |
| 186 | + writel(temp, fsl_lpspi->base + IMX7ULP_TCR); | |
| 187 | + } | |
| 188 | + | |
| 189 | + fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); | |
| 190 | + } else | |
| 199 | 191 | fsl_lpspi_intctrl(fsl_lpspi, IER_TDIE); |
| 200 | 192 | } |
| 201 | 193 | |
| @@ -276,10 +268,6 @@ static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi) · 74 unmodified lines | ||
| 276 | 268 | u32 temp; |
| 277 | 269 | int ret; |
| 278 | 270 | |
| 279 | − temp = CR_RST; | |
| 280 | − writel(temp, fsl_lpspi->base + IMX7ULP_CR); | |
| 281 | − writel(0, fsl_lpspi->base + IMX7ULP_CR); | |
| 282 | − | |
| 283 | 271 | if (!fsl_lpspi->is_slave) { |
| 284 | 272 | ret = fsl_lpspi_set_bitrate(fsl_lpspi); |
| 285 | 273 | if (ret) |
| @@ -370,6 +358,24 @@ static int fsl_lpspi_wait_for_completion(struct spi_controller *controller) · 84 unmodified lines | ||
| 370 | 358 | return 0; |
| 371 | 359 | } |
| 372 | 360 | |
| 361 | +static int fsl_lpspi_reset(struct fsl_lpspi_data *fsl_lpspi) | |
| 362 | +{ | |
| 363 | + u32 temp; | |
| 364 | + | |
| 365 | + /* Disable all interrupt */ | |
| 366 | + fsl_lpspi_intctrl(fsl_lpspi, 0); | |
| 367 | + | |
| 368 | + /* W1C for all flags in SR */ | |
| 369 | + temp = 0x3F << 8; | |
| 370 | + writel(temp, fsl_lpspi->base + IMX7ULP_SR); | |
| 371 | + | |
| 372 | + /* Clear FIFO and disable module */ | |
| 373 | + temp = CR_RRF | CR_RTF; | |
| 374 | + writel(temp, fsl_lpspi->base + IMX7ULP_CR); | |
| 375 | + | |
| 376 | + return 0; | |
| 377 | +} | |
| 378 | + | |
| 373 | 379 | static int fsl_lpspi_transfer_one(struct spi_controller *controller, |
| 374 | 380 | struct spi_device *spi, |
| 375 | 381 | struct spi_transfer *t) |
| @@ -391,11 +397,7 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller, · 15 unmodified lines | ||
| 391 | 397 | if (ret) |
| 392 | 398 | return ret; |
| 393 | 399 | |
| 394 | − ret = fsl_lpspi_txfifo_empty(fsl_lpspi); | |
| 395 | − if (ret) | |
| 396 | − return ret; | |
| 397 | − | |
| 398 | − fsl_lpspi_read_rx_fifo(fsl_lpspi); | |
| 400 | + fsl_lpspi_reset(fsl_lpspi); | |
| 399 | 401 | |
| 400 | 402 | return 0; |
| 401 | 403 | } |
| @@ -408,7 +410,6 @@ static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller, · 6 unmodified lines | ||
| 408 | 410 | struct spi_device *spi = msg->spi; |
| 409 | 411 | struct spi_transfer *xfer; |
| 410 | 412 | bool is_first_xfer = true; |
| 411 | − u32 temp; | |
| 412 | 413 | int ret = 0; |
| 413 | 414 | |
| 414 | 415 | msg->status = 0; |
| @@ -428,13 +429,6 @@ static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller, · 13 unmodified lines | ||
| 428 | 429 | } |
| 429 | 430 | |
| 430 | 431 | complete: |
| 431 | − if (!fsl_lpspi->is_slave) { | |
| 432 | − /* de-assert SS, then finalize current message */ | |
| 433 | − temp = readl(fsl_lpspi->base + IMX7ULP_TCR); | |
| 434 | − temp &= ~TCR_CONTC; | |
| 435 | − writel(temp, fsl_lpspi->base + IMX7ULP_TCR); | |
| 436 | − } | |
| 437 | − | |
| 438 | 432 | msg->status = ret; |
| 439 | 433 | spi_finalize_current_message(controller); |
| 440 | 434 | |
| @@ -443,20 +437,30 @@ complete: · 2 unmodified lines | ||
| 443 | 437 | |
| 444 | 438 | static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id) |
| 445 | 439 | { |
| 440 | + u32 temp_SR, temp_IER; | |
| 446 | 441 | struct fsl_lpspi_data *fsl_lpspi = dev_id; |
| 447 | − u32 temp; | |
| 448 | 442 | |
| 443 | + temp_IER = readl(fsl_lpspi->base + IMX7ULP_IER); | |
| 449 | 444 | fsl_lpspi_intctrl(fsl_lpspi, 0); |
| 450 | − temp = readl(fsl_lpspi->base + IMX7ULP_SR); | |
| 445 | + temp_SR = readl(fsl_lpspi->base + IMX7ULP_SR); | |
| 451 | 446 | |
| 452 | 447 | fsl_lpspi_read_rx_fifo(fsl_lpspi); |
| 453 | 448 | |
| 454 | − if (temp & SR_TDF) { | |
| 449 | + if ((temp_SR & SR_TDF) && (temp_IER & IER_TDIE)) { | |
| 455 | 450 | fsl_lpspi_write_tx_fifo(fsl_lpspi); |
| 451 | + return IRQ_HANDLED; | |
| 452 | + } | |
| 456 | 453 | |
| 457 | − if (!fsl_lpspi->remain) | |
| 458 | − complete(&fsl_lpspi->xfer_done); | |
| 454 | + if (temp_SR & SR_MBF || | |
| 455 | + readl(fsl_lpspi->base + IMX7ULP_FSR) & FSR_RXCOUNT) { | |
| 456 | + writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); | |
| 457 | + fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE); | |
| 458 | + return IRQ_HANDLED; | |
| 459 | + } | |
| 459 | 460 | |
| 461 | + if (temp_SR & SR_FCF && (temp_IER & IER_FCIE)) { | |
| 462 | + writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR); | |
| 463 | + complete(&fsl_lpspi->xfer_done); | |
| 460 | 464 | return IRQ_HANDLED; |
| 461 | 465 | } |
| 462 | 466 | |
| @@ -0,0 +1,966 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | |
| 2 | + | |
| 3 | +/* | |
| 4 | + * Freescale QuadSPI driver. | |
| 5 | + * | |
| 6 | + * Copyright (C) 2013 Freescale Semiconductor, Inc. | |
| 7 | + * Copyright (C) 2018 Bootlin | |
| 8 | + * Copyright (C) 2018 exceet electronics GmbH | |
| 9 | + * Copyright (C) 2018 Kontron Electronics GmbH | |
| 10 | + * | |
| 11 | + * Transition to SPI MEM interface: | |
| 12 | + * Authors: | |
| 13 | + * Boris Brezillon <bbrezillon@kernel.org> | |
| 14 | + * Frieder Schrempf <frieder.schrempf@kontron.de> | |
| 15 | + * Yogesh Gaur <yogeshnarayan.gaur@nxp.com> | |
| 16 | + * Suresh Gupta <suresh.gupta@nxp.com> | |
| 17 | + * | |
| 18 | + * Based on the original fsl-quadspi.c spi-nor driver: | |
| 19 | + * Author: Freescale Semiconductor, Inc. | |
| 20 | + * | |
| 21 | + */ | |
| 22 | + | |
| 23 | +#include <linux/bitops.h> | |
| 24 | +#include <linux/clk.h> | |
| 25 | +#include <linux/completion.h> | |
| 26 | +#include <linux/delay.h> | |
| 27 | +#include <linux/err.h> | |
| 28 | +#include <linux/errno.h> | |
| 29 | +#include <linux/interrupt.h> | |
| 30 | +#include <linux/io.h> | |
| 31 | +#include <linux/iopoll.h> | |
| 32 | +#include <linux/jiffies.h> | |
| 33 | +#include <linux/kernel.h> | |
| 34 | +#include <linux/module.h> | |
| 35 | +#include <linux/mutex.h> | |
| 36 | +#include <linux/of.h> | |
| 37 | +#include <linux/of_device.h> | |
| 38 | +#include <linux/platform_device.h> | |
| 39 | +#include <linux/pm_qos.h> | |
| 40 | +#include <linux/sizes.h> | |
| 41 | + | |
| 42 | +#include <linux/spi/spi.h> | |
| 43 | +#include <linux/spi/spi-mem.h> | |
| 44 | + | |
| 45 | +/* | |
| 46 | + * The driver only uses one single LUT entry, that is updated on | |
| 47 | + * each call of exec_op(). Index 0 is preset at boot with a basic | |
| 48 | + * read operation, so let's use the last entry (15). | |
| 49 | + */ | |
| 50 | +#define SEQID_LUT 15 | |
| 51 | + | |
| 52 | +/* Registers used by the driver */ | |
| 53 | +#define QUADSPI_MCR 0x00 | |
| 54 | +#define QUADSPI_MCR_RESERVED_MASK GENMASK(19, 16) | |
| 55 | +#define QUADSPI_MCR_MDIS_MASK BIT(14) | |
| 56 | +#define QUADSPI_MCR_CLR_TXF_MASK BIT(11) | |
| 57 | +#define QUADSPI_MCR_CLR_RXF_MASK BIT(10) | |
| 58 | +#define QUADSPI_MCR_DDR_EN_MASK BIT(7) | |
| 59 | +#define QUADSPI_MCR_END_CFG_MASK GENMASK(3, 2) | |
| 60 | +#define QUADSPI_MCR_SWRSTHD_MASK BIT(1) | |
| 61 | +#define QUADSPI_MCR_SWRSTSD_MASK BIT(0) | |
| 62 | + | |
| 63 | +#define QUADSPI_IPCR 0x08 | |
| 64 | +#define QUADSPI_IPCR_SEQID(x) ((x) << 24) | |
| 65 | + | |
| 66 | +#define QUADSPI_BUF3CR 0x1c | |
| 67 | +#define QUADSPI_BUF3CR_ALLMST_MASK BIT(31) | |
| 68 | +#define QUADSPI_BUF3CR_ADATSZ(x) ((x) << 8) | |
| 69 | +#define QUADSPI_BUF3CR_ADATSZ_MASK GENMASK(15, 8) | |
| 70 | + | |
| 71 | +#define QUADSPI_BFGENCR 0x20 | |
| 72 | +#define QUADSPI_BFGENCR_SEQID(x) ((x) << 12) | |
| 73 | + | |
| 74 | +#define QUADSPI_BUF0IND 0x30 | |
| 75 | +#define QUADSPI_BUF1IND 0x34 | |
| 76 | +#define QUADSPI_BUF2IND 0x38 | |
| 77 | +#define QUADSPI_SFAR 0x100 | |
| 78 | + | |
| 79 | +#define QUADSPI_SMPR 0x108 | |
| 80 | +#define QUADSPI_SMPR_DDRSMP_MASK GENMASK(18, 16) | |
| 81 | +#define QUADSPI_SMPR_FSDLY_MASK BIT(6) | |
| 82 | +#define QUADSPI_SMPR_FSPHS_MASK BIT(5) | |
| 83 | +#define QUADSPI_SMPR_HSENA_MASK BIT(0) | |
| 84 | + | |
| 85 | +#define QUADSPI_RBCT 0x110 | |
| 86 | +#define QUADSPI_RBCT_WMRK_MASK GENMASK(4, 0) | |
| 87 | +#define QUADSPI_RBCT_RXBRD_USEIPS BIT(8) | |
| 88 | + | |
| 89 | +#define QUADSPI_TBDR 0x154 | |
| 90 | + | |
| 91 | +#define QUADSPI_SR 0x15c | |
| 92 | +#define QUADSPI_SR_IP_ACC_MASK BIT(1) | |
| 93 | +#define QUADSPI_SR_AHB_ACC_MASK BIT(2) | |
| 94 | + | |
| 95 | +#define QUADSPI_FR 0x160 | |
| 96 | +#define QUADSPI_FR_TFF_MASK BIT(0) | |
| 97 | + | |
| 98 | +#define QUADSPI_SPTRCLR 0x16c | |
| 99 | +#define QUADSPI_SPTRCLR_IPPTRC BIT(8) | |
| 100 | +#define QUADSPI_SPTRCLR_BFPTRC BIT(0) | |
| 101 | + | |
| 102 | +#define QUADSPI_SFA1AD 0x180 | |
| 103 | +#define QUADSPI_SFA2AD 0x184 | |
| 104 | +#define QUADSPI_SFB1AD 0x188 | |
| 105 | +#define QUADSPI_SFB2AD 0x18c | |
| 106 | +#define QUADSPI_RBDR(x) (0x200 + ((x) * 4)) | |
| 107 | + | |
| 108 | +#define QUADSPI_LUTKEY 0x300 | |
| 109 | +#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0 | |
| 110 | + | |
| 111 | +#define QUADSPI_LCKCR 0x304 | |
| 112 | +#define QUADSPI_LCKER_LOCK BIT(0) | |
| 113 | +#define QUADSPI_LCKER_UNLOCK BIT(1) | |
| 114 | + | |
| 115 | +#define QUADSPI_RSER 0x164 | |
| 116 | +#define QUADSPI_RSER_TFIE BIT(0) | |
| 117 | + | |
| 118 | +#define QUADSPI_LUT_BASE 0x310 | |
| 119 | +#define QUADSPI_LUT_OFFSET (SEQID_LUT * 4 * 4) | |
| 120 | +#define QUADSPI_LUT_REG(idx) \ | |
| 121 | + (QUADSPI_LUT_BASE + QUADSPI_LUT_OFFSET + (idx) * 4) | |
| 122 | + | |
| 123 | +/* Instruction set for the LUT register */ | |
| 124 | +#define LUT_STOP 0 | |
| 125 | +#define LUT_CMD 1 | |
| 126 | +#define LUT_ADDR 2 | |
| 127 | +#define LUT_DUMMY 3 | |
| 128 | +#define LUT_MODE 4 | |
| 129 | +#define LUT_MODE2 5 | |
| 130 | +#define LUT_MODE4 6 | |
| 131 | +#define LUT_FSL_READ 7 | |
| 132 | +#define LUT_FSL_WRITE 8 | |
| 133 | +#define LUT_JMP_ON_CS 9 | |
| 134 | +#define LUT_ADDR_DDR 10 | |
| 135 | +#define LUT_MODE_DDR 11 | |
| 136 | +#define LUT_MODE2_DDR 12 | |
| 137 | +#define LUT_MODE4_DDR 13 | |
| 138 | +#define LUT_FSL_READ_DDR 14 | |
| 139 | +#define LUT_FSL_WRITE_DDR 15 | |
| 140 | +#define LUT_DATA_LEARN 16 | |
| 141 | + | |
| 142 | +/* | |
| 143 | + * The PAD definitions for LUT register. | |
| 144 | + * | |
| 145 | + * The pad stands for the number of IO lines [0:3]. | |
| 146 | + * For example, the quad read needs four IO lines, | |
| 147 | + * so you should use LUT_PAD(4). | |
| 148 | + */ | |
| 149 | +#define LUT_PAD(x) (fls(x) - 1) | |
| 150 | + | |
| 151 | +/* | |
| 152 | + * Macro for constructing the LUT entries with the following | |
| 153 | + * register layout: | |
| 154 | + * | |
| 155 | + * --------------------------------------------------- | |
| 156 | + * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 | | |
| 157 | + * --------------------------------------------------- | |
| 158 | + */ | |
| 159 | +#define LUT_DEF(idx, ins, pad, opr) \ | |
| 160 | + ((((ins) << 10) | ((pad) << 8) | (opr)) << (((idx) % 2) * 16)) | |
| 161 | + | |
| 162 | +/* Controller needs driver to swap endianness */ | |
| 163 | +#define QUADSPI_QUIRK_SWAP_ENDIAN BIT(0) | |
| 164 | + | |
| 165 | +/* Controller needs 4x internal clock */ | |
| 166 | +#define QUADSPI_QUIRK_4X_INT_CLK BIT(1) | |
| 167 | + | |
| 168 | +/* | |
| 169 | + * TKT253890, the controller needs the driver to fill the txfifo with | |
| 170 | + * 16 bytes at least to trigger a data transfer, even though the extra | |
| 171 | + * data won't be transferred. | |
| 172 | + */ | |
| 173 | +#define QUADSPI_QUIRK_TKT253890 BIT(2) | |
| 174 | + | |
| 175 | +/* TKT245618, the controller cannot wake up from wait mode */ | |
| 176 | +#define QUADSPI_QUIRK_TKT245618 BIT(3) | |
| 177 | + | |
| 178 | +/* | |
| 179 | + * Controller adds QSPI_AMBA_BASE (base address of the mapped memory) | |
| 180 | + * internally. No need to add it when setting SFXXAD and SFAR registers | |
| 181 | + */ | |
| 182 | +#define QUADSPI_QUIRK_BASE_INTERNAL BIT(4) | |
| 183 | + | |
| 184 | +struct fsl_qspi_devtype_data { | |
| 185 | + unsigned int rxfifo; | |
| 186 | + unsigned int txfifo; | |
| 187 | + unsigned int ahb_buf_size; | |
| 188 | + unsigned int quirks; | |
| 189 | + bool little_endian; | |
| 190 | +}; | |
| 191 | + | |
| 192 | +static const struct fsl_qspi_devtype_data vybrid_data = { | |
| 193 | + .rxfifo = SZ_128, | |
| 194 | + .txfifo = SZ_64, | |
| 195 | + .ahb_buf_size = SZ_1K, | |
| 196 | + .quirks = QUADSPI_QUIRK_SWAP_ENDIAN, | |
| 197 | + .little_endian = true, | |
| 198 | +}; | |
| 199 | + | |
| 200 | +static const struct fsl_qspi_devtype_data imx6sx_data = { | |
| 201 | + .rxfifo = SZ_128, | |
| 202 | + .txfifo = SZ_512, | |
| 203 | + .ahb_buf_size = SZ_1K, | |
| 204 | + .quirks = QUADSPI_QUIRK_4X_INT_CLK | QUADSPI_QUIRK_TKT245618, | |
| 205 | + .little_endian = true, | |
| 206 | +}; | |
| 207 | + | |
| 208 | +static const struct fsl_qspi_devtype_data imx7d_data = { | |
| 209 | + .rxfifo = SZ_512, | |
| 210 | + .txfifo = SZ_512, | |
| 211 | + .ahb_buf_size = SZ_1K, | |
| 212 | + .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK, | |
| 213 | + .little_endian = true, | |
| 214 | +}; | |
| 215 | + | |
| 216 | +static const struct fsl_qspi_devtype_data imx6ul_data = { | |
| 217 | + .rxfifo = SZ_128, | |
| 218 | + .txfifo = SZ_512, | |
| 219 | + .ahb_buf_size = SZ_1K, | |
| 220 | + .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK, | |
| 221 | + .little_endian = true, | |
| 222 | +}; | |
| 223 | + | |
| 224 | +static const struct fsl_qspi_devtype_data ls1021a_data = { | |
| 225 | + .rxfifo = SZ_128, | |
| 226 | + .txfifo = SZ_64, | |
| 227 | + .ahb_buf_size = SZ_1K, | |
| 228 | + .quirks = 0, | |
| 229 | + .little_endian = false, | |
| 230 | +}; | |
| 231 | + | |
| 232 | +static const struct fsl_qspi_devtype_data ls2080a_data = { | |
| 233 | + .rxfifo = SZ_128, | |
| 234 | + .txfifo = SZ_64, | |
| 235 | + .ahb_buf_size = SZ_1K, | |
| 236 | + .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_BASE_INTERNAL, | |
| 237 | + .little_endian = true, | |
| 238 | +}; | |
| 239 | + | |
| 240 | +struct fsl_qspi { | |
| 241 | + void __iomem *iobase; | |
| 242 | + void __iomem *ahb_addr; | |
| 243 | + u32 memmap_phy; | |
| 244 | + struct clk *clk, *clk_en; | |
| 245 | + struct device *dev; | |
| 246 | + struct completion c; | |
| 247 | + const struct fsl_qspi_devtype_data *devtype_data; | |
| 248 | + struct mutex lock; | |
| 249 | + struct pm_qos_request pm_qos_req; | |
| 250 | + int selected; | |
| 251 | +}; | |
| 252 | + | |
| 253 | +static inline int needs_swap_endian(struct fsl_qspi *q) | |
| 254 | +{ | |
| 255 | + return q->devtype_data->quirks & QUADSPI_QUIRK_SWAP_ENDIAN; | |
| 256 | +} | |
| 257 | + | |
| 258 | +static inline int needs_4x_clock(struct fsl_qspi *q) | |
| 259 | +{ | |
| 260 | + return q->devtype_data->quirks & QUADSPI_QUIRK_4X_INT_CLK; | |
| 261 | +} | |
| 262 | + | |
| 263 | +static inline int needs_fill_txfifo(struct fsl_qspi *q) | |
| 264 | +{ | |
| 265 | + return q->devtype_data->quirks & QUADSPI_QUIRK_TKT253890; | |
| 266 | +} | |
| 267 | + | |
| 268 | +static inline int needs_wakeup_wait_mode(struct fsl_qspi *q) | |
| 269 | +{ | |
| 270 | + return q->devtype_data->quirks & QUADSPI_QUIRK_TKT245618; | |
| 271 | +} | |
| 272 | + | |
| 273 | +static inline int needs_amba_base_offset(struct fsl_qspi *q) | |
| 274 | +{ | |
| 275 | + return !(q->devtype_data->quirks & QUADSPI_QUIRK_BASE_INTERNAL); | |
| 276 | +} | |
| 277 | + | |
| 278 | +/* | |
| 279 | + * An IC bug makes it necessary to rearrange the 32-bit data. | |
| 280 | + * Later chips, such as IMX6SLX, have fixed this bug. | |
| 281 | + */ | |
| 282 | +static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a) | |
| 283 | +{ | |
| 284 | + return needs_swap_endian(q) ? __swab32(a) : a; | |
| 285 | +} | |
| 286 | + | |
| 287 | +/* | |
| 288 | + * R/W functions for big- or little-endian registers: | |
| 289 | + * The QSPI controller's endianness is independent of | |
| 290 | + * the CPU core's endianness. So far, although the CPU | |
| 291 | + * core is little-endian the QSPI controller can use | |
| 292 | + * big-endian or little-endian. | |
| 293 | + */ | |
| 294 | +static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr) | |
| 295 | +{ | |
| 296 | + if (q->devtype_data->little_endian) | |
| 297 | + iowrite32(val, addr); | |
| 298 | + else | |
| 299 | + iowrite32be(val, addr); | |
| 300 | +} | |
| 301 | + | |
| 302 | +static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr) | |
| 303 | +{ | |
| 304 | + if (q->devtype_data->little_endian) | |
| 305 | + return ioread32(addr); | |
| 306 | + | |
| 307 | + return ioread32be(addr); | |
| 308 | +} | |
| 309 | + | |
| 310 | +static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id) | |
| 311 | +{ | |
| 312 | + struct fsl_qspi *q = dev_id; | |
| 313 | + u32 reg; | |
| 314 | + | |
| 315 | + /* clear interrupt */ | |
| 316 | + reg = qspi_readl(q, q->iobase + QUADSPI_FR); | |
| 317 | + qspi_writel(q, reg, q->iobase + QUADSPI_FR); | |
| 318 | + | |
| 319 | + if (reg & QUADSPI_FR_TFF_MASK) | |
| 320 | + complete(&q->c); | |
| 321 | + | |
| 322 | + dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", 0, reg); | |
| 323 | + return IRQ_HANDLED; | |
| 324 | +} | |
| 325 | + | |
| 326 | +static int fsl_qspi_check_buswidth(struct fsl_qspi *q, u8 width) | |
| 327 | +{ | |
| 328 | + switch (width) { | |
| 329 | + case 1: | |
| 330 | + case 2: | |
| 331 | + case 4: | |
| 332 | + return 0; | |
| 333 | + } | |
| 334 | + | |
| 335 | + return -ENOTSUPP; | |
| 336 | +} | |
| 337 | + | |
| 338 | +static bool fsl_qspi_supports_op(struct spi_mem *mem, | |
| 339 | + const struct spi_mem_op *op) | |
| 340 | +{ | |
| 341 | + struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master); | |
| 342 | + int ret; | |
| 343 | + | |
| 344 | + ret = fsl_qspi_check_buswidth(q, op->cmd.buswidth); | |
| 345 | + | |
| 346 | + if (op->addr.nbytes) | |
| 347 | + ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth); | |
| 348 | + | |
| 349 | + if (op->dummy.nbytes) | |
| 350 | + ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth); | |
| 351 | + | |
| 352 | + if (op->data.nbytes) | |
| 353 | + ret |= fsl_qspi_check_buswidth(q, op->data.buswidth); | |
| 354 | + | |
| 355 | + if (ret) | |
| 356 | + return false; | |
| 357 | + | |
| 358 | + /* | |
| 359 | + * The number of instructions needed for the op, needs | |
| 360 | + * to fit into a single LUT entry. | |
| 361 | + */ | |
| 362 | + if (op->addr.nbytes + | |
| 363 | + (op->dummy.nbytes ? 1:0) + | |
| 364 | + (op->data.nbytes ? 1:0) > 6) | |
| 365 | + return false; | |
| 366 | + | |
| 367 | + /* Max 64 dummy clock cycles supported */ | |
| 368 | + if (op->dummy.nbytes && | |
| 369 | + (op->dummy.nbytes * 8 / op->dummy.buswidth > 64)) | |
| 370 | + return false; | |
| 371 | + | |
| 372 | + /* Max data length, check controller limits and alignment */ | |
| 373 | + if (op->data.dir == SPI_MEM_DATA_IN && | |
| 374 | + (op->data.nbytes > q->devtype_data->ahb_buf_size || | |
| 375 | + (op->data.nbytes > q->devtype_data->rxfifo - 4 && | |
| 376 | + !IS_ALIGNED(op->data.nbytes, 8)))) | |
| 377 | + return false; | |
| 378 | + | |
| 379 | + if (op->data.dir == SPI_MEM_DATA_OUT && | |
| 380 | + op->data.nbytes > q->devtype_data->txfifo) | |
| 381 | + return false; | |
| 382 | + | |
| 383 | + return true; | |
| 384 | +} | |
| 385 | + | |
| 386 | +static void fsl_qspi_prepare_lut(struct fsl_qspi *q, | |
| 387 | + const struct spi_mem_op *op) | |
| 388 | +{ | |
| 389 | + void __iomem *base = q->iobase; | |
| 390 | + u32 lutval[4] = {}; | |
| 391 | + int lutidx = 1, i; | |
| 392 | + | |
| 393 | + lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth), | |
| 394 | + op->cmd.opcode); | |
| 395 | + | |
| 396 | + /* | |
| 397 | + * For some unknown reason, using LUT_ADDR doesn't work in some | |
| 398 | + * cases (at least with only one byte long addresses), so | |
| 399 | + * let's use LUT_MODE to write the address bytes one by one | |
| 400 | + */ | |
| 401 | + for (i = 0; i < op->addr.nbytes; i++) { | |
| 402 | + u8 addrbyte = op->addr.val >> (8 * (op->addr.nbytes - i - 1)); | |
| 403 | + | |
| 404 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_MODE, | |
| 405 | + LUT_PAD(op->addr.buswidth), | |
| 406 | + addrbyte); | |
| 407 | + lutidx++; | |
| 408 | + } | |
| 409 | + | |
| 410 | + if (op->dummy.nbytes) { | |
| 411 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, | |
| 412 | + LUT_PAD(op->dummy.buswidth), | |
| 413 | + op->dummy.nbytes * 8 / | |
| 414 | + op->dummy.buswidth); | |
| 415 | + lutidx++; | |
| 416 | + } | |
| 417 | + | |
| 418 | + if (op->data.nbytes) { | |
| 419 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, | |
| 420 | + op->data.dir == SPI_MEM_DATA_IN ? | |
| 421 | + LUT_FSL_READ : LUT_FSL_WRITE, | |
| 422 | + LUT_PAD(op->data.buswidth), | |
| 423 | + 0); | |
| 424 | + lutidx++; | |
| 425 | + } | |
| 426 | + | |
| 427 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0); | |
| 428 | + | |
| 429 | + /* unlock LUT */ | |
| 430 | + qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); | |
| 431 | + qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR); | |
| 432 | + | |
| 433 | + /* fill LUT */ | |
| 434 | + for (i = 0; i < ARRAY_SIZE(lutval); i++) | |
| 435 | + qspi_writel(q, lutval[i], base + QUADSPI_LUT_REG(i)); | |
| 436 | + | |
| 437 | + /* lock LUT */ | |
| 438 | + qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); | |
| 439 | + qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR); | |
| 440 | +} | |
| 441 | + | |
| 442 | +static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q) | |
| 443 | +{ | |
| 444 | + int ret; | |
| 445 | + | |
| 446 | + ret = clk_prepare_enable(q->clk_en); | |
| 447 | + if (ret) | |
| 448 | + return ret; | |
| 449 | + | |
| 450 | + ret = clk_prepare_enable(q->clk); | |
| 451 | + if (ret) { | |
| 452 | + clk_disable_unprepare(q->clk_en); | |
| 453 | + return ret; | |
| 454 | + } | |
| 455 | + | |
| 456 | + if (needs_wakeup_wait_mode(q)) | |
| 457 | + pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0); | |
| 458 | + | |
| 459 | + return 0; | |
| 460 | +} | |
| 461 | + | |
| 462 | +static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q) | |
| 463 | +{ | |
| 464 | + if (needs_wakeup_wait_mode(q)) | |
| 465 | + pm_qos_remove_request(&q->pm_qos_req); | |
| 466 | + | |
| 467 | + clk_disable_unprepare(q->clk); | |
| 468 | + clk_disable_unprepare(q->clk_en); | |
| 469 | +} | |
| 470 | + | |
| 471 | +/* | |
| 472 | + * If we have changed the content of the flash by writing or erasing, or if we | |
| 473 | + * read from flash with a different offset into the page buffer, we need to | |
| 474 | + * invalidate the AHB buffer. If we do not do so, we may read out the wrong | |
| 475 | + * data. The spec tells us reset the AHB domain and Serial Flash domain at | |
| 476 | + * the same time. | |
| 477 | + */ | |
| 478 | +static void fsl_qspi_invalidate(struct fsl_qspi *q) | |
| 479 | +{ | |
| 480 | + u32 reg; | |
| 481 | + | |
| 482 | + reg = qspi_readl(q, q->iobase + QUADSPI_MCR); | |
| 483 | + reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK; | |
| 484 | + qspi_writel(q, reg, q->iobase + QUADSPI_MCR); | |
| 485 | + | |
| 486 | + /* | |
| 487 | + * The minimum delay : 1 AHB + 2 SFCK clocks. | |
| 488 | + * Delay 1 us is enough. | |
| 489 | + */ | |
| 490 | + udelay(1); | |
| 491 | + | |
| 492 | + reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK); | |
| 493 | + qspi_writel(q, reg, q->iobase + QUADSPI_MCR); | |
| 494 | +} | |
| 495 | + | |
| 496 | +static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi) | |
| 497 | +{ | |
| 498 | + unsigned long rate = spi->max_speed_hz; | |
| 499 | + int ret; | |
| 500 | + | |
| 501 | + if (q->selected == spi->chip_select) | |
| 502 | + return; | |
| 503 | + | |
| 504 | + if (needs_4x_clock(q)) | |
| 505 | + rate *= 4; | |
| 506 | + | |
| 507 | + fsl_qspi_clk_disable_unprep(q); | |
| 508 | + | |
| 509 | + ret = clk_set_rate(q->clk, rate); | |
| 510 | + if (ret) | |
| 511 | + return; | |
| 512 | + | |
| 513 | + ret = fsl_qspi_clk_prep_enable(q); | |
| 514 | + if (ret) | |
| 515 | + return; | |
| 516 | + | |
| 517 | + q->selected = spi->chip_select; | |
| 518 | + | |
| 519 | + fsl_qspi_invalidate(q); | |
| 520 | +} | |
| 521 | + | |
| 522 | +static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op) | |
| 523 | +{ | |
| 524 | + memcpy_fromio(op->data.buf.in, | |
| 525 | + q->ahb_addr + q->selected * q->devtype_data->ahb_buf_size, | |
| 526 | + op->data.nbytes); | |
| 527 | +} | |
| 528 | + | |
| 529 | +static void fsl_qspi_fill_txfifo(struct fsl_qspi *q, | |
| 530 | + const struct spi_mem_op *op) | |
| 531 | +{ | |
| 532 | + void __iomem *base = q->iobase; | |
| 533 | + int i; | |
| 534 | + u32 val; | |
| 535 | + | |
| 536 | + for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) { | |
| 537 | + memcpy(&val, op->data.buf.out + i, 4); | |
| 538 | + val = fsl_qspi_endian_xchg(q, val); | |
| 539 | + qspi_writel(q, val, base + QUADSPI_TBDR); | |
| 540 | + } | |
| 541 | + | |
| 542 | + if (i < op->data.nbytes) { | |
| 543 | + memcpy(&val, op->data.buf.out + i, op->data.nbytes - i); | |
| 544 | + val = fsl_qspi_endian_xchg(q, val); | |
| 545 | + qspi_writel(q, val, base + QUADSPI_TBDR); | |
| 546 | + } | |
| 547 | + | |
| 548 | + if (needs_fill_txfifo(q)) { | |
| 549 | + for (i = op->data.nbytes; i < 16; i += 4) | |
| 550 | + qspi_writel(q, 0, base + QUADSPI_TBDR); | |
| 551 | + } | |
| 552 | +} | |
| 553 | + | |
| 554 | +static void fsl_qspi_read_rxfifo(struct fsl_qspi *q, | |
| 555 | + const struct spi_mem_op *op) | |
| 556 | +{ | |
| 557 | + void __iomem *base = q->iobase; | |
| 558 | + int i; | |
| 559 | + u8 *buf = op->data.buf.in; | |
| 560 | + u32 val; | |
| 561 | + | |
| 562 | + for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) { | |
| 563 | + val = qspi_readl(q, base + QUADSPI_RBDR(i / 4)); | |
| 564 | + val = fsl_qspi_endian_xchg(q, val); | |
| 565 | + memcpy(buf + i, &val, 4); | |
| 566 | + } | |
| 567 | + | |
| 568 | + if (i < op->data.nbytes) { | |
| 569 | + val = qspi_readl(q, base + QUADSPI_RBDR(i / 4)); | |
| 570 | + val = fsl_qspi_endian_xchg(q, val); | |
| 571 | + memcpy(buf + i, &val, op->data.nbytes - i); | |
| 572 | + } | |
| 573 | +} | |
| 574 | + | |
| 575 | +static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op) | |
| 576 | +{ | |
| 577 | + void __iomem *base = q->iobase; | |
| 578 | + int err = 0; | |
| 579 | + | |
| 580 | + init_completion(&q->c); | |
| 581 | + | |
| 582 | + /* | |
| 583 | + * Always start the sequence at the same index since we update | |
| 584 | + * the LUT at each exec_op() call. And also specify the DATA | |
| 585 | + * length, since it's has not been specified in the LUT. | |
| 586 | + */ | |
| 587 | + qspi_writel(q, op->data.nbytes | QUADSPI_IPCR_SEQID(SEQID_LUT), | |
| 588 | + base + QUADSPI_IPCR); | |
| 589 | + | |
| 590 | + /* Wait for the interrupt. */ | |
| 591 | + if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000))) | |
| 592 | + err = -ETIMEDOUT; | |
| 593 | + | |
| 594 | + if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN) | |
| 595 | + fsl_qspi_read_rxfifo(q, op); | |
| 596 | + | |
| 597 | + return err; | |
| 598 | +} | |
| 599 | + | |
| 600 | +static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base, | |
| 601 | + u32 mask, u32 delay_us, u32 timeout_us) | |
| 602 | +{ | |
| 603 | + u32 reg; | |
| 604 | + | |
| 605 | + if (!q->devtype_data->little_endian) | |
| 606 | + mask = (u32)cpu_to_be32(mask); | |
| 607 | + | |
| 608 | + return readl_poll_timeout(base, reg, !(reg & mask), delay_us, | |
| 609 | + timeout_us); | |
| 610 | +} | |
| 611 | + | |
| 612 | +static int fsl_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) | |
| 613 | +{ | |
| 614 | + struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master); | |
| 615 | + void __iomem *base = q->iobase; | |
| 616 | + u32 addr_offset = 0; | |
| 617 | + int err = 0; | |
| 618 | + | |
| 619 | + mutex_lock(&q->lock); | |
| 620 | + | |
| 621 | + /* wait for the controller being ready */ | |
| 622 | + fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK | | |
| 623 | + QUADSPI_SR_AHB_ACC_MASK), 10, 1000); | |
| 624 | + | |
| 625 | + fsl_qspi_select_mem(q, mem->spi); | |
| 626 | + | |
| 627 | + if (needs_amba_base_offset(q)) | |
| 628 | + addr_offset = q->memmap_phy; | |
| 629 | + | |
| 630 | + qspi_writel(q, | |
| 631 | + q->selected * q->devtype_data->ahb_buf_size + addr_offset, | |
| 632 | + base + QUADSPI_SFAR); | |
| 633 | + | |
| 634 | + qspi_writel(q, qspi_readl(q, base + QUADSPI_MCR) | | |
| 635 | + QUADSPI_MCR_CLR_RXF_MASK | QUADSPI_MCR_CLR_TXF_MASK, | |
| 636 | + base + QUADSPI_MCR); | |
| 637 | + | |
| 638 | + qspi_writel(q, QUADSPI_SPTRCLR_BFPTRC | QUADSPI_SPTRCLR_IPPTRC, | |
| 639 | + base + QUADSPI_SPTRCLR); | |
| 640 | + | |
| 641 | + fsl_qspi_prepare_lut(q, op); | |
| 642 | + | |
| 643 | + /* | |
| 644 | + * If we have large chunks of data, we read them through the AHB bus | |
| 645 | + * by accessing the mapped memory. In all other cases we use | |
| 646 | + * IP commands to access the flash. | |
| 647 | + */ | |
| 648 | + if (op->data.nbytes > (q->devtype_data->rxfifo - 4) && | |
| 649 | + op->data.dir == SPI_MEM_DATA_IN) { | |
| 650 | + fsl_qspi_read_ahb(q, op); | |
| 651 | + } else { | |
| 652 | + qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | | |
| 653 | + QUADSPI_RBCT_RXBRD_USEIPS, base + QUADSPI_RBCT); | |
| 654 | + | |
| 655 | + if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT) | |
| 656 | + fsl_qspi_fill_txfifo(q, op); | |
| 657 | + | |
| 658 | + err = fsl_qspi_do_op(q, op); | |
| 659 | + } | |
| 660 | + | |
| 661 | + /* Invalidate the data in the AHB buffer. */ | |
| 662 | + fsl_qspi_invalidate(q); | |
| 663 | + | |
| 664 | + mutex_unlock(&q->lock); | |
| 665 | + | |
| 666 | + return err; | |
| 667 | +} | |
| 668 | + | |
| 669 | +static int fsl_qspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) | |
| 670 | +{ | |
| 671 | + struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master); | |
| 672 | + | |
| 673 | + if (op->data.dir == SPI_MEM_DATA_OUT) { | |
| 674 | + if (op->data.nbytes > q->devtype_data->txfifo) | |
| 675 | + op->data.nbytes = q->devtype_data->txfifo; | |
| 676 | + } else { | |
| 677 | + if (op->data.nbytes > q->devtype_data->ahb_buf_size) | |
| 678 | + op->data.nbytes = q->devtype_data->ahb_buf_size; | |
| 679 | + else if (op->data.nbytes > (q->devtype_data->rxfifo - 4)) | |
| 680 | + op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8); | |
| 681 | + } | |
| 682 | + | |
| 683 | + return 0; | |
| 684 | +} | |
| 685 | + | |
| 686 | +static int fsl_qspi_default_setup(struct fsl_qspi *q) | |
| 687 | +{ | |
| 688 | + void __iomem *base = q->iobase; | |
| 689 | + u32 reg, addr_offset = 0; | |
| 690 | + int ret; | |
| 691 | + | |
| 692 | + /* disable and unprepare clock to avoid glitch pass to controller */ | |
| 693 | + fsl_qspi_clk_disable_unprep(q); | |
| 694 | + | |
| 695 | + /* the default frequency, we will change it later if necessary. */ | |
| 696 | + ret = clk_set_rate(q->clk, 66000000); | |
| 697 | + if (ret) | |
| 698 | + return ret; | |
| 699 | + | |
| 700 | + ret = fsl_qspi_clk_prep_enable(q); | |
| 701 | + if (ret) | |
| 702 | + return ret; | |
| 703 | + | |
| 704 | + /* Reset the module */ | |
| 705 | + qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK, | |
| 706 | + base + QUADSPI_MCR); | |
| 707 | + udelay(1); | |
| 708 | + | |
| 709 | + /* Disable the module */ | |
| 710 | + qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK, | |
| 711 | + base + QUADSPI_MCR); | |
| 712 | + | |
| 713 | + reg = qspi_readl(q, base + QUADSPI_SMPR); | |
| 714 | + qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK | |
| 715 | + | QUADSPI_SMPR_FSPHS_MASK | |
| 716 | + | QUADSPI_SMPR_HSENA_MASK | |
| 717 | + | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR); | |
| 718 | + | |
| 719 | + /* We only use the buffer3 for AHB read */ | |
| 720 | + qspi_writel(q, 0, base + QUADSPI_BUF0IND); | |
| 721 | + qspi_writel(q, 0, base + QUADSPI_BUF1IND); | |
| 722 | + qspi_writel(q, 0, base + QUADSPI_BUF2IND); | |
| 723 | + | |
| 724 | + qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT), | |
| 725 | + q->iobase + QUADSPI_BFGENCR); | |
| 726 | + qspi_writel(q, QUADSPI_RBCT_WMRK_MASK, base + QUADSPI_RBCT); | |
| 727 | + qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK | | |
| 728 | + QUADSPI_BUF3CR_ADATSZ(q->devtype_data->ahb_buf_size / 8), | |
| 729 | + base + QUADSPI_BUF3CR); | |
| 730 | + | |
| 731 | + if (needs_amba_base_offset(q)) | |
| 732 | + addr_offset = q->memmap_phy; | |
| 733 | + | |
| 734 | + /* | |
| 735 | + * In HW there can be a maximum of four chips on two buses with | |
| 736 | + * two chip selects on each bus. We use four chip selects in SW | |
| 737 | + * to differentiate between the four chips. | |
| 738 | + * We use ahb_buf_size for each chip and set SFA1AD, SFA2AD, SFB1AD, | |
| 739 | + * SFB2AD accordingly. | |
| 740 | + */ | |
| 741 | + qspi_writel(q, q->devtype_data->ahb_buf_size + addr_offset, | |
| 742 | + base + QUADSPI_SFA1AD); | |
| 743 | + qspi_writel(q, q->devtype_data->ahb_buf_size * 2 + addr_offset, | |
| 744 | + base + QUADSPI_SFA2AD); | |
| 745 | + qspi_writel(q, q->devtype_data->ahb_buf_size * 3 + addr_offset, | |
| 746 | + base + QUADSPI_SFB1AD); | |
| 747 | + qspi_writel(q, q->devtype_data->ahb_buf_size * 4 + addr_offset, | |
| 748 | + base + QUADSPI_SFB2AD); | |
| 749 | + | |
| 750 | + q->selected = -1; | |
| 751 | + | |
| 752 | + /* Enable the module */ | |
| 753 | + qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK, | |
| 754 | + base + QUADSPI_MCR); | |
| 755 | + | |
| 756 | + /* clear all interrupt status */ | |
| 757 | + qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR); | |
| 758 | + | |
| 759 | + /* enable the interrupt */ | |
| 760 | + qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER); | |
| 761 | + | |
| 762 | + return 0; | |
| 763 | +} | |
| 764 | + | |
| 765 | +static const char *fsl_qspi_get_name(struct spi_mem *mem) | |
| 766 | +{ | |
| 767 | + struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master); | |
| 768 | + struct device *dev = &mem->spi->dev; | |
| 769 | + const char *name; | |
| 770 | + | |
| 771 | + /* | |
| 772 | + * In order to keep mtdparts compatible with the old MTD driver at | |
| 773 | + * mtd/spi-nor/fsl-quadspi.c, we set a custom name derived from the | |
| 774 | + * platform_device of the controller. | |
| 775 | + */ | |
| 776 | + if (of_get_available_child_count(q->dev->of_node) == 1) | |
| 777 | + return dev_name(q->dev); | |
| 778 | + | |
| 779 | + name = devm_kasprintf(dev, GFP_KERNEL, | |
| 780 | + "%s-%d", dev_name(q->dev), | |
| 781 | + mem->spi->chip_select); | |
| 782 | + | |
| 783 | + if (!name) { | |
| 784 | + dev_err(dev, "failed to get memory for custom flash name\n"); | |
| 785 | + return ERR_PTR(-ENOMEM); | |
| 786 | + } | |
| 787 | + | |
| 788 | + return name; | |
| 789 | +} | |
| 790 | + | |
| 791 | +static const struct spi_controller_mem_ops fsl_qspi_mem_ops = { | |
| 792 | + .adjust_op_size = fsl_qspi_adjust_op_size, | |
| 793 | + .supports_op = fsl_qspi_supports_op, | |
| 794 | + .exec_op = fsl_qspi_exec_op, | |
| 795 | + .get_name = fsl_qspi_get_name, | |
| 796 | +}; | |
| 797 | + | |
| 798 | +static int fsl_qspi_probe(struct platform_device *pdev) | |
| 799 | +{ | |
| 800 | + struct spi_controller *ctlr; | |
| 801 | + struct device *dev = &pdev->dev; | |
| 802 | + struct device_node *np = dev->of_node; | |
| 803 | + struct resource *res; | |
| 804 | + struct fsl_qspi *q; | |
| 805 | + int ret; | |
| 806 | + | |
| 807 | + ctlr = spi_alloc_master(&pdev->dev, sizeof(*q)); | |
| 808 | + if (!ctlr) | |
| 809 | + return -ENOMEM; | |
| 810 | + | |
| 811 | + ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | | |
| 812 | + SPI_TX_DUAL | SPI_TX_QUAD; | |
| 813 | + | |
| 814 | + q = spi_controller_get_devdata(ctlr); | |
| 815 | + q->dev = dev; | |
| 816 | + q->devtype_data = of_device_get_match_data(dev); | |
| 817 | + if (!q->devtype_data) { | |
| 818 | + ret = -ENODEV; | |
| 819 | + goto err_put_ctrl; | |
| 820 | + } | |
| 821 | + | |
| 822 | + platform_set_drvdata(pdev, q); | |
| 823 | + | |
| 824 | + /* find the resources */ | |
| 825 | + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI"); | |
| 826 | + q->iobase = devm_ioremap_resource(dev, res); | |
| 827 | + if (IS_ERR(q->iobase)) { | |
| 828 | + ret = PTR_ERR(q->iobase); | |
| 829 | + goto err_put_ctrl; | |
| 830 | + } | |
| 831 | + | |
| 832 | + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | |
| 833 | + "QuadSPI-memory"); | |
| 834 | + q->ahb_addr = devm_ioremap_resource(dev, res); | |
| 835 | + if (IS_ERR(q->ahb_addr)) { | |
| 836 | + ret = PTR_ERR(q->ahb_addr); | |
| 837 | + goto err_put_ctrl; | |
| 838 | + } | |
| 839 | + | |
| 840 | + q->memmap_phy = res->start; | |
| 841 | + | |
| 842 | + /* find the clocks */ | |
| 843 | + q->clk_en = devm_clk_get(dev, "qspi_en"); | |
| 844 | + if (IS_ERR(q->clk_en)) { | |
| 845 | + ret = PTR_ERR(q->clk_en); | |
| 846 | + goto err_put_ctrl; | |
| 847 | + } | |
| 848 | + | |
| 849 | + q->clk = devm_clk_get(dev, "qspi"); | |
| 850 | + if (IS_ERR(q->clk)) { | |
| 851 | + ret = PTR_ERR(q->clk); | |
| 852 | + goto err_put_ctrl; | |
| 853 | + } | |
| 854 | + | |
| 855 | + ret = fsl_qspi_clk_prep_enable(q); | |
| 856 | + if (ret) { | |
| 857 | + dev_err(dev, "can not enable the clock\n"); | |
| 858 | + goto err_put_ctrl; | |
| 859 | + } | |
| 860 | + | |
| 861 | + /* find the irq */ | |
| 862 | + ret = platform_get_irq(pdev, 0); | |
| 863 | + if (ret < 0) { | |
| 864 | + dev_err(dev, "failed to get the irq: %d\n", ret); | |
| 865 | + goto err_disable_clk; | |
| 866 | + } | |
| 867 | + | |
| 868 | + ret = devm_request_irq(dev, ret, | |
| 869 | + fsl_qspi_irq_handler, 0, pdev->name, q); | |
| 870 | + if (ret) { | |
| 871 | + dev_err(dev, "failed to request irq: %d\n", ret); | |
| 872 | + goto err_disable_clk; | |
| 873 | + } | |
| 874 | + | |
| 875 | + mutex_init(&q->lock); | |
| 876 | + | |
| 877 | + ctlr->bus_num = -1; | |
| 878 | + ctlr->num_chipselect = 4; | |
| 879 | + ctlr->mem_ops = &fsl_qspi_mem_ops; | |
| 880 | + | |
| 881 | + fsl_qspi_default_setup(q); | |
| 882 | + | |
| 883 | + ctlr->dev.of_node = np; | |
| 884 | + | |
| 885 | + ret = spi_register_controller(ctlr); | |
| 886 | + if (ret) | |
| 887 | + goto err_destroy_mutex; | |
| 888 | + | |
| 889 | + return 0; | |
| 890 | + | |
| 891 | +err_destroy_mutex: | |
| 892 | + mutex_destroy(&q->lock); | |
| 893 | + | |
| 894 | +err_disable_clk: | |
| 895 | + fsl_qspi_clk_disable_unprep(q); | |
| 896 | + | |
| 897 | +err_put_ctrl: | |
| 898 | + spi_controller_put(ctlr); | |
| 899 | + | |
| 900 | + dev_err(dev, "Freescale QuadSPI probe failed\n"); | |
| 901 | + return ret; | |
| 902 | +} | |
| 903 | + | |
| 904 | +static int fsl_qspi_remove(struct platform_device *pdev) | |
| 905 | +{ | |
| 906 | + struct fsl_qspi *q = platform_get_drvdata(pdev); | |
| 907 | + | |
| 908 | + /* disable the hardware */ | |
| 909 | + qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR); | |
| 910 | + qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER); | |
| 911 | + | |
| 912 | + fsl_qspi_clk_disable_unprep(q); | |
| 913 | + | |
| 914 | + mutex_destroy(&q->lock); | |
| 915 | + | |
| 916 | + return 0; | |
| 917 | +} | |
| 918 | + | |
| 919 | +static int fsl_qspi_suspend(struct device *dev) | |
| 920 | +{ | |
| 921 | + return 0; | |
| 922 | +} | |
| 923 | + | |
| 924 | +static int fsl_qspi_resume(struct device *dev) | |
| 925 | +{ | |
| 926 | + struct fsl_qspi *q = dev_get_drvdata(dev); | |
| 927 | + | |
| 928 | + fsl_qspi_default_setup(q); | |
| 929 | + | |
| 930 | + return 0; | |
| 931 | +} | |
| 932 | + | |
| 933 | +static const struct of_device_id fsl_qspi_dt_ids[] = { | |
| 934 | + { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, }, | |
| 935 | + { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, }, | |
| 936 | + { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, }, | |
| 937 | + { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, }, | |
| 938 | + { .compatible = "fsl,ls1021a-qspi", .data = &ls1021a_data, }, | |
| 939 | + { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, }, | |
| 940 | + { /* sentinel */ } | |
| 941 | +}; | |
| 942 | +MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids); | |
| 943 | + | |
| 944 | +static const struct dev_pm_ops fsl_qspi_pm_ops = { | |
| 945 | + .suspend = fsl_qspi_suspend, | |
| 946 | + .resume = fsl_qspi_resume, | |
| 947 | +}; | |
| 948 | + | |
| 949 | +static struct platform_driver fsl_qspi_driver = { | |
| 950 | + .driver = { | |
| 951 | + .name = "fsl-quadspi", | |
| 952 | + .of_match_table = fsl_qspi_dt_ids, | |
| 953 | + .pm = &fsl_qspi_pm_ops, | |
| 954 | + }, | |
| 955 | + .probe = fsl_qspi_probe, | |
| 956 | + .remove = fsl_qspi_remove, | |
| 957 | +}; | |
| 958 | +module_platform_driver(fsl_qspi_driver); | |
| 959 | + | |
| 960 | +MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver"); | |
| 961 | +MODULE_AUTHOR("Freescale Semiconductor Inc."); | |
| 962 | +MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>"); | |
| 963 | +MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>"); | |
| 964 | +MODULE_AUTHOR("Yogesh Gaur <yogeshnarayan.gaur@nxp.com>"); | |
| 965 | +MODULE_AUTHOR("Suresh Gupta <suresh.gupta@nxp.com>"); | |
| 966 | +MODULE_LICENSE("GPL v2"); | |
| @@ -89,9 +89,6 @@ struct spi_geni_master { · 88 unmodified lines | ||
| 89 | 89 | int irq; |
| 90 | 90 | }; |
| 91 | 91 | |
| 92 | −static void handle_fifo_timeout(struct spi_master *spi, | |
| 93 | − struct spi_message *msg); | |
| 94 | − | |
| 95 | 92 | static int get_spi_clk_cfg(unsigned int speed_hz, |
| 96 | 93 | struct spi_geni_master *mas, |
| 97 | 94 | unsigned int *clk_idx, |
| @@ -122,6 +119,32 @@ static int get_spi_clk_cfg(unsigned int speed_hz, · 24 unmodified lines | ||
| 122 | 119 | return ret; |
| 123 | 120 | } |
| 124 | 121 | |
| 122 | +static void handle_fifo_timeout(struct spi_master *spi, | |
| 123 | + struct spi_message *msg) | |
| 124 | +{ | |
| 125 | + struct spi_geni_master *mas = spi_master_get_devdata(spi); | |
| 126 | + unsigned long time_left, flags; | |
| 127 | + struct geni_se *se = &mas->se; | |
| 128 | + | |
| 129 | + spin_lock_irqsave(&mas->lock, flags); | |
| 130 | + reinit_completion(&mas->xfer_done); | |
| 131 | + mas->cur_mcmd = CMD_CANCEL; | |
| 132 | + geni_se_cancel_m_cmd(se); | |
| 133 | + writel(0, se->base + SE_GENI_TX_WATERMARK_REG); | |
| 134 | + spin_unlock_irqrestore(&mas->lock, flags); | |
| 135 | + time_left = wait_for_completion_timeout(&mas->xfer_done, HZ); | |
| 136 | + if (time_left) | |
| 137 | + return; | |
| 138 | + | |
| 139 | + spin_lock_irqsave(&mas->lock, flags); | |
| 140 | + reinit_completion(&mas->xfer_done); | |
| 141 | + geni_se_abort_m_cmd(se); | |
| 142 | + spin_unlock_irqrestore(&mas->lock, flags); | |
| 143 | + time_left = wait_for_completion_timeout(&mas->xfer_done, HZ); | |
| 144 | + if (!time_left) | |
| 145 | + dev_err(mas->dev, "Failed to cancel/abort m_cmd\n"); | |
| 146 | +} | |
| 147 | + | |
| 125 | 148 | static void spi_geni_set_cs(struct spi_device *slv, bool set_flag) |
| 126 | 149 | { |
| 127 | 150 | struct spi_geni_master *mas = spi_master_get_devdata(slv->master); |
| @@ -233,7 +256,6 @@ static int spi_geni_prepare_message(struct spi_master *spi, · 105 unmodified lines | ||
| 233 | 256 | struct geni_se *se = &mas->se; |
| 234 | 257 | |
| 235 | 258 | geni_se_select_mode(se, GENI_SE_FIFO); |
| 236 | − reinit_completion(&mas->xfer_done); | |
| 237 | 259 | ret = setup_fifo_params(spi_msg->spi, spi); |
| 238 | 260 | if (ret) |
| 239 | 261 | dev_err(mas->dev, "Couldn't select mode %d\n", ret); |
| @@ -357,32 +379,6 @@ static void setup_fifo_xfer(struct spi_transfer *xfer, · 117 unmodified lines | ||
| 357 | 379 | writel(mas->tx_wm, se->base + SE_GENI_TX_WATERMARK_REG); |
| 358 | 380 | } |
| 359 | 381 | |
| 360 | −static void handle_fifo_timeout(struct spi_master *spi, | |
| 361 | − struct spi_message *msg) | |
| 362 | −{ | |
| 363 | − struct spi_geni_master *mas = spi_master_get_devdata(spi); | |
| 364 | − unsigned long time_left, flags; | |
| 365 | − struct geni_se *se = &mas->se; | |
| 366 | − | |
| 367 | − spin_lock_irqsave(&mas->lock, flags); | |
| 368 | − reinit_completion(&mas->xfer_done); | |
| 369 | − mas->cur_mcmd = CMD_CANCEL; | |
| 370 | − geni_se_cancel_m_cmd(se); | |
| 371 | − writel(0, se->base + SE_GENI_TX_WATERMARK_REG); | |
| 372 | − spin_unlock_irqrestore(&mas->lock, flags); | |
| 373 | − time_left = wait_for_completion_timeout(&mas->xfer_done, HZ); | |
| 374 | − if (time_left) | |
| 375 | − return; | |
| 376 | − | |
| 377 | − spin_lock_irqsave(&mas->lock, flags); | |
| 378 | − reinit_completion(&mas->xfer_done); | |
| 379 | − geni_se_abort_m_cmd(se); | |
| 380 | − spin_unlock_irqrestore(&mas->lock, flags); | |
| 381 | − time_left = wait_for_completion_timeout(&mas->xfer_done, HZ); | |
| 382 | − if (!time_left) | |
| 383 | − dev_err(mas->dev, "Failed to cancel/abort m_cmd\n"); | |
| 384 | −} | |
| 385 | − | |
| 386 | 382 | static int spi_geni_transfer_one(struct spi_master *spi, |
| 387 | 383 | struct spi_device *slv, |
| 388 | 384 | struct spi_transfer *xfer) |
| @@ -428,7 +428,8 @@ static int spi_gpio_probe(struct platform_device *pdev) · 427 unmodified lines | ||
| 428 | 428 | return status; |
| 429 | 429 | |
| 430 | 430 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); |
| 431 | − master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL; | |
| 431 | + master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL | | |
| 432 | + SPI_CS_HIGH; | |
| 432 | 433 | master->flags = master_flags; |
| 433 | 434 | master->bus_num = pdev->id; |
| 434 | 435 | /* The master needs to think there is a chipselect even if not connected */ |
| @@ -455,7 +456,6 @@ static int spi_gpio_probe(struct platform_device *pdev) · 20 unmodified lines | ||
| 455 | 456 | spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; |
| 456 | 457 | } |
| 457 | 458 | spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; |
| 458 | − spi_gpio->bitbang.flags = SPI_CS_HIGH; | |
| 459 | 459 | |
| 460 | 460 | status = spi_bitbang_start(&spi_gpio->bitbang); |
| 461 | 461 | if (status) |
| @@ -537,7 +537,6 @@ EXPORT_SYMBOL_GPL(spi_mem_dirmap_create); · 536 unmodified lines | ||
| 537 | 537 | /** |
| 538 | 538 | * spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor |
| 539 | 539 | * @desc: the direct mapping descriptor to destroy |
| 540 | − * @info: direct mapping information | |
| 541 | 540 | * |
| 542 | 541 | * This function destroys a direct mapping descriptor previously created by |
| 543 | 542 | * spi_mem_dirmap_create(). |
| @@ -548,9 +547,80 @@ void spi_mem_dirmap_destroy(struct spi_mem_dirmap_desc *desc) · 4 unmodified lines | ||
| 548 | 547 | |
| 549 | 548 | if (!desc->nodirmap && ctlr->mem_ops && ctlr->mem_ops->dirmap_destroy) |
| 550 | 549 | ctlr->mem_ops->dirmap_destroy(desc); |
| 550 | + | |
| 551 | + kfree(desc); | |
| 551 | 552 | } |
| 552 | 553 | EXPORT_SYMBOL_GPL(spi_mem_dirmap_destroy); |
| 553 | 554 | |
| 555 | +static void devm_spi_mem_dirmap_release(struct device *dev, void *res) | |
| 556 | +{ | |
| 557 | + struct spi_mem_dirmap_desc *desc = *(struct spi_mem_dirmap_desc **)res; | |
| 558 | + | |
| 559 | + spi_mem_dirmap_destroy(desc); | |
| 560 | +} | |
| 561 | + | |
| 562 | +/** | |
| 563 | + * devm_spi_mem_dirmap_create() - Create a direct mapping descriptor and attach | |
| 564 | + * it to a device | |
| 565 | + * @dev: device the dirmap desc will be attached to | |
| 566 | + * @mem: SPI mem device this direct mapping should be created for | |
| 567 | + * @info: direct mapping information | |
| 568 | + * | |
| 569 | + * devm_ variant of the spi_mem_dirmap_create() function. See | |
| 570 | + * spi_mem_dirmap_create() for more details. | |
| 571 | + * | |
| 572 | + * Return: a valid pointer in case of success, and ERR_PTR() otherwise. | |
| 573 | + */ | |
| 574 | +struct spi_mem_dirmap_desc * | |
| 575 | +devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, | |
| 576 | + const struct spi_mem_dirmap_info *info) | |
| 577 | +{ | |
| 578 | + struct spi_mem_dirmap_desc **ptr, *desc; | |
| 579 | + | |
| 580 | + ptr = devres_alloc(devm_spi_mem_dirmap_release, sizeof(*ptr), | |
| 581 | + GFP_KERNEL); | |
| 582 | + if (!ptr) | |
| 583 | + return ERR_PTR(-ENOMEM); | |
| 584 | + | |
| 585 | + desc = spi_mem_dirmap_create(mem, info); | |
| 586 | + if (IS_ERR(desc)) { | |
| 587 | + devres_free(ptr); | |
| 588 | + } else { | |
| 589 | + *ptr = desc; | |
| 590 | + devres_add(dev, ptr); | |
| 591 | + } | |
| 592 | + | |
| 593 | + return desc; | |
| 594 | +} | |
| 595 | +EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_create); | |
| 596 | + | |
| 597 | +static int devm_spi_mem_dirmap_match(struct device *dev, void *res, void *data) | |
| 598 | +{ | |
| 599 | + struct spi_mem_dirmap_desc **ptr = res; | |
| 600 | + | |
| 601 | + if (WARN_ON(!ptr || !*ptr)) | |
| 602 | + return 0; | |
| 603 | + | |
| 604 | + return *ptr == data; | |
| 605 | +} | |
| 606 | + | |
| 607 | +/** | |
| 608 | + * devm_spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor attached | |
| 609 | + * to a device | |
| 610 | + * @dev: device the dirmap desc is attached to | |
| 611 | + * @desc: the direct mapping descriptor to destroy | |
| 612 | + * | |
| 613 | + * devm_ variant of the spi_mem_dirmap_destroy() function. See | |
| 614 | + * spi_mem_dirmap_destroy() for more details. | |
| 615 | + */ | |
| 616 | +void devm_spi_mem_dirmap_destroy(struct device *dev, | |
| 617 | + struct spi_mem_dirmap_desc *desc) | |
| 618 | +{ | |
| 619 | + devres_release(dev, devm_spi_mem_dirmap_release, | |
| 620 | + devm_spi_mem_dirmap_match, desc); | |
| 621 | +} | |
| 622 | +EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_destroy); | |
| 623 | + | |
| 554 | 624 | /** |
| 555 | 625 | * spi_mem_dirmap_dirmap_read() - Read data through a direct mapping |
| 556 | 626 | * @desc: direct mapping descriptor |
| @@ -39,6 +39,7 @@ · 38 unmodified lines | ||
| 39 | 39 | #include <linux/stmp_device.h> |
| 40 | 40 | #include <linux/spi/spi.h> |
| 41 | 41 | #include <linux/spi/mxs-spi.h> |
| 42 | +#include <trace/events/spi.h> | |
| 42 | 43 | |
| 43 | 44 | #define DRIVER_NAME "mxs-spi" |
| 44 | 45 | |
| @@ -374,6 +375,8 @@ static int mxs_spi_transfer_one(struct spi_master *master, · 329 unmodified lines | ||
| 374 | 375 | |
| 375 | 376 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 376 | 377 | |
| 378 | + trace_spi_transfer_start(m, t); | |
| 379 | + | |
| 377 | 380 | status = mxs_spi_setup_transfer(m->spi, t); |
| 378 | 381 | if (status) |
| 379 | 382 | break; |
| @@ -419,6 +422,8 @@ static int mxs_spi_transfer_one(struct spi_master *master, · 39 unmodified lines | ||
| 419 | 422 | flag); |
| 420 | 423 | } |
| 421 | 424 | |
| 425 | + trace_spi_transfer_stop(m, t); | |
| 426 | + | |
| 422 | 427 | if (status) { |
| 423 | 428 | stmp_reset_block(ssp->base); |
| 424 | 429 | break; |
| @@ -465,7 +465,8 @@ out_master_put: · 464 unmodified lines | ||
| 465 | 465 | |
| 466 | 466 | static int npcm_pspi_remove(struct platform_device *pdev) |
| 467 | 467 | { |
| 468 | − struct npcm_pspi *priv = platform_get_drvdata(pdev); | |
| 468 | + struct spi_master *master = platform_get_drvdata(pdev); | |
| 469 | + struct npcm_pspi *priv = spi_master_get_devdata(master); | |
| 469 | 470 | |
| 470 | 471 | npcm_pspi_reset_hw(priv); |
| 471 | 472 | clk_disable_unprepare(priv->clk); |
| @@ -0,0 +1,1106 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0+ | |
| 2 | + | |
| 3 | +/* | |
| 4 | + * NXP FlexSPI(FSPI) controller driver. | |
| 5 | + * | |
| 6 | + * Copyright 2019 NXP. | |
| 7 | + * | |
| 8 | + * FlexSPI is a flexsible SPI host controller which supports two SPI | |
| 9 | + * channels and up to 4 external devices. Each channel supports | |
| 10 | + * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional | |
| 11 | + * data lines). | |
| 12 | + * | |
| 13 | + * FlexSPI controller is driven by the LUT(Look-up Table) registers | |
| 14 | + * LUT registers are a look-up-table for sequences of instructions. | |
| 15 | + * A valid sequence consists of four LUT registers. | |
| 16 | + * Maximum 32 LUT sequences can be programmed simultaneously. | |
| 17 | + * | |
| 18 | + * LUTs are being created at run-time based on the commands passed | |
| 19 | + * from the spi-mem framework, thus using single LUT index. | |
| 20 | + * | |
| 21 | + * Software triggered Flash read/write access by IP Bus. | |
| 22 | + * | |
| 23 | + * Memory mapped read access by AHB Bus. | |
| 24 | + * | |
| 25 | + * Based on SPI MEM interface and spi-fsl-qspi.c driver. | |
| 26 | + * | |
| 27 | + * Author: | |
| 28 | + * Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com> | |
| 29 | + * Boris Brezillon <bbrezillon@kernel.org> | |
| 30 | + * Frieder Schrempf <frieder.schrempf@kontron.de> | |
| 31 | + */ | |
| 32 | + | |
| 33 | +#include <linux/bitops.h> | |
| 34 | +#include <linux/clk.h> | |
| 35 | +#include <linux/completion.h> | |
| 36 | +#include <linux/delay.h> | |
| 37 | +#include <linux/err.h> | |
| 38 | +#include <linux/errno.h> | |
| 39 | +#include <linux/interrupt.h> | |
| 40 | +#include <linux/io.h> | |
| 41 | +#include <linux/iopoll.h> | |
| 42 | +#include <linux/jiffies.h> | |
| 43 | +#include <linux/kernel.h> | |
| 44 | +#include <linux/module.h> | |
| 45 | +#include <linux/mutex.h> | |
| 46 | +#include <linux/of.h> | |
| 47 | +#include <linux/of_device.h> | |
| 48 | +#include <linux/platform_device.h> | |
| 49 | +#include <linux/pm_qos.h> | |
| 50 | +#include <linux/sizes.h> | |
| 51 | + | |
| 52 | +#include <linux/spi/spi.h> | |
| 53 | +#include <linux/spi/spi-mem.h> | |
| 54 | + | |
| 55 | +/* | |
| 56 | + * The driver only uses one single LUT entry, that is updated on | |
| 57 | + * each call of exec_op(). Index 0 is preset at boot with a basic | |
| 58 | + * read operation, so let's use the last entry (31). | |
| 59 | + */ | |
| 60 | +#define SEQID_LUT 31 | |
| 61 | + | |
| 62 | +/* Registers used by the driver */ | |
| 63 | +#define FSPI_MCR0 0x00 | |
| 64 | +#define FSPI_MCR0_AHB_TIMEOUT(x) ((x) << 24) | |
| 65 | +#define FSPI_MCR0_IP_TIMEOUT(x) ((x) << 16) | |
| 66 | +#define FSPI_MCR0_LEARN_EN BIT(15) | |
| 67 | +#define FSPI_MCR0_SCRFRUN_EN BIT(14) | |
| 68 | +#define FSPI_MCR0_OCTCOMB_EN BIT(13) | |
| 69 | +#define FSPI_MCR0_DOZE_EN BIT(12) | |
| 70 | +#define FSPI_MCR0_HSEN BIT(11) | |
| 71 | +#define FSPI_MCR0_SERCLKDIV BIT(8) | |
| 72 | +#define FSPI_MCR0_ATDF_EN BIT(7) | |
| 73 | +#define FSPI_MCR0_ARDF_EN BIT(6) | |
| 74 | +#define FSPI_MCR0_RXCLKSRC(x) ((x) << 4) | |
| 75 | +#define FSPI_MCR0_END_CFG(x) ((x) << 2) | |
| 76 | +#define FSPI_MCR0_MDIS BIT(1) | |
| 77 | +#define FSPI_MCR0_SWRST BIT(0) | |
| 78 | + | |
| 79 | +#define FSPI_MCR1 0x04 | |
| 80 | +#define FSPI_MCR1_SEQ_TIMEOUT(x) ((x) << 16) | |
| 81 | +#define FSPI_MCR1_AHB_TIMEOUT(x) (x) | |
| 82 | + | |
| 83 | +#define FSPI_MCR2 0x08 | |
| 84 | +#define FSPI_MCR2_IDLE_WAIT(x) ((x) << 24) | |
| 85 | +#define FSPI_MCR2_SAMEDEVICEEN BIT(15) | |
| 86 | +#define FSPI_MCR2_CLRLRPHS BIT(14) | |
| 87 | +#define FSPI_MCR2_ABRDATSZ BIT(8) | |
| 88 | +#define FSPI_MCR2_ABRLEARN BIT(7) | |
| 89 | +#define FSPI_MCR2_ABR_READ BIT(6) | |
| 90 | +#define FSPI_MCR2_ABRWRITE BIT(5) | |
| 91 | +#define FSPI_MCR2_ABRDUMMY BIT(4) | |
| 92 | +#define FSPI_MCR2_ABR_MODE BIT(3) | |
| 93 | +#define FSPI_MCR2_ABRCADDR BIT(2) | |
| 94 | +#define FSPI_MCR2_ABRRADDR BIT(1) | |
| 95 | +#define FSPI_MCR2_ABR_CMD BIT(0) | |
| 96 | + | |
| 97 | +#define FSPI_AHBCR 0x0c | |
| 98 | +#define FSPI_AHBCR_RDADDROPT BIT(6) | |
| 99 | +#define FSPI_AHBCR_PREF_EN BIT(5) | |
| 100 | +#define FSPI_AHBCR_BUFF_EN BIT(4) | |
| 101 | +#define FSPI_AHBCR_CACH_EN BIT(3) | |
| 102 | +#define FSPI_AHBCR_CLRTXBUF BIT(2) | |
| 103 | +#define FSPI_AHBCR_CLRRXBUF BIT(1) | |
| 104 | +#define FSPI_AHBCR_PAR_EN BIT(0) | |
| 105 | + | |
| 106 | +#define FSPI_INTEN 0x10 | |
| 107 | +#define FSPI_INTEN_SCLKSBWR BIT(9) | |
| 108 | +#define FSPI_INTEN_SCLKSBRD BIT(8) | |
| 109 | +#define FSPI_INTEN_DATALRNFL BIT(7) | |
| 110 | +#define FSPI_INTEN_IPTXWE BIT(6) | |
| 111 | +#define FSPI_INTEN_IPRXWA BIT(5) | |
| 112 | +#define FSPI_INTEN_AHBCMDERR BIT(4) | |
| 113 | +#define FSPI_INTEN_IPCMDERR BIT(3) | |
| 114 | +#define FSPI_INTEN_AHBCMDGE BIT(2) | |
| 115 | +#define FSPI_INTEN_IPCMDGE BIT(1) | |
| 116 | +#define FSPI_INTEN_IPCMDDONE BIT(0) | |
| 117 | + | |
| 118 | +#define FSPI_INTR 0x14 | |
| 119 | +#define FSPI_INTR_SCLKSBWR BIT(9) | |
| 120 | +#define FSPI_INTR_SCLKSBRD BIT(8) | |
| 121 | +#define FSPI_INTR_DATALRNFL BIT(7) | |
| 122 | +#define FSPI_INTR_IPTXWE BIT(6) | |
| 123 | +#define FSPI_INTR_IPRXWA BIT(5) | |
| 124 | +#define FSPI_INTR_AHBCMDERR BIT(4) | |
| 125 | +#define FSPI_INTR_IPCMDERR BIT(3) | |
| 126 | +#define FSPI_INTR_AHBCMDGE BIT(2) | |
| 127 | +#define FSPI_INTR_IPCMDGE BIT(1) | |
| 128 | +#define FSPI_INTR_IPCMDDONE BIT(0) | |
| 129 | + | |
| 130 | +#define FSPI_LUTKEY 0x18 | |
| 131 | +#define FSPI_LUTKEY_VALUE 0x5AF05AF0 | |
| 132 | + | |
| 133 | +#define FSPI_LCKCR 0x1C | |
| 134 | + | |
| 135 | +#define FSPI_LCKER_LOCK 0x1 | |
| 136 | +#define FSPI_LCKER_UNLOCK 0x2 | |
| 137 | + | |
| 138 | +#define FSPI_BUFXCR_INVALID_MSTRID 0xE | |
| 139 | +#define FSPI_AHBRX_BUF0CR0 0x20 | |
| 140 | +#define FSPI_AHBRX_BUF1CR0 0x24 | |
| 141 | +#define FSPI_AHBRX_BUF2CR0 0x28 | |
| 142 | +#define FSPI_AHBRX_BUF3CR0 0x2C | |
| 143 | +#define FSPI_AHBRX_BUF4CR0 0x30 | |
| 144 | +#define FSPI_AHBRX_BUF5CR0 0x34 | |
| 145 | +#define FSPI_AHBRX_BUF6CR0 0x38 | |
| 146 | +#define FSPI_AHBRX_BUF7CR0 0x3C | |
| 147 | +#define FSPI_AHBRXBUF0CR7_PREF BIT(31) | |
| 148 | + | |
| 149 | +#define FSPI_AHBRX_BUF0CR1 0x40 | |
| 150 | +#define FSPI_AHBRX_BUF1CR1 0x44 | |
| 151 | +#define FSPI_AHBRX_BUF2CR1 0x48 | |
| 152 | +#define FSPI_AHBRX_BUF3CR1 0x4C | |
| 153 | +#define FSPI_AHBRX_BUF4CR1 0x50 | |
| 154 | +#define FSPI_AHBRX_BUF5CR1 0x54 | |
| 155 | +#define FSPI_AHBRX_BUF6CR1 0x58 | |
| 156 | +#define FSPI_AHBRX_BUF7CR1 0x5C | |
| 157 | + | |
| 158 | +#define FSPI_FLSHA1CR0 0x60 | |
| 159 | +#define FSPI_FLSHA2CR0 0x64 | |
| 160 | +#define FSPI_FLSHB1CR0 0x68 | |
| 161 | +#define FSPI_FLSHB2CR0 0x6C | |
| 162 | +#define FSPI_FLSHXCR0_SZ_KB 10 | |
| 163 | +#define FSPI_FLSHXCR0_SZ(x) ((x) >> FSPI_FLSHXCR0_SZ_KB) | |
| 164 | + | |
| 165 | +#define FSPI_FLSHA1CR1 0x70 | |
| 166 | +#define FSPI_FLSHA2CR1 0x74 | |
| 167 | +#define FSPI_FLSHB1CR1 0x78 | |
| 168 | +#define FSPI_FLSHB2CR1 0x7C | |
| 169 | +#define FSPI_FLSHXCR1_CSINTR(x) ((x) << 16) | |
| 170 | +#define FSPI_FLSHXCR1_CAS(x) ((x) << 11) | |
| 171 | +#define FSPI_FLSHXCR1_WA BIT(10) | |
| 172 | +#define FSPI_FLSHXCR1_TCSH(x) ((x) << 5) | |
| 173 | +#define FSPI_FLSHXCR1_TCSS(x) (x) | |
| 174 | + | |
| 175 | +#define FSPI_FLSHA1CR2 0x80 | |
| 176 | +#define FSPI_FLSHA2CR2 0x84 | |
| 177 | +#define FSPI_FLSHB1CR2 0x88 | |
| 178 | +#define FSPI_FLSHB2CR2 0x8C | |
| 179 | +#define FSPI_FLSHXCR2_CLRINSP BIT(24) | |
| 180 | +#define FSPI_FLSHXCR2_AWRWAIT BIT(16) | |
| 181 | +#define FSPI_FLSHXCR2_AWRSEQN_SHIFT 13 | |
| 182 | +#define FSPI_FLSHXCR2_AWRSEQI_SHIFT 8 | |
| 183 | +#define FSPI_FLSHXCR2_ARDSEQN_SHIFT 5 | |
| 184 | +#define FSPI_FLSHXCR2_ARDSEQI_SHIFT 0 | |
| 185 | + | |
| 186 | +#define FSPI_IPCR0 0xA0 | |
| 187 | + | |
| 188 | +#define FSPI_IPCR1 0xA4 | |
| 189 | +#define FSPI_IPCR1_IPAREN BIT(31) | |
| 190 | +#define FSPI_IPCR1_SEQNUM_SHIFT 24 | |
| 191 | +#define FSPI_IPCR1_SEQID_SHIFT 16 | |
| 192 | +#define FSPI_IPCR1_IDATSZ(x) (x) | |
| 193 | + | |
| 194 | +#define FSPI_IPCMD 0xB0 | |
| 195 | +#define FSPI_IPCMD_TRG BIT(0) | |
| 196 | + | |
| 197 | +#define FSPI_DLPR 0xB4 | |
| 198 | + | |
| 199 | +#define FSPI_IPRXFCR 0xB8 | |
| 200 | +#define FSPI_IPRXFCR_CLR BIT(0) | |
| 201 | +#define FSPI_IPRXFCR_DMA_EN BIT(1) | |
| 202 | +#define FSPI_IPRXFCR_WMRK(x) ((x) << 2) | |
| 203 | + | |
| 204 | +#define FSPI_IPTXFCR 0xBC | |
| 205 | +#define FSPI_IPTXFCR_CLR BIT(0) | |
| 206 | +#define FSPI_IPTXFCR_DMA_EN BIT(1) | |
| 207 | +#define FSPI_IPTXFCR_WMRK(x) ((x) << 2) | |
| 208 | + | |
| 209 | +#define FSPI_DLLACR 0xC0 | |
| 210 | +#define FSPI_DLLACR_OVRDEN BIT(8) | |
| 211 | + | |
| 212 | +#define FSPI_DLLBCR 0xC4 | |
| 213 | +#define FSPI_DLLBCR_OVRDEN BIT(8) | |
| 214 | + | |
| 215 | +#define FSPI_STS0 0xE0 | |
| 216 | +#define FSPI_STS0_DLPHB(x) ((x) << 8) | |
| 217 | +#define FSPI_STS0_DLPHA(x) ((x) << 4) | |
| 218 | +#define FSPI_STS0_CMD_SRC(x) ((x) << 2) | |
| 219 | +#define FSPI_STS0_ARB_IDLE BIT(1) | |
| 220 | +#define FSPI_STS0_SEQ_IDLE BIT(0) | |
| 221 | + | |
| 222 | +#define FSPI_STS1 0xE4 | |
| 223 | +#define FSPI_STS1_IP_ERRCD(x) ((x) << 24) | |
| 224 | +#define FSPI_STS1_IP_ERRID(x) ((x) << 16) | |
| 225 | +#define FSPI_STS1_AHB_ERRCD(x) ((x) << 8) | |
| 226 | +#define FSPI_STS1_AHB_ERRID(x) (x) | |
| 227 | + | |
| 228 | +#define FSPI_AHBSPNST 0xEC | |
| 229 | +#define FSPI_AHBSPNST_DATLFT(x) ((x) << 16) | |
| 230 | +#define FSPI_AHBSPNST_BUFID(x) ((x) << 1) | |
| 231 | +#define FSPI_AHBSPNST_ACTIVE BIT(0) | |
| 232 | + | |
| 233 | +#define FSPI_IPRXFSTS 0xF0 | |
| 234 | +#define FSPI_IPRXFSTS_RDCNTR(x) ((x) << 16) | |
| 235 | +#define FSPI_IPRXFSTS_FILL(x) (x) | |
| 236 | + | |
| 237 | +#define FSPI_IPTXFSTS 0xF4 | |
| 238 | +#define FSPI_IPTXFSTS_WRCNTR(x) ((x) << 16) | |
| 239 | +#define FSPI_IPTXFSTS_FILL(x) (x) | |
| 240 | + | |
| 241 | +#define FSPI_RFDR 0x100 | |
| 242 | +#define FSPI_TFDR 0x180 | |
| 243 | + | |
| 244 | +#define FSPI_LUT_BASE 0x200 | |
| 245 | +#define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4) | |
| 246 | +#define FSPI_LUT_REG(idx) \ | |
| 247 | + (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4) | |
| 248 | + | |
| 249 | +/* register map end */ | |
| 250 | + | |
| 251 | +/* Instruction set for the LUT register. */ | |
| 252 | +#define LUT_STOP 0x00 | |
| 253 | +#define LUT_CMD 0x01 | |
| 254 | +#define LUT_ADDR 0x02 | |
| 255 | +#define LUT_CADDR_SDR 0x03 | |
| 256 | +#define LUT_MODE 0x04 | |
| 257 | +#define LUT_MODE2 0x05 | |
| 258 | +#define LUT_MODE4 0x06 | |
| 259 | +#define LUT_MODE8 0x07 | |
| 260 | +#define LUT_NXP_WRITE 0x08 | |
| 261 | +#define LUT_NXP_READ 0x09 | |
| 262 | +#define LUT_LEARN_SDR 0x0A | |
| 263 | +#define LUT_DATSZ_SDR 0x0B | |
| 264 | +#define LUT_DUMMY 0x0C | |
| 265 | +#define LUT_DUMMY_RWDS_SDR 0x0D | |
| 266 | +#define LUT_JMP_ON_CS 0x1F | |
| 267 | +#define LUT_CMD_DDR 0x21 | |
| 268 | +#define LUT_ADDR_DDR 0x22 | |
| 269 | +#define LUT_CADDR_DDR 0x23 | |
| 270 | +#define LUT_MODE_DDR 0x24 | |
| 271 | +#define LUT_MODE2_DDR 0x25 | |
| 272 | +#define LUT_MODE4_DDR 0x26 | |
| 273 | +#define LUT_MODE8_DDR 0x27 | |
| 274 | +#define LUT_WRITE_DDR 0x28 | |
| 275 | +#define LUT_READ_DDR 0x29 | |
| 276 | +#define LUT_LEARN_DDR 0x2A | |
| 277 | +#define LUT_DATSZ_DDR 0x2B | |
| 278 | +#define LUT_DUMMY_DDR 0x2C | |
| 279 | +#define LUT_DUMMY_RWDS_DDR 0x2D | |
| 280 | + | |
| 281 | +/* | |
| 282 | + * Calculate number of required PAD bits for LUT register. | |
| 283 | + * | |
| 284 | + * The pad stands for the number of IO lines [0:7]. | |
| 285 | + * For example, the octal read needs eight IO lines, | |
| 286 | + * so you should use LUT_PAD(8). This macro | |
| 287 | + * returns 3 i.e. use eight (2^3) IP lines for read. | |
| 288 | + */ | |
| 289 | +#define LUT_PAD(x) (fls(x) - 1) | |
| 290 | + | |
| 291 | +/* | |
| 292 | + * Macro for constructing the LUT entries with the following | |
| 293 | + * register layout: | |
| 294 | + * | |
| 295 | + * --------------------------------------------------- | |
| 296 | + * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 | | |
| 297 | + * --------------------------------------------------- | |
| 298 | + */ | |
| 299 | +#define PAD_SHIFT 8 | |
| 300 | +#define INSTR_SHIFT 10 | |
| 301 | +#define OPRND_SHIFT 16 | |
| 302 | + | |
| 303 | +/* Macros for constructing the LUT register. */ | |
| 304 | +#define LUT_DEF(idx, ins, pad, opr) \ | |
| 305 | + ((((ins) << INSTR_SHIFT) | ((pad) << PAD_SHIFT) | \ | |
| 306 | + (opr)) << (((idx) % 2) * OPRND_SHIFT)) | |
| 307 | + | |
| 308 | +#define POLL_TOUT 5000 | |
| 309 | +#define NXP_FSPI_MAX_CHIPSELECT 4 | |
| 310 | + | |
| 311 | +struct nxp_fspi_devtype_data { | |
| 312 | + unsigned int rxfifo; | |
| 313 | + unsigned int txfifo; | |
| 314 | + unsigned int ahb_buf_size; | |
| 315 | + unsigned int quirks; | |
| 316 | + bool little_endian; | |
| 317 | +}; | |
| 318 | + | |
| 319 | +static const struct nxp_fspi_devtype_data lx2160a_data = { | |
| 320 | + .rxfifo = SZ_512, /* (64 * 64 bits) */ | |
| 321 | + .txfifo = SZ_1K, /* (128 * 64 bits) */ | |
| 322 | + .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */ | |
| 323 | + .quirks = 0, | |
| 324 | + .little_endian = true, /* little-endian */ | |
| 325 | +}; | |
| 326 | + | |
| 327 | +struct nxp_fspi { | |
| 328 | + void __iomem *iobase; | |
| 329 | + void __iomem *ahb_addr; | |
| 330 | + u32 memmap_phy; | |
| 331 | + u32 memmap_phy_size; | |
| 332 | + struct clk *clk, *clk_en; | |
| 333 | + struct device *dev; | |
| 334 | + struct completion c; | |
| 335 | + const struct nxp_fspi_devtype_data *devtype_data; | |
| 336 | + struct mutex lock; | |
| 337 | + struct pm_qos_request pm_qos_req; | |
| 338 | + int selected; | |
| 339 | +}; | |
| 340 | + | |
| 341 | +/* | |
| 342 | + * R/W functions for big- or little-endian registers: | |
| 343 | + * The FSPI controller's endianness is independent of | |
| 344 | + * the CPU core's endianness. So far, although the CPU | |
| 345 | + * core is little-endian the FSPI controller can use | |
| 346 | + * big-endian or little-endian. | |
| 347 | + */ | |
| 348 | +static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr) | |
| 349 | +{ | |
| 350 | + if (f->devtype_data->little_endian) | |
| 351 | + iowrite32(val, addr); | |
| 352 | + else | |
| 353 | + iowrite32be(val, addr); | |
| 354 | +} | |
| 355 | + | |
| 356 | +static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) | |
| 357 | +{ | |
| 358 | + if (f->devtype_data->little_endian) | |
| 359 | + return ioread32(addr); | |
| 360 | + else | |
| 361 | + return ioread32be(addr); | |
| 362 | +} | |
| 363 | + | |
| 364 | +static irqreturn_t nxp_fspi_irq_handler(int irq, void *dev_id) | |
| 365 | +{ | |
| 366 | + struct nxp_fspi *f = dev_id; | |
| 367 | + u32 reg; | |
| 368 | + | |
| 369 | + /* clear interrupt */ | |
| 370 | + reg = fspi_readl(f, f->iobase + FSPI_INTR); | |
| 371 | + fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR); | |
| 372 | + | |
| 373 | + if (reg & FSPI_INTR_IPCMDDONE) | |
| 374 | + complete(&f->c); | |
| 375 | + | |
| 376 | + return IRQ_HANDLED; | |
| 377 | +} | |
| 378 | + | |
| 379 | +static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width) | |
| 380 | +{ | |
| 381 | + switch (width) { | |
| 382 | + case 1: | |
| 383 | + case 2: | |
| 384 | + case 4: | |
| 385 | + case 8: | |
| 386 | + return 0; | |
| 387 | + } | |
| 388 | + | |
| 389 | + return -ENOTSUPP; | |
| 390 | +} | |
| 391 | + | |
| 392 | +static bool nxp_fspi_supports_op(struct spi_mem *mem, | |
| 393 | + const struct spi_mem_op *op) | |
| 394 | +{ | |
| 395 | + struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); | |
| 396 | + int ret; | |
| 397 | + | |
| 398 | + ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth); | |
| 399 | + | |
| 400 | + if (op->addr.nbytes) | |
| 401 | + ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth); | |
| 402 | + | |
| 403 | + if (op->dummy.nbytes) | |
| 404 | + ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth); | |
| 405 | + | |
| 406 | + if (op->data.nbytes) | |
| 407 | + ret |= nxp_fspi_check_buswidth(f, op->data.buswidth); | |
| 408 | + | |
| 409 | + if (ret) | |
| 410 | + return false; | |
| 411 | + | |
| 412 | + /* | |
| 413 | + * The number of address bytes should be equal to or less than 4 bytes. | |
| 414 | + */ | |
| 415 | + if (op->addr.nbytes > 4) | |
| 416 | + return false; | |
| 417 | + | |
| 418 | + /* | |
| 419 | + * If requested address value is greater than controller assigned | |
| 420 | + * memory mapped space, return error as it didn't fit in the range | |
| 421 | + * of assigned address space. | |
| 422 | + */ | |
| 423 | + if (op->addr.val >= f->memmap_phy_size) | |
| 424 | + return false; | |
| 425 | + | |
| 426 | + /* Max 64 dummy clock cycles supported */ | |
| 427 | + if (op->dummy.buswidth && | |
| 428 | + (op->dummy.nbytes * 8 / op->dummy.buswidth > 64)) | |
| 429 | + return false; | |
| 430 | + | |
| 431 | + /* Max data length, check controller limits and alignment */ | |
| 432 | + if (op->data.dir == SPI_MEM_DATA_IN && | |
| 433 | + (op->data.nbytes > f->devtype_data->ahb_buf_size || | |
| 434 | + (op->data.nbytes > f->devtype_data->rxfifo - 4 && | |
| 435 | + !IS_ALIGNED(op->data.nbytes, 8)))) | |
| 436 | + return false; | |
| 437 | + | |
| 438 | + if (op->data.dir == SPI_MEM_DATA_OUT && | |
| 439 | + op->data.nbytes > f->devtype_data->txfifo) | |
| 440 | + return false; | |
| 441 | + | |
| 442 | + return true; | |
| 443 | +} | |
| 444 | + | |
| 445 | +/* Instead of busy looping invoke readl_poll_timeout functionality. */ | |
| 446 | +static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base, | |
| 447 | + u32 mask, u32 delay_us, | |
| 448 | + u32 timeout_us, bool c) | |
| 449 | +{ | |
| 450 | + u32 reg; | |
| 451 | + | |
| 452 | + if (!f->devtype_data->little_endian) | |
| 453 | + mask = (u32)cpu_to_be32(mask); | |
| 454 | + | |
| 455 | + if (c) | |
| 456 | + return readl_poll_timeout(base, reg, (reg & mask), | |
| 457 | + delay_us, timeout_us); | |
| 458 | + else | |
| 459 | + return readl_poll_timeout(base, reg, !(reg & mask), | |
| 460 | + delay_us, timeout_us); | |
| 461 | +} | |
| 462 | + | |
| 463 | +/* | |
| 464 | + * If the slave device content being changed by Write/Erase, need to | |
| 465 | + * invalidate the AHB buffer. This can be achieved by doing the reset | |
| 466 | + * of controller after setting MCR0[SWRESET] bit. | |
| 467 | + */ | |
| 468 | +static inline void nxp_fspi_invalid(struct nxp_fspi *f) | |
| 469 | +{ | |
| 470 | + u32 reg; | |
| 471 | + int ret; | |
| 472 | + | |
| 473 | + reg = fspi_readl(f, f->iobase + FSPI_MCR0); | |
| 474 | + fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0); | |
| 475 | + | |
| 476 | + /* w1c register, wait unit clear */ | |
| 477 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, | |
| 478 | + FSPI_MCR0_SWRST, 0, POLL_TOUT, false); | |
| 479 | + WARN_ON(ret); | |
| 480 | +} | |
| 481 | + | |
| 482 | +static void nxp_fspi_prepare_lut(struct nxp_fspi *f, | |
| 483 | + const struct spi_mem_op *op) | |
| 484 | +{ | |
| 485 | + void __iomem *base = f->iobase; | |
| 486 | + u32 lutval[4] = {}; | |
| 487 | + int lutidx = 1, i; | |
| 488 | + | |
| 489 | + /* cmd */ | |
| 490 | + lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth), | |
| 491 | + op->cmd.opcode); | |
| 492 | + | |
| 493 | + /* addr bytes */ | |
| 494 | + if (op->addr.nbytes) { | |
| 495 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_ADDR, | |
| 496 | + LUT_PAD(op->addr.buswidth), | |
| 497 | + op->addr.nbytes * 8); | |
| 498 | + lutidx++; | |
| 499 | + } | |
| 500 | + | |
| 501 | + /* dummy bytes, if needed */ | |
| 502 | + if (op->dummy.nbytes) { | |
| 503 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, | |
| 504 | + /* | |
| 505 | + * Due to FlexSPI controller limitation number of PAD for dummy | |
| 506 | + * buswidth needs to be programmed as equal to data buswidth. | |
| 507 | + */ | |
| 508 | + LUT_PAD(op->data.buswidth), | |
| 509 | + op->dummy.nbytes * 8 / | |
| 510 | + op->dummy.buswidth); | |
| 511 | + lutidx++; | |
| 512 | + } | |
| 513 | + | |
| 514 | + /* read/write data bytes */ | |
| 515 | + if (op->data.nbytes) { | |
| 516 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, | |
| 517 | + op->data.dir == SPI_MEM_DATA_IN ? | |
| 518 | + LUT_NXP_READ : LUT_NXP_WRITE, | |
| 519 | + LUT_PAD(op->data.buswidth), | |
| 520 | + 0); | |
| 521 | + lutidx++; | |
| 522 | + } | |
| 523 | + | |
| 524 | + /* stop condition. */ | |
| 525 | + lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0); | |
| 526 | + | |
| 527 | + /* unlock LUT */ | |
| 528 | + fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); | |
| 529 | + fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR); | |
| 530 | + | |
| 531 | + /* fill LUT */ | |
| 532 | + for (i = 0; i < ARRAY_SIZE(lutval); i++) | |
| 533 | + fspi_writel(f, lutval[i], base + FSPI_LUT_REG(i)); | |
| 534 | + | |
| 535 | + dev_dbg(f->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n", | |
| 536 | + op->cmd.opcode, lutval[0], lutval[1], lutval[2], lutval[3]); | |
| 537 | + | |
| 538 | + /* lock LUT */ | |
| 539 | + fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY); | |
| 540 | + fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR); | |
| 541 | +} | |
| 542 | + | |
| 543 | +static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f) | |
| 544 | +{ | |
| 545 | + int ret; | |
| 546 | + | |
| 547 | + ret = clk_prepare_enable(f->clk_en); | |
| 548 | + if (ret) | |
| 549 | + return ret; | |
| 550 | + | |
| 551 | + ret = clk_prepare_enable(f->clk); | |
| 552 | + if (ret) { | |
| 553 | + clk_disable_unprepare(f->clk_en); | |
| 554 | + return ret; | |
| 555 | + } | |
| 556 | + | |
| 557 | + return 0; | |
| 558 | +} | |
| 559 | + | |
| 560 | +static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *f) | |
| 561 | +{ | |
| 562 | + clk_disable_unprepare(f->clk); | |
| 563 | + clk_disable_unprepare(f->clk_en); | |
| 564 | +} | |
| 565 | + | |
| 566 | +/* | |
| 567 | + * In FlexSPI controller, flash access is based on value of FSPI_FLSHXXCR0 | |
| 568 | + * register and start base address of the slave device. | |
| 569 | + * | |
| 570 | + * (Higher address) | |
| 571 | + * -------- <-- FLSHB2CR0 | |
| 572 | + * | B2 | | |
| 573 | + * | | | |
| 574 | + * B2 start address --> -------- <-- FLSHB1CR0 | |
| 575 | + * | B1 | | |
| 576 | + * | | | |
| 577 | + * B1 start address --> -------- <-- FLSHA2CR0 | |
| 578 | + * | A2 | | |
| 579 | + * | | | |
| 580 | + * A2 start address --> -------- <-- FLSHA1CR0 | |
| 581 | + * | A1 | | |
| 582 | + * | | | |
| 583 | + * A1 start address --> -------- (Lower address) | |
| 584 | + * | |
| 585 | + * | |
| 586 | + * Start base address defines the starting address range for given CS and | |
| 587 | + * FSPI_FLSHXXCR0 defines the size of the slave device connected at given CS. | |
| 588 | + * | |
| 589 | + * But, different targets are having different combinations of number of CS, | |
| 590 | + * some targets only have single CS or two CS covering controller's full | |
| 591 | + * memory mapped space area. | |
| 592 | + * Thus, implementation is being done as independent of the size and number | |
| 593 | + * of the connected slave device. | |
| 594 | + * Assign controller memory mapped space size as the size to the connected | |
| 595 | + * slave device. | |
| 596 | + * Mark FLSHxxCR0 as zero initially and then assign value only to the selected | |
| 597 | + * chip-select Flash configuration register. | |
| 598 | + * | |
| 599 | + * For e.g. to access CS2 (B1), FLSHB1CR0 register would be equal to the | |
| 600 | + * memory mapped size of the controller. | |
| 601 | + * Value for rest of the CS FLSHxxCR0 register would be zero. | |
| 602 | + * | |
| 603 | + */ | |
| 604 | +static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi) | |
| 605 | +{ | |
| 606 | + unsigned long rate = spi->max_speed_hz; | |
| 607 | + int ret; | |
| 608 | + uint64_t size_kb; | |
| 609 | + | |
| 610 | + /* | |
| 611 | + * Return, if previously selected slave device is same as current | |
| 612 | + * requested slave device. | |
| 613 | + */ | |
| 614 | + if (f->selected == spi->chip_select) | |
| 615 | + return; | |
| 616 | + | |
| 617 | + /* Reset FLSHxxCR0 registers */ | |
| 618 | + fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0); | |
| 619 | + fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0); | |
| 620 | + fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0); | |
| 621 | + fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0); | |
| 622 | + | |
| 623 | + /* Assign controller memory mapped space as size, KBytes, of flash. */ | |
| 624 | + size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size); | |
| 625 | + | |
| 626 | + fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 + | |
| 627 | + 4 * spi->chip_select); | |
| 628 | + | |
| 629 | + dev_dbg(f->dev, "Slave device [CS:%x] selected\n", spi->chip_select); | |
| 630 | + | |
| 631 | + nxp_fspi_clk_disable_unprep(f); | |
| 632 | + | |
| 633 | + ret = clk_set_rate(f->clk, rate); | |
| 634 | + if (ret) | |
| 635 | + return; | |
| 636 | + | |
| 637 | + ret = nxp_fspi_clk_prep_enable(f); | |
| 638 | + if (ret) | |
| 639 | + return; | |
| 640 | + | |
| 641 | + f->selected = spi->chip_select; | |
| 642 | +} | |
| 643 | + | |
| 644 | +static void nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op) | |
| 645 | +{ | |
| 646 | + u32 len = op->data.nbytes; | |
| 647 | + | |
| 648 | + /* Read out the data directly from the AHB buffer. */ | |
| 649 | + memcpy_fromio(op->data.buf.in, (f->ahb_addr + op->addr.val), len); | |
| 650 | +} | |
| 651 | + | |
| 652 | +static void nxp_fspi_fill_txfifo(struct nxp_fspi *f, | |
| 653 | + const struct spi_mem_op *op) | |
| 654 | +{ | |
| 655 | + void __iomem *base = f->iobase; | |
| 656 | + int i, ret; | |
| 657 | + u8 *buf = (u8 *) op->data.buf.out; | |
| 658 | + | |
| 659 | + /* clear the TX FIFO. */ | |
| 660 | + fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR); | |
| 661 | + | |
| 662 | + /* | |
| 663 | + * Default value of water mark level is 8 bytes, hence in single | |
| 664 | + * write request controller can write max 8 bytes of data. | |
| 665 | + */ | |
| 666 | + | |
| 667 | + for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 8); i += 8) { | |
| 668 | + /* Wait for TXFIFO empty */ | |
| 669 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, | |
| 670 | + FSPI_INTR_IPTXWE, 0, | |
| 671 | + POLL_TOUT, true); | |
| 672 | + WARN_ON(ret); | |
| 673 | + | |
| 674 | + fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR); | |
| 675 | + fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4); | |
| 676 | + fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); | |
| 677 | + } | |
| 678 | + | |
| 679 | + if (i < op->data.nbytes) { | |
| 680 | + u32 data = 0; | |
| 681 | + int j; | |
| 682 | + /* Wait for TXFIFO empty */ | |
| 683 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, | |
| 684 | + FSPI_INTR_IPTXWE, 0, | |
| 685 | + POLL_TOUT, true); | |
| 686 | + WARN_ON(ret); | |
| 687 | + | |
| 688 | + for (j = 0; j < ALIGN(op->data.nbytes - i, 4); j += 4) { | |
| 689 | + memcpy(&data, buf + i + j, 4); | |
| 690 | + fspi_writel(f, data, base + FSPI_TFDR + j); | |
| 691 | + } | |
| 692 | + fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR); | |
| 693 | + } | |
| 694 | +} | |
| 695 | + | |
| 696 | +static void nxp_fspi_read_rxfifo(struct nxp_fspi *f, | |
| 697 | + const struct spi_mem_op *op) | |
| 698 | +{ | |
| 699 | + void __iomem *base = f->iobase; | |
| 700 | + int i, ret; | |
| 701 | + int len = op->data.nbytes; | |
| 702 | + u8 *buf = (u8 *) op->data.buf.in; | |
| 703 | + | |
| 704 | + /* | |
| 705 | + * Default value of water mark level is 8 bytes, hence in single | |
| 706 | + * read request controller can read max 8 bytes of data. | |
| 707 | + */ | |
| 708 | + for (i = 0; i < ALIGN_DOWN(len, 8); i += 8) { | |
| 709 | + /* Wait for RXFIFO available */ | |
| 710 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, | |
| 711 | + FSPI_INTR_IPRXWA, 0, | |
| 712 | + POLL_TOUT, true); | |
| 713 | + WARN_ON(ret); | |
| 714 | + | |
| 715 | + *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR); | |
| 716 | + *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4); | |
| 717 | + /* move the FIFO pointer */ | |
| 718 | + fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); | |
| 719 | + } | |
| 720 | + | |
| 721 | + if (i < len) { | |
| 722 | + u32 tmp; | |
| 723 | + int size, j; | |
| 724 | + | |
| 725 | + buf = op->data.buf.in + i; | |
| 726 | + /* Wait for RXFIFO available */ | |
| 727 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR, | |
| 728 | + FSPI_INTR_IPRXWA, 0, | |
| 729 | + POLL_TOUT, true); | |
| 730 | + WARN_ON(ret); | |
| 731 | + | |
| 732 | + len = op->data.nbytes - i; | |
| 733 | + for (j = 0; j < op->data.nbytes - i; j += 4) { | |
| 734 | + tmp = fspi_readl(f, base + FSPI_RFDR + j); | |
| 735 | + size = min(len, 4); | |
| 736 | + memcpy(buf + j, &tmp, size); | |
| 737 | + len -= size; | |
| 738 | + } | |
| 739 | + } | |
| 740 | + | |
| 741 | + /* invalid the RXFIFO */ | |
| 742 | + fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR); | |
| 743 | + /* move the FIFO pointer */ | |
| 744 | + fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR); | |
| 745 | +} | |
| 746 | + | |
| 747 | +static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op) | |
| 748 | +{ | |
| 749 | + void __iomem *base = f->iobase; | |
| 750 | + int seqnum = 0; | |
| 751 | + int err = 0; | |
| 752 | + u32 reg; | |
| 753 | + | |
| 754 | + reg = fspi_readl(f, base + FSPI_IPRXFCR); | |
| 755 | + /* invalid RXFIFO first */ | |
| 756 | + reg &= ~FSPI_IPRXFCR_DMA_EN; | |
| 757 | + reg = reg | FSPI_IPRXFCR_CLR; | |
| 758 | + fspi_writel(f, reg, base + FSPI_IPRXFCR); | |
| 759 | + | |
| 760 | + init_completion(&f->c); | |
| 761 | + | |
| 762 | + fspi_writel(f, op->addr.val, base + FSPI_IPCR0); | |
| 763 | + /* | |
| 764 | + * Always start the sequence at the same index since we update | |
| 765 | + * the LUT at each exec_op() call. And also specify the DATA | |
| 766 | + * length, since it's has not been specified in the LUT. | |
| 767 | + */ | |
| 768 | + fspi_writel(f, op->data.nbytes | | |
| 769 | + (SEQID_LUT << FSPI_IPCR1_SEQID_SHIFT) | | |
| 770 | + (seqnum << FSPI_IPCR1_SEQNUM_SHIFT), | |
| 771 | + base + FSPI_IPCR1); | |
| 772 | + | |
| 773 | + /* Trigger the LUT now. */ | |
| 774 | + fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD); | |
| 775 | + | |
| 776 | + /* Wait for the interrupt. */ | |
| 777 | + if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000))) | |
| 778 | + err = -ETIMEDOUT; | |
| 779 | + | |
| 780 | + /* Invoke IP data read, if request is of data read. */ | |
| 781 | + if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN) | |
| 782 | + nxp_fspi_read_rxfifo(f, op); | |
| 783 | + | |
| 784 | + return err; | |
| 785 | +} | |
| 786 | + | |
| 787 | +static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) | |
| 788 | +{ | |
| 789 | + struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); | |
| 790 | + int err = 0; | |
| 791 | + | |
| 792 | + mutex_lock(&f->lock); | |
| 793 | + | |
| 794 | + /* Wait for controller being ready. */ | |
| 795 | + err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0, | |
| 796 | + FSPI_STS0_ARB_IDLE, 1, POLL_TOUT, true); | |
| 797 | + WARN_ON(err); | |
| 798 | + | |
| 799 | + nxp_fspi_select_mem(f, mem->spi); | |
| 800 | + | |
| 801 | + nxp_fspi_prepare_lut(f, op); | |
| 802 | + /* | |
| 803 | + * If we have large chunks of data, we read them through the AHB bus | |
| 804 | + * by accessing the mapped memory. In all other cases we use | |
| 805 | + * IP commands to access the flash. | |
| 806 | + */ | |
| 807 | + if (op->data.nbytes > (f->devtype_data->rxfifo - 4) && | |
| 808 | + op->data.dir == SPI_MEM_DATA_IN) { | |
| 809 | + nxp_fspi_read_ahb(f, op); | |
| 810 | + } else { | |
| 811 | + if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT) | |
| 812 | + nxp_fspi_fill_txfifo(f, op); | |
| 813 | + | |
| 814 | + err = nxp_fspi_do_op(f, op); | |
| 815 | + } | |
| 816 | + | |
| 817 | + /* Invalidate the data in the AHB buffer. */ | |
| 818 | + nxp_fspi_invalid(f); | |
| 819 | + | |
| 820 | + mutex_unlock(&f->lock); | |
| 821 | + | |
| 822 | + return err; | |
| 823 | +} | |
| 824 | + | |
| 825 | +static int nxp_fspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) | |
| 826 | +{ | |
| 827 | + struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); | |
| 828 | + | |
| 829 | + if (op->data.dir == SPI_MEM_DATA_OUT) { | |
| 830 | + if (op->data.nbytes > f->devtype_data->txfifo) | |
| 831 | + op->data.nbytes = f->devtype_data->txfifo; | |
| 832 | + } else { | |
| 833 | + if (op->data.nbytes > f->devtype_data->ahb_buf_size) | |
| 834 | + op->data.nbytes = f->devtype_data->ahb_buf_size; | |
| 835 | + else if (op->data.nbytes > (f->devtype_data->rxfifo - 4)) | |
| 836 | + op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8); | |
| 837 | + } | |
| 838 | + | |
| 839 | + return 0; | |
| 840 | +} | |
| 841 | + | |
| 842 | +static int nxp_fspi_default_setup(struct nxp_fspi *f) | |
| 843 | +{ | |
| 844 | + void __iomem *base = f->iobase; | |
| 845 | + int ret, i; | |
| 846 | + u32 reg; | |
| 847 | + | |
| 848 | + /* disable and unprepare clock to avoid glitch pass to controller */ | |
| 849 | + nxp_fspi_clk_disable_unprep(f); | |
| 850 | + | |
| 851 | + /* the default frequency, we will change it later if necessary. */ | |
| 852 | + ret = clk_set_rate(f->clk, 20000000); | |
| 853 | + if (ret) | |
| 854 | + return ret; | |
| 855 | + | |
| 856 | + ret = nxp_fspi_clk_prep_enable(f); | |
| 857 | + if (ret) | |
| 858 | + return ret; | |
| 859 | + | |
| 860 | + /* Reset the module */ | |
| 861 | + /* w1c register, wait unit clear */ | |
| 862 | + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0, | |
| 863 | + FSPI_MCR0_SWRST, 0, POLL_TOUT, false); | |
| 864 | + WARN_ON(ret); | |
| 865 | + | |
| 866 | + /* Disable the module */ | |
| 867 | + fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0); | |
| 868 | + | |
| 869 | + /* Reset the DLL register to default value */ | |
| 870 | + fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR); | |
| 871 | + fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR); | |
| 872 | + | |
| 873 | + /* enable module */ | |
| 874 | + fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | FSPI_MCR0_IP_TIMEOUT(0xFF), | |
| 875 | + base + FSPI_MCR0); | |
| 876 | + | |
| 877 | + /* | |
| 878 | + * Disable same device enable bit and configure all slave devices | |
| 879 | + * independently. | |
| 880 | + */ | |
| 881 | + reg = fspi_readl(f, f->iobase + FSPI_MCR2); | |
| 882 | + reg = reg & ~(FSPI_MCR2_SAMEDEVICEEN); | |
| 883 | + fspi_writel(f, reg, base + FSPI_MCR2); | |
| 884 | + | |
| 885 | + /* AHB configuration for access buffer 0~7. */ | |
| 886 | + for (i = 0; i < 7; i++) | |
| 887 | + fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i); | |
| 888 | + | |
| 889 | + /* | |
| 890 | + * Set ADATSZ with the maximum AHB buffer size to improve the read | |
| 891 | + * performance. | |
| 892 | + */ | |
| 893 | + fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 | | |
| 894 | + FSPI_AHBRXBUF0CR7_PREF), base + FSPI_AHBRX_BUF7CR0); | |
| 895 | + | |
| 896 | + /* prefetch and no start address alignment limitation */ | |
| 897 | + fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT, | |
| 898 | + base + FSPI_AHBCR); | |
| 899 | + | |
| 900 | + /* AHB Read - Set lut sequence ID for all CS. */ | |
| 901 | + fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA1CR2); | |
| 902 | + fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA2CR2); | |
| 903 | + fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB1CR2); | |
| 904 | + fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB2CR2); | |
| 905 | + | |
| 906 | + f->selected = -1; | |
| 907 | + | |
| 908 | + /* enable the interrupt */ | |
| 909 | + fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN); | |
| 910 | + | |
| 911 | + return 0; | |
| 912 | +} | |
| 913 | + | |
| 914 | +static const char *nxp_fspi_get_name(struct spi_mem *mem) | |
| 915 | +{ | |
| 916 | + struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master); | |
| 917 | + struct device *dev = &mem->spi->dev; | |
| 918 | + const char *name; | |
| 919 | + | |
| 920 | + // Set custom name derived from the platform_device of the controller. | |
| 921 | + if (of_get_available_child_count(f->dev->of_node) == 1) | |
| 922 | + return dev_name(f->dev); | |
| 923 | + | |
| 924 | + name = devm_kasprintf(dev, GFP_KERNEL, | |
| 925 | + "%s-%d", dev_name(f->dev), | |
| 926 | + mem->spi->chip_select); | |
| 927 | + | |
| 928 | + if (!name) { | |
| 929 | + dev_err(dev, "failed to get memory for custom flash name\n"); | |
| 930 | + return ERR_PTR(-ENOMEM); | |
| 931 | + } | |
| 932 | + | |
| 933 | + return name; | |
| 934 | +} | |
| 935 | + | |
| 936 | +static const struct spi_controller_mem_ops nxp_fspi_mem_ops = { | |
| 937 | + .adjust_op_size = nxp_fspi_adjust_op_size, | |
| 938 | + .supports_op = nxp_fspi_supports_op, | |
| 939 | + .exec_op = nxp_fspi_exec_op, | |
| 940 | + .get_name = nxp_fspi_get_name, | |
| 941 | +}; | |
| 942 | + | |
| 943 | +static int nxp_fspi_probe(struct platform_device *pdev) | |
| 944 | +{ | |
| 945 | + struct spi_controller *ctlr; | |
| 946 | + struct device *dev = &pdev->dev; | |
| 947 | + struct device_node *np = dev->of_node; | |
| 948 | + struct resource *res; | |
| 949 | + struct nxp_fspi *f; | |
| 950 | + int ret; | |
| 951 | + | |
| 952 | + ctlr = spi_alloc_master(&pdev->dev, sizeof(*f)); | |
| 953 | + if (!ctlr) | |
| 954 | + return -ENOMEM; | |
| 955 | + | |
| 956 | + ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL | | |
| 957 | + SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL; | |
| 958 | + | |
| 959 | + f = spi_controller_get_devdata(ctlr); | |
| 960 | + f->dev = dev; | |
| 961 | + f->devtype_data = of_device_get_match_data(dev); | |
| 962 | + if (!f->devtype_data) { | |
| 963 | + ret = -ENODEV; | |
| 964 | + goto err_put_ctrl; | |
| 965 | + } | |
| 966 | + | |
| 967 | + platform_set_drvdata(pdev, f); | |
| 968 | + | |
| 969 | + /* find the resources - configuration register address space */ | |
| 970 | + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_base"); | |
| 971 | + f->iobase = devm_ioremap_resource(dev, res); | |
| 972 | + if (IS_ERR(f->iobase)) { | |
| 973 | + ret = PTR_ERR(f->iobase); | |
| 974 | + goto err_put_ctrl; | |
| 975 | + } | |
| 976 | + | |
| 977 | + /* find the resources - controller memory mapped space */ | |
| 978 | + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_mmap"); | |
| 979 | + f->ahb_addr = devm_ioremap_resource(dev, res); | |
| 980 | + if (IS_ERR(f->ahb_addr)) { | |
| 981 | + ret = PTR_ERR(f->ahb_addr); | |
| 982 | + goto err_put_ctrl; | |
| 983 | + } | |
| 984 | + | |
| 985 | + /* assign memory mapped starting address and mapped size. */ | |
| 986 | + f->memmap_phy = res->start; | |
| 987 | + f->memmap_phy_size = resource_size(res); | |
| 988 | + | |
| 989 | + /* find the clocks */ | |
| 990 | + f->clk_en = devm_clk_get(dev, "fspi_en"); | |
| 991 | + if (IS_ERR(f->clk_en)) { | |
| 992 | + ret = PTR_ERR(f->clk_en); | |
| 993 | + goto err_put_ctrl; | |
| 994 | + } | |
| 995 | + | |
| 996 | + f->clk = devm_clk_get(dev, "fspi"); | |
| 997 | + if (IS_ERR(f->clk)) { | |
| 998 | + ret = PTR_ERR(f->clk); | |
| 999 | + goto err_put_ctrl; | |
| 1000 | + } | |
| 1001 | + | |
| 1002 | + ret = nxp_fspi_clk_prep_enable(f); | |
| 1003 | + if (ret) { | |
| 1004 | + dev_err(dev, "can not enable the clock\n"); | |
| 1005 | + goto err_put_ctrl; | |
| 1006 | + } | |
| 1007 | + | |
| 1008 | + /* find the irq */ | |
| 1009 | + ret = platform_get_irq(pdev, 0); | |
| 1010 | + if (ret < 0) { | |
| 1011 | + dev_err(dev, "failed to get the irq: %d\n", ret); | |
| 1012 | + goto err_disable_clk; | |
| 1013 | + } | |
| 1014 | + | |
| 1015 | + ret = devm_request_irq(dev, ret, | |
| 1016 | + nxp_fspi_irq_handler, 0, pdev->name, f); | |
| 1017 | + if (ret) { | |
| 1018 | + dev_err(dev, "failed to request irq: %d\n", ret); | |
| 1019 | + goto err_disable_clk; | |
| 1020 | + } | |
| 1021 | + | |
| 1022 | + mutex_init(&f->lock); | |
| 1023 | + | |
| 1024 | + ctlr->bus_num = -1; | |
| 1025 | + ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT; | |
| 1026 | + ctlr->mem_ops = &nxp_fspi_mem_ops; | |
| 1027 | + | |
| 1028 | + nxp_fspi_default_setup(f); | |
| 1029 | + | |
| 1030 | + ctlr->dev.of_node = np; | |
| 1031 | + | |
| 1032 | + ret = spi_register_controller(ctlr); | |
| 1033 | + if (ret) | |
| 1034 | + goto err_destroy_mutex; | |
| 1035 | + | |
| 1036 | + return 0; | |
| 1037 | + | |
| 1038 | +err_destroy_mutex: | |
| 1039 | + mutex_destroy(&f->lock); | |
| 1040 | + | |
| 1041 | +err_disable_clk: | |
| 1042 | + nxp_fspi_clk_disable_unprep(f); | |
| 1043 | + | |
| 1044 | +err_put_ctrl: | |
| 1045 | + spi_controller_put(ctlr); | |
| 1046 | + | |
| 1047 | + dev_err(dev, "NXP FSPI probe failed\n"); | |
| 1048 | + return ret; | |
| 1049 | +} | |
| 1050 | + | |
| 1051 | +static int nxp_fspi_remove(struct platform_device *pdev) | |
| 1052 | +{ | |
| 1053 | + struct nxp_fspi *f = platform_get_drvdata(pdev); | |
| 1054 | + | |
| 1055 | + /* disable the hardware */ | |
| 1056 | + fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0); | |
| 1057 | + | |
| 1058 | + nxp_fspi_clk_disable_unprep(f); | |
| 1059 | + | |
| 1060 | + mutex_destroy(&f->lock); | |
| 1061 | + | |
| 1062 | + return 0; | |
| 1063 | +} | |
| 1064 | + | |
| 1065 | +static int nxp_fspi_suspend(struct device *dev) | |
| 1066 | +{ | |
| 1067 | + return 0; | |
| 1068 | +} | |
| 1069 | + | |
| 1070 | +static int nxp_fspi_resume(struct device *dev) | |
| 1071 | +{ | |
| 1072 | + struct nxp_fspi *f = dev_get_drvdata(dev); | |
| 1073 | + | |
| 1074 | + nxp_fspi_default_setup(f); | |
| 1075 | + | |
| 1076 | + return 0; | |
| 1077 | +} | |
| 1078 | + | |
| 1079 | +static const struct of_device_id nxp_fspi_dt_ids[] = { | |
| 1080 | + { .compatible = "nxp,lx2160a-fspi", .data = (void *)&lx2160a_data, }, | |
| 1081 | + { /* sentinel */ } | |
| 1082 | +}; | |
| 1083 | +MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids); | |
| 1084 | + | |
| 1085 | +static const struct dev_pm_ops nxp_fspi_pm_ops = { | |
| 1086 | + .suspend = nxp_fspi_suspend, | |
| 1087 | + .resume = nxp_fspi_resume, | |
| 1088 | +}; | |
| 1089 | + | |
| 1090 | +static struct platform_driver nxp_fspi_driver = { | |
| 1091 | + .driver = { | |
| 1092 | + .name = "nxp-fspi", | |
| 1093 | + .of_match_table = nxp_fspi_dt_ids, | |
| 1094 | + .pm = &nxp_fspi_pm_ops, | |
| 1095 | + }, | |
| 1096 | + .probe = nxp_fspi_probe, | |
| 1097 | + .remove = nxp_fspi_remove, | |
| 1098 | +}; | |
| 1099 | +module_platform_driver(nxp_fspi_driver); | |
| 1100 | + | |
| 1101 | +MODULE_DESCRIPTION("NXP FSPI Controller Driver"); | |
| 1102 | +MODULE_AUTHOR("NXP Semiconductor"); | |
| 1103 | +MODULE_AUTHOR("Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>"); | |
| 1104 | +MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>"); | |
| 1105 | +MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>"); | |
| 1106 | +MODULE_LICENSE("GPL v2"); | |
| @@ -623,8 +623,8 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) · 622 unmodified lines | ||
| 623 | 623 | cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0; |
| 624 | 624 | cfg.src_addr_width = width; |
| 625 | 625 | cfg.dst_addr_width = width; |
| 626 | − cfg.src_maxburst = es; | |
| 627 | − cfg.dst_maxburst = es; | |
| 626 | + cfg.src_maxburst = 1; | |
| 627 | + cfg.dst_maxburst = 1; | |
| 628 | 628 | |
| 629 | 629 | rx = xfer->rx_buf; |
| 630 | 630 | tx = xfer->tx_buf; |
| @@ -253,6 +253,7 @@ · 252 unmodified lines | ||
| 253 | 253 | #define STATE_RUNNING ((void *) 1) |
| 254 | 254 | #define STATE_DONE ((void *) 2) |
| 255 | 255 | #define STATE_ERROR ((void *) -1) |
| 256 | +#define STATE_TIMEOUT ((void *) -2) | |
| 256 | 257 | |
| 257 | 258 | /* |
| 258 | 259 | * SSP State - Whether Enabled or Disabled |
| @@ -1484,6 +1485,30 @@ err_config_dma: · 1225 unmodified lines | ||
| 1484 | 1485 | writew(irqflags, SSP_IMSC(pl022->virtbase)); |
| 1485 | 1486 | } |
| 1486 | 1487 | |
| 1488 | +static void print_current_status(struct pl022 *pl022) | |
| 1489 | +{ | |
| 1490 | + u32 read_cr0; | |
| 1491 | + u16 read_cr1, read_dmacr, read_sr; | |
| 1492 | + | |
| 1493 | + if (pl022->vendor->extended_cr) | |
| 1494 | + read_cr0 = readl(SSP_CR0(pl022->virtbase)); | |
| 1495 | + else | |
| 1496 | + read_cr0 = readw(SSP_CR0(pl022->virtbase)); | |
| 1497 | + read_cr1 = readw(SSP_CR1(pl022->virtbase)); | |
| 1498 | + read_dmacr = readw(SSP_DMACR(pl022->virtbase)); | |
| 1499 | + read_sr = readw(SSP_SR(pl022->virtbase)); | |
| 1500 | + | |
| 1501 | + dev_warn(&pl022->adev->dev, "spi-pl022 CR0: %x\n", read_cr0); | |
| 1502 | + dev_warn(&pl022->adev->dev, "spi-pl022 CR1: %x\n", read_cr1); | |
| 1503 | + dev_warn(&pl022->adev->dev, "spi-pl022 DMACR: %x\n", read_dmacr); | |
| 1504 | + dev_warn(&pl022->adev->dev, "spi-pl022 SR: %x\n", read_sr); | |
| 1505 | + dev_warn(&pl022->adev->dev, | |
| 1506 | + "spi-pl022 exp_fifo_level/fifodepth: %u/%d\n", | |
| 1507 | + pl022->exp_fifo_level, | |
| 1508 | + pl022->vendor->fifodepth); | |
| 1509 | + | |
| 1510 | +} | |
| 1511 | + | |
| 1487 | 1512 | static void do_polling_transfer(struct pl022 *pl022) |
| 1488 | 1513 | { |
| 1489 | 1514 | struct spi_message *message = NULL; |
| @@ -1535,7 +1560,8 @@ static void do_polling_transfer(struct pl022 *pl022) · 45 unmodified lines | ||
| 1535 | 1560 | if (time_after(time, timeout)) { |
| 1536 | 1561 | dev_warn(&pl022->adev->dev, |
| 1537 | 1562 | "%s: timeout!\n", __func__); |
| 1538 | − message->state = STATE_ERROR; | |
| 1563 | + message->state = STATE_TIMEOUT; | |
| 1564 | + print_current_status(pl022); | |
| 1539 | 1565 | goto out; |
| 1540 | 1566 | } |
| 1541 | 1567 | cpu_relax(); |
| @@ -1553,6 +1579,8 @@ out: · 11 unmodified lines | ||
| 1553 | 1579 | /* Handle end of message */ |
| 1554 | 1580 | if (message->state == STATE_DONE) |
| 1555 | 1581 | message->status = 0; |
| 1582 | + else if (message->state == STATE_TIMEOUT) | |
| 1583 | + message->status = -EAGAIN; | |
| 1556 | 1584 | else |
| 1557 | 1585 | message->status = -EIO; |
| 1558 | 1586 | |
| @@ -23,7 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, |
| 24 | 24 | bool error) |
| 25 | 25 | { |
| 26 | − struct spi_message *msg = drv_data->master->cur_msg; | |
| 26 | + struct spi_message *msg = drv_data->controller->cur_msg; | |
| 27 | 27 | |
| 28 | 28 | /* |
| 29 | 29 | * It is possible that one CPU is handling ROR interrupt and other |
| @@ -59,7 +59,7 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 29 unmodified lines | ||
| 59 | 59 | msg->status = -EIO; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | − spi_finalize_current_transfer(drv_data->master); | |
| 62 | + spi_finalize_current_transfer(drv_data->controller); | |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| @@ -74,7 +74,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 8 unmodified lines | ||
| 74 | 74 | struct spi_transfer *xfer) |
| 75 | 75 | { |
| 76 | 76 | struct chip_data *chip = |
| 77 | − spi_get_ctldata(drv_data->master->cur_msg->spi); | |
| 77 | + spi_get_ctldata(drv_data->controller->cur_msg->spi); | |
| 78 | 78 | enum dma_slave_buswidth width; |
| 79 | 79 | struct dma_slave_config cfg; |
| 80 | 80 | struct dma_chan *chan; |
| @@ -102,14 +102,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 21 unmodified lines | ||
| 102 | 102 | cfg.dst_maxburst = chip->dma_burst_size; |
| 103 | 103 | |
| 104 | 104 | sgt = &xfer->tx_sg; |
| 105 | − chan = drv_data->master->dma_tx; | |
| 105 | + chan = drv_data->controller->dma_tx; | |
| 106 | 106 | } else { |
| 107 | 107 | cfg.src_addr = drv_data->ssdr_physical; |
| 108 | 108 | cfg.src_addr_width = width; |
| 109 | 109 | cfg.src_maxburst = chip->dma_burst_size; |
| 110 | 110 | |
| 111 | 111 | sgt = &xfer->rx_sg; |
| 112 | − chan = drv_data->master->dma_rx; | |
| 112 | + chan = drv_data->controller->dma_rx; | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | ret = dmaengine_slave_config(chan, &cfg); |
| @@ -130,8 +130,8 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) · 14 unmodified lines | ||
| 130 | 130 | if (status & SSSR_ROR) { |
| 131 | 131 | dev_err(&drv_data->pdev->dev, "FIFO overrun\n"); |
| 132 | 132 | |
| 133 | − dmaengine_terminate_async(drv_data->master->dma_rx); | |
| 134 | − dmaengine_terminate_async(drv_data->master->dma_tx); | |
| 133 | + dmaengine_terminate_async(drv_data->controller->dma_rx); | |
| 134 | + dmaengine_terminate_async(drv_data->controller->dma_tx); | |
| 135 | 135 | |
| 136 | 136 | pxa2xx_spi_dma_transfer_complete(drv_data, true); |
| 137 | 137 | return IRQ_HANDLED; |
| @@ -171,15 +171,15 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, · 33 unmodified lines | ||
| 171 | 171 | return 0; |
| 172 | 172 | |
| 173 | 173 | err_rx: |
| 174 | − dmaengine_terminate_async(drv_data->master->dma_tx); | |
| 174 | + dmaengine_terminate_async(drv_data->controller->dma_tx); | |
| 175 | 175 | err_tx: |
| 176 | 176 | return err; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | void pxa2xx_spi_dma_start(struct driver_data *drv_data) |
| 180 | 180 | { |
| 181 | − dma_async_issue_pending(drv_data->master->dma_rx); | |
| 182 | − dma_async_issue_pending(drv_data->master->dma_tx); | |
| 181 | + dma_async_issue_pending(drv_data->controller->dma_rx); | |
| 182 | + dma_async_issue_pending(drv_data->controller->dma_tx); | |
| 183 | 183 | |
| 184 | 184 | atomic_set(&drv_data->dma_running, 1); |
| 185 | 185 | } |
| @@ -187,30 +187,30 @@ void pxa2xx_spi_dma_start(struct driver_data *drv_data) · 1 unmodified line | ||
| 187 | 187 | void pxa2xx_spi_dma_stop(struct driver_data *drv_data) |
| 188 | 188 | { |
| 189 | 189 | atomic_set(&drv_data->dma_running, 0); |
| 190 | − dmaengine_terminate_sync(drv_data->master->dma_rx); | |
| 191 | − dmaengine_terminate_sync(drv_data->master->dma_tx); | |
| 190 | + dmaengine_terminate_sync(drv_data->controller->dma_rx); | |
| 191 | + dmaengine_terminate_sync(drv_data->controller->dma_tx); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | int pxa2xx_spi_dma_setup(struct driver_data *drv_data) |
| 195 | 195 | { |
| 196 | − struct pxa2xx_spi_master *pdata = drv_data->master_info; | |
| 196 | + struct pxa2xx_spi_controller *pdata = drv_data->controller_info; | |
| 197 | 197 | struct device *dev = &drv_data->pdev->dev; |
| 198 | − struct spi_controller *master = drv_data->master; | |
| 198 | + struct spi_controller *controller = drv_data->controller; | |
| 199 | 199 | dma_cap_mask_t mask; |
| 200 | 200 | |
| 201 | 201 | dma_cap_zero(mask); |
| 202 | 202 | dma_cap_set(DMA_SLAVE, mask); |
| 203 | 203 | |
| 204 | − master->dma_tx = dma_request_slave_channel_compat(mask, | |
| 204 | + controller->dma_tx = dma_request_slave_channel_compat(mask, | |
| 205 | 205 | pdata->dma_filter, pdata->tx_param, dev, "tx"); |
| 206 | − if (!master->dma_tx) | |
| 206 | + if (!controller->dma_tx) | |
| 207 | 207 | return -ENODEV; |
| 208 | 208 | |
| 209 | − master->dma_rx = dma_request_slave_channel_compat(mask, | |
| 209 | + controller->dma_rx = dma_request_slave_channel_compat(mask, | |
| 210 | 210 | pdata->dma_filter, pdata->rx_param, dev, "rx"); |
| 211 | − if (!master->dma_rx) { | |
| 212 | − dma_release_channel(master->dma_tx); | |
| 213 | − master->dma_tx = NULL; | |
| 211 | + if (!controller->dma_rx) { | |
| 212 | + dma_release_channel(controller->dma_tx); | |
| 213 | + controller->dma_tx = NULL; | |
| 214 | 214 | return -ENODEV; |
| 215 | 215 | } |
| 216 | 216 | |
| @@ -219,17 +219,17 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data) · 2 unmodified lines | ||
| 219 | 219 | |
| 220 | 220 | void pxa2xx_spi_dma_release(struct driver_data *drv_data) |
| 221 | 221 | { |
| 222 | − struct spi_controller *master = drv_data->master; | |
| 222 | + struct spi_controller *controller = drv_data->controller; | |
| 223 | 223 | |
| 224 | − if (master->dma_rx) { | |
| 225 | − dmaengine_terminate_sync(master->dma_rx); | |
| 226 | − dma_release_channel(master->dma_rx); | |
| 227 | − master->dma_rx = NULL; | |
| 224 | + if (controller->dma_rx) { | |
| 225 | + dmaengine_terminate_sync(controller->dma_rx); | |
| 226 | + dma_release_channel(controller->dma_rx); | |
| 227 | + controller->dma_rx = NULL; | |
| 228 | 228 | } |
| 229 | − if (master->dma_tx) { | |
| 230 | − dmaengine_terminate_sync(master->dma_tx); | |
| 231 | − dma_release_channel(master->dma_tx); | |
| 232 | − master->dma_tx = NULL; | |
| 229 | + if (controller->dma_tx) { | |
| 230 | + dmaengine_terminate_sync(controller->dma_tx); | |
| 231 | + dma_release_channel(controller->dma_tx); | |
| 232 | + controller->dma_tx = NULL; | |
| 233 | 233 | } |
| 234 | 234 | } |
| 235 | 235 | |
| @@ -197,7 +197,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 196 unmodified lines | ||
| 197 | 197 | struct platform_device_info pi; |
| 198 | 198 | int ret; |
| 199 | 199 | struct platform_device *pdev; |
| 200 | − struct pxa2xx_spi_master spi_pdata; | |
| 200 | + struct pxa2xx_spi_controller spi_pdata; | |
| 201 | 201 | struct ssp_device *ssp; |
| 202 | 202 | struct pxa_spi_info *c; |
| 203 | 203 | char buf[40]; |
| @@ -265,7 +265,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 61 unmodified lines | ||
| 265 | 265 | static void pxa2xx_spi_pci_remove(struct pci_dev *dev) |
| 266 | 266 | { |
| 267 | 267 | struct platform_device *pdev = pci_get_drvdata(dev); |
| 268 | − struct pxa2xx_spi_master *spi_pdata; | |
| 268 | + struct pxa2xx_spi_controller *spi_pdata; | |
| 269 | 269 | |
| 270 | 270 | spi_pdata = dev_get_platdata(&pdev->dev); |
| 271 | 271 | |
| @@ -328,7 +328,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data) · 327 unmodified lines | ||
| 328 | 328 | __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); |
| 329 | 329 | |
| 330 | 330 | /* Enable multiblock DMA transfers */ |
| 331 | − if (drv_data->master_info->enable_dma) { | |
| 331 | + if (drv_data->controller_info->enable_dma) { | |
| 332 | 332 | __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1); |
| 333 | 333 | |
| 334 | 334 | if (config->reg_general >= 0) { |
| @@ -368,7 +368,7 @@ static void lpss_ssp_select_cs(struct spi_device *spi, · 33 unmodified lines | ||
| 368 | 368 | __lpss_ssp_write_priv(drv_data, |
| 369 | 369 | config->reg_cs_ctrl, value); |
| 370 | 370 | ndelay(1000000000 / |
| 371 | − (drv_data->master->max_speed_hz / 2)); | |
| 371 | + (drv_data->controller->max_speed_hz / 2)); | |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | |
| @@ -567,7 +567,7 @@ static int u32_reader(struct driver_data *drv_data) · 192 unmodified lines | ||
| 567 | 567 | static void reset_sccr1(struct driver_data *drv_data) |
| 568 | 568 | { |
| 569 | 569 | struct chip_data *chip = |
| 570 | − spi_get_ctldata(drv_data->master->cur_msg->spi); | |
| 570 | + spi_get_ctldata(drv_data->controller->cur_msg->spi); | |
| 571 | 571 | u32 sccr1_reg; |
| 572 | 572 | |
| 573 | 573 | sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1; |
| @@ -599,8 +599,8 @@ static void int_error_stop(struct driver_data *drv_data, const char* msg) · 25 unmodified lines | ||
| 599 | 599 | |
| 600 | 600 | dev_err(&drv_data->pdev->dev, "%s\n", msg); |
| 601 | 601 | |
| 602 | − drv_data->master->cur_msg->status = -EIO; | |
| 603 | − spi_finalize_current_transfer(drv_data->master); | |
| 602 | + drv_data->controller->cur_msg->status = -EIO; | |
| 603 | + spi_finalize_current_transfer(drv_data->controller); | |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | static void int_transfer_complete(struct driver_data *drv_data) |
| @@ -611,7 +611,7 @@ static void int_transfer_complete(struct driver_data *drv_data) · 4 unmodified lines | ||
| 611 | 611 | if (!pxa25x_ssp_comp(drv_data)) |
| 612 | 612 | pxa2xx_spi_write(drv_data, SSTO, 0); |
| 613 | 613 | |
| 614 | − spi_finalize_current_transfer(drv_data->master); | |
| 614 | + spi_finalize_current_transfer(drv_data->controller); | |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | static irqreturn_t interrupt_transfer(struct driver_data *drv_data) |
| @@ -747,7 +747,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id) · 129 unmodified lines | ||
| 747 | 747 | pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1); |
| 748 | 748 | pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg); |
| 749 | 749 | |
| 750 | − if (!drv_data->master->cur_msg) { | |
| 750 | + if (!drv_data->controller->cur_msg) { | |
| 751 | 751 | handle_bad_msg(drv_data); |
| 752 | 752 | /* Never fail */ |
| 753 | 753 | return IRQ_HANDLED; |
| @@ -879,7 +879,7 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds) · 125 unmodified lines | ||
| 879 | 879 | |
| 880 | 880 | static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) |
| 881 | 881 | { |
| 882 | − unsigned long ssp_clk = drv_data->master->max_speed_hz; | |
| 882 | + unsigned long ssp_clk = drv_data->controller->max_speed_hz; | |
| 883 | 883 | const struct ssp_device *ssp = drv_data->ssp; |
| 884 | 884 | |
| 885 | 885 | rate = min_t(int, ssp_clk, rate); |
| @@ -894,7 +894,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, · 8 unmodified lines | ||
| 894 | 894 | int rate) |
| 895 | 895 | { |
| 896 | 896 | struct chip_data *chip = |
| 897 | − spi_get_ctldata(drv_data->master->cur_msg->spi); | |
| 897 | + spi_get_ctldata(drv_data->controller->cur_msg->spi); | |
| 898 | 898 | unsigned int clk_div; |
| 899 | 899 | |
| 900 | 900 | switch (drv_data->ssp_type) { |
| @@ -908,7 +908,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, · 7 unmodified lines | ||
| 908 | 908 | return clk_div << 8; |
| 909 | 909 | } |
| 910 | 910 | |
| 911 | −static bool pxa2xx_spi_can_dma(struct spi_controller *master, | |
| 911 | +static bool pxa2xx_spi_can_dma(struct spi_controller *controller, | |
| 912 | 912 | struct spi_device *spi, |
| 913 | 913 | struct spi_transfer *xfer) |
| 914 | 914 | { |
| @@ -919,12 +919,12 @@ static bool pxa2xx_spi_can_dma(struct spi_controller *master, · 4 unmodified lines | ||
| 919 | 919 | xfer->len >= chip->dma_burst_size; |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | −static int pxa2xx_spi_transfer_one(struct spi_controller *master, | |
| 922 | +static int pxa2xx_spi_transfer_one(struct spi_controller *controller, | |
| 923 | 923 | struct spi_device *spi, |
| 924 | 924 | struct spi_transfer *transfer) |
| 925 | 925 | { |
| 926 | − struct driver_data *drv_data = spi_controller_get_devdata(master); | |
| 927 | − struct spi_message *message = master->cur_msg; | |
| 926 | + struct driver_data *drv_data = spi_controller_get_devdata(controller); | |
| 927 | + struct spi_message *message = controller->cur_msg; | |
| 928 | 928 | struct chip_data *chip = spi_get_ctldata(message->spi); |
| 929 | 929 | u32 dma_thresh = chip->dma_threshold; |
| 930 | 930 | u32 dma_burst = chip->dma_burst_size; |
| @@ -1006,9 +1006,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 75 unmodified lines | ||
| 1006 | 1006 | "DMA burst size reduced to match bits_per_word\n"); |
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | − dma_mapped = master->can_dma && | |
| 1010 | − master->can_dma(master, message->spi, transfer) && | |
| 1011 | − master->cur_msg_mapped; | |
| 1009 | + dma_mapped = controller->can_dma && | |
| 1010 | + controller->can_dma(controller, message->spi, transfer) && | |
| 1011 | + controller->cur_msg_mapped; | |
| 1012 | 1012 | if (dma_mapped) { |
| 1013 | 1013 | |
| 1014 | 1014 | /* Ensure we have the correct interrupt handler */ |
| @@ -1036,12 +1036,12 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 21 unmodified lines | ||
| 1036 | 1036 | cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits); |
| 1037 | 1037 | if (!pxa25x_ssp_comp(drv_data)) |
| 1038 | 1038 | dev_dbg(&message->spi->dev, "%u Hz actual, %s\n", |
| 1039 | − master->max_speed_hz | |
| 1039 | + controller->max_speed_hz | |
| 1040 | 1040 | / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)), |
| 1041 | 1041 | dma_mapped ? "DMA" : "PIO"); |
| 1042 | 1042 | else |
| 1043 | 1043 | dev_dbg(&message->spi->dev, "%u Hz actual, %s\n", |
| 1044 | − master->max_speed_hz / 2 | |
| 1044 | + controller->max_speed_hz / 2 | |
| 1045 | 1045 | / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)), |
| 1046 | 1046 | dma_mapped ? "DMA" : "PIO"); |
| 1047 | 1047 | |
| @@ -1092,7 +1092,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 44 unmodified lines | ||
| 1092 | 1092 | } |
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | − if (spi_controller_is_slave(master)) { | |
| 1095 | + if (spi_controller_is_slave(controller)) { | |
| 1096 | 1096 | while (drv_data->write(drv_data)) |
| 1097 | 1097 | ; |
| 1098 | 1098 | if (drv_data->gpiod_ready) { |
| @@ -1111,9 +1111,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 12 unmodified lines | ||
| 1111 | 1111 | return 1; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | −static int pxa2xx_spi_slave_abort(struct spi_master *master) | |
| 1114 | +static int pxa2xx_spi_slave_abort(struct spi_controller *controller) | |
| 1115 | 1115 | { |
| 1116 | − struct driver_data *drv_data = spi_controller_get_devdata(master); | |
| 1116 | + struct driver_data *drv_data = spi_controller_get_devdata(controller); | |
| 1117 | 1117 | |
| 1118 | 1118 | /* Stop and reset SSP */ |
| 1119 | 1119 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
| @@ -1126,16 +1126,16 @@ static int pxa2xx_spi_slave_abort(struct spi_master *master) · 6 unmodified lines | ||
| 1126 | 1126 | |
| 1127 | 1127 | dev_dbg(&drv_data->pdev->dev, "transfer aborted\n"); |
| 1128 | 1128 | |
| 1129 | − drv_data->master->cur_msg->status = -EINTR; | |
| 1130 | − spi_finalize_current_transfer(drv_data->master); | |
| 1129 | + drv_data->controller->cur_msg->status = -EINTR; | |
| 1130 | + spi_finalize_current_transfer(drv_data->controller); | |
| 1131 | 1131 | |
| 1132 | 1132 | return 0; |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | −static void pxa2xx_spi_handle_err(struct spi_controller *master, | |
| 1135 | +static void pxa2xx_spi_handle_err(struct spi_controller *controller, | |
| 1136 | 1136 | struct spi_message *msg) |
| 1137 | 1137 | { |
| 1138 | − struct driver_data *drv_data = spi_controller_get_devdata(master); | |
| 1138 | + struct driver_data *drv_data = spi_controller_get_devdata(controller); | |
| 1139 | 1139 | |
| 1140 | 1140 | /* Disable the SSP */ |
| 1141 | 1141 | pxa2xx_spi_write(drv_data, SSCR0, |
| @@ -1159,9 +1159,9 @@ static void pxa2xx_spi_handle_err(struct spi_controller *master, · 17 unmodified lines | ||
| 1159 | 1159 | pxa2xx_spi_dma_stop(drv_data); |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | −static int pxa2xx_spi_unprepare_transfer(struct spi_controller *master) | |
| 1162 | +static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller) | |
| 1163 | 1163 | { |
| 1164 | − struct driver_data *drv_data = spi_controller_get_devdata(master); | |
| 1164 | + struct driver_data *drv_data = spi_controller_get_devdata(controller); | |
| 1165 | 1165 | |
| 1166 | 1166 | /* Disable the SSP now */ |
| 1167 | 1167 | pxa2xx_spi_write(drv_data, SSCR0, |
| @@ -1260,7 +1260,7 @@ static int setup(struct spi_device *spi) · 92 unmodified lines | ||
| 1260 | 1260 | break; |
| 1261 | 1261 | default: |
| 1262 | 1262 | tx_hi_thres = 0; |
| 1263 | − if (spi_controller_is_slave(drv_data->master)) { | |
| 1263 | + if (spi_controller_is_slave(drv_data->controller)) { | |
| 1264 | 1264 | tx_thres = 1; |
| 1265 | 1265 | rx_thres = 2; |
| 1266 | 1266 | } else { |
| @@ -1287,7 +1287,7 @@ static int setup(struct spi_device *spi) · 20 unmodified lines | ||
| 1287 | 1287 | |
| 1288 | 1288 | chip->frm = spi->chip_select; |
| 1289 | 1289 | } |
| 1290 | − chip->enable_dma = drv_data->master_info->enable_dma; | |
| 1290 | + chip->enable_dma = drv_data->controller_info->enable_dma; | |
| 1291 | 1291 | chip->timeout = TIMOUT_DFLT; |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| @@ -1310,7 +1310,7 @@ static int setup(struct spi_device *spi) · 16 unmodified lines | ||
| 1310 | 1310 | if (chip_info->enable_loopback) |
| 1311 | 1311 | chip->cr1 = SSCR1_LBM; |
| 1312 | 1312 | } |
| 1313 | − if (spi_controller_is_slave(drv_data->master)) { | |
| 1313 | + if (spi_controller_is_slave(drv_data->controller)) { | |
| 1314 | 1314 | chip->cr1 |= SSCR1_SCFR; |
| 1315 | 1315 | chip->cr1 |= SSCR1_SCLKDIR; |
| 1316 | 1316 | chip->cr1 |= SSCR1_SFRMDIR; |
| @@ -1497,10 +1497,10 @@ static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param) · 180 unmodified lines | ||
| 1497 | 1497 | |
| 1498 | 1498 | #endif /* CONFIG_PCI */ |
| 1499 | 1499 | |
| 1500 | −static struct pxa2xx_spi_master * | |
| 1500 | +static struct pxa2xx_spi_controller * | |
| 1501 | 1501 | pxa2xx_spi_init_pdata(struct platform_device *pdev) |
| 1502 | 1502 | { |
| 1503 | − struct pxa2xx_spi_master *pdata; | |
| 1503 | + struct pxa2xx_spi_controller *pdata; | |
| 1504 | 1504 | struct acpi_device *adev; |
| 1505 | 1505 | struct ssp_device *ssp; |
| 1506 | 1506 | struct resource *res; |
| @@ -1568,10 +1568,10 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev) · 61 unmodified lines | ||
| 1568 | 1568 | return pdata; |
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | −static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master, | |
| 1571 | +static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller, | |
| 1572 | 1572 | unsigned int cs) |
| 1573 | 1573 | { |
| 1574 | − struct driver_data *drv_data = spi_controller_get_devdata(master); | |
| 1574 | + struct driver_data *drv_data = spi_controller_get_devdata(controller); | |
| 1575 | 1575 | |
| 1576 | 1576 | if (has_acpi_companion(&drv_data->pdev->dev)) { |
| 1577 | 1577 | switch (drv_data->ssp_type) { |
| @@ -1595,8 +1595,8 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master, · 17 unmodified lines | ||
| 1595 | 1595 | static int pxa2xx_spi_probe(struct platform_device *pdev) |
| 1596 | 1596 | { |
| 1597 | 1597 | struct device *dev = &pdev->dev; |
| 1598 | − struct pxa2xx_spi_master *platform_info; | |
| 1599 | − struct spi_controller *master; | |
| 1598 | + struct pxa2xx_spi_controller *platform_info; | |
| 1599 | + struct spi_controller *controller; | |
| 1600 | 1600 | struct driver_data *drv_data; |
| 1601 | 1601 | struct ssp_device *ssp; |
| 1602 | 1602 | const struct lpss_config *config; |
| @@ -1622,37 +1622,37 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 19 unmodified lines | ||
| 1622 | 1622 | } |
| 1623 | 1623 | |
| 1624 | 1624 | if (platform_info->is_slave) |
| 1625 | − master = spi_alloc_slave(dev, sizeof(struct driver_data)); | |
| 1625 | + controller = spi_alloc_slave(dev, sizeof(struct driver_data)); | |
| 1626 | 1626 | else |
| 1627 | − master = spi_alloc_master(dev, sizeof(struct driver_data)); | |
| 1627 | + controller = spi_alloc_master(dev, sizeof(struct driver_data)); | |
| 1628 | 1628 | |
| 1629 | − if (!master) { | |
| 1630 | − dev_err(&pdev->dev, "cannot alloc spi_master\n"); | |
| 1629 | + if (!controller) { | |
| 1630 | + dev_err(&pdev->dev, "cannot alloc spi_controller\n"); | |
| 1631 | 1631 | pxa_ssp_free(ssp); |
| 1632 | 1632 | return -ENOMEM; |
| 1633 | 1633 | } |
| 1634 | − drv_data = spi_controller_get_devdata(master); | |
| 1635 | − drv_data->master = master; | |
| 1636 | − drv_data->master_info = platform_info; | |
| 1634 | + drv_data = spi_controller_get_devdata(controller); | |
| 1635 | + drv_data->controller = controller; | |
| 1636 | + drv_data->controller_info = platform_info; | |
| 1637 | 1637 | drv_data->pdev = pdev; |
| 1638 | 1638 | drv_data->ssp = ssp; |
| 1639 | 1639 | |
| 1640 | − master->dev.of_node = pdev->dev.of_node; | |
| 1640 | + controller->dev.of_node = pdev->dev.of_node; | |
| 1641 | 1641 | /* the spi->mode bits understood by this driver: */ |
| 1642 | − master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; | |
| 1643 | − | |
| 1644 | − master->bus_num = ssp->port_id; | |
| 1645 | − master->dma_alignment = DMA_ALIGNMENT; | |
| 1646 | − master->cleanup = cleanup; | |
| 1647 | − master->setup = setup; | |
| 1648 | − master->set_cs = pxa2xx_spi_set_cs; | |
| 1649 | − master->transfer_one = pxa2xx_spi_transfer_one; | |
| 1650 | − master->slave_abort = pxa2xx_spi_slave_abort; | |
| 1651 | − master->handle_err = pxa2xx_spi_handle_err; | |
| 1652 | − master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; | |
| 1653 | − master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; | |
| 1654 | − master->auto_runtime_pm = true; | |
| 1655 | − master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX; | |
| 1642 | + controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; | |
| 1643 | + | |
| 1644 | + controller->bus_num = ssp->port_id; | |
| 1645 | + controller->dma_alignment = DMA_ALIGNMENT; | |
| 1646 | + controller->cleanup = cleanup; | |
| 1647 | + controller->setup = setup; | |
| 1648 | + controller->set_cs = pxa2xx_spi_set_cs; | |
| 1649 | + controller->transfer_one = pxa2xx_spi_transfer_one; | |
| 1650 | + controller->slave_abort = pxa2xx_spi_slave_abort; | |
| 1651 | + controller->handle_err = pxa2xx_spi_handle_err; | |
| 1652 | + controller->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; | |
| 1653 | + controller->fw_translate_cs = pxa2xx_spi_fw_translate_cs; | |
| 1654 | + controller->auto_runtime_pm = true; | |
| 1655 | + controller->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX; | |
| 1656 | 1656 | |
| 1657 | 1657 | drv_data->ssp_type = ssp->type; |
| 1658 | 1658 | |
| @@ -1661,10 +1661,10 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1661 | 1661 | if (pxa25x_ssp_comp(drv_data)) { |
| 1662 | 1662 | switch (drv_data->ssp_type) { |
| 1663 | 1663 | case QUARK_X1000_SSP: |
| 1664 | − master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); | |
| 1664 | + controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); | |
| 1665 | 1665 | break; |
| 1666 | 1666 | default: |
| 1667 | − master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); | |
| 1667 | + controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); | |
| 1668 | 1668 | break; |
| 1669 | 1669 | } |
| 1670 | 1670 | |
| @@ -1673,7 +1673,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1673 | 1673 | drv_data->clear_sr = SSSR_ROR; |
| 1674 | 1674 | drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR; |
| 1675 | 1675 | } else { |
| 1676 | − master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); | |
| 1676 | + controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); | |
| 1677 | 1677 | drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE; |
| 1678 | 1678 | drv_data->dma_cr1 = DEFAULT_DMA_CR1; |
| 1679 | 1679 | drv_data->clear_sr = SSSR_ROR | SSSR_TINT; |
| @@ -1685,7 +1685,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 5 unmodified lines | ||
| 1685 | 1685 | drv_data); |
| 1686 | 1686 | if (status < 0) { |
| 1687 | 1687 | dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq); |
| 1688 | − goto out_error_master_alloc; | |
| 1688 | + goto out_error_controller_alloc; | |
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | /* Setup DMA if requested */ |
| @@ -1695,7 +1695,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 1695 | 1695 | dev_dbg(dev, "no DMA channels available, using PIO\n"); |
| 1696 | 1696 | platform_info->enable_dma = false; |
| 1697 | 1697 | } else { |
| 1698 | − master->can_dma = pxa2xx_spi_can_dma; | |
| 1698 | + controller->can_dma = pxa2xx_spi_can_dma; | |
| 1699 | + controller->max_dma_len = MAX_DMA_LEN; | |
| 1699 | 1700 | } |
| 1700 | 1701 | } |
| 1701 | 1702 | |
| @@ -1704,7 +1705,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1704 | 1705 | if (status) |
| 1705 | 1706 | goto out_error_dma_irq_alloc; |
| 1706 | 1707 | |
| 1707 | − master->max_speed_hz = clk_get_rate(ssp->clk); | |
| 1708 | + controller->max_speed_hz = clk_get_rate(ssp->clk); | |
| 1708 | 1709 | |
| 1709 | 1710 | /* Load default SSP configuration */ |
| 1710 | 1711 | pxa2xx_spi_write(drv_data, SSCR0, 0); |
| @@ -1727,7 +1728,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 16 unmodified lines | ||
| 1727 | 1728 | break; |
| 1728 | 1729 | default: |
| 1729 | 1730 | |
| 1730 | − if (spi_controller_is_slave(master)) { | |
| 1731 | + if (spi_controller_is_slave(controller)) { | |
| 1731 | 1732 | tmp = SSCR1_SCFR | |
| 1732 | 1733 | SSCR1_SCLKDIR | |
| 1733 | 1734 | SSCR1_SFRMDIR | |
| @@ -1740,7 +1741,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 6 unmodified lines | ||
| 1740 | 1741 | } |
| 1741 | 1742 | pxa2xx_spi_write(drv_data, SSCR1, tmp); |
| 1742 | 1743 | tmp = SSCR0_Motorola | SSCR0_DataSize(8); |
| 1743 | − if (!spi_controller_is_slave(master)) | |
| 1744 | + if (!spi_controller_is_slave(controller)) | |
| 1744 | 1745 | tmp |= SSCR0_SCR(2); |
| 1745 | 1746 | pxa2xx_spi_write(drv_data, SSCR0, tmp); |
| 1746 | 1747 | break; |
| @@ -1765,24 +1766,24 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 18 unmodified lines | ||
| 1765 | 1766 | platform_info->num_chipselect = config->cs_num; |
| 1766 | 1767 | } |
| 1767 | 1768 | } |
| 1768 | − master->num_chipselect = platform_info->num_chipselect; | |
| 1769 | + controller->num_chipselect = platform_info->num_chipselect; | |
| 1769 | 1770 | |
| 1770 | 1771 | count = gpiod_count(&pdev->dev, "cs"); |
| 1771 | 1772 | if (count > 0) { |
| 1772 | 1773 | int i; |
| 1773 | 1774 | |
| 1774 | − master->num_chipselect = max_t(int, count, | |
| 1775 | − master->num_chipselect); | |
| 1775 | + controller->num_chipselect = max_t(int, count, | |
| 1776 | + controller->num_chipselect); | |
| 1776 | 1777 | |
| 1777 | 1778 | drv_data->cs_gpiods = devm_kcalloc(&pdev->dev, |
| 1778 | − master->num_chipselect, sizeof(struct gpio_desc *), | |
| 1779 | + controller->num_chipselect, sizeof(struct gpio_desc *), | |
| 1779 | 1780 | GFP_KERNEL); |
| 1780 | 1781 | if (!drv_data->cs_gpiods) { |
| 1781 | 1782 | status = -ENOMEM; |
| 1782 | 1783 | goto out_error_clock_enabled; |
| 1783 | 1784 | } |
| 1784 | 1785 | |
| 1785 | − for (i = 0; i < master->num_chipselect; i++) { | |
| 1786 | + for (i = 0; i < controller->num_chipselect; i++) { | |
| 1786 | 1787 | struct gpio_desc *gpiod; |
| 1787 | 1788 | |
| 1788 | 1789 | gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS); |
| @@ -1815,9 +1816,9 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 26 unmodified lines | ||
| 1815 | 1816 | |
| 1816 | 1817 | /* Register with the SPI framework */ |
| 1817 | 1818 | platform_set_drvdata(pdev, drv_data); |
| 1818 | − status = devm_spi_register_controller(&pdev->dev, master); | |
| 1819 | + status = devm_spi_register_controller(&pdev->dev, controller); | |
| 1819 | 1820 | if (status != 0) { |
| 1820 | − dev_err(&pdev->dev, "problem registering spi master\n"); | |
| 1821 | + dev_err(&pdev->dev, "problem registering spi controller\n"); | |
| 1821 | 1822 | goto out_error_clock_enabled; |
| 1822 | 1823 | } |
| 1823 | 1824 | |
| @@ -1832,8 +1833,8 @@ out_error_dma_irq_alloc: · 8 unmodified lines | ||
| 1832 | 1833 | pxa2xx_spi_dma_release(drv_data); |
| 1833 | 1834 | free_irq(ssp->irq, drv_data); |
| 1834 | 1835 | |
| 1835 | −out_error_master_alloc: | |
| 1836 | − spi_controller_put(master); | |
| 1836 | +out_error_controller_alloc: | |
| 1837 | + spi_controller_put(controller); | |
| 1837 | 1838 | pxa_ssp_free(ssp); |
| 1838 | 1839 | return status; |
| 1839 | 1840 | } |
| @@ -1854,7 +1855,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev) · 14 unmodified lines | ||
| 1854 | 1855 | clk_disable_unprepare(ssp->clk); |
| 1855 | 1856 | |
| 1856 | 1857 | /* Release DMA */ |
| 1857 | − if (drv_data->master_info->enable_dma) | |
| 1858 | + if (drv_data->controller_info->enable_dma) | |
| 1858 | 1859 | pxa2xx_spi_dma_release(drv_data); |
| 1859 | 1860 | |
| 1860 | 1861 | pm_runtime_put_noidle(&pdev->dev); |
| @@ -1876,7 +1877,7 @@ static int pxa2xx_spi_suspend(struct device *dev) · 15 unmodified lines | ||
| 1876 | 1877 | struct ssp_device *ssp = drv_data->ssp; |
| 1877 | 1878 | int status; |
| 1878 | 1879 | |
| 1879 | − status = spi_controller_suspend(drv_data->master); | |
| 1880 | + status = spi_controller_suspend(drv_data->controller); | |
| 1880 | 1881 | if (status != 0) |
| 1881 | 1882 | return status; |
| 1882 | 1883 | pxa2xx_spi_write(drv_data, SSCR0, 0); |
| @@ -1901,7 +1902,7 @@ static int pxa2xx_spi_resume(struct device *dev) · 18 unmodified lines | ||
| 1901 | 1902 | } |
| 1902 | 1903 | |
| 1903 | 1904 | /* Start the queue running */ |
| 1904 | − return spi_controller_resume(drv_data->master); | |
| 1905 | + return spi_controller_resume(drv_data->controller); | |
| 1905 | 1906 | } |
| 1906 | 1907 | #endif |
| 1907 | 1908 | |
| @@ -31,10 +31,10 @@ struct driver_data { · 30 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | /* SPI framework hookup */ |
| 33 | 33 | enum pxa_ssp_type ssp_type; |
| 34 | − struct spi_controller *master; | |
| 34 | + struct spi_controller *controller; | |
| 35 | 35 | |
| 36 | 36 | /* PXA hookup */ |
| 37 | − struct pxa2xx_spi_master *master_info; | |
| 37 | + struct pxa2xx_spi_controller *controller_info; | |
| 38 | 38 | |
| 39 | 39 | /* SSP register addresses */ |
| 40 | 40 | void __iomem *ioaddr; |
| @@ -180,7 +180,7 @@ · 179 unmodified lines | ||
| 180 | 180 | struct rspi_data { |
| 181 | 181 | void __iomem *addr; |
| 182 | 182 | u32 max_speed_hz; |
| 183 | − struct spi_master *master; | |
| 183 | + struct spi_controller *ctlr; | |
| 184 | 184 | wait_queue_head_t wait; |
| 185 | 185 | struct clk *clk; |
| 186 | 186 | u16 spcmd; |
| @@ -237,8 +237,8 @@ static u16 rspi_read_data(const struct rspi_data *rspi) · 50 unmodified lines | ||
| 237 | 237 | /* optional functions */ |
| 238 | 238 | struct spi_ops { |
| 239 | 239 | int (*set_config_register)(struct rspi_data *rspi, int access_size); |
| 240 | − int (*transfer_one)(struct spi_master *master, struct spi_device *spi, | |
| 241 | − struct spi_transfer *xfer); | |
| 240 | + int (*transfer_one)(struct spi_controller *ctlr, | |
| 241 | + struct spi_device *spi, struct spi_transfer *xfer); | |
| 242 | 242 | u16 mode_bits; |
| 243 | 243 | u16 flags; |
| 244 | 244 | u16 fifo_size; |
| @@ -466,7 +466,7 @@ static int rspi_data_out(struct rspi_data *rspi, u8 data) · 221 unmodified lines | ||
| 466 | 466 | { |
| 467 | 467 | int error = rspi_wait_for_tx_empty(rspi); |
| 468 | 468 | if (error < 0) { |
| 469 | − dev_err(&rspi->master->dev, "transmit timeout\n"); | |
| 469 | + dev_err(&rspi->ctlr->dev, "transmit timeout\n"); | |
| 470 | 470 | return error; |
| 471 | 471 | } |
| 472 | 472 | rspi_write_data(rspi, data); |
| @@ -480,7 +480,7 @@ static int rspi_data_in(struct rspi_data *rspi) · 7 unmodified lines | ||
| 480 | 480 | |
| 481 | 481 | error = rspi_wait_for_rx_full(rspi); |
| 482 | 482 | if (error < 0) { |
| 483 | − dev_err(&rspi->master->dev, "receive timeout\n"); | |
| 483 | + dev_err(&rspi->ctlr->dev, "receive timeout\n"); | |
| 484 | 484 | return error; |
| 485 | 485 | } |
| 486 | 486 | data = rspi_read_data(rspi); |
| @@ -526,8 +526,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 39 unmodified lines | ||
| 526 | 526 | |
| 527 | 527 | /* First prepare and submit the DMA request(s), as this may fail */ |
| 528 | 528 | if (rx) { |
| 529 | − desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx, | |
| 530 | − rx->sgl, rx->nents, DMA_DEV_TO_MEM, | |
| 529 | + desc_rx = dmaengine_prep_slave_sg(rspi->ctlr->dma_rx, rx->sgl, | |
| 530 | + rx->nents, DMA_DEV_TO_MEM, | |
| 531 | 531 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 532 | 532 | if (!desc_rx) { |
| 533 | 533 | ret = -EAGAIN; |
| @@ -546,8 +546,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 12 unmodified lines | ||
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | if (tx) { |
| 549 | − desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx, | |
| 550 | − tx->sgl, tx->nents, DMA_MEM_TO_DEV, | |
| 549 | + desc_tx = dmaengine_prep_slave_sg(rspi->ctlr->dma_tx, tx->sgl, | |
| 550 | + tx->nents, DMA_MEM_TO_DEV, | |
| 551 | 551 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 552 | 552 | if (!desc_tx) { |
| 553 | 553 | ret = -EAGAIN; |
| @@ -584,9 +584,9 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 30 unmodified lines | ||
| 584 | 584 | |
| 585 | 585 | /* Now start DMA */ |
| 586 | 586 | if (rx) |
| 587 | − dma_async_issue_pending(rspi->master->dma_rx); | |
| 587 | + dma_async_issue_pending(rspi->ctlr->dma_rx); | |
| 588 | 588 | if (tx) |
| 589 | − dma_async_issue_pending(rspi->master->dma_tx); | |
| 589 | + dma_async_issue_pending(rspi->ctlr->dma_tx); | |
| 590 | 590 | |
| 591 | 591 | ret = wait_event_interruptible_timeout(rspi->wait, |
| 592 | 592 | rspi->dma_callbacked, HZ); |
| @@ -594,13 +594,13 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 1 unmodified line | ||
| 594 | 594 | ret = 0; |
| 595 | 595 | } else { |
| 596 | 596 | if (!ret) { |
| 597 | − dev_err(&rspi->master->dev, "DMA timeout\n"); | |
| 597 | + dev_err(&rspi->ctlr->dev, "DMA timeout\n"); | |
| 598 | 598 | ret = -ETIMEDOUT; |
| 599 | 599 | } |
| 600 | 600 | if (tx) |
| 601 | − dmaengine_terminate_all(rspi->master->dma_tx); | |
| 601 | + dmaengine_terminate_all(rspi->ctlr->dma_tx); | |
| 602 | 602 | if (rx) |
| 603 | − dmaengine_terminate_all(rspi->master->dma_rx); | |
| 603 | + dmaengine_terminate_all(rspi->ctlr->dma_rx); | |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | rspi_disable_irq(rspi, irq_mask); |
| @@ -614,12 +614,12 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 7 unmodified lines | ||
| 614 | 614 | |
| 615 | 615 | no_dma_tx: |
| 616 | 616 | if (rx) |
| 617 | − dmaengine_terminate_all(rspi->master->dma_rx); | |
| 617 | + dmaengine_terminate_all(rspi->ctlr->dma_rx); | |
| 618 | 618 | no_dma_rx: |
| 619 | 619 | if (ret == -EAGAIN) { |
| 620 | 620 | pr_warn_once("%s %s: DMA not available, falling back to PIO\n", |
| 621 | − dev_driver_string(&rspi->master->dev), | |
| 622 | − dev_name(&rspi->master->dev)); | |
| 621 | + dev_driver_string(&rspi->ctlr->dev), | |
| 622 | + dev_name(&rspi->ctlr->dev)); | |
| 623 | 623 | } |
| 624 | 624 | return ret; |
| 625 | 625 | } |
| @@ -660,10 +660,10 @@ static bool __rspi_can_dma(const struct rspi_data *rspi, · 34 unmodified lines | ||
| 660 | 660 | return xfer->len > rspi->ops->fifo_size; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | −static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, | |
| 663 | +static bool rspi_can_dma(struct spi_controller *ctlr, struct spi_device *spi, | |
| 664 | 664 | struct spi_transfer *xfer) |
| 665 | 665 | { |
| 666 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 666 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 667 | 667 | |
| 668 | 668 | return __rspi_can_dma(rspi, xfer); |
| 669 | 669 | } |
| @@ -671,7 +671,7 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, · 1 unmodified line | ||
| 671 | 671 | static int rspi_dma_check_then_transfer(struct rspi_data *rspi, |
| 672 | 672 | struct spi_transfer *xfer) |
| 673 | 673 | { |
| 674 | − if (!rspi->master->can_dma || !__rspi_can_dma(rspi, xfer)) | |
| 674 | + if (!rspi->ctlr->can_dma || !__rspi_can_dma(rspi, xfer)) | |
| 675 | 675 | return -EAGAIN; |
| 676 | 676 | |
| 677 | 677 | /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ |
| @@ -698,10 +698,10 @@ static int rspi_common_transfer(struct rspi_data *rspi, · 20 unmodified lines | ||
| 698 | 698 | return 0; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | −static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, | |
| 702 | − struct spi_transfer *xfer) | |
| 701 | +static int rspi_transfer_one(struct spi_controller *ctlr, | |
| 702 | + struct spi_device *spi, struct spi_transfer *xfer) | |
| 703 | 703 | { |
| 704 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 704 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 705 | 705 | u8 spcr; |
| 706 | 706 | |
| 707 | 707 | spcr = rspi_read8(rspi, RSPI_SPCR); |
| @@ -716,11 +716,11 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, · 8 unmodified lines | ||
| 716 | 716 | return rspi_common_transfer(rspi, xfer); |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | −static int rspi_rz_transfer_one(struct spi_master *master, | |
| 719 | +static int rspi_rz_transfer_one(struct spi_controller *ctlr, | |
| 720 | 720 | struct spi_device *spi, |
| 721 | 721 | struct spi_transfer *xfer) |
| 722 | 722 | { |
| 723 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 723 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 724 | 724 | |
| 725 | 725 | rspi_rz_receive_init(rspi); |
| 726 | 726 | |
| @@ -739,7 +739,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, · 12 unmodified lines | ||
| 739 | 739 | if (n == QSPI_BUFFER_SIZE) { |
| 740 | 740 | ret = rspi_wait_for_tx_empty(rspi); |
| 741 | 741 | if (ret < 0) { |
| 742 | − dev_err(&rspi->master->dev, "transmit timeout\n"); | |
| 742 | + dev_err(&rspi->ctlr->dev, "transmit timeout\n"); | |
| 743 | 743 | return ret; |
| 744 | 744 | } |
| 745 | 745 | for (i = 0; i < n; i++) |
| @@ -747,7 +747,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, · 1 unmodified line | ||
| 747 | 747 | |
| 748 | 748 | ret = rspi_wait_for_rx_full(rspi); |
| 749 | 749 | if (ret < 0) { |
| 750 | − dev_err(&rspi->master->dev, "receive timeout\n"); | |
| 750 | + dev_err(&rspi->ctlr->dev, "receive timeout\n"); | |
| 751 | 751 | return ret; |
| 752 | 752 | } |
| 753 | 753 | for (i = 0; i < n; i++) |
| @@ -785,7 +785,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) · 31 unmodified lines | ||
| 785 | 785 | unsigned int i, len; |
| 786 | 786 | int ret; |
| 787 | 787 | |
| 788 | − if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { | |
| 788 | + if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) { | |
| 789 | 789 | ret = rspi_dma_transfer(rspi, &xfer->tx_sg, NULL); |
| 790 | 790 | if (ret != -EAGAIN) |
| 791 | 791 | return ret; |
| @@ -796,7 +796,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) · 4 unmodified lines | ||
| 796 | 796 | if (len == QSPI_BUFFER_SIZE) { |
| 797 | 797 | ret = rspi_wait_for_tx_empty(rspi); |
| 798 | 798 | if (ret < 0) { |
| 799 | − dev_err(&rspi->master->dev, "transmit timeout\n"); | |
| 799 | + dev_err(&rspi->ctlr->dev, "transmit timeout\n"); | |
| 800 | 800 | return ret; |
| 801 | 801 | } |
| 802 | 802 | for (i = 0; i < len; i++) |
| @@ -822,7 +822,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 19 unmodified lines | ||
| 822 | 822 | unsigned int i, len; |
| 823 | 823 | int ret; |
| 824 | 824 | |
| 825 | − if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { | |
| 825 | + if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) { | |
| 826 | 826 | int ret = rspi_dma_transfer(rspi, NULL, &xfer->rx_sg); |
| 827 | 827 | if (ret != -EAGAIN) |
| 828 | 828 | return ret; |
| @@ -833,7 +833,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 4 unmodified lines | ||
| 833 | 833 | if (len == QSPI_BUFFER_SIZE) { |
| 834 | 834 | ret = rspi_wait_for_rx_full(rspi); |
| 835 | 835 | if (ret < 0) { |
| 836 | − dev_err(&rspi->master->dev, "receive timeout\n"); | |
| 836 | + dev_err(&rspi->ctlr->dev, "receive timeout\n"); | |
| 837 | 837 | return ret; |
| 838 | 838 | } |
| 839 | 839 | for (i = 0; i < len; i++) |
| @@ -849,10 +849,10 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 9 unmodified lines | ||
| 849 | 849 | return 0; |
| 850 | 850 | } |
| 851 | 851 | |
| 852 | −static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi, | |
| 853 | − struct spi_transfer *xfer) | |
| 852 | +static int qspi_transfer_one(struct spi_controller *ctlr, | |
| 853 | + struct spi_device *spi, struct spi_transfer *xfer) | |
| 854 | 854 | { |
| 855 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 855 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 856 | 856 | |
| 857 | 857 | if (spi->mode & SPI_LOOP) { |
| 858 | 858 | return qspi_transfer_out_in(rspi, xfer); |
| @@ -870,7 +870,7 @@ static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi, · 11 unmodified lines | ||
| 870 | 870 | |
| 871 | 871 | static int rspi_setup(struct spi_device *spi) |
| 872 | 872 | { |
| 873 | − struct rspi_data *rspi = spi_master_get_devdata(spi->master); | |
| 873 | + struct rspi_data *rspi = spi_controller_get_devdata(spi->controller); | |
| 874 | 874 | |
| 875 | 875 | rspi->max_speed_hz = spi->max_speed_hz; |
| 876 | 876 | |
| @@ -955,10 +955,10 @@ static int qspi_setup_sequencer(struct rspi_data *rspi, · 78 unmodified lines | ||
| 955 | 955 | return 0; |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | −static int rspi_prepare_message(struct spi_master *master, | |
| 958 | +static int rspi_prepare_message(struct spi_controller *ctlr, | |
| 959 | 959 | struct spi_message *msg) |
| 960 | 960 | { |
| 961 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 961 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 962 | 962 | int ret; |
| 963 | 963 | |
| 964 | 964 | if (msg->spi->mode & |
| @@ -974,10 +974,10 @@ static int rspi_prepare_message(struct spi_master *master, · 9 unmodified lines | ||
| 974 | 974 | return 0; |
| 975 | 975 | } |
| 976 | 976 | |
| 977 | −static int rspi_unprepare_message(struct spi_master *master, | |
| 977 | +static int rspi_unprepare_message(struct spi_controller *ctlr, | |
| 978 | 978 | struct spi_message *msg) |
| 979 | 979 | { |
| 980 | − struct rspi_data *rspi = spi_master_get_devdata(master); | |
| 980 | + struct rspi_data *rspi = spi_controller_get_devdata(ctlr); | |
| 981 | 981 | |
| 982 | 982 | /* Disable SPI function */ |
| 983 | 983 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR); |
| @@ -1081,7 +1081,7 @@ static struct dma_chan *rspi_request_dma_chan(struct device *dev, · 97 unmodified lines | ||
| 1081 | 1081 | return chan; |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | −static int rspi_request_dma(struct device *dev, struct spi_master *master, | |
| 1084 | +static int rspi_request_dma(struct device *dev, struct spi_controller *ctlr, | |
| 1085 | 1085 | const struct resource *res) |
| 1086 | 1086 | { |
| 1087 | 1087 | const struct rspi_plat_data *rspi_pd = dev_get_platdata(dev); |
| @@ -1099,37 +1099,37 @@ static int rspi_request_dma(struct device *dev, struct spi_master *master, · 11 unmodified lines | ||
| 1099 | 1099 | return 0; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
| 1102 | − master->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id, | |
| 1103 | − res->start + RSPI_SPDR); | |
| 1104 | − if (!master->dma_tx) | |
| 1102 | + ctlr->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id, | |
| 1103 | + res->start + RSPI_SPDR); | |
| 1104 | + if (!ctlr->dma_tx) | |
| 1105 | 1105 | return -ENODEV; |
| 1106 | 1106 | |
| 1107 | − master->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id, | |
| 1108 | − res->start + RSPI_SPDR); | |
| 1109 | − if (!master->dma_rx) { | |
| 1110 | − dma_release_channel(master->dma_tx); | |
| 1111 | − master->dma_tx = NULL; | |
| 1107 | + ctlr->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id, | |
| 1108 | + res->start + RSPI_SPDR); | |
| 1109 | + if (!ctlr->dma_rx) { | |
| 1110 | + dma_release_channel(ctlr->dma_tx); | |
| 1111 | + ctlr->dma_tx = NULL; | |
| 1112 | 1112 | return -ENODEV; |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | − master->can_dma = rspi_can_dma; | |
| 1115 | + ctlr->can_dma = rspi_can_dma; | |
| 1116 | 1116 | dev_info(dev, "DMA available"); |
| 1117 | 1117 | return 0; |
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | −static void rspi_release_dma(struct spi_master *master) | |
| 1120 | +static void rspi_release_dma(struct spi_controller *ctlr) | |
| 1121 | 1121 | { |
| 1122 | − if (master->dma_tx) | |
| 1123 | − dma_release_channel(master->dma_tx); | |
| 1124 | − if (master->dma_rx) | |
| 1125 | − dma_release_channel(master->dma_rx); | |
| 1122 | + if (ctlr->dma_tx) | |
| 1123 | + dma_release_channel(ctlr->dma_tx); | |
| 1124 | + if (ctlr->dma_rx) | |
| 1125 | + dma_release_channel(ctlr->dma_rx); | |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | static int rspi_remove(struct platform_device *pdev) |
| 1129 | 1129 | { |
| 1130 | 1130 | struct rspi_data *rspi = platform_get_drvdata(pdev); |
| 1131 | 1131 | |
| 1132 | − rspi_release_dma(rspi->master); | |
| 1132 | + rspi_release_dma(rspi->ctlr); | |
| 1133 | 1133 | pm_runtime_disable(&pdev->dev); |
| 1134 | 1134 | |
| 1135 | 1135 | return 0; |
| @@ -1139,7 +1139,7 @@ static const struct spi_ops rspi_ops = { · 3 unmodified lines | ||
| 1139 | 1139 | .set_config_register = rspi_set_config_register, |
| 1140 | 1140 | .transfer_one = rspi_transfer_one, |
| 1141 | 1141 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, |
| 1142 | − .flags = SPI_MASTER_MUST_TX, | |
| 1142 | + .flags = SPI_CONTROLLER_MUST_TX, | |
| 1143 | 1143 | .fifo_size = 8, |
| 1144 | 1144 | }; |
| 1145 | 1145 | |
| @@ -1147,7 +1147,7 @@ static const struct spi_ops rspi_rz_ops = { · 1 unmodified line | ||
| 1147 | 1147 | .set_config_register = rspi_rz_set_config_register, |
| 1148 | 1148 | .transfer_one = rspi_rz_transfer_one, |
| 1149 | 1149 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, |
| 1150 | − .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, | |
| 1150 | + .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX, | |
| 1151 | 1151 | .fifo_size = 8, /* 8 for TX, 32 for RX */ |
| 1152 | 1152 | }; |
| 1153 | 1153 | |
| @@ -1157,7 +1157,7 @@ static const struct spi_ops qspi_ops = { · 3 unmodified lines | ||
| 1157 | 1157 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP | |
| 1158 | 1158 | SPI_TX_DUAL | SPI_TX_QUAD | |
| 1159 | 1159 | SPI_RX_DUAL | SPI_RX_QUAD, |
| 1160 | − .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, | |
| 1160 | + .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX, | |
| 1161 | 1161 | .fifo_size = 32, |
| 1162 | 1162 | }; |
| 1163 | 1163 | |
| @@ -1174,7 +1174,7 @@ static const struct of_device_id rspi_of_match[] = { · 10 unmodified lines | ||
| 1174 | 1174 | |
| 1175 | 1175 | MODULE_DEVICE_TABLE(of, rspi_of_match); |
| 1176 | 1176 | |
| 1177 | −static int rspi_parse_dt(struct device *dev, struct spi_master *master) | |
| 1177 | +static int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr) | |
| 1178 | 1178 | { |
| 1179 | 1179 | u32 num_cs; |
| 1180 | 1180 | int error; |
| @@ -1186,12 +1186,12 @@ static int rspi_parse_dt(struct device *dev, struct spi_master *master) · 5 unmodified lines | ||
| 1186 | 1186 | return error; |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | − master->num_chipselect = num_cs; | |
| 1189 | + ctlr->num_chipselect = num_cs; | |
| 1190 | 1190 | return 0; |
| 1191 | 1191 | } |
| 1192 | 1192 | #else |
| 1193 | 1193 | #define rspi_of_match NULL |
| 1194 | −static inline int rspi_parse_dt(struct device *dev, struct spi_master *master) | |
| 1194 | +static inline int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr) | |
| 1195 | 1195 | { |
| 1196 | 1196 | return -EINVAL; |
| 1197 | 1197 | } |
| @@ -1212,28 +1212,28 @@ static int rspi_request_irq(struct device *dev, unsigned int irq, · 14 unmodified lines | ||
| 1212 | 1212 | static int rspi_probe(struct platform_device *pdev) |
| 1213 | 1213 | { |
| 1214 | 1214 | struct resource *res; |
| 1215 | − struct spi_master *master; | |
| 1215 | + struct spi_controller *ctlr; | |
| 1216 | 1216 | struct rspi_data *rspi; |
| 1217 | 1217 | int ret; |
| 1218 | 1218 | const struct rspi_plat_data *rspi_pd; |
| 1219 | 1219 | const struct spi_ops *ops; |
| 1220 | 1220 | |
| 1221 | − master = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data)); | |
| 1222 | − if (master == NULL) | |
| 1221 | + ctlr = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data)); | |
| 1222 | + if (ctlr == NULL) | |
| 1223 | 1223 | return -ENOMEM; |
| 1224 | 1224 | |
| 1225 | 1225 | ops = of_device_get_match_data(&pdev->dev); |
| 1226 | 1226 | if (ops) { |
| 1227 | − ret = rspi_parse_dt(&pdev->dev, master); | |
| 1227 | + ret = rspi_parse_dt(&pdev->dev, ctlr); | |
| 1228 | 1228 | if (ret) |
| 1229 | 1229 | goto error1; |
| 1230 | 1230 | } else { |
| 1231 | 1231 | ops = (struct spi_ops *)pdev->id_entry->driver_data; |
| 1232 | 1232 | rspi_pd = dev_get_platdata(&pdev->dev); |
| 1233 | 1233 | if (rspi_pd && rspi_pd->num_chipselect) |
| 1234 | − master->num_chipselect = rspi_pd->num_chipselect; | |
| 1234 | + ctlr->num_chipselect = rspi_pd->num_chipselect; | |
| 1235 | 1235 | else |
| 1236 | − master->num_chipselect = 2; /* default */ | |
| 1236 | + ctlr->num_chipselect = 2; /* default */ | |
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | /* ops parameter check */ |
| @@ -1243,10 +1243,10 @@ static int rspi_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 1243 | 1243 | goto error1; |
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | − rspi = spi_master_get_devdata(master); | |
| 1246 | + rspi = spi_controller_get_devdata(ctlr); | |
| 1247 | 1247 | platform_set_drvdata(pdev, rspi); |
| 1248 | 1248 | rspi->ops = ops; |
| 1249 | − rspi->master = master; | |
| 1249 | + rspi->ctlr = ctlr; | |
| 1250 | 1250 | |
| 1251 | 1251 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1252 | 1252 | rspi->addr = devm_ioremap_resource(&pdev->dev, res); |
| @@ -1266,15 +1266,15 @@ static int rspi_probe(struct platform_device *pdev) · 13 unmodified lines | ||
| 1266 | 1266 | |
| 1267 | 1267 | init_waitqueue_head(&rspi->wait); |
| 1268 | 1268 | |
| 1269 | − master->bus_num = pdev->id; | |
| 1270 | − master->setup = rspi_setup; | |
| 1271 | − master->auto_runtime_pm = true; | |
| 1272 | − master->transfer_one = ops->transfer_one; | |
| 1273 | − master->prepare_message = rspi_prepare_message; | |
| 1274 | − master->unprepare_message = rspi_unprepare_message; | |
| 1275 | − master->mode_bits = ops->mode_bits; | |
| 1276 | − master->flags = ops->flags; | |
| 1277 | − master->dev.of_node = pdev->dev.of_node; | |
| 1269 | + ctlr->bus_num = pdev->id; | |
| 1270 | + ctlr->setup = rspi_setup; | |
| 1271 | + ctlr->auto_runtime_pm = true; | |
| 1272 | + ctlr->transfer_one = ops->transfer_one; | |
| 1273 | + ctlr->prepare_message = rspi_prepare_message; | |
| 1274 | + ctlr->unprepare_message = rspi_unprepare_message; | |
| 1275 | + ctlr->mode_bits = ops->mode_bits; | |
| 1276 | + ctlr->flags = ops->flags; | |
| 1277 | + ctlr->dev.of_node = pdev->dev.of_node; | |
| 1278 | 1278 | |
| 1279 | 1279 | ret = platform_get_irq_byname(pdev, "rx"); |
| 1280 | 1280 | if (ret < 0) { |
| @@ -1311,13 +1311,13 @@ static int rspi_probe(struct platform_device *pdev) · 30 unmodified lines | ||
| 1311 | 1311 | goto error2; |
| 1312 | 1312 | } |
| 1313 | 1313 | |
| 1314 | − ret = rspi_request_dma(&pdev->dev, master, res); | |
| 1314 | + ret = rspi_request_dma(&pdev->dev, ctlr, res); | |
| 1315 | 1315 | if (ret < 0) |
| 1316 | 1316 | dev_warn(&pdev->dev, "DMA not available, using PIO\n"); |
| 1317 | 1317 | |
| 1318 | − ret = devm_spi_register_master(&pdev->dev, master); | |
| 1318 | + ret = devm_spi_register_controller(&pdev->dev, ctlr); | |
| 1319 | 1319 | if (ret < 0) { |
| 1320 | − dev_err(&pdev->dev, "spi_register_master error.\n"); | |
| 1320 | + dev_err(&pdev->dev, "devm_spi_register_controller error.\n"); | |
| 1321 | 1321 | goto error3; |
| 1322 | 1322 | } |
| 1323 | 1323 | |
| @@ -1326,11 +1326,11 @@ static int rspi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1326 | 1326 | return 0; |
| 1327 | 1327 | |
| 1328 | 1328 | error3: |
| 1329 | − rspi_release_dma(master); | |
| 1329 | + rspi_release_dma(ctlr); | |
| 1330 | 1330 | error2: |
| 1331 | 1331 | pm_runtime_disable(&pdev->dev); |
| 1332 | 1332 | error1: |
| 1333 | − spi_master_put(master); | |
| 1333 | + spi_controller_put(ctlr); | |
| 1334 | 1334 | |
| 1335 | 1335 | return ret; |
| 1336 | 1336 | } |
| @@ -1349,14 +1349,14 @@ static int rspi_suspend(struct device *dev) · 12 unmodified lines | ||
| 1349 | 1349 | { |
| 1350 | 1350 | struct rspi_data *rspi = dev_get_drvdata(dev); |
| 1351 | 1351 | |
| 1352 | − return spi_master_suspend(rspi->master); | |
| 1352 | + return spi_controller_suspend(rspi->ctlr); | |
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | static int rspi_resume(struct device *dev) |
| 1356 | 1356 | { |
| 1357 | 1357 | struct rspi_data *rspi = dev_get_drvdata(dev); |
| 1358 | 1358 | |
| 1359 | − return spi_master_resume(rspi->master); | |
| 1359 | + return spi_controller_resume(rspi->ctlr); | |
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | static SIMPLE_DEV_PM_OPS(rspi_pm_ops, rspi_suspend, rspi_resume); |
| @@ -35,7 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | |
| 36 | 36 | struct hspi_priv { |
| 37 | 37 | void __iomem *addr; |
| 38 | − struct spi_master *master; | |
| 38 | + struct spi_controller *ctlr; | |
| 39 | 39 | struct device *dev; |
| 40 | 40 | struct clk *clk; |
| 41 | 41 | }; |
| @@ -140,10 +140,10 @@ static void hspi_hw_setup(struct hspi_priv *hspi, · 98 unmodified lines | ||
| 140 | 140 | hspi_write(hspi, SPSCR, 0x21); /* master mode / CS control */ |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | −static int hspi_transfer_one_message(struct spi_master *master, | |
| 143 | +static int hspi_transfer_one_message(struct spi_controller *ctlr, | |
| 144 | 144 | struct spi_message *msg) |
| 145 | 145 | { |
| 146 | − struct hspi_priv *hspi = spi_master_get_devdata(master); | |
| 146 | + struct hspi_priv *hspi = spi_controller_get_devdata(ctlr); | |
| 147 | 147 | struct spi_transfer *t; |
| 148 | 148 | u32 tx; |
| 149 | 149 | u32 rx; |
| @@ -205,7 +205,7 @@ static int hspi_transfer_one_message(struct spi_master *master, · 55 unmodified lines | ||
| 205 | 205 | ndelay(nsecs); |
| 206 | 206 | hspi_hw_cs_disable(hspi); |
| 207 | 207 | } |
| 208 | − spi_finalize_current_message(master); | |
| 208 | + spi_finalize_current_message(ctlr); | |
| 209 | 209 | |
| 210 | 210 | return ret; |
| 211 | 211 | } |
| @@ -213,7 +213,7 @@ static int hspi_transfer_one_message(struct spi_master *master, · 1 unmodified line | ||
| 213 | 213 | static int hspi_probe(struct platform_device *pdev) |
| 214 | 214 | { |
| 215 | 215 | struct resource *res; |
| 216 | − struct spi_master *master; | |
| 216 | + struct spi_controller *ctlr; | |
| 217 | 217 | struct hspi_priv *hspi; |
| 218 | 218 | struct clk *clk; |
| 219 | 219 | int ret; |
| @@ -225,11 +225,9 @@ static int hspi_probe(struct platform_device *pdev) · 5 unmodified lines | ||
| 225 | 225 | return -EINVAL; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | − master = spi_alloc_master(&pdev->dev, sizeof(*hspi)); | |
| 229 | − if (!master) { | |
| 230 | − dev_err(&pdev->dev, "spi_alloc_master error.\n"); | |
| 228 | + ctlr = spi_alloc_master(&pdev->dev, sizeof(*hspi)); | |
| 229 | + if (!ctlr) | |
| 231 | 230 | return -ENOMEM; |
| 232 | − } | |
| 233 | 231 | |
| 234 | 232 | clk = clk_get(&pdev->dev, NULL); |
| 235 | 233 | if (IS_ERR(clk)) { |
| @@ -238,33 +236,32 @@ static int hspi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 238 | 236 | goto error0; |
| 239 | 237 | } |
| 240 | 238 | |
| 241 | − hspi = spi_master_get_devdata(master); | |
| 239 | + hspi = spi_controller_get_devdata(ctlr); | |
| 242 | 240 | platform_set_drvdata(pdev, hspi); |
| 243 | 241 | |
| 244 | 242 | /* init hspi */ |
| 245 | − hspi->master = master; | |
| 243 | + hspi->ctlr = ctlr; | |
| 246 | 244 | hspi->dev = &pdev->dev; |
| 247 | 245 | hspi->clk = clk; |
| 248 | 246 | hspi->addr = devm_ioremap(hspi->dev, |
| 249 | 247 | res->start, resource_size(res)); |
| 250 | 248 | if (!hspi->addr) { |
| 251 | − dev_err(&pdev->dev, "ioremap error.\n"); | |
| 252 | 249 | ret = -ENOMEM; |
| 253 | 250 | goto error1; |
| 254 | 251 | } |
| 255 | 252 | |
| 256 | 253 | pm_runtime_enable(&pdev->dev); |
| 257 | 254 | |
| 258 | − master->bus_num = pdev->id; | |
| 259 | − master->mode_bits = SPI_CPOL | SPI_CPHA; | |
| 260 | − master->dev.of_node = pdev->dev.of_node; | |
| 261 | − master->auto_runtime_pm = true; | |
| 262 | − master->transfer_one_message = hspi_transfer_one_message; | |
| 263 | − master->bits_per_word_mask = SPI_BPW_MASK(8); | |
| 255 | + ctlr->bus_num = pdev->id; | |
| 256 | + ctlr->mode_bits = SPI_CPOL | SPI_CPHA; | |
| 257 | + ctlr->dev.of_node = pdev->dev.of_node; | |
| 258 | + ctlr->auto_runtime_pm = true; | |
| 259 | + ctlr->transfer_one_message = hspi_transfer_one_message; | |
| 260 | + ctlr->bits_per_word_mask = SPI_BPW_MASK(8); | |
| 264 | 261 | |
| 265 | − ret = devm_spi_register_master(&pdev->dev, master); | |
| 262 | + ret = devm_spi_register_controller(&pdev->dev, ctlr); | |
| 266 | 263 | if (ret < 0) { |
| 267 | − dev_err(&pdev->dev, "spi_register_master error.\n"); | |
| 264 | + dev_err(&pdev->dev, "devm_spi_register_controller error.\n"); | |
| 268 | 265 | goto error2; |
| 269 | 266 | } |
| 270 | 267 | |
| @@ -275,7 +272,7 @@ static int hspi_probe(struct platform_device *pdev) · 4 unmodified lines | ||
| 275 | 272 | error1: |
| 276 | 273 | clk_put(clk); |
| 277 | 274 | error0: |
| 278 | − spi_master_put(master); | |
| 275 | + spi_controller_put(ctlr); | |
| 279 | 276 | |
| 280 | 277 | return ret; |
| 281 | 278 | } |
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | 2 | /* |
| 3 | − * SuperH MSIOF SPI Master Interface | |
| 3 | + * SuperH MSIOF SPI Controller Interface | |
| 4 | 4 | * |
| 5 | 5 | * Copyright (c) 2009 Magnus Damm |
| 6 | 6 | * Copyright (C) 2014 Renesas Electronics Corporation |
| @@ -32,14 +32,15 @@ · 25 unmodified lines | ||
| 32 | 32 | #include <asm/unaligned.h> |
| 33 | 33 | |
| 34 | 34 | struct sh_msiof_chipdata { |
| 35 | + u32 bits_per_word_mask; | |
| 35 | 36 | u16 tx_fifo_size; |
| 36 | 37 | u16 rx_fifo_size; |
| 37 | − u16 master_flags; | |
| 38 | + u16 ctlr_flags; | |
| 38 | 39 | u16 min_div_pow; |
| 39 | 40 | }; |
| 40 | 41 | |
| 41 | 42 | struct sh_msiof_spi_priv { |
| 42 | − struct spi_master *master; | |
| 43 | + struct spi_controller *ctlr; | |
| 43 | 44 | void __iomem *mapbase; |
| 44 | 45 | struct clk *clk; |
| 45 | 46 | struct platform_device *pdev; |
| @@ -287,7 +288,7 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p, · 241 unmodified lines | ||
| 287 | 288 | |
| 288 | 289 | scr = sh_msiof_spi_div_array[div_pow] | SCR_BRPS(brps); |
| 289 | 290 | sh_msiof_write(p, TSCR, scr); |
| 290 | − if (!(p->master->flags & SPI_MASTER_MUST_TX)) | |
| 291 | + if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX)) | |
| 291 | 292 | sh_msiof_write(p, RSCR, scr); |
| 292 | 293 | } |
| 293 | 294 | |
| @@ -351,14 +352,14 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss, · 57 unmodified lines | ||
| 351 | 352 | tmp |= !cs_high << MDR1_SYNCAC_SHIFT; |
| 352 | 353 | tmp |= lsb_first << MDR1_BITLSB_SHIFT; |
| 353 | 354 | tmp |= sh_msiof_spi_get_dtdl_and_syncdl(p); |
| 354 | − if (spi_controller_is_slave(p->master)) { | |
| 355 | + if (spi_controller_is_slave(p->ctlr)) { | |
| 355 | 356 | sh_msiof_write(p, TMDR1, tmp | TMDR1_PCON); |
| 356 | 357 | } else { |
| 357 | 358 | sh_msiof_write(p, TMDR1, |
| 358 | 359 | tmp | MDR1_TRMD | TMDR1_PCON | |
| 359 | 360 | (ss < MAX_SS ? ss : 0) << TMDR1_SYNCCH_SHIFT); |
| 360 | 361 | } |
| 361 | − if (p->master->flags & SPI_MASTER_MUST_TX) { | |
| 362 | + if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) { | |
| 362 | 363 | /* These bits are reserved if RX needs TX */ |
| 363 | 364 | tmp &= ~0x0000ffff; |
| 364 | 365 | } |
| @@ -382,7 +383,7 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p, · 17 unmodified lines | ||
| 382 | 383 | { |
| 383 | 384 | u32 dr2 = MDR2_BITLEN1(bits) | MDR2_WDLEN1(words); |
| 384 | 385 | |
| 385 | − if (tx_buf || (p->master->flags & SPI_MASTER_MUST_TX)) | |
| 386 | + if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX)) | |
| 386 | 387 | sh_msiof_write(p, TMDR2, dr2); |
| 387 | 388 | else |
| 388 | 389 | sh_msiof_write(p, TMDR2, dr2 | MDR2_GRPMASK1); |
| @@ -539,8 +540,9 @@ static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p, · 150 unmodified lines | ||
| 539 | 540 | |
| 540 | 541 | static int sh_msiof_spi_setup(struct spi_device *spi) |
| 541 | 542 | { |
| 542 | − struct device_node *np = spi->master->dev.of_node; | |
| 543 | − struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); | |
| 543 | + struct device_node *np = spi->controller->dev.of_node; | |
| 544 | + struct sh_msiof_spi_priv *p = | |
| 545 | + spi_controller_get_devdata(spi->controller); | |
| 544 | 546 | u32 clr, set, tmp; |
| 545 | 547 | |
| 546 | 548 | if (!np) { |
| @@ -556,7 +558,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi) · 9 unmodified lines | ||
| 556 | 558 | return 0; |
| 557 | 559 | } |
| 558 | 560 | |
| 559 | − if (spi_controller_is_slave(p->master)) | |
| 561 | + if (spi_controller_is_slave(p->ctlr)) | |
| 560 | 562 | return 0; |
| 561 | 563 | |
| 562 | 564 | if (p->native_cs_inited && |
| @@ -581,10 +583,10 @@ static int sh_msiof_spi_setup(struct spi_device *spi) · 18 unmodified lines | ||
| 581 | 583 | return 0; |
| 582 | 584 | } |
| 583 | 585 | |
| 584 | −static int sh_msiof_prepare_message(struct spi_master *master, | |
| 586 | +static int sh_msiof_prepare_message(struct spi_controller *ctlr, | |
| 585 | 587 | struct spi_message *msg) |
| 586 | 588 | { |
| 587 | − struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | |
| 589 | + struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr); | |
| 588 | 590 | const struct spi_device *spi = msg->spi; |
| 589 | 591 | u32 ss, cs_high; |
| 590 | 592 | |
| @@ -605,7 +607,7 @@ static int sh_msiof_prepare_message(struct spi_master *master, · 14 unmodified lines | ||
| 605 | 607 | |
| 606 | 608 | static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf) |
| 607 | 609 | { |
| 608 | − bool slave = spi_controller_is_slave(p->master); | |
| 610 | + bool slave = spi_controller_is_slave(p->ctlr); | |
| 609 | 611 | int ret = 0; |
| 610 | 612 | |
| 611 | 613 | /* setup clock and rx/tx signals */ |
| @@ -625,7 +627,7 @@ static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf) · 13 unmodified lines | ||
| 625 | 627 | |
| 626 | 628 | static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf) |
| 627 | 629 | { |
| 628 | − bool slave = spi_controller_is_slave(p->master); | |
| 630 | + bool slave = spi_controller_is_slave(p->ctlr); | |
| 629 | 631 | int ret = 0; |
| 630 | 632 | |
| 631 | 633 | /* shut down frame, rx/tx and clock signals */ |
| @@ -641,9 +643,9 @@ static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf) · 9 unmodified lines | ||
| 641 | 643 | return ret; |
| 642 | 644 | } |
| 643 | 645 | |
| 644 | −static int sh_msiof_slave_abort(struct spi_master *master) | |
| 646 | +static int sh_msiof_slave_abort(struct spi_controller *ctlr) | |
| 645 | 647 | { |
| 646 | − struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | |
| 648 | + struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr); | |
| 647 | 649 | |
| 648 | 650 | p->slave_aborted = true; |
| 649 | 651 | complete(&p->done); |
| @@ -654,7 +656,7 @@ static int sh_msiof_slave_abort(struct spi_master *master) · 4 unmodified lines | ||
| 654 | 656 | static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p, |
| 655 | 657 | struct completion *x) |
| 656 | 658 | { |
| 657 | − if (spi_controller_is_slave(p->master)) { | |
| 659 | + if (spi_controller_is_slave(p->ctlr)) { | |
| 658 | 660 | if (wait_for_completion_interruptible(x) || |
| 659 | 661 | p->slave_aborted) { |
| 660 | 662 | dev_dbg(&p->pdev->dev, "interrupted\n"); |
| @@ -754,7 +756,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 93 unmodified lines | ||
| 754 | 756 | /* First prepare and submit the DMA request(s), as this may fail */ |
| 755 | 757 | if (rx) { |
| 756 | 758 | ier_bits |= IER_RDREQE | IER_RDMAE; |
| 757 | − desc_rx = dmaengine_prep_slave_single(p->master->dma_rx, | |
| 759 | + desc_rx = dmaengine_prep_slave_single(p->ctlr->dma_rx, | |
| 758 | 760 | p->rx_dma_addr, len, DMA_DEV_TO_MEM, |
| 759 | 761 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 760 | 762 | if (!desc_rx) |
| @@ -769,9 +771,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 8 unmodified lines | ||
| 769 | 771 | |
| 770 | 772 | if (tx) { |
| 771 | 773 | ier_bits |= IER_TDREQE | IER_TDMAE; |
| 772 | − dma_sync_single_for_device(p->master->dma_tx->device->dev, | |
| 774 | + dma_sync_single_for_device(p->ctlr->dma_tx->device->dev, | |
| 773 | 775 | p->tx_dma_addr, len, DMA_TO_DEVICE); |
| 774 | − desc_tx = dmaengine_prep_slave_single(p->master->dma_tx, | |
| 776 | + desc_tx = dmaengine_prep_slave_single(p->ctlr->dma_tx, | |
| 775 | 777 | p->tx_dma_addr, len, DMA_MEM_TO_DEV, |
| 776 | 778 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 777 | 779 | if (!desc_tx) { |
| @@ -803,9 +805,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 25 unmodified lines | ||
| 803 | 805 | |
| 804 | 806 | /* Now start DMA */ |
| 805 | 807 | if (rx) |
| 806 | − dma_async_issue_pending(p->master->dma_rx); | |
| 808 | + dma_async_issue_pending(p->ctlr->dma_rx); | |
| 807 | 809 | if (tx) |
| 808 | − dma_async_issue_pending(p->master->dma_tx); | |
| 810 | + dma_async_issue_pending(p->ctlr->dma_tx); | |
| 809 | 811 | |
| 810 | 812 | ret = sh_msiof_spi_start(p, rx); |
| 811 | 813 | if (ret) { |
| @@ -845,9 +847,8 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 33 unmodified lines | ||
| 845 | 847 | } |
| 846 | 848 | |
| 847 | 849 | if (rx) |
| 848 | − dma_sync_single_for_cpu(p->master->dma_rx->device->dev, | |
| 849 | − p->rx_dma_addr, len, | |
| 850 | − DMA_FROM_DEVICE); | |
| 850 | + dma_sync_single_for_cpu(p->ctlr->dma_rx->device->dev, | |
| 851 | + p->rx_dma_addr, len, DMA_FROM_DEVICE); | |
| 851 | 852 | |
| 852 | 853 | return 0; |
| 853 | 854 | |
| @@ -856,10 +857,10 @@ stop_reset: · 2 unmodified lines | ||
| 856 | 857 | sh_msiof_spi_stop(p, rx); |
| 857 | 858 | stop_dma: |
| 858 | 859 | if (tx) |
| 859 | − dmaengine_terminate_all(p->master->dma_tx); | |
| 860 | + dmaengine_terminate_all(p->ctlr->dma_tx); | |
| 860 | 861 | no_dma_tx: |
| 861 | 862 | if (rx) |
| 862 | − dmaengine_terminate_all(p->master->dma_rx); | |
| 863 | + dmaengine_terminate_all(p->ctlr->dma_rx); | |
| 863 | 864 | sh_msiof_write(p, IER, 0); |
| 864 | 865 | return ret; |
| 865 | 866 | } |
| @@ -907,11 +908,11 @@ static void copy_plain32(u32 *dst, const u32 *src, unsigned int words) · 41 unmodified lines | ||
| 907 | 908 | memcpy(dst, src, words * 4); |
| 908 | 909 | } |
| 909 | 910 | |
| 910 | −static int sh_msiof_transfer_one(struct spi_master *master, | |
| 911 | +static int sh_msiof_transfer_one(struct spi_controller *ctlr, | |
| 911 | 912 | struct spi_device *spi, |
| 912 | 913 | struct spi_transfer *t) |
| 913 | 914 | { |
| 914 | − struct sh_msiof_spi_priv *p = spi_master_get_devdata(master); | |
| 915 | + struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr); | |
| 915 | 916 | void (*copy32)(u32 *, const u32 *, unsigned int); |
| 916 | 917 | void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int); |
| 917 | 918 | void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int); |
| @@ -926,10 +927,10 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 8 unmodified lines | ||
| 926 | 927 | int ret; |
| 927 | 928 | |
| 928 | 929 | /* setup clocks (clock already enabled in chipselect()) */ |
| 929 | − if (!spi_controller_is_slave(p->master)) | |
| 930 | + if (!spi_controller_is_slave(p->ctlr)) | |
| 930 | 931 | sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); |
| 931 | 932 | |
| 932 | − while (master->dma_tx && len > 15) { | |
| 933 | + while (ctlr->dma_tx && len > 15) { | |
| 933 | 934 | /* |
| 934 | 935 | * DMA supports 32-bit words only, hence pack 8-bit and 16-bit |
| 935 | 936 | * words, with byte resp. word swapping. |
| @@ -937,17 +938,13 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 1 unmodified line | ||
| 937 | 938 | unsigned int l = 0; |
| 938 | 939 | |
| 939 | 940 | if (tx_buf) |
| 940 | − l = min(len, p->tx_fifo_size * 4); | |
| 941 | + l = min(round_down(len, 4), p->tx_fifo_size * 4); | |
| 941 | 942 | if (rx_buf) |
| 942 | − l = min(len, p->rx_fifo_size * 4); | |
| 943 | + l = min(round_down(len, 4), p->rx_fifo_size * 4); | |
| 943 | 944 | |
| 944 | 945 | if (bits <= 8) { |
| 945 | − if (l & 3) | |
| 946 | − break; | |
| 947 | 946 | copy32 = copy_bswap32; |
| 948 | 947 | } else if (bits <= 16) { |
| 949 | − if (l & 3) | |
| 950 | − break; | |
| 951 | 948 | copy32 = copy_wswap32; |
| 952 | 949 | } else { |
| 953 | 950 | copy32 = copy_plain32; |
| @@ -1052,23 +1049,28 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 98 unmodified lines | ||
| 1052 | 1049 | } |
| 1053 | 1050 | |
| 1054 | 1051 | static const struct sh_msiof_chipdata sh_data = { |
| 1052 | + .bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32), | |
| 1055 | 1053 | .tx_fifo_size = 64, |
| 1056 | 1054 | .rx_fifo_size = 64, |
| 1057 | − .master_flags = 0, | |
| 1055 | + .ctlr_flags = 0, | |
| 1058 | 1056 | .min_div_pow = 0, |
| 1059 | 1057 | }; |
| 1060 | 1058 | |
| 1061 | 1059 | static const struct sh_msiof_chipdata rcar_gen2_data = { |
| 1060 | + .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) | | |
| 1061 | + SPI_BPW_MASK(24) | SPI_BPW_MASK(32), | |
| 1062 | 1062 | .tx_fifo_size = 64, |
| 1063 | 1063 | .rx_fifo_size = 64, |
| 1064 | − .master_flags = SPI_MASTER_MUST_TX, | |
| 1064 | + .ctlr_flags = SPI_CONTROLLER_MUST_TX, | |
| 1065 | 1065 | .min_div_pow = 0, |
| 1066 | 1066 | }; |
| 1067 | 1067 | |
| 1068 | 1068 | static const struct sh_msiof_chipdata rcar_gen3_data = { |
| 1069 | + .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) | | |
| 1070 | + SPI_BPW_MASK(24) | SPI_BPW_MASK(32), | |
| 1069 | 1071 | .tx_fifo_size = 64, |
| 1070 | 1072 | .rx_fifo_size = 64, |
| 1071 | − .master_flags = SPI_MASTER_MUST_TX, | |
| 1073 | + .ctlr_flags = SPI_CONTROLLER_MUST_TX, | |
| 1072 | 1074 | .min_div_pow = 1, |
| 1073 | 1075 | }; |
| 1074 | 1076 | |
| @@ -1136,7 +1138,7 @@ static int sh_msiof_get_cs_gpios(struct sh_msiof_spi_priv *p) · 61 unmodified lines | ||
| 1136 | 1138 | if (ret <= 0) |
| 1137 | 1139 | return 0; |
| 1138 | 1140 | |
| 1139 | − num_cs = max_t(unsigned int, ret, p->master->num_chipselect); | |
| 1141 | + num_cs = max_t(unsigned int, ret, p->ctlr->num_chipselect); | |
| 1140 | 1142 | for (i = 0; i < num_cs; i++) { |
| 1141 | 1143 | struct gpio_desc *gpiod; |
| 1142 | 1144 | |
| @@ -1206,10 +1208,10 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 63 unmodified lines | ||
| 1206 | 1208 | { |
| 1207 | 1209 | struct platform_device *pdev = p->pdev; |
| 1208 | 1210 | struct device *dev = &pdev->dev; |
| 1209 | − const struct sh_msiof_spi_info *info = dev_get_platdata(dev); | |
| 1211 | + const struct sh_msiof_spi_info *info = p->info; | |
| 1210 | 1212 | unsigned int dma_tx_id, dma_rx_id; |
| 1211 | 1213 | const struct resource *res; |
| 1212 | − struct spi_master *master; | |
| 1214 | + struct spi_controller *ctlr; | |
| 1213 | 1215 | struct device *tx_dev, *rx_dev; |
| 1214 | 1216 | |
| 1215 | 1217 | if (dev->of_node) { |
| @@ -1229,17 +1231,15 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 13 unmodified lines | ||
| 1229 | 1231 | if (!res) |
| 1230 | 1232 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1231 | 1233 | |
| 1232 | − master = p->master; | |
| 1233 | − master->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV, | |
| 1234 | − dma_tx_id, | |
| 1235 | − res->start + TFDR); | |
| 1236 | − if (!master->dma_tx) | |
| 1234 | + ctlr = p->ctlr; | |
| 1235 | + ctlr->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV, | |
| 1236 | + dma_tx_id, res->start + TFDR); | |
| 1237 | + if (!ctlr->dma_tx) | |
| 1237 | 1238 | return -ENODEV; |
| 1238 | 1239 | |
| 1239 | − master->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM, | |
| 1240 | − dma_rx_id, | |
| 1241 | − res->start + RFDR); | |
| 1242 | − if (!master->dma_rx) | |
| 1240 | + ctlr->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM, | |
| 1241 | + dma_rx_id, res->start + RFDR); | |
| 1242 | + if (!ctlr->dma_rx) | |
| 1243 | 1243 | goto free_tx_chan; |
| 1244 | 1244 | |
| 1245 | 1245 | p->tx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); |
| @@ -1250,13 +1250,13 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 4 unmodified lines | ||
| 1250 | 1250 | if (!p->rx_dma_page) |
| 1251 | 1251 | goto free_tx_page; |
| 1252 | 1252 | |
| 1253 | − tx_dev = master->dma_tx->device->dev; | |
| 1253 | + tx_dev = ctlr->dma_tx->device->dev; | |
| 1254 | 1254 | p->tx_dma_addr = dma_map_single(tx_dev, p->tx_dma_page, PAGE_SIZE, |
| 1255 | 1255 | DMA_TO_DEVICE); |
| 1256 | 1256 | if (dma_mapping_error(tx_dev, p->tx_dma_addr)) |
| 1257 | 1257 | goto free_rx_page; |
| 1258 | 1258 | |
| 1259 | − rx_dev = master->dma_rx->device->dev; | |
| 1259 | + rx_dev = ctlr->dma_rx->device->dev; | |
| 1260 | 1260 | p->rx_dma_addr = dma_map_single(rx_dev, p->rx_dma_page, PAGE_SIZE, |
| 1261 | 1261 | DMA_FROM_DEVICE); |
| 1262 | 1262 | if (dma_mapping_error(rx_dev, p->rx_dma_addr)) |
| @@ -1272,34 +1272,34 @@ free_rx_page: · 9 unmodified lines | ||
| 1272 | 1272 | free_tx_page: |
| 1273 | 1273 | free_page((unsigned long)p->tx_dma_page); |
| 1274 | 1274 | free_rx_chan: |
| 1275 | − dma_release_channel(master->dma_rx); | |
| 1275 | + dma_release_channel(ctlr->dma_rx); | |
| 1276 | 1276 | free_tx_chan: |
| 1277 | − dma_release_channel(master->dma_tx); | |
| 1278 | − master->dma_tx = NULL; | |
| 1277 | + dma_release_channel(ctlr->dma_tx); | |
| 1278 | + ctlr->dma_tx = NULL; | |
| 1279 | 1279 | return -ENODEV; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | static void sh_msiof_release_dma(struct sh_msiof_spi_priv *p) |
| 1283 | 1283 | { |
| 1284 | − struct spi_master *master = p->master; | |
| 1284 | + struct spi_controller *ctlr = p->ctlr; | |
| 1285 | 1285 | |
| 1286 | − if (!master->dma_tx) | |
| 1286 | + if (!ctlr->dma_tx) | |
| 1287 | 1287 | return; |
| 1288 | 1288 | |
| 1289 | − dma_unmap_single(master->dma_rx->device->dev, p->rx_dma_addr, | |
| 1290 | − PAGE_SIZE, DMA_FROM_DEVICE); | |
| 1291 | − dma_unmap_single(master->dma_tx->device->dev, p->tx_dma_addr, | |
| 1292 | − PAGE_SIZE, DMA_TO_DEVICE); | |
| 1289 | + dma_unmap_single(ctlr->dma_rx->device->dev, p->rx_dma_addr, PAGE_SIZE, | |
| 1290 | + DMA_FROM_DEVICE); | |
| 1291 | + dma_unmap_single(ctlr->dma_tx->device->dev, p->tx_dma_addr, PAGE_SIZE, | |
| 1292 | + DMA_TO_DEVICE); | |
| 1293 | 1293 | free_page((unsigned long)p->rx_dma_page); |
| 1294 | 1294 | free_page((unsigned long)p->tx_dma_page); |
| 1295 | − dma_release_channel(master->dma_rx); | |
| 1296 | − dma_release_channel(master->dma_tx); | |
| 1295 | + dma_release_channel(ctlr->dma_rx); | |
| 1296 | + dma_release_channel(ctlr->dma_tx); | |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | static int sh_msiof_spi_probe(struct platform_device *pdev) |
| 1300 | 1300 | { |
| 1301 | 1301 | struct resource *r; |
| 1302 | − struct spi_master *master; | |
| 1302 | + struct spi_controller *ctlr; | |
| 1303 | 1303 | const struct sh_msiof_chipdata *chipdata; |
| 1304 | 1304 | struct sh_msiof_spi_info *info; |
| 1305 | 1305 | struct sh_msiof_spi_priv *p; |
| @@ -1320,18 +1320,18 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 14 unmodified lines | ||
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | if (info->mode == MSIOF_SPI_SLAVE) |
| 1323 | − master = spi_alloc_slave(&pdev->dev, | |
| 1324 | − sizeof(struct sh_msiof_spi_priv)); | |
| 1323 | + ctlr = spi_alloc_slave(&pdev->dev, | |
| 1324 | + sizeof(struct sh_msiof_spi_priv)); | |
| 1325 | 1325 | else |
| 1326 | − master = spi_alloc_master(&pdev->dev, | |
| 1327 | − sizeof(struct sh_msiof_spi_priv)); | |
| 1328 | − if (master == NULL) | |
| 1326 | + ctlr = spi_alloc_master(&pdev->dev, | |
| 1327 | + sizeof(struct sh_msiof_spi_priv)); | |
| 1328 | + if (ctlr == NULL) | |
| 1329 | 1329 | return -ENOMEM; |
| 1330 | 1330 | |
| 1331 | − p = spi_master_get_devdata(master); | |
| 1331 | + p = spi_controller_get_devdata(ctlr); | |
| 1332 | 1332 | |
| 1333 | 1333 | platform_set_drvdata(pdev, p); |
| 1334 | − p->master = master; | |
| 1334 | + p->ctlr = ctlr; | |
| 1335 | 1335 | p->info = info; |
| 1336 | 1336 | p->min_div_pow = chipdata->min_div_pow; |
| 1337 | 1337 | |
| @@ -1378,31 +1378,31 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 40 unmodified lines | ||
| 1378 | 1378 | p->rx_fifo_size = p->info->rx_fifo_override; |
| 1379 | 1379 | |
| 1380 | 1380 | /* Setup GPIO chip selects */ |
| 1381 | − master->num_chipselect = p->info->num_chipselect; | |
| 1381 | + ctlr->num_chipselect = p->info->num_chipselect; | |
| 1382 | 1382 | ret = sh_msiof_get_cs_gpios(p); |
| 1383 | 1383 | if (ret) |
| 1384 | 1384 | goto err1; |
| 1385 | 1385 | |
| 1386 | − /* init master code */ | |
| 1387 | − master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; | |
| 1388 | − master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE; | |
| 1389 | − master->flags = chipdata->master_flags; | |
| 1390 | − master->bus_num = pdev->id; | |
| 1391 | − master->dev.of_node = pdev->dev.of_node; | |
| 1392 | − master->setup = sh_msiof_spi_setup; | |
| 1393 | − master->prepare_message = sh_msiof_prepare_message; | |
| 1394 | − master->slave_abort = sh_msiof_slave_abort; | |
| 1395 | − master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32); | |
| 1396 | − master->auto_runtime_pm = true; | |
| 1397 | − master->transfer_one = sh_msiof_transfer_one; | |
| 1386 | + /* init controller code */ | |
| 1387 | + ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; | |
| 1388 | + ctlr->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE; | |
| 1389 | + ctlr->flags = chipdata->ctlr_flags; | |
| 1390 | + ctlr->bus_num = pdev->id; | |
| 1391 | + ctlr->dev.of_node = pdev->dev.of_node; | |
| 1392 | + ctlr->setup = sh_msiof_spi_setup; | |
| 1393 | + ctlr->prepare_message = sh_msiof_prepare_message; | |
| 1394 | + ctlr->slave_abort = sh_msiof_slave_abort; | |
| 1395 | + ctlr->bits_per_word_mask = chipdata->bits_per_word_mask; | |
| 1396 | + ctlr->auto_runtime_pm = true; | |
| 1397 | + ctlr->transfer_one = sh_msiof_transfer_one; | |
| 1398 | 1398 | |
| 1399 | 1399 | ret = sh_msiof_request_dma(p); |
| 1400 | 1400 | if (ret < 0) |
| 1401 | 1401 | dev_warn(&pdev->dev, "DMA not available, using PIO\n"); |
| 1402 | 1402 | |
| 1403 | − ret = devm_spi_register_master(&pdev->dev, master); | |
| 1403 | + ret = devm_spi_register_controller(&pdev->dev, ctlr); | |
| 1404 | 1404 | if (ret < 0) { |
| 1405 | − dev_err(&pdev->dev, "spi_register_master error.\n"); | |
| 1405 | + dev_err(&pdev->dev, "devm_spi_register_controller error.\n"); | |
| 1406 | 1406 | goto err2; |
| 1407 | 1407 | } |
| 1408 | 1408 | |
| @@ -1412,7 +1412,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 1412 | 1412 | sh_msiof_release_dma(p); |
| 1413 | 1413 | pm_runtime_disable(&pdev->dev); |
| 1414 | 1414 | err1: |
| 1415 | − spi_master_put(master); | |
| 1415 | + spi_controller_put(ctlr); | |
| 1416 | 1416 | return ret; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
| @@ -1436,14 +1436,14 @@ static int sh_msiof_spi_suspend(struct device *dev) · 17 unmodified lines | ||
| 1436 | 1436 | { |
| 1437 | 1437 | struct sh_msiof_spi_priv *p = dev_get_drvdata(dev); |
| 1438 | 1438 | |
| 1439 | − return spi_master_suspend(p->master); | |
| 1439 | + return spi_controller_suspend(p->ctlr); | |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | static int sh_msiof_spi_resume(struct device *dev) |
| 1443 | 1443 | { |
| 1444 | 1444 | struct sh_msiof_spi_priv *p = dev_get_drvdata(dev); |
| 1445 | 1445 | |
| 1446 | − return spi_master_resume(p->master); | |
| 1446 | + return spi_controller_resume(p->ctlr); | |
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | static SIMPLE_DEV_PM_OPS(sh_msiof_spi_pm_ops, sh_msiof_spi_suspend, |
| @@ -1465,7 +1465,7 @@ static struct platform_driver sh_msiof_spi_drv = { · 15 unmodified lines | ||
| 1465 | 1465 | }; |
| 1466 | 1466 | module_platform_driver(sh_msiof_spi_drv); |
| 1467 | 1467 | |
| 1468 | −MODULE_DESCRIPTION("SuperH MSIOF SPI Master Interface Driver"); | |
| 1468 | +MODULE_DESCRIPTION("SuperH MSIOF SPI Controller Interface Driver"); | |
| 1469 | 1469 | MODULE_AUTHOR("Magnus Damm"); |
| 1470 | 1470 | MODULE_LICENSE("GPL v2"); |
| 1471 | 1471 | MODULE_ALIAS("platform:spi_sh_msiof"); |
| @@ -0,0 +1,448 @@ | ||
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 2 | +// | |
| 3 | +// Copyright 2018 SiFive, Inc. | |
| 4 | +// | |
| 5 | +// SiFive SPI controller driver (master mode only) | |
| 6 | +// | |
| 7 | +// Author: SiFive, Inc. | |
| 8 | +// sifive@sifive.com | |
| 9 | + | |
| 10 | +#include <linux/clk.h> | |
| 11 | +#include <linux/module.h> | |
| 12 | +#include <linux/interrupt.h> | |
| 13 | +#include <linux/of.h> | |
| 14 | +#include <linux/platform_device.h> | |
| 15 | +#include <linux/spi/spi.h> | |
| 16 | +#include <linux/io.h> | |
| 17 | +#include <linux/log2.h> | |
| 18 | + | |
| 19 | +#define SIFIVE_SPI_DRIVER_NAME "sifive_spi" | |
| 20 | + | |
| 21 | +#define SIFIVE_SPI_MAX_CS 32 | |
| 22 | +#define SIFIVE_SPI_DEFAULT_DEPTH 8 | |
| 23 | +#define SIFIVE_SPI_DEFAULT_MAX_BITS 8 | |
| 24 | + | |
| 25 | +/* register offsets */ | |
| 26 | +#define SIFIVE_SPI_REG_SCKDIV 0x00 /* Serial clock divisor */ | |
| 27 | +#define SIFIVE_SPI_REG_SCKMODE 0x04 /* Serial clock mode */ | |
| 28 | +#define SIFIVE_SPI_REG_CSID 0x10 /* Chip select ID */ | |
| 29 | +#define SIFIVE_SPI_REG_CSDEF 0x14 /* Chip select default */ | |
| 30 | +#define SIFIVE_SPI_REG_CSMODE 0x18 /* Chip select mode */ | |
| 31 | +#define SIFIVE_SPI_REG_DELAY0 0x28 /* Delay control 0 */ | |
| 32 | +#define SIFIVE_SPI_REG_DELAY1 0x2c /* Delay control 1 */ | |
| 33 | +#define SIFIVE_SPI_REG_FMT 0x40 /* Frame format */ | |
| 34 | +#define SIFIVE_SPI_REG_TXDATA 0x48 /* Tx FIFO data */ | |
| 35 | +#define SIFIVE_SPI_REG_RXDATA 0x4c /* Rx FIFO data */ | |
| 36 | +#define SIFIVE_SPI_REG_TXMARK 0x50 /* Tx FIFO watermark */ | |
| 37 | +#define SIFIVE_SPI_REG_RXMARK 0x54 /* Rx FIFO watermark */ | |
| 38 | +#define SIFIVE_SPI_REG_FCTRL 0x60 /* SPI flash interface control */ | |
| 39 | +#define SIFIVE_SPI_REG_FFMT 0x64 /* SPI flash instruction format */ | |
| 40 | +#define SIFIVE_SPI_REG_IE 0x70 /* Interrupt Enable Register */ | |
| 41 | +#define SIFIVE_SPI_REG_IP 0x74 /* Interrupt Pendings Register */ | |
| 42 | + | |
| 43 | +/* sckdiv bits */ | |
| 44 | +#define SIFIVE_SPI_SCKDIV_DIV_MASK 0xfffU | |
| 45 | + | |
| 46 | +/* sckmode bits */ | |
| 47 | +#define SIFIVE_SPI_SCKMODE_PHA BIT(0) | |
| 48 | +#define SIFIVE_SPI_SCKMODE_POL BIT(1) | |
| 49 | +#define SIFIVE_SPI_SCKMODE_MODE_MASK (SIFIVE_SPI_SCKMODE_PHA | \ | |
| 50 | + SIFIVE_SPI_SCKMODE_POL) | |
| 51 | + | |
| 52 | +/* csmode bits */ | |
| 53 | +#define SIFIVE_SPI_CSMODE_MODE_AUTO 0U | |
| 54 | +#define SIFIVE_SPI_CSMODE_MODE_HOLD 2U | |
| 55 | +#define SIFIVE_SPI_CSMODE_MODE_OFF 3U | |
| 56 | + | |
| 57 | +/* delay0 bits */ | |
| 58 | +#define SIFIVE_SPI_DELAY0_CSSCK(x) ((u32)(x)) | |
| 59 | +#define SIFIVE_SPI_DELAY0_CSSCK_MASK 0xffU | |
| 60 | +#define SIFIVE_SPI_DELAY0_SCKCS(x) ((u32)(x) << 16) | |
| 61 | +#define SIFIVE_SPI_DELAY0_SCKCS_MASK (0xffU << 16) | |
| 62 | + | |
| 63 | +/* delay1 bits */ | |
| 64 | +#define SIFIVE_SPI_DELAY1_INTERCS(x) ((u32)(x)) | |
| 65 | +#define SIFIVE_SPI_DELAY1_INTERCS_MASK 0xffU | |
| 66 | +#define SIFIVE_SPI_DELAY1_INTERXFR(x) ((u32)(x) << 16) | |
| 67 | +#define SIFIVE_SPI_DELAY1_INTERXFR_MASK (0xffU << 16) | |
| 68 | + | |
| 69 | +/* fmt bits */ | |
| 70 | +#define SIFIVE_SPI_FMT_PROTO_SINGLE 0U | |
| 71 | +#define SIFIVE_SPI_FMT_PROTO_DUAL 1U | |
| 72 | +#define SIFIVE_SPI_FMT_PROTO_QUAD 2U | |
| 73 | +#define SIFIVE_SPI_FMT_PROTO_MASK 3U | |
| 74 | +#define SIFIVE_SPI_FMT_ENDIAN BIT(2) | |
| 75 | +#define SIFIVE_SPI_FMT_DIR BIT(3) | |
| 76 | +#define SIFIVE_SPI_FMT_LEN(x) ((u32)(x) << 16) | |
| 77 | +#define SIFIVE_SPI_FMT_LEN_MASK (0xfU << 16) | |
| 78 | + | |
| 79 | +/* txdata bits */ | |
| 80 | +#define SIFIVE_SPI_TXDATA_DATA_MASK 0xffU | |
| 81 | +#define SIFIVE_SPI_TXDATA_FULL BIT(31) | |
| 82 | + | |
| 83 | +/* rxdata bits */ | |
| 84 | +#define SIFIVE_SPI_RXDATA_DATA_MASK 0xffU | |
| 85 | +#define SIFIVE_SPI_RXDATA_EMPTY BIT(31) | |
| 86 | + | |
| 87 | +/* ie and ip bits */ | |
| 88 | +#define SIFIVE_SPI_IP_TXWM BIT(0) | |
| 89 | +#define SIFIVE_SPI_IP_RXWM BIT(1) | |
| 90 | + | |
| 91 | +struct sifive_spi { | |
| 92 | + void __iomem *regs; /* virt. address of control registers */ | |
| 93 | + struct clk *clk; /* bus clock */ | |
| 94 | + unsigned int fifo_depth; /* fifo depth in words */ | |
| 95 | + u32 cs_inactive; /* level of the CS pins when inactive */ | |
| 96 | + struct completion done; /* wake-up from interrupt */ | |
| 97 | +}; | |
| 98 | + | |
| 99 | +static void sifive_spi_write(struct sifive_spi *spi, int offset, u32 value) | |
| 100 | +{ | |
| 101 | + iowrite32(value, spi->regs + offset); | |
| 102 | +} | |
| 103 | + | |
| 104 | +static u32 sifive_spi_read(struct sifive_spi *spi, int offset) | |
| 105 | +{ | |
| 106 | + return ioread32(spi->regs + offset); | |
| 107 | +} | |
| 108 | + | |
| 109 | +static void sifive_spi_init(struct sifive_spi *spi) | |
| 110 | +{ | |
| 111 | + /* Watermark interrupts are disabled by default */ | |
| 112 | + sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0); | |
| 113 | + | |
| 114 | + /* Default watermark FIFO threshold values */ | |
| 115 | + sifive_spi_write(spi, SIFIVE_SPI_REG_TXMARK, 1); | |
| 116 | + sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK, 0); | |
| 117 | + | |
| 118 | + /* Set CS/SCK Delays and Inactive Time to defaults */ | |
| 119 | + sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY0, | |
| 120 | + SIFIVE_SPI_DELAY0_CSSCK(1) | | |
| 121 | + SIFIVE_SPI_DELAY0_SCKCS(1)); | |
| 122 | + sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY1, | |
| 123 | + SIFIVE_SPI_DELAY1_INTERCS(1) | | |
| 124 | + SIFIVE_SPI_DELAY1_INTERXFR(0)); | |
| 125 | + | |
| 126 | + /* Exit specialized memory-mapped SPI flash mode */ | |
| 127 | + sifive_spi_write(spi, SIFIVE_SPI_REG_FCTRL, 0); | |
| 128 | +} | |
| 129 | + | |
| 130 | +static int | |
| 131 | +sifive_spi_prepare_message(struct spi_master *master, struct spi_message *msg) | |
| 132 | +{ | |
| 133 | + struct sifive_spi *spi = spi_master_get_devdata(master); | |
| 134 | + struct spi_device *device = msg->spi; | |
| 135 | + | |
| 136 | + /* Update the chip select polarity */ | |
| 137 | + if (device->mode & SPI_CS_HIGH) | |
| 138 | + spi->cs_inactive &= ~BIT(device->chip_select); | |
| 139 | + else | |
| 140 | + spi->cs_inactive |= BIT(device->chip_select); | |
| 141 | + sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive); | |
| 142 | + | |
| 143 | + /* Select the correct device */ | |
| 144 | + sifive_spi_write(spi, SIFIVE_SPI_REG_CSID, device->chip_select); | |
| 145 | + | |
| 146 | + /* Set clock mode */ | |
| 147 | + sifive_spi_write(spi, SIFIVE_SPI_REG_SCKMODE, | |
| 148 | + device->mode & SIFIVE_SPI_SCKMODE_MODE_MASK); | |
| 149 | + | |
| 150 | + return 0; | |
| 151 | +} | |
| 152 | + | |
| 153 | +static void sifive_spi_set_cs(struct spi_device *device, bool is_high) | |
| 154 | +{ | |
| 155 | + struct sifive_spi *spi = spi_master_get_devdata(device->master); | |
| 156 | + | |
| 157 | + /* Reverse polarity is handled by SCMR/CPOL. Not inverted CS. */ | |
| 158 | + if (device->mode & SPI_CS_HIGH) | |
| 159 | + is_high = !is_high; | |
| 160 | + | |
| 161 | + sifive_spi_write(spi, SIFIVE_SPI_REG_CSMODE, is_high ? | |
| 162 | + SIFIVE_SPI_CSMODE_MODE_AUTO : | |
| 163 | + SIFIVE_SPI_CSMODE_MODE_HOLD); | |
| 164 | +} | |
| 165 | + | |
| 166 | +static int | |
| 167 | +sifive_spi_prep_transfer(struct sifive_spi *spi, struct spi_device *device, | |
| 168 | + struct spi_transfer *t) | |
| 169 | +{ | |
| 170 | + u32 cr; | |
| 171 | + unsigned int mode; | |
| 172 | + | |
| 173 | + /* Calculate and program the clock rate */ | |
| 174 | + cr = DIV_ROUND_UP(clk_get_rate(spi->clk) >> 1, t->speed_hz) - 1; | |
| 175 | + cr &= SIFIVE_SPI_SCKDIV_DIV_MASK; | |
| 176 | + sifive_spi_write(spi, SIFIVE_SPI_REG_SCKDIV, cr); | |
| 177 | + | |
| 178 | + mode = max_t(unsigned int, t->rx_nbits, t->tx_nbits); | |
| 179 | + | |
| 180 | + /* Set frame format */ | |
| 181 | + cr = SIFIVE_SPI_FMT_LEN(t->bits_per_word); | |
| 182 | + switch (mode) { | |
| 183 | + case SPI_NBITS_QUAD: | |
| 184 | + cr |= SIFIVE_SPI_FMT_PROTO_QUAD; | |
| 185 | + break; | |
| 186 | + case SPI_NBITS_DUAL: | |
| 187 | + cr |= SIFIVE_SPI_FMT_PROTO_DUAL; | |
| 188 | + break; | |
| 189 | + default: | |
| 190 | + cr |= SIFIVE_SPI_FMT_PROTO_SINGLE; | |
| 191 | + break; | |
| 192 | + } | |
| 193 | + if (device->mode & SPI_LSB_FIRST) | |
| 194 | + cr |= SIFIVE_SPI_FMT_ENDIAN; | |
| 195 | + if (!t->rx_buf) | |
| 196 | + cr |= SIFIVE_SPI_FMT_DIR; | |
| 197 | + sifive_spi_write(spi, SIFIVE_SPI_REG_FMT, cr); | |
| 198 | + | |
| 199 | + /* We will want to poll if the time we need to wait is | |
| 200 | + * less than the context switching time. | |
| 201 | + * Let's call that threshold 5us. The operation will take: | |
| 202 | + * (8/mode) * fifo_depth / hz <= 5 * 10^-6 | |
| 203 | + * 1600000 * fifo_depth <= hz * mode | |
| 204 | + */ | |
| 205 | + return 1600000 * spi->fifo_depth <= t->speed_hz * mode; | |
| 206 | +} | |
| 207 | + | |
| 208 | +static irqreturn_t sifive_spi_irq(int irq, void *dev_id) | |
| 209 | +{ | |
| 210 | + struct sifive_spi *spi = dev_id; | |
| 211 | + u32 ip = sifive_spi_read(spi, SIFIVE_SPI_REG_IP); | |
| 212 | + | |
| 213 | + if (ip & (SIFIVE_SPI_IP_TXWM | SIFIVE_SPI_IP_RXWM)) { | |
| 214 | + /* Disable interrupts until next transfer */ | |
| 215 | + sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0); | |
| 216 | + complete(&spi->done); | |
| 217 | + return IRQ_HANDLED; | |
| 218 | + } | |
| 219 | + | |
| 220 | + return IRQ_NONE; | |
| 221 | +} | |
| 222 | + | |
| 223 | +static void sifive_spi_wait(struct sifive_spi *spi, u32 bit, int poll) | |
| 224 | +{ | |
| 225 | + if (poll) { | |
| 226 | + u32 cr; | |
| 227 | + | |
| 228 | + do { | |
| 229 | + cr = sifive_spi_read(spi, SIFIVE_SPI_REG_IP); | |
| 230 | + } while (!(cr & bit)); | |
| 231 | + } else { | |
| 232 | + reinit_completion(&spi->done); | |
| 233 | + sifive_spi_write(spi, SIFIVE_SPI_REG_IE, bit); | |
| 234 | + wait_for_completion(&spi->done); | |
| 235 | + } | |
| 236 | +} | |
| 237 | + | |
| 238 | +static void sifive_spi_tx(struct sifive_spi *spi, const u8 *tx_ptr) | |
| 239 | +{ | |
| 240 | + WARN_ON_ONCE((sifive_spi_read(spi, SIFIVE_SPI_REG_TXDATA) | |
| 241 | + & SIFIVE_SPI_TXDATA_FULL) != 0); | |
| 242 | + sifive_spi_write(spi, SIFIVE_SPI_REG_TXDATA, | |
| 243 | + *tx_ptr & SIFIVE_SPI_TXDATA_DATA_MASK); | |
| 244 | +} | |
| 245 | + | |
| 246 | +static void sifive_spi_rx(struct sifive_spi *spi, u8 *rx_ptr) | |
| 247 | +{ | |
| 248 | + u32 data = sifive_spi_read(spi, SIFIVE_SPI_REG_RXDATA); | |
| 249 | + | |
| 250 | + WARN_ON_ONCE((data & SIFIVE_SPI_RXDATA_EMPTY) != 0); | |
| 251 | + *rx_ptr = data & SIFIVE_SPI_RXDATA_DATA_MASK; | |
| 252 | +} | |
| 253 | + | |
| 254 | +static int | |
| 255 | +sifive_spi_transfer_one(struct spi_master *master, struct spi_device *device, | |
| 256 | + struct spi_transfer *t) | |
| 257 | +{ | |
| 258 | + struct sifive_spi *spi = spi_master_get_devdata(master); | |
| 259 | + int poll = sifive_spi_prep_transfer(spi, device, t); | |
| 260 | + const u8 *tx_ptr = t->tx_buf; | |
| 261 | + u8 *rx_ptr = t->rx_buf; | |
| 262 | + unsigned int remaining_words = t->len; | |
| 263 | + | |
| 264 | + while (remaining_words) { | |
| 265 | + unsigned int n_words = min(remaining_words, spi->fifo_depth); | |
| 266 | + unsigned int i; | |
| 267 | + | |
| 268 | + /* Enqueue n_words for transmission */ | |
| 269 | + for (i = 0; i < n_words; i++) | |
| 270 | + sifive_spi_tx(spi, tx_ptr++); | |
| 271 | + | |
| 272 | + if (rx_ptr) { | |
| 273 | + /* Wait for transmission + reception to complete */ | |
| 274 | + sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK, | |
| 275 | + n_words - 1); | |
| 276 | + sifive_spi_wait(spi, SIFIVE_SPI_IP_RXWM, poll); | |
| 277 | + | |
| 278 | + /* Read out all the data from the RX FIFO */ | |
| 279 | + for (i = 0; i < n_words; i++) | |
| 280 | + sifive_spi_rx(spi, rx_ptr++); | |
| 281 | + } else { | |
| 282 | + /* Wait for transmission to complete */ | |
| 283 | + sifive_spi_wait(spi, SIFIVE_SPI_IP_TXWM, poll); | |
| 284 | + } | |
| 285 | + | |
| 286 | + remaining_words -= n_words; | |
| 287 | + } | |
| 288 | + | |
| 289 | + return 0; | |
| 290 | +} | |
| 291 | + | |
| 292 | +static int sifive_spi_probe(struct platform_device *pdev) | |
| 293 | +{ | |
| 294 | + struct sifive_spi *spi; | |
| 295 | + struct resource *res; | |
| 296 | + int ret, irq, num_cs; | |
| 297 | + u32 cs_bits, max_bits_per_word; | |
| 298 | + struct spi_master *master; | |
| 299 | + | |
| 300 | + master = spi_alloc_master(&pdev->dev, sizeof(struct sifive_spi)); | |
| 301 | + if (!master) { | |
| 302 | + dev_err(&pdev->dev, "out of memory\n"); | |
| 303 | + return -ENOMEM; | |
| 304 | + } | |
| 305 | + | |
| 306 | + spi = spi_master_get_devdata(master); | |
| 307 | + init_completion(&spi->done); | |
| 308 | + platform_set_drvdata(pdev, master); | |
| 309 | + | |
| 310 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
| 311 | + spi->regs = devm_ioremap_resource(&pdev->dev, res); | |
| 312 | + if (IS_ERR(spi->regs)) { | |
| 313 | + ret = PTR_ERR(spi->regs); | |
| 314 | + goto put_master; | |
| 315 | + } | |
| 316 | + | |
| 317 | + spi->clk = devm_clk_get(&pdev->dev, NULL); | |
| 318 | + if (IS_ERR(spi->clk)) { | |
| 319 | + dev_err(&pdev->dev, "Unable to find bus clock\n"); | |
| 320 | + ret = PTR_ERR(spi->clk); | |
| 321 | + goto put_master; | |
| 322 | + } | |
| 323 | + | |
| 324 | + irq = platform_get_irq(pdev, 0); | |
| 325 | + if (irq < 0) { | |
| 326 | + dev_err(&pdev->dev, "Unable to find interrupt\n"); | |
| 327 | + ret = irq; | |
| 328 | + goto put_master; | |
| 329 | + } | |
| 330 | + | |
| 331 | + /* Optional parameters */ | |
| 332 | + ret = | |
| 333 | + of_property_read_u32(pdev->dev.of_node, "sifive,fifo-depth", | |
| 334 | + &spi->fifo_depth); | |
| 335 | + if (ret < 0) | |
| 336 | + spi->fifo_depth = SIFIVE_SPI_DEFAULT_DEPTH; | |
| 337 | + | |
| 338 | + ret = | |
| 339 | + of_property_read_u32(pdev->dev.of_node, "sifive,max-bits-per-word", | |
| 340 | + &max_bits_per_word); | |
| 341 | + | |
| 342 | + if (!ret && max_bits_per_word < 8) { | |
| 343 | + dev_err(&pdev->dev, "Only 8bit SPI words supported by the driver\n"); | |
| 344 | + ret = -EINVAL; | |
| 345 | + goto put_master; | |
| 346 | + } | |
| 347 | + | |
| 348 | + /* Spin up the bus clock before hitting registers */ | |
| 349 | + ret = clk_prepare_enable(spi->clk); | |
| 350 | + if (ret) { | |
| 351 | + dev_err(&pdev->dev, "Unable to enable bus clock\n"); | |
| 352 | + goto put_master; | |
| 353 | + } | |
| 354 | + | |
| 355 | + /* probe the number of CS lines */ | |
| 356 | + spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF); | |
| 357 | + sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU); | |
| 358 | + cs_bits = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF); | |
| 359 | + sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive); | |
| 360 | + if (!cs_bits) { | |
| 361 | + dev_err(&pdev->dev, "Could not auto probe CS lines\n"); | |
| 362 | + ret = -EINVAL; | |
| 363 | + goto put_master; | |
| 364 | + } | |
| 365 | + | |
| 366 | + num_cs = ilog2(cs_bits) + 1; | |
| 367 | + if (num_cs > SIFIVE_SPI_MAX_CS) { | |
| 368 | + dev_err(&pdev->dev, "Invalid number of spi slaves\n"); | |
| 369 | + ret = -EINVAL; | |
| 370 | + goto put_master; | |
| 371 | + } | |
| 372 | + | |
| 373 | + /* Define our master */ | |
| 374 | + master->dev.of_node = pdev->dev.of_node; | |
| 375 | + master->bus_num = pdev->id; | |
| 376 | + master->num_chipselect = num_cs; | |
| 377 | + master->mode_bits = SPI_CPHA | SPI_CPOL | |
| 378 | + | SPI_CS_HIGH | SPI_LSB_FIRST | |
| 379 | + | SPI_TX_DUAL | SPI_TX_QUAD | |
| 380 | + | SPI_RX_DUAL | SPI_RX_QUAD; | |
| 381 | + /* TODO: add driver support for bits_per_word < 8 | |
| 382 | + * we need to "left-align" the bits (unless SPI_LSB_FIRST) | |
| 383 | + */ | |
| 384 | + master->bits_per_word_mask = SPI_BPW_MASK(8); | |
| 385 | + master->flags = SPI_CONTROLLER_MUST_TX | SPI_MASTER_GPIO_SS; | |
| 386 | + master->prepare_message = sifive_spi_prepare_message; | |
| 387 | + master->set_cs = sifive_spi_set_cs; | |
| 388 | + master->transfer_one = sifive_spi_transfer_one; | |
| 389 | + | |
| 390 | + pdev->dev.dma_mask = NULL; | |
| 391 | + /* Configure the SPI master hardware */ | |
| 392 | + sifive_spi_init(spi); | |
| 393 | + | |
| 394 | + /* Register for SPI Interrupt */ | |
| 395 | + ret = devm_request_irq(&pdev->dev, irq, sifive_spi_irq, 0, | |
| 396 | + dev_name(&pdev->dev), spi); | |
| 397 | + if (ret) { | |
| 398 | + dev_err(&pdev->dev, "Unable to bind to interrupt\n"); | |
| 399 | + goto put_master; | |
| 400 | + } | |
| 401 | + | |
| 402 | + dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n", | |
| 403 | + irq, master->num_chipselect); | |
| 404 | + | |
| 405 | + ret = devm_spi_register_master(&pdev->dev, master); | |
| 406 | + if (ret < 0) { | |
| 407 | + dev_err(&pdev->dev, "spi_register_master failed\n"); | |
| 408 | + goto put_master; | |
| 409 | + } | |
| 410 | + | |
| 411 | + return 0; | |
| 412 | + | |
| 413 | +put_master: | |
| 414 | + spi_master_put(master); | |
| 415 | + | |
| 416 | + return ret; | |
| 417 | +} | |
| 418 | + | |
| 419 | +static int sifive_spi_remove(struct platform_device *pdev) | |
| 420 | +{ | |
| 421 | + struct spi_master *master = platform_get_drvdata(pdev); | |
| 422 | + struct sifive_spi *spi = spi_master_get_devdata(master); | |
| 423 | + | |
| 424 | + /* Disable all the interrupts just in case */ | |
| 425 | + sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0); | |
| 426 | + | |
| 427 | + return 0; | |
| 428 | +} | |
| 429 | + | |
| 430 | +static const struct of_device_id sifive_spi_of_match[] = { | |
| 431 | + { .compatible = "sifive,spi0", }, | |
| 432 | + {} | |
| 433 | +}; | |
| 434 | +MODULE_DEVICE_TABLE(of, sifive_spi_of_match); | |
| 435 | + | |
| 436 | +static struct platform_driver sifive_spi_driver = { | |
| 437 | + .probe = sifive_spi_probe, | |
| 438 | + .remove = sifive_spi_remove, | |
| 439 | + .driver = { | |
| 440 | + .name = SIFIVE_SPI_DRIVER_NAME, | |
| 441 | + .of_match_table = sifive_spi_of_match, | |
| 442 | + }, | |
| 443 | +}; | |
| 444 | +module_platform_driver(sifive_spi_driver); | |
| 445 | + | |
| 446 | +MODULE_AUTHOR("SiFive, Inc. <sifive@sifive.com>"); | |
| 447 | +MODULE_DESCRIPTION("SiFive SPI driver"); | |
| 448 | +MODULE_LICENSE("GPL"); | |
| @@ -2,6 +2,9 @@ · 1 unmodified line | ||
| 2 | 2 | // Copyright (C) 2018 Spreadtrum Communications Inc. |
| 3 | 3 | |
| 4 | 4 | #include <linux/clk.h> |
| 5 | +#include <linux/dmaengine.h> | |
| 6 | +#include <linux/dma-mapping.h> | |
| 7 | +#include <linux/dma/sprd-dma.h> | |
| 5 | 8 | #include <linux/interrupt.h> |
| 6 | 9 | #include <linux/io.h> |
| 7 | 10 | #include <linux/iopoll.h> |
| @@ -9,6 +12,7 @@ · 1 unmodified line | ||
| 9 | 12 | #include <linux/module.h> |
| 10 | 13 | #include <linux/of.h> |
| 11 | 14 | #include <linux/of_device.h> |
| 15 | +#include <linux/of_dma.h> | |
| 12 | 16 | #include <linux/platform_device.h> |
| 13 | 17 | #include <linux/pm_runtime.h> |
| 14 | 18 | #include <linux/spi/spi.h> |
| @@ -128,11 +132,28 @@ · 113 unmodified lines | ||
| 128 | 132 | #define SPRD_SPI_DEFAULT_SOURCE 26000000 |
| 129 | 133 | #define SPRD_SPI_MAX_SPEED_HZ 48000000 |
| 130 | 134 | #define SPRD_SPI_AUTOSUSPEND_DELAY 100 |
| 135 | +#define SPRD_SPI_DMA_STEP 8 | |
| 136 | + | |
| 137 | +enum sprd_spi_dma_channel { | |
| 138 | + SPRD_SPI_RX, | |
| 139 | + SPRD_SPI_TX, | |
| 140 | + SPRD_SPI_MAX, | |
| 141 | +}; | |
| 142 | + | |
| 143 | +struct sprd_spi_dma { | |
| 144 | + bool enable; | |
| 145 | + struct dma_chan *dma_chan[SPRD_SPI_MAX]; | |
| 146 | + enum dma_slave_buswidth width; | |
| 147 | + u32 fragmens_len; | |
| 148 | + u32 rx_len; | |
| 149 | +}; | |
| 131 | 150 | |
| 132 | 151 | struct sprd_spi { |
| 133 | 152 | void __iomem *base; |
| 153 | + phys_addr_t phy_base; | |
| 134 | 154 | struct device *dev; |
| 135 | 155 | struct clk *clk; |
| 156 | + int irq; | |
| 136 | 157 | u32 src_clk; |
| 137 | 158 | u32 hw_mode; |
| 138 | 159 | u32 trans_len; |
| @@ -141,6 +162,8 @@ struct sprd_spi { · 2 unmodified lines | ||
| 141 | 162 | u32 hw_speed_hz; |
| 142 | 163 | u32 len; |
| 143 | 164 | int status; |
| 165 | + struct sprd_spi_dma dma; | |
| 166 | + struct completion xfer_completion; | |
| 144 | 167 | const void *tx_buf; |
| 145 | 168 | void *rx_buf; |
| 146 | 169 | int (*read_bufs)(struct sprd_spi *ss, u32 len); |
| @@ -380,7 +403,7 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t) · 233 unmodified lines | ||
| 380 | 403 | { |
| 381 | 404 | struct sprd_spi *ss = spi_controller_get_devdata(sdev->controller); |
| 382 | 405 | u32 trans_len = ss->trans_len, len; |
| 383 | − int ret, write_size = 0; | |
| 406 | + int ret, write_size = 0, read_size = 0; | |
| 384 | 407 | |
| 385 | 408 | while (trans_len) { |
| 386 | 409 | len = trans_len > SPRD_SPI_FIFO_SIZE ? SPRD_SPI_FIFO_SIZE : |
| @@ -416,19 +439,223 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t) · 29 unmodified lines | ||
| 416 | 439 | goto complete; |
| 417 | 440 | |
| 418 | 441 | if (ss->trans_mode & SPRD_SPI_RX_MODE) |
| 419 | − ss->read_bufs(ss, len); | |
| 442 | + read_size += ss->read_bufs(ss, len); | |
| 420 | 443 | |
| 421 | 444 | trans_len -= len; |
| 422 | 445 | } |
| 423 | 446 | |
| 424 | − ret = write_size; | |
| 425 | − | |
| 447 | + if (ss->trans_mode & SPRD_SPI_TX_MODE) | |
| 448 | + ret = write_size; | |
| 449 | + else | |
| 450 | + ret = read_size; | |
| 426 | 451 | complete: |
| 427 | 452 | sprd_spi_enter_idle(ss); |
| 428 | 453 | |
| 429 | 454 | return ret; |
| 430 | 455 | } |
| 431 | 456 | |
| 457 | +static void sprd_spi_irq_enable(struct sprd_spi *ss) | |
| 458 | +{ | |
| 459 | + u32 val; | |
| 460 | + | |
| 461 | + /* Clear interrupt status before enabling interrupt. */ | |
| 462 | + writel_relaxed(SPRD_SPI_TX_END_CLR | SPRD_SPI_RX_END_CLR, | |
| 463 | + ss->base + SPRD_SPI_INT_CLR); | |
| 464 | + /* Enable SPI interrupt only in DMA mode. */ | |
| 465 | + val = readl_relaxed(ss->base + SPRD_SPI_INT_EN); | |
| 466 | + writel_relaxed(val | SPRD_SPI_TX_END_INT_EN | | |
| 467 | + SPRD_SPI_RX_END_INT_EN, | |
| 468 | + ss->base + SPRD_SPI_INT_EN); | |
| 469 | +} | |
| 470 | + | |
| 471 | +static void sprd_spi_irq_disable(struct sprd_spi *ss) | |
| 472 | +{ | |
| 473 | + writel_relaxed(0, ss->base + SPRD_SPI_INT_EN); | |
| 474 | +} | |
| 475 | + | |
| 476 | +static void sprd_spi_dma_enable(struct sprd_spi *ss, bool enable) | |
| 477 | +{ | |
| 478 | + u32 val = readl_relaxed(ss->base + SPRD_SPI_CTL2); | |
| 479 | + | |
| 480 | + if (enable) | |
| 481 | + val |= SPRD_SPI_DMA_EN; | |
| 482 | + else | |
| 483 | + val &= ~SPRD_SPI_DMA_EN; | |
| 484 | + | |
| 485 | + writel_relaxed(val, ss->base + SPRD_SPI_CTL2); | |
| 486 | +} | |
| 487 | + | |
| 488 | +static int sprd_spi_dma_submit(struct dma_chan *dma_chan, | |
| 489 | + struct dma_slave_config *c, | |
| 490 | + struct sg_table *sg, | |
| 491 | + enum dma_transfer_direction dir) | |
| 492 | +{ | |
| 493 | + struct dma_async_tx_descriptor *desc; | |
| 494 | + dma_cookie_t cookie; | |
| 495 | + unsigned long flags; | |
| 496 | + int ret; | |
| 497 | + | |
| 498 | + ret = dmaengine_slave_config(dma_chan, c); | |
| 499 | + if (ret < 0) | |
| 500 | + return ret; | |
| 501 | + | |
| 502 | + flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, SPRD_DMA_NO_TRG, | |
| 503 | + SPRD_DMA_FRAG_REQ, SPRD_DMA_TRANS_INT); | |
| 504 | + desc = dmaengine_prep_slave_sg(dma_chan, sg->sgl, sg->nents, dir, flags); | |
| 505 | + if (!desc) | |
| 506 | + return -ENODEV; | |
| 507 | + | |
| 508 | + cookie = dmaengine_submit(desc); | |
| 509 | + if (dma_submit_error(cookie)) | |
| 510 | + return dma_submit_error(cookie); | |
| 511 | + | |
| 512 | + dma_async_issue_pending(dma_chan); | |
| 513 | + | |
| 514 | + return 0; | |
| 515 | +} | |
| 516 | + | |
| 517 | +static int sprd_spi_dma_rx_config(struct sprd_spi *ss, struct spi_transfer *t) | |
| 518 | +{ | |
| 519 | + struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_RX]; | |
| 520 | + struct dma_slave_config config = { | |
| 521 | + .src_addr = ss->phy_base, | |
| 522 | + .src_addr_width = ss->dma.width, | |
| 523 | + .dst_addr_width = ss->dma.width, | |
| 524 | + .dst_maxburst = ss->dma.fragmens_len, | |
| 525 | + }; | |
| 526 | + int ret; | |
| 527 | + | |
| 528 | + ret = sprd_spi_dma_submit(dma_chan, &config, &t->rx_sg, DMA_DEV_TO_MEM); | |
| 529 | + if (ret) | |
| 530 | + return ret; | |
| 531 | + | |
| 532 | + return ss->dma.rx_len; | |
| 533 | +} | |
| 534 | + | |
| 535 | +static int sprd_spi_dma_tx_config(struct sprd_spi *ss, struct spi_transfer *t) | |
| 536 | +{ | |
| 537 | + struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_TX]; | |
| 538 | + struct dma_slave_config config = { | |
| 539 | + .dst_addr = ss->phy_base, | |
| 540 | + .src_addr_width = ss->dma.width, | |
| 541 | + .dst_addr_width = ss->dma.width, | |
| 542 | + .src_maxburst = ss->dma.fragmens_len, | |
| 543 | + }; | |
| 544 | + int ret; | |
| 545 | + | |
| 546 | + ret = sprd_spi_dma_submit(dma_chan, &config, &t->tx_sg, DMA_MEM_TO_DEV); | |
| 547 | + if (ret) | |
| 548 | + return ret; | |
| 549 | + | |
| 550 | + return t->len; | |
| 551 | +} | |
| 552 | + | |
| 553 | +static int sprd_spi_dma_request(struct sprd_spi *ss) | |
| 554 | +{ | |
| 555 | + ss->dma.dma_chan[SPRD_SPI_RX] = dma_request_chan(ss->dev, "rx_chn"); | |
| 556 | + if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_RX])) { | |
| 557 | + if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]) == -EPROBE_DEFER) | |
| 558 | + return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]); | |
| 559 | + | |
| 560 | + dev_err(ss->dev, "request RX DMA channel failed!\n"); | |
| 561 | + return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]); | |
| 562 | + } | |
| 563 | + | |
| 564 | + ss->dma.dma_chan[SPRD_SPI_TX] = dma_request_chan(ss->dev, "tx_chn"); | |
| 565 | + if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_TX])) { | |
| 566 | + if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]) == -EPROBE_DEFER) | |
| 567 | + return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]); | |
| 568 | + | |
| 569 | + dev_err(ss->dev, "request TX DMA channel failed!\n"); | |
| 570 | + dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]); | |
| 571 | + return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]); | |
| 572 | + } | |
| 573 | + | |
| 574 | + return 0; | |
| 575 | +} | |
| 576 | + | |
| 577 | +static void sprd_spi_dma_release(struct sprd_spi *ss) | |
| 578 | +{ | |
| 579 | + if (ss->dma.dma_chan[SPRD_SPI_RX]) | |
| 580 | + dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]); | |
| 581 | + | |
| 582 | + if (ss->dma.dma_chan[SPRD_SPI_TX]) | |
| 583 | + dma_release_channel(ss->dma.dma_chan[SPRD_SPI_TX]); | |
| 584 | +} | |
| 585 | + | |
| 586 | +static int sprd_spi_dma_txrx_bufs(struct spi_device *sdev, | |
| 587 | + struct spi_transfer *t) | |
| 588 | +{ | |
| 589 | + struct sprd_spi *ss = spi_master_get_devdata(sdev->master); | |
| 590 | + u32 trans_len = ss->trans_len; | |
| 591 | + int ret, write_size = 0; | |
| 592 | + | |
| 593 | + reinit_completion(&ss->xfer_completion); | |
| 594 | + sprd_spi_irq_enable(ss); | |
| 595 | + if (ss->trans_mode & SPRD_SPI_TX_MODE) { | |
| 596 | + write_size = sprd_spi_dma_tx_config(ss, t); | |
| 597 | + sprd_spi_set_tx_length(ss, trans_len); | |
| 598 | + | |
| 599 | + /* | |
| 600 | + * For our 3 wires mode or dual TX line mode, we need | |
| 601 | + * to request the controller to transfer. | |
| 602 | + */ | |
| 603 | + if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL) | |
| 604 | + sprd_spi_tx_req(ss); | |
| 605 | + } else { | |
| 606 | + sprd_spi_set_rx_length(ss, trans_len); | |
| 607 | + | |
| 608 | + /* | |
| 609 | + * For our 3 wires mode or dual TX line mode, we need | |
| 610 | + * to request the controller to read. | |
| 611 | + */ | |
| 612 | + if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL) | |
| 613 | + sprd_spi_rx_req(ss); | |
| 614 | + else | |
| 615 | + write_size = ss->write_bufs(ss, trans_len); | |
| 616 | + } | |
| 617 | + | |
| 618 | + if (write_size < 0) { | |
| 619 | + ret = write_size; | |
| 620 | + dev_err(ss->dev, "failed to write, ret = %d\n", ret); | |
| 621 | + goto trans_complete; | |
| 622 | + } | |
| 623 | + | |
| 624 | + if (ss->trans_mode & SPRD_SPI_RX_MODE) { | |
| 625 | + /* | |
| 626 | + * Set up the DMA receive data length, which must be an | |
| 627 | + * integral multiple of fragment length. But when the length | |
| 628 | + * of received data is less than fragment length, DMA can be | |
| 629 | + * configured to receive data according to the actual length | |
| 630 | + * of received data. | |
| 631 | + */ | |
| 632 | + ss->dma.rx_len = t->len > ss->dma.fragmens_len ? | |
| 633 | + (t->len - t->len % ss->dma.fragmens_len) : | |
| 634 | + t->len; | |
| 635 | + ret = sprd_spi_dma_rx_config(ss, t); | |
| 636 | + if (ret < 0) { | |
| 637 | + dev_err(&sdev->dev, | |
| 638 | + "failed to configure rx DMA, ret = %d\n", ret); | |
| 639 | + goto trans_complete; | |
| 640 | + } | |
| 641 | + } | |
| 642 | + | |
| 643 | + sprd_spi_dma_enable(ss, true); | |
| 644 | + wait_for_completion(&(ss->xfer_completion)); | |
| 645 | + | |
| 646 | + if (ss->trans_mode & SPRD_SPI_TX_MODE) | |
| 647 | + ret = write_size; | |
| 648 | + else | |
| 649 | + ret = ss->dma.rx_len; | |
| 650 | + | |
| 651 | +trans_complete: | |
| 652 | + sprd_spi_dma_enable(ss, false); | |
| 653 | + sprd_spi_enter_idle(ss); | |
| 654 | + sprd_spi_irq_disable(ss); | |
| 655 | + | |
| 656 | + return ret; | |
| 657 | +} | |
| 658 | + | |
| 432 | 659 | static void sprd_spi_set_speed(struct sprd_spi *ss, u32 speed_hz) |
| 433 | 660 | { |
| 434 | 661 | /* |
| @@ -514,16 +741,22 @@ static int sprd_spi_setup_transfer(struct spi_device *sdev, · 79 unmodified lines | ||
| 514 | 741 | ss->trans_len = t->len; |
| 515 | 742 | ss->read_bufs = sprd_spi_read_bufs_u8; |
| 516 | 743 | ss->write_bufs = sprd_spi_write_bufs_u8; |
| 744 | + ss->dma.width = DMA_SLAVE_BUSWIDTH_1_BYTE; | |
| 745 | + ss->dma.fragmens_len = SPRD_SPI_DMA_STEP; | |
| 517 | 746 | break; |
| 518 | 747 | case 16: |
| 519 | 748 | ss->trans_len = t->len >> 1; |
| 520 | 749 | ss->read_bufs = sprd_spi_read_bufs_u16; |
| 521 | 750 | ss->write_bufs = sprd_spi_write_bufs_u16; |
| 751 | + ss->dma.width = DMA_SLAVE_BUSWIDTH_2_BYTES; | |
| 752 | + ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 1; | |
| 522 | 753 | break; |
| 523 | 754 | case 32: |
| 524 | 755 | ss->trans_len = t->len >> 2; |
| 525 | 756 | ss->read_bufs = sprd_spi_read_bufs_u32; |
| 526 | 757 | ss->write_bufs = sprd_spi_write_bufs_u32; |
| 758 | + ss->dma.width = DMA_SLAVE_BUSWIDTH_4_BYTES; | |
| 759 | + ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 2; | |
| 527 | 760 | break; |
| 528 | 761 | default: |
| 529 | 762 | return -EINVAL; |
| @@ -561,7 +794,11 @@ static int sprd_spi_transfer_one(struct spi_controller *sctlr, · 31 unmodified lines | ||
| 561 | 794 | if (ret) |
| 562 | 795 | goto setup_err; |
| 563 | 796 | |
| 564 | − ret = sprd_spi_txrx_bufs(sdev, t); | |
| 797 | + if (sctlr->can_dma(sctlr, sdev, t)) | |
| 798 | + ret = sprd_spi_dma_txrx_bufs(sdev, t); | |
| 799 | + else | |
| 800 | + ret = sprd_spi_txrx_bufs(sdev, t); | |
| 801 | + | |
| 565 | 802 | if (ret == t->len) |
| 566 | 803 | ret = 0; |
| 567 | 804 | else if (ret >= 0) |
| @@ -573,6 +810,53 @@ setup_err: · 5 unmodified lines | ||
| 573 | 810 | return ret; |
| 574 | 811 | } |
| 575 | 812 | |
| 813 | +static irqreturn_t sprd_spi_handle_irq(int irq, void *data) | |
| 814 | +{ | |
| 815 | + struct sprd_spi *ss = (struct sprd_spi *)data; | |
| 816 | + u32 val = readl_relaxed(ss->base + SPRD_SPI_INT_MASK_STS); | |
| 817 | + | |
| 818 | + if (val & SPRD_SPI_MASK_TX_END) { | |
| 819 | + writel_relaxed(SPRD_SPI_TX_END_CLR, ss->base + SPRD_SPI_INT_CLR); | |
| 820 | + if (!(ss->trans_mode & SPRD_SPI_RX_MODE)) | |
| 821 | + complete(&ss->xfer_completion); | |
| 822 | + | |
| 823 | + return IRQ_HANDLED; | |
| 824 | + } | |
| 825 | + | |
| 826 | + if (val & SPRD_SPI_MASK_RX_END) { | |
| 827 | + writel_relaxed(SPRD_SPI_RX_END_CLR, ss->base + SPRD_SPI_INT_CLR); | |
| 828 | + if (ss->dma.rx_len < ss->len) { | |
| 829 | + ss->rx_buf += ss->dma.rx_len; | |
| 830 | + ss->dma.rx_len += | |
| 831 | + ss->read_bufs(ss, ss->len - ss->dma.rx_len); | |
| 832 | + } | |
| 833 | + complete(&ss->xfer_completion); | |
| 834 | + | |
| 835 | + return IRQ_HANDLED; | |
| 836 | + } | |
| 837 | + | |
| 838 | + return IRQ_NONE; | |
| 839 | +} | |
| 840 | + | |
| 841 | +static int sprd_spi_irq_init(struct platform_device *pdev, struct sprd_spi *ss) | |
| 842 | +{ | |
| 843 | + int ret; | |
| 844 | + | |
| 845 | + ss->irq = platform_get_irq(pdev, 0); | |
| 846 | + if (ss->irq < 0) { | |
| 847 | + dev_err(&pdev->dev, "failed to get irq resource\n"); | |
| 848 | + return ss->irq; | |
| 849 | + } | |
| 850 | + | |
| 851 | + ret = devm_request_irq(&pdev->dev, ss->irq, sprd_spi_handle_irq, | |
| 852 | + 0, pdev->name, ss); | |
| 853 | + if (ret) | |
| 854 | + dev_err(&pdev->dev, "failed to request spi irq %d, ret = %d\n", | |
| 855 | + ss->irq, ret); | |
| 856 | + | |
| 857 | + return ret; | |
| 858 | +} | |
| 859 | + | |
| 576 | 860 | static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss) |
| 577 | 861 | { |
| 578 | 862 | struct clk *clk_spi, *clk_parent; |
| @@ -603,6 +887,35 @@ static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss) · 24 unmodified lines | ||
| 603 | 887 | return 0; |
| 604 | 888 | } |
| 605 | 889 | |
| 890 | +static bool sprd_spi_can_dma(struct spi_controller *sctlr, | |
| 891 | + struct spi_device *spi, struct spi_transfer *t) | |
| 892 | +{ | |
| 893 | + struct sprd_spi *ss = spi_controller_get_devdata(sctlr); | |
| 894 | + | |
| 895 | + return ss->dma.enable && (t->len > SPRD_SPI_FIFO_SIZE); | |
| 896 | +} | |
| 897 | + | |
| 898 | +static int sprd_spi_dma_init(struct platform_device *pdev, struct sprd_spi *ss) | |
| 899 | +{ | |
| 900 | + int ret; | |
| 901 | + | |
| 902 | + ret = sprd_spi_dma_request(ss); | |
| 903 | + if (ret) { | |
| 904 | + if (ret == -EPROBE_DEFER) | |
| 905 | + return ret; | |
| 906 | + | |
| 907 | + dev_warn(&pdev->dev, | |
| 908 | + "failed to request dma, enter no dma mode, ret = %d\n", | |
| 909 | + ret); | |
| 910 | + | |
| 911 | + return 0; | |
| 912 | + } | |
| 913 | + | |
| 914 | + ss->dma.enable = true; | |
| 915 | + | |
| 916 | + return 0; | |
| 917 | +} | |
| 918 | + | |
| 606 | 919 | static int sprd_spi_probe(struct platform_device *pdev) |
| 607 | 920 | { |
| 608 | 921 | struct spi_controller *sctlr; |
| @@ -623,25 +936,36 @@ static int sprd_spi_probe(struct platform_device *pdev) · 14 unmodified lines | ||
| 623 | 936 | goto free_controller; |
| 624 | 937 | } |
| 625 | 938 | |
| 939 | + ss->phy_base = res->start; | |
| 626 | 940 | ss->dev = &pdev->dev; |
| 627 | 941 | sctlr->dev.of_node = pdev->dev.of_node; |
| 628 | 942 | sctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE | SPI_TX_DUAL; |
| 629 | 943 | sctlr->bus_num = pdev->id; |
| 630 | 944 | sctlr->set_cs = sprd_spi_chipselect; |
| 631 | 945 | sctlr->transfer_one = sprd_spi_transfer_one; |
| 946 | + sctlr->can_dma = sprd_spi_can_dma; | |
| 632 | 947 | sctlr->auto_runtime_pm = true; |
| 633 | 948 | sctlr->max_speed_hz = min_t(u32, ss->src_clk >> 1, |
| 634 | 949 | SPRD_SPI_MAX_SPEED_HZ); |
| 635 | 950 | |
| 951 | + init_completion(&ss->xfer_completion); | |
| 636 | 952 | platform_set_drvdata(pdev, sctlr); |
| 637 | 953 | ret = sprd_spi_clk_init(pdev, ss); |
| 638 | 954 | if (ret) |
| 639 | 955 | goto free_controller; |
| 640 | 956 | |
| 641 | − ret = clk_prepare_enable(ss->clk); | |
| 957 | + ret = sprd_spi_irq_init(pdev, ss); | |
| 642 | 958 | if (ret) |
| 643 | 959 | goto free_controller; |
| 644 | 960 | |
| 961 | + ret = sprd_spi_dma_init(pdev, ss); | |
| 962 | + if (ret) | |
| 963 | + goto free_controller; | |
| 964 | + | |
| 965 | + ret = clk_prepare_enable(ss->clk); | |
| 966 | + if (ret) | |
| 967 | + goto release_dma; | |
| 968 | + | |
| 645 | 969 | ret = pm_runtime_set_active(&pdev->dev); |
| 646 | 970 | if (ret < 0) |
| 647 | 971 | goto disable_clk; |
| @@ -670,6 +994,8 @@ err_rpm_put: · 22 unmodified lines | ||
| 670 | 994 | pm_runtime_disable(&pdev->dev); |
| 671 | 995 | disable_clk: |
| 672 | 996 | clk_disable_unprepare(ss->clk); |
| 997 | +release_dma: | |
| 998 | + sprd_spi_dma_release(ss); | |
| 673 | 999 | free_controller: |
| 674 | 1000 | spi_controller_put(sctlr); |
| 675 | 1001 | |
| @@ -688,6 +1014,10 @@ static int sprd_spi_remove(struct platform_device *pdev) · 12 unmodified lines | ||
| 688 | 1014 | return ret; |
| 689 | 1015 | } |
| 690 | 1016 | |
| 1017 | + spi_controller_suspend(sctlr); | |
| 1018 | + | |
| 1019 | + if (ss->dma.enable) | |
| 1020 | + sprd_spi_dma_release(ss); | |
| 691 | 1021 | clk_disable_unprepare(ss->clk); |
| 692 | 1022 | pm_runtime_put_noidle(&pdev->dev); |
| 693 | 1023 | pm_runtime_disable(&pdev->dev); |
| @@ -700,6 +1030,9 @@ static int __maybe_unused sprd_spi_runtime_suspend(struct device *dev) · 6 unmodified lines | ||
| 700 | 1030 | struct spi_controller *sctlr = dev_get_drvdata(dev); |
| 701 | 1031 | struct sprd_spi *ss = spi_controller_get_devdata(sctlr); |
| 702 | 1032 | |
| 1033 | + if (ss->dma.enable) | |
| 1034 | + sprd_spi_dma_release(ss); | |
| 1035 | + | |
| 703 | 1036 | clk_disable_unprepare(ss->clk); |
| 704 | 1037 | |
| 705 | 1038 | return 0; |
| @@ -715,7 +1048,14 @@ static int __maybe_unused sprd_spi_runtime_resume(struct device *dev) · 9 unmodified lines | ||
| 715 | 1048 | if (ret) |
| 716 | 1049 | return ret; |
| 717 | 1050 | |
| 718 | − return 0; | |
| 1051 | + if (!ss->dma.enable) | |
| 1052 | + return 0; | |
| 1053 | + | |
| 1054 | + ret = sprd_spi_dma_request(ss); | |
| 1055 | + if (ret) | |
| 1056 | + clk_disable_unprepare(ss->clk); | |
| 1057 | + | |
| 1058 | + return ret; | |
| 719 | 1059 | } |
| 720 | 1060 | |
| 721 | 1061 | static const struct dev_pm_ops sprd_spi_pm_ops = { |
| @@ -1,23 +1,10 @@ | ||
| 1 | −/* | |
| 2 | − * STMicroelectronics STM32 SPI Controller driver (master mode only) | |
| 3 | − * | |
| 4 | − * Copyright (C) 2017, STMicroelectronics - All Rights Reserved | |
| 5 | − * Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics. | |
| 6 | − * | |
| 7 | − * License terms: GPL V2.0. | |
| 8 | − * | |
| 9 | − * spi_stm32 driver is free software; you can redistribute it and/or modify it | |
| 10 | − * under the terms of the GNU General Public License version 2 as published by | |
| 11 | − * the Free Software Foundation. | |
| 12 | − * | |
| 13 | − * spi_stm32 driver is distributed in the hope that it will be useful, but | |
| 14 | − * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 15 | − * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
| 16 | − * details. | |
| 17 | − * | |
| 18 | − * You should have received a copy of the GNU General Public License along with | |
| 19 | − * spi_stm32 driver. If not, see <http://www.gnu.org/licenses/>. | |
| 20 | − */ | |
| 1 | +// SPDX-License-Identifier: GPL-2.0 | |
| 2 | +// | |
| 3 | +// STMicroelectronics STM32 SPI Controller driver (master mode only) | |
| 4 | +// | |
| 5 | +// Copyright (C) 2017, STMicroelectronics - All Rights Reserved | |
| 6 | +// Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics. | |
| 7 | + | |
| 21 | 8 | #include <linux/debugfs.h> |
| 22 | 9 | #include <linux/clk.h> |
| 23 | 10 | #include <linux/delay.h> |
| @@ -33,99 +20,251 @@ · 9 unmodified lines | ||
| 33 | 20 | |
| 34 | 21 | #define DRIVER_NAME "spi_stm32" |
| 35 | 22 | |
| 36 | −/* STM32 SPI registers */ | |
| 37 | −#define STM32_SPI_CR1 0x00 | |
| 38 | −#define STM32_SPI_CR2 0x04 | |
| 39 | −#define STM32_SPI_CFG1 0x08 | |
| 40 | −#define STM32_SPI_CFG2 0x0C | |
| 41 | −#define STM32_SPI_IER 0x10 | |
| 42 | −#define STM32_SPI_SR 0x14 | |
| 43 | −#define STM32_SPI_IFCR 0x18 | |
| 44 | −#define STM32_SPI_TXDR 0x20 | |
| 45 | −#define STM32_SPI_RXDR 0x30 | |
| 46 | −#define STM32_SPI_I2SCFGR 0x50 | |
| 47 | − | |
| 48 | −/* STM32_SPI_CR1 bit fields */ | |
| 49 | −#define SPI_CR1_SPE BIT(0) | |
| 50 | −#define SPI_CR1_MASRX BIT(8) | |
| 51 | −#define SPI_CR1_CSTART BIT(9) | |
| 52 | −#define SPI_CR1_CSUSP BIT(10) | |
| 53 | −#define SPI_CR1_HDDIR BIT(11) | |
| 54 | −#define SPI_CR1_SSI BIT(12) | |
| 55 | − | |
| 56 | −/* STM32_SPI_CR2 bit fields */ | |
| 57 | −#define SPI_CR2_TSIZE_SHIFT 0 | |
| 58 | −#define SPI_CR2_TSIZE GENMASK(15, 0) | |
| 59 | − | |
| 60 | −/* STM32_SPI_CFG1 bit fields */ | |
| 61 | −#define SPI_CFG1_DSIZE_SHIFT 0 | |
| 62 | −#define SPI_CFG1_DSIZE GENMASK(4, 0) | |
| 63 | −#define SPI_CFG1_FTHLV_SHIFT 5 | |
| 64 | −#define SPI_CFG1_FTHLV GENMASK(8, 5) | |
| 65 | −#define SPI_CFG1_RXDMAEN BIT(14) | |
| 66 | −#define SPI_CFG1_TXDMAEN BIT(15) | |
| 67 | −#define SPI_CFG1_MBR_SHIFT 28 | |
| 68 | −#define SPI_CFG1_MBR GENMASK(30, 28) | |
| 69 | −#define SPI_CFG1_MBR_MIN 0 | |
| 70 | −#define SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28) | |
| 71 | − | |
| 72 | −/* STM32_SPI_CFG2 bit fields */ | |
| 73 | −#define SPI_CFG2_MIDI_SHIFT 4 | |
| 74 | −#define SPI_CFG2_MIDI GENMASK(7, 4) | |
| 75 | −#define SPI_CFG2_COMM_SHIFT 17 | |
| 76 | −#define SPI_CFG2_COMM GENMASK(18, 17) | |
| 77 | −#define SPI_CFG2_SP_SHIFT 19 | |
| 78 | −#define SPI_CFG2_SP GENMASK(21, 19) | |
| 79 | −#define SPI_CFG2_MASTER BIT(22) | |
| 80 | −#define SPI_CFG2_LSBFRST BIT(23) | |
| 81 | −#define SPI_CFG2_CPHA BIT(24) | |
| 82 | −#define SPI_CFG2_CPOL BIT(25) | |
| 83 | −#define SPI_CFG2_SSM BIT(26) | |
| 84 | −#define SPI_CFG2_AFCNTR BIT(31) | |
| 85 | − | |
| 86 | −/* STM32_SPI_IER bit fields */ | |
| 87 | −#define SPI_IER_RXPIE BIT(0) | |
| 88 | −#define SPI_IER_TXPIE BIT(1) | |
| 89 | −#define SPI_IER_DXPIE BIT(2) | |
| 90 | −#define SPI_IER_EOTIE BIT(3) | |
| 91 | −#define SPI_IER_TXTFIE BIT(4) | |
| 92 | −#define SPI_IER_OVRIE BIT(6) | |
| 93 | −#define SPI_IER_MODFIE BIT(9) | |
| 94 | −#define SPI_IER_ALL GENMASK(10, 0) | |
| 95 | − | |
| 96 | −/* STM32_SPI_SR bit fields */ | |
| 97 | −#define SPI_SR_RXP BIT(0) | |
| 98 | −#define SPI_SR_TXP BIT(1) | |
| 99 | −#define SPI_SR_EOT BIT(3) | |
| 100 | −#define SPI_SR_OVR BIT(6) | |
| 101 | −#define SPI_SR_MODF BIT(9) | |
| 102 | −#define SPI_SR_SUSP BIT(11) | |
| 103 | −#define SPI_SR_RXPLVL_SHIFT 13 | |
| 104 | −#define SPI_SR_RXPLVL GENMASK(14, 13) | |
| 105 | −#define SPI_SR_RXWNE BIT(15) | |
| 106 | − | |
| 107 | −/* STM32_SPI_IFCR bit fields */ | |
| 108 | −#define SPI_IFCR_ALL GENMASK(11, 3) | |
| 109 | − | |
| 110 | −/* STM32_SPI_I2SCFGR bit fields */ | |
| 111 | −#define SPI_I2SCFGR_I2SMOD BIT(0) | |
| 112 | − | |
| 113 | −/* SPI Master Baud Rate min/max divisor */ | |
| 114 | −#define SPI_MBR_DIV_MIN (2 << SPI_CFG1_MBR_MIN) | |
| 115 | −#define SPI_MBR_DIV_MAX (2 << SPI_CFG1_MBR_MAX) | |
| 116 | − | |
| 117 | −/* SPI Communication mode */ | |
| 23 | +/* STM32F4 SPI registers */ | |
| 24 | +#define STM32F4_SPI_CR1 0x00 | |
| 25 | +#define STM32F4_SPI_CR2 0x04 | |
| 26 | +#define STM32F4_SPI_SR 0x08 | |
| 27 | +#define STM32F4_SPI_DR 0x0C | |
| 28 | +#define STM32F4_SPI_I2SCFGR 0x1C | |
| 29 | + | |
| 30 | +/* STM32F4_SPI_CR1 bit fields */ | |
| 31 | +#define STM32F4_SPI_CR1_CPHA BIT(0) | |
| 32 | +#define STM32F4_SPI_CR1_CPOL BIT(1) | |
| 33 | +#define STM32F4_SPI_CR1_MSTR BIT(2) | |
| 34 | +#define STM32F4_SPI_CR1_BR_SHIFT 3 | |
| 35 | +#define STM32F4_SPI_CR1_BR GENMASK(5, 3) | |
| 36 | +#define STM32F4_SPI_CR1_SPE BIT(6) | |
| 37 | +#define STM32F4_SPI_CR1_LSBFRST BIT(7) | |
| 38 | +#define STM32F4_SPI_CR1_SSI BIT(8) | |
| 39 | +#define STM32F4_SPI_CR1_SSM BIT(9) | |
| 40 | +#define STM32F4_SPI_CR1_RXONLY BIT(10) | |
| 41 | +#define STM32F4_SPI_CR1_DFF BIT(11) | |
| 42 | +#define STM32F4_SPI_CR1_CRCNEXT BIT(12) | |
| 43 | +#define STM32F4_SPI_CR1_CRCEN BIT(13) | |
| 44 | +#define STM32F4_SPI_CR1_BIDIOE BIT(14) | |
| 45 | +#define STM32F4_SPI_CR1_BIDIMODE BIT(15) | |
| 46 | +#define STM32F4_SPI_CR1_BR_MIN 0 | |
| 47 | +#define STM32F4_SPI_CR1_BR_MAX (GENMASK(5, 3) >> 3) | |
| 48 | + | |
| 49 | +/* STM32F4_SPI_CR2 bit fields */ | |
| 50 | +#define STM32F4_SPI_CR2_RXDMAEN BIT(0) | |
| 51 | +#define STM32F4_SPI_CR2_TXDMAEN BIT(1) | |
| 52 | +#define STM32F4_SPI_CR2_SSOE BIT(2) | |
| 53 | +#define STM32F4_SPI_CR2_FRF BIT(4) | |
| 54 | +#define STM32F4_SPI_CR2_ERRIE BIT(5) | |
| 55 | +#define STM32F4_SPI_CR2_RXNEIE BIT(6) | |
| 56 | +#define STM32F4_SPI_CR2_TXEIE BIT(7) | |
| 57 | + | |
| 58 | +/* STM32F4_SPI_SR bit fields */ | |
| 59 | +#define STM32F4_SPI_SR_RXNE BIT(0) | |
| 60 | +#define STM32F4_SPI_SR_TXE BIT(1) | |
| 61 | +#define STM32F4_SPI_SR_CHSIDE BIT(2) | |
| 62 | +#define STM32F4_SPI_SR_UDR BIT(3) | |
| 63 | +#define STM32F4_SPI_SR_CRCERR BIT(4) | |
| 64 | +#define STM32F4_SPI_SR_MODF BIT(5) | |
| 65 | +#define STM32F4_SPI_SR_OVR BIT(6) | |
| 66 | +#define STM32F4_SPI_SR_BSY BIT(7) | |
| 67 | +#define STM32F4_SPI_SR_FRE BIT(8) | |
| 68 | + | |
| 69 | +/* STM32F4_SPI_I2SCFGR bit fields */ | |
| 70 | +#define STM32F4_SPI_I2SCFGR_I2SMOD BIT(11) | |
| 71 | + | |
| 72 | +/* STM32F4 SPI Baud Rate min/max divisor */ | |
| 73 | +#define STM32F4_SPI_BR_DIV_MIN (2 << STM32F4_SPI_CR1_BR_MIN) | |
| 74 | +#define STM32F4_SPI_BR_DIV_MAX (2 << STM32F4_SPI_CR1_BR_MAX) | |
| 75 | + | |
| 76 | +/* STM32H7 SPI registers */ | |
| 77 | +#define STM32H7_SPI_CR1 0x00 | |
| 78 | +#define STM32H7_SPI_CR2 0x04 | |
| 79 | +#define STM32H7_SPI_CFG1 0x08 | |
| 80 | +#define STM32H7_SPI_CFG2 0x0C | |
| 81 | +#define STM32H7_SPI_IER 0x10 | |
| 82 | +#define STM32H7_SPI_SR 0x14 | |
| 83 | +#define STM32H7_SPI_IFCR 0x18 | |
| 84 | +#define STM32H7_SPI_TXDR 0x20 | |
| 85 | +#define STM32H7_SPI_RXDR 0x30 | |
| 86 | +#define STM32H7_SPI_I2SCFGR 0x50 | |
| 87 | + | |
| 88 | +/* STM32H7_SPI_CR1 bit fields */ | |
| 89 | +#define STM32H7_SPI_CR1_SPE BIT(0) | |
| 90 | +#define STM32H7_SPI_CR1_MASRX BIT(8) | |
| 91 | +#define STM32H7_SPI_CR1_CSTART BIT(9) | |
| 92 | +#define STM32H7_SPI_CR1_CSUSP BIT(10) | |
| 93 | +#define STM32H7_SPI_CR1_HDDIR BIT(11) | |
| 94 | +#define STM32H7_SPI_CR1_SSI BIT(12) | |
| 95 | + | |
| 96 | +/* STM32H7_SPI_CR2 bit fields */ | |
| 97 | +#define STM32H7_SPI_CR2_TSIZE_SHIFT 0 | |
| 98 | +#define STM32H7_SPI_CR2_TSIZE GENMASK(15, 0) | |
| 99 | + | |
| 100 | +/* STM32H7_SPI_CFG1 bit fields */ | |
| 101 | +#define STM32H7_SPI_CFG1_DSIZE_SHIFT 0 | |
| 102 | +#define STM32H7_SPI_CFG1_DSIZE GENMASK(4, 0) | |
| 103 | +#define STM32H7_SPI_CFG1_FTHLV_SHIFT 5 | |
| 104 | +#define STM32H7_SPI_CFG1_FTHLV GENMASK(8, 5) | |
| 105 | +#define STM32H7_SPI_CFG1_RXDMAEN BIT(14) | |
| 106 | +#define STM32H7_SPI_CFG1_TXDMAEN BIT(15) | |
| 107 | +#define STM32H7_SPI_CFG1_MBR_SHIFT 28 | |
| 108 | +#define STM32H7_SPI_CFG1_MBR GENMASK(30, 28) | |
| 109 | +#define STM32H7_SPI_CFG1_MBR_MIN 0 | |
| 110 | +#define STM32H7_SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28) | |
| 111 | + | |
| 112 | +/* STM32H7_SPI_CFG2 bit fields */ | |
| 113 | +#define STM32H7_SPI_CFG2_MIDI_SHIFT 4 | |
| 114 | +#define STM32H7_SPI_CFG2_MIDI GENMASK(7, 4) | |
| 115 | +#define STM32H7_SPI_CFG2_COMM_SHIFT 17 | |
| 116 | +#define STM32H7_SPI_CFG2_COMM GENMASK(18, 17) | |
| 117 | +#define STM32H7_SPI_CFG2_SP_SHIFT 19 | |
| 118 | +#define STM32H7_SPI_CFG2_SP GENMASK(21, 19) | |
| 119 | +#define STM32H7_SPI_CFG2_MASTER BIT(22) | |
| 120 | +#define STM32H7_SPI_CFG2_LSBFRST BIT(23) | |
| 121 | +#define STM32H7_SPI_CFG2_CPHA BIT(24) | |
| 122 | +#define STM32H7_SPI_CFG2_CPOL BIT(25) | |
| 123 | +#define STM32H7_SPI_CFG2_SSM BIT(26) | |
| 124 | +#define STM32H7_SPI_CFG2_AFCNTR BIT(31) | |
| 125 | + | |
| 126 | +/* STM32H7_SPI_IER bit fields */ | |
| 127 | +#define STM32H7_SPI_IER_RXPIE BIT(0) | |
| 128 | +#define STM32H7_SPI_IER_TXPIE BIT(1) | |
| 129 | +#define STM32H7_SPI_IER_DXPIE BIT(2) | |
| 130 | +#define STM32H7_SPI_IER_EOTIE BIT(3) | |
| 131 | +#define STM32H7_SPI_IER_TXTFIE BIT(4) | |
| 132 | +#define STM32H7_SPI_IER_OVRIE BIT(6) | |
| 133 | +#define STM32H7_SPI_IER_MODFIE BIT(9) | |
| 134 | +#define STM32H7_SPI_IER_ALL GENMASK(10, 0) | |
| 135 | + | |
| 136 | +/* STM32H7_SPI_SR bit fields */ | |
| 137 | +#define STM32H7_SPI_SR_RXP BIT(0) | |
| 138 | +#define STM32H7_SPI_SR_TXP BIT(1) | |
| 139 | +#define STM32H7_SPI_SR_EOT BIT(3) | |
| 140 | +#define STM32H7_SPI_SR_OVR BIT(6) | |
| 141 | +#define STM32H7_SPI_SR_MODF BIT(9) | |
| 142 | +#define STM32H7_SPI_SR_SUSP BIT(11) | |
| 143 | +#define STM32H7_SPI_SR_RXPLVL_SHIFT 13 | |
| 144 | +#define STM32H7_SPI_SR_RXPLVL GENMASK(14, 13) | |
| 145 | +#define STM32H7_SPI_SR_RXWNE BIT(15) | |
| 146 | + | |
| 147 | +/* STM32H7_SPI_IFCR bit fields */ | |
| 148 | +#define STM32H7_SPI_IFCR_ALL GENMASK(11, 3) | |
| 149 | + | |
| 150 | +/* STM32H7_SPI_I2SCFGR bit fields */ | |
| 151 | +#define STM32H7_SPI_I2SCFGR_I2SMOD BIT(0) | |
| 152 | + | |
| 153 | +/* STM32H7 SPI Master Baud Rate min/max divisor */ | |
| 154 | +#define STM32H7_SPI_MBR_DIV_MIN (2 << STM32H7_SPI_CFG1_MBR_MIN) | |
| 155 | +#define STM32H7_SPI_MBR_DIV_MAX (2 << STM32H7_SPI_CFG1_MBR_MAX) | |
| 156 | + | |
| 157 | +/* STM32H7 SPI Communication mode */ | |
| 158 | +#define STM32H7_SPI_FULL_DUPLEX 0 | |
| 159 | +#define STM32H7_SPI_SIMPLEX_TX 1 | |
| 160 | +#define STM32H7_SPI_SIMPLEX_RX 2 | |
| 161 | +#define STM32H7_SPI_HALF_DUPLEX 3 | |
| 162 | + | |
| 163 | +/* SPI Communication type */ | |
| 118 | 164 | #define SPI_FULL_DUPLEX 0 |
| 119 | 165 | #define SPI_SIMPLEX_TX 1 |
| 120 | 166 | #define SPI_SIMPLEX_RX 2 |
| 121 | −#define SPI_HALF_DUPLEX 3 | |
| 167 | +#define SPI_3WIRE_TX 3 | |
| 168 | +#define SPI_3WIRE_RX 4 | |
| 122 | 169 | |
| 123 | 170 | #define SPI_1HZ_NS 1000000000 |
| 124 | 171 | |
| 172 | +/* | |
| 173 | + * use PIO for small transfers, avoiding DMA setup/teardown overhead for drivers | |
| 174 | + * without fifo buffers. | |
| 175 | + */ | |
| 176 | +#define SPI_DMA_MIN_BYTES 16 | |
| 177 | + | |
| 178 | +/** | |
| 179 | + * stm32_spi_reg - stm32 SPI register & bitfield desc | |
| 180 | + * @reg: register offset | |
| 181 | + * @mask: bitfield mask | |
| 182 | + * @shift: left shift | |
| 183 | + */ | |
| 184 | +struct stm32_spi_reg { | |
| 185 | + int reg; | |
| 186 | + int mask; | |
| 187 | + int shift; | |
| 188 | +}; | |
| 189 | + | |
| 190 | +/** | |
| 191 | + * stm32_spi_regspec - stm32 registers definition, compatible dependent data | |
| 192 | + * en: enable register and SPI enable bit | |
| 193 | + * dma_rx_en: SPI DMA RX enable register end SPI DMA RX enable bit | |
| 194 | + * dma_tx_en: SPI DMA TX enable register end SPI DMA TX enable bit | |
| 195 | + * cpol: clock polarity register and polarity bit | |
| 196 | + * cpha: clock phase register and phase bit | |
| 197 | + * lsb_first: LSB transmitted first register and bit | |
| 198 | + * br: baud rate register and bitfields | |
| 199 | + * rx: SPI RX data register | |
| 200 | + * tx: SPI TX data register | |
| 201 | + */ | |
| 202 | +struct stm32_spi_regspec { | |
| 203 | + const struct stm32_spi_reg en; | |
| 204 | + const struct stm32_spi_reg dma_rx_en; | |
| 205 | + const struct stm32_spi_reg dma_tx_en; | |
| 206 | + const struct stm32_spi_reg cpol; | |
| 207 | + const struct stm32_spi_reg cpha; | |
| 208 | + const struct stm32_spi_reg lsb_first; | |
| 209 | + const struct stm32_spi_reg br; | |
| 210 | + const struct stm32_spi_reg rx; | |
| 211 | + const struct stm32_spi_reg tx; | |
| 212 | +}; | |
| 213 | + | |
| 214 | +struct stm32_spi; | |
| 215 | + | |
| 216 | +/** | |
| 217 | + * stm32_spi_cfg - stm32 compatible configuration data | |
| 218 | + * @regs: registers descriptions | |
| 219 | + * @get_fifo_size: routine to get fifo size | |
| 220 | + * @get_bpw_mask: routine to get bits per word mask | |
| 221 | + * @disable: routine to disable controller | |
| 222 | + * @config: routine to configure controller as SPI Master | |
| 223 | + * @set_bpw: routine to configure registers to for bits per word | |
| 224 | + * @set_mode: routine to configure registers to desired mode | |
| 225 | + * @set_data_idleness: optional routine to configure registers to desired idle | |
| 226 | + * time between frames (if driver has this functionality) | |
| 227 | + * set_number_of_data: optional routine to configure registers to desired | |
| 228 | + * number of data (if driver has this functionality) | |
| 229 | + * @can_dma: routine to determine if the transfer is eligible for DMA use | |
| 230 | + * @transfer_one_dma_start: routine to start transfer a single spi_transfer | |
| 231 | + * using DMA | |
| 232 | + * @dma_rx cb: routine to call after DMA RX channel operation is complete | |
| 233 | + * @dma_tx cb: routine to call after DMA TX channel operation is complete | |
| 234 | + * @transfer_one_irq: routine to configure interrupts for driver | |
| 235 | + * @irq_handler_event: Interrupt handler for SPI controller events | |
| 236 | + * @irq_handler_thread: thread of interrupt handler for SPI controller | |
| 237 | + * @baud_rate_div_min: minimum baud rate divisor | |
| 238 | + * @baud_rate_div_max: maximum baud rate divisor | |
| 239 | + * @has_fifo: boolean to know if fifo is used for driver | |
| 240 | + * @has_startbit: boolean to know if start bit is used to start transfer | |
| 241 | + */ | |
| 242 | +struct stm32_spi_cfg { | |
| 243 | + const struct stm32_spi_regspec *regs; | |
| 244 | + int (*get_fifo_size)(struct stm32_spi *spi); | |
| 245 | + int (*get_bpw_mask)(struct stm32_spi *spi); | |
| 246 | + void (*disable)(struct stm32_spi *spi); | |
| 247 | + int (*config)(struct stm32_spi *spi); | |
| 248 | + void (*set_bpw)(struct stm32_spi *spi); | |
| 249 | + int (*set_mode)(struct stm32_spi *spi, unsigned int comm_type); | |
| 250 | + void (*set_data_idleness)(struct stm32_spi *spi, u32 length); | |
| 251 | + int (*set_number_of_data)(struct stm32_spi *spi, u32 length); | |
| 252 | + void (*transfer_one_dma_start)(struct stm32_spi *spi); | |
| 253 | + void (*dma_rx_cb)(void *data); | |
| 254 | + void (*dma_tx_cb)(void *data); | |
| 255 | + int (*transfer_one_irq)(struct stm32_spi *spi); | |
| 256 | + irqreturn_t (*irq_handler_event)(int irq, void *dev_id); | |
| 257 | + irqreturn_t (*irq_handler_thread)(int irq, void *dev_id); | |
| 258 | + unsigned int baud_rate_div_min; | |
| 259 | + unsigned int baud_rate_div_max; | |
| 260 | + bool has_fifo; | |
| 261 | +}; | |
| 262 | + | |
| 125 | 263 | /** |
| 126 | 264 | * struct stm32_spi - private data of the SPI controller |
| 127 | 265 | * @dev: driver model representation of the controller |
| 128 | 266 | * @master: controller master interface |
| 267 | + * @cfg: compatible configuration data | |
| 129 | 268 | * @base: virtual memory area |
| 130 | 269 | * @clk: hw kernel clock feeding the SPI clock generator |
| 131 | 270 | * @clk_rate: rate of the hw kernel clock feeding the SPI clock generator |
| @@ -151,6 +290,7 @@ · 19 unmodified lines | ||
| 151 | 290 | struct stm32_spi { |
| 152 | 291 | struct device *dev; |
| 153 | 292 | struct spi_master *master; |
| 293 | + const struct stm32_spi_cfg *cfg; | |
| 154 | 294 | void __iomem *base; |
| 155 | 295 | struct clk *clk; |
| 156 | 296 | u32 clk_rate; |
| @@ -176,6 +316,40 @@ struct stm32_spi { · 19 unmodified lines | ||
| 176 | 316 | dma_addr_t phys_addr; |
| 177 | 317 | }; |
| 178 | 318 | |
| 319 | +static const struct stm32_spi_regspec stm32f4_spi_regspec = { | |
| 320 | + .en = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE }, | |
| 321 | + | |
| 322 | + .dma_rx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_RXDMAEN }, | |
| 323 | + .dma_tx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN }, | |
| 324 | + | |
| 325 | + .cpol = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPOL }, | |
| 326 | + .cpha = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPHA }, | |
| 327 | + .lsb_first = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_LSBFRST }, | |
| 328 | + .br = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_BR, STM32F4_SPI_CR1_BR_SHIFT }, | |
| 329 | + | |
| 330 | + .rx = { STM32F4_SPI_DR }, | |
| 331 | + .tx = { STM32F4_SPI_DR }, | |
| 332 | +}; | |
| 333 | + | |
| 334 | +static const struct stm32_spi_regspec stm32h7_spi_regspec = { | |
| 335 | + /* SPI data transfer is enabled but spi_ker_ck is idle. | |
| 336 | + * CFG1 and CFG2 registers are write protected when SPE is enabled. | |
| 337 | + */ | |
| 338 | + .en = { STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE }, | |
| 339 | + | |
| 340 | + .dma_rx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_RXDMAEN }, | |
| 341 | + .dma_tx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN }, | |
| 342 | + | |
| 343 | + .cpol = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPOL }, | |
| 344 | + .cpha = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPHA }, | |
| 345 | + .lsb_first = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_LSBFRST }, | |
| 346 | + .br = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_MBR, | |
| 347 | + STM32H7_SPI_CFG1_MBR_SHIFT }, | |
| 348 | + | |
| 349 | + .rx = { STM32H7_SPI_RXDR }, | |
| 350 | + .tx = { STM32H7_SPI_TXDR }, | |
| 351 | +}; | |
| 352 | + | |
| 179 | 353 | static inline void stm32_spi_set_bits(struct stm32_spi *spi, |
| 180 | 354 | u32 offset, u32 bits) |
| 181 | 355 | { |
| @@ -191,22 +365,22 @@ static inline void stm32_spi_clr_bits(struct stm32_spi *spi, · 9 unmodified lines | ||
| 191 | 365 | } |
| 192 | 366 | |
| 193 | 367 | /** |
| 194 | − * stm32_spi_get_fifo_size - Return fifo size | |
| 368 | + * stm32h7_spi_get_fifo_size - Return fifo size | |
| 195 | 369 | * @spi: pointer to the spi controller data structure |
| 196 | 370 | */ |
| 197 | −static int stm32_spi_get_fifo_size(struct stm32_spi *spi) | |
| 371 | +static int stm32h7_spi_get_fifo_size(struct stm32_spi *spi) | |
| 198 | 372 | { |
| 199 | 373 | unsigned long flags; |
| 200 | 374 | u32 count = 0; |
| 201 | 375 | |
| 202 | 376 | spin_lock_irqsave(&spi->lock, flags); |
| 203 | 377 | |
| 204 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE); | |
| 378 | + stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE); | |
| 205 | 379 | |
| 206 | − while (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP) | |
| 207 | − writeb_relaxed(++count, spi->base + STM32_SPI_TXDR); | |
| 380 | + while (readl_relaxed(spi->base + STM32H7_SPI_SR) & STM32H7_SPI_SR_TXP) | |
| 381 | + writeb_relaxed(++count, spi->base + STM32H7_SPI_TXDR); | |
| 208 | 382 | |
| 209 | − stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE); | |
| 383 | + stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE); | |
| 210 | 384 | |
| 211 | 385 | spin_unlock_irqrestore(&spi->lock, flags); |
| 212 | 386 | |
| @@ -216,10 +390,20 @@ static int stm32_spi_get_fifo_size(struct stm32_spi *spi) · 3 unmodified lines | ||
| 216 | 390 | } |
| 217 | 391 | |
| 218 | 392 | /** |
| 219 | − * stm32_spi_get_bpw_mask - Return bits per word mask | |
| 393 | + * stm32f4_spi_get_bpw_mask - Return bits per word mask | |
| 220 | 394 | * @spi: pointer to the spi controller data structure |
| 221 | 395 | */ |
| 222 | −static int stm32_spi_get_bpw_mask(struct stm32_spi *spi) | |
| 396 | +static int stm32f4_spi_get_bpw_mask(struct stm32_spi *spi) | |
| 397 | +{ | |
| 398 | + dev_dbg(spi->dev, "8-bit or 16-bit data frame supported\n"); | |
| 399 | + return SPI_BPW_MASK(8) | SPI_BPW_MASK(16); | |
| 400 | +} | |
| 401 | + | |
| 402 | +/** | |
| 403 | + * stm32h7_spi_get_bpw_mask - Return bits per word mask | |
| 404 | + * @spi: pointer to the spi controller data structure | |
| 405 | + */ | |
| 406 | +static int stm32h7_spi_get_bpw_mask(struct stm32_spi *spi) | |
| 223 | 407 | { |
| 224 | 408 | unsigned long flags; |
| 225 | 409 | u32 cfg1, max_bpw; |
| @@ -230,10 +414,11 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi) · 4 unmodified lines | ||
| 230 | 414 | * The most significant bit at DSIZE bit field is reserved when the |
| 231 | 415 | * maximum data size of periperal instances is limited to 16-bit |
| 232 | 416 | */ |
| 233 | − stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_DSIZE); | |
| 417 | + stm32_spi_set_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_DSIZE); | |
| 234 | 418 | |
| 235 | − cfg1 = readl_relaxed(spi->base + STM32_SPI_CFG1); | |
| 236 | − max_bpw = (cfg1 & SPI_CFG1_DSIZE) >> SPI_CFG1_DSIZE_SHIFT; | |
| 419 | + cfg1 = readl_relaxed(spi->base + STM32H7_SPI_CFG1); | |
| 420 | + max_bpw = (cfg1 & STM32H7_SPI_CFG1_DSIZE) >> | |
| 421 | + STM32H7_SPI_CFG1_DSIZE_SHIFT; | |
| 237 | 422 | max_bpw += 1; |
| 238 | 423 | |
| 239 | 424 | spin_unlock_irqrestore(&spi->lock, flags); |
| @@ -244,13 +429,16 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi) · 4 unmodified lines | ||
| 244 | 429 | } |
| 245 | 430 | |
| 246 | 431 | /** |
| 247 | − * stm32_spi_prepare_mbr - Determine SPI_CFG1.MBR value | |
| 432 | + * stm32_spi_prepare_mbr - Determine baud rate divisor value | |
| 248 | 433 | * @spi: pointer to the spi controller data structure |
| 249 | 434 | * @speed_hz: requested speed |
| 435 | + * @min_div: minimum baud rate divisor | |
| 436 | + * @max_div: maximum baud rate divisor | |
| 250 | 437 | * |
| 251 | − * Return SPI_CFG1.MBR value in case of success or -EINVAL | |
| 438 | + * Return baud rate divisor value in case of success or -EINVAL | |
| 252 | 439 | */ |
| 253 | −static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) | |
| 440 | +static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz, | |
| 441 | + u32 min_div, u32 max_div) | |
| 254 | 442 | { |
| 255 | 443 | u32 div, mbrdiv; |
| 256 | 444 | |
| @@ -263,8 +451,7 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) · 6 unmodified lines | ||
| 263 | 451 | * no need to check it there. |
| 264 | 452 | * However, we need to ensure the following calculations. |
| 265 | 453 | */ |
| 266 | − if (div < SPI_MBR_DIV_MIN || | |
| 267 | − div > SPI_MBR_DIV_MAX) | |
| 454 | + if ((div < min_div) || (div > max_div)) | |
| 268 | 455 | return -EINVAL; |
| 269 | 456 | |
| 270 | 457 | /* Determine the first power of 2 greater than or equal to div */ |
| @@ -279,10 +466,10 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) · 8 unmodified lines | ||
| 279 | 466 | } |
| 280 | 467 | |
| 281 | 468 | /** |
| 282 | − * stm32_spi_prepare_fthlv - Determine FIFO threshold level | |
| 469 | + * stm32h7_spi_prepare_fthlv - Determine FIFO threshold level | |
| 283 | 470 | * @spi: pointer to the spi controller data structure |
| 284 | 471 | */ |
| 285 | −static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi) | |
| 472 | +static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi) | |
| 286 | 473 | { |
| 287 | 474 | u32 fthlv, half_fifo; |
| 288 | 475 | |
| @@ -306,32 +493,62 @@ static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi) · 17 unmodified lines | ||
| 306 | 493 | } |
| 307 | 494 | |
| 308 | 495 | /** |
| 309 | − * stm32_spi_write_txfifo - Write bytes in Transmit Data Register | |
| 496 | + * stm32f4_spi_write_tx - Write bytes to Transmit Data Register | |
| 310 | 497 | * @spi: pointer to the spi controller data structure |
| 311 | 498 | * |
| 312 | 499 | * Read from tx_buf depends on remaining bytes to avoid to read beyond |
| 313 | 500 | * tx_buf end. |
| 314 | 501 | */ |
| 315 | −static void stm32_spi_write_txfifo(struct stm32_spi *spi) | |
| 502 | +static void stm32f4_spi_write_tx(struct stm32_spi *spi) | |
| 503 | +{ | |
| 504 | + if ((spi->tx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) & | |
| 505 | + STM32F4_SPI_SR_TXE)) { | |
| 506 | + u32 offs = spi->cur_xferlen - spi->tx_len; | |
| 507 | + | |
| 508 | + if (spi->cur_bpw == 16) { | |
| 509 | + const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs); | |
| 510 | + | |
| 511 | + writew_relaxed(*tx_buf16, spi->base + STM32F4_SPI_DR); | |
| 512 | + spi->tx_len -= sizeof(u16); | |
| 513 | + } else { | |
| 514 | + const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs); | |
| 515 | + | |
| 516 | + writeb_relaxed(*tx_buf8, spi->base + STM32F4_SPI_DR); | |
| 517 | + spi->tx_len -= sizeof(u8); | |
| 518 | + } | |
| 519 | + } | |
| 520 | + | |
| 521 | + dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->tx_len); | |
| 522 | +} | |
| 523 | + | |
| 524 | +/** | |
| 525 | + * stm32h7_spi_write_txfifo - Write bytes in Transmit Data Register | |
| 526 | + * @spi: pointer to the spi controller data structure | |
| 527 | + * | |
| 528 | + * Read from tx_buf depends on remaining bytes to avoid to read beyond | |
| 529 | + * tx_buf end. | |
| 530 | + */ | |
| 531 | +static void stm32h7_spi_write_txfifo(struct stm32_spi *spi) | |
| 316 | 532 | { |
| 317 | 533 | while ((spi->tx_len > 0) && |
| 318 | − (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP)) { | |
| 534 | + (readl_relaxed(spi->base + STM32H7_SPI_SR) & | |
| 535 | + STM32H7_SPI_SR_TXP)) { | |
| 319 | 536 | u32 offs = spi->cur_xferlen - spi->tx_len; |
| 320 | 537 | |
| 321 | 538 | if (spi->tx_len >= sizeof(u32)) { |
| 322 | 539 | const u32 *tx_buf32 = (const u32 *)(spi->tx_buf + offs); |
| 323 | 540 | |
| 324 | − writel_relaxed(*tx_buf32, spi->base + STM32_SPI_TXDR); | |
| 541 | + writel_relaxed(*tx_buf32, spi->base + STM32H7_SPI_TXDR); | |
| 325 | 542 | spi->tx_len -= sizeof(u32); |
| 326 | 543 | } else if (spi->tx_len >= sizeof(u16)) { |
| 327 | 544 | const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs); |
| 328 | 545 | |
| 329 | − writew_relaxed(*tx_buf16, spi->base + STM32_SPI_TXDR); | |
| 546 | + writew_relaxed(*tx_buf16, spi->base + STM32H7_SPI_TXDR); | |
| 330 | 547 | spi->tx_len -= sizeof(u16); |
| 331 | 548 | } else { |
| 332 | 549 | const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs); |
| 333 | 550 | |
| 334 | − writeb_relaxed(*tx_buf8, spi->base + STM32_SPI_TXDR); | |
| 551 | + writeb_relaxed(*tx_buf8, spi->base + STM32H7_SPI_TXDR); | |
| 335 | 552 | spi->tx_len -= sizeof(u8); |
| 336 | 553 | } |
| 337 | 554 | } |
| @@ -340,43 +557,74 @@ static void stm32_spi_write_txfifo(struct stm32_spi *spi) · 2 unmodified lines | ||
| 340 | 557 | } |
| 341 | 558 | |
| 342 | 559 | /** |
| 343 | − * stm32_spi_read_rxfifo - Read bytes in Receive Data Register | |
| 560 | + * stm32f4_spi_read_rx - Read bytes from Receive Data Register | |
| 561 | + * @spi: pointer to the spi controller data structure | |
| 562 | + * | |
| 563 | + * Write in rx_buf depends on remaining bytes to avoid to write beyond | |
| 564 | + * rx_buf end. | |
| 565 | + */ | |
| 566 | +static void stm32f4_spi_read_rx(struct stm32_spi *spi) | |
| 567 | +{ | |
| 568 | + if ((spi->rx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) & | |
| 569 | + STM32F4_SPI_SR_RXNE)) { | |
| 570 | + u32 offs = spi->cur_xferlen - spi->rx_len; | |
| 571 | + | |
| 572 | + if (spi->cur_bpw == 16) { | |
| 573 | + u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs); | |
| 574 | + | |
| 575 | + *rx_buf16 = readw_relaxed(spi->base + STM32F4_SPI_DR); | |
| 576 | + spi->rx_len -= sizeof(u16); | |
| 577 | + } else { | |
| 578 | + u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs); | |
| 579 | + | |
| 580 | + *rx_buf8 = readb_relaxed(spi->base + STM32F4_SPI_DR); | |
| 581 | + spi->rx_len -= sizeof(u8); | |
| 582 | + } | |
| 583 | + } | |
| 584 | + | |
| 585 | + dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->rx_len); | |
| 586 | +} | |
| 587 | + | |
| 588 | +/** | |
| 589 | + * stm32h7_spi_read_rxfifo - Read bytes in Receive Data Register | |
| 344 | 590 | * @spi: pointer to the spi controller data structure |
| 345 | 591 | * |
| 346 | 592 | * Write in rx_buf depends on remaining bytes to avoid to write beyond |
| 347 | 593 | * rx_buf end. |
| 348 | 594 | */ |
| 349 | −static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush) | |
| 595 | +static void stm32h7_spi_read_rxfifo(struct stm32_spi *spi, bool flush) | |
| 350 | 596 | { |
| 351 | − u32 sr = readl_relaxed(spi->base + STM32_SPI_SR); | |
| 352 | − u32 rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT; | |
| 597 | + u32 sr = readl_relaxed(spi->base + STM32H7_SPI_SR); | |
| 598 | + u32 rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >> | |
| 599 | + STM32H7_SPI_SR_RXPLVL_SHIFT; | |
| 353 | 600 | |
| 354 | 601 | while ((spi->rx_len > 0) && |
| 355 | − ((sr & SPI_SR_RXP) || | |
| 356 | − (flush && ((sr & SPI_SR_RXWNE) || (rxplvl > 0))))) { | |
| 602 | + ((sr & STM32H7_SPI_SR_RXP) || | |
| 603 | + (flush && ((sr & STM32H7_SPI_SR_RXWNE) || (rxplvl > 0))))) { | |
| 357 | 604 | u32 offs = spi->cur_xferlen - spi->rx_len; |
| 358 | 605 | |
| 359 | 606 | if ((spi->rx_len >= sizeof(u32)) || |
| 360 | − (flush && (sr & SPI_SR_RXWNE))) { | |
| 607 | + (flush && (sr & STM32H7_SPI_SR_RXWNE))) { | |
| 361 | 608 | u32 *rx_buf32 = (u32 *)(spi->rx_buf + offs); |
| 362 | 609 | |
| 363 | − *rx_buf32 = readl_relaxed(spi->base + STM32_SPI_RXDR); | |
| 610 | + *rx_buf32 = readl_relaxed(spi->base + STM32H7_SPI_RXDR); | |
| 364 | 611 | spi->rx_len -= sizeof(u32); |
| 365 | 612 | } else if ((spi->rx_len >= sizeof(u16)) || |
| 366 | 613 | (flush && (rxplvl >= 2 || spi->cur_bpw > 8))) { |
| 367 | 614 | u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs); |
| 368 | 615 | |
| 369 | − *rx_buf16 = readw_relaxed(spi->base + STM32_SPI_RXDR); | |
| 616 | + *rx_buf16 = readw_relaxed(spi->base + STM32H7_SPI_RXDR); | |
| 370 | 617 | spi->rx_len -= sizeof(u16); |
| 371 | 618 | } else { |
| 372 | 619 | u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs); |
| 373 | 620 | |
| 374 | − *rx_buf8 = readb_relaxed(spi->base + STM32_SPI_RXDR); | |
| 621 | + *rx_buf8 = readb_relaxed(spi->base + STM32H7_SPI_RXDR); | |
| 375 | 622 | spi->rx_len -= sizeof(u8); |
| 376 | 623 | } |
| 377 | 624 | |
| 378 | − sr = readl_relaxed(spi->base + STM32_SPI_SR); | |
| 379 | − rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT; | |
| 625 | + sr = readl_relaxed(spi->base + STM32H7_SPI_SR); | |
| 626 | + rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >> | |
| 627 | + STM32H7_SPI_SR_RXPLVL_SHIFT; | |
| 380 | 628 | } |
| 381 | 629 | |
| 382 | 630 | dev_dbg(spi->dev, "%s%s: %d bytes left\n", __func__, |
| @@ -386,26 +634,76 @@ static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush) · 3 unmodified lines | ||
| 386 | 634 | /** |
| 387 | 635 | * stm32_spi_enable - Enable SPI controller |
| 388 | 636 | * @spi: pointer to the spi controller data structure |
| 389 | − * | |
| 390 | − * SPI data transfer is enabled but spi_ker_ck is idle. | |
| 391 | − * SPI_CFG1 and SPI_CFG2 are now write protected. | |
| 392 | 637 | */ |
| 393 | 638 | static void stm32_spi_enable(struct stm32_spi *spi) |
| 394 | 639 | { |
| 395 | 640 | dev_dbg(spi->dev, "enable controller\n"); |
| 396 | 641 | |
| 397 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE); | |
| 642 | + stm32_spi_set_bits(spi, spi->cfg->regs->en.reg, | |
| 643 | + spi->cfg->regs->en.mask); | |
| 398 | 644 | } |
| 399 | 645 | |
| 400 | 646 | /** |
| 401 | − * stm32_spi_disable - Disable SPI controller | |
| 647 | + * stm32f4_spi_disable - Disable SPI controller | |
| 648 | + * @spi: pointer to the spi controller data structure | |
| 649 | + */ | |
| 650 | +static void stm32f4_spi_disable(struct stm32_spi *spi) | |
| 651 | +{ | |
| 652 | + unsigned long flags; | |
| 653 | + u32 sr; | |
| 654 | + | |
| 655 | + dev_dbg(spi->dev, "disable controller\n"); | |
| 656 | + | |
| 657 | + spin_lock_irqsave(&spi->lock, flags); | |
| 658 | + | |
| 659 | + if (!(readl_relaxed(spi->base + STM32F4_SPI_CR1) & | |
| 660 | + STM32F4_SPI_CR1_SPE)) { | |
| 661 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 662 | + return; | |
| 663 | + } | |
| 664 | + | |
| 665 | + /* Disable interrupts */ | |
| 666 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXEIE | | |
| 667 | + STM32F4_SPI_CR2_RXNEIE | | |
| 668 | + STM32F4_SPI_CR2_ERRIE); | |
| 669 | + | |
| 670 | + /* Wait until BSY = 0 */ | |
| 671 | + if (readl_relaxed_poll_timeout_atomic(spi->base + STM32F4_SPI_SR, | |
| 672 | + sr, !(sr & STM32F4_SPI_SR_BSY), | |
| 673 | + 10, 100000) < 0) { | |
| 674 | + dev_warn(spi->dev, "disabling condition timeout\n"); | |
| 675 | + } | |
| 676 | + | |
| 677 | + if (spi->cur_usedma && spi->dma_tx) | |
| 678 | + dmaengine_terminate_all(spi->dma_tx); | |
| 679 | + if (spi->cur_usedma && spi->dma_rx) | |
| 680 | + dmaengine_terminate_all(spi->dma_rx); | |
| 681 | + | |
| 682 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE); | |
| 683 | + | |
| 684 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN | | |
| 685 | + STM32F4_SPI_CR2_RXDMAEN); | |
| 686 | + | |
| 687 | + /* Sequence to clear OVR flag */ | |
| 688 | + readl_relaxed(spi->base + STM32F4_SPI_DR); | |
| 689 | + readl_relaxed(spi->base + STM32F4_SPI_SR); | |
| 690 | + | |
| 691 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 692 | +} | |
| 693 | + | |
| 694 | +/** | |
| 695 | + * stm32h7_spi_disable - Disable SPI controller | |
| 402 | 696 | * @spi: pointer to the spi controller data structure |
| 403 | 697 | * |
| 404 | 698 | * RX-Fifo is flushed when SPI controller is disabled. To prevent any data |
| 405 | − * loss, use stm32_spi_read_rxfifo(flush) to read the remaining bytes in | |
| 699 | + * loss, use stm32h7_spi_read_rxfifo(flush) to read the remaining bytes in | |
| 406 | 700 | * RX-Fifo. |
| 701 | + * Normally, if TSIZE has been configured, we should relax the hardware at the | |
| 702 | + * reception of the EOT interrupt. But in case of error, EOT will not be | |
| 703 | + * raised. So the subsystem unprepare_message call allows us to properly | |
| 704 | + * complete the transfer from an hardware point of view. | |
| 407 | 705 | */ |
| 408 | −static void stm32_spi_disable(struct stm32_spi *spi) | |
| 706 | +static void stm32h7_spi_disable(struct stm32_spi *spi) | |
| 409 | 707 | { |
| 410 | 708 | unsigned long flags; |
| 411 | 709 | u32 cr1, sr; |
| @@ -414,23 +712,23 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 2 unmodified lines | ||
| 414 | 712 | |
| 415 | 713 | spin_lock_irqsave(&spi->lock, flags); |
| 416 | 714 | |
| 417 | − cr1 = readl_relaxed(spi->base + STM32_SPI_CR1); | |
| 715 | + cr1 = readl_relaxed(spi->base + STM32H7_SPI_CR1); | |
| 418 | 716 | |
| 419 | − if (!(cr1 & SPI_CR1_SPE)) { | |
| 717 | + if (!(cr1 & STM32H7_SPI_CR1_SPE)) { | |
| 420 | 718 | spin_unlock_irqrestore(&spi->lock, flags); |
| 421 | 719 | return; |
| 422 | 720 | } |
| 423 | 721 | |
| 424 | 722 | /* Wait on EOT or suspend the flow */ |
| 425 | − if (readl_relaxed_poll_timeout_atomic(spi->base + STM32_SPI_SR, | |
| 426 | − sr, !(sr & SPI_SR_EOT), | |
| 723 | + if (readl_relaxed_poll_timeout_atomic(spi->base + STM32H7_SPI_SR, | |
| 724 | + sr, !(sr & STM32H7_SPI_SR_EOT), | |
| 427 | 725 | 10, 100000) < 0) { |
| 428 | − if (cr1 & SPI_CR1_CSTART) { | |
| 429 | − writel_relaxed(cr1 | SPI_CR1_CSUSP, | |
| 430 | − spi->base + STM32_SPI_CR1); | |
| 726 | + if (cr1 & STM32H7_SPI_CR1_CSTART) { | |
| 727 | + writel_relaxed(cr1 | STM32H7_SPI_CR1_CSUSP, | |
| 728 | + spi->base + STM32H7_SPI_CR1); | |
| 431 | 729 | if (readl_relaxed_poll_timeout_atomic( |
| 432 | − spi->base + STM32_SPI_SR, | |
| 433 | − sr, !(sr & SPI_SR_SUSP), | |
| 730 | + spi->base + STM32H7_SPI_SR, | |
| 731 | + sr, !(sr & STM32H7_SPI_SR_SUSP), | |
| 434 | 732 | 10, 100000) < 0) |
| 435 | 733 | dev_warn(spi->dev, |
| 436 | 734 | "Suspend request timeout\n"); |
| @@ -438,21 +736,21 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 1 unmodified line | ||
| 438 | 736 | } |
| 439 | 737 | |
| 440 | 738 | if (!spi->cur_usedma && spi->rx_buf && (spi->rx_len > 0)) |
| 441 | − stm32_spi_read_rxfifo(spi, true); | |
| 739 | + stm32h7_spi_read_rxfifo(spi, true); | |
| 442 | 740 | |
| 443 | − if (spi->cur_usedma && spi->tx_buf) | |
| 741 | + if (spi->cur_usedma && spi->dma_tx) | |
| 444 | 742 | dmaengine_terminate_all(spi->dma_tx); |
| 445 | − if (spi->cur_usedma && spi->rx_buf) | |
| 743 | + if (spi->cur_usedma && spi->dma_rx) | |
| 446 | 744 | dmaengine_terminate_all(spi->dma_rx); |
| 447 | 745 | |
| 448 | − stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE); | |
| 746 | + stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE); | |
| 449 | 747 | |
| 450 | − stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN | | |
| 451 | − SPI_CFG1_RXDMAEN); | |
| 748 | + stm32_spi_clr_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN | | |
| 749 | + STM32H7_SPI_CFG1_RXDMAEN); | |
| 452 | 750 | |
| 453 | 751 | /* Disable interrupts and clear status flags */ |
| 454 | − writel_relaxed(0, spi->base + STM32_SPI_IER); | |
| 455 | − writel_relaxed(SPI_IFCR_ALL, spi->base + STM32_SPI_IFCR); | |
| 752 | + writel_relaxed(0, spi->base + STM32H7_SPI_IER); | |
| 753 | + writel_relaxed(STM32H7_SPI_IFCR_ALL, spi->base + STM32H7_SPI_IFCR); | |
| 456 | 754 | |
| 457 | 755 | spin_unlock_irqrestore(&spi->lock, flags); |
| 458 | 756 | } |
| @@ -460,26 +758,136 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 1 unmodified line | ||
| 460 | 758 | /** |
| 461 | 759 | * stm32_spi_can_dma - Determine if the transfer is eligible for DMA use |
| 462 | 760 | * |
| 463 | − * If the current transfer size is greater than fifo size, use DMA. | |
| 761 | + * If driver has fifo and the current transfer size is greater than fifo size, | |
| 762 | + * use DMA. Otherwise use DMA for transfer longer than defined DMA min bytes. | |
| 464 | 763 | */ |
| 465 | 764 | static bool stm32_spi_can_dma(struct spi_master *master, |
| 466 | 765 | struct spi_device *spi_dev, |
| 467 | 766 | struct spi_transfer *transfer) |
| 468 | 767 | { |
| 768 | + unsigned int dma_size; | |
| 469 | 769 | struct stm32_spi *spi = spi_master_get_devdata(master); |
| 470 | 770 | |
| 771 | + if (spi->cfg->has_fifo) | |
| 772 | + dma_size = spi->fifo_size; | |
| 773 | + else | |
| 774 | + dma_size = SPI_DMA_MIN_BYTES; | |
| 775 | + | |
| 471 | 776 | dev_dbg(spi->dev, "%s: %s\n", __func__, |
| 472 | − (transfer->len > spi->fifo_size) ? "true" : "false"); | |
| 777 | + (transfer->len > dma_size) ? "true" : "false"); | |
| 778 | + | |
| 779 | + return (transfer->len > dma_size); | |
| 780 | +} | |
| 781 | + | |
| 782 | +/** | |
| 783 | + * stm32f4_spi_irq_event - Interrupt handler for SPI controller events | |
| 784 | + * @irq: interrupt line | |
| 785 | + * @dev_id: SPI controller master interface | |
| 786 | + */ | |
| 787 | +static irqreturn_t stm32f4_spi_irq_event(int irq, void *dev_id) | |
| 788 | +{ | |
| 789 | + struct spi_master *master = dev_id; | |
| 790 | + struct stm32_spi *spi = spi_master_get_devdata(master); | |
| 791 | + u32 sr, mask = 0; | |
| 792 | + unsigned long flags; | |
| 793 | + bool end = false; | |
| 794 | + | |
| 795 | + spin_lock_irqsave(&spi->lock, flags); | |
| 796 | + | |
| 797 | + sr = readl_relaxed(spi->base + STM32F4_SPI_SR); | |
| 798 | + /* | |
| 799 | + * BSY flag is not handled in interrupt but it is normal behavior when | |
| 800 | + * this flag is set. | |
| 801 | + */ | |
| 802 | + sr &= ~STM32F4_SPI_SR_BSY; | |
| 803 | + | |
| 804 | + if (!spi->cur_usedma && (spi->cur_comm == SPI_SIMPLEX_TX || | |
| 805 | + spi->cur_comm == SPI_3WIRE_TX)) { | |
| 806 | + /* OVR flag shouldn't be handled for TX only mode */ | |
| 807 | + sr &= ~STM32F4_SPI_SR_OVR | STM32F4_SPI_SR_RXNE; | |
| 808 | + mask |= STM32F4_SPI_SR_TXE; | |
| 809 | + } | |
| 810 | + | |
| 811 | + if (!spi->cur_usedma && spi->cur_comm == SPI_FULL_DUPLEX) { | |
| 812 | + /* TXE flag is set and is handled when RXNE flag occurs */ | |
| 813 | + sr &= ~STM32F4_SPI_SR_TXE; | |
| 814 | + mask |= STM32F4_SPI_SR_RXNE | STM32F4_SPI_SR_OVR; | |
| 815 | + } | |
| 816 | + | |
| 817 | + if (!(sr & mask)) { | |
| 818 | + dev_dbg(spi->dev, "spurious IT (sr=0x%08x)\n", sr); | |
| 819 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 820 | + return IRQ_NONE; | |
| 821 | + } | |
| 822 | + | |
| 823 | + if (sr & STM32F4_SPI_SR_OVR) { | |
| 824 | + dev_warn(spi->dev, "Overrun: received value discarded\n"); | |
| 825 | + | |
| 826 | + /* Sequence to clear OVR flag */ | |
| 827 | + readl_relaxed(spi->base + STM32F4_SPI_DR); | |
| 828 | + readl_relaxed(spi->base + STM32F4_SPI_SR); | |
| 829 | + | |
| 830 | + /* | |
| 831 | + * If overrun is detected, it means that something went wrong, | |
| 832 | + * so stop the current transfer. Transfer can wait for next | |
| 833 | + * RXNE but DR is already read and end never happens. | |
| 834 | + */ | |
| 835 | + end = true; | |
| 836 | + goto end_irq; | |
| 837 | + } | |
| 838 | + | |
| 839 | + if (sr & STM32F4_SPI_SR_TXE) { | |
| 840 | + if (spi->tx_buf) | |
| 841 | + stm32f4_spi_write_tx(spi); | |
| 842 | + if (spi->tx_len == 0) | |
| 843 | + end = true; | |
| 844 | + } | |
| 845 | + | |
| 846 | + if (sr & STM32F4_SPI_SR_RXNE) { | |
| 847 | + stm32f4_spi_read_rx(spi); | |
| 848 | + if (spi->rx_len == 0) | |
| 849 | + end = true; | |
| 850 | + else /* Load data for discontinuous mode */ | |
| 851 | + stm32f4_spi_write_tx(spi); | |
| 852 | + } | |
| 853 | + | |
| 854 | +end_irq: | |
| 855 | + if (end) { | |
| 856 | + /* Immediately disable interrupts to do not generate new one */ | |
| 857 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, | |
| 858 | + STM32F4_SPI_CR2_TXEIE | | |
| 859 | + STM32F4_SPI_CR2_RXNEIE | | |
| 860 | + STM32F4_SPI_CR2_ERRIE); | |
| 861 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 862 | + return IRQ_WAKE_THREAD; | |
| 863 | + } | |
| 864 | + | |
| 865 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 866 | + return IRQ_HANDLED; | |
| 867 | +} | |
| 868 | + | |
| 869 | +/** | |
| 870 | + * stm32f4_spi_irq_thread - Thread of interrupt handler for SPI controller | |
| 871 | + * @irq: interrupt line | |
| 872 | + * @dev_id: SPI controller master interface | |
| 873 | + */ | |
| 874 | +static irqreturn_t stm32f4_spi_irq_thread(int irq, void *dev_id) | |
| 875 | +{ | |
| 876 | + struct spi_master *master = dev_id; | |
| 877 | + struct stm32_spi *spi = spi_master_get_devdata(master); | |
| 878 | + | |
| 879 | + spi_finalize_current_transfer(master); | |
| 880 | + stm32f4_spi_disable(spi); | |
| 473 | 881 | |
| 474 | − return (transfer->len > spi->fifo_size); | |
| 882 | + return IRQ_HANDLED; | |
| 475 | 883 | } |
| 476 | 884 | |
| 477 | 885 | /** |
| 478 | − * stm32_spi_irq - Interrupt handler for SPI controller events | |
| 886 | + * stm32h7_spi_irq_thread - Thread of interrupt handler for SPI controller | |
| 479 | 887 | * @irq: interrupt line |
| 480 | 888 | * @dev_id: SPI controller master interface |
| 481 | 889 | */ |
| 482 | −static irqreturn_t stm32_spi_irq(int irq, void *dev_id) | |
| 890 | +static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id) | |
| 483 | 891 | { |
| 484 | 892 | struct spi_master *master = dev_id; |
| 485 | 893 | struct stm32_spi *spi = spi_master_get_devdata(master); |
| @@ -489,19 +897,19 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 3 unmodified lines | ||
| 489 | 897 | |
| 490 | 898 | spin_lock_irqsave(&spi->lock, flags); |
| 491 | 899 | |
| 492 | − sr = readl_relaxed(spi->base + STM32_SPI_SR); | |
| 493 | − ier = readl_relaxed(spi->base + STM32_SPI_IER); | |
| 900 | + sr = readl_relaxed(spi->base + STM32H7_SPI_SR); | |
| 901 | + ier = readl_relaxed(spi->base + STM32H7_SPI_IER); | |
| 494 | 902 | |
| 495 | 903 | mask = ier; |
| 496 | 904 | /* EOTIE is triggered on EOT, SUSP and TXC events. */ |
| 497 | − mask |= SPI_SR_SUSP; | |
| 905 | + mask |= STM32H7_SPI_SR_SUSP; | |
| 498 | 906 | /* |
| 499 | 907 | * When TXTF is set, DXPIE and TXPIE are cleared. So in case of |
| 500 | 908 | * Full-Duplex, need to poll RXP event to know if there are remaining |
| 501 | 909 | * data, before disabling SPI. |
| 502 | 910 | */ |
| 503 | 911 | if (spi->rx_buf && !spi->cur_usedma) |
| 504 | − mask |= SPI_SR_RXP; | |
| 912 | + mask |= STM32H7_SPI_SR_RXP; | |
| 505 | 913 | |
| 506 | 914 | if (!(sr & mask)) { |
| 507 | 915 | dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n", |
| @@ -510,10 +918,10 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines | ||
| 510 | 918 | return IRQ_NONE; |
| 511 | 919 | } |
| 512 | 920 | |
| 513 | − if (sr & SPI_SR_SUSP) { | |
| 921 | + if (sr & STM32H7_SPI_SR_SUSP) { | |
| 514 | 922 | dev_warn(spi->dev, "Communication suspended\n"); |
| 515 | 923 | if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0))) |
| 516 | − stm32_spi_read_rxfifo(spi, false); | |
| 924 | + stm32h7_spi_read_rxfifo(spi, false); | |
| 517 | 925 | /* |
| 518 | 926 | * If communication is suspended while using DMA, it means |
| 519 | 927 | * that something went wrong, so stop the current transfer |
| @@ -522,15 +930,15 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines | ||
| 522 | 930 | end = true; |
| 523 | 931 | } |
| 524 | 932 | |
| 525 | − if (sr & SPI_SR_MODF) { | |
| 933 | + if (sr & STM32H7_SPI_SR_MODF) { | |
| 526 | 934 | dev_warn(spi->dev, "Mode fault: transfer aborted\n"); |
| 527 | 935 | end = true; |
| 528 | 936 | } |
| 529 | 937 | |
| 530 | − if (sr & SPI_SR_OVR) { | |
| 938 | + if (sr & STM32H7_SPI_SR_OVR) { | |
| 531 | 939 | dev_warn(spi->dev, "Overrun: received value discarded\n"); |
| 532 | 940 | if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0))) |
| 533 | − stm32_spi_read_rxfifo(spi, false); | |
| 941 | + stm32h7_spi_read_rxfifo(spi, false); | |
| 534 | 942 | /* |
| 535 | 943 | * If overrun is detected while using DMA, it means that |
| 536 | 944 | * something went wrong, so stop the current transfer |
| @@ -539,27 +947,27 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines | ||
| 539 | 947 | end = true; |
| 540 | 948 | } |
| 541 | 949 | |
| 542 | − if (sr & SPI_SR_EOT) { | |
| 950 | + if (sr & STM32H7_SPI_SR_EOT) { | |
| 543 | 951 | if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0))) |
| 544 | − stm32_spi_read_rxfifo(spi, true); | |
| 952 | + stm32h7_spi_read_rxfifo(spi, true); | |
| 545 | 953 | end = true; |
| 546 | 954 | } |
| 547 | 955 | |
| 548 | − if (sr & SPI_SR_TXP) | |
| 956 | + if (sr & STM32H7_SPI_SR_TXP) | |
| 549 | 957 | if (!spi->cur_usedma && (spi->tx_buf && (spi->tx_len > 0))) |
| 550 | − stm32_spi_write_txfifo(spi); | |
| 958 | + stm32h7_spi_write_txfifo(spi); | |
| 551 | 959 | |
| 552 | − if (sr & SPI_SR_RXP) | |
| 960 | + if (sr & STM32H7_SPI_SR_RXP) | |
| 553 | 961 | if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0))) |
| 554 | − stm32_spi_read_rxfifo(spi, false); | |
| 962 | + stm32h7_spi_read_rxfifo(spi, false); | |
| 555 | 963 | |
| 556 | − writel_relaxed(mask, spi->base + STM32_SPI_IFCR); | |
| 964 | + writel_relaxed(mask, spi->base + STM32H7_SPI_IFCR); | |
| 557 | 965 | |
| 558 | 966 | spin_unlock_irqrestore(&spi->lock, flags); |
| 559 | 967 | |
| 560 | 968 | if (end) { |
| 561 | 969 | spi_finalize_current_transfer(master); |
| 562 | − stm32_spi_disable(spi); | |
| 970 | + stm32h7_spi_disable(spi); | |
| 563 | 971 | } |
| 564 | 972 | |
| 565 | 973 | return IRQ_HANDLED; |
| @@ -598,7 +1006,7 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 32 unmodified lines | ||
| 598 | 1006 | struct spi_device *spi_dev = msg->spi; |
| 599 | 1007 | struct device_node *np = spi_dev->dev.of_node; |
| 600 | 1008 | unsigned long flags; |
| 601 | − u32 cfg2_clrb = 0, cfg2_setb = 0; | |
| 1009 | + u32 clrb = 0, setb = 0; | |
| 602 | 1010 | |
| 603 | 1011 | /* SPI slave device may need time between data frames */ |
| 604 | 1012 | spi->cur_midi = 0; |
| @@ -606,19 +1014,19 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 1 unmodified line | ||
| 606 | 1014 | dev_dbg(spi->dev, "%dns inter-data idleness\n", spi->cur_midi); |
| 607 | 1015 | |
| 608 | 1016 | if (spi_dev->mode & SPI_CPOL) |
| 609 | − cfg2_setb |= SPI_CFG2_CPOL; | |
| 1017 | + setb |= spi->cfg->regs->cpol.mask; | |
| 610 | 1018 | else |
| 611 | − cfg2_clrb |= SPI_CFG2_CPOL; | |
| 1019 | + clrb |= spi->cfg->regs->cpol.mask; | |
| 612 | 1020 | |
| 613 | 1021 | if (spi_dev->mode & SPI_CPHA) |
| 614 | − cfg2_setb |= SPI_CFG2_CPHA; | |
| 1022 | + setb |= spi->cfg->regs->cpha.mask; | |
| 615 | 1023 | else |
| 616 | − cfg2_clrb |= SPI_CFG2_CPHA; | |
| 1024 | + clrb |= spi->cfg->regs->cpha.mask; | |
| 617 | 1025 | |
| 618 | 1026 | if (spi_dev->mode & SPI_LSB_FIRST) |
| 619 | − cfg2_setb |= SPI_CFG2_LSBFRST; | |
| 1027 | + setb |= spi->cfg->regs->lsb_first.mask; | |
| 620 | 1028 | else |
| 621 | − cfg2_clrb |= SPI_CFG2_LSBFRST; | |
| 1029 | + clrb |= spi->cfg->regs->lsb_first.mask; | |
| 622 | 1030 | |
| 623 | 1031 | dev_dbg(spi->dev, "cpol=%d cpha=%d lsb_first=%d cs_high=%d\n", |
| 624 | 1032 | spi_dev->mode & SPI_CPOL, |
| @@ -628,11 +1036,12 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 3 unmodified lines | ||
| 628 | 1036 | |
| 629 | 1037 | spin_lock_irqsave(&spi->lock, flags); |
| 630 | 1038 | |
| 631 | − if (cfg2_clrb || cfg2_setb) | |
| 1039 | + /* CPOL, CPHA and LSB FIRST bits have common register */ | |
| 1040 | + if (clrb || setb) | |
| 632 | 1041 | writel_relaxed( |
| 633 | − (readl_relaxed(spi->base + STM32_SPI_CFG2) & | |
| 634 | − ~cfg2_clrb) | cfg2_setb, | |
| 635 | − spi->base + STM32_SPI_CFG2); | |
| 1042 | + (readl_relaxed(spi->base + spi->cfg->regs->cpol.reg) & | |
| 1043 | + ~clrb) | setb, | |
| 1044 | + spi->base + spi->cfg->regs->cpol.reg); | |
| 636 | 1045 | |
| 637 | 1046 | spin_unlock_irqrestore(&spi->lock, flags); |
| 638 | 1047 | |
| @@ -640,12 +1049,40 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 1 unmodified line | ||
| 640 | 1049 | } |
| 641 | 1050 | |
| 642 | 1051 | /** |
| 643 | − * stm32_spi_dma_cb - dma callback | |
| 1052 | + * stm32f4_spi_dma_tx_cb - dma callback | |
| 1053 | + * | |
| 1054 | + * DMA callback is called when the transfer is complete for DMA TX channel. | |
| 1055 | + */ | |
| 1056 | +static void stm32f4_spi_dma_tx_cb(void *data) | |
| 1057 | +{ | |
| 1058 | + struct stm32_spi *spi = data; | |
| 1059 | + | |
| 1060 | + if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) { | |
| 1061 | + spi_finalize_current_transfer(spi->master); | |
| 1062 | + stm32f4_spi_disable(spi); | |
| 1063 | + } | |
| 1064 | +} | |
| 1065 | + | |
| 1066 | +/** | |
| 1067 | + * stm32f4_spi_dma_rx_cb - dma callback | |
| 1068 | + * | |
| 1069 | + * DMA callback is called when the transfer is complete for DMA RX channel. | |
| 1070 | + */ | |
| 1071 | +static void stm32f4_spi_dma_rx_cb(void *data) | |
| 1072 | +{ | |
| 1073 | + struct stm32_spi *spi = data; | |
| 1074 | + | |
| 1075 | + spi_finalize_current_transfer(spi->master); | |
| 1076 | + stm32f4_spi_disable(spi); | |
| 1077 | +} | |
| 1078 | + | |
| 1079 | +/** | |
| 1080 | + * stm32h7_spi_dma_cb - dma callback | |
| 644 | 1081 | * |
| 645 | 1082 | * DMA callback is called when the transfer is complete or when an error |
| 646 | 1083 | * occurs. If the transfer is complete, EOT flag is raised. |
| 647 | 1084 | */ |
| 648 | −static void stm32_spi_dma_cb(void *data) | |
| 1085 | +static void stm32h7_spi_dma_cb(void *data) | |
| 649 | 1086 | { |
| 650 | 1087 | struct stm32_spi *spi = data; |
| 651 | 1088 | unsigned long flags; |
| @@ -653,11 +1090,11 @@ static void stm32_spi_dma_cb(void *data) · 1 unmodified line | ||
| 653 | 1090 | |
| 654 | 1091 | spin_lock_irqsave(&spi->lock, flags); |
| 655 | 1092 | |
| 656 | − sr = readl_relaxed(spi->base + STM32_SPI_SR); | |
| 1093 | + sr = readl_relaxed(spi->base + STM32H7_SPI_SR); | |
| 657 | 1094 | |
| 658 | 1095 | spin_unlock_irqrestore(&spi->lock, flags); |
| 659 | 1096 | |
| 660 | − if (!(sr & SPI_SR_EOT)) | |
| 1097 | + if (!(sr & STM32H7_SPI_SR_EOT)) | |
| 661 | 1098 | dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr); |
| 662 | 1099 | |
| 663 | 1100 | /* Now wait for EOT, or SUSP or OVR in case of error */ |
| @@ -681,23 +1118,27 @@ static void stm32_spi_dma_config(struct stm32_spi *spi, · 17 unmodified lines | ||
| 681 | 1118 | else |
| 682 | 1119 | buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 683 | 1120 | |
| 684 | − /* Valid for DMA Half or Full Fifo threshold */ | |
| 685 | − if (spi->cur_fthlv == 2) | |
| 1121 | + if (spi->cfg->has_fifo) { | |
| 1122 | + /* Valid for DMA Half or Full Fifo threshold */ | |
| 1123 | + if (spi->cur_fthlv == 2) | |
| 1124 | + maxburst = 1; | |
| 1125 | + else | |
| 1126 | + maxburst = spi->cur_fthlv; | |
| 1127 | + } else { | |
| 686 | 1128 | maxburst = 1; |
| 687 | − else | |
| 688 | − maxburst = spi->cur_fthlv; | |
| 1129 | + } | |
| 689 | 1130 | |
| 690 | 1131 | memset(dma_conf, 0, sizeof(struct dma_slave_config)); |
| 691 | 1132 | dma_conf->direction = dir; |
| 692 | 1133 | if (dma_conf->direction == DMA_DEV_TO_MEM) { /* RX */ |
| 693 | − dma_conf->src_addr = spi->phys_addr + STM32_SPI_RXDR; | |
| 1134 | + dma_conf->src_addr = spi->phys_addr + spi->cfg->regs->rx.reg; | |
| 694 | 1135 | dma_conf->src_addr_width = buswidth; |
| 695 | 1136 | dma_conf->src_maxburst = maxburst; |
| 696 | 1137 | |
| 697 | 1138 | dev_dbg(spi->dev, "Rx DMA config buswidth=%d, maxburst=%d\n", |
| 698 | 1139 | buswidth, maxburst); |
| 699 | 1140 | } else if (dma_conf->direction == DMA_MEM_TO_DEV) { /* TX */ |
| 700 | − dma_conf->dst_addr = spi->phys_addr + STM32_SPI_TXDR; | |
| 1141 | + dma_conf->dst_addr = spi->phys_addr + spi->cfg->regs->tx.reg; | |
| 701 | 1142 | dma_conf->dst_addr_width = buswidth; |
| 702 | 1143 | dma_conf->dst_maxburst = maxburst; |
| 703 | 1144 | |
| @@ -707,27 +1148,68 @@ static void stm32_spi_dma_config(struct stm32_spi *spi, · 3 unmodified lines | ||
| 707 | 1148 | } |
| 708 | 1149 | |
| 709 | 1150 | /** |
| 710 | − * stm32_spi_transfer_one_irq - transfer a single spi_transfer using | |
| 711 | − * interrupts | |
| 1151 | + * stm32f4_spi_transfer_one_irq - transfer a single spi_transfer using | |
| 1152 | + * interrupts | |
| 712 | 1153 | * |
| 713 | 1154 | * It must returns 0 if the transfer is finished or 1 if the transfer is still |
| 714 | 1155 | * in progress. |
| 715 | 1156 | */ |
| 716 | −static int stm32_spi_transfer_one_irq(struct stm32_spi *spi) | |
| 1157 | +static int stm32f4_spi_transfer_one_irq(struct stm32_spi *spi) | |
| 1158 | +{ | |
| 1159 | + unsigned long flags; | |
| 1160 | + u32 cr2 = 0; | |
| 1161 | + | |
| 1162 | + /* Enable the interrupts relative to the current communication mode */ | |
| 1163 | + if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) { | |
| 1164 | + cr2 |= STM32F4_SPI_CR2_TXEIE; | |
| 1165 | + } else if (spi->cur_comm == SPI_FULL_DUPLEX) { | |
| 1166 | + /* In transmit-only mode, the OVR flag is set in the SR register | |
| 1167 | + * since the received data are never read. Therefore set OVR | |
| 1168 | + * interrupt only when rx buffer is available. | |
| 1169 | + */ | |
| 1170 | + cr2 |= STM32F4_SPI_CR2_RXNEIE | STM32F4_SPI_CR2_ERRIE; | |
| 1171 | + } else { | |
| 1172 | + return -EINVAL; | |
| 1173 | + } | |
| 1174 | + | |
| 1175 | + spin_lock_irqsave(&spi->lock, flags); | |
| 1176 | + | |
| 1177 | + stm32_spi_set_bits(spi, STM32F4_SPI_CR2, cr2); | |
| 1178 | + | |
| 1179 | + stm32_spi_enable(spi); | |
| 1180 | + | |
| 1181 | + /* starting data transfer when buffer is loaded */ | |
| 1182 | + if (spi->tx_buf) | |
| 1183 | + stm32f4_spi_write_tx(spi); | |
| 1184 | + | |
| 1185 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 1186 | + | |
| 1187 | + return 1; | |
| 1188 | +} | |
| 1189 | + | |
| 1190 | +/** | |
| 1191 | + * stm32h7_spi_transfer_one_irq - transfer a single spi_transfer using | |
| 1192 | + * interrupts | |
| 1193 | + * | |
| 1194 | + * It must returns 0 if the transfer is finished or 1 if the transfer is still | |
| 1195 | + * in progress. | |
| 1196 | + */ | |
| 1197 | +static int stm32h7_spi_transfer_one_irq(struct stm32_spi *spi) | |
| 717 | 1198 | { |
| 718 | 1199 | unsigned long flags; |
| 719 | 1200 | u32 ier = 0; |
| 720 | 1201 | |
| 721 | 1202 | /* Enable the interrupts relative to the current communication mode */ |
| 722 | 1203 | if (spi->tx_buf && spi->rx_buf) /* Full Duplex */ |
| 723 | − ier |= SPI_IER_DXPIE; | |
| 1204 | + ier |= STM32H7_SPI_IER_DXPIE; | |
| 724 | 1205 | else if (spi->tx_buf) /* Half-Duplex TX dir or Simplex TX */ |
| 725 | − ier |= SPI_IER_TXPIE; | |
| 1206 | + ier |= STM32H7_SPI_IER_TXPIE; | |
| 726 | 1207 | else if (spi->rx_buf) /* Half-Duplex RX dir or Simplex RX */ |
| 727 | − ier |= SPI_IER_RXPIE; | |
| 1208 | + ier |= STM32H7_SPI_IER_RXPIE; | |
| 728 | 1209 | |
| 729 | 1210 | /* Enable the interrupts relative to the end of transfer */ |
| 730 | − ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE; | |
| 1211 | + ier |= STM32H7_SPI_IER_EOTIE | STM32H7_SPI_IER_TXTFIE | | |
| 1212 | + STM32H7_SPI_IER_OVRIE | STM32H7_SPI_IER_MODFIE; | |
| 731 | 1213 | |
| 732 | 1214 | spin_lock_irqsave(&spi->lock, flags); |
| 733 | 1215 | |
| @@ -735,17 +1217,54 @@ static int stm32_spi_transfer_one_irq(struct stm32_spi *spi) · 1 unmodified line | ||
| 735 | 1217 | |
| 736 | 1218 | /* Be sure to have data in fifo before starting data transfer */ |
| 737 | 1219 | if (spi->tx_buf) |
| 738 | − stm32_spi_write_txfifo(spi); | |
| 1220 | + stm32h7_spi_write_txfifo(spi); | |
| 739 | 1221 | |
| 740 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART); | |
| 1222 | + stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART); | |
| 741 | 1223 | |
| 742 | − writel_relaxed(ier, spi->base + STM32_SPI_IER); | |
| 1224 | + writel_relaxed(ier, spi->base + STM32H7_SPI_IER); | |
| 743 | 1225 | |
| 744 | 1226 | spin_unlock_irqrestore(&spi->lock, flags); |
| 745 | 1227 | |
| 746 | 1228 | return 1; |
| 747 | 1229 | } |
| 748 | 1230 | |
| 1231 | +/** | |
| 1232 | + * stm32f4_spi_transfer_one_dma_start - Set SPI driver registers to start | |
| 1233 | + * transfer using DMA | |
| 1234 | + */ | |
| 1235 | +static void stm32f4_spi_transfer_one_dma_start(struct stm32_spi *spi) | |
| 1236 | +{ | |
| 1237 | + /* In DMA mode end of transfer is handled by DMA TX or RX callback. */ | |
| 1238 | + if (spi->cur_comm == SPI_SIMPLEX_RX || spi->cur_comm == SPI_3WIRE_RX || | |
| 1239 | + spi->cur_comm == SPI_FULL_DUPLEX) { | |
| 1240 | + /* | |
| 1241 | + * In transmit-only mode, the OVR flag is set in the SR register | |
| 1242 | + * since the received data are never read. Therefore set OVR | |
| 1243 | + * interrupt only when rx buffer is available. | |
| 1244 | + */ | |
| 1245 | + stm32_spi_set_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_ERRIE); | |
| 1246 | + } | |
| 1247 | + | |
| 1248 | + stm32_spi_enable(spi); | |
| 1249 | +} | |
| 1250 | + | |
| 1251 | +/** | |
| 1252 | + * stm32h7_spi_transfer_one_dma_start - Set SPI driver registers to start | |
| 1253 | + * transfer using DMA | |
| 1254 | + */ | |
| 1255 | +static void stm32h7_spi_transfer_one_dma_start(struct stm32_spi *spi) | |
| 1256 | +{ | |
| 1257 | + /* Enable the interrupts relative to the end of transfer */ | |
| 1258 | + stm32_spi_set_bits(spi, STM32H7_SPI_IER, STM32H7_SPI_IER_EOTIE | | |
| 1259 | + STM32H7_SPI_IER_TXTFIE | | |
| 1260 | + STM32H7_SPI_IER_OVRIE | | |
| 1261 | + STM32H7_SPI_IER_MODFIE); | |
| 1262 | + | |
| 1263 | + stm32_spi_enable(spi); | |
| 1264 | + | |
| 1265 | + stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART); | |
| 1266 | +} | |
| 1267 | + | |
| 749 | 1268 | /** |
| 750 | 1269 | * stm32_spi_transfer_one_dma - transfer a single spi_transfer using DMA |
| 751 | 1270 | * |
| @@ -758,17 +1277,17 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 6 unmodified lines | ||
| 758 | 1277 | struct dma_slave_config tx_dma_conf, rx_dma_conf; |
| 759 | 1278 | struct dma_async_tx_descriptor *tx_dma_desc, *rx_dma_desc; |
| 760 | 1279 | unsigned long flags; |
| 761 | − u32 ier = 0; | |
| 762 | 1280 | |
| 763 | 1281 | spin_lock_irqsave(&spi->lock, flags); |
| 764 | 1282 | |
| 765 | 1283 | rx_dma_desc = NULL; |
| 766 | − if (spi->rx_buf) { | |
| 1284 | + if (spi->rx_buf && spi->dma_rx) { | |
| 767 | 1285 | stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM); |
| 768 | 1286 | dmaengine_slave_config(spi->dma_rx, &rx_dma_conf); |
| 769 | 1287 | |
| 770 | 1288 | /* Enable Rx DMA request */ |
| 771 | − stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN); | |
| 1289 | + stm32_spi_set_bits(spi, spi->cfg->regs->dma_rx_en.reg, | |
| 1290 | + spi->cfg->regs->dma_rx_en.mask); | |
| 772 | 1291 | |
| 773 | 1292 | rx_dma_desc = dmaengine_prep_slave_sg( |
| 774 | 1293 | spi->dma_rx, xfer->rx_sg.sgl, |
| @@ -778,7 +1297,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 3 unmodified lines | ||
| 778 | 1297 | } |
| 779 | 1298 | |
| 780 | 1299 | tx_dma_desc = NULL; |
| 781 | − if (spi->tx_buf) { | |
| 1300 | + if (spi->tx_buf && spi->dma_tx) { | |
| 782 | 1301 | stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV); |
| 783 | 1302 | dmaengine_slave_config(spi->dma_tx, &tx_dma_conf); |
| 784 | 1303 | |
| @@ -789,12 +1308,15 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 4 unmodified lines | ||
| 789 | 1308 | DMA_PREP_INTERRUPT); |
| 790 | 1309 | } |
| 791 | 1310 | |
| 792 | − if ((spi->tx_buf && !tx_dma_desc) || | |
| 793 | − (spi->rx_buf && !rx_dma_desc)) | |
| 1311 | + if ((spi->tx_buf && spi->dma_tx && !tx_dma_desc) || | |
| 1312 | + (spi->rx_buf && spi->dma_rx && !rx_dma_desc)) | |
| 1313 | + goto dma_desc_error; | |
| 1314 | + | |
| 1315 | + if (spi->cur_comm == SPI_FULL_DUPLEX && (!tx_dma_desc || !rx_dma_desc)) | |
| 794 | 1316 | goto dma_desc_error; |
| 795 | 1317 | |
| 796 | 1318 | if (rx_dma_desc) { |
| 797 | − rx_dma_desc->callback = stm32_spi_dma_cb; | |
| 1319 | + rx_dma_desc->callback = spi->cfg->dma_rx_cb; | |
| 798 | 1320 | rx_dma_desc->callback_param = spi; |
| 799 | 1321 | |
| 800 | 1322 | if (dma_submit_error(dmaengine_submit(rx_dma_desc))) { |
| @@ -806,8 +1328,9 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 5 unmodified lines | ||
| 806 | 1328 | } |
| 807 | 1329 | |
| 808 | 1330 | if (tx_dma_desc) { |
| 809 | − if (spi->cur_comm == SPI_SIMPLEX_TX) { | |
| 810 | − tx_dma_desc->callback = stm32_spi_dma_cb; | |
| 1331 | + if (spi->cur_comm == SPI_SIMPLEX_TX || | |
| 1332 | + spi->cur_comm == SPI_3WIRE_TX) { | |
| 1333 | + tx_dma_desc->callback = spi->cfg->dma_tx_cb; | |
| 811 | 1334 | tx_dma_desc->callback_param = spi; |
| 812 | 1335 | } |
| 813 | 1336 | |
| @@ -819,130 +1342,278 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 5 unmodified lines | ||
| 819 | 1342 | dma_async_issue_pending(spi->dma_tx); |
| 820 | 1343 | |
| 821 | 1344 | /* Enable Tx DMA request */ |
| 822 | − stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN); | |
| 1345 | + stm32_spi_set_bits(spi, spi->cfg->regs->dma_tx_en.reg, | |
| 1346 | + spi->cfg->regs->dma_tx_en.mask); | |
| 823 | 1347 | } |
| 824 | 1348 | |
| 825 | − /* Enable the interrupts relative to the end of transfer */ | |
| 826 | − ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE; | |
| 827 | − writel_relaxed(ier, spi->base + STM32_SPI_IER); | |
| 828 | − | |
| 829 | − stm32_spi_enable(spi); | |
| 830 | − | |
| 831 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART); | |
| 1349 | + spi->cfg->transfer_one_dma_start(spi); | |
| 832 | 1350 | |
| 833 | 1351 | spin_unlock_irqrestore(&spi->lock, flags); |
| 834 | 1352 | |
| 835 | 1353 | return 1; |
| 836 | 1354 | |
| 837 | 1355 | dma_submit_error: |
| 838 | − if (spi->rx_buf) | |
| 1356 | + if (spi->dma_rx) | |
| 839 | 1357 | dmaengine_terminate_all(spi->dma_rx); |
| 840 | 1358 | |
| 841 | 1359 | dma_desc_error: |
| 842 | − stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN); | |
| 1360 | + stm32_spi_clr_bits(spi, spi->cfg->regs->dma_rx_en.reg, | |
| 1361 | + spi->cfg->regs->dma_rx_en.mask); | |
| 843 | 1362 | |
| 844 | 1363 | spin_unlock_irqrestore(&spi->lock, flags); |
| 845 | 1364 | |
| 846 | 1365 | dev_info(spi->dev, "DMA issue: fall back to irq transfer\n"); |
| 847 | 1366 | |
| 848 | − return stm32_spi_transfer_one_irq(spi); | |
| 1367 | + spi->cur_usedma = false; | |
| 1368 | + return spi->cfg->transfer_one_irq(spi); | |
| 849 | 1369 | } |
| 850 | 1370 | |
| 851 | 1371 | /** |
| 852 | − * stm32_spi_transfer_one_setup - common setup to transfer a single | |
| 853 | − * spi_transfer either using DMA or | |
| 854 | − * interrupts. | |
| 1372 | + * stm32f4_spi_set_bpw - Configure bits per word | |
| 1373 | + * @spi: pointer to the spi controller data structure | |
| 855 | 1374 | */ |
| 856 | −static int stm32_spi_transfer_one_setup(struct stm32_spi *spi, | |
| 857 | − struct spi_device *spi_dev, | |
| 858 | − struct spi_transfer *transfer) | |
| 1375 | +static void stm32f4_spi_set_bpw(struct stm32_spi *spi) | |
| 859 | 1376 | { |
| 860 | − unsigned long flags; | |
| 861 | − u32 cfg1_clrb = 0, cfg1_setb = 0, cfg2_clrb = 0, cfg2_setb = 0; | |
| 862 | − u32 mode, nb_words; | |
| 863 | − int ret = 0; | |
| 864 | − | |
| 865 | − spin_lock_irqsave(&spi->lock, flags); | |
| 1377 | + if (spi->cur_bpw == 16) | |
| 1378 | + stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF); | |
| 1379 | + else | |
| 1380 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF); | |
| 1381 | +} | |
| 866 | 1382 | |
| 867 | − if (spi->cur_bpw != transfer->bits_per_word) { | |
| 868 | − u32 bpw, fthlv; | |
| 1383 | +/** | |
| 1384 | + * stm32h7_spi_set_bpw - configure bits per word | |
| 1385 | + * @spi: pointer to the spi controller data structure | |
| 1386 | + */ | |
| 1387 | +static void stm32h7_spi_set_bpw(struct stm32_spi *spi) | |
| 1388 | +{ | |
| 1389 | + u32 bpw, fthlv; | |
| 1390 | + u32 cfg1_clrb = 0, cfg1_setb = 0; | |
| 869 | 1391 | |
| 870 | − spi->cur_bpw = transfer->bits_per_word; | |
| 871 | − bpw = spi->cur_bpw - 1; | |
| 1392 | + bpw = spi->cur_bpw - 1; | |
| 872 | 1393 | |
| 873 | − cfg1_clrb |= SPI_CFG1_DSIZE; | |
| 874 | − cfg1_setb |= (bpw << SPI_CFG1_DSIZE_SHIFT) & SPI_CFG1_DSIZE; | |
| 1394 | + cfg1_clrb |= STM32H7_SPI_CFG1_DSIZE; | |
| 1395 | + cfg1_setb |= (bpw << STM32H7_SPI_CFG1_DSIZE_SHIFT) & | |
| 1396 | + STM32H7_SPI_CFG1_DSIZE; | |
| 875 | 1397 | |
| 876 | − spi->cur_fthlv = stm32_spi_prepare_fthlv(spi); | |
| 877 | − fthlv = spi->cur_fthlv - 1; | |
| 1398 | + spi->cur_fthlv = stm32h7_spi_prepare_fthlv(spi); | |
| 1399 | + fthlv = spi->cur_fthlv - 1; | |
| 878 | 1400 | |
| 879 | − cfg1_clrb |= SPI_CFG1_FTHLV; | |
| 880 | − cfg1_setb |= (fthlv << SPI_CFG1_FTHLV_SHIFT) & SPI_CFG1_FTHLV; | |
| 881 | − } | |
| 1401 | + cfg1_clrb |= STM32H7_SPI_CFG1_FTHLV; | |
| 1402 | + cfg1_setb |= (fthlv << STM32H7_SPI_CFG1_FTHLV_SHIFT) & | |
| 1403 | + STM32H7_SPI_CFG1_FTHLV; | |
| 882 | 1404 | |
| 883 | − if (spi->cur_speed != transfer->speed_hz) { | |
| 884 | − int mbr; | |
| 1405 | + writel_relaxed( | |
| 1406 | + (readl_relaxed(spi->base + STM32H7_SPI_CFG1) & | |
| 1407 | + ~cfg1_clrb) | cfg1_setb, | |
| 1408 | + spi->base + STM32H7_SPI_CFG1); | |
| 1409 | +} | |
| 885 | 1410 | |
| 886 | − /* Update spi->cur_speed with real clock speed */ | |
| 887 | − mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz); | |
| 888 | − if (mbr < 0) { | |
| 889 | − ret = mbr; | |
| 890 | − goto out; | |
| 891 | − } | |
| 1411 | +/** | |
| 1412 | + * stm32_spi_set_mbr - Configure baud rate divisor in master mode | |
| 1413 | + * @spi: pointer to the spi controller data structure | |
| 1414 | + * @mbrdiv: baud rate divisor value | |
| 1415 | + */ | |
| 1416 | +static void stm32_spi_set_mbr(struct stm32_spi *spi, u32 mbrdiv) | |
| 1417 | +{ | |
| 1418 | + u32 clrb = 0, setb = 0; | |
| 892 | 1419 | |
| 893 | − transfer->speed_hz = spi->cur_speed; | |
| 1420 | + clrb |= spi->cfg->regs->br.mask; | |
| 1421 | + setb |= ((u32)mbrdiv << spi->cfg->regs->br.shift) & | |
| 1422 | + spi->cfg->regs->br.mask; | |
| 894 | 1423 | |
| 895 | − cfg1_clrb |= SPI_CFG1_MBR; | |
| 896 | − cfg1_setb |= ((u32)mbr << SPI_CFG1_MBR_SHIFT) & SPI_CFG1_MBR; | |
| 897 | − } | |
| 1424 | + writel_relaxed((readl_relaxed(spi->base + spi->cfg->regs->br.reg) & | |
| 1425 | + ~clrb) | setb, | |
| 1426 | + spi->base + spi->cfg->regs->br.reg); | |
| 1427 | +} | |
| 898 | 1428 | |
| 899 | − if (cfg1_clrb || cfg1_setb) | |
| 900 | − writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG1) & | |
| 901 | − ~cfg1_clrb) | cfg1_setb, | |
| 902 | − spi->base + STM32_SPI_CFG1); | |
| 1429 | +/** | |
| 1430 | + * stm32_spi_communication_type - return transfer communication type | |
| 1431 | + * @spi_dev: pointer to the spi device | |
| 1432 | + * transfer: pointer to spi transfer | |
| 1433 | + */ | |
| 1434 | +static unsigned int stm32_spi_communication_type(struct spi_device *spi_dev, | |
| 1435 | + struct spi_transfer *transfer) | |
| 1436 | +{ | |
| 1437 | + unsigned int type = SPI_FULL_DUPLEX; | |
| 903 | 1438 | |
| 904 | − mode = SPI_FULL_DUPLEX; | |
| 905 | 1439 | if (spi_dev->mode & SPI_3WIRE) { /* MISO/MOSI signals shared */ |
| 906 | 1440 | /* |
| 907 | 1441 | * SPI_3WIRE and xfer->tx_buf != NULL and xfer->rx_buf != NULL |
| 908 | − * is forbidden und unvalidated by SPI subsystem so depending | |
| 1442 | + * is forbidden and unvalidated by SPI subsystem so depending | |
| 909 | 1443 | * on the valid buffer, we can determine the direction of the |
| 910 | 1444 | * transfer. |
| 911 | 1445 | */ |
| 912 | − mode = SPI_HALF_DUPLEX; | |
| 913 | 1446 | if (!transfer->tx_buf) |
| 914 | − stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR); | |
| 915 | − else if (!transfer->rx_buf) | |
| 916 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR); | |
| 1447 | + type = SPI_3WIRE_RX; | |
| 1448 | + else | |
| 1449 | + type = SPI_3WIRE_TX; | |
| 917 | 1450 | } else { |
| 918 | 1451 | if (!transfer->tx_buf) |
| 919 | − mode = SPI_SIMPLEX_RX; | |
| 1452 | + type = SPI_SIMPLEX_RX; | |
| 920 | 1453 | else if (!transfer->rx_buf) |
| 921 | − mode = SPI_SIMPLEX_TX; | |
| 1454 | + type = SPI_SIMPLEX_TX; | |
| 1455 | + } | |
| 1456 | + | |
| 1457 | + return type; | |
| 1458 | +} | |
| 1459 | + | |
| 1460 | +/** | |
| 1461 | + * stm32f4_spi_set_mode - configure communication mode | |
| 1462 | + * @spi: pointer to the spi controller data structure | |
| 1463 | + * @comm_type: type of communication to configure | |
| 1464 | + */ | |
| 1465 | +static int stm32f4_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type) | |
| 1466 | +{ | |
| 1467 | + if (comm_type == SPI_3WIRE_TX || comm_type == SPI_SIMPLEX_TX) { | |
| 1468 | + stm32_spi_set_bits(spi, STM32F4_SPI_CR1, | |
| 1469 | + STM32F4_SPI_CR1_BIDIMODE | | |
| 1470 | + STM32F4_SPI_CR1_BIDIOE); | |
| 1471 | + } else if (comm_type == SPI_FULL_DUPLEX) { | |
| 1472 | + stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, | |
| 1473 | + STM32F4_SPI_CR1_BIDIMODE | | |
| 1474 | + STM32F4_SPI_CR1_BIDIOE); | |
| 1475 | + } else { | |
| 1476 | + return -EINVAL; | |
| 922 | 1477 | } |
| 923 | − if (spi->cur_comm != mode) { | |
| 924 | − spi->cur_comm = mode; | |
| 925 | 1478 | |
| 926 | − cfg2_clrb |= SPI_CFG2_COMM; | |
| 927 | − cfg2_setb |= (mode << SPI_CFG2_COMM_SHIFT) & SPI_CFG2_COMM; | |
| 1479 | + return 0; | |
| 1480 | +} | |
| 1481 | + | |
| 1482 | +/** | |
| 1483 | + * stm32h7_spi_set_mode - configure communication mode | |
| 1484 | + * @spi: pointer to the spi controller data structure | |
| 1485 | + * @comm_type: type of communication to configure | |
| 1486 | + */ | |
| 1487 | +static int stm32h7_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type) | |
| 1488 | +{ | |
| 1489 | + u32 mode; | |
| 1490 | + u32 cfg2_clrb = 0, cfg2_setb = 0; | |
| 1491 | + | |
| 1492 | + if (comm_type == SPI_3WIRE_RX) { | |
| 1493 | + mode = STM32H7_SPI_HALF_DUPLEX; | |
| 1494 | + stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR); | |
| 1495 | + } else if (comm_type == SPI_3WIRE_TX) { | |
| 1496 | + mode = STM32H7_SPI_HALF_DUPLEX; | |
| 1497 | + stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR); | |
| 1498 | + } else if (comm_type == SPI_SIMPLEX_RX) { | |
| 1499 | + mode = STM32H7_SPI_SIMPLEX_RX; | |
| 1500 | + } else if (comm_type == SPI_SIMPLEX_TX) { | |
| 1501 | + mode = STM32H7_SPI_SIMPLEX_TX; | |
| 1502 | + } else { | |
| 1503 | + mode = STM32H7_SPI_FULL_DUPLEX; | |
| 928 | 1504 | } |
| 929 | 1505 | |
| 930 | − cfg2_clrb |= SPI_CFG2_MIDI; | |
| 931 | − if ((transfer->len > 1) && (spi->cur_midi > 0)) { | |
| 1506 | + cfg2_clrb |= STM32H7_SPI_CFG2_COMM; | |
| 1507 | + cfg2_setb |= (mode << STM32H7_SPI_CFG2_COMM_SHIFT) & | |
| 1508 | + STM32H7_SPI_CFG2_COMM; | |
| 1509 | + | |
| 1510 | + writel_relaxed( | |
| 1511 | + (readl_relaxed(spi->base + STM32H7_SPI_CFG2) & | |
| 1512 | + ~cfg2_clrb) | cfg2_setb, | |
| 1513 | + spi->base + STM32H7_SPI_CFG2); | |
| 1514 | + | |
| 1515 | + return 0; | |
| 1516 | +} | |
| 1517 | + | |
| 1518 | +/** | |
| 1519 | + * stm32h7_spi_data_idleness - configure minimum time delay inserted between two | |
| 1520 | + * consecutive data frames in master mode | |
| 1521 | + * @spi: pointer to the spi controller data structure | |
| 1522 | + * @len: transfer len | |
| 1523 | + */ | |
| 1524 | +static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len) | |
| 1525 | +{ | |
| 1526 | + u32 cfg2_clrb = 0, cfg2_setb = 0; | |
| 1527 | + | |
| 1528 | + cfg2_clrb |= STM32H7_SPI_CFG2_MIDI; | |
| 1529 | + if ((len > 1) && (spi->cur_midi > 0)) { | |
| 932 | 1530 | u32 sck_period_ns = DIV_ROUND_UP(SPI_1HZ_NS, spi->cur_speed); |
| 933 | 1531 | u32 midi = min((u32)DIV_ROUND_UP(spi->cur_midi, sck_period_ns), |
| 934 | − (u32)SPI_CFG2_MIDI >> SPI_CFG2_MIDI_SHIFT); | |
| 1532 | + (u32)STM32H7_SPI_CFG2_MIDI >> | |
| 1533 | + STM32H7_SPI_CFG2_MIDI_SHIFT); | |
| 935 | 1534 | |
| 936 | 1535 | dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n", |
| 937 | 1536 | sck_period_ns, midi, midi * sck_period_ns); |
| 1537 | + cfg2_setb |= (midi << STM32H7_SPI_CFG2_MIDI_SHIFT) & | |
| 1538 | + STM32H7_SPI_CFG2_MIDI; | |
| 1539 | + } | |
| 1540 | + | |
| 1541 | + writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CFG2) & | |
| 1542 | + ~cfg2_clrb) | cfg2_setb, | |
| 1543 | + spi->base + STM32H7_SPI_CFG2); | |
| 1544 | +} | |
| 1545 | + | |
| 1546 | +/** | |
| 1547 | + * stm32h7_spi_number_of_data - configure number of data at current transfer | |
| 1548 | + * @spi: pointer to the spi controller data structure | |
| 1549 | + * @len: transfer length | |
| 1550 | + */ | |
| 1551 | +static int stm32h7_spi_number_of_data(struct stm32_spi *spi, u32 nb_words) | |
| 1552 | +{ | |
| 1553 | + u32 cr2_clrb = 0, cr2_setb = 0; | |
| 1554 | + | |
| 1555 | + if (nb_words <= (STM32H7_SPI_CR2_TSIZE >> | |
| 1556 | + STM32H7_SPI_CR2_TSIZE_SHIFT)) { | |
| 1557 | + cr2_clrb |= STM32H7_SPI_CR2_TSIZE; | |
| 1558 | + cr2_setb = nb_words << STM32H7_SPI_CR2_TSIZE_SHIFT; | |
| 1559 | + writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CR2) & | |
| 1560 | + ~cr2_clrb) | cr2_setb, | |
| 1561 | + spi->base + STM32H7_SPI_CR2); | |
| 1562 | + } else { | |
| 1563 | + return -EMSGSIZE; | |
| 1564 | + } | |
| 1565 | + | |
| 1566 | + return 0; | |
| 1567 | +} | |
| 1568 | + | |
| 1569 | +/** | |
| 1570 | + * stm32_spi_transfer_one_setup - common setup to transfer a single | |
| 1571 | + * spi_transfer either using DMA or | |
| 1572 | + * interrupts. | |
| 1573 | + */ | |
| 1574 | +static int stm32_spi_transfer_one_setup(struct stm32_spi *spi, | |
| 1575 | + struct spi_device *spi_dev, | |
| 1576 | + struct spi_transfer *transfer) | |
| 1577 | +{ | |
| 1578 | + unsigned long flags; | |
| 1579 | + unsigned int comm_type; | |
| 1580 | + int nb_words, ret = 0; | |
| 1581 | + | |
| 1582 | + spin_lock_irqsave(&spi->lock, flags); | |
| 1583 | + | |
| 1584 | + if (spi->cur_bpw != transfer->bits_per_word) { | |
| 1585 | + spi->cur_bpw = transfer->bits_per_word; | |
| 1586 | + spi->cfg->set_bpw(spi); | |
| 1587 | + } | |
| 938 | 1588 | |
| 939 | − cfg2_setb |= (midi << SPI_CFG2_MIDI_SHIFT) & SPI_CFG2_MIDI; | |
| 1589 | + if (spi->cur_speed != transfer->speed_hz) { | |
| 1590 | + int mbr; | |
| 1591 | + | |
| 1592 | + /* Update spi->cur_speed with real clock speed */ | |
| 1593 | + mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz, | |
| 1594 | + spi->cfg->baud_rate_div_min, | |
| 1595 | + spi->cfg->baud_rate_div_max); | |
| 1596 | + if (mbr < 0) { | |
| 1597 | + ret = mbr; | |
| 1598 | + goto out; | |
| 1599 | + } | |
| 1600 | + | |
| 1601 | + transfer->speed_hz = spi->cur_speed; | |
| 1602 | + stm32_spi_set_mbr(spi, mbr); | |
| 940 | 1603 | } |
| 941 | 1604 | |
| 942 | − if (cfg2_clrb || cfg2_setb) | |
| 943 | − writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG2) & | |
| 944 | − ~cfg2_clrb) | cfg2_setb, | |
| 945 | − spi->base + STM32_SPI_CFG2); | |
| 1605 | + comm_type = stm32_spi_communication_type(spi_dev, transfer); | |
| 1606 | + if (spi->cur_comm != comm_type) { | |
| 1607 | + ret = spi->cfg->set_mode(spi, comm_type); | |
| 1608 | + | |
| 1609 | + if (ret < 0) | |
| 1610 | + goto out; | |
| 1611 | + | |
| 1612 | + spi->cur_comm = comm_type; | |
| 1613 | + } | |
| 1614 | + | |
| 1615 | + if (spi->cfg->set_data_idleness) | |
| 1616 | + spi->cfg->set_data_idleness(spi, transfer->len); | |
| 946 | 1617 | |
| 947 | 1618 | if (spi->cur_bpw <= 8) |
| 948 | 1619 | nb_words = transfer->len; |
| @@ -950,13 +1621,11 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi, · 1 unmodified line | ||
| 950 | 1621 | nb_words = DIV_ROUND_UP(transfer->len * 8, 16); |
| 951 | 1622 | else |
| 952 | 1623 | nb_words = DIV_ROUND_UP(transfer->len * 8, 32); |
| 953 | − nb_words <<= SPI_CR2_TSIZE_SHIFT; | |
| 954 | 1624 | |
| 955 | − if (nb_words <= SPI_CR2_TSIZE) { | |
| 956 | − writel_relaxed(nb_words, spi->base + STM32_SPI_CR2); | |
| 957 | − } else { | |
| 958 | − ret = -EMSGSIZE; | |
| 959 | − goto out; | |
| 1625 | + if (spi->cfg->set_number_of_data) { | |
| 1626 | + ret = spi->cfg->set_number_of_data(spi, nb_words); | |
| 1627 | + if (ret < 0) | |
| 1628 | + goto out; | |
| 960 | 1629 | } |
| 961 | 1630 | |
| 962 | 1631 | spi->cur_xferlen = transfer->len; |
| @@ -997,7 +1666,7 @@ static int stm32_spi_transfer_one(struct spi_master *master, · 34 unmodified lines | ||
| 997 | 1666 | spi->rx_len = spi->rx_buf ? transfer->len : 0; |
| 998 | 1667 | |
| 999 | 1668 | spi->cur_usedma = (master->can_dma && |
| 1000 | − stm32_spi_can_dma(master, spi_dev, transfer)); | |
| 1669 | + master->can_dma(master, spi_dev, transfer)); | |
| 1001 | 1670 | |
| 1002 | 1671 | ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer); |
| 1003 | 1672 | if (ret) { |
| @@ -1008,47 +1677,73 @@ static int stm32_spi_transfer_one(struct spi_master *master, · 4 unmodified lines | ||
| 1008 | 1677 | if (spi->cur_usedma) |
| 1009 | 1678 | return stm32_spi_transfer_one_dma(spi, transfer); |
| 1010 | 1679 | else |
| 1011 | − return stm32_spi_transfer_one_irq(spi); | |
| 1680 | + return spi->cfg->transfer_one_irq(spi); | |
| 1012 | 1681 | } |
| 1013 | 1682 | |
| 1014 | 1683 | /** |
| 1015 | 1684 | * stm32_spi_unprepare_msg - relax the hardware |
| 1016 | − * | |
| 1017 | − * Normally, if TSIZE has been configured, we should relax the hardware at the | |
| 1018 | − * reception of the EOT interrupt. But in case of error, EOT will not be | |
| 1019 | − * raised. So the subsystem unprepare_message call allows us to properly | |
| 1020 | − * complete the transfer from an hardware point of view. | |
| 1021 | 1685 | */ |
| 1022 | 1686 | static int stm32_spi_unprepare_msg(struct spi_master *master, |
| 1023 | 1687 | struct spi_message *msg) |
| 1024 | 1688 | { |
| 1025 | 1689 | struct stm32_spi *spi = spi_master_get_devdata(master); |
| 1026 | 1690 | |
| 1027 | − stm32_spi_disable(spi); | |
| 1691 | + spi->cfg->disable(spi); | |
| 1692 | + | |
| 1693 | + return 0; | |
| 1694 | +} | |
| 1695 | + | |
| 1696 | +/** | |
| 1697 | + * stm32f4_spi_config - Configure SPI controller as SPI master | |
| 1698 | + */ | |
| 1699 | +static int stm32f4_spi_config(struct stm32_spi *spi) | |
| 1700 | +{ | |
| 1701 | + unsigned long flags; | |
| 1702 | + | |
| 1703 | + spin_lock_irqsave(&spi->lock, flags); | |
| 1704 | + | |
| 1705 | + /* Ensure I2SMOD bit is kept cleared */ | |
| 1706 | + stm32_spi_clr_bits(spi, STM32F4_SPI_I2SCFGR, | |
| 1707 | + STM32F4_SPI_I2SCFGR_I2SMOD); | |
| 1708 | + | |
| 1709 | + /* | |
| 1710 | + * - SS input value high | |
| 1711 | + * - transmitter half duplex direction | |
| 1712 | + * - Set the master mode (default Motorola mode) | |
| 1713 | + * - Consider 1 master/n slaves configuration and | |
| 1714 | + * SS input value is determined by the SSI bit | |
| 1715 | + */ | |
| 1716 | + stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SSI | | |
| 1717 | + STM32F4_SPI_CR1_BIDIOE | | |
| 1718 | + STM32F4_SPI_CR1_MSTR | | |
| 1719 | + STM32F4_SPI_CR1_SSM); | |
| 1720 | + | |
| 1721 | + spin_unlock_irqrestore(&spi->lock, flags); | |
| 1028 | 1722 | |
| 1029 | 1723 | return 0; |
| 1030 | 1724 | } |
| 1031 | 1725 | |
| 1032 | 1726 | /** |
| 1033 | − * stm32_spi_config - Configure SPI controller as SPI master | |
| 1727 | + * stm32h7_spi_config - Configure SPI controller as SPI master | |
| 1034 | 1728 | */ |
| 1035 | −static int stm32_spi_config(struct stm32_spi *spi) | |
| 1729 | +static int stm32h7_spi_config(struct stm32_spi *spi) | |
| 1036 | 1730 | { |
| 1037 | 1731 | unsigned long flags; |
| 1038 | 1732 | |
| 1039 | 1733 | spin_lock_irqsave(&spi->lock, flags); |
| 1040 | 1734 | |
| 1041 | 1735 | /* Ensure I2SMOD bit is kept cleared */ |
| 1042 | − stm32_spi_clr_bits(spi, STM32_SPI_I2SCFGR, SPI_I2SCFGR_I2SMOD); | |
| 1736 | + stm32_spi_clr_bits(spi, STM32H7_SPI_I2SCFGR, | |
| 1737 | + STM32H7_SPI_I2SCFGR_I2SMOD); | |
| 1043 | 1738 | |
| 1044 | 1739 | /* |
| 1045 | 1740 | * - SS input value high |
| 1046 | 1741 | * - transmitter half duplex direction |
| 1047 | 1742 | * - automatic communication suspend when RX-Fifo is full |
| 1048 | 1743 | */ |
| 1049 | − stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SSI | | |
| 1050 | − SPI_CR1_HDDIR | | |
| 1051 | − SPI_CR1_MASRX); | |
| 1744 | + stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SSI | | |
| 1745 | + STM32H7_SPI_CR1_HDDIR | | |
| 1746 | + STM32H7_SPI_CR1_MASRX); | |
| 1052 | 1747 | |
| 1053 | 1748 | /* |
| 1054 | 1749 | * - Set the master mode (default Motorola mode) |
| @@ -1056,17 +1751,56 @@ static int stm32_spi_config(struct stm32_spi *spi) · 1 unmodified line | ||
| 1056 | 1751 | * SS input value is determined by the SSI bit |
| 1057 | 1752 | * - keep control of all associated GPIOs |
| 1058 | 1753 | */ |
| 1059 | − stm32_spi_set_bits(spi, STM32_SPI_CFG2, SPI_CFG2_MASTER | | |
| 1060 | − SPI_CFG2_SSM | | |
| 1061 | − SPI_CFG2_AFCNTR); | |
| 1754 | + stm32_spi_set_bits(spi, STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_MASTER | | |
| 1755 | + STM32H7_SPI_CFG2_SSM | | |
| 1756 | + STM32H7_SPI_CFG2_AFCNTR); | |
| 1062 | 1757 | |
| 1063 | 1758 | spin_unlock_irqrestore(&spi->lock, flags); |
| 1064 | 1759 | |
| 1065 | 1760 | return 0; |
| 1066 | 1761 | } |
| 1067 | 1762 | |
| 1763 | +static const struct stm32_spi_cfg stm32f4_spi_cfg = { | |
| 1764 | + .regs = &stm32f4_spi_regspec, | |
| 1765 | + .get_bpw_mask = stm32f4_spi_get_bpw_mask, | |
| 1766 | + .disable = stm32f4_spi_disable, | |
| 1767 | + .config = stm32f4_spi_config, | |
| 1768 | + .set_bpw = stm32f4_spi_set_bpw, | |
| 1769 | + .set_mode = stm32f4_spi_set_mode, | |
| 1770 | + .transfer_one_dma_start = stm32f4_spi_transfer_one_dma_start, | |
| 1771 | + .dma_tx_cb = stm32f4_spi_dma_tx_cb, | |
| 1772 | + .dma_rx_cb = stm32f4_spi_dma_rx_cb, | |
| 1773 | + .transfer_one_irq = stm32f4_spi_transfer_one_irq, | |
| 1774 | + .irq_handler_event = stm32f4_spi_irq_event, | |
| 1775 | + .irq_handler_thread = stm32f4_spi_irq_thread, | |
| 1776 | + .baud_rate_div_min = STM32F4_SPI_BR_DIV_MIN, | |
| 1777 | + .baud_rate_div_max = STM32F4_SPI_BR_DIV_MAX, | |
| 1778 | + .has_fifo = false, | |
| 1779 | +}; | |
| 1780 | + | |
| 1781 | +static const struct stm32_spi_cfg stm32h7_spi_cfg = { | |
| 1782 | + .regs = &stm32h7_spi_regspec, | |
| 1783 | + .get_fifo_size = stm32h7_spi_get_fifo_size, | |
| 1784 | + .get_bpw_mask = stm32h7_spi_get_bpw_mask, | |
| 1785 | + .disable = stm32h7_spi_disable, | |
| 1786 | + .config = stm32h7_spi_config, | |
| 1787 | + .set_bpw = stm32h7_spi_set_bpw, | |
| 1788 | + .set_mode = stm32h7_spi_set_mode, | |
| 1789 | + .set_data_idleness = stm32h7_spi_data_idleness, | |
| 1790 | + .set_number_of_data = stm32h7_spi_number_of_data, | |
| 1791 | + .transfer_one_dma_start = stm32h7_spi_transfer_one_dma_start, | |
| 1792 | + .dma_rx_cb = stm32h7_spi_dma_cb, | |
| 1793 | + .dma_tx_cb = stm32h7_spi_dma_cb, | |
| 1794 | + .transfer_one_irq = stm32h7_spi_transfer_one_irq, | |
| 1795 | + .irq_handler_thread = stm32h7_spi_irq_thread, | |
| 1796 | + .baud_rate_div_min = STM32H7_SPI_MBR_DIV_MIN, | |
| 1797 | + .baud_rate_div_max = STM32H7_SPI_MBR_DIV_MAX, | |
| 1798 | + .has_fifo = true, | |
| 1799 | +}; | |
| 1800 | + | |
| 1068 | 1801 | static const struct of_device_id stm32_spi_of_match[] = { |
| 1069 | − { .compatible = "st,stm32h7-spi", }, | |
| 1802 | + { .compatible = "st,stm32h7-spi", .data = (void *)&stm32h7_spi_cfg }, | |
| 1803 | + { .compatible = "st,stm32f4-spi", .data = (void *)&stm32f4_spi_cfg }, | |
| 1070 | 1804 | {}, |
| 1071 | 1805 | }; |
| 1072 | 1806 | MODULE_DEVICE_TABLE(of, stm32_spi_of_match); |
| @@ -1090,12 +1824,17 @@ static int stm32_spi_probe(struct platform_device *pdev) · 17 unmodified lines | ||
| 1090 | 1824 | spi->master = master; |
| 1091 | 1825 | spin_lock_init(&spi->lock); |
| 1092 | 1826 | |
| 1827 | + spi->cfg = (const struct stm32_spi_cfg *) | |
| 1828 | + of_match_device(pdev->dev.driver->of_match_table, | |
| 1829 | + &pdev->dev)->data; | |
| 1830 | + | |
| 1093 | 1831 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1094 | 1832 | spi->base = devm_ioremap_resource(&pdev->dev, res); |
| 1095 | 1833 | if (IS_ERR(spi->base)) { |
| 1096 | 1834 | ret = PTR_ERR(spi->base); |
| 1097 | 1835 | goto err_master_put; |
| 1098 | 1836 | } |
| 1837 | + | |
| 1099 | 1838 | spi->phys_addr = (dma_addr_t)res->start; |
| 1100 | 1839 | |
| 1101 | 1840 | spi->irq = platform_get_irq(pdev, 0); |
| @@ -1104,16 +1843,17 @@ static int stm32_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1104 | 1843 | ret = -ENOENT; |
| 1105 | 1844 | goto err_master_put; |
| 1106 | 1845 | } |
| 1107 | − ret = devm_request_threaded_irq(&pdev->dev, spi->irq, NULL, | |
| 1108 | − stm32_spi_irq, IRQF_ONESHOT, | |
| 1109 | − pdev->name, master); | |
| 1846 | + ret = devm_request_threaded_irq(&pdev->dev, spi->irq, | |
| 1847 | + spi->cfg->irq_handler_event, | |
| 1848 | + spi->cfg->irq_handler_thread, | |
| 1849 | + IRQF_ONESHOT, pdev->name, master); | |
| 1110 | 1850 | if (ret) { |
| 1111 | 1851 | dev_err(&pdev->dev, "irq%d request failed: %d\n", spi->irq, |
| 1112 | 1852 | ret); |
| 1113 | 1853 | goto err_master_put; |
| 1114 | 1854 | } |
| 1115 | 1855 | |
| 1116 | − spi->clk = devm_clk_get(&pdev->dev, 0); | |
| 1856 | + spi->clk = devm_clk_get(&pdev->dev, NULL); | |
| 1117 | 1857 | if (IS_ERR(spi->clk)) { |
| 1118 | 1858 | ret = PTR_ERR(spi->clk); |
| 1119 | 1859 | dev_err(&pdev->dev, "clk get failed: %d\n", ret); |
| @@ -1139,9 +1879,10 @@ static int stm32_spi_probe(struct platform_device *pdev) · 19 unmodified lines | ||
| 1139 | 1879 | reset_control_deassert(spi->rst); |
| 1140 | 1880 | } |
| 1141 | 1881 | |
| 1142 | − spi->fifo_size = stm32_spi_get_fifo_size(spi); | |
| 1882 | + if (spi->cfg->has_fifo) | |
| 1883 | + spi->fifo_size = spi->cfg->get_fifo_size(spi); | |
| 1143 | 1884 | |
| 1144 | − ret = stm32_spi_config(spi); | |
| 1885 | + ret = spi->cfg->config(spi); | |
| 1145 | 1886 | if (ret) { |
| 1146 | 1887 | dev_err(&pdev->dev, "controller configuration failed: %d\n", |
| 1147 | 1888 | ret); |
| @@ -1151,11 +1892,11 @@ static int stm32_spi_probe(struct platform_device *pdev) · 3 unmodified lines | ||
| 1151 | 1892 | master->dev.of_node = pdev->dev.of_node; |
| 1152 | 1893 | master->auto_runtime_pm = true; |
| 1153 | 1894 | master->bus_num = pdev->id; |
| 1154 | − master->mode_bits = SPI_MODE_3 | SPI_CS_HIGH | SPI_LSB_FIRST | | |
| 1155 | − SPI_3WIRE | SPI_LOOP; | |
| 1156 | − master->bits_per_word_mask = stm32_spi_get_bpw_mask(spi); | |
| 1157 | − master->max_speed_hz = spi->clk_rate / SPI_MBR_DIV_MIN; | |
| 1158 | − master->min_speed_hz = spi->clk_rate / SPI_MBR_DIV_MAX; | |
| 1895 | + master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST | | |
| 1896 | + SPI_3WIRE; | |
| 1897 | + master->bits_per_word_mask = spi->cfg->get_bpw_mask(spi); | |
| 1898 | + master->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min; | |
| 1899 | + master->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max; | |
| 1159 | 1900 | master->setup = stm32_spi_setup; |
| 1160 | 1901 | master->prepare_message = stm32_spi_prepare_msg; |
| 1161 | 1902 | master->transfer_one = stm32_spi_transfer_one; |
| @@ -1233,7 +1974,7 @@ static int stm32_spi_remove(struct platform_device *pdev) · 71 unmodified lines | ||
| 1233 | 1974 | struct spi_master *master = platform_get_drvdata(pdev); |
| 1234 | 1975 | struct stm32_spi *spi = spi_master_get_devdata(master); |
| 1235 | 1976 | |
| 1236 | − stm32_spi_disable(spi); | |
| 1977 | + spi->cfg->disable(spi); | |
| 1237 | 1978 | |
| 1238 | 1979 | if (master->dma_tx) |
| 1239 | 1980 | dma_release_channel(master->dma_tx); |
| @@ -490,8 +490,8 @@ static void ti_qspi_enable_memory_map(struct spi_device *spi) · 489 unmodified lines | ||
| 490 | 490 | ti_qspi_write(qspi, MM_SWITCH, QSPI_SPI_SWITCH_REG); |
| 491 | 491 | if (qspi->ctrl_base) { |
| 492 | 492 | regmap_update_bits(qspi->ctrl_base, qspi->ctrl_reg, |
| 493 | − MEM_CS_EN(spi->chip_select), | |
| 494 | − MEM_CS_MASK); | |
| 493 | + MEM_CS_MASK, | |
| 494 | + MEM_CS_EN(spi->chip_select)); | |
| 495 | 495 | } |
| 496 | 496 | qspi->mmap_enabled = true; |
| 497 | 497 | } |
| @@ -503,7 +503,7 @@ static void ti_qspi_disable_memory_map(struct spi_device *spi) · 5 unmodified lines | ||
| 503 | 503 | ti_qspi_write(qspi, 0, QSPI_SPI_SWITCH_REG); |
| 504 | 504 | if (qspi->ctrl_base) |
| 505 | 505 | regmap_update_bits(qspi->ctrl_base, qspi->ctrl_reg, |
| 506 | − 0, MEM_CS_MASK); | |
| 506 | + MEM_CS_MASK, 0); | |
| 507 | 507 | qspi->mmap_enabled = false; |
| 508 | 508 | } |
| 509 | 509 | |
| @@ -1008,6 +1008,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) · 1007 unmodified lines | ||
| 1008 | 1008 | |
| 1009 | 1009 | /* RX */ |
| 1010 | 1010 | dma->sg_rx_p = kcalloc(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC); |
| 1011 | + if (!dma->sg_rx_p) | |
| 1012 | + return; | |
| 1013 | + | |
| 1011 | 1014 | sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */ |
| 1012 | 1015 | /* offset, length setting */ |
| 1013 | 1016 | sg = dma->sg_rx_p; |
| @@ -1068,6 +1071,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw) · 54 unmodified lines | ||
| 1068 | 1071 | } |
| 1069 | 1072 | |
| 1070 | 1073 | dma->sg_tx_p = kcalloc(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC); |
| 1074 | + if (!dma->sg_tx_p) | |
| 1075 | + return; | |
| 1076 | + | |
| 1071 | 1077 | sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */ |
| 1072 | 1078 | /* offset, length setting */ |
| 1073 | 1079 | sg = dma->sg_tx_p; |
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | #include <linux/spi/spi.h> |
| 20 | 20 | #include <linux/spi/spi-mem.h> |
| 21 | 21 | #include <linux/of_gpio.h> |
| 22 | +#include <linux/gpio/consumer.h> | |
| 22 | 23 | #include <linux/pm_runtime.h> |
| 23 | 24 | #include <linux/pm_domain.h> |
| 24 | 25 | #include <linux/property.h> |
| @@ -578,7 +579,10 @@ int spi_add_device(struct spi_device *spi) · 553 unmodified lines | ||
| 578 | 579 | goto done; |
| 579 | 580 | } |
| 580 | 581 | |
| 581 | − if (ctlr->cs_gpios) | |
| 582 | + /* Descriptors take precedence */ | |
| 583 | + if (ctlr->cs_gpiods) | |
| 584 | + spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select]; | |
| 585 | + else if (ctlr->cs_gpios) | |
| 582 | 586 | spi->cs_gpio = ctlr->cs_gpios[spi->chip_select]; |
| 583 | 587 | |
| 584 | 588 | /* Drivers may modify this initial i/o setup, but will |
| @@ -772,10 +776,21 @@ static void spi_set_cs(struct spi_device *spi, bool enable) · 187 unmodified lines | ||
| 772 | 776 | if (spi->mode & SPI_CS_HIGH) |
| 773 | 777 | enable = !enable; |
| 774 | 778 | |
| 775 | − if (gpio_is_valid(spi->cs_gpio)) { | |
| 776 | − /* Honour the SPI_NO_CS flag */ | |
| 777 | − if (!(spi->mode & SPI_NO_CS)) | |
| 778 | − gpio_set_value(spi->cs_gpio, !enable); | |
| 779 | + if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) { | |
| 780 | + /* | |
| 781 | + * Honour the SPI_NO_CS flag and invert the enable line, as | |
| 782 | + * active low is default for SPI. Execution paths that handle | |
| 783 | + * polarity inversion in gpiolib (such as device tree) will | |
| 784 | + * enforce active high using the SPI_CS_HIGH resulting in a | |
| 785 | + * double inversion through the code above. | |
| 786 | + */ | |
| 787 | + if (!(spi->mode & SPI_NO_CS)) { | |
| 788 | + if (spi->cs_gpiod) | |
| 789 | + gpiod_set_value_cansleep(spi->cs_gpiod, | |
| 790 | + !enable); | |
| 791 | + else | |
| 792 | + gpio_set_value_cansleep(spi->cs_gpio, !enable); | |
| 793 | + } | |
| 779 | 794 | /* Some SPI masters need both GPIO CS & slave_select */ |
| 780 | 795 | if ((spi->controller->flags & SPI_MASTER_GPIO_SS) && |
| 781 | 796 | spi->controller->set_cs) |
| @@ -1615,13 +1630,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · 833 unmodified lines | ||
| 1615 | 1630 | spi->mode |= SPI_CPHA; |
| 1616 | 1631 | if (of_property_read_bool(nc, "spi-cpol")) |
| 1617 | 1632 | spi->mode |= SPI_CPOL; |
| 1618 | − if (of_property_read_bool(nc, "spi-cs-high")) | |
| 1619 | − spi->mode |= SPI_CS_HIGH; | |
| 1620 | 1633 | if (of_property_read_bool(nc, "spi-3wire")) |
| 1621 | 1634 | spi->mode |= SPI_3WIRE; |
| 1622 | 1635 | if (of_property_read_bool(nc, "spi-lsb-first")) |
| 1623 | 1636 | spi->mode |= SPI_LSB_FIRST; |
| 1624 | 1637 | |
| 1638 | + /* | |
| 1639 | + * For descriptors associated with the device, polarity inversion is | |
| 1640 | + * handled in the gpiolib, so all chip selects are "active high" in | |
| 1641 | + * the logical sense, the gpiolib will invert the line if need be. | |
| 1642 | + */ | |
| 1643 | + if (ctlr->use_gpio_descriptors) | |
| 1644 | + spi->mode |= SPI_CS_HIGH; | |
| 1645 | + else if (of_property_read_bool(nc, "spi-cs-high")) | |
| 1646 | + spi->mode |= SPI_CS_HIGH; | |
| 1647 | + | |
| 1625 | 1648 | /* Device DUAL/QUAD mode */ |
| 1626 | 1649 | if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) { |
| 1627 | 1650 | switch (value) { |
| @@ -2137,6 +2160,60 @@ static int of_spi_register_master(struct spi_controller *ctlr) · 509 unmodified lines | ||
| 2137 | 2160 | } |
| 2138 | 2161 | #endif |
| 2139 | 2162 | |
| 2163 | +/** | |
| 2164 | + * spi_get_gpio_descs() - grab chip select GPIOs for the master | |
| 2165 | + * @ctlr: The SPI master to grab GPIO descriptors for | |
| 2166 | + */ | |
| 2167 | +static int spi_get_gpio_descs(struct spi_controller *ctlr) | |
| 2168 | +{ | |
| 2169 | + int nb, i; | |
| 2170 | + struct gpio_desc **cs; | |
| 2171 | + struct device *dev = &ctlr->dev; | |
| 2172 | + | |
| 2173 | + nb = gpiod_count(dev, "cs"); | |
| 2174 | + ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect); | |
| 2175 | + | |
| 2176 | + /* No GPIOs at all is fine, else return the error */ | |
| 2177 | + if (nb == 0 || nb == -ENOENT) | |
| 2178 | + return 0; | |
| 2179 | + else if (nb < 0) | |
| 2180 | + return nb; | |
| 2181 | + | |
| 2182 | + cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs), | |
| 2183 | + GFP_KERNEL); | |
| 2184 | + if (!cs) | |
| 2185 | + return -ENOMEM; | |
| 2186 | + ctlr->cs_gpiods = cs; | |
| 2187 | + | |
| 2188 | + for (i = 0; i < nb; i++) { | |
| 2189 | + /* | |
| 2190 | + * Most chipselects are active low, the inverted | |
| 2191 | + * semantics are handled by special quirks in gpiolib, | |
| 2192 | + * so initializing them GPIOD_OUT_LOW here means | |
| 2193 | + * "unasserted", in most cases this will drive the physical | |
| 2194 | + * line high. | |
| 2195 | + */ | |
| 2196 | + cs[i] = devm_gpiod_get_index_optional(dev, "cs", i, | |
| 2197 | + GPIOD_OUT_LOW); | |
| 2198 | + | |
| 2199 | + if (cs[i]) { | |
| 2200 | + /* | |
| 2201 | + * If we find a CS GPIO, name it after the device and | |
| 2202 | + * chip select line. | |
| 2203 | + */ | |
| 2204 | + char *gpioname; | |
| 2205 | + | |
| 2206 | + gpioname = devm_kasprintf(dev, GFP_KERNEL, "%s CS%d", | |
| 2207 | + dev_name(dev), i); | |
| 2208 | + if (!gpioname) | |
| 2209 | + return -ENOMEM; | |
| 2210 | + gpiod_set_consumer_name(cs[i], gpioname); | |
| 2211 | + } | |
| 2212 | + } | |
| 2213 | + | |
| 2214 | + return 0; | |
| 2215 | +} | |
| 2216 | + | |
| 2140 | 2217 | static int spi_controller_check_ops(struct spi_controller *ctlr) |
| 2141 | 2218 | { |
| 2142 | 2219 | /* |
| @@ -2199,9 +2276,21 @@ int spi_register_controller(struct spi_controller *ctlr) · 56 unmodified lines | ||
| 2199 | 2276 | return status; |
| 2200 | 2277 | |
| 2201 | 2278 | if (!spi_controller_is_slave(ctlr)) { |
| 2202 | − status = of_spi_register_master(ctlr); | |
| 2203 | − if (status) | |
| 2204 | − return status; | |
| 2279 | + if (ctlr->use_gpio_descriptors) { | |
| 2280 | + status = spi_get_gpio_descs(ctlr); | |
| 2281 | + if (status) | |
| 2282 | + return status; | |
| 2283 | + /* | |
| 2284 | + * A controller using GPIO descriptors always | |
| 2285 | + * supports SPI_CS_HIGH if need be. | |
| 2286 | + */ | |
| 2287 | + ctlr->mode_bits |= SPI_CS_HIGH; | |
| 2288 | + } else { | |
| 2289 | + /* Legacy code path for GPIOs from DT */ | |
| 2290 | + status = of_spi_register_master(ctlr); | |
| 2291 | + if (status) | |
| 2292 | + return status; | |
| 2293 | + } | |
| 2205 | 2294 | } |
| 2206 | 2295 | |
| 2207 | 2296 | /* even if it's just one always-selected device, there must |
| @@ -2915,6 +3004,7 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 707 unmodified lines | ||
| 2915 | 3004 | * cs_change is set for each transfer. |
| 2916 | 3005 | */ |
| 2917 | 3006 | if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) || |
| 3007 | + spi->cs_gpiod || | |
| 2918 | 3008 | gpio_is_valid(spi->cs_gpio))) { |
| 2919 | 3009 | size_t maxsize; |
| 2920 | 3010 | int ret; |
| @@ -2961,6 +3051,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 40 unmodified lines | ||
| 2961 | 3051 | * it is not set for this transfer. |
| 2962 | 3052 | * Set transfer tx_nbits and rx_nbits as single transfer default |
| 2963 | 3053 | * (SPI_NBITS_SINGLE) if it is not set for this transfer. |
| 3054 | + * Ensure transfer word_delay is at least as long as that required by | |
| 3055 | + * device itself. | |
| 2964 | 3056 | */ |
| 2965 | 3057 | message->frame_length = 0; |
| 2966 | 3058 | list_for_each_entry(xfer, &message->transfers, transfer_list) { |
| @@ -3031,6 +3123,9 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 64 unmodified lines | ||
| 3031 | 3123 | !(spi->mode & SPI_RX_QUAD)) |
| 3032 | 3124 | return -EINVAL; |
| 3033 | 3125 | } |
| 3126 | + | |
| 3127 | + if (xfer->word_delay_usecs < spi->word_delay_usecs) | |
| 3128 | + xfer->word_delay_usecs = spi->word_delay_usecs; | |
| 3034 | 3129 | } |
| 3035 | 3130 | |
| 3036 | 3131 | message->status = -EINPROGRESS; |
File renamed without changes.
| @@ -22,7 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | struct dma_chan; |
| 23 | 23 | |
| 24 | 24 | /* device.platform_data for SSP controller devices */ |
| 25 | −struct pxa2xx_spi_master { | |
| 25 | +struct pxa2xx_spi_controller { | |
| 26 | 26 | u16 num_chipselect; |
| 27 | 27 | u8 enable_dma; |
| 28 | 28 | bool is_slave; |
| @@ -54,7 +54,7 @@ struct pxa2xx_spi_chip { · 25 unmodified lines | ||
| 54 | 54 | |
| 55 | 55 | #include <linux/clk.h> |
| 56 | 56 | |
| 57 | −extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info); | |
| 57 | +extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info); | |
| 58 | 58 | |
| 59 | 59 | #endif |
| 60 | 60 | #endif |
| @@ -330,6 +330,11 @@ ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc, · 329 unmodified lines | ||
| 330 | 330 | u64 offs, size_t len, void *buf); |
| 331 | 331 | ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc, |
| 332 | 332 | u64 offs, size_t len, const void *buf); |
| 333 | +struct spi_mem_dirmap_desc * | |
| 334 | +devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, | |
| 335 | + const struct spi_mem_dirmap_info *info); | |
| 336 | +void devm_spi_mem_dirmap_destroy(struct device *dev, | |
| 337 | + struct spi_mem_dirmap_desc *desc); | |
| 333 | 338 | |
| 334 | 339 | int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv, |
| 335 | 340 | struct module *owner); |
| @@ -12,6 +12,7 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <linux/kthread.h> |
| 13 | 13 | #include <linux/completion.h> |
| 14 | 14 | #include <linux/scatterlist.h> |
| 15 | +#include <linux/gpio/consumer.h> | |
| 15 | 16 | |
| 16 | 17 | struct dma_chan; |
| 17 | 18 | struct property_entry; |
| @@ -116,8 +117,13 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, · 98 unmodified lines | ||
| 116 | 117 | * @modalias: Name of the driver to use with this device, or an alias |
| 117 | 118 | * for that name. This appears in the sysfs "modalias" attribute |
| 118 | 119 | * for driver coldplugging, and in uevents used for hotplugging |
| 119 | − * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when | |
| 120 | + * @cs_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when | |
| 121 | + * not using a GPIO line) use cs_gpiod in new drivers by opting in on | |
| 122 | + * the spi_master. | |
| 123 | + * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when | |
| 120 | 124 | * not using a GPIO line) |
| 125 | + * @word_delay_usecs: microsecond delay to be inserted between consecutive | |
| 126 | + * words of a transfer | |
| 121 | 127 | * |
| 122 | 128 | * @statistics: statistics for the spi_device |
| 123 | 129 | * |
| @@ -163,7 +169,9 @@ struct spi_device { · 39 unmodified lines | ||
| 163 | 169 | void *controller_data; |
| 164 | 170 | char modalias[SPI_NAME_SIZE]; |
| 165 | 171 | const char *driver_override; |
| 166 | − int cs_gpio; /* chip select gpio */ | |
| 172 | + int cs_gpio; /* LEGACY: chip select gpio */ | |
| 173 | + struct gpio_desc *cs_gpiod; /* chip select gpio desc */ | |
| 174 | + uint8_t word_delay_usecs; /* inter-word delay */ | |
| 167 | 175 | |
| 168 | 176 | /* the statistics */ |
| 169 | 177 | struct spi_statistics statistics; |
| @@ -376,9 +384,17 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 206 unmodified lines | ||
| 376 | 384 | * controller has native support for memory like operations. |
| 377 | 385 | * @unprepare_message: undo any work done by prepare_message(). |
| 378 | 386 | * @slave_abort: abort the ongoing transfer request on an SPI slave controller |
| 379 | − * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS | |
| 380 | − * number. Any individual value may be -ENOENT for CS lines that | |
| 387 | + * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per | |
| 388 | + * CS number. Any individual value may be -ENOENT for CS lines that | |
| 389 | + * are not GPIOs (driven by the SPI controller itself). Use the cs_gpiods | |
| 390 | + * in new drivers. | |
| 391 | + * @cs_gpiods: Array of GPIO descs to use as chip select lines; one per CS | |
| 392 | + * number. Any individual value may be NULL for CS lines that | |
| 381 | 393 | * are not GPIOs (driven by the SPI controller itself). |
| 394 | + * @use_gpio_descriptors: Turns on the code in the SPI core to parse and grab | |
| 395 | + * GPIO descriptors rather than using global GPIO numbers grabbed by the | |
| 396 | + * driver. This will fill in @cs_gpiods and @cs_gpios should not be used, | |
| 397 | + * and SPI devices will have the cs_gpiod assigned rather than cs_gpio. | |
| 382 | 398 | * @statistics: statistics for the spi_controller |
| 383 | 399 | * @dma_tx: DMA transmit channel |
| 384 | 400 | * @dma_rx: DMA receive channel |
| @@ -557,6 +573,8 @@ struct spi_controller { · 172 unmodified lines | ||
| 557 | 573 | |
| 558 | 574 | /* gpio chip select */ |
| 559 | 575 | int *cs_gpios; |
| 576 | + struct gpio_desc **cs_gpiods; | |
| 577 | + bool use_gpio_descriptors; | |
| 560 | 578 | |
| 561 | 579 | /* statistics */ |
| 562 | 580 | struct spi_statistics statistics; |
| @@ -706,6 +724,8 @@ extern void spi_res_release(struct spi_controller *ctlr, · 143 unmodified lines | ||
| 706 | 724 | * @delay_usecs: microseconds to delay after this transfer before |
| 707 | 725 | * (optionally) changing the chipselect status, then starting |
| 708 | 726 | * the next transfer or completing this @spi_message. |
| 727 | + * @word_delay_usecs: microseconds to inter word delay after each word size | |
| 728 | + * (set by bits_per_word) transmission. | |
| 709 | 729 | * @word_delay: clock cycles to inter word delay after each word size |
| 710 | 730 | * (set by bits_per_word) transmission. |
| 711 | 731 | * @transfer_list: transfers are sequenced through @spi_message.transfers |
| @@ -788,6 +808,7 @@ struct spi_transfer { · 76 unmodified lines | ||
| 788 | 808 | #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */ |
| 789 | 809 | #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */ |
| 790 | 810 | u8 bits_per_word; |
| 811 | + u8 word_delay_usecs; | |
| 791 | 812 | u16 delay_usecs; |
| 792 | 813 | u32 speed_hz; |
| 793 | 814 | u16 word_delay; |
| @@ -109,6 +109,16 @@ TRACE_EVENT(spi_message_done, · 108 unmodified lines | ||
| 109 | 109 | (unsigned)__entry->actual, (unsigned)__entry->frame) |
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | +/* | |
| 113 | + * consider a buffer valid if non-NULL and if it doesn't match the dummy buffer | |
| 114 | + * that only exist to work with controllers that have SPI_CONTROLLER_MUST_TX or | |
| 115 | + * SPI_CONTROLLER_MUST_RX. | |
| 116 | + */ | |
| 117 | +#define spi_valid_txbuf(msg, xfer) \ | |
| 118 | + (xfer->tx_buf && xfer->tx_buf != msg->spi->controller->dummy_tx) | |
| 119 | +#define spi_valid_rxbuf(msg, xfer) \ | |
| 120 | + (xfer->rx_buf && xfer->rx_buf != msg->spi->controller->dummy_rx) | |
| 121 | + | |
| 112 | 122 | DECLARE_EVENT_CLASS(spi_transfer, |
| 113 | 123 | |
| 114 | 124 | TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer), |
| @@ -120,6 +130,10 @@ DECLARE_EVENT_CLASS(spi_transfer, · 5 unmodified lines | ||
| 120 | 130 | __field( int, chip_select ) |
| 121 | 131 | __field( struct spi_transfer *, xfer ) |
| 122 | 132 | __field( int, len ) |
| 133 | + __dynamic_array(u8, rx_buf, | |
| 134 | + spi_valid_rxbuf(msg, xfer) ? xfer->len : 0) | |
| 135 | + __dynamic_array(u8, tx_buf, | |
| 136 | + spi_valid_txbuf(msg, xfer) ? xfer->len : 0) | |
| 123 | 137 | ), |
| 124 | 138 | |
| 125 | 139 | TP_fast_assign( |
| @@ -127,12 +141,21 @@ DECLARE_EVENT_CLASS(spi_transfer, · 1 unmodified line | ||
| 127 | 141 | __entry->chip_select = msg->spi->chip_select; |
| 128 | 142 | __entry->xfer = xfer; |
| 129 | 143 | __entry->len = xfer->len; |
| 144 | + | |
| 145 | + if (spi_valid_txbuf(msg, xfer)) | |
| 146 | + memcpy(__get_dynamic_array(tx_buf), | |
| 147 | + xfer->tx_buf, xfer->len); | |
| 148 | + | |
| 149 | + if (spi_valid_rxbuf(msg, xfer)) | |
| 150 | + memcpy(__get_dynamic_array(rx_buf), | |
| 151 | + xfer->rx_buf, xfer->len); | |
| 130 | 152 | ), |
| 131 | 153 | |
| 132 | − TP_printk("spi%d.%d %p len=%d", (int)__entry->bus_num, | |
| 133 | − (int)__entry->chip_select, | |
| 134 | − (struct spi_message *)__entry->xfer, | |
| 135 | − (int)__entry->len) | |
| 154 | + TP_printk("spi%d.%d %p len=%d tx=[%*phD] rx=[%*phD]", | |
| 155 | + __entry->bus_num, __entry->chip_select, | |
| 156 | + __entry->xfer, __entry->len, | |
| 157 | + __get_dynamic_array_len(tx_buf), __get_dynamic_array(tx_buf), | |
| 158 | + __get_dynamic_array_len(rx_buf), __get_dynamic_array(rx_buf)) | |
| 136 | 159 | ); |
| 137 | 160 | |
| 138 | 161 | DEFINE_EVENT(spi_transfer, spi_transfer_start, |