fc8300_ppi.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fc8300_ppi.c
  4. Description : source of EBI2/LCD 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 "linux/io.h"
  20. #include "fci_types.h"
  21. #include "fc8300_regs.h"
  22. #include "fci_oal.h"
  23. #define BBM_BASE_ADDR 0x00
  24. #define PPI_LEN 0x10
  25. #define PPI_REG 0x20
  26. #define PPI_THR 0x30
  27. #define PPI_READ 0x40
  28. #define PPI_WRITE 0x00
  29. #define PPI_AINC 0x80
  30. #define FC8300_PPI_REG_OUT(x) outb(x, BBM_BASE_ADDR)
  31. #define FC8300_PPI_REG_IN inb(BBM_BASE_ADDR)
  32. s32 fc8300_ppi_init(HANDLE handle, u16 param1, u16 param2)
  33. {
  34. OAL_CREATE_SEMAPHORE();
  35. return BBM_OK;
  36. }
  37. s32 fc8300_ppi_byteread(HANDLE handle, DEVICEID devid, u16 addr, u8 *data)
  38. {
  39. u16 length = 1;
  40. u8 command = PPI_READ;
  41. OAL_OBTAIN_SEMAPHORE();
  42. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  43. FC8300_PPI_REG_OUT(addr & 0xff);
  44. FC8300_PPI_REG_OUT(command);
  45. FC8300_PPI_REG_OUT(length & 0xff);
  46. *data = FC8300_PPI_REG_IN;
  47. OAL_RELEASE_SEMAPHORE();
  48. return BBM_OK;
  49. }
  50. s32 fc8300_ppi_wordread(HANDLE handle, DEVICEID devid, u16 addr, u16 *data)
  51. {
  52. u16 length = 2;
  53. u8 command = PPI_AINC | PPI_READ;
  54. OAL_OBTAIN_SEMAPHORE();
  55. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  56. FC8300_PPI_REG_OUT(addr & 0xff);
  57. FC8300_PPI_REG_OUT(command);
  58. FC8300_PPI_REG_OUT(length & 0xff);
  59. *data = FC8300_PPI_REG_IN;
  60. *data |= FC8300_PPI_REG_IN << 8;
  61. OAL_RELEASE_SEMAPHORE();
  62. return BBM_OK;
  63. }
  64. s32 fc8300_ppi_longread(HANDLE handle, DEVICEID devid, u16 addr, u32 *data)
  65. {
  66. u16 length = 4;
  67. u8 command = PPI_AINC | PPI_READ;
  68. OAL_OBTAIN_SEMAPHORE();
  69. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  70. FC8300_PPI_REG_OUT(addr & 0xff);
  71. FC8300_PPI_REG_OUT(command);
  72. FC8300_PPI_REG_OUT(length & 0xff);
  73. *data = FC8300_PPI_REG_IN;
  74. *data |= FC8300_PPI_REG_IN << 8;
  75. *data |= FC8300_PPI_REG_IN << 16;
  76. *data |= FC8300_PPI_REG_IN << 24;
  77. OAL_RELEASE_SEMAPHORE();
  78. return BBM_OK;
  79. }
  80. s32 fc8300_ppi_bulkread(HANDLE handle, DEVICEID devid,
  81. u16 addr, u8 *data, u16 length)
  82. {
  83. s32 i;
  84. u8 command = PPI_AINC | PPI_READ;
  85. OAL_OBTAIN_SEMAPHORE();
  86. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  87. FC8300_PPI_REG_OUT(addr & 0xff);
  88. FC8300_PPI_REG_OUT(command);
  89. FC8300_PPI_REG_OUT(length & 0xff);
  90. for (i = 0; i < length; i++)
  91. data[i] = FC8300_PPI_REG_IN;
  92. OAL_RELEASE_SEMAPHORE();
  93. return BBM_OK;
  94. }
  95. s32 fc8300_ppi_bytewrite(HANDLE handle, DEVICEID devid, u16 addr, u8 data)
  96. {
  97. u16 length = 1;
  98. u8 command = PPI_WRITE;
  99. OAL_OBTAIN_SEMAPHORE();
  100. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  101. FC8300_PPI_REG_OUT(addr & 0xff);
  102. FC8300_PPI_REG_OUT(command);
  103. FC8300_PPI_REG_OUT(length & 0xff);
  104. FC8300_PPI_REG_OUT(data);
  105. OAL_RELEASE_SEMAPHORE();
  106. return BBM_OK;
  107. }
  108. s32 fc8300_ppi_wordwrite(HANDLE handle, DEVICEID devid, u16 addr, u16 data)
  109. {
  110. u16 length = 2;
  111. u8 command = PPI_AINC | PPI_WRITE;
  112. OAL_OBTAIN_SEMAPHORE();
  113. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  114. FC8300_PPI_REG_OUT(addr & 0xff);
  115. FC8300_PPI_REG_OUT(command);
  116. FC8300_PPI_REG_OUT(length & 0xff);
  117. FC8300_PPI_REG_OUT(data & 0xff);
  118. FC8300_PPI_REG_OUT((data & 0xff00) >> 8);
  119. OAL_RELEASE_SEMAPHORE();
  120. return BBM_OK;
  121. }
  122. s32 fc8300_ppi_longwrite(HANDLE handle, DEVICEID devid, u16 addr, u32 data)
  123. {
  124. u16 length = 4;
  125. u8 command = PPI_AINC | PPI_WRITE;
  126. OAL_OBTAIN_SEMAPHORE();
  127. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  128. FC8300_PPI_REG_OUT(addr & 0xff);
  129. FC8300_PPI_REG_OUT(command);
  130. FC8300_PPI_REG_OUT(length & 0xff);
  131. FC8300_PPI_REG_OUT(data & 0x000000ff);
  132. FC8300_PPI_REG_OUT((data & 0x0000ff00) >> 8);
  133. FC8300_PPI_REG_OUT((data & 0x00ff0000) >> 16);
  134. FC8300_PPI_REG_OUT((data & 0xff000000) >> 24);
  135. OAL_RELEASE_SEMAPHORE();
  136. return BBM_OK;
  137. }
  138. s32 fc8300_ppi_bulkwrite(HANDLE handle, DEVICEID devid,
  139. u16 addr, u8 *data, u16 length)
  140. {
  141. s32 i;
  142. u8 command = PPI_AINC | PPI_WRITE;
  143. OAL_OBTAIN_SEMAPHORE();
  144. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  145. FC8300_PPI_REG_OUT(addr & 0xff);
  146. FC8300_PPI_REG_OUT(command);
  147. FC8300_PPI_REG_OUT(length & 0xff);
  148. for (i = 0; i < length; i++)
  149. FC8300_PPI_REG_OUT(data[i]);
  150. OAL_RELEASE_SEMAPHORE();
  151. return BBM_OK;
  152. }
  153. s32 fc8300_ppi_dataread(HANDLE handle, DEVICEID devid,
  154. u16 addr, u8 *data, u32 length)
  155. {
  156. s32 i;
  157. u8 command = PPI_READ | PPI_THR;
  158. OAL_OBTAIN_SEMAPHORE();
  159. FC8300_PPI_REG_OUT((addr & 0xff00) >> 8);
  160. FC8300_PPI_REG_OUT(addr & 0xff);
  161. FC8300_PPI_REG_OUT(command);
  162. FC8300_PPI_REG_OUT(0);
  163. for (i = 0; i < length; i++)
  164. data[i] = FC8300_PPI_REG_IN;
  165. OAL_RELEASE_SEMAPHORE();
  166. return BBM_OK;
  167. }
  168. s32 fc8300_ppi_deinit(HANDLE handle)
  169. {
  170. OAL_DELETE_SEMAPHORE();
  171. return BBM_OK;
  172. }