Wolfram Sang | 9135bac | 2018-08-22 00:02:23 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 2 | /* |
| 3 | * SH RSPI driver |
| 4 | * |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 5 | * Copyright (C) 2012, 2013 Renesas Solutions Corp. |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 6 | * Copyright (C) 2014 Glider bvba |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 7 | * |
| 8 | * Based on spi-sh.c: |
| 9 | * Copyright (C) 2011 Renesas Solutions Corp. |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/errno.h> |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/clk.h> |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 20 | #include <linux/dmaengine.h> |
| 21 | #include <linux/dma-mapping.h> |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 22 | #include <linux/of_device.h> |
Geert Uytterhoeven | 490c977 | 2014-03-11 10:59:12 +0100 | [diff] [blame] | 23 | #include <linux/pm_runtime.h> |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 24 | #include <linux/sh_dma.h> |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 25 | #include <linux/spi/spi.h> |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 26 | #include <linux/spi/rspi.h> |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 27 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 28 | #define RSPI_SPCR 0x00 /* Control Register */ |
| 29 | #define RSPI_SSLP 0x01 /* Slave Select Polarity Register */ |
| 30 | #define RSPI_SPPCR 0x02 /* Pin Control Register */ |
| 31 | #define RSPI_SPSR 0x03 /* Status Register */ |
| 32 | #define RSPI_SPDR 0x04 /* Data Register */ |
| 33 | #define RSPI_SPSCR 0x08 /* Sequence Control Register */ |
| 34 | #define RSPI_SPSSR 0x09 /* Sequence Status Register */ |
| 35 | #define RSPI_SPBR 0x0a /* Bit Rate Register */ |
| 36 | #define RSPI_SPDCR 0x0b /* Data Control Register */ |
| 37 | #define RSPI_SPCKD 0x0c /* Clock Delay Register */ |
| 38 | #define RSPI_SSLND 0x0d /* Slave Select Negation Delay Register */ |
| 39 | #define RSPI_SPND 0x0e /* Next-Access Delay Register */ |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 40 | #define RSPI_SPCR2 0x0f /* Control Register 2 (SH only) */ |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 41 | #define RSPI_SPCMD0 0x10 /* Command Register 0 */ |
| 42 | #define RSPI_SPCMD1 0x12 /* Command Register 1 */ |
| 43 | #define RSPI_SPCMD2 0x14 /* Command Register 2 */ |
| 44 | #define RSPI_SPCMD3 0x16 /* Command Register 3 */ |
| 45 | #define RSPI_SPCMD4 0x18 /* Command Register 4 */ |
| 46 | #define RSPI_SPCMD5 0x1a /* Command Register 5 */ |
| 47 | #define RSPI_SPCMD6 0x1c /* Command Register 6 */ |
| 48 | #define RSPI_SPCMD7 0x1e /* Command Register 7 */ |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 49 | #define RSPI_SPCMD(i) (RSPI_SPCMD0 + (i) * 2) |
| 50 | #define RSPI_NUM_SPCMD 8 |
| 51 | #define RSPI_RZ_NUM_SPCMD 4 |
| 52 | #define QSPI_NUM_SPCMD 4 |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 53 | |
| 54 | /* RSPI on RZ only */ |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 55 | #define RSPI_SPBFCR 0x20 /* Buffer Control Register */ |
| 56 | #define RSPI_SPBFDR 0x22 /* Buffer Data Count Setting Register */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 57 | |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 58 | /* QSPI only */ |
Geert Uytterhoeven | fbe5072 | 2014-01-12 11:27:38 +0100 | [diff] [blame] | 59 | #define QSPI_SPBFCR 0x18 /* Buffer Control Register */ |
| 60 | #define QSPI_SPBDCR 0x1a /* Buffer Data Count Register */ |
| 61 | #define QSPI_SPBMUL0 0x1c /* Transfer Data Length Multiplier Setting Register 0 */ |
| 62 | #define QSPI_SPBMUL1 0x20 /* Transfer Data Length Multiplier Setting Register 1 */ |
| 63 | #define QSPI_SPBMUL2 0x24 /* Transfer Data Length Multiplier Setting Register 2 */ |
| 64 | #define QSPI_SPBMUL3 0x28 /* Transfer Data Length Multiplier Setting Register 3 */ |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 65 | #define QSPI_SPBMUL(i) (QSPI_SPBMUL0 + (i) * 4) |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 66 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 67 | /* SPCR - Control Register */ |
| 68 | #define SPCR_SPRIE 0x80 /* Receive Interrupt Enable */ |
| 69 | #define SPCR_SPE 0x40 /* Function Enable */ |
| 70 | #define SPCR_SPTIE 0x20 /* Transmit Interrupt Enable */ |
| 71 | #define SPCR_SPEIE 0x10 /* Error Interrupt Enable */ |
| 72 | #define SPCR_MSTR 0x08 /* Master/Slave Mode Select */ |
| 73 | #define SPCR_MODFEN 0x04 /* Mode Fault Error Detection Enable */ |
| 74 | /* RSPI on SH only */ |
| 75 | #define SPCR_TXMD 0x02 /* TX Only Mode (vs. Full Duplex) */ |
| 76 | #define SPCR_SPMS 0x01 /* 3-wire Mode (vs. 4-wire) */ |
Geert Uytterhoeven | 6089af7 | 2014-08-28 10:10:19 +0200 | [diff] [blame] | 77 | /* QSPI on R-Car Gen2 only */ |
Geert Uytterhoeven | fbe5072 | 2014-01-12 11:27:38 +0100 | [diff] [blame] | 78 | #define SPCR_WSWAP 0x02 /* Word Swap of read-data for DMAC */ |
| 79 | #define SPCR_BSWAP 0x01 /* Byte Swap of read-data for DMAC */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 80 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 81 | /* SSLP - Slave Select Polarity Register */ |
| 82 | #define SSLP_SSL1P 0x02 /* SSL1 Signal Polarity Setting */ |
| 83 | #define SSLP_SSL0P 0x01 /* SSL0 Signal Polarity Setting */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 84 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 85 | /* SPPCR - Pin Control Register */ |
| 86 | #define SPPCR_MOIFE 0x20 /* MOSI Idle Value Fixing Enable */ |
| 87 | #define SPPCR_MOIFV 0x10 /* MOSI Idle Fixed Value */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 88 | #define SPPCR_SPOM 0x04 |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 89 | #define SPPCR_SPLP2 0x02 /* Loopback Mode 2 (non-inverting) */ |
| 90 | #define SPPCR_SPLP 0x01 /* Loopback Mode (inverting) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 91 | |
Geert Uytterhoeven | fbe5072 | 2014-01-12 11:27:38 +0100 | [diff] [blame] | 92 | #define SPPCR_IO3FV 0x04 /* Single-/Dual-SPI Mode IO3 Output Fixed Value */ |
| 93 | #define SPPCR_IO2FV 0x04 /* Single-/Dual-SPI Mode IO2 Output Fixed Value */ |
| 94 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 95 | /* SPSR - Status Register */ |
| 96 | #define SPSR_SPRF 0x80 /* Receive Buffer Full Flag */ |
| 97 | #define SPSR_TEND 0x40 /* Transmit End */ |
| 98 | #define SPSR_SPTEF 0x20 /* Transmit Buffer Empty Flag */ |
| 99 | #define SPSR_PERF 0x08 /* Parity Error Flag */ |
| 100 | #define SPSR_MODF 0x04 /* Mode Fault Error Flag */ |
| 101 | #define SPSR_IDLNF 0x02 /* RSPI Idle Flag */ |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 102 | #define SPSR_OVRF 0x01 /* Overrun Error Flag (RSPI only) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 103 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 104 | /* SPSCR - Sequence Control Register */ |
| 105 | #define SPSCR_SPSLN_MASK 0x07 /* Sequence Length Specification */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 106 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 107 | /* SPSSR - Sequence Status Register */ |
| 108 | #define SPSSR_SPECM_MASK 0x70 /* Command Error Mask */ |
| 109 | #define SPSSR_SPCP_MASK 0x07 /* Command Pointer Mask */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 110 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 111 | /* SPDCR - Data Control Register */ |
| 112 | #define SPDCR_TXDMY 0x80 /* Dummy Data Transmission Enable */ |
| 113 | #define SPDCR_SPLW1 0x40 /* Access Width Specification (RZ) */ |
| 114 | #define SPDCR_SPLW0 0x20 /* Access Width Specification (RZ) */ |
| 115 | #define SPDCR_SPLLWORD (SPDCR_SPLW1 | SPDCR_SPLW0) |
| 116 | #define SPDCR_SPLWORD SPDCR_SPLW1 |
| 117 | #define SPDCR_SPLBYTE SPDCR_SPLW0 |
| 118 | #define SPDCR_SPLW 0x20 /* Access Width Specification (SH) */ |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 119 | #define SPDCR_SPRDTD 0x10 /* Receive Transmit Data Select (SH) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 120 | #define SPDCR_SLSEL1 0x08 |
| 121 | #define SPDCR_SLSEL0 0x04 |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 122 | #define SPDCR_SLSEL_MASK 0x0c /* SSL1 Output Select (SH) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 123 | #define SPDCR_SPFC1 0x02 |
| 124 | #define SPDCR_SPFC0 0x01 |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 125 | #define SPDCR_SPFC_MASK 0x03 /* Frame Count Setting (1-4) (SH) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 126 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 127 | /* SPCKD - Clock Delay Register */ |
| 128 | #define SPCKD_SCKDL_MASK 0x07 /* Clock Delay Setting (1-8) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 129 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 130 | /* SSLND - Slave Select Negation Delay Register */ |
| 131 | #define SSLND_SLNDL_MASK 0x07 /* SSL Negation Delay Setting (1-8) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 132 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 133 | /* SPND - Next-Access Delay Register */ |
| 134 | #define SPND_SPNDL_MASK 0x07 /* Next-Access Delay Setting (1-8) */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 135 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 136 | /* SPCR2 - Control Register 2 */ |
| 137 | #define SPCR2_PTE 0x08 /* Parity Self-Test Enable */ |
| 138 | #define SPCR2_SPIE 0x04 /* Idle Interrupt Enable */ |
| 139 | #define SPCR2_SPOE 0x02 /* Odd Parity Enable (vs. Even) */ |
| 140 | #define SPCR2_SPPE 0x01 /* Parity Enable */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 141 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 142 | /* SPCMDn - Command Registers */ |
| 143 | #define SPCMD_SCKDEN 0x8000 /* Clock Delay Setting Enable */ |
| 144 | #define SPCMD_SLNDEN 0x4000 /* SSL Negation Delay Setting Enable */ |
| 145 | #define SPCMD_SPNDEN 0x2000 /* Next-Access Delay Enable */ |
| 146 | #define SPCMD_LSBF 0x1000 /* LSB First */ |
| 147 | #define SPCMD_SPB_MASK 0x0f00 /* Data Length Setting */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 148 | #define SPCMD_SPB_8_TO_16(bit) (((bit - 1) << 8) & SPCMD_SPB_MASK) |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 149 | #define SPCMD_SPB_8BIT 0x0000 /* QSPI only */ |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 150 | #define SPCMD_SPB_16BIT 0x0100 |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 151 | #define SPCMD_SPB_20BIT 0x0000 |
| 152 | #define SPCMD_SPB_24BIT 0x0100 |
| 153 | #define SPCMD_SPB_32BIT 0x0200 |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 154 | #define SPCMD_SSLKP 0x0080 /* SSL Signal Level Keeping */ |
Geert Uytterhoeven | fbe5072 | 2014-01-12 11:27:38 +0100 | [diff] [blame] | 155 | #define SPCMD_SPIMOD_MASK 0x0060 /* SPI Operating Mode (QSPI only) */ |
| 156 | #define SPCMD_SPIMOD1 0x0040 |
| 157 | #define SPCMD_SPIMOD0 0x0020 |
| 158 | #define SPCMD_SPIMOD_SINGLE 0 |
| 159 | #define SPCMD_SPIMOD_DUAL SPCMD_SPIMOD0 |
| 160 | #define SPCMD_SPIMOD_QUAD SPCMD_SPIMOD1 |
| 161 | #define SPCMD_SPRW 0x0010 /* SPI Read/Write Access (Dual/Quad) */ |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 162 | #define SPCMD_SSLA_MASK 0x0030 /* SSL Assert Signal Setting (RSPI) */ |
| 163 | #define SPCMD_BRDV_MASK 0x000c /* Bit Rate Division Setting */ |
| 164 | #define SPCMD_CPOL 0x0002 /* Clock Polarity Setting */ |
| 165 | #define SPCMD_CPHA 0x0001 /* Clock Phase Setting */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 166 | |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 167 | /* SPBFCR - Buffer Control Register */ |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 168 | #define SPBFCR_TXRST 0x80 /* Transmit Buffer Data Reset */ |
| 169 | #define SPBFCR_RXRST 0x40 /* Receive Buffer Data Reset */ |
Geert Uytterhoeven | 6ab4865 | 2014-01-12 11:27:37 +0100 | [diff] [blame] | 170 | #define SPBFCR_TXTRG_MASK 0x30 /* Transmit Buffer Data Triggering Number */ |
| 171 | #define SPBFCR_RXTRG_MASK 0x07 /* Receive Buffer Data Triggering Number */ |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 172 | /* QSPI on R-Car Gen2 */ |
| 173 | #define SPBFCR_TXTRG_1B 0x00 /* 31 bytes (1 byte available) */ |
| 174 | #define SPBFCR_TXTRG_32B 0x30 /* 0 byte (32 bytes available) */ |
| 175 | #define SPBFCR_RXTRG_1B 0x00 /* 1 byte (31 bytes available) */ |
| 176 | #define SPBFCR_RXTRG_32B 0x07 /* 32 bytes (0 byte available) */ |
| 177 | |
| 178 | #define QSPI_BUFFER_SIZE 32u |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 179 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 180 | struct rspi_data { |
| 181 | void __iomem *addr; |
| 182 | u32 max_speed_hz; |
| 183 | struct spi_master *master; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 184 | wait_queue_head_t wait; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 185 | struct clk *clk; |
Geert Uytterhoeven | 348e515 | 2014-01-12 11:27:43 +0100 | [diff] [blame] | 186 | u16 spcmd; |
Geert Uytterhoeven | 06a7a3c | 2014-01-24 09:44:00 +0100 | [diff] [blame] | 187 | u8 spsr; |
| 188 | u8 sppcr; |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 189 | int rx_irq, tx_irq; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 190 | const struct spi_ops *ops; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 191 | |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 192 | unsigned dma_callbacked:1; |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 193 | unsigned byte_access:1; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 194 | }; |
| 195 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 196 | static void rspi_write8(const struct rspi_data *rspi, u8 data, u16 offset) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 197 | { |
| 198 | iowrite8(data, rspi->addr + offset); |
| 199 | } |
| 200 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 201 | static void rspi_write16(const struct rspi_data *rspi, u16 data, u16 offset) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 202 | { |
| 203 | iowrite16(data, rspi->addr + offset); |
| 204 | } |
| 205 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 206 | static void rspi_write32(const struct rspi_data *rspi, u32 data, u16 offset) |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 207 | { |
| 208 | iowrite32(data, rspi->addr + offset); |
| 209 | } |
| 210 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 211 | static u8 rspi_read8(const struct rspi_data *rspi, u16 offset) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 212 | { |
| 213 | return ioread8(rspi->addr + offset); |
| 214 | } |
| 215 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 216 | static u16 rspi_read16(const struct rspi_data *rspi, u16 offset) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 217 | { |
| 218 | return ioread16(rspi->addr + offset); |
| 219 | } |
| 220 | |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 221 | static void rspi_write_data(const struct rspi_data *rspi, u16 data) |
| 222 | { |
| 223 | if (rspi->byte_access) |
| 224 | rspi_write8(rspi, data, RSPI_SPDR); |
| 225 | else /* 16 bit */ |
| 226 | rspi_write16(rspi, data, RSPI_SPDR); |
| 227 | } |
| 228 | |
| 229 | static u16 rspi_read_data(const struct rspi_data *rspi) |
| 230 | { |
| 231 | if (rspi->byte_access) |
| 232 | return rspi_read8(rspi, RSPI_SPDR); |
| 233 | else /* 16 bit */ |
| 234 | return rspi_read16(rspi, RSPI_SPDR); |
| 235 | } |
| 236 | |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 237 | /* optional functions */ |
| 238 | struct spi_ops { |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 239 | int (*set_config_register)(struct rspi_data *rspi, int access_size); |
Geert Uytterhoeven | eb557f7 | 2014-01-24 09:43:55 +0100 | [diff] [blame] | 240 | int (*transfer_one)(struct spi_master *master, struct spi_device *spi, |
| 241 | struct spi_transfer *xfer); |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 242 | u16 mode_bits; |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 243 | u16 flags; |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 244 | u16 fifo_size; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | /* |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 248 | * functions for RSPI on legacy SH |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 249 | */ |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 250 | static int rspi_set_config_register(struct rspi_data *rspi, int access_size) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 251 | { |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 252 | int spbr; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 253 | |
Geert Uytterhoeven | 06a7a3c | 2014-01-24 09:44:00 +0100 | [diff] [blame] | 254 | /* Sets output mode, MOSI signal, and (optionally) loopback */ |
| 255 | rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 256 | |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 257 | /* Sets transfer bit rate */ |
Geert Uytterhoeven | 3beb61d | 2014-05-22 20:07:35 +0200 | [diff] [blame] | 258 | spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), |
| 259 | 2 * rspi->max_speed_hz) - 1; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 260 | rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); |
| 261 | |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 262 | /* Disable dummy transmission, set 16-bit word access, 1 frame */ |
| 263 | rspi_write8(rspi, 0, RSPI_SPDCR); |
| 264 | rspi->byte_access = 0; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 265 | |
| 266 | /* Sets RSPCK, SSL, next-access delay value */ |
| 267 | rspi_write8(rspi, 0x00, RSPI_SPCKD); |
| 268 | rspi_write8(rspi, 0x00, RSPI_SSLND); |
| 269 | rspi_write8(rspi, 0x00, RSPI_SPND); |
| 270 | |
| 271 | /* Sets parity, interrupt mask */ |
| 272 | rspi_write8(rspi, 0x00, RSPI_SPCR2); |
| 273 | |
| 274 | /* Sets SPCMD */ |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 275 | rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size); |
| 276 | rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 277 | |
| 278 | /* Sets RSPI mode */ |
| 279 | rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); |
| 280 | |
| 281 | return 0; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 282 | } |
| 283 | |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 284 | /* |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 285 | * functions for RSPI on RZ |
| 286 | */ |
| 287 | static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size) |
| 288 | { |
| 289 | int spbr; |
Chris Brandt | aeb8f8c | 2016-08-05 09:36:03 -0400 | [diff] [blame] | 290 | int div = 0; |
| 291 | unsigned long clksrc; |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 292 | |
Geert Uytterhoeven | 06a7a3c | 2014-01-24 09:44:00 +0100 | [diff] [blame] | 293 | /* Sets output mode, MOSI signal, and (optionally) loopback */ |
| 294 | rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 295 | |
Chris Brandt | aeb8f8c | 2016-08-05 09:36:03 -0400 | [diff] [blame] | 296 | clksrc = clk_get_rate(rspi->clk); |
| 297 | while (div < 3) { |
| 298 | if (rspi->max_speed_hz >= clksrc/4) /* 4=(CLK/2)/2 */ |
| 299 | break; |
| 300 | div++; |
| 301 | clksrc /= 2; |
| 302 | } |
| 303 | |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 304 | /* Sets transfer bit rate */ |
Chris Brandt | aeb8f8c | 2016-08-05 09:36:03 -0400 | [diff] [blame] | 305 | spbr = DIV_ROUND_UP(clksrc, 2 * rspi->max_speed_hz) - 1; |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 306 | rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); |
Chris Brandt | aeb8f8c | 2016-08-05 09:36:03 -0400 | [diff] [blame] | 307 | rspi->spcmd |= div << 2; |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 308 | |
| 309 | /* Disable dummy transmission, set byte access */ |
| 310 | rspi_write8(rspi, SPDCR_SPLBYTE, RSPI_SPDCR); |
| 311 | rspi->byte_access = 1; |
| 312 | |
| 313 | /* Sets RSPCK, SSL, next-access delay value */ |
| 314 | rspi_write8(rspi, 0x00, RSPI_SPCKD); |
| 315 | rspi_write8(rspi, 0x00, RSPI_SSLND); |
| 316 | rspi_write8(rspi, 0x00, RSPI_SPND); |
| 317 | |
| 318 | /* Sets SPCMD */ |
| 319 | rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size); |
| 320 | rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0); |
| 321 | |
| 322 | /* Sets RSPI mode */ |
| 323 | rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); |
| 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | /* |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 329 | * functions for QSPI |
| 330 | */ |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 331 | static int qspi_set_config_register(struct rspi_data *rspi, int access_size) |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 332 | { |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 333 | int spbr; |
| 334 | |
Geert Uytterhoeven | 06a7a3c | 2014-01-24 09:44:00 +0100 | [diff] [blame] | 335 | /* Sets output mode, MOSI signal, and (optionally) loopback */ |
| 336 | rspi_write8(rspi, rspi->sppcr, RSPI_SPPCR); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 337 | |
| 338 | /* Sets transfer bit rate */ |
Geert Uytterhoeven | 3beb61d | 2014-05-22 20:07:35 +0200 | [diff] [blame] | 339 | spbr = DIV_ROUND_UP(clk_get_rate(rspi->clk), 2 * rspi->max_speed_hz); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 340 | rspi_write8(rspi, clamp(spbr, 0, 255), RSPI_SPBR); |
| 341 | |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 342 | /* Disable dummy transmission, set byte access */ |
| 343 | rspi_write8(rspi, 0, RSPI_SPDCR); |
| 344 | rspi->byte_access = 1; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 345 | |
| 346 | /* Sets RSPCK, SSL, next-access delay value */ |
| 347 | rspi_write8(rspi, 0x00, RSPI_SPCKD); |
| 348 | rspi_write8(rspi, 0x00, RSPI_SSLND); |
| 349 | rspi_write8(rspi, 0x00, RSPI_SPND); |
| 350 | |
| 351 | /* Data Length Setting */ |
| 352 | if (access_size == 8) |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 353 | rspi->spcmd |= SPCMD_SPB_8BIT; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 354 | else if (access_size == 16) |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 355 | rspi->spcmd |= SPCMD_SPB_16BIT; |
Laurent Pinchart | 8e1c809 | 2013-11-27 01:41:44 +0100 | [diff] [blame] | 356 | else |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 357 | rspi->spcmd |= SPCMD_SPB_32BIT; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 358 | |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 359 | rspi->spcmd |= SPCMD_SCKDEN | SPCMD_SLNDEN | SPCMD_SPNDEN; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 360 | |
| 361 | /* Resets transfer data length */ |
| 362 | rspi_write32(rspi, 0, QSPI_SPBMUL0); |
| 363 | |
| 364 | /* Resets transmit and receive buffer */ |
| 365 | rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR); |
| 366 | /* Sets buffer to allow normal operation */ |
| 367 | rspi_write8(rspi, 0x00, QSPI_SPBFCR); |
| 368 | |
| 369 | /* Sets SPCMD */ |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 370 | rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 371 | |
Geert Uytterhoeven | b458a34 | 2017-12-07 11:09:21 +0100 | [diff] [blame] | 372 | /* Sets RSPI mode */ |
| 373 | rspi_write8(rspi, SPCR_MSTR, RSPI_SPCR); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 378 | static void qspi_update(const struct rspi_data *rspi, u8 mask, u8 val, u8 reg) |
| 379 | { |
| 380 | u8 data; |
| 381 | |
| 382 | data = rspi_read8(rspi, reg); |
| 383 | data &= ~mask; |
| 384 | data |= (val & mask); |
| 385 | rspi_write8(rspi, data, reg); |
| 386 | } |
| 387 | |
Geert Uytterhoeven | cb76b1c | 2015-06-23 15:04:29 +0200 | [diff] [blame] | 388 | static unsigned int qspi_set_send_trigger(struct rspi_data *rspi, |
| 389 | unsigned int len) |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 390 | { |
| 391 | unsigned int n; |
| 392 | |
| 393 | n = min(len, QSPI_BUFFER_SIZE); |
| 394 | |
| 395 | if (len >= QSPI_BUFFER_SIZE) { |
| 396 | /* sets triggering number to 32 bytes */ |
| 397 | qspi_update(rspi, SPBFCR_TXTRG_MASK, |
| 398 | SPBFCR_TXTRG_32B, QSPI_SPBFCR); |
| 399 | } else { |
| 400 | /* sets triggering number to 1 byte */ |
| 401 | qspi_update(rspi, SPBFCR_TXTRG_MASK, |
| 402 | SPBFCR_TXTRG_1B, QSPI_SPBFCR); |
| 403 | } |
| 404 | |
| 405 | return n; |
| 406 | } |
| 407 | |
Hiep Cao Minh | 3be09be | 2016-11-04 17:38:54 +0900 | [diff] [blame] | 408 | static int qspi_set_receive_trigger(struct rspi_data *rspi, unsigned int len) |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 409 | { |
| 410 | unsigned int n; |
| 411 | |
| 412 | n = min(len, QSPI_BUFFER_SIZE); |
| 413 | |
| 414 | if (len >= QSPI_BUFFER_SIZE) { |
| 415 | /* sets triggering number to 32 bytes */ |
| 416 | qspi_update(rspi, SPBFCR_RXTRG_MASK, |
| 417 | SPBFCR_RXTRG_32B, QSPI_SPBFCR); |
| 418 | } else { |
| 419 | /* sets triggering number to 1 byte */ |
| 420 | qspi_update(rspi, SPBFCR_RXTRG_MASK, |
| 421 | SPBFCR_RXTRG_1B, QSPI_SPBFCR); |
| 422 | } |
Hiep Cao Minh | 3be09be | 2016-11-04 17:38:54 +0900 | [diff] [blame] | 423 | return n; |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 424 | } |
| 425 | |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 426 | #define set_config_register(spi, n) spi->ops->set_config_register(spi, n) |
| 427 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 428 | static void rspi_enable_irq(const struct rspi_data *rspi, u8 enable) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 429 | { |
| 430 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | enable, RSPI_SPCR); |
| 431 | } |
| 432 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 433 | static void rspi_disable_irq(const struct rspi_data *rspi, u8 disable) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 434 | { |
| 435 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~disable, RSPI_SPCR); |
| 436 | } |
| 437 | |
| 438 | static int rspi_wait_for_interrupt(struct rspi_data *rspi, u8 wait_mask, |
| 439 | u8 enable_bit) |
| 440 | { |
| 441 | int ret; |
| 442 | |
| 443 | rspi->spsr = rspi_read8(rspi, RSPI_SPSR); |
Geert Uytterhoeven | 5dd1ad2 | 2014-02-04 11:06:24 +0100 | [diff] [blame] | 444 | if (rspi->spsr & wait_mask) |
| 445 | return 0; |
| 446 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 447 | rspi_enable_irq(rspi, enable_bit); |
| 448 | ret = wait_event_timeout(rspi->wait, rspi->spsr & wait_mask, HZ); |
| 449 | if (ret == 0 && !(rspi->spsr & wait_mask)) |
| 450 | return -ETIMEDOUT; |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 455 | static inline int rspi_wait_for_tx_empty(struct rspi_data *rspi) |
| 456 | { |
| 457 | return rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE); |
| 458 | } |
| 459 | |
| 460 | static inline int rspi_wait_for_rx_full(struct rspi_data *rspi) |
| 461 | { |
| 462 | return rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE); |
| 463 | } |
| 464 | |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 465 | static int rspi_data_out(struct rspi_data *rspi, u8 data) |
| 466 | { |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 467 | int error = rspi_wait_for_tx_empty(rspi); |
| 468 | if (error < 0) { |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 469 | dev_err(&rspi->master->dev, "transmit timeout\n"); |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 470 | return error; |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 471 | } |
| 472 | rspi_write_data(rspi, data); |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | static int rspi_data_in(struct rspi_data *rspi) |
| 477 | { |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 478 | int error; |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 479 | u8 data; |
| 480 | |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 481 | error = rspi_wait_for_rx_full(rspi); |
| 482 | if (error < 0) { |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 483 | dev_err(&rspi->master->dev, "receive timeout\n"); |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 484 | return error; |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 485 | } |
| 486 | data = rspi_read_data(rspi); |
| 487 | return data; |
| 488 | } |
| 489 | |
Geert Uytterhoeven | 6837b8e9 | 2014-06-02 15:38:07 +0200 | [diff] [blame] | 490 | static int rspi_pio_transfer(struct rspi_data *rspi, const u8 *tx, u8 *rx, |
| 491 | unsigned int n) |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 492 | { |
Geert Uytterhoeven | 6837b8e9 | 2014-06-02 15:38:07 +0200 | [diff] [blame] | 493 | while (n-- > 0) { |
| 494 | if (tx) { |
| 495 | int ret = rspi_data_out(rspi, *tx++); |
| 496 | if (ret < 0) |
| 497 | return ret; |
| 498 | } |
| 499 | if (rx) { |
| 500 | int ret = rspi_data_in(rspi); |
| 501 | if (ret < 0) |
| 502 | return ret; |
| 503 | *rx++ = ret; |
| 504 | } |
| 505 | } |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 506 | |
Geert Uytterhoeven | 6837b8e9 | 2014-06-02 15:38:07 +0200 | [diff] [blame] | 507 | return 0; |
Geert Uytterhoeven | 35301c9 | 2014-01-24 09:43:54 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 510 | static void rspi_dma_complete(void *arg) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 511 | { |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 512 | struct rspi_data *rspi = arg; |
| 513 | |
| 514 | rspi->dma_callbacked = 1; |
| 515 | wake_up_interruptible(&rspi->wait); |
| 516 | } |
| 517 | |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 518 | static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, |
| 519 | struct sg_table *rx) |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 520 | { |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 521 | struct dma_async_tx_descriptor *desc_tx = NULL, *desc_rx = NULL; |
| 522 | u8 irq_mask = 0; |
| 523 | unsigned int other_irq = 0; |
| 524 | dma_cookie_t cookie; |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 525 | int ret; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 526 | |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 527 | /* First prepare and submit the DMA request(s), as this may fail */ |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 528 | if (rx) { |
| 529 | desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx, |
Stefan Agner | 768d59f | 2018-03-19 23:16:22 +0100 | [diff] [blame] | 530 | rx->sgl, rx->nents, DMA_DEV_TO_MEM, |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 531 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 532 | if (!desc_rx) { |
| 533 | ret = -EAGAIN; |
| 534 | goto no_dma_rx; |
| 535 | } |
| 536 | |
| 537 | desc_rx->callback = rspi_dma_complete; |
| 538 | desc_rx->callback_param = rspi; |
| 539 | cookie = dmaengine_submit(desc_rx); |
| 540 | if (dma_submit_error(cookie)) { |
| 541 | ret = cookie; |
| 542 | goto no_dma_rx; |
| 543 | } |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 544 | |
| 545 | irq_mask |= SPCR_SPRIE; |
| 546 | } |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 547 | |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 548 | if (tx) { |
| 549 | desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx, |
Stefan Agner | 768d59f | 2018-03-19 23:16:22 +0100 | [diff] [blame] | 550 | tx->sgl, tx->nents, DMA_MEM_TO_DEV, |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 551 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 552 | if (!desc_tx) { |
| 553 | ret = -EAGAIN; |
| 554 | goto no_dma_tx; |
| 555 | } |
| 556 | |
| 557 | if (rx) { |
| 558 | /* No callback */ |
| 559 | desc_tx->callback = NULL; |
| 560 | } else { |
| 561 | desc_tx->callback = rspi_dma_complete; |
| 562 | desc_tx->callback_param = rspi; |
| 563 | } |
| 564 | cookie = dmaengine_submit(desc_tx); |
| 565 | if (dma_submit_error(cookie)) { |
| 566 | ret = cookie; |
| 567 | goto no_dma_tx; |
| 568 | } |
| 569 | |
| 570 | irq_mask |= SPCR_SPTIE; |
| 571 | } |
| 572 | |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 573 | /* |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 574 | * DMAC needs SPxIE, but if SPxIE is set, the IRQ routine will be |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 575 | * called. So, this driver disables the IRQ while DMA transfer. |
| 576 | */ |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 577 | if (tx) |
| 578 | disable_irq(other_irq = rspi->tx_irq); |
| 579 | if (rx && rspi->rx_irq != other_irq) |
| 580 | disable_irq(rspi->rx_irq); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 581 | |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 582 | rspi_enable_irq(rspi, irq_mask); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 583 | rspi->dma_callbacked = 0; |
| 584 | |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 585 | /* Now start DMA */ |
| 586 | if (rx) |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 587 | dma_async_issue_pending(rspi->master->dma_rx); |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 588 | if (tx) |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 589 | dma_async_issue_pending(rspi->master->dma_tx); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 590 | |
| 591 | ret = wait_event_interruptible_timeout(rspi->wait, |
| 592 | rspi->dma_callbacked, HZ); |
Geert Uytterhoeven | 8dbbaa4 | 2018-09-05 10:49:39 +0200 | [diff] [blame] | 593 | if (ret > 0 && rspi->dma_callbacked) { |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 594 | ret = 0; |
Geert Uytterhoeven | 8dbbaa4 | 2018-09-05 10:49:39 +0200 | [diff] [blame] | 595 | } else { |
| 596 | if (!ret) { |
| 597 | dev_err(&rspi->master->dev, "DMA timeout\n"); |
| 598 | ret = -ETIMEDOUT; |
| 599 | } |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 600 | if (tx) |
| 601 | dmaengine_terminate_all(rspi->master->dma_tx); |
| 602 | if (rx) |
| 603 | dmaengine_terminate_all(rspi->master->dma_rx); |
| 604 | } |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 605 | |
Geert Uytterhoeven | c52fb6d | 2014-06-02 15:38:15 +0200 | [diff] [blame] | 606 | rspi_disable_irq(rspi, irq_mask); |
| 607 | |
| 608 | if (tx) |
| 609 | enable_irq(rspi->tx_irq); |
| 610 | if (rx && rspi->rx_irq != other_irq) |
| 611 | enable_irq(rspi->rx_irq); |
| 612 | |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 613 | return ret; |
Geert Uytterhoeven | 85912a8 | 2014-07-09 12:26:22 +0200 | [diff] [blame] | 614 | |
Geert Uytterhoeven | 3819bc8 | 2014-08-06 14:58:58 +0200 | [diff] [blame] | 615 | no_dma_tx: |
| 616 | if (rx) |
| 617 | dmaengine_terminate_all(rspi->master->dma_rx); |
| 618 | no_dma_rx: |
| 619 | if (ret == -EAGAIN) { |
| 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)); |
| 623 | } |
| 624 | return ret; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 625 | } |
| 626 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 627 | static void rspi_receive_init(const struct rspi_data *rspi) |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 628 | { |
Geert Uytterhoeven | 97b95c1 | 2013-12-24 10:49:34 +0100 | [diff] [blame] | 629 | u8 spsr; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 630 | |
| 631 | spsr = rspi_read8(rspi, RSPI_SPSR); |
| 632 | if (spsr & SPSR_SPRF) |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 633 | rspi_read_data(rspi); /* dummy read */ |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 634 | if (spsr & SPSR_OVRF) |
| 635 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPSR) & ~SPSR_OVRF, |
Geert Uytterhoeven | df900e6 | 2013-12-23 19:34:24 +0100 | [diff] [blame] | 636 | RSPI_SPSR); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 637 | } |
| 638 | |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 639 | static void rspi_rz_receive_init(const struct rspi_data *rspi) |
| 640 | { |
| 641 | rspi_receive_init(rspi); |
| 642 | rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, RSPI_SPBFCR); |
| 643 | rspi_write8(rspi, 0, RSPI_SPBFCR); |
| 644 | } |
| 645 | |
Geert Uytterhoeven | baf588f | 2013-12-24 10:49:32 +0100 | [diff] [blame] | 646 | static void qspi_receive_init(const struct rspi_data *rspi) |
Hiep Cao Minh | cb52c67 | 2013-10-10 17:14:03 +0900 | [diff] [blame] | 647 | { |
Geert Uytterhoeven | 97b95c1 | 2013-12-24 10:49:34 +0100 | [diff] [blame] | 648 | u8 spsr; |
Hiep Cao Minh | cb52c67 | 2013-10-10 17:14:03 +0900 | [diff] [blame] | 649 | |
| 650 | spsr = rspi_read8(rspi, RSPI_SPSR); |
| 651 | if (spsr & SPSR_SPRF) |
Geert Uytterhoeven | 74da768 | 2014-01-24 09:43:53 +0100 | [diff] [blame] | 652 | rspi_read_data(rspi); /* dummy read */ |
Hiep Cao Minh | cb52c67 | 2013-10-10 17:14:03 +0900 | [diff] [blame] | 653 | rspi_write8(rspi, SPBFCR_TXRST | SPBFCR_RXRST, QSPI_SPBFCR); |
Geert Uytterhoeven | 340a15e | 2014-01-24 09:43:57 +0100 | [diff] [blame] | 654 | rspi_write8(rspi, 0, QSPI_SPBFCR); |
Hiep Cao Minh | cb52c67 | 2013-10-10 17:14:03 +0900 | [diff] [blame] | 655 | } |
| 656 | |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 657 | static bool __rspi_can_dma(const struct rspi_data *rspi, |
| 658 | const struct spi_transfer *xfer) |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 659 | { |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 660 | return xfer->len > rspi->ops->fifo_size; |
| 661 | } |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 662 | |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 663 | static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, |
| 664 | struct spi_transfer *xfer) |
| 665 | { |
| 666 | struct rspi_data *rspi = spi_master_get_devdata(master); |
| 667 | |
| 668 | return __rspi_can_dma(rspi, xfer); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 669 | } |
| 670 | |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 671 | static int rspi_dma_check_then_transfer(struct rspi_data *rspi, |
| 672 | struct spi_transfer *xfer) |
| 673 | { |
Hiep Cao Minh | 6310372 | 2015-04-30 11:12:12 +0900 | [diff] [blame] | 674 | if (!rspi->master->can_dma || !__rspi_can_dma(rspi, xfer)) |
| 675 | return -EAGAIN; |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 676 | |
Hiep Cao Minh | 6310372 | 2015-04-30 11:12:12 +0900 | [diff] [blame] | 677 | /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ |
| 678 | return rspi_dma_transfer(rspi, &xfer->tx_sg, |
| 679 | xfer->rx_buf ? &xfer->rx_sg : NULL); |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 680 | } |
| 681 | |
Geert Uytterhoeven | 8b983e9 | 2014-06-02 15:38:19 +0200 | [diff] [blame] | 682 | static int rspi_common_transfer(struct rspi_data *rspi, |
| 683 | struct spi_transfer *xfer) |
| 684 | { |
| 685 | int ret; |
| 686 | |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 687 | ret = rspi_dma_check_then_transfer(rspi, xfer); |
| 688 | if (ret != -EAGAIN) |
| 689 | return ret; |
Geert Uytterhoeven | 8b983e9 | 2014-06-02 15:38:19 +0200 | [diff] [blame] | 690 | |
| 691 | ret = rspi_pio_transfer(rspi, xfer->tx_buf, xfer->rx_buf, xfer->len); |
| 692 | if (ret < 0) |
| 693 | return ret; |
| 694 | |
| 695 | /* Wait for the last transmission */ |
| 696 | rspi_wait_for_tx_empty(rspi); |
| 697 | |
| 698 | return 0; |
| 699 | } |
| 700 | |
Geert Uytterhoeven | 8393fa7 | 2014-06-02 15:38:13 +0200 | [diff] [blame] | 701 | static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, |
| 702 | struct spi_transfer *xfer) |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 703 | { |
Geert Uytterhoeven | 8393fa7 | 2014-06-02 15:38:13 +0200 | [diff] [blame] | 704 | struct rspi_data *rspi = spi_master_get_devdata(master); |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 705 | u8 spcr; |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 706 | |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 707 | spcr = rspi_read8(rspi, RSPI_SPCR); |
Geert Uytterhoeven | 6837b8e9 | 2014-06-02 15:38:07 +0200 | [diff] [blame] | 708 | if (xfer->rx_buf) { |
Geert Uytterhoeven | 32c6426 | 2014-06-02 15:38:04 +0200 | [diff] [blame] | 709 | rspi_receive_init(rspi); |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 710 | spcr &= ~SPCR_TXMD; |
Geert Uytterhoeven | 32c6426 | 2014-06-02 15:38:04 +0200 | [diff] [blame] | 711 | } else { |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 712 | spcr |= SPCR_TXMD; |
Geert Uytterhoeven | 32c6426 | 2014-06-02 15:38:04 +0200 | [diff] [blame] | 713 | } |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 714 | rspi_write8(rspi, spcr, RSPI_SPCR); |
| 715 | |
Geert Uytterhoeven | 8b983e9 | 2014-06-02 15:38:19 +0200 | [diff] [blame] | 716 | return rspi_common_transfer(rspi, xfer); |
Geert Uytterhoeven | 8449fd7 | 2014-01-24 09:43:56 +0100 | [diff] [blame] | 717 | } |
| 718 | |
Geert Uytterhoeven | 03e627c | 2014-06-02 15:38:16 +0200 | [diff] [blame] | 719 | static int rspi_rz_transfer_one(struct spi_master *master, |
| 720 | struct spi_device *spi, |
| 721 | struct spi_transfer *xfer) |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 722 | { |
Geert Uytterhoeven | 03e627c | 2014-06-02 15:38:16 +0200 | [diff] [blame] | 723 | struct rspi_data *rspi = spi_master_get_devdata(master); |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 724 | |
| 725 | rspi_rz_receive_init(rspi); |
| 726 | |
Geert Uytterhoeven | 8b983e9 | 2014-06-02 15:38:19 +0200 | [diff] [blame] | 727 | return rspi_common_transfer(rspi, xfer); |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Hiep Cao Minh | a91bbe7 | 2015-05-22 18:59:36 +0900 | [diff] [blame] | 730 | static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 731 | u8 *rx, unsigned int len) |
| 732 | { |
Geert Uytterhoeven | cb76b1c | 2015-06-23 15:04:29 +0200 | [diff] [blame] | 733 | unsigned int i, n; |
| 734 | int ret; |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 735 | |
| 736 | while (len > 0) { |
| 737 | n = qspi_set_send_trigger(rspi, len); |
| 738 | qspi_set_receive_trigger(rspi, len); |
| 739 | if (n == QSPI_BUFFER_SIZE) { |
Geert Uytterhoeven | 5d4db69 | 2015-06-23 15:04:28 +0200 | [diff] [blame] | 740 | ret = rspi_wait_for_tx_empty(rspi); |
| 741 | if (ret < 0) { |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 742 | dev_err(&rspi->master->dev, "transmit timeout\n"); |
Geert Uytterhoeven | 5d4db69 | 2015-06-23 15:04:28 +0200 | [diff] [blame] | 743 | return ret; |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 744 | } |
| 745 | for (i = 0; i < n; i++) |
| 746 | rspi_write_data(rspi, *tx++); |
| 747 | |
Geert Uytterhoeven | 5d4db69 | 2015-06-23 15:04:28 +0200 | [diff] [blame] | 748 | ret = rspi_wait_for_rx_full(rspi); |
| 749 | if (ret < 0) { |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 750 | dev_err(&rspi->master->dev, "receive timeout\n"); |
Geert Uytterhoeven | 5d4db69 | 2015-06-23 15:04:28 +0200 | [diff] [blame] | 751 | return ret; |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 752 | } |
| 753 | for (i = 0; i < n; i++) |
| 754 | *rx++ = rspi_read_data(rspi); |
| 755 | } else { |
| 756 | ret = rspi_pio_transfer(rspi, tx, rx, n); |
| 757 | if (ret < 0) |
| 758 | return ret; |
| 759 | } |
| 760 | len -= n; |
| 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
Geert Uytterhoeven | 340a15e | 2014-01-24 09:43:57 +0100 | [diff] [blame] | 766 | static int qspi_transfer_out_in(struct rspi_data *rspi, |
| 767 | struct spi_transfer *xfer) |
| 768 | { |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 769 | int ret; |
| 770 | |
Geert Uytterhoeven | 340a15e | 2014-01-24 09:43:57 +0100 | [diff] [blame] | 771 | qspi_receive_init(rspi); |
| 772 | |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 773 | ret = rspi_dma_check_then_transfer(rspi, xfer); |
| 774 | if (ret != -EAGAIN) |
| 775 | return ret; |
| 776 | |
Hiep Cao Minh | cc2e932 | 2015-05-22 18:59:37 +0900 | [diff] [blame] | 777 | return qspi_trigger_transfer_out_in(rspi, xfer->tx_buf, |
Hiep Cao Minh | 4b6fe3e | 2014-10-23 12:14:13 +0900 | [diff] [blame] | 778 | xfer->rx_buf, xfer->len); |
Geert Uytterhoeven | 340a15e | 2014-01-24 09:43:57 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 781 | static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) |
| 782 | { |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 783 | const u8 *tx = xfer->tx_buf; |
| 784 | unsigned int n = xfer->len; |
| 785 | unsigned int i, len; |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 786 | int ret; |
| 787 | |
Geert Uytterhoeven | 85912a8 | 2014-07-09 12:26:22 +0200 | [diff] [blame] | 788 | if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { |
| 789 | ret = rspi_dma_transfer(rspi, &xfer->tx_sg, NULL); |
| 790 | if (ret != -EAGAIN) |
| 791 | return ret; |
| 792 | } |
Geert Uytterhoeven | 4f12b5e | 2014-06-02 15:38:17 +0200 | [diff] [blame] | 793 | |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 794 | while (n > 0) { |
| 795 | len = qspi_set_send_trigger(rspi, n); |
| 796 | if (len == QSPI_BUFFER_SIZE) { |
| 797 | ret = rspi_wait_for_tx_empty(rspi); |
| 798 | if (ret < 0) { |
| 799 | dev_err(&rspi->master->dev, "transmit timeout\n"); |
| 800 | return ret; |
| 801 | } |
| 802 | for (i = 0; i < len; i++) |
| 803 | rspi_write_data(rspi, *tx++); |
| 804 | } else { |
DongCV | ad16d4a | 2017-02-15 19:50:52 +0900 | [diff] [blame] | 805 | ret = rspi_pio_transfer(rspi, tx, NULL, len); |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 806 | if (ret < 0) |
| 807 | return ret; |
| 808 | } |
| 809 | n -= len; |
| 810 | } |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 811 | |
| 812 | /* Wait for the last transmission */ |
Geert Uytterhoeven | 5f684c3 | 2014-06-02 15:38:03 +0200 | [diff] [blame] | 813 | rspi_wait_for_tx_empty(rspi); |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) |
| 819 | { |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 820 | u8 *rx = xfer->rx_buf; |
| 821 | unsigned int n = xfer->len; |
| 822 | unsigned int i, len; |
| 823 | int ret; |
| 824 | |
Geert Uytterhoeven | 85912a8 | 2014-07-09 12:26:22 +0200 | [diff] [blame] | 825 | if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { |
| 826 | int ret = rspi_dma_transfer(rspi, NULL, &xfer->rx_sg); |
| 827 | if (ret != -EAGAIN) |
| 828 | return ret; |
| 829 | } |
Geert Uytterhoeven | 4f12b5e | 2014-06-02 15:38:17 +0200 | [diff] [blame] | 830 | |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 831 | while (n > 0) { |
| 832 | len = qspi_set_receive_trigger(rspi, n); |
| 833 | if (len == QSPI_BUFFER_SIZE) { |
| 834 | ret = rspi_wait_for_rx_full(rspi); |
| 835 | if (ret < 0) { |
| 836 | dev_err(&rspi->master->dev, "receive timeout\n"); |
| 837 | return ret; |
| 838 | } |
| 839 | for (i = 0; i < len; i++) |
| 840 | *rx++ = rspi_read_data(rspi); |
| 841 | } else { |
DongCV | ad16d4a | 2017-02-15 19:50:52 +0900 | [diff] [blame] | 842 | ret = rspi_pio_transfer(rspi, NULL, rx, len); |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 843 | if (ret < 0) |
| 844 | return ret; |
Arnd Bergmann | db30083 | 2016-11-08 14:46:12 +0100 | [diff] [blame] | 845 | } |
| 846 | n -= len; |
| 847 | } |
| 848 | |
| 849 | return 0; |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 850 | } |
| 851 | |
Geert Uytterhoeven | eb557f7 | 2014-01-24 09:43:55 +0100 | [diff] [blame] | 852 | static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi, |
| 853 | struct spi_transfer *xfer) |
| 854 | { |
| 855 | struct rspi_data *rspi = spi_master_get_devdata(master); |
Geert Uytterhoeven | eb557f7 | 2014-01-24 09:43:55 +0100 | [diff] [blame] | 856 | |
Geert Uytterhoeven | ba824d4 | 2014-02-21 17:29:18 +0100 | [diff] [blame] | 857 | if (spi->mode & SPI_LOOP) { |
| 858 | return qspi_transfer_out_in(rspi, xfer); |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 859 | } else if (xfer->tx_nbits > SPI_NBITS_SINGLE) { |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 860 | /* Quad or Dual SPI Write */ |
| 861 | return qspi_transfer_out(rspi, xfer); |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 862 | } else if (xfer->rx_nbits > SPI_NBITS_SINGLE) { |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 863 | /* Quad or Dual SPI Read */ |
| 864 | return qspi_transfer_in(rspi, xfer); |
| 865 | } else { |
| 866 | /* Single SPI Transfer */ |
| 867 | return qspi_transfer_out_in(rspi, xfer); |
| 868 | } |
Geert Uytterhoeven | eb557f7 | 2014-01-24 09:43:55 +0100 | [diff] [blame] | 869 | } |
| 870 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 871 | static int rspi_setup(struct spi_device *spi) |
| 872 | { |
| 873 | struct rspi_data *rspi = spi_master_get_devdata(spi->master); |
| 874 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 875 | rspi->max_speed_hz = spi->max_speed_hz; |
| 876 | |
Geert Uytterhoeven | 348e515 | 2014-01-12 11:27:43 +0100 | [diff] [blame] | 877 | rspi->spcmd = SPCMD_SSLKP; |
| 878 | if (spi->mode & SPI_CPOL) |
| 879 | rspi->spcmd |= SPCMD_CPOL; |
| 880 | if (spi->mode & SPI_CPHA) |
| 881 | rspi->spcmd |= SPCMD_CPHA; |
| 882 | |
Geert Uytterhoeven | 06a7a3c | 2014-01-24 09:44:00 +0100 | [diff] [blame] | 883 | /* CMOS output mode and MOSI signal from previous transfer */ |
| 884 | rspi->sppcr = 0; |
| 885 | if (spi->mode & SPI_LOOP) |
| 886 | rspi->sppcr |= SPPCR_SPLP; |
| 887 | |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 888 | set_config_register(rspi, 8); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 893 | static u16 qspi_transfer_mode(const struct spi_transfer *xfer) |
| 894 | { |
| 895 | if (xfer->tx_buf) |
| 896 | switch (xfer->tx_nbits) { |
| 897 | case SPI_NBITS_QUAD: |
| 898 | return SPCMD_SPIMOD_QUAD; |
| 899 | case SPI_NBITS_DUAL: |
| 900 | return SPCMD_SPIMOD_DUAL; |
| 901 | default: |
| 902 | return 0; |
| 903 | } |
| 904 | if (xfer->rx_buf) |
| 905 | switch (xfer->rx_nbits) { |
| 906 | case SPI_NBITS_QUAD: |
| 907 | return SPCMD_SPIMOD_QUAD | SPCMD_SPRW; |
| 908 | case SPI_NBITS_DUAL: |
| 909 | return SPCMD_SPIMOD_DUAL | SPCMD_SPRW; |
| 910 | default: |
| 911 | return 0; |
| 912 | } |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static int qspi_setup_sequencer(struct rspi_data *rspi, |
| 918 | const struct spi_message *msg) |
| 919 | { |
| 920 | const struct spi_transfer *xfer; |
| 921 | unsigned int i = 0, len = 0; |
| 922 | u16 current_mode = 0xffff, mode; |
| 923 | |
| 924 | list_for_each_entry(xfer, &msg->transfers, transfer_list) { |
| 925 | mode = qspi_transfer_mode(xfer); |
| 926 | if (mode == current_mode) { |
| 927 | len += xfer->len; |
| 928 | continue; |
| 929 | } |
| 930 | |
| 931 | /* Transfer mode change */ |
| 932 | if (i) { |
| 933 | /* Set transfer data length of previous transfer */ |
| 934 | rspi_write32(rspi, len, QSPI_SPBMUL(i - 1)); |
| 935 | } |
| 936 | |
| 937 | if (i >= QSPI_NUM_SPCMD) { |
| 938 | dev_err(&msg->spi->dev, |
| 939 | "Too many different transfer modes"); |
| 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | /* Program transfer mode for this transfer */ |
| 944 | rspi_write16(rspi, rspi->spcmd | mode, RSPI_SPCMD(i)); |
| 945 | current_mode = mode; |
| 946 | len = xfer->len; |
| 947 | i++; |
| 948 | } |
| 949 | if (i) { |
| 950 | /* Set final transfer data length and sequence length */ |
| 951 | rspi_write32(rspi, len, QSPI_SPBMUL(i - 1)); |
| 952 | rspi_write8(rspi, i - 1, RSPI_SPSCR); |
| 953 | } |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 958 | static int rspi_prepare_message(struct spi_master *master, |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 959 | struct spi_message *msg) |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 960 | { |
| 961 | struct rspi_data *rspi = spi_master_get_devdata(master); |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 962 | int ret; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 963 | |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 964 | if (msg->spi->mode & |
| 965 | (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD)) { |
| 966 | /* Setup sequencer for messages with multiple transfer modes */ |
| 967 | ret = qspi_setup_sequencer(rspi, msg); |
| 968 | if (ret < 0) |
| 969 | return ret; |
| 970 | } |
| 971 | |
| 972 | /* Enable SPI function in master mode */ |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 973 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_SPE, RSPI_SPCR); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 977 | static int rspi_unprepare_message(struct spi_master *master, |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 978 | struct spi_message *msg) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 979 | { |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 980 | struct rspi_data *rspi = spi_master_get_devdata(master); |
| 981 | |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 982 | /* Disable SPI function */ |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 983 | rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR); |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 984 | |
| 985 | /* Reset sequencer for Single SPI Transfers */ |
| 986 | rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0); |
| 987 | rspi_write8(rspi, 0, RSPI_SPSCR); |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 988 | return 0; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 989 | } |
| 990 | |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 991 | static irqreturn_t rspi_irq_mux(int irq, void *_sr) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 992 | { |
Geert Uytterhoeven | c132f09 | 2013-12-24 10:49:31 +0100 | [diff] [blame] | 993 | struct rspi_data *rspi = _sr; |
Geert Uytterhoeven | 97b95c1 | 2013-12-24 10:49:34 +0100 | [diff] [blame] | 994 | u8 spsr; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 995 | irqreturn_t ret = IRQ_NONE; |
Geert Uytterhoeven | 97b95c1 | 2013-12-24 10:49:34 +0100 | [diff] [blame] | 996 | u8 disable_irq = 0; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 997 | |
| 998 | rspi->spsr = spsr = rspi_read8(rspi, RSPI_SPSR); |
| 999 | if (spsr & SPSR_SPRF) |
| 1000 | disable_irq |= SPCR_SPRIE; |
| 1001 | if (spsr & SPSR_SPTEF) |
| 1002 | disable_irq |= SPCR_SPTIE; |
| 1003 | |
| 1004 | if (disable_irq) { |
| 1005 | ret = IRQ_HANDLED; |
| 1006 | rspi_disable_irq(rspi, disable_irq); |
| 1007 | wake_up(&rspi->wait); |
| 1008 | } |
| 1009 | |
| 1010 | return ret; |
| 1011 | } |
| 1012 | |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1013 | static irqreturn_t rspi_irq_rx(int irq, void *_sr) |
| 1014 | { |
| 1015 | struct rspi_data *rspi = _sr; |
| 1016 | u8 spsr; |
| 1017 | |
| 1018 | rspi->spsr = spsr = rspi_read8(rspi, RSPI_SPSR); |
| 1019 | if (spsr & SPSR_SPRF) { |
| 1020 | rspi_disable_irq(rspi, SPCR_SPRIE); |
| 1021 | wake_up(&rspi->wait); |
| 1022 | return IRQ_HANDLED; |
| 1023 | } |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | static irqreturn_t rspi_irq_tx(int irq, void *_sr) |
| 1029 | { |
| 1030 | struct rspi_data *rspi = _sr; |
| 1031 | u8 spsr; |
| 1032 | |
| 1033 | rspi->spsr = spsr = rspi_read8(rspi, RSPI_SPSR); |
| 1034 | if (spsr & SPSR_SPTEF) { |
| 1035 | rspi_disable_irq(rspi, SPCR_SPTIE); |
| 1036 | wake_up(&rspi->wait); |
| 1037 | return IRQ_HANDLED; |
| 1038 | } |
| 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1043 | static struct dma_chan *rspi_request_dma_chan(struct device *dev, |
| 1044 | enum dma_transfer_direction dir, |
| 1045 | unsigned int id, |
| 1046 | dma_addr_t port_addr) |
| 1047 | { |
| 1048 | dma_cap_mask_t mask; |
| 1049 | struct dma_chan *chan; |
| 1050 | struct dma_slave_config cfg; |
| 1051 | int ret; |
| 1052 | |
| 1053 | dma_cap_zero(mask); |
| 1054 | dma_cap_set(DMA_SLAVE, mask); |
| 1055 | |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1056 | chan = dma_request_slave_channel_compat(mask, shdma_chan_filter, |
| 1057 | (void *)(unsigned long)id, dev, |
| 1058 | dir == DMA_MEM_TO_DEV ? "tx" : "rx"); |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1059 | if (!chan) { |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1060 | dev_warn(dev, "dma_request_slave_channel_compat failed\n"); |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1061 | return NULL; |
| 1062 | } |
| 1063 | |
| 1064 | memset(&cfg, 0, sizeof(cfg)); |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1065 | cfg.direction = dir; |
Geert Uytterhoeven | a30b95a7 | 2014-08-06 14:59:01 +0200 | [diff] [blame] | 1066 | if (dir == DMA_MEM_TO_DEV) { |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1067 | cfg.dst_addr = port_addr; |
Geert Uytterhoeven | a30b95a7 | 2014-08-06 14:59:01 +0200 | [diff] [blame] | 1068 | cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 1069 | } else { |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1070 | cfg.src_addr = port_addr; |
Geert Uytterhoeven | a30b95a7 | 2014-08-06 14:59:01 +0200 | [diff] [blame] | 1071 | cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 1072 | } |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1073 | |
| 1074 | ret = dmaengine_slave_config(chan, &cfg); |
| 1075 | if (ret) { |
| 1076 | dev_warn(dev, "dmaengine_slave_config failed %d\n", ret); |
| 1077 | dma_release_channel(chan); |
| 1078 | return NULL; |
| 1079 | } |
| 1080 | |
| 1081 | return chan; |
| 1082 | } |
| 1083 | |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1084 | static int rspi_request_dma(struct device *dev, struct spi_master *master, |
Geert Uytterhoeven | fcdc49a | 2014-06-02 15:38:10 +0200 | [diff] [blame] | 1085 | const struct resource *res) |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1086 | { |
Geert Uytterhoeven | fcdc49a | 2014-06-02 15:38:10 +0200 | [diff] [blame] | 1087 | const struct rspi_plat_data *rspi_pd = dev_get_platdata(dev); |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1088 | unsigned int dma_tx_id, dma_rx_id; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1089 | |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1090 | if (dev->of_node) { |
| 1091 | /* In the OF case we will get the slave IDs from the DT */ |
| 1092 | dma_tx_id = 0; |
| 1093 | dma_rx_id = 0; |
| 1094 | } else if (rspi_pd && rspi_pd->dma_tx_id && rspi_pd->dma_rx_id) { |
| 1095 | dma_tx_id = rspi_pd->dma_tx_id; |
| 1096 | dma_rx_id = rspi_pd->dma_rx_id; |
| 1097 | } else { |
| 1098 | /* The driver assumes no error. */ |
| 1099 | return 0; |
| 1100 | } |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1101 | |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1102 | master->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id, |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1103 | res->start + RSPI_SPDR); |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1104 | if (!master->dma_tx) |
Geert Uytterhoeven | 5f338d0 | 2014-06-02 15:38:11 +0200 | [diff] [blame] | 1105 | return -ENODEV; |
Geert Uytterhoeven | 65bf220 | 2014-06-02 15:38:09 +0200 | [diff] [blame] | 1106 | |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1107 | master->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id, |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1108 | res->start + RSPI_SPDR); |
Geert Uytterhoeven | e825b8d | 2014-08-06 14:59:02 +0200 | [diff] [blame] | 1109 | if (!master->dma_rx) { |
| 1110 | dma_release_channel(master->dma_tx); |
| 1111 | master->dma_tx = NULL; |
Geert Uytterhoeven | 5f338d0 | 2014-06-02 15:38:11 +0200 | [diff] [blame] | 1112 | return -ENODEV; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1113 | } |
Shimoda, Yoshihiro | 0243c536 | 2012-08-02 17:17:33 +0900 | [diff] [blame] | 1114 | |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1115 | master->can_dma = rspi_can_dma; |
Geert Uytterhoeven | 5f338d0 | 2014-06-02 15:38:11 +0200 | [diff] [blame] | 1116 | dev_info(dev, "DMA available"); |
Shimoda, Yoshihiro | 0243c536 | 2012-08-02 17:17:33 +0900 | [diff] [blame] | 1117 | return 0; |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1118 | } |
| 1119 | |
Geert Uytterhoeven | afcc98d | 2014-06-06 13:38:43 +0200 | [diff] [blame] | 1120 | static void rspi_release_dma(struct spi_master *master) |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1121 | { |
Geert Uytterhoeven | afcc98d | 2014-06-06 13:38:43 +0200 | [diff] [blame] | 1122 | if (master->dma_tx) |
| 1123 | dma_release_channel(master->dma_tx); |
| 1124 | if (master->dma_rx) |
| 1125 | dma_release_channel(master->dma_rx); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1126 | } |
| 1127 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1128 | static int rspi_remove(struct platform_device *pdev) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1129 | { |
Laurent Pinchart | 5ffbe2d | 2013-11-27 01:41:45 +0100 | [diff] [blame] | 1130 | struct rspi_data *rspi = platform_get_drvdata(pdev); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1131 | |
Geert Uytterhoeven | afcc98d | 2014-06-06 13:38:43 +0200 | [diff] [blame] | 1132 | rspi_release_dma(rspi->master); |
Geert Uytterhoeven | 490c977 | 2014-03-11 10:59:12 +0100 | [diff] [blame] | 1133 | pm_runtime_disable(&pdev->dev); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1138 | static const struct spi_ops rspi_ops = { |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 1139 | .set_config_register = rspi_set_config_register, |
| 1140 | .transfer_one = rspi_transfer_one, |
| 1141 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, |
| 1142 | .flags = SPI_MASTER_MUST_TX, |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1143 | .fifo_size = 8, |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1144 | }; |
| 1145 | |
| 1146 | static const struct spi_ops rspi_rz_ops = { |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 1147 | .set_config_register = rspi_rz_set_config_register, |
| 1148 | .transfer_one = rspi_rz_transfer_one, |
| 1149 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP, |
| 1150 | .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1151 | .fifo_size = 8, /* 8 for TX, 32 for RX */ |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1152 | }; |
| 1153 | |
| 1154 | static const struct spi_ops qspi_ops = { |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 1155 | .set_config_register = qspi_set_config_register, |
| 1156 | .transfer_one = qspi_transfer_one, |
| 1157 | .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP | |
| 1158 | SPI_TX_DUAL | SPI_TX_QUAD | |
| 1159 | SPI_RX_DUAL | SPI_RX_QUAD, |
| 1160 | .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX, |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1161 | .fifo_size = 32, |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1162 | }; |
| 1163 | |
| 1164 | #ifdef CONFIG_OF |
| 1165 | static const struct of_device_id rspi_of_match[] = { |
| 1166 | /* RSPI on legacy SH */ |
| 1167 | { .compatible = "renesas,rspi", .data = &rspi_ops }, |
| 1168 | /* RSPI on RZ/A1H */ |
| 1169 | { .compatible = "renesas,rspi-rz", .data = &rspi_rz_ops }, |
| 1170 | /* QSPI on R-Car Gen2 */ |
| 1171 | { .compatible = "renesas,qspi", .data = &qspi_ops }, |
| 1172 | { /* sentinel */ } |
| 1173 | }; |
| 1174 | |
| 1175 | MODULE_DEVICE_TABLE(of, rspi_of_match); |
| 1176 | |
| 1177 | static int rspi_parse_dt(struct device *dev, struct spi_master *master) |
| 1178 | { |
| 1179 | u32 num_cs; |
| 1180 | int error; |
| 1181 | |
| 1182 | /* Parse DT properties */ |
| 1183 | error = of_property_read_u32(dev->of_node, "num-cs", &num_cs); |
| 1184 | if (error) { |
| 1185 | dev_err(dev, "of_property_read_u32 num-cs failed %d\n", error); |
| 1186 | return error; |
| 1187 | } |
| 1188 | |
| 1189 | master->num_chipselect = num_cs; |
| 1190 | return 0; |
| 1191 | } |
| 1192 | #else |
Shimoda, Yoshihiro | 64b67de | 2014-02-03 10:43:46 +0900 | [diff] [blame] | 1193 | #define rspi_of_match NULL |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1194 | static inline int rspi_parse_dt(struct device *dev, struct spi_master *master) |
| 1195 | { |
| 1196 | return -EINVAL; |
| 1197 | } |
| 1198 | #endif /* CONFIG_OF */ |
| 1199 | |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1200 | static int rspi_request_irq(struct device *dev, unsigned int irq, |
| 1201 | irq_handler_t handler, const char *suffix, |
| 1202 | void *dev_id) |
| 1203 | { |
Geert Uytterhoeven | 4393745 | 2014-08-06 14:59:00 +0200 | [diff] [blame] | 1204 | const char *name = devm_kasprintf(dev, GFP_KERNEL, "%s:%s", |
| 1205 | dev_name(dev), suffix); |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1206 | if (!name) |
| 1207 | return -ENOMEM; |
Geert Uytterhoeven | 4393745 | 2014-08-06 14:59:00 +0200 | [diff] [blame] | 1208 | |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1209 | return devm_request_irq(dev, irq, handler, 0, name, dev_id); |
| 1210 | } |
| 1211 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1212 | static int rspi_probe(struct platform_device *pdev) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1213 | { |
| 1214 | struct resource *res; |
| 1215 | struct spi_master *master; |
| 1216 | struct rspi_data *rspi; |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1217 | int ret; |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1218 | const struct rspi_plat_data *rspi_pd; |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1219 | const struct spi_ops *ops; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1220 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1221 | master = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data)); |
Geert Uytterhoeven | ffcfae3 | 2017-01-04 11:15:07 +0100 | [diff] [blame] | 1222 | if (master == NULL) |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1223 | return -ENOMEM; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1224 | |
Geert Uytterhoeven | 219a7bc | 2017-10-04 14:19:53 +0200 | [diff] [blame] | 1225 | ops = of_device_get_match_data(&pdev->dev); |
| 1226 | if (ops) { |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1227 | ret = rspi_parse_dt(&pdev->dev, master); |
| 1228 | if (ret) |
| 1229 | goto error1; |
| 1230 | } else { |
| 1231 | ops = (struct spi_ops *)pdev->id_entry->driver_data; |
| 1232 | rspi_pd = dev_get_platdata(&pdev->dev); |
| 1233 | if (rspi_pd && rspi_pd->num_chipselect) |
| 1234 | master->num_chipselect = rspi_pd->num_chipselect; |
| 1235 | else |
| 1236 | master->num_chipselect = 2; /* default */ |
Geert Uytterhoeven | d64b472 | 2014-08-06 14:58:59 +0200 | [diff] [blame] | 1237 | } |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1238 | |
| 1239 | /* ops parameter check */ |
| 1240 | if (!ops->set_config_register) { |
| 1241 | dev_err(&pdev->dev, "there is no set_config_register\n"); |
| 1242 | ret = -ENODEV; |
| 1243 | goto error1; |
| 1244 | } |
| 1245 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1246 | rspi = spi_master_get_devdata(master); |
Jingoo Han | 24b5a82 | 2013-05-23 19:20:40 +0900 | [diff] [blame] | 1247 | platform_set_drvdata(pdev, rspi); |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1248 | rspi->ops = ops; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1249 | rspi->master = master; |
Laurent Pinchart | 5d79e9a | 2013-11-27 01:41:46 +0100 | [diff] [blame] | 1250 | |
| 1251 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1252 | rspi->addr = devm_ioremap_resource(&pdev->dev, res); |
| 1253 | if (IS_ERR(rspi->addr)) { |
| 1254 | ret = PTR_ERR(rspi->addr); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1255 | goto error1; |
| 1256 | } |
| 1257 | |
Geert Uytterhoeven | 29f397b | 2014-01-24 09:44:02 +0100 | [diff] [blame] | 1258 | rspi->clk = devm_clk_get(&pdev->dev, NULL); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1259 | if (IS_ERR(rspi->clk)) { |
| 1260 | dev_err(&pdev->dev, "cannot get clock\n"); |
| 1261 | ret = PTR_ERR(rspi->clk); |
Laurent Pinchart | 5d79e9a | 2013-11-27 01:41:46 +0100 | [diff] [blame] | 1262 | goto error1; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1263 | } |
Geert Uytterhoeven | 17fe0d9 | 2014-01-24 09:44:01 +0100 | [diff] [blame] | 1264 | |
Geert Uytterhoeven | 490c977 | 2014-03-11 10:59:12 +0100 | [diff] [blame] | 1265 | pm_runtime_enable(&pdev->dev); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1266 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1267 | init_waitqueue_head(&rspi->wait); |
| 1268 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1269 | master->bus_num = pdev->id; |
| 1270 | master->setup = rspi_setup; |
Geert Uytterhoeven | 490c977 | 2014-03-11 10:59:12 +0100 | [diff] [blame] | 1271 | master->auto_runtime_pm = true; |
Geert Uytterhoeven | eb557f7 | 2014-01-24 09:43:55 +0100 | [diff] [blame] | 1272 | master->transfer_one = ops->transfer_one; |
Geert Uytterhoeven | 79d2349 | 2014-01-24 09:43:52 +0100 | [diff] [blame] | 1273 | master->prepare_message = rspi_prepare_message; |
| 1274 | master->unprepare_message = rspi_unprepare_message; |
Geert Uytterhoeven | 880c6d1 | 2014-01-30 09:43:50 +0100 | [diff] [blame] | 1275 | master->mode_bits = ops->mode_bits; |
Geert Uytterhoeven | b42e035 | 2014-06-02 15:38:06 +0200 | [diff] [blame] | 1276 | master->flags = ops->flags; |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1277 | master->dev.of_node = pdev->dev.of_node; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1278 | |
Geert Uytterhoeven | 9372220 | 2014-01-24 09:43:58 +0100 | [diff] [blame] | 1279 | ret = platform_get_irq_byname(pdev, "rx"); |
| 1280 | if (ret < 0) { |
| 1281 | ret = platform_get_irq_byname(pdev, "mux"); |
| 1282 | if (ret < 0) |
| 1283 | ret = platform_get_irq(pdev, 0); |
| 1284 | if (ret >= 0) |
| 1285 | rspi->rx_irq = rspi->tx_irq = ret; |
| 1286 | } else { |
| 1287 | rspi->rx_irq = ret; |
| 1288 | ret = platform_get_irq_byname(pdev, "tx"); |
| 1289 | if (ret >= 0) |
| 1290 | rspi->tx_irq = ret; |
| 1291 | } |
| 1292 | if (ret < 0) { |
| 1293 | dev_err(&pdev->dev, "platform_get_irq error\n"); |
| 1294 | goto error2; |
| 1295 | } |
| 1296 | |
| 1297 | if (rspi->rx_irq == rspi->tx_irq) { |
| 1298 | /* Single multiplexed interrupt */ |
| 1299 | ret = rspi_request_irq(&pdev->dev, rspi->rx_irq, rspi_irq_mux, |
| 1300 | "mux", rspi); |
| 1301 | } else { |
| 1302 | /* Multi-interrupt mode, only SPRI and SPTI are used */ |
| 1303 | ret = rspi_request_irq(&pdev->dev, rspi->rx_irq, rspi_irq_rx, |
| 1304 | "rx", rspi); |
| 1305 | if (!ret) |
| 1306 | ret = rspi_request_irq(&pdev->dev, rspi->tx_irq, |
| 1307 | rspi_irq_tx, "tx", rspi); |
| 1308 | } |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1309 | if (ret < 0) { |
| 1310 | dev_err(&pdev->dev, "request_irq error\n"); |
Geert Uytterhoeven | fcb4ed7 | 2014-01-14 10:20:33 +0100 | [diff] [blame] | 1311 | goto error2; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1312 | } |
| 1313 | |
Geert Uytterhoeven | 2f777ec | 2014-06-02 15:38:12 +0200 | [diff] [blame] | 1314 | ret = rspi_request_dma(&pdev->dev, master, res); |
Geert Uytterhoeven | 27e105a | 2014-06-02 15:38:08 +0200 | [diff] [blame] | 1315 | if (ret < 0) |
| 1316 | dev_warn(&pdev->dev, "DMA not available, using PIO\n"); |
Shimoda, Yoshihiro | a3633fe | 2012-04-20 14:50:36 +0900 | [diff] [blame] | 1317 | |
Jingoo Han | 9e03d05 | 2013-12-04 14:13:50 +0900 | [diff] [blame] | 1318 | ret = devm_spi_register_master(&pdev->dev, master); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1319 | if (ret < 0) { |
| 1320 | dev_err(&pdev->dev, "spi_register_master error.\n"); |
Geert Uytterhoeven | fcb4ed7 | 2014-01-14 10:20:33 +0100 | [diff] [blame] | 1321 | goto error3; |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | dev_info(&pdev->dev, "probed\n"); |
| 1325 | |
| 1326 | return 0; |
| 1327 | |
Geert Uytterhoeven | fcb4ed7 | 2014-01-14 10:20:33 +0100 | [diff] [blame] | 1328 | error3: |
Geert Uytterhoeven | afcc98d | 2014-06-06 13:38:43 +0200 | [diff] [blame] | 1329 | rspi_release_dma(master); |
Geert Uytterhoeven | fcb4ed7 | 2014-01-14 10:20:33 +0100 | [diff] [blame] | 1330 | error2: |
Geert Uytterhoeven | 490c977 | 2014-03-11 10:59:12 +0100 | [diff] [blame] | 1331 | pm_runtime_disable(&pdev->dev); |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1332 | error1: |
| 1333 | spi_master_put(master); |
| 1334 | |
| 1335 | return ret; |
| 1336 | } |
| 1337 | |
Krzysztof Kozlowski | 8634daf | 2015-05-02 00:44:05 +0900 | [diff] [blame] | 1338 | static const struct platform_device_id spi_driver_ids[] = { |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1339 | { "rspi", (kernel_ulong_t)&rspi_ops }, |
Geert Uytterhoeven | 862d357 | 2014-01-24 09:43:59 +0100 | [diff] [blame] | 1340 | { "rspi-rz", (kernel_ulong_t)&rspi_rz_ops }, |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1341 | { "qspi", (kernel_ulong_t)&qspi_ops }, |
| 1342 | {}, |
| 1343 | }; |
| 1344 | |
| 1345 | MODULE_DEVICE_TABLE(platform, spi_driver_ids); |
| 1346 | |
Geert Uytterhoeven | c1ca59c | 2018-09-05 10:49:38 +0200 | [diff] [blame] | 1347 | #ifdef CONFIG_PM_SLEEP |
| 1348 | static int rspi_suspend(struct device *dev) |
| 1349 | { |
Wolfram Sang | be0bf62 | 2018-10-21 22:00:45 +0200 | [diff] [blame] | 1350 | struct rspi_data *rspi = dev_get_drvdata(dev); |
Geert Uytterhoeven | c1ca59c | 2018-09-05 10:49:38 +0200 | [diff] [blame] | 1351 | |
| 1352 | return spi_master_suspend(rspi->master); |
| 1353 | } |
| 1354 | |
| 1355 | static int rspi_resume(struct device *dev) |
| 1356 | { |
Wolfram Sang | be0bf62 | 2018-10-21 22:00:45 +0200 | [diff] [blame] | 1357 | struct rspi_data *rspi = dev_get_drvdata(dev); |
Geert Uytterhoeven | c1ca59c | 2018-09-05 10:49:38 +0200 | [diff] [blame] | 1358 | |
| 1359 | return spi_master_resume(rspi->master); |
| 1360 | } |
| 1361 | |
| 1362 | static SIMPLE_DEV_PM_OPS(rspi_pm_ops, rspi_suspend, rspi_resume); |
| 1363 | #define DEV_PM_OPS &rspi_pm_ops |
| 1364 | #else |
| 1365 | #define DEV_PM_OPS NULL |
| 1366 | #endif /* CONFIG_PM_SLEEP */ |
| 1367 | |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1368 | static struct platform_driver rspi_driver = { |
| 1369 | .probe = rspi_probe, |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1370 | .remove = rspi_remove, |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1371 | .id_table = spi_driver_ids, |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1372 | .driver = { |
Hiep Cao Minh | 5ce0ba8 | 2013-09-03 13:10:26 +0900 | [diff] [blame] | 1373 | .name = "renesas_spi", |
Geert Uytterhoeven | c1ca59c | 2018-09-05 10:49:38 +0200 | [diff] [blame] | 1374 | .pm = DEV_PM_OPS, |
Geert Uytterhoeven | 426ef76 | 2014-01-28 10:21:38 +0100 | [diff] [blame] | 1375 | .of_match_table = of_match_ptr(rspi_of_match), |
Shimoda, Yoshihiro | 0b2182d | 2012-03-07 14:46:25 +0900 | [diff] [blame] | 1376 | }, |
| 1377 | }; |
| 1378 | module_platform_driver(rspi_driver); |
| 1379 | |
| 1380 | MODULE_DESCRIPTION("Renesas RSPI bus driver"); |
| 1381 | MODULE_LICENSE("GPL v2"); |
| 1382 | MODULE_AUTHOR("Yoshihiro Shimoda"); |
| 1383 | MODULE_ALIAS("platform:rspi"); |