Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * SPI bus driver for CSR SiRFprimaII |
| 3 | * |
| 4 | * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company. |
| 5 | * |
| 6 | * Licensed under GPLv2 or later. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/clk.h> |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 13 | #include <linux/completion.h> |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/of.h> |
| 17 | #include <linux/bitops.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/of_gpio.h> |
| 21 | #include <linux/spi/spi.h> |
| 22 | #include <linux/spi/spi_bitbang.h> |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 23 | #include <linux/dmaengine.h> |
| 24 | #include <linux/dma-direction.h> |
| 25 | #include <linux/dma-mapping.h> |
Qipan Li | 8509c55 | 2014-11-20 22:33:07 +0800 | [diff] [blame] | 26 | #include <linux/reset.h> |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 27 | |
| 28 | #define DRIVER_NAME "sirfsoc_spi" |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 29 | /* SPI CTRL register defines */ |
| 30 | #define SIRFSOC_SPI_SLV_MODE BIT(16) |
| 31 | #define SIRFSOC_SPI_CMD_MODE BIT(17) |
| 32 | #define SIRFSOC_SPI_CS_IO_OUT BIT(18) |
| 33 | #define SIRFSOC_SPI_CS_IO_MODE BIT(19) |
| 34 | #define SIRFSOC_SPI_CLK_IDLE_STAT BIT(20) |
| 35 | #define SIRFSOC_SPI_CS_IDLE_STAT BIT(21) |
| 36 | #define SIRFSOC_SPI_TRAN_MSB BIT(22) |
| 37 | #define SIRFSOC_SPI_DRV_POS_EDGE BIT(23) |
| 38 | #define SIRFSOC_SPI_CS_HOLD_TIME BIT(24) |
| 39 | #define SIRFSOC_SPI_CLK_SAMPLE_MODE BIT(25) |
| 40 | #define SIRFSOC_SPI_TRAN_DAT_FORMAT_8 (0 << 26) |
| 41 | #define SIRFSOC_SPI_TRAN_DAT_FORMAT_12 (1 << 26) |
| 42 | #define SIRFSOC_SPI_TRAN_DAT_FORMAT_16 (2 << 26) |
| 43 | #define SIRFSOC_SPI_TRAN_DAT_FORMAT_32 (3 << 26) |
Qipan Li | 9593e61 | 2014-09-02 17:02:36 +0800 | [diff] [blame] | 44 | #define SIRFSOC_SPI_CMD_BYTE_NUM(x) ((x & 3) << 28) |
| 45 | #define SIRFSOC_SPI_ENA_AUTO_CLR BIT(30) |
| 46 | #define SIRFSOC_SPI_MUL_DAT_MODE BIT(31) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 47 | |
| 48 | /* Interrupt Enable */ |
Qipan Li | 9593e61 | 2014-09-02 17:02:36 +0800 | [diff] [blame] | 49 | #define SIRFSOC_SPI_RX_DONE_INT_EN BIT(0) |
| 50 | #define SIRFSOC_SPI_TX_DONE_INT_EN BIT(1) |
| 51 | #define SIRFSOC_SPI_RX_OFLOW_INT_EN BIT(2) |
| 52 | #define SIRFSOC_SPI_TX_UFLOW_INT_EN BIT(3) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 53 | #define SIRFSOC_SPI_RX_IO_DMA_INT_EN BIT(4) |
| 54 | #define SIRFSOC_SPI_TX_IO_DMA_INT_EN BIT(5) |
| 55 | #define SIRFSOC_SPI_RXFIFO_FULL_INT_EN BIT(6) |
| 56 | #define SIRFSOC_SPI_TXFIFO_EMPTY_INT_EN BIT(7) |
| 57 | #define SIRFSOC_SPI_RXFIFO_THD_INT_EN BIT(8) |
| 58 | #define SIRFSOC_SPI_TXFIFO_THD_INT_EN BIT(9) |
| 59 | #define SIRFSOC_SPI_FRM_END_INT_EN BIT(10) |
| 60 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 61 | /* Interrupt status */ |
| 62 | #define SIRFSOC_SPI_RX_DONE BIT(0) |
| 63 | #define SIRFSOC_SPI_TX_DONE BIT(1) |
| 64 | #define SIRFSOC_SPI_RX_OFLOW BIT(2) |
| 65 | #define SIRFSOC_SPI_TX_UFLOW BIT(3) |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 66 | #define SIRFSOC_SPI_RX_IO_DMA BIT(4) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 67 | #define SIRFSOC_SPI_RX_FIFO_FULL BIT(6) |
| 68 | #define SIRFSOC_SPI_TXFIFO_EMPTY BIT(7) |
| 69 | #define SIRFSOC_SPI_RXFIFO_THD_REACH BIT(8) |
| 70 | #define SIRFSOC_SPI_TXFIFO_THD_REACH BIT(9) |
| 71 | #define SIRFSOC_SPI_FRM_END BIT(10) |
| 72 | |
| 73 | /* TX RX enable */ |
| 74 | #define SIRFSOC_SPI_RX_EN BIT(0) |
| 75 | #define SIRFSOC_SPI_TX_EN BIT(1) |
| 76 | #define SIRFSOC_SPI_CMD_TX_EN BIT(2) |
| 77 | |
| 78 | #define SIRFSOC_SPI_IO_MODE_SEL BIT(0) |
| 79 | #define SIRFSOC_SPI_RX_DMA_FLUSH BIT(2) |
| 80 | |
| 81 | /* FIFO OPs */ |
| 82 | #define SIRFSOC_SPI_FIFO_RESET BIT(0) |
| 83 | #define SIRFSOC_SPI_FIFO_START BIT(1) |
| 84 | |
| 85 | /* FIFO CTRL */ |
| 86 | #define SIRFSOC_SPI_FIFO_WIDTH_BYTE (0 << 0) |
| 87 | #define SIRFSOC_SPI_FIFO_WIDTH_WORD (1 << 0) |
| 88 | #define SIRFSOC_SPI_FIFO_WIDTH_DWORD (2 << 0) |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 89 | /* USP related */ |
| 90 | #define SIRFSOC_USP_SYNC_MODE BIT(0) |
| 91 | #define SIRFSOC_USP_SLV_MODE BIT(1) |
| 92 | #define SIRFSOC_USP_LSB BIT(4) |
| 93 | #define SIRFSOC_USP_EN BIT(5) |
| 94 | #define SIRFSOC_USP_RXD_FALLING_EDGE BIT(6) |
| 95 | #define SIRFSOC_USP_TXD_FALLING_EDGE BIT(7) |
| 96 | #define SIRFSOC_USP_CS_HIGH_VALID BIT(9) |
| 97 | #define SIRFSOC_USP_SCLK_IDLE_STAT BIT(11) |
| 98 | #define SIRFSOC_USP_TFS_IO_MODE BIT(14) |
| 99 | #define SIRFSOC_USP_TFS_IO_INPUT BIT(19) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 100 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 101 | #define SIRFSOC_USP_RXD_DELAY_LEN_MASK 0xFF |
| 102 | #define SIRFSOC_USP_TXD_DELAY_LEN_MASK 0xFF |
| 103 | #define SIRFSOC_USP_RXD_DELAY_OFFSET 0 |
| 104 | #define SIRFSOC_USP_TXD_DELAY_OFFSET 8 |
| 105 | #define SIRFSOC_USP_RXD_DELAY_LEN 1 |
| 106 | #define SIRFSOC_USP_TXD_DELAY_LEN 1 |
| 107 | #define SIRFSOC_USP_CLK_DIVISOR_OFFSET 21 |
| 108 | #define SIRFSOC_USP_CLK_DIVISOR_MASK 0x3FF |
| 109 | #define SIRFSOC_USP_CLK_10_11_MASK 0x3 |
| 110 | #define SIRFSOC_USP_CLK_10_11_OFFSET 30 |
| 111 | #define SIRFSOC_USP_CLK_12_15_MASK 0xF |
| 112 | #define SIRFSOC_USP_CLK_12_15_OFFSET 24 |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 113 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 114 | #define SIRFSOC_USP_TX_DATA_OFFSET 0 |
| 115 | #define SIRFSOC_USP_TX_SYNC_OFFSET 8 |
| 116 | #define SIRFSOC_USP_TX_FRAME_OFFSET 16 |
| 117 | #define SIRFSOC_USP_TX_SHIFTER_OFFSET 24 |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 118 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 119 | #define SIRFSOC_USP_TX_DATA_MASK 0xFF |
| 120 | #define SIRFSOC_USP_TX_SYNC_MASK 0xFF |
| 121 | #define SIRFSOC_USP_TX_FRAME_MASK 0xFF |
| 122 | #define SIRFSOC_USP_TX_SHIFTER_MASK 0x1F |
| 123 | |
| 124 | #define SIRFSOC_USP_RX_DATA_OFFSET 0 |
| 125 | #define SIRFSOC_USP_RX_FRAME_OFFSET 8 |
| 126 | #define SIRFSOC_USP_RX_SHIFTER_OFFSET 16 |
| 127 | |
| 128 | #define SIRFSOC_USP_RX_DATA_MASK 0xFF |
| 129 | #define SIRFSOC_USP_RX_FRAME_MASK 0xFF |
| 130 | #define SIRFSOC_USP_RX_SHIFTER_MASK 0x1F |
| 131 | #define SIRFSOC_USP_CS_HIGH_VALUE BIT(1) |
| 132 | |
| 133 | #define SIRFSOC_SPI_FIFO_SC_OFFSET 0 |
| 134 | #define SIRFSOC_SPI_FIFO_LC_OFFSET 10 |
| 135 | #define SIRFSOC_SPI_FIFO_HC_OFFSET 20 |
| 136 | |
| 137 | #define SIRFSOC_SPI_FIFO_FULL_MASK(s) (1 << ((s)->fifo_full_offset)) |
| 138 | #define SIRFSOC_SPI_FIFO_EMPTY_MASK(s) (1 << ((s)->fifo_full_offset + 1)) |
| 139 | #define SIRFSOC_SPI_FIFO_THD_MASK(s) ((s)->fifo_size - 1) |
| 140 | #define SIRFSOC_SPI_FIFO_THD_OFFSET 2 |
| 141 | #define SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(s, val) \ |
| 142 | ((val) & (s)->fifo_level_chk_mask) |
| 143 | |
| 144 | enum sirf_spi_type { |
| 145 | SIRF_REAL_SPI, |
| 146 | SIRF_USP_SPI_P2, |
| 147 | SIRF_USP_SPI_A7, |
| 148 | }; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 149 | |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 150 | /* |
| 151 | * only if the rx/tx buffer and transfer size are 4-bytes aligned, we use dma |
| 152 | * due to the limitation of dma controller |
| 153 | */ |
| 154 | |
| 155 | #define ALIGNED(x) (!((u32)x & 0x3)) |
| 156 | #define IS_DMA_VALID(x) (x && ALIGNED(x->tx_buf) && ALIGNED(x->rx_buf) && \ |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 157 | ALIGNED(x->len) && (x->len < 2 * PAGE_SIZE)) |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 158 | |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 159 | #define SIRFSOC_MAX_CMD_BYTES 4 |
Qipan Li | fcc50e5 | 2014-11-17 23:17:03 +0800 | [diff] [blame] | 160 | #define SIRFSOC_SPI_DEFAULT_FRQ 1000000 |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 161 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 162 | struct sirf_spi_register { |
| 163 | /*SPI and USP-SPI common*/ |
| 164 | u32 tx_rx_en; |
| 165 | u32 int_en; |
| 166 | u32 int_st; |
| 167 | u32 tx_dma_io_ctrl; |
| 168 | u32 tx_dma_io_len; |
| 169 | u32 txfifo_ctrl; |
| 170 | u32 txfifo_level_chk; |
| 171 | u32 txfifo_op; |
| 172 | u32 txfifo_st; |
| 173 | u32 txfifo_data; |
| 174 | u32 rx_dma_io_ctrl; |
| 175 | u32 rx_dma_io_len; |
| 176 | u32 rxfifo_ctrl; |
| 177 | u32 rxfifo_level_chk; |
| 178 | u32 rxfifo_op; |
| 179 | u32 rxfifo_st; |
| 180 | u32 rxfifo_data; |
| 181 | /*SPI self*/ |
| 182 | u32 spi_ctrl; |
| 183 | u32 spi_cmd; |
| 184 | u32 spi_dummy_delay_ctrl; |
| 185 | /*USP-SPI self*/ |
| 186 | u32 usp_mode1; |
| 187 | u32 usp_mode2; |
| 188 | u32 usp_tx_frame_ctrl; |
| 189 | u32 usp_rx_frame_ctrl; |
| 190 | u32 usp_pin_io_data; |
| 191 | u32 usp_risc_dsp_mode; |
| 192 | u32 usp_async_param_reg; |
| 193 | u32 usp_irda_x_mode_div; |
| 194 | u32 usp_sm_cfg; |
| 195 | u32 usp_int_en_clr; |
| 196 | }; |
| 197 | |
| 198 | static const struct sirf_spi_register real_spi_register = { |
| 199 | .tx_rx_en = 0x8, |
| 200 | .int_en = 0xc, |
| 201 | .int_st = 0x10, |
| 202 | .tx_dma_io_ctrl = 0x100, |
| 203 | .tx_dma_io_len = 0x104, |
| 204 | .txfifo_ctrl = 0x108, |
| 205 | .txfifo_level_chk = 0x10c, |
| 206 | .txfifo_op = 0x110, |
| 207 | .txfifo_st = 0x114, |
| 208 | .txfifo_data = 0x118, |
| 209 | .rx_dma_io_ctrl = 0x120, |
| 210 | .rx_dma_io_len = 0x124, |
| 211 | .rxfifo_ctrl = 0x128, |
| 212 | .rxfifo_level_chk = 0x12c, |
| 213 | .rxfifo_op = 0x130, |
| 214 | .rxfifo_st = 0x134, |
| 215 | .rxfifo_data = 0x138, |
| 216 | .spi_ctrl = 0x0, |
| 217 | .spi_cmd = 0x4, |
| 218 | .spi_dummy_delay_ctrl = 0x144, |
| 219 | }; |
| 220 | |
| 221 | static const struct sirf_spi_register usp_spi_register = { |
| 222 | .tx_rx_en = 0x10, |
| 223 | .int_en = 0x14, |
| 224 | .int_st = 0x18, |
| 225 | .tx_dma_io_ctrl = 0x100, |
| 226 | .tx_dma_io_len = 0x104, |
| 227 | .txfifo_ctrl = 0x108, |
| 228 | .txfifo_level_chk = 0x10c, |
| 229 | .txfifo_op = 0x110, |
| 230 | .txfifo_st = 0x114, |
| 231 | .txfifo_data = 0x118, |
| 232 | .rx_dma_io_ctrl = 0x120, |
| 233 | .rx_dma_io_len = 0x124, |
| 234 | .rxfifo_ctrl = 0x128, |
| 235 | .rxfifo_level_chk = 0x12c, |
| 236 | .rxfifo_op = 0x130, |
| 237 | .rxfifo_st = 0x134, |
| 238 | .rxfifo_data = 0x138, |
| 239 | .usp_mode1 = 0x0, |
| 240 | .usp_mode2 = 0x4, |
| 241 | .usp_tx_frame_ctrl = 0x8, |
| 242 | .usp_rx_frame_ctrl = 0xc, |
| 243 | .usp_pin_io_data = 0x1c, |
| 244 | .usp_risc_dsp_mode = 0x20, |
| 245 | .usp_async_param_reg = 0x24, |
| 246 | .usp_irda_x_mode_div = 0x28, |
| 247 | .usp_sm_cfg = 0x2c, |
| 248 | .usp_int_en_clr = 0x140, |
| 249 | }; |
| 250 | |
| 251 | struct sirf_spi_comp_data { |
| 252 | const struct sirf_spi_register *regs; |
| 253 | enum sirf_spi_type type; |
| 254 | unsigned int dat_max_frm_len; |
| 255 | unsigned int fifo_size; |
| 256 | }; |
| 257 | |
| 258 | static const struct sirf_spi_comp_data sirf_real_spi = { |
| 259 | .regs = &real_spi_register, |
| 260 | .type = SIRF_REAL_SPI, |
| 261 | .dat_max_frm_len = 64 * 1024, |
| 262 | .fifo_size = 256, |
| 263 | }; |
| 264 | |
| 265 | static const struct sirf_spi_comp_data sirf_usp_spi_p2 = { |
| 266 | .regs = &usp_spi_register, |
| 267 | .type = SIRF_USP_SPI_P2, |
| 268 | .dat_max_frm_len = 1024 * 1024, |
| 269 | .fifo_size = 128, |
| 270 | }; |
| 271 | |
| 272 | static const struct sirf_spi_comp_data sirf_usp_spi_a7 = { |
| 273 | .regs = &usp_spi_register, |
| 274 | .type = SIRF_USP_SPI_A7, |
| 275 | .dat_max_frm_len = 1024 * 1024, |
| 276 | .fifo_size = 512, |
| 277 | }; |
| 278 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 279 | struct sirfsoc_spi { |
| 280 | struct spi_bitbang bitbang; |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 281 | struct completion rx_done; |
| 282 | struct completion tx_done; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 283 | |
| 284 | void __iomem *base; |
| 285 | u32 ctrl_freq; /* SPI controller clock speed */ |
| 286 | struct clk *clk; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 287 | |
| 288 | /* rx & tx bufs from the spi_transfer */ |
| 289 | const void *tx; |
| 290 | void *rx; |
| 291 | |
| 292 | /* place received word into rx buffer */ |
| 293 | void (*rx_word) (struct sirfsoc_spi *); |
| 294 | /* get word from tx buffer for sending */ |
| 295 | void (*tx_word) (struct sirfsoc_spi *); |
| 296 | |
| 297 | /* number of words left to be tranmitted/received */ |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 298 | unsigned int left_tx_word; |
| 299 | unsigned int left_rx_word; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 300 | |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 301 | /* rx & tx DMA channels */ |
| 302 | struct dma_chan *rx_chan; |
| 303 | struct dma_chan *tx_chan; |
| 304 | dma_addr_t src_start; |
| 305 | dma_addr_t dst_start; |
| 306 | void *dummypage; |
| 307 | int word_width; /* in bytes */ |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 308 | |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 309 | /* |
| 310 | * if tx size is not more than 4 and rx size is NULL, use |
| 311 | * command model |
| 312 | */ |
| 313 | bool tx_by_cmd; |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 314 | bool hw_cs; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 315 | enum sirf_spi_type type; |
| 316 | const struct sirf_spi_register *regs; |
| 317 | unsigned int fifo_size; |
| 318 | /* fifo empty offset is (fifo full offset + 1)*/ |
| 319 | unsigned int fifo_full_offset; |
| 320 | /* fifo_level_chk_mask is (fifo_size/4 - 1) */ |
| 321 | unsigned int fifo_level_chk_mask; |
| 322 | unsigned int dat_max_frm_len; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | static void spi_sirfsoc_rx_word_u8(struct sirfsoc_spi *sspi) |
| 326 | { |
| 327 | u32 data; |
| 328 | u8 *rx = sspi->rx; |
| 329 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 330 | data = readl(sspi->base + sspi->regs->rxfifo_data); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 331 | |
| 332 | if (rx) { |
| 333 | *rx++ = (u8) data; |
| 334 | sspi->rx = rx; |
| 335 | } |
| 336 | |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 337 | sspi->left_rx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void spi_sirfsoc_tx_word_u8(struct sirfsoc_spi *sspi) |
| 341 | { |
| 342 | u32 data = 0; |
| 343 | const u8 *tx = sspi->tx; |
| 344 | |
| 345 | if (tx) { |
| 346 | data = *tx++; |
| 347 | sspi->tx = tx; |
| 348 | } |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 349 | writel(data, sspi->base + sspi->regs->txfifo_data); |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 350 | sspi->left_tx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void spi_sirfsoc_rx_word_u16(struct sirfsoc_spi *sspi) |
| 354 | { |
| 355 | u32 data; |
| 356 | u16 *rx = sspi->rx; |
| 357 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 358 | data = readl(sspi->base + sspi->regs->rxfifo_data); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 359 | |
| 360 | if (rx) { |
| 361 | *rx++ = (u16) data; |
| 362 | sspi->rx = rx; |
| 363 | } |
| 364 | |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 365 | sspi->left_rx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static void spi_sirfsoc_tx_word_u16(struct sirfsoc_spi *sspi) |
| 369 | { |
| 370 | u32 data = 0; |
| 371 | const u16 *tx = sspi->tx; |
| 372 | |
| 373 | if (tx) { |
| 374 | data = *tx++; |
| 375 | sspi->tx = tx; |
| 376 | } |
| 377 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 378 | writel(data, sspi->base + sspi->regs->txfifo_data); |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 379 | sspi->left_tx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | static void spi_sirfsoc_rx_word_u32(struct sirfsoc_spi *sspi) |
| 383 | { |
| 384 | u32 data; |
| 385 | u32 *rx = sspi->rx; |
| 386 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 387 | data = readl(sspi->base + sspi->regs->rxfifo_data); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 388 | |
| 389 | if (rx) { |
| 390 | *rx++ = (u32) data; |
| 391 | sspi->rx = rx; |
| 392 | } |
| 393 | |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 394 | sspi->left_rx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 395 | |
| 396 | } |
| 397 | |
| 398 | static void spi_sirfsoc_tx_word_u32(struct sirfsoc_spi *sspi) |
| 399 | { |
| 400 | u32 data = 0; |
| 401 | const u32 *tx = sspi->tx; |
| 402 | |
| 403 | if (tx) { |
| 404 | data = *tx++; |
| 405 | sspi->tx = tx; |
| 406 | } |
| 407 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 408 | writel(data, sspi->base + sspi->regs->txfifo_data); |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 409 | sspi->left_tx_word--; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 410 | } |
| 411 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 412 | static irqreturn_t spi_sirfsoc_irq(int irq, void *dev_id) |
| 413 | { |
| 414 | struct sirfsoc_spi *sspi = dev_id; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 415 | u32 spi_stat; |
| 416 | |
| 417 | spi_stat = readl(sspi->base + sspi->regs->int_st); |
| 418 | if (sspi->tx_by_cmd && sspi->type == SIRF_REAL_SPI |
| 419 | && (spi_stat & SIRFSOC_SPI_FRM_END)) { |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 420 | complete(&sspi->tx_done); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 421 | writel(0x0, sspi->base + sspi->regs->int_en); |
| 422 | writel(readl(sspi->base + sspi->regs->int_st), |
| 423 | sspi->base + sspi->regs->int_st); |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 424 | return IRQ_HANDLED; |
| 425 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 426 | /* Error Conditions */ |
| 427 | if (spi_stat & SIRFSOC_SPI_RX_OFLOW || |
| 428 | spi_stat & SIRFSOC_SPI_TX_UFLOW) { |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 429 | complete(&sspi->tx_done); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 430 | complete(&sspi->rx_done); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 431 | switch (sspi->type) { |
| 432 | case SIRF_REAL_SPI: |
| 433 | case SIRF_USP_SPI_P2: |
| 434 | writel(0x0, sspi->base + sspi->regs->int_en); |
| 435 | break; |
| 436 | case SIRF_USP_SPI_A7: |
| 437 | writel(~0UL, sspi->base + sspi->regs->usp_int_en_clr); |
| 438 | break; |
| 439 | } |
| 440 | writel(readl(sspi->base + sspi->regs->int_st), |
| 441 | sspi->base + sspi->regs->int_st); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 442 | return IRQ_HANDLED; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 443 | } |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 444 | if (spi_stat & SIRFSOC_SPI_TXFIFO_EMPTY) |
| 445 | complete(&sspi->tx_done); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 446 | while (!(readl(sspi->base + sspi->regs->int_st) & |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 447 | SIRFSOC_SPI_RX_IO_DMA)) |
| 448 | cpu_relax(); |
| 449 | complete(&sspi->rx_done); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 450 | switch (sspi->type) { |
| 451 | case SIRF_REAL_SPI: |
| 452 | case SIRF_USP_SPI_P2: |
| 453 | writel(0x0, sspi->base + sspi->regs->int_en); |
| 454 | break; |
| 455 | case SIRF_USP_SPI_A7: |
| 456 | writel(~0UL, sspi->base + sspi->regs->usp_int_en_clr); |
| 457 | break; |
| 458 | } |
| 459 | writel(readl(sspi->base + sspi->regs->int_st), |
| 460 | sspi->base + sspi->regs->int_st); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 461 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 462 | return IRQ_HANDLED; |
| 463 | } |
| 464 | |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 465 | static void spi_sirfsoc_dma_fini_callback(void *data) |
| 466 | { |
| 467 | struct completion *dma_complete = data; |
| 468 | |
| 469 | complete(dma_complete); |
| 470 | } |
| 471 | |
Qipan Li | 0021d97 | 2014-09-02 17:01:04 +0800 | [diff] [blame] | 472 | static void spi_sirfsoc_cmd_transfer(struct spi_device *spi, |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 473 | struct spi_transfer *t) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 474 | { |
| 475 | struct sirfsoc_spi *sspi; |
| 476 | int timeout = t->len * 10; |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 477 | u32 cmd; |
| 478 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 479 | sspi = spi_master_get_devdata(spi->master); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 480 | writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + sspi->regs->txfifo_op); |
| 481 | writel(SIRFSOC_SPI_FIFO_START, sspi->base + sspi->regs->txfifo_op); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 482 | memcpy(&cmd, sspi->tx, t->len); |
| 483 | if (sspi->word_width == 1 && !(spi->mode & SPI_LSB_FIRST)) |
| 484 | cmd = cpu_to_be32(cmd) >> |
| 485 | ((SIRFSOC_MAX_CMD_BYTES - t->len) * 8); |
| 486 | if (sspi->word_width == 2 && t->len == 4 && |
| 487 | (!(spi->mode & SPI_LSB_FIRST))) |
| 488 | cmd = ((cmd & 0xffff) << 16) | (cmd >> 16); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 489 | writel(cmd, sspi->base + sspi->regs->spi_cmd); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 490 | writel(SIRFSOC_SPI_FRM_END_INT_EN, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 491 | sspi->base + sspi->regs->int_en); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 492 | writel(SIRFSOC_SPI_CMD_TX_EN, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 493 | sspi->base + sspi->regs->tx_rx_en); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 494 | if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { |
| 495 | dev_err(&spi->dev, "cmd transfer timeout\n"); |
Qipan Li | 0021d97 | 2014-09-02 17:01:04 +0800 | [diff] [blame] | 496 | return; |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 497 | } |
Qipan Li | 0021d97 | 2014-09-02 17:01:04 +0800 | [diff] [blame] | 498 | sspi->left_rx_word -= t->len; |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static void spi_sirfsoc_dma_transfer(struct spi_device *spi, |
| 502 | struct spi_transfer *t) |
| 503 | { |
| 504 | struct sirfsoc_spi *sspi; |
| 505 | struct dma_async_tx_descriptor *rx_desc, *tx_desc; |
| 506 | int timeout = t->len * 10; |
| 507 | |
| 508 | sspi = spi_master_get_devdata(spi->master); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 509 | writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + sspi->regs->rxfifo_op); |
| 510 | writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + sspi->regs->txfifo_op); |
| 511 | switch (sspi->type) { |
| 512 | case SIRF_REAL_SPI: |
| 513 | writel(SIRFSOC_SPI_FIFO_START, |
| 514 | sspi->base + sspi->regs->rxfifo_op); |
| 515 | writel(SIRFSOC_SPI_FIFO_START, |
| 516 | sspi->base + sspi->regs->txfifo_op); |
| 517 | writel(0, sspi->base + sspi->regs->int_en); |
| 518 | break; |
| 519 | case SIRF_USP_SPI_P2: |
| 520 | writel(0x0, sspi->base + sspi->regs->rxfifo_op); |
| 521 | writel(0x0, sspi->base + sspi->regs->txfifo_op); |
| 522 | writel(0, sspi->base + sspi->regs->int_en); |
| 523 | break; |
| 524 | case SIRF_USP_SPI_A7: |
| 525 | writel(0x0, sspi->base + sspi->regs->rxfifo_op); |
| 526 | writel(0x0, sspi->base + sspi->regs->txfifo_op); |
| 527 | writel(~0UL, sspi->base + sspi->regs->usp_int_en_clr); |
| 528 | break; |
| 529 | } |
| 530 | writel(readl(sspi->base + sspi->regs->int_st), |
| 531 | sspi->base + sspi->regs->int_st); |
| 532 | if (sspi->left_tx_word < sspi->dat_max_frm_len) { |
| 533 | switch (sspi->type) { |
| 534 | case SIRF_REAL_SPI: |
| 535 | writel(readl(sspi->base + sspi->regs->spi_ctrl) | |
| 536 | SIRFSOC_SPI_ENA_AUTO_CLR | |
| 537 | SIRFSOC_SPI_MUL_DAT_MODE, |
| 538 | sspi->base + sspi->regs->spi_ctrl); |
| 539 | writel(sspi->left_tx_word - 1, |
| 540 | sspi->base + sspi->regs->tx_dma_io_len); |
| 541 | writel(sspi->left_tx_word - 1, |
| 542 | sspi->base + sspi->regs->rx_dma_io_len); |
| 543 | break; |
| 544 | case SIRF_USP_SPI_P2: |
| 545 | case SIRF_USP_SPI_A7: |
| 546 | /*USP simulate SPI, tx/rx_dma_io_len indicates bytes*/ |
| 547 | writel(sspi->left_tx_word * sspi->word_width, |
| 548 | sspi->base + sspi->regs->tx_dma_io_len); |
| 549 | writel(sspi->left_tx_word * sspi->word_width, |
| 550 | sspi->base + sspi->regs->rx_dma_io_len); |
| 551 | break; |
| 552 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 553 | } else { |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 554 | if (sspi->type == SIRF_REAL_SPI) |
| 555 | writel(readl(sspi->base + sspi->regs->spi_ctrl), |
| 556 | sspi->base + sspi->regs->spi_ctrl); |
| 557 | writel(0, sspi->base + sspi->regs->tx_dma_io_len); |
| 558 | writel(0, sspi->base + sspi->regs->rx_dma_io_len); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 559 | } |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 560 | sspi->dst_start = dma_map_single(&spi->dev, sspi->rx, t->len, |
| 561 | (t->tx_buf != t->rx_buf) ? |
| 562 | DMA_FROM_DEVICE : DMA_BIDIRECTIONAL); |
| 563 | rx_desc = dmaengine_prep_slave_single(sspi->rx_chan, |
| 564 | sspi->dst_start, t->len, DMA_DEV_TO_MEM, |
| 565 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 566 | rx_desc->callback = spi_sirfsoc_dma_fini_callback; |
| 567 | rx_desc->callback_param = &sspi->rx_done; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 568 | |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 569 | sspi->src_start = dma_map_single(&spi->dev, (void *)sspi->tx, t->len, |
| 570 | (t->tx_buf != t->rx_buf) ? |
| 571 | DMA_TO_DEVICE : DMA_BIDIRECTIONAL); |
| 572 | tx_desc = dmaengine_prep_slave_single(sspi->tx_chan, |
| 573 | sspi->src_start, t->len, DMA_MEM_TO_DEV, |
| 574 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 575 | tx_desc->callback = spi_sirfsoc_dma_fini_callback; |
| 576 | tx_desc->callback_param = &sspi->tx_done; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 577 | |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 578 | dmaengine_submit(tx_desc); |
| 579 | dmaengine_submit(rx_desc); |
| 580 | dma_async_issue_pending(sspi->tx_chan); |
| 581 | dma_async_issue_pending(sspi->rx_chan); |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 582 | writel(SIRFSOC_SPI_RX_EN | SIRFSOC_SPI_TX_EN, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 583 | sspi->base + sspi->regs->tx_rx_en); |
| 584 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 585 | sspi->type == SIRF_USP_SPI_A7) { |
| 586 | writel(SIRFSOC_SPI_FIFO_START, |
| 587 | sspi->base + sspi->regs->rxfifo_op); |
| 588 | writel(SIRFSOC_SPI_FIFO_START, |
| 589 | sspi->base + sspi->regs->txfifo_op); |
| 590 | } |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 591 | if (wait_for_completion_timeout(&sspi->rx_done, timeout) == 0) { |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 592 | dev_err(&spi->dev, "transfer timeout\n"); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 593 | dmaengine_terminate_all(sspi->rx_chan); |
| 594 | } else |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 595 | sspi->left_rx_word = 0; |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 596 | /* |
| 597 | * we only wait tx-done event if transferring by DMA. for PIO, |
| 598 | * we get rx data by writing tx data, so if rx is done, tx has |
| 599 | * done earlier |
| 600 | */ |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 601 | if (wait_for_completion_timeout(&sspi->tx_done, timeout) == 0) { |
| 602 | dev_err(&spi->dev, "transfer timeout\n"); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 603 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 604 | sspi->type == SIRF_USP_SPI_A7) |
| 605 | writel(0, sspi->base + sspi->regs->tx_rx_en); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 606 | dmaengine_terminate_all(sspi->tx_chan); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 607 | } |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 608 | dma_unmap_single(&spi->dev, sspi->src_start, t->len, DMA_TO_DEVICE); |
| 609 | dma_unmap_single(&spi->dev, sspi->dst_start, t->len, DMA_FROM_DEVICE); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 610 | /* TX, RX FIFO stop */ |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 611 | writel(0, sspi->base + sspi->regs->rxfifo_op); |
| 612 | writel(0, sspi->base + sspi->regs->txfifo_op); |
| 613 | if (sspi->left_tx_word >= sspi->dat_max_frm_len) |
| 614 | writel(0, sspi->base + sspi->regs->tx_rx_en); |
| 615 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 616 | sspi->type == SIRF_USP_SPI_A7) |
| 617 | writel(0, sspi->base + sspi->regs->tx_rx_en); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static void spi_sirfsoc_pio_transfer(struct spi_device *spi, |
| 621 | struct spi_transfer *t) |
| 622 | { |
| 623 | struct sirfsoc_spi *sspi; |
| 624 | int timeout = t->len * 10; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 625 | unsigned int data_units; |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 626 | |
| 627 | sspi = spi_master_get_devdata(spi->master); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 628 | do { |
| 629 | writel(SIRFSOC_SPI_FIFO_RESET, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 630 | sspi->base + sspi->regs->rxfifo_op); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 631 | writel(SIRFSOC_SPI_FIFO_RESET, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 632 | sspi->base + sspi->regs->txfifo_op); |
| 633 | switch (sspi->type) { |
| 634 | case SIRF_USP_SPI_P2: |
| 635 | writel(0x0, sspi->base + sspi->regs->rxfifo_op); |
| 636 | writel(0x0, sspi->base + sspi->regs->txfifo_op); |
| 637 | writel(0, sspi->base + sspi->regs->int_en); |
| 638 | writel(readl(sspi->base + sspi->regs->int_st), |
| 639 | sspi->base + sspi->regs->int_st); |
| 640 | writel(min((sspi->left_tx_word * sspi->word_width), |
| 641 | sspi->fifo_size), |
| 642 | sspi->base + sspi->regs->tx_dma_io_len); |
| 643 | writel(min((sspi->left_rx_word * sspi->word_width), |
| 644 | sspi->fifo_size), |
| 645 | sspi->base + sspi->regs->rx_dma_io_len); |
| 646 | break; |
| 647 | case SIRF_USP_SPI_A7: |
| 648 | writel(0x0, sspi->base + sspi->regs->rxfifo_op); |
| 649 | writel(0x0, sspi->base + sspi->regs->txfifo_op); |
| 650 | writel(~0UL, sspi->base + sspi->regs->usp_int_en_clr); |
| 651 | writel(readl(sspi->base + sspi->regs->int_st), |
| 652 | sspi->base + sspi->regs->int_st); |
| 653 | writel(min((sspi->left_tx_word * sspi->word_width), |
| 654 | sspi->fifo_size), |
| 655 | sspi->base + sspi->regs->tx_dma_io_len); |
| 656 | writel(min((sspi->left_rx_word * sspi->word_width), |
| 657 | sspi->fifo_size), |
| 658 | sspi->base + sspi->regs->rx_dma_io_len); |
| 659 | break; |
| 660 | case SIRF_REAL_SPI: |
| 661 | writel(SIRFSOC_SPI_FIFO_START, |
| 662 | sspi->base + sspi->regs->rxfifo_op); |
| 663 | writel(SIRFSOC_SPI_FIFO_START, |
| 664 | sspi->base + sspi->regs->txfifo_op); |
| 665 | writel(0, sspi->base + sspi->regs->int_en); |
| 666 | writel(readl(sspi->base + sspi->regs->int_st), |
| 667 | sspi->base + sspi->regs->int_st); |
| 668 | writel(readl(sspi->base + sspi->regs->spi_ctrl) | |
| 669 | SIRFSOC_SPI_MUL_DAT_MODE | |
| 670 | SIRFSOC_SPI_ENA_AUTO_CLR, |
| 671 | sspi->base + sspi->regs->spi_ctrl); |
| 672 | data_units = sspi->fifo_size / sspi->word_width; |
| 673 | writel(min(sspi->left_tx_word, data_units) - 1, |
| 674 | sspi->base + sspi->regs->tx_dma_io_len); |
| 675 | writel(min(sspi->left_rx_word, data_units) - 1, |
| 676 | sspi->base + sspi->regs->rx_dma_io_len); |
| 677 | break; |
| 678 | } |
| 679 | while (!((readl(sspi->base + sspi->regs->txfifo_st) |
| 680 | & SIRFSOC_SPI_FIFO_FULL_MASK(sspi))) && |
| 681 | sspi->left_tx_word) |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 682 | sspi->tx_word(sspi); |
| 683 | writel(SIRFSOC_SPI_TXFIFO_EMPTY_INT_EN | |
| 684 | SIRFSOC_SPI_TX_UFLOW_INT_EN | |
Qipan Li | f2a08b4 | 2014-09-02 17:01:03 +0800 | [diff] [blame] | 685 | SIRFSOC_SPI_RX_OFLOW_INT_EN | |
| 686 | SIRFSOC_SPI_RX_IO_DMA_INT_EN, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 687 | sspi->base + sspi->regs->int_en); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 688 | writel(SIRFSOC_SPI_RX_EN | SIRFSOC_SPI_TX_EN, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 689 | sspi->base + sspi->regs->tx_rx_en); |
| 690 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 691 | sspi->type == SIRF_USP_SPI_A7) { |
| 692 | writel(SIRFSOC_SPI_FIFO_START, |
| 693 | sspi->base + sspi->regs->rxfifo_op); |
| 694 | writel(SIRFSOC_SPI_FIFO_START, |
| 695 | sspi->base + sspi->regs->txfifo_op); |
| 696 | } |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 697 | if (!wait_for_completion_timeout(&sspi->tx_done, timeout) || |
| 698 | !wait_for_completion_timeout(&sspi->rx_done, timeout)) { |
| 699 | dev_err(&spi->dev, "transfer timeout\n"); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 700 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 701 | sspi->type == SIRF_USP_SPI_A7) |
| 702 | writel(0, sspi->base + sspi->regs->tx_rx_en); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 703 | break; |
| 704 | } |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 705 | while (!((readl(sspi->base + sspi->regs->rxfifo_st) |
| 706 | & SIRFSOC_SPI_FIFO_EMPTY_MASK(sspi))) && |
| 707 | sspi->left_rx_word) |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 708 | sspi->rx_word(sspi); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 709 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 710 | sspi->type == SIRF_USP_SPI_A7) |
| 711 | writel(0, sspi->base + sspi->regs->tx_rx_en); |
| 712 | writel(0, sspi->base + sspi->regs->rxfifo_op); |
| 713 | writel(0, sspi->base + sspi->regs->txfifo_op); |
Qipan Li | 41148c3 | 2014-05-04 14:32:36 +0800 | [diff] [blame] | 714 | } while (sspi->left_tx_word != 0 || sspi->left_rx_word != 0); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static int spi_sirfsoc_transfer(struct spi_device *spi, struct spi_transfer *t) |
| 718 | { |
| 719 | struct sirfsoc_spi *sspi; |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 720 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 721 | sspi = spi_master_get_devdata(spi->master); |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 722 | sspi->tx = t->tx_buf ? t->tx_buf : sspi->dummypage; |
| 723 | sspi->rx = t->rx_buf ? t->rx_buf : sspi->dummypage; |
| 724 | sspi->left_tx_word = sspi->left_rx_word = t->len / sspi->word_width; |
| 725 | reinit_completion(&sspi->rx_done); |
| 726 | reinit_completion(&sspi->tx_done); |
| 727 | /* |
| 728 | * in the transfer, if transfer data using command register with rx_buf |
| 729 | * null, just fill command data into command register and wait for its |
| 730 | * completion. |
| 731 | */ |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 732 | if (sspi->type == SIRF_REAL_SPI && sspi->tx_by_cmd) |
Qipan Li | c908ef3 | 2014-04-15 15:24:59 +0800 | [diff] [blame] | 733 | spi_sirfsoc_cmd_transfer(spi, t); |
| 734 | else if (IS_DMA_VALID(t)) |
| 735 | spi_sirfsoc_dma_transfer(spi, t); |
| 736 | else |
| 737 | spi_sirfsoc_pio_transfer(spi, t); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 738 | |
Qipan Li | 692fb0f | 2013-08-25 21:42:50 +0800 | [diff] [blame] | 739 | return t->len - sspi->left_rx_word * sspi->word_width; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static void spi_sirfsoc_chipselect(struct spi_device *spi, int value) |
| 743 | { |
| 744 | struct sirfsoc_spi *sspi = spi_master_get_devdata(spi->master); |
| 745 | |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 746 | if (sspi->hw_cs) { |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 747 | u32 regval; |
| 748 | |
| 749 | switch (sspi->type) { |
| 750 | case SIRF_REAL_SPI: |
| 751 | regval = readl(sspi->base + sspi->regs->spi_ctrl); |
| 752 | switch (value) { |
| 753 | case BITBANG_CS_ACTIVE: |
| 754 | if (spi->mode & SPI_CS_HIGH) |
| 755 | regval |= SIRFSOC_SPI_CS_IO_OUT; |
| 756 | else |
| 757 | regval &= ~SIRFSOC_SPI_CS_IO_OUT; |
| 758 | break; |
| 759 | case BITBANG_CS_INACTIVE: |
| 760 | if (spi->mode & SPI_CS_HIGH) |
| 761 | regval &= ~SIRFSOC_SPI_CS_IO_OUT; |
| 762 | else |
| 763 | regval |= SIRFSOC_SPI_CS_IO_OUT; |
| 764 | break; |
| 765 | } |
| 766 | writel(regval, sspi->base + sspi->regs->spi_ctrl); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 767 | break; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 768 | case SIRF_USP_SPI_P2: |
| 769 | case SIRF_USP_SPI_A7: |
| 770 | regval = readl(sspi->base + |
| 771 | sspi->regs->usp_pin_io_data); |
| 772 | switch (value) { |
| 773 | case BITBANG_CS_ACTIVE: |
| 774 | if (spi->mode & SPI_CS_HIGH) |
| 775 | regval |= SIRFSOC_USP_CS_HIGH_VALUE; |
| 776 | else |
| 777 | regval &= ~(SIRFSOC_USP_CS_HIGH_VALUE); |
| 778 | break; |
| 779 | case BITBANG_CS_INACTIVE: |
| 780 | if (spi->mode & SPI_CS_HIGH) |
| 781 | regval &= ~(SIRFSOC_USP_CS_HIGH_VALUE); |
| 782 | else |
| 783 | regval |= SIRFSOC_USP_CS_HIGH_VALUE; |
| 784 | break; |
| 785 | } |
| 786 | writel(regval, |
| 787 | sspi->base + sspi->regs->usp_pin_io_data); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 788 | break; |
| 789 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 790 | } else { |
Qipan Li | 6ee8a2f | 2014-04-14 14:29:59 +0800 | [diff] [blame] | 791 | switch (value) { |
| 792 | case BITBANG_CS_ACTIVE: |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 793 | gpio_direction_output(spi->cs_gpio, |
Qipan Li | 6ee8a2f | 2014-04-14 14:29:59 +0800 | [diff] [blame] | 794 | spi->mode & SPI_CS_HIGH ? 1 : 0); |
| 795 | break; |
| 796 | case BITBANG_CS_INACTIVE: |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 797 | gpio_direction_output(spi->cs_gpio, |
Qipan Li | 6ee8a2f | 2014-04-14 14:29:59 +0800 | [diff] [blame] | 798 | spi->mode & SPI_CS_HIGH ? 0 : 1); |
| 799 | break; |
| 800 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 804 | static int spi_sirfsoc_config_mode(struct spi_device *spi) |
| 805 | { |
| 806 | struct sirfsoc_spi *sspi; |
| 807 | u32 regval, usp_mode1; |
| 808 | |
| 809 | sspi = spi_master_get_devdata(spi->master); |
| 810 | regval = readl(sspi->base + sspi->regs->spi_ctrl); |
| 811 | usp_mode1 = readl(sspi->base + sspi->regs->usp_mode1); |
| 812 | if (!(spi->mode & SPI_CS_HIGH)) { |
| 813 | regval |= SIRFSOC_SPI_CS_IDLE_STAT; |
| 814 | usp_mode1 &= ~SIRFSOC_USP_CS_HIGH_VALID; |
| 815 | } else { |
| 816 | regval &= ~SIRFSOC_SPI_CS_IDLE_STAT; |
| 817 | usp_mode1 |= SIRFSOC_USP_CS_HIGH_VALID; |
| 818 | } |
| 819 | if (!(spi->mode & SPI_LSB_FIRST)) { |
| 820 | regval |= SIRFSOC_SPI_TRAN_MSB; |
| 821 | usp_mode1 &= ~SIRFSOC_USP_LSB; |
| 822 | } else { |
| 823 | regval &= ~SIRFSOC_SPI_TRAN_MSB; |
| 824 | usp_mode1 |= SIRFSOC_USP_LSB; |
| 825 | } |
| 826 | if (spi->mode & SPI_CPOL) { |
| 827 | regval |= SIRFSOC_SPI_CLK_IDLE_STAT; |
| 828 | usp_mode1 |= SIRFSOC_USP_SCLK_IDLE_STAT; |
| 829 | } else { |
| 830 | regval &= ~SIRFSOC_SPI_CLK_IDLE_STAT; |
| 831 | usp_mode1 &= ~SIRFSOC_USP_SCLK_IDLE_STAT; |
| 832 | } |
| 833 | /* |
| 834 | * Data should be driven at least 1/2 cycle before the fetch edge |
| 835 | * to make sure that data gets stable at the fetch edge. |
| 836 | */ |
| 837 | if (((spi->mode & SPI_CPOL) && (spi->mode & SPI_CPHA)) || |
| 838 | (!(spi->mode & SPI_CPOL) && !(spi->mode & SPI_CPHA))) { |
| 839 | regval &= ~SIRFSOC_SPI_DRV_POS_EDGE; |
| 840 | usp_mode1 |= (SIRFSOC_USP_TXD_FALLING_EDGE | |
| 841 | SIRFSOC_USP_RXD_FALLING_EDGE); |
| 842 | } else { |
| 843 | regval |= SIRFSOC_SPI_DRV_POS_EDGE; |
| 844 | usp_mode1 &= ~(SIRFSOC_USP_RXD_FALLING_EDGE | |
| 845 | SIRFSOC_USP_TXD_FALLING_EDGE); |
| 846 | } |
| 847 | writel((SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, sspi->fifo_size - 2) << |
| 848 | SIRFSOC_SPI_FIFO_SC_OFFSET) | |
| 849 | (SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, sspi->fifo_size / 2) << |
| 850 | SIRFSOC_SPI_FIFO_LC_OFFSET) | |
| 851 | (SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, 2) << |
| 852 | SIRFSOC_SPI_FIFO_HC_OFFSET), |
| 853 | sspi->base + sspi->regs->txfifo_level_chk); |
| 854 | writel((SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, 2) << |
| 855 | SIRFSOC_SPI_FIFO_SC_OFFSET) | |
| 856 | (SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, sspi->fifo_size / 2) << |
| 857 | SIRFSOC_SPI_FIFO_LC_OFFSET) | |
| 858 | (SIRFSOC_SPI_FIFO_LEVEL_CHK_MASK(sspi, sspi->fifo_size - 2) << |
| 859 | SIRFSOC_SPI_FIFO_HC_OFFSET), |
| 860 | sspi->base + sspi->regs->rxfifo_level_chk); |
| 861 | /* |
| 862 | * it should never set to hardware cs mode because in hardware cs mode, |
| 863 | * cs signal can't controlled by driver. |
| 864 | */ |
| 865 | switch (sspi->type) { |
| 866 | case SIRF_REAL_SPI: |
| 867 | regval |= SIRFSOC_SPI_CS_IO_MODE; |
| 868 | writel(regval, sspi->base + sspi->regs->spi_ctrl); |
| 869 | break; |
| 870 | case SIRF_USP_SPI_P2: |
| 871 | case SIRF_USP_SPI_A7: |
| 872 | usp_mode1 |= SIRFSOC_USP_SYNC_MODE; |
| 873 | usp_mode1 |= SIRFSOC_USP_TFS_IO_MODE; |
| 874 | usp_mode1 &= ~SIRFSOC_USP_TFS_IO_INPUT; |
| 875 | writel(usp_mode1, sspi->base + sspi->regs->usp_mode1); |
| 876 | break; |
| 877 | } |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 882 | static int |
| 883 | spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t) |
| 884 | { |
| 885 | struct sirfsoc_spi *sspi; |
| 886 | u8 bits_per_word = 0; |
| 887 | int hz = 0; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 888 | u32 regval, txfifo_ctrl, rxfifo_ctrl, tx_frm_ctl, rx_frm_ctl, usp_mode2; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 889 | |
| 890 | sspi = spi_master_get_devdata(spi->master); |
| 891 | |
Laxman Dewangan | 766ed70 | 2012-12-18 14:25:43 +0530 | [diff] [blame] | 892 | bits_per_word = (t) ? t->bits_per_word : spi->bits_per_word; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 893 | hz = t && t->speed_hz ? t->speed_hz : spi->max_speed_hz; |
| 894 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 895 | usp_mode2 = regval = (sspi->ctrl_freq / (2 * hz)) - 1; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 896 | if (regval > 0xFFFF || regval < 0) { |
| 897 | dev_err(&spi->dev, "Speed %d not supported\n", hz); |
| 898 | return -EINVAL; |
| 899 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 900 | switch (bits_per_word) { |
| 901 | case 8: |
| 902 | regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_8; |
| 903 | sspi->rx_word = spi_sirfsoc_rx_word_u8; |
| 904 | sspi->tx_word = spi_sirfsoc_tx_word_u8; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 905 | break; |
| 906 | case 12: |
| 907 | case 16: |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 908 | regval |= (bits_per_word == 12) ? |
| 909 | SIRFSOC_SPI_TRAN_DAT_FORMAT_12 : |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 910 | SIRFSOC_SPI_TRAN_DAT_FORMAT_16; |
| 911 | sspi->rx_word = spi_sirfsoc_rx_word_u16; |
| 912 | sspi->tx_word = spi_sirfsoc_tx_word_u16; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 913 | break; |
| 914 | case 32: |
| 915 | regval |= SIRFSOC_SPI_TRAN_DAT_FORMAT_32; |
| 916 | sspi->rx_word = spi_sirfsoc_rx_word_u32; |
| 917 | sspi->tx_word = spi_sirfsoc_tx_word_u32; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 918 | break; |
Arnd Bergmann | 804ae43 | 2013-06-03 15:24:53 +0200 | [diff] [blame] | 919 | default: |
Qipan Li | f08654a | 2015-04-27 09:22:28 +0000 | [diff] [blame] | 920 | dev_err(&spi->dev, "bpw %d not supported\n", bits_per_word); |
| 921 | return -EINVAL; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 922 | } |
Axel Lin | 8c328a2 | 2014-01-15 17:07:43 +0800 | [diff] [blame] | 923 | sspi->word_width = DIV_ROUND_UP(bits_per_word, 8); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 924 | txfifo_ctrl = (((sspi->fifo_size / 2) & |
| 925 | SIRFSOC_SPI_FIFO_THD_MASK(sspi)) |
| 926 | << SIRFSOC_SPI_FIFO_THD_OFFSET) | |
| 927 | (sspi->word_width >> 1); |
| 928 | rxfifo_ctrl = (((sspi->fifo_size / 2) & |
| 929 | SIRFSOC_SPI_FIFO_THD_MASK(sspi)) |
| 930 | << SIRFSOC_SPI_FIFO_THD_OFFSET) | |
| 931 | (sspi->word_width >> 1); |
| 932 | writel(txfifo_ctrl, sspi->base + sspi->regs->txfifo_ctrl); |
| 933 | writel(rxfifo_ctrl, sspi->base + sspi->regs->rxfifo_ctrl); |
| 934 | if (sspi->type == SIRF_USP_SPI_P2 || |
| 935 | sspi->type == SIRF_USP_SPI_A7) { |
| 936 | tx_frm_ctl = 0; |
| 937 | tx_frm_ctl |= ((bits_per_word - 1) & SIRFSOC_USP_TX_DATA_MASK) |
| 938 | << SIRFSOC_USP_TX_DATA_OFFSET; |
| 939 | tx_frm_ctl |= ((bits_per_word + 1 + SIRFSOC_USP_TXD_DELAY_LEN |
| 940 | - 1) & SIRFSOC_USP_TX_SYNC_MASK) << |
| 941 | SIRFSOC_USP_TX_SYNC_OFFSET; |
| 942 | tx_frm_ctl |= ((bits_per_word + 1 + SIRFSOC_USP_TXD_DELAY_LEN |
| 943 | + 2 - 1) & SIRFSOC_USP_TX_FRAME_MASK) << |
| 944 | SIRFSOC_USP_TX_FRAME_OFFSET; |
| 945 | tx_frm_ctl |= ((bits_per_word - 1) & |
| 946 | SIRFSOC_USP_TX_SHIFTER_MASK) << |
| 947 | SIRFSOC_USP_TX_SHIFTER_OFFSET; |
| 948 | rx_frm_ctl = 0; |
| 949 | rx_frm_ctl |= ((bits_per_word - 1) & SIRFSOC_USP_RX_DATA_MASK) |
| 950 | << SIRFSOC_USP_RX_DATA_OFFSET; |
| 951 | rx_frm_ctl |= ((bits_per_word + 1 + SIRFSOC_USP_RXD_DELAY_LEN |
| 952 | + 2 - 1) & SIRFSOC_USP_RX_FRAME_MASK) << |
| 953 | SIRFSOC_USP_RX_FRAME_OFFSET; |
| 954 | rx_frm_ctl |= ((bits_per_word - 1) |
| 955 | & SIRFSOC_USP_RX_SHIFTER_MASK) << |
| 956 | SIRFSOC_USP_RX_SHIFTER_OFFSET; |
| 957 | writel(tx_frm_ctl | (((usp_mode2 >> 10) & |
| 958 | SIRFSOC_USP_CLK_10_11_MASK) << |
| 959 | SIRFSOC_USP_CLK_10_11_OFFSET), |
| 960 | sspi->base + sspi->regs->usp_tx_frame_ctrl); |
| 961 | writel(rx_frm_ctl | (((usp_mode2 >> 12) & |
| 962 | SIRFSOC_USP_CLK_12_15_MASK) << |
| 963 | SIRFSOC_USP_CLK_12_15_OFFSET), |
| 964 | sspi->base + sspi->regs->usp_rx_frame_ctrl); |
| 965 | writel(readl(sspi->base + sspi->regs->usp_mode2) | |
| 966 | ((usp_mode2 & SIRFSOC_USP_CLK_DIVISOR_MASK) << |
| 967 | SIRFSOC_USP_CLK_DIVISOR_OFFSET) | |
| 968 | (SIRFSOC_USP_RXD_DELAY_LEN << |
| 969 | SIRFSOC_USP_RXD_DELAY_OFFSET) | |
| 970 | (SIRFSOC_USP_TXD_DELAY_LEN << |
| 971 | SIRFSOC_USP_TXD_DELAY_OFFSET), |
| 972 | sspi->base + sspi->regs->usp_mode2); |
Qipan Li | eeb71395 | 2014-03-01 12:38:17 +0800 | [diff] [blame] | 973 | } |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 974 | if (sspi->type == SIRF_REAL_SPI) |
| 975 | writel(regval, sspi->base + sspi->regs->spi_ctrl); |
| 976 | spi_sirfsoc_config_mode(spi); |
| 977 | if (sspi->type == SIRF_REAL_SPI) { |
| 978 | if (t && t->tx_buf && !t->rx_buf && |
| 979 | (t->len <= SIRFSOC_MAX_CMD_BYTES)) { |
| 980 | sspi->tx_by_cmd = true; |
| 981 | writel(readl(sspi->base + sspi->regs->spi_ctrl) | |
| 982 | (SIRFSOC_SPI_CMD_BYTE_NUM((t->len - 1)) | |
| 983 | SIRFSOC_SPI_CMD_MODE), |
| 984 | sspi->base + sspi->regs->spi_ctrl); |
| 985 | } else { |
| 986 | sspi->tx_by_cmd = false; |
| 987 | writel(readl(sspi->base + sspi->regs->spi_ctrl) & |
| 988 | ~SIRFSOC_SPI_CMD_MODE, |
| 989 | sspi->base + sspi->regs->spi_ctrl); |
| 990 | } |
| 991 | } |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 992 | if (IS_DMA_VALID(t)) { |
| 993 | /* Enable DMA mode for RX, TX */ |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 994 | writel(0, sspi->base + sspi->regs->tx_dma_io_ctrl); |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 995 | writel(SIRFSOC_SPI_RX_DMA_FLUSH, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 996 | sspi->base + sspi->regs->rx_dma_io_ctrl); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 997 | } else { |
| 998 | /* Enable IO mode for RX, TX */ |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 999 | writel(SIRFSOC_SPI_IO_MODE_SEL, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1000 | sspi->base + sspi->regs->tx_dma_io_ctrl); |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 1001 | writel(SIRFSOC_SPI_IO_MODE_SEL, |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1002 | sspi->base + sspi->regs->rx_dma_io_ctrl); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1003 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1004 | return 0; |
| 1005 | } |
| 1006 | |
| 1007 | static int spi_sirfsoc_setup(struct spi_device *spi) |
| 1008 | { |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1009 | struct sirfsoc_spi *sspi; |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1010 | int ret = 0; |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1011 | |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1012 | sspi = spi_master_get_devdata(spi->master); |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1013 | if (spi->cs_gpio == -ENOENT) |
| 1014 | sspi->hw_cs = true; |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1015 | else { |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1016 | sspi->hw_cs = false; |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1017 | if (!spi_get_ctldata(spi)) { |
| 1018 | void *cs = kmalloc(sizeof(int), GFP_KERNEL); |
| 1019 | if (!cs) { |
| 1020 | ret = -ENOMEM; |
| 1021 | goto exit; |
| 1022 | } |
| 1023 | ret = gpio_is_valid(spi->cs_gpio); |
| 1024 | if (!ret) { |
| 1025 | dev_err(&spi->dev, "no valid gpio\n"); |
| 1026 | ret = -ENOENT; |
| 1027 | goto exit; |
| 1028 | } |
| 1029 | ret = gpio_request(spi->cs_gpio, DRIVER_NAME); |
| 1030 | if (ret) { |
| 1031 | dev_err(&spi->dev, "failed to request gpio\n"); |
| 1032 | goto exit; |
| 1033 | } |
| 1034 | spi_set_ctldata(spi, cs); |
| 1035 | } |
| 1036 | } |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1037 | spi_sirfsoc_config_mode(spi); |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1038 | spi_sirfsoc_chipselect(spi, BITBANG_CS_INACTIVE); |
| 1039 | exit: |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
| 1043 | static void spi_sirfsoc_cleanup(struct spi_device *spi) |
| 1044 | { |
| 1045 | if (spi_get_ctldata(spi)) { |
| 1046 | gpio_free(spi->cs_gpio); |
| 1047 | kfree(spi_get_ctldata(spi)); |
| 1048 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1049 | } |
| 1050 | |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1051 | static const struct of_device_id spi_sirfsoc_of_match[] = { |
| 1052 | { .compatible = "sirf,prima2-spi", .data = &sirf_real_spi}, |
| 1053 | { .compatible = "sirf,prima2-usp-spi", .data = &sirf_usp_spi_p2}, |
| 1054 | { .compatible = "sirf,atlas7-usp-spi", .data = &sirf_usp_spi_a7}, |
| 1055 | {} |
| 1056 | }; |
| 1057 | MODULE_DEVICE_TABLE(of, spi_sirfsoc_of_match); |
| 1058 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1059 | static int spi_sirfsoc_probe(struct platform_device *pdev) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1060 | { |
| 1061 | struct sirfsoc_spi *sspi; |
| 1062 | struct spi_master *master; |
| 1063 | struct resource *mem_res; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1064 | struct sirf_spi_comp_data *spi_comp_data; |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1065 | int irq; |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1066 | int ret; |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1067 | const struct of_device_id *match; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1068 | |
Qipan Li | 8509c55 | 2014-11-20 22:33:07 +0800 | [diff] [blame] | 1069 | ret = device_reset(&pdev->dev); |
| 1070 | if (ret) { |
| 1071 | dev_err(&pdev->dev, "SPI reset failed!\n"); |
| 1072 | return ret; |
| 1073 | } |
| 1074 | |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1075 | master = spi_alloc_master(&pdev->dev, sizeof(*sspi)); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1076 | if (!master) { |
| 1077 | dev_err(&pdev->dev, "Unable to allocate SPI master\n"); |
| 1078 | return -ENOMEM; |
| 1079 | } |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1080 | match = of_match_node(spi_sirfsoc_of_match, pdev->dev.of_node); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1081 | platform_set_drvdata(pdev, master); |
| 1082 | sspi = spi_master_get_devdata(master); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1083 | sspi->fifo_full_offset = ilog2(sspi->fifo_size); |
| 1084 | spi_comp_data = (struct sirf_spi_comp_data *)match->data; |
| 1085 | sspi->regs = spi_comp_data->regs; |
| 1086 | sspi->type = spi_comp_data->type; |
| 1087 | sspi->fifo_level_chk_mask = (sspi->fifo_size / 4) - 1; |
| 1088 | sspi->dat_max_frm_len = spi_comp_data->dat_max_frm_len; |
| 1089 | sspi->fifo_size = spi_comp_data->fifo_size; |
Julia Lawall | 2479790 | 2013-08-14 11:11:29 +0200 | [diff] [blame] | 1090 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | b0ee560 | 2013-01-21 11:09:18 +0100 | [diff] [blame] | 1091 | sspi->base = devm_ioremap_resource(&pdev->dev, mem_res); |
| 1092 | if (IS_ERR(sspi->base)) { |
| 1093 | ret = PTR_ERR(sspi->base); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1094 | goto free_master; |
| 1095 | } |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1096 | irq = platform_get_irq(pdev, 0); |
| 1097 | if (irq < 0) { |
| 1098 | ret = -ENXIO; |
| 1099 | goto free_master; |
| 1100 | } |
| 1101 | ret = devm_request_irq(&pdev->dev, irq, spi_sirfsoc_irq, 0, |
| 1102 | DRIVER_NAME, sspi); |
| 1103 | if (ret) |
| 1104 | goto free_master; |
| 1105 | |
Axel Lin | 94c69f7 | 2013-09-10 15:43:41 +0800 | [diff] [blame] | 1106 | sspi->bitbang.master = master; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1107 | sspi->bitbang.chipselect = spi_sirfsoc_chipselect; |
| 1108 | sspi->bitbang.setup_transfer = spi_sirfsoc_setup_transfer; |
| 1109 | sspi->bitbang.txrx_bufs = spi_sirfsoc_transfer; |
| 1110 | sspi->bitbang.master->setup = spi_sirfsoc_setup; |
Qipan Li | 96bf401 | 2015-05-03 10:30:12 +0000 | [diff] [blame] | 1111 | sspi->bitbang.master->cleanup = spi_sirfsoc_cleanup; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1112 | master->bus_num = pdev->id; |
Qipan Li | 94b1f0d | 2013-06-25 19:45:29 +0800 | [diff] [blame] | 1113 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST | SPI_CS_HIGH; |
Stephen Warren | 24778be | 2013-05-21 20:36:35 -0600 | [diff] [blame] | 1114 | master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(12) | |
| 1115 | SPI_BPW_MASK(16) | SPI_BPW_MASK(32); |
Qipan Li | fcc50e5 | 2014-11-17 23:17:03 +0800 | [diff] [blame] | 1116 | master->max_speed_hz = SIRFSOC_SPI_DEFAULT_FRQ; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1117 | sspi->bitbang.master->dev.of_node = pdev->dev.of_node; |
| 1118 | |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1119 | /* request DMA channels */ |
Barry Song | dd7243d | 2014-02-13 00:30:19 +0800 | [diff] [blame] | 1120 | sspi->rx_chan = dma_request_slave_channel(&pdev->dev, "rx"); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1121 | if (!sspi->rx_chan) { |
| 1122 | dev_err(&pdev->dev, "can not allocate rx dma channel\n"); |
Wei Yongjun | 6cca9e2 | 2013-08-23 08:33:39 +0800 | [diff] [blame] | 1123 | ret = -ENODEV; |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1124 | goto free_master; |
| 1125 | } |
Barry Song | dd7243d | 2014-02-13 00:30:19 +0800 | [diff] [blame] | 1126 | sspi->tx_chan = dma_request_slave_channel(&pdev->dev, "tx"); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1127 | if (!sspi->tx_chan) { |
| 1128 | dev_err(&pdev->dev, "can not allocate tx dma channel\n"); |
Wei Yongjun | 6cca9e2 | 2013-08-23 08:33:39 +0800 | [diff] [blame] | 1129 | ret = -ENODEV; |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1130 | goto free_rx_dma; |
| 1131 | } |
| 1132 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1133 | sspi->clk = clk_get(&pdev->dev, NULL); |
| 1134 | if (IS_ERR(sspi->clk)) { |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1135 | ret = PTR_ERR(sspi->clk); |
| 1136 | goto free_tx_dma; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1137 | } |
Barry Song | e5118cd | 2012-12-26 10:48:33 +0800 | [diff] [blame] | 1138 | clk_prepare_enable(sspi->clk); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1139 | sspi->ctrl_freq = clk_get_rate(sspi->clk); |
| 1140 | |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1141 | init_completion(&sspi->rx_done); |
| 1142 | init_completion(&sspi->tx_done); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1143 | |
Qipan Li | a34bcbe | 2015-05-07 07:13:10 +0000 | [diff] [blame] | 1144 | sspi->dummypage = devm_kzalloc(&pdev->dev, 2 * PAGE_SIZE, GFP_KERNEL); |
Wei Yongjun | 6cca9e2 | 2013-08-23 08:33:39 +0800 | [diff] [blame] | 1145 | if (!sspi->dummypage) { |
| 1146 | ret = -ENOMEM; |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1147 | goto free_clk; |
Wei Yongjun | 6cca9e2 | 2013-08-23 08:33:39 +0800 | [diff] [blame] | 1148 | } |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1149 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1150 | ret = spi_bitbang_start(&sspi->bitbang); |
| 1151 | if (ret) |
Qipan Li | a34bcbe | 2015-05-07 07:13:10 +0000 | [diff] [blame] | 1152 | goto free_clk; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1153 | dev_info(&pdev->dev, "registerred, bus number = %d\n", master->bus_num); |
| 1154 | |
| 1155 | return 0; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1156 | free_clk: |
Barry Song | e5118cd | 2012-12-26 10:48:33 +0800 | [diff] [blame] | 1157 | clk_disable_unprepare(sspi->clk); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1158 | clk_put(sspi->clk); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1159 | free_tx_dma: |
| 1160 | dma_release_channel(sspi->tx_chan); |
| 1161 | free_rx_dma: |
| 1162 | dma_release_channel(sspi->rx_chan); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1163 | free_master: |
| 1164 | spi_master_put(master); |
Qipan Li | 7850cdf | 2014-09-02 17:01:01 +0800 | [diff] [blame] | 1165 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1166 | return ret; |
| 1167 | } |
| 1168 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1169 | static int spi_sirfsoc_remove(struct platform_device *pdev) |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1170 | { |
| 1171 | struct spi_master *master; |
| 1172 | struct sirfsoc_spi *sspi; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1173 | |
| 1174 | master = platform_get_drvdata(pdev); |
| 1175 | sspi = spi_master_get_devdata(master); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1176 | spi_bitbang_stop(&sspi->bitbang); |
Barry Song | e5118cd | 2012-12-26 10:48:33 +0800 | [diff] [blame] | 1177 | clk_disable_unprepare(sspi->clk); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1178 | clk_put(sspi->clk); |
Barry Song | de39f5f | 2013-08-06 14:21:21 +0800 | [diff] [blame] | 1179 | dma_release_channel(sspi->rx_chan); |
| 1180 | dma_release_channel(sspi->tx_chan); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1181 | spi_master_put(master); |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
Qipan Li | facffed | 2014-02-13 00:30:20 +0800 | [diff] [blame] | 1185 | #ifdef CONFIG_PM_SLEEP |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1186 | static int spi_sirfsoc_suspend(struct device *dev) |
| 1187 | { |
Axel Lin | a1216394 | 2013-08-09 15:35:16 +0800 | [diff] [blame] | 1188 | struct spi_master *master = dev_get_drvdata(dev); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1189 | struct sirfsoc_spi *sspi = spi_master_get_devdata(master); |
Axel Lin | a82ba3a | 2014-03-05 15:19:09 +0800 | [diff] [blame] | 1190 | int ret; |
| 1191 | |
| 1192 | ret = spi_master_suspend(master); |
| 1193 | if (ret) |
| 1194 | return ret; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1195 | |
| 1196 | clk_disable(sspi->clk); |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | static int spi_sirfsoc_resume(struct device *dev) |
| 1201 | { |
Axel Lin | a1216394 | 2013-08-09 15:35:16 +0800 | [diff] [blame] | 1202 | struct spi_master *master = dev_get_drvdata(dev); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1203 | struct sirfsoc_spi *sspi = spi_master_get_devdata(master); |
| 1204 | |
| 1205 | clk_enable(sspi->clk); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1206 | writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + sspi->regs->txfifo_op); |
| 1207 | writel(SIRFSOC_SPI_FIFO_RESET, sspi->base + sspi->regs->rxfifo_op); |
| 1208 | writel(SIRFSOC_SPI_FIFO_START, sspi->base + sspi->regs->txfifo_op); |
| 1209 | writel(SIRFSOC_SPI_FIFO_START, sspi->base + sspi->regs->rxfifo_op); |
| 1210 | return 0; |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1211 | } |
Qipan Li | facffed | 2014-02-13 00:30:20 +0800 | [diff] [blame] | 1212 | #endif |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1213 | |
Jingoo Han | 71aa2e3 | 2014-02-26 10:32:48 +0900 | [diff] [blame] | 1214 | static SIMPLE_DEV_PM_OPS(spi_sirfsoc_pm_ops, spi_sirfsoc_suspend, |
| 1215 | spi_sirfsoc_resume); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1216 | |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1217 | static struct platform_driver spi_sirfsoc_driver = { |
| 1218 | .driver = { |
| 1219 | .name = DRIVER_NAME, |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1220 | .pm = &spi_sirfsoc_pm_ops, |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1221 | .of_match_table = spi_sirfsoc_of_match, |
| 1222 | }, |
| 1223 | .probe = spi_sirfsoc_probe, |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1224 | .remove = spi_sirfsoc_remove, |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1225 | }; |
| 1226 | module_platform_driver(spi_sirfsoc_driver); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1227 | MODULE_DESCRIPTION("SiRF SoC SPI master driver"); |
Qipan Li | d77ec5d | 2014-04-14 14:30:00 +0800 | [diff] [blame] | 1228 | MODULE_AUTHOR("Zhiwu Song <Zhiwu.Song@csr.com>"); |
| 1229 | MODULE_AUTHOR("Barry Song <Baohua.Song@csr.com>"); |
Qipan Li | e3fb57c | 2015-05-19 14:41:12 +0000 | [diff] [blame^] | 1230 | MODULE_AUTHOR("Qipan Li <Qipan.Li@csr.com>"); |
Zhiwu Song | 1cc2df9 | 2012-02-13 17:45:38 +0800 | [diff] [blame] | 1231 | MODULE_LICENSE("GPL v2"); |