fci_hal.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*****************************************************************************
  2. Copyright(c) 2009 FCI Inc. All Rights Reserved
  3. File name : fci_hal.c
  4. Description : fc8050 host interface
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. History :
  17. ----------------------------------------------------------------------
  18. 2009/08/29 jason initial
  19. *******************************************************************************/
  20. #include "fci_types.h"
  21. #include "bbm.h"
  22. #include "fci_hal.h"
  23. /* #include "fc8050_hpi.h" */
  24. #include "fc8050_i2c.h"
  25. #if defined(CONFIG_TDMB_SPI)
  26. #include "fc8050_spi.h"
  27. #endif
  28. #if defined(CONFIG_TDMB_EBI)
  29. #include "fc8050_ppi.h"
  30. #endif
  31. #define FEATURE_INTERFACE_DEBUG
  32. struct interface_port {
  33. int (*init)(HANDLE hDevice, u16 param1, u16 param2);
  34. int (*byteread)(HANDLE hDevice, u16 addr, u8 *data);
  35. int (*wordread)(HANDLE hDevice, u16 addr, u16 *data);
  36. int (*longread)(HANDLE hDevice, u16 addr, u32 *data);
  37. int (*bulkread)(HANDLE hDevice, u16 addr, u8 *data, u16 size);
  38. int (*bytewrite)(HANDLE hDevice, u16 addr, u8 data);
  39. int (*wordwrite)(HANDLE hDevice, u16 addr, u16 data);
  40. int (*longwrite)(HANDLE hDevice, u16 addr, u32 data);
  41. int (*bulkwrite)(HANDLE hDevice, u16 addr, u8 *data, u16 size);
  42. int (*dataread)(HANDLE hDevice, u16 addr, u8 *data, u16 size);
  43. int (*deinit)(HANDLE hDevice);
  44. } ;
  45. static struct interface_port ifport;
  46. static u8 hostif_type = BBM_SPI;
  47. int bbm_hostif_get(HANDLE hDevice, u8 *hostif)
  48. {
  49. *hostif = hostif_type;
  50. return BBM_OK;
  51. }
  52. int bbm_hostif_select(HANDLE hDevice, u8 hostif, u32 param)
  53. {
  54. hostif_type = hostif;
  55. switch (hostif) {
  56. #if defined(CONFIG_TDMB_SPI)
  57. case BBM_SPI:
  58. ifport.init = fc8050_spi_init;
  59. ifport.byteread = fc8050_spi_byteread;
  60. ifport.wordread = fc8050_spi_wordread;
  61. ifport.longread = fc8050_spi_longread;
  62. ifport.bulkread = fc8050_spi_bulkread;
  63. ifport.bytewrite = fc8050_spi_bytewrite;
  64. ifport.wordwrite = fc8050_spi_wordwrite;
  65. ifport.longwrite = fc8050_spi_longwrite;
  66. ifport.bulkwrite = fc8050_spi_bulkwrite;
  67. ifport.dataread = fc8050_spi_dataread;
  68. ifport.deinit = fc8050_spi_deinit;
  69. break;
  70. #endif
  71. #ifndef FEATURE_INTERFACE_DEBUG
  72. case BBM_HPI:
  73. ifport.init = fc8050_hpi_init;
  74. ifport.byteread = fc8050_hpi_byteread;
  75. ifport.wordread = fc8050_hpi_wordread;
  76. ifport.longread = fc8050_hpi_longread;
  77. ifport.bulkread = fc8050_hpi_bulkread;
  78. ifport.bytewrite = fc8050_hpi_bytewrite;
  79. ifport.wordwrite = fc8050_hpi_wordwrite;
  80. ifport.longwrite = fc8050_hpi_longwrite;
  81. ifport.bulkwrite = fc8050_hpi_bulkwrite;
  82. ifport.dataread = fc8050_hpi_dataread;
  83. ifport.deinit = fc8050_hpi_deinit;
  84. break;
  85. case BBM_I2C:
  86. ifport.init = fc8050_i2c_init;
  87. ifport.byteread = fc8050_i2c_byteread;
  88. ifport.wordread = fc8050_i2c_wordread;
  89. ifport.longread = fc8050_i2c_longread;
  90. ifport.bulkread = fc8050_i2c_bulkread;
  91. ifport.bytewrite = fc8050_i2c_bytewrite;
  92. ifport.wordwrite = fc8050_i2c_wordwrite;
  93. ifport.longwrite = fc8050_i2c_longwrite;
  94. ifport.bulkwrite = fc8050_i2c_bulkwrite;
  95. ifport.dataread = fc8050_i2c_dataread;
  96. ifport.deinit = fc8050_i2c_deinit;
  97. break;
  98. #endif
  99. #if defined(CONFIG_TDMB_EBI)
  100. case BBM_PPI:
  101. ifport.init = fc8050_ppi_init;
  102. ifport.byteread = fc8050_ppi_byteread;
  103. ifport.wordread = fc8050_ppi_wordread;
  104. ifport.longread = fc8050_ppi_longread;
  105. ifport.bulkread = fc8050_ppi_bulkread;
  106. ifport.bytewrite = fc8050_ppi_bytewrite;
  107. ifport.wordwrite = fc8050_ppi_wordwrite;
  108. ifport.longwrite = fc8050_ppi_longwrite;
  109. ifport.bulkwrite = fc8050_ppi_bulkwrite;
  110. ifport.dataread = fc8050_ppi_dataread;
  111. ifport.deinit = fc8050_ppi_deinit;
  112. break;
  113. #endif
  114. default:
  115. return BBM_E_HOSTIF_SELECT;
  116. }
  117. if (ifport.init(hDevice, (param & 0xffff), ((param >> 16) & 0xffff)))
  118. return BBM_E_HOSTIF_INIT;
  119. return BBM_OK;
  120. }
  121. int bbm_hostif_deselect(HANDLE hDevice)
  122. {
  123. if (ifport.deinit(hDevice))
  124. return BBM_NOK;
  125. hostif_type = BBM_HPI;
  126. return BBM_OK;
  127. }
  128. int bbm_read(HANDLE hDevice, u16 addr, u8 *data)
  129. {
  130. if (ifport.byteread(hDevice, addr, data))
  131. return BBM_E_BB_REG_READ;
  132. return BBM_OK;
  133. }
  134. int bbm_byte_read(HANDLE hDevice, u16 addr, u8 *data)
  135. {
  136. if (ifport.byteread(hDevice, addr, data))
  137. return BBM_E_BB_REG_READ;
  138. return BBM_OK;
  139. }
  140. int bbm_word_read(HANDLE hDevice, u16 addr, u16 *data)
  141. {
  142. if (ifport.wordread(hDevice, addr, data))
  143. return BBM_E_BB_REG_READ;
  144. return BBM_OK;
  145. }
  146. int bbm_long_read(HANDLE hDevice, u16 addr, u32 *data)
  147. {
  148. if (ifport.longread(hDevice, addr, data))
  149. return BBM_E_BB_REG_READ;
  150. return BBM_OK;
  151. }
  152. int bbm_bulk_read(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  153. {
  154. if (ifport.bulkread(hDevice, addr, data, length))
  155. return BBM_E_BB_REG_READ;
  156. return BBM_OK;
  157. }
  158. int bbm_write(HANDLE hDevice, u16 addr, u8 data)
  159. {
  160. if (ifport.bytewrite(hDevice, addr, data))
  161. return BBM_E_BB_REG_WRITE;
  162. return BBM_OK;
  163. }
  164. int bbm_byte_write(HANDLE hDevice, u16 addr, u8 data)
  165. {
  166. if (ifport.bytewrite(hDevice, addr, data))
  167. return BBM_E_BB_REG_WRITE;
  168. return BBM_OK;
  169. }
  170. int bbm_word_write(HANDLE hDevice, u16 addr, u16 data)
  171. {
  172. if (ifport.wordwrite(hDevice, addr, data))
  173. return BBM_E_BB_REG_WRITE;
  174. return BBM_OK;
  175. }
  176. int bbm_long_write(HANDLE hDevice, u16 addr, u32 data)
  177. {
  178. if (ifport.longwrite(hDevice, addr, data))
  179. return BBM_E_BB_REG_WRITE;
  180. return BBM_OK;
  181. }
  182. int bbm_bulk_write(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  183. {
  184. if (ifport.bulkwrite(hDevice, addr, data, length))
  185. return BBM_E_BB_REG_WRITE;
  186. return BBM_OK;
  187. }
  188. int bbm_data(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  189. {
  190. if (ifport.dataread(hDevice, addr, data, length))
  191. return BBM_E_BB_REG_WRITE;
  192. return BBM_OK;
  193. }