fc8150_ppi.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*****************************************************************************
  2. Copyright(c) 2012 FCI Inc. All Rights Reserved
  3. File name : fc8150_ppi.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 BBM_BASE_ADDR 0x00
  11. #define PPI_BMODE 0x00
  12. #define PPI_WMODE 0x10
  13. #define PPI_LMODE 0x20
  14. #define PPI_READ 0x40
  15. #define PPI_WRITE 0x00
  16. #define PPI_AINC 0x80
  17. #define FC8150_PPI_REG_OUT(x) outb(x, BBM_BASE_ADDR)
  18. #define FC8150_PPI_REG_IN inb(BBM_BASE_ADDR)
  19. int fc8150_ppi_init(HANDLE hDevice, u16 param1, u16 param2)
  20. {
  21. OAL_CREATE_SEMAPHORE();
  22. return BBM_OK;
  23. }
  24. int fc8150_ppi_byteread(HANDLE hDevice, u16 addr, u8 *data)
  25. {
  26. u32 length = 1;
  27. OAL_OBTAIN_SEMAPHORE();
  28. FC8150_PPI_REG_OUT(addr & 0xff);
  29. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  30. FC8150_PPI_REG_OUT(PPI_READ | ((length & 0x0f0000) >> 16));
  31. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  32. FC8150_PPI_REG_OUT(length & 0xff);
  33. *data = FC8150_PPI_REG_IN;
  34. OAL_RELEASE_SEMAPHORE();
  35. return BBM_OK;
  36. }
  37. int fc8150_ppi_wordread(HANDLE hDevice, u16 addr, u16 *data)
  38. {
  39. u32 length = 2;
  40. u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
  41. OAL_OBTAIN_SEMAPHORE();
  42. FC8150_PPI_REG_OUT(addr & 0xff);
  43. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  44. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  45. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  46. FC8150_PPI_REG_OUT(length & 0xff);
  47. *data = FC8150_PPI_REG_IN;
  48. *data |= FC8150_PPI_REG_IN << 8;
  49. OAL_RELEASE_SEMAPHORE();
  50. return BBM_OK;
  51. }
  52. int fc8150_ppi_longread(HANDLE hDevice, u16 addr, u32 *data)
  53. {
  54. u32 length = 4;
  55. u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
  56. OAL_OBTAIN_SEMAPHORE();
  57. FC8150_PPI_REG_OUT(addr & 0xff);
  58. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  59. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  60. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  61. FC8150_PPI_REG_OUT(length & 0xff);
  62. *data = FC8150_PPI_REG_IN;
  63. *data |= FC8150_PPI_REG_IN << 8;
  64. *data |= FC8150_PPI_REG_IN << 16;
  65. *data |= FC8150_PPI_REG_IN << 24;
  66. OAL_RELEASE_SEMAPHORE();
  67. return BBM_OK;
  68. }
  69. int fc8150_ppi_bulkread(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  70. {
  71. int i;
  72. u8 command = PPI_AINC | PPI_READ | PPI_BMODE;
  73. OAL_OBTAIN_SEMAPHORE();
  74. FC8150_PPI_REG_OUT(addr & 0xff);
  75. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  76. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  77. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  78. FC8150_PPI_REG_OUT(length & 0xff);
  79. for (i = 0; i < length; i++)
  80. data[i] = FC8150_PPI_REG_IN;
  81. OAL_RELEASE_SEMAPHORE();
  82. return BBM_OK;
  83. }
  84. int fc8150_ppi_bytewrite(HANDLE hDevice, u16 addr, u8 data)
  85. {
  86. u32 length = 1;
  87. OAL_OBTAIN_SEMAPHORE();
  88. FC8150_PPI_REG_OUT(addr & 0xff);
  89. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  90. FC8150_PPI_REG_OUT(PPI_WRITE | ((length & 0x0f0000) >> 16));
  91. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  92. FC8150_PPI_REG_OUT(length & 0xff);
  93. FC8150_PPI_REG_OUT(data);
  94. OAL_RELEASE_SEMAPHORE();
  95. return BBM_OK;
  96. }
  97. int fc8150_ppi_wordwrite(HANDLE hDevice, u16 addr, u16 data)
  98. {
  99. u32 length = 2;
  100. u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
  101. OAL_OBTAIN_SEMAPHORE();
  102. FC8150_PPI_REG_OUT(addr & 0xff);
  103. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  104. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  105. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  106. FC8150_PPI_REG_OUT(length & 0xff);
  107. FC8150_PPI_REG_OUT(data & 0xff);
  108. FC8150_PPI_REG_OUT((data & 0xff00) >> 8);
  109. OAL_RELEASE_SEMAPHORE();
  110. return BBM_OK;
  111. }
  112. int fc8150_ppi_longwrite(HANDLE hDevice, u16 addr, u32 data)
  113. {
  114. u32 length = 4;
  115. u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
  116. OAL_OBTAIN_SEMAPHORE();
  117. FC8150_PPI_REG_OUT(addr & 0xff);
  118. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  119. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  120. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  121. FC8150_PPI_REG_OUT(length & 0xff);
  122. FC8150_PPI_REG_OUT(data & 0x000000ff);
  123. FC8150_PPI_REG_OUT((data & 0x0000ff00) >> 8);
  124. FC8150_PPI_REG_OUT((data & 0x00ff0000) >> 16);
  125. FC8150_PPI_REG_OUT((data & 0xff000000) >> 24);
  126. OAL_RELEASE_SEMAPHORE();
  127. return BBM_OK;
  128. }
  129. int fc8150_ppi_bulkwrite(HANDLE hDevice, u16 addr, u8 *data, u16 length)
  130. {
  131. int i;
  132. u8 command = PPI_AINC | PPI_WRITE | PPI_BMODE;
  133. OAL_OBTAIN_SEMAPHORE();
  134. FC8150_PPI_REG_OUT(addr & 0xff);
  135. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  136. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  137. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  138. FC8150_PPI_REG_OUT(length & 0xff);
  139. for (i = 0; i < length; i++)
  140. FC8150_PPI_REG_OUT(data[i]);
  141. OAL_RELEASE_SEMAPHORE();
  142. return BBM_OK;
  143. }
  144. int fc8150_ppi_dataread(HANDLE hDevice, u16 addr, u8 *data, u32 length)
  145. {
  146. int i;
  147. u8 command = PPI_READ | PPI_BMODE;
  148. OAL_OBTAIN_SEMAPHORE();
  149. FC8150_PPI_REG_OUT(addr & 0xff);
  150. FC8150_PPI_REG_OUT((addr & 0xff00) >> 8);
  151. FC8150_PPI_REG_OUT(command | ((length & 0x0f0000) >> 16));
  152. FC8150_PPI_REG_OUT((length & 0xff00) >> 8);
  153. FC8150_PPI_REG_OUT(length & 0xff);
  154. for (i = 0; i < length; i++)
  155. data[i] = FC8150_PPI_REG_IN;
  156. OAL_RELEASE_SEMAPHORE();
  157. return BBM_OK;
  158. }
  159. int fc8150_ppi_deinit(HANDLE hDevice)
  160. {
  161. OAL_DELETE_SEMAPHORE();
  162. return BBM_OK;
  163. }