PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/TNETW_Driver/TNETWIF/BusTxn/wspi.h

http://github.com/CyanogenMod/cm-kernel
C Header | 160 lines | 73 code | 29 blank | 58 comment | 0 complexity | 75fcb7593014dfae4f2bfb17bd7e81e5 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. #ifndef _WSPI_H_
  36. #define _WSPI_H_
  37. /*
  38. * Define this flag to use write-read SPI driver API
  39. */
  40. #define USE_WRITE_READ_API
  41. /*
  42. * Define this flag to use sync-over-async mode
  43. */
  44. #undef USE_SYNC_OVER_ASYNC
  45. /* Return codes */
  46. typedef enum
  47. {
  48. WSPI_OK = 0,
  49. WSPI_TXN_COMPLETE = 0,
  50. WSPI_TXN_PENDING = 1,
  51. WSPI_ERR_UNKNOWN = -1,
  52. WSPI_ERR_BUS_BUSY = -2,
  53. WSPI_ERR_QUEUE_FULL = -3,
  54. WSPI_ERR_ALLOC_MEM = -4,
  55. WSPI_ERR_ASYNC_TIMEOUT = -5,
  56. WSPI_ERR_WRONG_LENGTH = -6,
  57. } WSPI_Status_e;
  58. typedef struct _WSPI_CB_t
  59. {
  60. void (*CBFunc) (void *data, int status);
  61. void *CBArg;
  62. } WSPI_CB_T;
  63. typedef struct _WSPIConfig_t
  64. {
  65. int isFixedAddress;
  66. int fixedBusyLength;
  67. UINT8 mask;
  68. } WSPIConfig_t;
  69. /* WSPI API */
  70. TI_HANDLE WSPI_Open (TI_HANDLE hOs);
  71. int WSPI_Close (TI_HANDLE hWSPI);
  72. int WSPI_Configure (TI_HANDLE hWSPI, TI_HANDLE hReport, const WSPIConfig_t* aConfig, WSPI_CB_T* CB);
  73. int WSPI_ReadAsync (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length, WSPI_CB_T* CB, BOOL bMore, BOOL bSpaceReserved);
  74. int WSPI_WriteAsync (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length, WSPI_CB_T* CB, BOOL bMore, BOOL bSpaceReserved);
  75. void WSPI_HandleFixedBusy(TI_HANDLE hWSPI, UINT32 *pRbuf);
  76. #ifdef USE_SYNC_API
  77. int WSPI_ReadSync (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length);
  78. int WSPI_WriteSync (TI_HANDLE hWSPI, UINT32 address, UINT8* data, UINT32 length);
  79. #endif
  80. void WSPI_SetErrLog (void* hWSPI, void (*fErr)(void));
  81. /* Size of WSPI command */
  82. #define WSPI_SIZEOF_CMD 4
  83. /* Used to decide whether we want to use the temp buffer in order to read/write the data */
  84. #define WSPI_NO_EXTRA_ALLOC_SIZE 4
  85. /* Init command length */
  86. #define WSPI_INIT_CMD_LEN 8
  87. /* Size of extra buffer size : */
  88. /* NumOfExtraFixedBusy * WordLen + DataLost(beacuse of fixed busy) * WordLen = 10 * 4 + 10 * 4 = 80 */
  89. #define WSPI_EXTRA_BUFFER_ALLOC_SIZE 80
  90. /* Define the number of bytes to be read after FIXED BUSY error without the ~Busy word */
  91. #define WSPI_EXTRA_READ_AFTER_NO_RESPONSE (28 - WSPI_NO_EXTRA_ALLOC_SIZE)
  92. /* WSPI handle */
  93. typedef struct _WSPI_t
  94. {
  95. TI_HANDLE hOs; /* OS wrapper */
  96. TI_HANDLE hReport; /* Report handler */
  97. TI_HANDLE hSPI; /* SPI driver handle */
  98. BOOL bFixedAddr; /* use fixed address */
  99. UINT32 uFixedBusyLen; /* number of fixed busy cycles */
  100. UINT32 uFixedBusyBytes; /* number of fixed busy bytes */
  101. UINT32 uFixedBusy; /* fixed busy buffer */
  102. UINT8 uConfigMask; /* configurable Mask for the Init CMD */
  103. UINT32 uCmd; /* command word */
  104. UINT8 auInitCmd [WSPI_INIT_CMD_LEN];
  105. /* init command buffer */
  106. UINT8* pTempBuf; /* used for buffers with no extra room for command/fixed busy */
  107. UINT8* data; /* save the pointer to the data for read */
  108. UINT32 length; /* save length of the buffer to be read */
  109. void (*fCb) (void *data, int status);
  110. /* callback function */
  111. void *pCb; /* callback argument */
  112. WSPI_Status_e status; /* holds the current status */
  113. BOOL bSpaceReserved; /* extra room was saved for the fixed busy or command */
  114. BOOL bMore; /* indicate whether more use of the SPI is about to take place */
  115. BOOL bUseTempBuf; /* use temporary buffer */
  116. void (*fErr) (void); /* user debug error handler */
  117. UINT8* pExtraFixedBusyBuf;
  118. /* used for a seconed SPI read */
  119. /* for calls that returend with more FixedBusy words than allowed */
  120. UINT32 ExtraBufLength; /* save length of the extra buffer to be read */
  121. int returnStatus; /* return status for SPI_XXX functions. Note that return status is from type int */
  122. #ifdef USE_SYNC_OVER_ASYNC
  123. /*
  124. * NOTE: This flag MUST be volatile because its value is changed
  125. * in the context of ISR. So, the compiler is prohibited
  126. * to make register optimization inside the routine it polls for
  127. */
  128. volatile int bSyncFlag;
  129. #endif
  130. } WSPI_t;
  131. #endif /* _WSPI_H_ */