Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef _SPI_QSD_H |
| 15 | #define _SPI_QSD_H |
| 16 | |
| 17 | #define SPI_DRV_NAME "spi_qsd" |
| 18 | |
| 19 | #if defined(CONFIG_SPI_QSD) || defined(CONFIG_SPI_QSD_MODULE) |
| 20 | |
| 21 | #define QSD_REG(x) (x) |
| 22 | #define QUP_REG(x) |
| 23 | |
| 24 | #define SPI_FIFO_WORD_CNT 0x0048 |
| 25 | |
| 26 | #else |
| 27 | |
| 28 | #define QSD_REG(x) |
| 29 | #define QUP_REG(x) (x) |
| 30 | |
| 31 | #define QUP_CONFIG 0x0000 /* N & NO_INPUT/NO_OUPUT bits */ |
| 32 | #define QUP_ERROR_FLAGS_EN 0x030C |
| 33 | #define QUP_ERR_MASK 0x3 |
| 34 | #define SPI_OUTPUT_FIFO_WORD_CNT 0x010C |
| 35 | #define SPI_INPUT_FIFO_WORD_CNT 0x0214 |
| 36 | #define QUP_MX_WRITE_COUNT 0x0150 |
| 37 | #define QUP_MX_WRITE_CNT_CURRENT 0x0154 |
| 38 | |
| 39 | #define QUP_CONFIG_SPI_MODE 0x0100 |
| 40 | #endif |
| 41 | |
| 42 | #define GSBI_CTRL_REG 0x0 |
| 43 | #define GSBI_SPI_CONFIG 0x30 |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 44 | /* B-family only registers */ |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 45 | #define QUP_HARDWARE_VER 0x0030 |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 46 | #define QUP_HARDWARE_VER_2_1_1 0X20010001 |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 47 | #define QUP_OPERATIONAL_MASK 0x0028 |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 48 | #define QUP_OP_MASK_OUTPUT_SERVICE_FLAG 0x100 |
| 49 | #define QUP_OP_MASK_INPUT_SERVICE_FLAG 0x200 |
| 50 | |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 51 | #define QUP_ERROR_FLAGS 0x0308 |
| 52 | |
| 53 | #define SPI_CONFIG QSD_REG(0x0000) QUP_REG(0x0300) |
| 54 | #define SPI_IO_CONTROL QSD_REG(0x0004) QUP_REG(0x0304) |
| 55 | #define SPI_IO_MODES QSD_REG(0x0008) QUP_REG(0x0008) |
| 56 | #define SPI_SW_RESET QSD_REG(0x000C) QUP_REG(0x000C) |
| 57 | #define SPI_TIME_OUT_CURRENT QSD_REG(0x0014) QUP_REG(0x0014) |
| 58 | #define SPI_MX_OUTPUT_COUNT QSD_REG(0x0018) QUP_REG(0x0100) |
| 59 | #define SPI_MX_OUTPUT_CNT_CURRENT QSD_REG(0x001C) QUP_REG(0x0104) |
| 60 | #define SPI_MX_INPUT_COUNT QSD_REG(0x0020) QUP_REG(0x0200) |
| 61 | #define SPI_MX_INPUT_CNT_CURRENT QSD_REG(0x0024) QUP_REG(0x0204) |
| 62 | #define SPI_MX_READ_COUNT QSD_REG(0x0028) QUP_REG(0x0208) |
| 63 | #define SPI_MX_READ_CNT_CURRENT QSD_REG(0x002C) QUP_REG(0x020C) |
| 64 | #define SPI_OPERATIONAL QSD_REG(0x0030) QUP_REG(0x0018) |
| 65 | #define SPI_ERROR_FLAGS QSD_REG(0x0034) QUP_REG(0x001C) |
| 66 | #define SPI_ERROR_FLAGS_EN QSD_REG(0x0038) QUP_REG(0x0020) |
| 67 | #define SPI_DEASSERT_WAIT QSD_REG(0x003C) QUP_REG(0x0310) |
| 68 | #define SPI_OUTPUT_DEBUG QSD_REG(0x0040) QUP_REG(0x0108) |
| 69 | #define SPI_INPUT_DEBUG QSD_REG(0x0044) QUP_REG(0x0210) |
| 70 | #define SPI_TEST_CTRL QSD_REG(0x004C) QUP_REG(0x0024) |
| 71 | #define SPI_OUTPUT_FIFO QSD_REG(0x0100) QUP_REG(0x0110) |
| 72 | #define SPI_INPUT_FIFO QSD_REG(0x0200) QUP_REG(0x0218) |
| 73 | #define SPI_STATE QSD_REG(SPI_OPERATIONAL) QUP_REG(0x0004) |
| 74 | |
| 75 | /* SPI_CONFIG fields */ |
| 76 | #define SPI_CFG_INPUT_FIRST 0x00000200 |
| 77 | #define SPI_NO_INPUT 0x00000080 |
| 78 | #define SPI_NO_OUTPUT 0x00000040 |
| 79 | #define SPI_CFG_LOOPBACK 0x00000100 |
| 80 | #define SPI_CFG_N 0x0000001F |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 81 | #define SPI_EN_EXT_OUT_FLAG 0x00010000 |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 82 | |
| 83 | /* SPI_IO_CONTROL fields */ |
| 84 | #define SPI_IO_C_FORCE_CS 0x00000800 |
| 85 | #define SPI_IO_C_CLK_IDLE_HIGH 0x00000400 |
| 86 | #define SPI_IO_C_MX_CS_MODE 0x00000100 |
| 87 | #define SPI_IO_C_CS_N_POLARITY 0x000000F0 |
| 88 | #define SPI_IO_C_CS_N_POLARITY_0 0x00000010 |
| 89 | #define SPI_IO_C_CS_SELECT 0x0000000C |
| 90 | #define SPI_IO_C_TRISTATE_CS 0x00000002 |
| 91 | #define SPI_IO_C_NO_TRI_STATE 0x00000001 |
| 92 | |
| 93 | /* SPI_IO_MODES fields */ |
| 94 | #define SPI_IO_M_OUTPUT_BIT_SHIFT_EN QSD_REG(0x00004000) QUP_REG(0x00010000) |
| 95 | #define SPI_IO_M_PACK_EN QSD_REG(0x00002000) QUP_REG(0x00008000) |
| 96 | #define SPI_IO_M_UNPACK_EN QSD_REG(0x00001000) QUP_REG(0x00004000) |
| 97 | #define SPI_IO_M_INPUT_MODE QSD_REG(0x00000C00) QUP_REG(0x00003000) |
| 98 | #define SPI_IO_M_OUTPUT_MODE QSD_REG(0x00000300) QUP_REG(0x00000C00) |
| 99 | #define SPI_IO_M_INPUT_FIFO_SIZE QSD_REG(0x000000C0) QUP_REG(0x00000380) |
| 100 | #define SPI_IO_M_INPUT_BLOCK_SIZE QSD_REG(0x00000030) QUP_REG(0x00000060) |
| 101 | #define SPI_IO_M_OUTPUT_FIFO_SIZE QSD_REG(0x0000000C) QUP_REG(0x0000001C) |
| 102 | #define SPI_IO_M_OUTPUT_BLOCK_SIZE QSD_REG(0x00000003) QUP_REG(0x00000003) |
| 103 | |
| 104 | #define INPUT_BLOCK_SZ_SHIFT QSD_REG(4) QUP_REG(5) |
| 105 | #define INPUT_FIFO_SZ_SHIFT QSD_REG(6) QUP_REG(7) |
| 106 | #define OUTPUT_BLOCK_SZ_SHIFT QSD_REG(0) QUP_REG(0) |
| 107 | #define OUTPUT_FIFO_SZ_SHIFT QSD_REG(2) QUP_REG(2) |
| 108 | #define OUTPUT_MODE_SHIFT QSD_REG(8) QUP_REG(10) |
| 109 | #define INPUT_MODE_SHIFT QSD_REG(10) QUP_REG(12) |
| 110 | |
| 111 | /* SPI_OPERATIONAL fields */ |
| 112 | #define SPI_OP_MAX_INPUT_DONE_FLAG 0x00000800 |
| 113 | #define SPI_OP_MAX_OUTPUT_DONE_FLAG 0x00000400 |
| 114 | #define SPI_OP_INPUT_SERVICE_FLAG 0x00000200 |
| 115 | #define SPI_OP_OUTPUT_SERVICE_FLAG 0x00000100 |
| 116 | #define SPI_OP_INPUT_FIFO_FULL 0x00000080 |
| 117 | #define SPI_OP_OUTPUT_FIFO_FULL 0x00000040 |
| 118 | #define SPI_OP_IP_FIFO_NOT_EMPTY 0x00000020 |
| 119 | #define SPI_OP_OP_FIFO_NOT_EMPTY 0x00000010 |
| 120 | #define SPI_OP_STATE_VALID 0x00000004 |
| 121 | #define SPI_OP_STATE 0x00000003 |
| 122 | |
| 123 | #define SPI_OP_STATE_CLEAR_BITS 0x2 |
| 124 | enum msm_spi_state { |
| 125 | SPI_OP_STATE_RESET = 0x00000000, |
| 126 | SPI_OP_STATE_RUN = 0x00000001, |
| 127 | SPI_OP_STATE_PAUSE = 0x00000003, |
| 128 | }; |
| 129 | |
| 130 | /* SPI_ERROR_FLAGS fields */ |
| 131 | #define SPI_ERR_OUTPUT_OVER_RUN_ERR 0x00000020 |
| 132 | #define SPI_ERR_INPUT_UNDER_RUN_ERR 0x00000010 |
| 133 | #define SPI_ERR_OUTPUT_UNDER_RUN_ERR 0x00000008 |
| 134 | #define SPI_ERR_INPUT_OVER_RUN_ERR 0x00000004 |
| 135 | #define SPI_ERR_CLK_OVER_RUN_ERR 0x00000002 |
| 136 | #define SPI_ERR_CLK_UNDER_RUN_ERR 0x00000001 |
| 137 | |
| 138 | /* We don't allow transactions larger than 4K-64 or 64K-64 due to |
| 139 | mx_input/output_cnt register size */ |
| 140 | #define SPI_MAX_TRANSFERS QSD_REG(0xFC0) QUP_REG(0xFC0) |
| 141 | #define SPI_MAX_LEN (SPI_MAX_TRANSFERS * dd->bytes_per_word) |
| 142 | |
| 143 | #define SPI_NUM_CHIPSELECTS 4 |
| 144 | #define SPI_SUPPORTED_MODES (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP) |
| 145 | |
| 146 | #define SPI_DELAY_THRESHOLD 1 |
| 147 | /* Default timeout is 10 milliseconds */ |
| 148 | #define SPI_DEFAULT_TIMEOUT 10 |
| 149 | /* 250 microseconds */ |
| 150 | #define SPI_TRYLOCK_DELAY 250 |
| 151 | |
| 152 | /* Data Mover burst size */ |
| 153 | #define DM_BURST_SIZE 16 |
| 154 | /* Data Mover commands should be aligned to 64 bit(8 bytes) */ |
| 155 | #define DM_BYTE_ALIGN 8 |
| 156 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 157 | enum msm_spi_qup_version { |
| 158 | SPI_QUP_VERSION_NONE = 0x0, |
| 159 | SPI_QUP_VERSION_BFAM = 0x2, |
| 160 | }; |
| 161 | |
| 162 | enum msm_spi_pipe_direction { |
| 163 | SPI_BAM_CONSUMER_PIPE = 0x0, |
| 164 | SPI_BAM_PRODUCER_PIPE = 0x1, |
| 165 | }; |
| 166 | |
| 167 | #define SPI_BAM_MAX_DESC_NUM 32 |
| 168 | #define SPI_MAX_TRFR_BTWN_RESETS ((64 * 1024) - 16) /* 64KB - 16byte */ |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 169 | |
| 170 | static char const * const spi_rsrcs[] = { |
| 171 | "spi_clk", |
| 172 | "spi_miso", |
| 173 | "spi_mosi" |
| 174 | }; |
| 175 | |
| 176 | static char const * const spi_cs_rsrcs[] = { |
| 177 | "spi_cs", |
| 178 | "spi_cs1", |
| 179 | "spi_cs2", |
| 180 | "spi_cs3", |
| 181 | }; |
| 182 | |
| 183 | enum msm_spi_mode { |
| 184 | SPI_FIFO_MODE = 0x0, /* 00 */ |
| 185 | SPI_BLOCK_MODE = 0x1, /* 01 */ |
| 186 | SPI_DMOV_MODE = 0x2, /* 10 */ |
| 187 | SPI_BAM_MODE = 0x3, /* 11 */ |
| 188 | SPI_MODE_NONE = 0xFF, /* invalid value */ |
| 189 | }; |
| 190 | |
| 191 | /* Structure for SPI CS GPIOs */ |
| 192 | struct spi_cs_gpio { |
| 193 | int gpio_num; |
| 194 | bool valid; |
| 195 | }; |
| 196 | |
| 197 | /* Structures for Data Mover */ |
| 198 | struct spi_dmov_cmd { |
| 199 | dmov_box box; /* data aligned to max(dm_burst_size, block_size) |
| 200 | (<= fifo_size) */ |
| 201 | dmov_s single_pad; /* data unaligned to max(dm_burst_size, block_size) |
| 202 | padded to fit */ |
| 203 | dma_addr_t cmd_ptr; |
| 204 | }; |
| 205 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 206 | static struct pm_qos_request qos_req_list; |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 207 | |
| 208 | #ifdef CONFIG_DEBUG_FS |
| 209 | /* Used to create debugfs entries */ |
| 210 | static const struct { |
| 211 | const char *name; |
| 212 | mode_t mode; |
| 213 | int offset; |
| 214 | } debugfs_spi_regs[] = { |
| 215 | {"config", S_IRUGO | S_IWUSR, SPI_CONFIG}, |
| 216 | {"io_control", S_IRUGO | S_IWUSR, SPI_IO_CONTROL}, |
| 217 | {"io_modes", S_IRUGO | S_IWUSR, SPI_IO_MODES}, |
| 218 | {"sw_reset", S_IWUSR, SPI_SW_RESET}, |
| 219 | {"time_out_current", S_IRUGO, SPI_TIME_OUT_CURRENT}, |
| 220 | {"mx_output_count", S_IRUGO | S_IWUSR, SPI_MX_OUTPUT_COUNT}, |
| 221 | {"mx_output_cnt_current", S_IRUGO, SPI_MX_OUTPUT_CNT_CURRENT}, |
| 222 | {"mx_input_count", S_IRUGO | S_IWUSR, SPI_MX_INPUT_COUNT}, |
| 223 | {"mx_input_cnt_current", S_IRUGO, SPI_MX_INPUT_CNT_CURRENT}, |
| 224 | {"mx_read_count", S_IRUGO | S_IWUSR, SPI_MX_READ_COUNT}, |
| 225 | {"mx_read_cnt_current", S_IRUGO, SPI_MX_READ_CNT_CURRENT}, |
| 226 | {"operational", S_IRUGO | S_IWUSR, SPI_OPERATIONAL}, |
| 227 | {"error_flags", S_IRUGO | S_IWUSR, SPI_ERROR_FLAGS}, |
| 228 | {"error_flags_en", S_IRUGO | S_IWUSR, SPI_ERROR_FLAGS_EN}, |
| 229 | {"deassert_wait", S_IRUGO | S_IWUSR, SPI_DEASSERT_WAIT}, |
| 230 | {"output_debug", S_IRUGO, SPI_OUTPUT_DEBUG}, |
| 231 | {"input_debug", S_IRUGO, SPI_INPUT_DEBUG}, |
| 232 | {"test_ctrl", S_IRUGO | S_IWUSR, SPI_TEST_CTRL}, |
| 233 | {"output_fifo", S_IWUSR, SPI_OUTPUT_FIFO}, |
| 234 | {"input_fifo" , S_IRUSR, SPI_INPUT_FIFO}, |
| 235 | {"spi_state", S_IRUGO | S_IWUSR, SPI_STATE}, |
| 236 | #if defined(CONFIG_SPI_QSD) || defined(CONFIG_SPI_QSD_MODULE) |
| 237 | {"fifo_word_cnt", S_IRUGO, SPI_FIFO_WORD_CNT}, |
| 238 | #else |
| 239 | {"qup_config", S_IRUGO | S_IWUSR, QUP_CONFIG}, |
| 240 | {"qup_error_flags", S_IRUGO | S_IWUSR, QUP_ERROR_FLAGS}, |
| 241 | {"qup_error_flags_en", S_IRUGO | S_IWUSR, QUP_ERROR_FLAGS_EN}, |
| 242 | {"mx_write_cnt", S_IRUGO | S_IWUSR, QUP_MX_WRITE_COUNT}, |
| 243 | {"mx_write_cnt_current", S_IRUGO, QUP_MX_WRITE_CNT_CURRENT}, |
| 244 | {"output_fifo_word_cnt", S_IRUGO, SPI_OUTPUT_FIFO_WORD_CNT}, |
| 245 | {"input_fifo_word_cnt", S_IRUGO, SPI_INPUT_FIFO_WORD_CNT}, |
| 246 | #endif |
| 247 | }; |
| 248 | #endif |
| 249 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 250 | struct msm_spi_bam_pipe { |
| 251 | struct sps_pipe *handle; |
| 252 | struct sps_connect config; |
| 253 | bool teardown_required; |
| 254 | }; |
| 255 | |
| 256 | struct msm_spi_bam { |
| 257 | void __iomem *base; |
| 258 | u32 phys_addr; |
| 259 | u32 handle; |
| 260 | u32 irq; |
| 261 | struct msm_spi_bam_pipe prod; |
| 262 | struct msm_spi_bam_pipe cons; |
| 263 | bool deregister_required; |
| 264 | }; |
| 265 | |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 266 | struct msm_spi { |
| 267 | u8 *read_buf; |
| 268 | const u8 *write_buf; |
| 269 | void __iomem *base; |
| 270 | struct device *dev; |
| 271 | spinlock_t queue_lock; |
| 272 | struct mutex core_lock; |
| 273 | struct list_head queue; |
| 274 | struct workqueue_struct *workqueue; |
| 275 | struct work_struct work_data; |
| 276 | struct spi_message *cur_msg; |
| 277 | struct spi_transfer *cur_transfer; |
| 278 | struct completion transfer_complete; |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 279 | struct clk *clk; /* core clock */ |
| 280 | struct clk *pclk; /* interface clock */ |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 281 | unsigned long mem_phys_addr; |
| 282 | size_t mem_size; |
| 283 | int input_fifo_size; |
| 284 | int output_fifo_size; |
| 285 | u32 rx_bytes_remaining; |
| 286 | u32 tx_bytes_remaining; |
| 287 | u32 clock_speed; |
| 288 | int irq_in; |
| 289 | int read_xfr_cnt; |
| 290 | int write_xfr_cnt; |
| 291 | int write_len; |
| 292 | int read_len; |
| 293 | #if defined(CONFIG_SPI_QSD) || defined(CONFIG_SPI_QSD_MODULE) |
| 294 | int irq_out; |
| 295 | int irq_err; |
| 296 | #endif |
| 297 | int bytes_per_word; |
| 298 | bool suspended; |
| 299 | bool transfer_pending; |
| 300 | wait_queue_head_t continue_suspend; |
| 301 | /* DMA data */ |
| 302 | enum msm_spi_mode mode; |
| 303 | bool use_dma; |
| 304 | int tx_dma_chan; |
| 305 | int tx_dma_crci; |
| 306 | int rx_dma_chan; |
| 307 | int rx_dma_crci; |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 308 | int (*dma_init) (struct msm_spi *dd); |
| 309 | void (*dma_teardown) (struct msm_spi *dd); |
| 310 | struct msm_spi_bam bam; |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 311 | /* Data Mover Commands */ |
| 312 | struct spi_dmov_cmd *tx_dmov_cmd; |
| 313 | struct spi_dmov_cmd *rx_dmov_cmd; |
| 314 | /* Physical address of the tx dmov box command */ |
| 315 | dma_addr_t tx_dmov_cmd_dma; |
| 316 | dma_addr_t rx_dmov_cmd_dma; |
| 317 | struct msm_dmov_cmd tx_hdr; |
| 318 | struct msm_dmov_cmd rx_hdr; |
| 319 | int input_block_size; |
| 320 | int output_block_size; |
| 321 | int burst_size; |
| 322 | atomic_t rx_irq_called; |
Kiran Gunda | 54eb06e | 2012-05-18 15:17:06 +0530 | [diff] [blame] | 323 | atomic_t tx_irq_called; |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 324 | /* Used to pad messages unaligned to block size */ |
| 325 | u8 *tx_padding; |
| 326 | dma_addr_t tx_padding_dma; |
| 327 | u8 *rx_padding; |
| 328 | dma_addr_t rx_padding_dma; |
| 329 | u32 unaligned_len; |
| 330 | /* DMA statistics */ |
| 331 | int stat_dmov_tx_err; |
| 332 | int stat_dmov_rx_err; |
| 333 | int stat_rx; |
| 334 | int stat_dmov_rx; |
| 335 | int stat_tx; |
| 336 | int stat_dmov_tx; |
| 337 | #ifdef CONFIG_DEBUG_FS |
| 338 | struct dentry *dent_spi; |
| 339 | struct dentry *debugfs_spi_regs[ARRAY_SIZE(debugfs_spi_regs)]; |
| 340 | #endif |
| 341 | struct msm_spi_platform_data *pdata; /* Platform data */ |
| 342 | /* Remote Spinlock Data */ |
| 343 | bool use_rlock; |
| 344 | remote_mutex_t r_lock; |
| 345 | uint32_t pm_lat; |
| 346 | /* When set indicates multiple transfers in a single message */ |
| 347 | bool multi_xfr; |
| 348 | bool done; |
| 349 | u32 cur_msg_len; |
| 350 | /* Used in FIFO mode to keep track of the transfer being processed */ |
| 351 | struct spi_transfer *cur_tx_transfer; |
| 352 | struct spi_transfer *cur_rx_transfer; |
| 353 | /* Temporary buffer used for WR-WR or WR-RD transfers */ |
| 354 | u8 *temp_buf; |
| 355 | /* GPIO pin numbers for SPI clk, miso and mosi */ |
| 356 | int spi_gpios[ARRAY_SIZE(spi_rsrcs)]; |
| 357 | /* SPI CS GPIOs for each slave */ |
| 358 | struct spi_cs_gpio cs_gpios[ARRAY_SIZE(spi_cs_rsrcs)]; |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 359 | enum msm_spi_qup_version qup_ver; |
Kiran Gunda | c5fbd7f | 2012-07-30 13:22:39 +0530 | [diff] [blame] | 360 | int max_trfr_len; |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | /* Forward declaration */ |
| 364 | static irqreturn_t msm_spi_input_irq(int irq, void *dev_id); |
| 365 | static irqreturn_t msm_spi_output_irq(int irq, void *dev_id); |
| 366 | static irqreturn_t msm_spi_error_irq(int irq, void *dev_id); |
| 367 | static inline int msm_spi_set_state(struct msm_spi *dd, |
| 368 | enum msm_spi_state state); |
| 369 | static void msm_spi_write_word_to_fifo(struct msm_spi *dd); |
| 370 | static inline void msm_spi_write_rmn_to_fifo(struct msm_spi *dd); |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 371 | static irqreturn_t msm_spi_qup_irq(int irq, void *dev_id); |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 372 | |
| 373 | #if defined(CONFIG_SPI_QSD) || defined(CONFIG_SPI_QSD_MODULE) |
| 374 | static inline void msm_spi_disable_irqs(struct msm_spi *dd) |
| 375 | { |
| 376 | disable_irq(dd->irq_in); |
| 377 | disable_irq(dd->irq_out); |
| 378 | disable_irq(dd->irq_err); |
| 379 | } |
| 380 | |
| 381 | static inline void msm_spi_enable_irqs(struct msm_spi *dd) |
| 382 | { |
| 383 | enable_irq(dd->irq_in); |
| 384 | enable_irq(dd->irq_out); |
| 385 | enable_irq(dd->irq_err); |
| 386 | } |
| 387 | |
| 388 | static inline int msm_spi_request_irq(struct msm_spi *dd, |
| 389 | struct platform_device *pdev, |
| 390 | struct spi_master *master) |
| 391 | { |
| 392 | int rc; |
| 393 | |
| 394 | dd->irq_in = platform_get_irq(pdev, 0); |
| 395 | dd->irq_out = platform_get_irq(pdev, 1); |
| 396 | dd->irq_err = platform_get_irq(pdev, 2); |
| 397 | if ((dd->irq_in < 0) || (dd->irq_out < 0) || (dd->irq_err < 0)) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | rc = devm_request_irq(dd->dev, dd->irq_in, msm_spi_input_irq, |
| 401 | IRQF_TRIGGER_RISING, pdev->name, dd); |
| 402 | if (rc) |
| 403 | goto error_irq; |
| 404 | |
| 405 | rc = devm_request_irq(dd->dev, dd->irq_out, msm_spi_output_irq, |
| 406 | IRQF_TRIGGER_RISING, pdev->name, dd); |
| 407 | if (rc) |
| 408 | goto error_irq; |
| 409 | |
| 410 | rc = devm_request_irq(dd->dev, dd->irq_err, msm_spi_error_irq, |
| 411 | IRQF_TRIGGER_RISING, pdev->name, master); |
| 412 | if (rc) |
| 413 | goto error_irq; |
| 414 | |
| 415 | error_irq: |
| 416 | return rc; |
| 417 | } |
| 418 | |
| 419 | static inline void msm_spi_get_clk_err(struct msm_spi *dd, u32 *spi_err) {} |
| 420 | static inline void msm_spi_ack_clk_err(struct msm_spi *dd) {} |
| 421 | static inline void msm_spi_set_qup_config(struct msm_spi *dd, int bpw) {} |
| 422 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 423 | static inline int msm_spi_prepare_for_write(struct msm_spi *dd) { return 0; } |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 424 | static inline void msm_spi_start_write(struct msm_spi *dd, u32 read_count) |
| 425 | { |
| 426 | msm_spi_write_word_to_fifo(dd); |
| 427 | } |
| 428 | static inline void msm_spi_set_write_count(struct msm_spi *dd, int val) {} |
| 429 | |
| 430 | static inline void msm_spi_complete(struct msm_spi *dd) |
| 431 | { |
| 432 | complete(&dd->transfer_complete); |
| 433 | } |
| 434 | |
| 435 | static inline void msm_spi_enable_error_flags(struct msm_spi *dd) |
| 436 | { |
| 437 | writel_relaxed(0x0000007B, dd->base + SPI_ERROR_FLAGS_EN); |
| 438 | } |
| 439 | |
| 440 | static inline void msm_spi_clear_error_flags(struct msm_spi *dd) |
| 441 | { |
| 442 | writel_relaxed(0x0000007F, dd->base + SPI_ERROR_FLAGS); |
| 443 | } |
| 444 | |
| 445 | #else |
| 446 | /* In QUP the same interrupt line is used for input, output and error*/ |
| 447 | static inline int msm_spi_request_irq(struct msm_spi *dd, |
| 448 | struct platform_device *pdev, |
| 449 | struct spi_master *master) |
| 450 | { |
| 451 | dd->irq_in = platform_get_irq(pdev, 0); |
| 452 | if (dd->irq_in < 0) |
| 453 | return -EINVAL; |
| 454 | |
| 455 | return devm_request_irq(dd->dev, dd->irq_in, msm_spi_qup_irq, |
| 456 | IRQF_TRIGGER_HIGH, pdev->name, dd); |
| 457 | } |
| 458 | |
| 459 | static inline void msm_spi_disable_irqs(struct msm_spi *dd) |
| 460 | { |
| 461 | disable_irq(dd->irq_in); |
| 462 | } |
| 463 | |
| 464 | static inline void msm_spi_enable_irqs(struct msm_spi *dd) |
| 465 | { |
| 466 | enable_irq(dd->irq_in); |
| 467 | } |
| 468 | |
| 469 | static inline void msm_spi_get_clk_err(struct msm_spi *dd, u32 *spi_err) |
| 470 | { |
| 471 | *spi_err = readl_relaxed(dd->base + QUP_ERROR_FLAGS); |
| 472 | } |
| 473 | |
| 474 | static inline void msm_spi_ack_clk_err(struct msm_spi *dd) |
| 475 | { |
| 476 | writel_relaxed(QUP_ERR_MASK, dd->base + QUP_ERROR_FLAGS); |
| 477 | } |
| 478 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 479 | static inline void |
| 480 | msm_spi_set_bpw_and_no_io_flags(struct msm_spi *dd, u32 *config, int n); |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 481 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 482 | /** |
| 483 | * msm_spi_set_qup_config: set QUP_CONFIG to no_input, no_output, and N bits |
| 484 | */ |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 485 | static inline void msm_spi_set_qup_config(struct msm_spi *dd, int bpw) |
| 486 | { |
| 487 | u32 qup_config = readl_relaxed(dd->base + QUP_CONFIG); |
| 488 | |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 489 | msm_spi_set_bpw_and_no_io_flags(dd, &qup_config, bpw-1); |
| 490 | writel_relaxed(qup_config | QUP_CONFIG_SPI_MODE, dd->base + QUP_CONFIG); |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static inline int msm_spi_prepare_for_write(struct msm_spi *dd) |
| 494 | { |
| 495 | if (msm_spi_set_state(dd, SPI_OP_STATE_RUN)) |
| 496 | return -EINVAL; |
| 497 | if (msm_spi_set_state(dd, SPI_OP_STATE_PAUSE)) |
| 498 | return -EINVAL; |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | static inline void msm_spi_start_write(struct msm_spi *dd, u32 read_count) |
| 503 | { |
| 504 | if (read_count <= dd->input_fifo_size) |
| 505 | msm_spi_write_rmn_to_fifo(dd); |
| 506 | else |
| 507 | msm_spi_write_word_to_fifo(dd); |
| 508 | } |
| 509 | |
| 510 | static inline void msm_spi_set_write_count(struct msm_spi *dd, int val) |
| 511 | { |
| 512 | writel_relaxed(val, dd->base + QUP_MX_WRITE_COUNT); |
| 513 | } |
| 514 | |
| 515 | static inline void msm_spi_complete(struct msm_spi *dd) |
| 516 | { |
| 517 | dd->done = 1; |
| 518 | } |
| 519 | |
| 520 | static inline void msm_spi_enable_error_flags(struct msm_spi *dd) |
| 521 | { |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 522 | if (dd->qup_ver == SPI_QUP_VERSION_BFAM) |
| 523 | writel_relaxed( |
| 524 | SPI_ERR_CLK_UNDER_RUN_ERR | SPI_ERR_CLK_OVER_RUN_ERR, |
| 525 | dd->base + SPI_ERROR_FLAGS_EN); |
| 526 | else |
| 527 | writel_relaxed(0x00000078, dd->base + SPI_ERROR_FLAGS_EN); |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static inline void msm_spi_clear_error_flags(struct msm_spi *dd) |
| 531 | { |
Gilad Avidov | d026234 | 2012-10-24 16:52:30 -0600 | [diff] [blame] | 532 | if (dd->qup_ver == SPI_QUP_VERSION_BFAM) |
| 533 | writel_relaxed( |
| 534 | SPI_ERR_CLK_UNDER_RUN_ERR | SPI_ERR_CLK_OVER_RUN_ERR, |
| 535 | dd->base + SPI_ERROR_FLAGS); |
| 536 | else |
| 537 | writel_relaxed(0x0000007C, dd->base + SPI_ERROR_FLAGS); |
Harini Jayaraman | c710a5e | 2011-11-22 12:02:43 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | #endif |
| 541 | #endif |