fci_hal.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fci_hal.c
  4. Description : source of 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. *******************************************************************************/
  19. #include "fci_types.h"
  20. #include "fci_hal.h"
  21. #include "fc8300_spi.h"
  22. #include "fc8300_ppi.h"
  23. #include "fc8300_i2c.h"
  24. struct IF_PORT {
  25. s32 (*init)(HANDLE handle, u16 param1, u16 param2);
  26. s32 (*byteread)(HANDLE handle, DEVICEID devid, u16 addr, u8 *data);
  27. s32 (*wordread)(HANDLE handle, DEVICEID devid, u16 addr, u16 *data);
  28. s32 (*longread)(HANDLE handle, DEVICEID devid, u16 addr, u32 *data);
  29. s32 (*bulkread)(HANDLE handle, DEVICEID devid,
  30. u16 addr, u8 *data, u16 length);
  31. s32 (*bytewrite)(HANDLE handle, DEVICEID devid, u16 addr, u8 data);
  32. s32 (*wordwrite)(HANDLE handle, DEVICEID devid, u16 addr, u16 data);
  33. s32 (*longwrite)(HANDLE handle, DEVICEID devid, u16 addr, u32 data);
  34. s32 (*bulkwrite)(HANDLE handle, DEVICEID devid,
  35. u16 addr, u8 *data, u16 length);
  36. s32 (*dataread)(HANDLE handle, DEVICEID devid,
  37. u16 addr, u8 *data, u32 length);
  38. s32 (*deinit)(HANDLE handle);
  39. };
  40. static struct IF_PORT spiif = {
  41. &fc8300_spi_init,
  42. &fc8300_spi_byteread,
  43. &fc8300_spi_wordread,
  44. &fc8300_spi_longread,
  45. &fc8300_spi_bulkread,
  46. &fc8300_spi_bytewrite,
  47. &fc8300_spi_wordwrite,
  48. &fc8300_spi_longwrite,
  49. &fc8300_spi_bulkwrite,
  50. &fc8300_spi_dataread,
  51. &fc8300_spi_deinit
  52. };
  53. static struct IF_PORT ppiif = {
  54. &fc8300_ppi_init,
  55. &fc8300_ppi_byteread,
  56. &fc8300_ppi_wordread,
  57. &fc8300_ppi_longread,
  58. &fc8300_ppi_bulkread,
  59. &fc8300_ppi_bytewrite,
  60. &fc8300_ppi_wordwrite,
  61. &fc8300_ppi_longwrite,
  62. &fc8300_ppi_bulkwrite,
  63. &fc8300_ppi_dataread,
  64. &fc8300_ppi_deinit
  65. };
  66. static struct IF_PORT i2cif = {
  67. &fc8300_i2c_init,
  68. &fc8300_i2c_byteread,
  69. &fc8300_i2c_wordread,
  70. &fc8300_i2c_longread,
  71. &fc8300_i2c_bulkread,
  72. &fc8300_i2c_bytewrite,
  73. &fc8300_i2c_wordwrite,
  74. &fc8300_i2c_longwrite,
  75. &fc8300_i2c_bulkwrite,
  76. &fc8300_i2c_dataread,
  77. &fc8300_i2c_deinit
  78. };
  79. static struct IF_PORT *ifport = &i2cif;
  80. static u8 hostif_type = BBM_I2C;
  81. s32 bbm_hostif_select(HANDLE handle, u8 hostif)
  82. {
  83. hostif_type = hostif;
  84. switch (hostif) {
  85. case BBM_SPI:
  86. ifport = &spiif;
  87. break;
  88. case BBM_I2C:
  89. ifport = &i2cif;
  90. break;
  91. case BBM_PPI:
  92. ifport = &ppiif;
  93. break;
  94. default:
  95. return BBM_E_HOSTIF_SELECT;
  96. }
  97. if (ifport->init(handle, 0, 0))
  98. return BBM_E_HOSTIF_INIT;
  99. return BBM_OK;
  100. }
  101. s32 bbm_hostif_deselect(HANDLE handle)
  102. {
  103. if (ifport->deinit(handle))
  104. return BBM_NOK;
  105. ifport = &spiif;
  106. hostif_type = BBM_SPI;
  107. return BBM_OK;
  108. }
  109. s32 bbm_read(HANDLE handle, DEVICEID devid, u16 addr, u8 *data)
  110. {
  111. if (ifport->byteread(handle, devid, addr, data))
  112. return BBM_E_BB_READ;
  113. return BBM_OK;
  114. }
  115. s32 bbm_byte_read(HANDLE handle, DEVICEID devid, u16 addr, u8 *data)
  116. {
  117. if (ifport->byteread(handle, devid, addr, data))
  118. return BBM_E_BB_READ;
  119. return BBM_OK;
  120. }
  121. s32 bbm_word_read(HANDLE handle, DEVICEID devid, u16 addr, u16 *data)
  122. {
  123. if (ifport->wordread(handle, devid, addr, data))
  124. return BBM_E_BB_READ;
  125. return BBM_OK;
  126. }
  127. s32 bbm_long_read(HANDLE handle, DEVICEID devid, u16 addr, u32 *data)
  128. {
  129. if (ifport->longread(handle, devid, addr, data))
  130. return BBM_E_BB_READ;
  131. return BBM_OK;
  132. }
  133. s32 bbm_bulk_read(HANDLE handle, DEVICEID devid,
  134. u16 addr, u8 *data, u16 length)
  135. {
  136. if (ifport->bulkread(handle, devid, addr, data, length))
  137. return BBM_E_BB_READ;
  138. return BBM_OK;
  139. }
  140. s32 bbm_write(HANDLE handle, DEVICEID devid, u16 addr, u8 data)
  141. {
  142. if (ifport->bytewrite(handle, devid, addr, data))
  143. return BBM_E_BB_WRITE;
  144. return BBM_OK;
  145. }
  146. s32 bbm_byte_write(HANDLE handle, DEVICEID devid, u16 addr, u8 data)
  147. {
  148. if (ifport->bytewrite(handle, devid, addr, data))
  149. return BBM_E_BB_WRITE;
  150. return BBM_OK;
  151. }
  152. s32 bbm_word_write(HANDLE handle, DEVICEID devid, u16 addr, u16 data)
  153. {
  154. if (ifport->wordwrite(handle, devid, addr, data))
  155. return BBM_E_BB_WRITE;
  156. return BBM_OK;
  157. }
  158. s32 bbm_long_write(HANDLE handle, DEVICEID devid, u16 addr, u32 data)
  159. {
  160. if (ifport->longwrite(handle, devid, addr, data))
  161. return BBM_E_BB_WRITE;
  162. return BBM_OK;
  163. }
  164. s32 bbm_bulk_write(HANDLE handle, DEVICEID devid,
  165. u16 addr, u8 *data, u16 length)
  166. {
  167. if (ifport->bulkwrite(handle, devid, addr, data, length))
  168. return BBM_E_BB_WRITE;
  169. return BBM_OK;
  170. }
  171. s32 bbm_data(HANDLE handle, DEVICEID devid, u16 addr, u8 *data, u32 length)
  172. {
  173. if (ifport->dataread(handle, devid, addr, data, length))
  174. return BBM_E_BB_WRITE;
  175. return BBM_OK;
  176. }