/drivers/net/wireless/bcm4329/include/bcmsdstd.h

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C Header · 223 lines · 129 code · 42 blank · 52 comment · 4 complexity · 7c04cfef3d48ceacae3ff93c2ae819e7 MD5 · raw file

  1. /*
  2. * 'Standard' SDIO HOST CONTROLLER driver
  3. *
  4. * Copyright (C) 1999-2010, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: bcmsdstd.h,v 13.16.18.1.16.3 2009/12/10 01:09:23 Exp $
  25. */
  26. /* global msglevel for debug messages - bitvals come from sdiovar.h */
  27. #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
  28. #define sd_trace(x)
  29. #define sd_info(x)
  30. #define sd_debug(x)
  31. #define sd_data(x)
  32. #define sd_ctrl(x)
  33. #define sd_dma(x)
  34. #define sd_sync_dma(sd, read, nbytes)
  35. #define sd_init_dma(sd)
  36. #define sd_ack_intr(sd)
  37. #define sd_wakeup(sd);
  38. /* Allocate/init/free per-OS private data */
  39. extern int sdstd_osinit(sdioh_info_t *sd);
  40. extern void sdstd_osfree(sdioh_info_t *sd);
  41. #define sd_log(x)
  42. #define SDIOH_ASSERT(exp) \
  43. do { if (!(exp)) \
  44. printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
  45. } while (0)
  46. #define BLOCK_SIZE_4318 64
  47. #define BLOCK_SIZE_4328 512
  48. /* internal return code */
  49. #define SUCCESS 0
  50. #define ERROR 1
  51. /* private bus modes */
  52. #define SDIOH_MODE_SPI 0
  53. #define SDIOH_MODE_SD1 1
  54. #define SDIOH_MODE_SD4 2
  55. #define MAX_SLOTS 6 /* For PCI: Only 6 BAR entries => 6 slots */
  56. #define SDIOH_REG_WINSZ 0x100 /* Number of registers in Standard Host Controller */
  57. #define SDIOH_TYPE_ARASAN_HDK 1
  58. #define SDIOH_TYPE_BCM27XX 2
  59. #define SDIOH_TYPE_TI_PCIXX21 4 /* TI PCIxx21 Standard Host Controller */
  60. #define SDIOH_TYPE_RICOH_R5C822 5 /* Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter */
  61. #define SDIOH_TYPE_JMICRON 6 /* JMicron Standard SDIO Host Controller */
  62. /* For linux, allow yielding for dongle */
  63. #define BCMSDYIELD
  64. /* Expected card status value for CMD7 */
  65. #define SDIOH_CMD7_EXP_STATUS 0x00001E00
  66. #define RETRIES_LARGE 100000
  67. #define RETRIES_SMALL 100
  68. #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */
  69. #define USE_MULTIBLOCK 0x4
  70. #define USE_FIFO 0x8 /* Fifo vs non-fifo */
  71. #define CLIENT_INTR 0x100 /* Get rid of this! */
  72. struct sdioh_info {
  73. uint cfg_bar; /* pci cfg address for bar */
  74. uint32 caps; /* cached value of capabilities reg */
  75. uint32 curr_caps; /* max current capabilities reg */
  76. osl_t *osh; /* osh handler */
  77. volatile char *mem_space; /* pci device memory va */
  78. uint lockcount; /* nest count of sdstd_lock() calls */
  79. bool client_intr_enabled; /* interrupt connnected flag */
  80. bool intr_handler_valid; /* client driver interrupt handler valid */
  81. sdioh_cb_fn_t intr_handler; /* registered interrupt handler */
  82. void *intr_handler_arg; /* argument to call interrupt handler */
  83. bool initialized; /* card initialized */
  84. uint target_dev; /* Target device ID */
  85. uint16 intmask; /* Current active interrupts */
  86. void *sdos_info; /* Pointer to per-OS private data */
  87. uint32 controller_type; /* Host controller type */
  88. uint8 version; /* Host Controller Spec Compliance Version */
  89. uint irq; /* Client irq */
  90. int intrcount; /* Client interrupts */
  91. int local_intrcount; /* Controller interrupts */
  92. bool host_init_done; /* Controller initted */
  93. bool card_init_done; /* Client SDIO interface initted */
  94. bool polled_mode; /* polling for command completion */
  95. bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
  96. /* Must be on for sd_multiblock to be effective */
  97. bool use_client_ints; /* If this is false, make sure to restore */
  98. /* polling hack in wl_linux.c:wl_timer() */
  99. int adapter_slot; /* Maybe dealing with multiple slots/controllers */
  100. int sd_mode; /* SD1/SD4/SPI */
  101. int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */
  102. uint32 data_xfer_count; /* Current transfer */
  103. uint16 card_rca; /* Current Address */
  104. int8 sd_dma_mode; /* DMA Mode (PIO, SDMA, ... ADMA2) on CMD53 */
  105. uint8 num_funcs; /* Supported funcs on client */
  106. uint32 com_cis_ptr;
  107. uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
  108. void *dma_buf; /* DMA Buffer virtual address */
  109. ulong dma_phys; /* DMA Buffer physical address */
  110. void *adma2_dscr_buf; /* ADMA2 Descriptor Buffer virtual address */
  111. ulong adma2_dscr_phys; /* ADMA2 Descriptor Buffer physical address */
  112. /* adjustments needed to make the dma align properly */
  113. void *dma_start_buf;
  114. ulong dma_start_phys;
  115. uint alloced_dma_size;
  116. void *adma2_dscr_start_buf;
  117. ulong adma2_dscr_start_phys;
  118. uint alloced_adma2_dscr_size;
  119. int r_cnt; /* rx count */
  120. int t_cnt; /* tx_count */
  121. bool got_hcint; /* local interrupt flag */
  122. uint16 last_intrstatus; /* to cache intrstatus */
  123. };
  124. #define DMA_MODE_NONE 0
  125. #define DMA_MODE_SDMA 1
  126. #define DMA_MODE_ADMA1 2
  127. #define DMA_MODE_ADMA2 3
  128. #define DMA_MODE_ADMA2_64 4
  129. #define DMA_MODE_AUTO -1
  130. #define USE_DMA(sd) ((bool)((sd->sd_dma_mode > 0) ? TRUE : FALSE))
  131. /* SDIO Host Control Register DMA Mode Definitions */
  132. #define SDIOH_SDMA_MODE 0
  133. #define SDIOH_ADMA1_MODE 1
  134. #define SDIOH_ADMA2_MODE 2
  135. #define SDIOH_ADMA2_64_MODE 3
  136. #define ADMA2_ATTRIBUTE_VALID (1 << 0) /* ADMA Descriptor line valid */
  137. #define ADMA2_ATTRIBUTE_END (1 << 1) /* End of Descriptor */
  138. #define ADMA2_ATTRIBUTE_INT (1 << 2) /* Interrupt when line is done */
  139. #define ADMA2_ATTRIBUTE_ACT_NOP (0 << 4) /* Skip current line, go to next. */
  140. #define ADMA2_ATTRIBUTE_ACT_RSV (1 << 4) /* Same as NOP */
  141. #define ADMA1_ATTRIBUTE_ACT_SET (1 << 4) /* ADMA1 Only - set transfer length */
  142. #define ADMA2_ATTRIBUTE_ACT_TRAN (2 << 4) /* Transfer Data of one descriptor line. */
  143. #define ADMA2_ATTRIBUTE_ACT_LINK (3 << 4) /* Link Descriptor */
  144. /* ADMA2 Descriptor Table Entry for 32-bit Address */
  145. typedef struct adma2_dscr_32b {
  146. uint32 len_attr;
  147. uint32 phys_addr;
  148. } adma2_dscr_32b_t;
  149. /* ADMA1 Descriptor Table Entry */
  150. typedef struct adma1_dscr {
  151. uint32 phys_addr_attr;
  152. } adma1_dscr_t;
  153. /************************************************************
  154. * Internal interfaces: per-port references into bcmsdstd.c
  155. */
  156. /* Global message bits */
  157. extern uint sd_msglevel;
  158. /* OS-independent interrupt handler */
  159. extern bool check_client_intr(sdioh_info_t *sd);
  160. /* Core interrupt enable/disable of device interrupts */
  161. extern void sdstd_devintr_on(sdioh_info_t *sd);
  162. extern void sdstd_devintr_off(sdioh_info_t *sd);
  163. /* Enable/disable interrupts for local controller events */
  164. extern void sdstd_intrs_on(sdioh_info_t *sd, uint16 norm, uint16 err);
  165. extern void sdstd_intrs_off(sdioh_info_t *sd, uint16 norm, uint16 err);
  166. /* Wait for specified interrupt and error bits to be set */
  167. extern void sdstd_spinbits(sdioh_info_t *sd, uint16 norm, uint16 err);
  168. /**************************************************************
  169. * Internal interfaces: bcmsdstd.c references to per-port code
  170. */
  171. /* Register mapping routines */
  172. extern uint32 *sdstd_reg_map(osl_t *osh, int32 addr, int size);
  173. extern void sdstd_reg_unmap(osl_t *osh, int32 addr, int size);
  174. /* Interrupt (de)registration routines */
  175. extern int sdstd_register_irq(sdioh_info_t *sd, uint irq);
  176. extern void sdstd_free_irq(uint irq, sdioh_info_t *sd);
  177. /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
  178. extern void sdstd_lock(sdioh_info_t *sd);
  179. extern void sdstd_unlock(sdioh_info_t *sd);
  180. /* OS-specific wait-for-interrupt-or-status */
  181. extern uint16 sdstd_waitbits(sdioh_info_t *sd, uint16 norm, uint16 err, bool yield);