bcmsdspi.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * SD-SPI Protocol Conversion - BCMSDH->SPI 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: bcmsdspi.h 514727 2014-11-12 03:02:48Z $
  30. */
  31. #ifndef _BCM_SD_SPI_H
  32. #define _BCM_SD_SPI_H
  33. /* global msglevel for debug messages - bitvals come from sdiovar.h */
  34. #define sd_err(x)
  35. #define sd_trace(x)
  36. #define sd_info(x)
  37. #define sd_debug(x)
  38. #define sd_data(x)
  39. #define sd_ctrl(x)
  40. #define sd_log(x)
  41. #define SDIOH_ASSERT(exp) \
  42. do { if (!(exp)) \
  43. printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
  44. } while (0)
  45. #define BLOCK_SIZE_4318 64
  46. #define BLOCK_SIZE_4328 512
  47. /* internal return code */
  48. #define SUCCESS 0
  49. #undef ERROR
  50. #define ERROR 1
  51. /* private bus modes */
  52. #define SDIOH_MODE_SPI 0
  53. #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */
  54. #define USE_MULTIBLOCK 0x4
  55. struct sdioh_info {
  56. uint cfg_bar; /* pci cfg address for bar */
  57. uint32 caps; /* cached value of capabilities reg */
  58. uint bar0; /* BAR0 for PCI Device */
  59. osl_t *osh; /* osh handler */
  60. void *controller; /* Pointer to SPI Controller's private data struct */
  61. uint lockcount; /* nest count of sdspi_lock() calls */
  62. bool client_intr_enabled; /* interrupt connnected flag */
  63. bool intr_handler_valid; /* client driver interrupt handler valid */
  64. sdioh_cb_fn_t intr_handler; /* registered interrupt handler */
  65. void *intr_handler_arg; /* argument to call interrupt handler */
  66. bool initialized; /* card initialized */
  67. uint32 target_dev; /* Target device ID */
  68. uint32 intmask; /* Current active interrupts */
  69. void *sdos_info; /* Pointer to per-OS private data */
  70. uint32 controller_type; /* Host controller type */
  71. uint8 version; /* Host Controller Spec Compliance Version */
  72. uint irq; /* Client irq */
  73. uint32 intrcount; /* Client interrupts */
  74. uint32 local_intrcount; /* Controller interrupts */
  75. bool host_init_done; /* Controller initted */
  76. bool card_init_done; /* Client SDIO interface initted */
  77. bool polled_mode; /* polling for command completion */
  78. bool sd_use_dma; /* DMA on CMD53 */
  79. bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
  80. /* Must be on for sd_multiblock to be effective */
  81. bool use_client_ints; /* If this is false, make sure to restore */
  82. bool got_hcint; /* Host Controller interrupt. */
  83. /* polling hack in wl_linux.c:wl_timer() */
  84. int adapter_slot; /* Maybe dealing with multiple slots/controllers */
  85. int sd_mode; /* SD1/SD4/SPI */
  86. int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */
  87. uint32 data_xfer_count; /* Current register transfer size */
  88. uint32 cmd53_wr_data; /* Used to pass CMD53 write data */
  89. uint32 card_response; /* Used to pass back response status byte */
  90. uint32 card_rsp_data; /* Used to pass back response data word */
  91. uint16 card_rca; /* Current Address */
  92. uint8 num_funcs; /* Supported funcs on client */
  93. uint32 com_cis_ptr;
  94. uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
  95. void *dma_buf;
  96. ulong dma_phys;
  97. int r_cnt; /* rx count */
  98. int t_cnt; /* tx_count */
  99. };
  100. /************************************************************
  101. * Internal interfaces: per-port references into bcmsdspi.c
  102. */
  103. /* Global message bits */
  104. extern uint sd_msglevel;
  105. /**************************************************************
  106. * Internal interfaces: bcmsdspi.c references to per-port code
  107. */
  108. /* Register mapping routines */
  109. extern uint32 *spi_reg_map(osl_t *osh, uintptr addr, int size);
  110. extern void spi_reg_unmap(osl_t *osh, uintptr addr, int size);
  111. /* Interrupt (de)registration routines */
  112. extern int spi_register_irq(sdioh_info_t *sd, uint irq);
  113. extern void spi_free_irq(uint irq, sdioh_info_t *sd);
  114. /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
  115. extern void spi_lock(sdioh_info_t *sd);
  116. extern void spi_unlock(sdioh_info_t *sd);
  117. /* Allocate/init/free per-OS private data */
  118. extern int spi_osinit(sdioh_info_t *sd);
  119. extern void spi_osfree(sdioh_info_t *sd);
  120. #endif /* _BCM_SD_SPI_H */