fc8150_hpi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*****************************************************************************
  2. Copyright(c) 2012 FCI Inc. All Rights Reserved
  3. File name : fc8150_hpi.c
  4. Description : fc8150 host interface
  5. *******************************************************************************/
  6. #include "linux/io.h"
  7. #include "fci_types.h"
  8. #include "fc8150_regs.h"
  9. #include "fci_oal.h"
  10. #define HPIC_READ 0x01 /* read command */
  11. #define HPIC_WRITE 0x02 /* write command */
  12. #define HPIC_AINC 0x04 /* address increment */
  13. #define HPIC_BMODE 0x00 /* byte mode */
  14. #define HPIC_WMODE 0x10 /* word mode */
  15. #define HPIC_LMODE 0x20 /* long mode */
  16. #define HPIC_ENDIAN 0x00 /* little endian */
  17. #define HPIC_CLEAR 0x80 /* currently not used */
  18. #define BBM_BASE_ADDR 0
  19. #define BBM_BASE_OFFSET 0
  20. #define FC8150_ADDR_REG(x) outb(x, (BBM_BASE_ADDR \
  21. + (BBM_ADDRESS_REG << BBM_BASE_OFFSET)))
  22. #define FC8150_CMD_REG(x) outb(x, (BBM_BASE_ADDR \
  23. + (BBM_COMMAND_REG << BBM_BASE_OFFSET)))
  24. #define FC8150_DATA_REG_OUT(x) outb(x, (BBM_BASE_ADDR \
  25. + (BBM_DATA_REG << BBM_BASE_OFFSET)))
  26. #define FC8150_DATA_REG_IN inb(BBM_BASE_ADDR \
  27. + (BBM_DATA_REG << BBM_BASE_OFFSET))
  28. int fc8150_hpi_init(HANDLE hDevice, u16 param1, u16 param2)
  29. {
  30. OAL_CREATE_SEMAPHORE();
  31. return BBM_OK;
  32. }
  33. int fc8150_hpi_byteread(HANDLE hDevice, u16 addr, u8 *data)
  34. {
  35. u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
  36. OAL_OBTAIN_SEMAPHORE();
  37. FC8150_ADDR_REG(addr & 0xff);
  38. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  39. FC8150_CMD_REG(command);
  40. *data = FC8150_DATA_REG_IN;
  41. OAL_RELEASE_SEMAPHORE();
  42. return BBM_OK;
  43. }
  44. int fc8150_hpi_wordread(HANDLE hDevice, u16 addr, u16 *data)
  45. {
  46. u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
  47. OAL_OBTAIN_SEMAPHORE();
  48. FC8150_ADDR_REG(addr & 0xff);
  49. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  50. FC8150_CMD_REG(command);
  51. *data = FC8150_DATA_REG_IN;
  52. *data |= FC8150_DATA_REG_IN << 8;
  53. OAL_RELEASE_SEMAPHORE();
  54. return BBM_OK;
  55. }
  56. int fc8150_hpi_longread(HANDLE hDevice, u16 addr, u32 *data)
  57. {
  58. u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
  59. OAL_OBTAIN_SEMAPHORE();
  60. FC8150_ADDR_REG(addr & 0xff);
  61. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  62. FC8150_CMD_REG(command);
  63. *data = FC8150_DATA_REG_IN;
  64. *data |= FC8150_DATA_REG_IN << 8;
  65. *data |= FC8150_DATA_REG_IN << 16;
  66. *data |= FC8150_DATA_REG_IN << 24;
  67. OAL_RELEASE_SEMAPHORE();
  68. return BBM_OK;
  69. }
  70. int fc8150_hpi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  71. {
  72. s32 i;
  73. u8 command = HPIC_READ | HPIC_AINC | HPIC_BMODE | HPIC_ENDIAN;
  74. OAL_OBTAIN_SEMAPHORE();
  75. FC8150_ADDR_REG(addr & 0xff);
  76. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  77. FC8150_CMD_REG(command);
  78. for (i = 0; i < length; i++)
  79. data[i] = FC8150_DATA_REG_IN;
  80. OAL_RELEASE_SEMAPHORE();
  81. return BBM_OK;
  82. }
  83. int fc8150_hpi_bytewrite(HANDLE hDevice, u16 addr, u8 data)
  84. {
  85. u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN;
  86. OAL_OBTAIN_SEMAPHORE();
  87. FC8150_ADDR_REG(addr & 0xff);
  88. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  89. FC8150_CMD_REG(command);
  90. FC8150_DATA_REG_OUT(data);
  91. OAL_RELEASE_SEMAPHORE();
  92. return BBM_OK;
  93. }
  94. int fc8150_hpi_wordwrite(HANDLE hDevice, u16 addr, u16 data)
  95. {
  96. u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
  97. OAL_OBTAIN_SEMAPHORE();
  98. FC8150_ADDR_REG(addr & 0xff);
  99. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  100. FC8150_CMD_REG(command);
  101. FC8150_DATA_REG_OUT(data & 0xff);
  102. FC8150_DATA_REG_OUT((data & 0xff00) >> 8);
  103. OAL_RELEASE_SEMAPHORE();
  104. return BBM_OK;
  105. }
  106. int fc8150_hpi_longwrite(HANDLE hDevice, u16 addr, u32 data)
  107. {
  108. u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
  109. OAL_OBTAIN_SEMAPHORE();
  110. FC8150_ADDR_REG(addr & 0xff);
  111. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  112. FC8150_CMD_REG(command);
  113. FC8150_DATA_REG_OUT(data & 0xff);
  114. FC8150_DATA_REG_OUT((data & 0xff00) >> 8);
  115. FC8150_DATA_REG_OUT((data & 0xff0000) >> 16);
  116. FC8150_DATA_REG_OUT((data & 0xff000000) >> 24);
  117. OAL_RELEASE_SEMAPHORE();
  118. return BBM_OK;
  119. }
  120. int fc8150_hpi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  121. {
  122. s32 i;
  123. u8 command = HPIC_WRITE | HPIC_BMODE | HPIC_ENDIAN | HPIC_AINC;
  124. OAL_OBTAIN_SEMAPHORE();
  125. FC8150_ADDR_REG(addr & 0xff);
  126. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  127. FC8150_CMD_REG(command);
  128. for (i = 0; i < length; i++)
  129. FC8150_DATA_REG_OUT(data[i]);
  130. OAL_RELEASE_SEMAPHORE();
  131. return BBM_OK;
  132. }
  133. int fc8150_hpi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
  134. {
  135. s32 i;
  136. u8 command = HPIC_READ | HPIC_BMODE | HPIC_ENDIAN;
  137. OAL_OBTAIN_SEMAPHORE();
  138. FC8150_ADDR_REG(addr & 0xff);
  139. FC8150_ADDR_REG((addr & 0xff00) >> 8);
  140. FC8150_CMD_REG(command);
  141. for (i = 0; i < length; i++)
  142. data[i] = FC8150_DATA_REG_IN;
  143. OAL_RELEASE_SEMAPHORE();
  144. return BBM_OK;
  145. }
  146. int fc8150_hpi_deinit(HANDLE hDevice)
  147. {
  148. OAL_DELETE_SEMAPHORE();
  149. return BBM_OK;
  150. }