bcmspibrcm.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * SD-SPI Protocol Conversion - BCMSDH->gSPI Translation Layer
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: bcmspibrcm.h 514727 2014-11-12 03:02:48Z $
  30. */
  31. #ifndef _BCM_SPI_BRCM_H
  32. #define _BCM_SPI_BRCM_H
  33. #ifndef SPI_MAX_IOFUNCS
  34. /* Maximum number of I/O funcs */
  35. #define SPI_MAX_IOFUNCS 4
  36. #endif // endif
  37. /* global msglevel for debug messages - bitvals come from sdiovar.h */
  38. #if defined(DHD_DEBUG)
  39. #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
  40. #define sd_trace(x) do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0)
  41. #define sd_info(x) do { if (sd_msglevel & SDH_INFO_VAL) printf x; } while (0)
  42. #define sd_debug(x) do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0)
  43. #define sd_data(x) do { if (sd_msglevel & SDH_DATA_VAL) printf x; } while (0)
  44. #define sd_ctrl(x) do { if (sd_msglevel & SDH_CTRL_VAL) printf x; } while (0)
  45. #else
  46. #define sd_err(x)
  47. #define sd_trace(x)
  48. #define sd_info(x)
  49. #define sd_debug(x)
  50. #define sd_data(x)
  51. #define sd_ctrl(x)
  52. #endif // endif
  53. #define sd_log(x)
  54. #define SDIOH_ASSERT(exp) \
  55. do { if (!(exp)) \
  56. printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
  57. } while (0)
  58. #define BLOCK_SIZE_F1 64
  59. #define BLOCK_SIZE_F2 2048
  60. #define BLOCK_SIZE_F3 2048
  61. /* internal return code */
  62. #define SUCCESS 0
  63. #undef ERROR
  64. #define ERROR 1
  65. #define ERROR_UF 2
  66. #define ERROR_OF 3
  67. /* private bus modes */
  68. #define SDIOH_MODE_SPI 0
  69. #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */
  70. #define USE_MULTIBLOCK 0x4
  71. struct sdioh_info {
  72. uint cfg_bar; /* pci cfg address for bar */
  73. uint32 caps; /* cached value of capabilities reg */
  74. #ifndef BCMSPI_ANDROID
  75. void *bar0; /* BAR0 for PCI Device */
  76. #endif /* !BCMSPI_ANDROID */
  77. osl_t *osh; /* osh handler */
  78. void *controller; /* Pointer to SPI Controller's private data struct */
  79. uint lockcount; /* nest count of spi_lock() calls */
  80. bool client_intr_enabled; /* interrupt connnected flag */
  81. bool intr_handler_valid; /* client driver interrupt handler valid */
  82. sdioh_cb_fn_t intr_handler; /* registered interrupt handler */
  83. void *intr_handler_arg; /* argument to call interrupt handler */
  84. bool initialized; /* card initialized */
  85. uint32 target_dev; /* Target device ID */
  86. uint32 intmask; /* Current active interrupts */
  87. void *sdos_info; /* Pointer to per-OS private data */
  88. uint32 controller_type; /* Host controller type */
  89. uint8 version; /* Host Controller Spec Compliance Version */
  90. uint irq; /* Client irq */
  91. uint32 intrcount; /* Client interrupts */
  92. uint32 local_intrcount; /* Controller interrupts */
  93. bool host_init_done; /* Controller initted */
  94. bool card_init_done; /* Client SDIO interface initted */
  95. bool polled_mode; /* polling for command completion */
  96. bool sd_use_dma; /* DMA on CMD53 */
  97. bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
  98. /* Must be on for sd_multiblock to be effective */
  99. bool use_client_ints; /* If this is false, make sure to restore */
  100. /* polling hack in wl_linux.c:wl_timer() */
  101. int adapter_slot; /* Maybe dealing with multiple slots/controllers */
  102. int sd_mode; /* SD1/SD4/SPI */
  103. int client_block_size[SPI_MAX_IOFUNCS]; /* Blocksize */
  104. uint32 data_xfer_count; /* Current transfer */
  105. uint16 card_rca; /* Current Address */
  106. uint8 num_funcs; /* Supported funcs on client */
  107. uint32 card_dstatus; /* 32bit device status */
  108. uint32 com_cis_ptr;
  109. uint32 func_cis_ptr[SPI_MAX_IOFUNCS];
  110. void *dma_buf;
  111. ulong dma_phys;
  112. int r_cnt; /* rx count */
  113. int t_cnt; /* tx_count */
  114. uint32 wordlen; /* host processor 16/32bits */
  115. uint32 prev_fun;
  116. uint32 chip;
  117. uint32 chiprev;
  118. bool resp_delay_all;
  119. bool dwordmode;
  120. bool resp_delay_new;
  121. struct spierrstats_t spierrstats;
  122. };
  123. /************************************************************
  124. * Internal interfaces: per-port references into bcmspibrcm.c
  125. */
  126. /* Global message bits */
  127. extern uint sd_msglevel;
  128. /**************************************************************
  129. * Internal interfaces: bcmspibrcm.c references to per-port code
  130. */
  131. /* Interrupt (de)registration routines */
  132. extern int spi_register_irq(sdioh_info_t *sd, uint irq);
  133. extern void spi_free_irq(uint irq, sdioh_info_t *sd);
  134. /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
  135. extern void spi_lock(sdioh_info_t *sd);
  136. extern void spi_unlock(sdioh_info_t *sd);
  137. /* Allocate/init/free per-OS private data */
  138. extern int spi_osinit(sdioh_info_t *sd);
  139. extern void spi_osfree(sdioh_info_t *sd);
  140. #define SPI_RW_FLAG_M BITFIELD_MASK(1) /* Bit [31] - R/W Command Bit */
  141. #define SPI_RW_FLAG_S 31
  142. #define SPI_ACCESS_M BITFIELD_MASK(1) /* Bit [30] - Fixed/Incr Access */
  143. #define SPI_ACCESS_S 30
  144. #define SPI_FUNCTION_M BITFIELD_MASK(2) /* Bit [29:28] - Function Number */
  145. #define SPI_FUNCTION_S 28
  146. #define SPI_REG_ADDR_M BITFIELD_MASK(17) /* Bit [27:11] - Address */
  147. #define SPI_REG_ADDR_S 11
  148. #define SPI_LEN_M BITFIELD_MASK(11) /* Bit [10:0] - Packet length */
  149. #define SPI_LEN_S 0
  150. #endif /* _BCM_SPI_BRCM_H */