fci_hal.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*****************************************************************************
  2. Copyright(c) 2012 FCI Inc. All Rights Reserved
  3. File name : fci_hal.c
  4. Description : fc8150 host interface
  5. *******************************************************************************/
  6. #include "fci_types.h"
  7. #include "fci_hal.h"
  8. #include "fc8150_hpi.h"
  9. #include "fc8150_spi.h"
  10. #include "fc8150_ppi.h"
  11. #include "fc8150_i2c.h"
  12. #include "fc8150_spib.h"
  13. struct IF_PORT{
  14. int (*init)(HANDLE hDevice, u16 param1, u16 param2);
  15. int (*byteread)(HANDLE hDevice, u16 addr, u8 *data);
  16. int (*wordread)(HANDLE hDevice, u16 addr, u16 *data);
  17. int (*longread)(HANDLE hDevice, u16 addr, u32 *data);
  18. int (*bulkread)(HANDLE hDevice, u16 addr, u8 *data, u16 length);
  19. int (*bytewrite)(HANDLE hDevice, u16 addr, u8 data);
  20. int (*wordwrite)(HANDLE hDevice, u16 addr, u16 data);
  21. int (*longwrite)(HANDLE hDevice, u16 addr, u32 data);
  22. int (*bulkwrite)(HANDLE hDevice, u16 addr, u8 *data, u16 length);
  23. int (*dataread)(HANDLE hDevice, u16 addr, u8 *data, u32 length);
  24. int (*deinit)(HANDLE hDevice);
  25. };
  26. static struct IF_PORT hpiif = {
  27. &fc8150_hpi_init,
  28. &fc8150_hpi_byteread,
  29. &fc8150_hpi_wordread,
  30. &fc8150_hpi_longread,
  31. &fc8150_hpi_bulkread,
  32. &fc8150_hpi_bytewrite,
  33. &fc8150_hpi_wordwrite,
  34. &fc8150_hpi_longwrite,
  35. &fc8150_hpi_bulkwrite,
  36. &fc8150_hpi_dataread,
  37. &fc8150_hpi_deinit
  38. };
  39. static struct IF_PORT spiif = {
  40. &fc8150_spi_init,
  41. &fc8150_spi_byteread,
  42. &fc8150_spi_wordread,
  43. &fc8150_spi_longread,
  44. &fc8150_spi_bulkread,
  45. &fc8150_spi_bytewrite,
  46. &fc8150_spi_wordwrite,
  47. &fc8150_spi_longwrite,
  48. &fc8150_spi_bulkwrite,
  49. &fc8150_spi_dataread,
  50. &fc8150_spi_deinit
  51. };
  52. static struct IF_PORT spibif = {
  53. &fc8150_spib_init,
  54. &fc8150_spib_byteread,
  55. &fc8150_spib_wordread,
  56. &fc8150_spib_longread,
  57. &fc8150_spib_bulkread,
  58. &fc8150_spib_bytewrite,
  59. &fc8150_spib_wordwrite,
  60. &fc8150_spib_longwrite,
  61. &fc8150_spib_bulkwrite,
  62. &fc8150_spib_dataread,
  63. &fc8150_spib_deinit
  64. };
  65. static struct IF_PORT ppiif = {
  66. &fc8150_ppi_init,
  67. &fc8150_ppi_byteread,
  68. &fc8150_ppi_wordread,
  69. &fc8150_ppi_longread,
  70. &fc8150_ppi_bulkread,
  71. &fc8150_ppi_bytewrite,
  72. &fc8150_ppi_wordwrite,
  73. &fc8150_ppi_longwrite,
  74. &fc8150_ppi_bulkwrite,
  75. &fc8150_ppi_dataread,
  76. &fc8150_ppi_deinit
  77. };
  78. static struct IF_PORT i2cif = {
  79. &fc8150_i2c_init,
  80. &fc8150_i2c_byteread,
  81. &fc8150_i2c_wordread,
  82. &fc8150_i2c_longread,
  83. &fc8150_i2c_bulkread,
  84. &fc8150_i2c_bytewrite,
  85. &fc8150_i2c_wordwrite,
  86. &fc8150_i2c_longwrite,
  87. &fc8150_i2c_bulkwrite,
  88. &fc8150_i2c_dataread,
  89. &fc8150_i2c_deinit
  90. };
  91. static struct IF_PORT *ifport = &spiif;
  92. u8 hostif_type = BBM_SPI;
  93. int bbm_hostif_select(HANDLE hDevice, u8 hostif)
  94. {
  95. hostif_type = hostif;
  96. switch (hostif) {
  97. case BBM_HPI:
  98. ifport = &hpiif;
  99. break;
  100. case BBM_SPI:
  101. ifport = &spiif;
  102. break;
  103. case BBM_I2C:
  104. ifport = &i2cif;
  105. break;
  106. case BBM_PPI:
  107. ifport = &ppiif;
  108. break;
  109. case BBM_SPIB:
  110. ifport = &spibif;
  111. break;
  112. default:
  113. return BBM_E_HOSTIF_SELECT;
  114. }
  115. if (ifport->init(hDevice, 0, 0))
  116. return BBM_E_HOSTIF_INIT;
  117. return BBM_OK;
  118. }
  119. int bbm_hostif_deselect(HANDLE hDevice)
  120. {
  121. if (ifport->deinit(hDevice))
  122. return BBM_NOK;
  123. ifport = NULL;
  124. hostif_type = BBM_SPI;
  125. return BBM_OK;
  126. }
  127. int bbm_read(HANDLE hDevice, u16 addr, u8 *data)
  128. {
  129. if (ifport->byteread(hDevice, addr, data))
  130. return BBM_E_BB_READ;
  131. return BBM_OK;
  132. }
  133. int bbm_byte_read(HANDLE hDevice, u16 addr, u8 *data)
  134. {
  135. if (ifport->byteread(hDevice, addr, data))
  136. return BBM_E_BB_READ;
  137. return BBM_OK;
  138. }
  139. int bbm_word_read(HANDLE hDevice, u16 addr, u16 *data)
  140. {
  141. if (ifport->wordread(hDevice, addr, data))
  142. return BBM_E_BB_READ;
  143. return BBM_OK;
  144. }
  145. int bbm_long_read(HANDLE hDevice, u16 addr, u32 *data)
  146. {
  147. if (ifport->longread(hDevice, addr, data))
  148. return BBM_E_BB_READ;
  149. return BBM_OK;
  150. }
  151. int bbm_bulk_read(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  152. {
  153. if (ifport->bulkread(hDevice, addr, data, length))
  154. return BBM_E_BB_READ;
  155. return BBM_OK;
  156. }
  157. int bbm_write(HANDLE hDevice, u16 addr, u8 data)
  158. {
  159. if (ifport->bytewrite(hDevice, addr, data))
  160. return BBM_E_BB_WRITE;
  161. return BBM_OK;
  162. }
  163. int bbm_byte_write(HANDLE hDevice, u16 addr, u8 data)
  164. {
  165. if (ifport->bytewrite(hDevice, addr, data))
  166. return BBM_E_BB_WRITE;
  167. return BBM_OK;
  168. }
  169. int bbm_word_write(HANDLE hDevice, u16 addr, u16 data)
  170. {
  171. if (ifport->wordwrite(hDevice, addr, data))
  172. return BBM_E_BB_WRITE;
  173. return BBM_OK;
  174. }
  175. int bbm_long_write(HANDLE hDevice, u16 addr, u32 data)
  176. {
  177. if (ifport->longwrite(hDevice, addr, data))
  178. return BBM_E_BB_WRITE;
  179. return BBM_OK;
  180. }
  181. int bbm_bulk_write(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  182. {
  183. if (ifport->bulkwrite(hDevice, addr, data, length))
  184. return BBM_E_BB_WRITE;
  185. return BBM_OK;
  186. }
  187. int bbm_data(HANDLE hDevice, u16 addr, u8 *data, u32 length)
  188. {
  189. if (ifport->dataread(hDevice, addr, data, length))
  190. return BBM_E_BB_WRITE;
  191. return BBM_OK;
  192. }