spi_qsd.h 20 KB

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