fc8080_ppi.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*****************************************************************************
  2. Copyright(c) 2013 FCI Inc. All Rights Reserved
  3. File name : fc8080_ppi.c
  4. Description : EBI2LCD interface header file
  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 <linux/mutex.h>
  21. #include "fci_types.h"
  22. #include "fc8080_regs.h"
  23. #include "fc8080_ppi.h"
  24. #include "fci_oal.h"
  25. #include "tdmb.h"
  26. #define BBM_BASE_ADDR (0)
  27. #define PPI_BMODE 0x00
  28. #define PPI_WMODE 0x04
  29. #define PPI_LMODE 0x08
  30. #define PPI_RD_THRESH 0x30
  31. #define PPI_RD_REG 0x20
  32. #define PPI_READ 0x40
  33. #define PPI_WRITE 0x00
  34. #define PPI_AINC 0x80
  35. static DEFINE_MUTEX(lock);
  36. u32 base_address;
  37. #define FC8080_PPI_REG_OUT(x) writeb(x, (void __iomem *)base_address)
  38. #define FC8080_PPI_REG_IN readb((void __iomem *)base_address)
  39. s32 fc8080_ppi_init(HANDLE handle, u16 param1, u16 param2)
  40. {
  41. base_address = param2;
  42. base_address <<= 16;
  43. base_address |= param1;
  44. DPRINTK("%s : 0x%p\n", __func__, (void __iomem *)base_address);
  45. return BBM_OK;
  46. }
  47. s32 fc8080_ppi_byteread(HANDLE handle, u16 addr, u8 *data)
  48. {
  49. u16 length = 1;
  50. u8 command;
  51. mutex_lock(&lock);
  52. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  53. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  54. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  55. FC8080_PPI_REG_OUT(addr & 0x0f);
  56. command = (u8) (PPI_READ);
  57. FC8080_PPI_REG_OUT(command >> 4);
  58. FC8080_PPI_REG_OUT(command);
  59. FC8080_PPI_REG_OUT(length >> 4);
  60. FC8080_PPI_REG_OUT(length);
  61. *data = FC8080_PPI_REG_IN << 4;
  62. *data |= (FC8080_PPI_REG_IN & 0x0f);
  63. mutex_unlock(&lock);
  64. return BBM_OK;
  65. }
  66. s32 fc8080_ppi_wordread(HANDLE handle, u16 addr, u16 *data)
  67. {
  68. u16 length = 2;
  69. u8 command;
  70. mutex_lock(&lock);
  71. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  72. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  73. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  74. FC8080_PPI_REG_OUT(addr & 0x0f);
  75. command = (u8) (PPI_READ | PPI_AINC);
  76. FC8080_PPI_REG_OUT(command >> 4);
  77. FC8080_PPI_REG_OUT(command);
  78. FC8080_PPI_REG_OUT(length >> 4);
  79. FC8080_PPI_REG_OUT(length);
  80. *data = (FC8080_PPI_REG_IN & 0x0f) << 4;
  81. *data |= FC8080_PPI_REG_IN & 0x0f;
  82. *data |= (FC8080_PPI_REG_IN & 0x0f) << 12;
  83. *data |= (FC8080_PPI_REG_IN & 0x0f) << 8;
  84. mutex_unlock(&lock);
  85. return BBM_OK;
  86. }
  87. s32 fc8080_ppi_longread(HANDLE handle, u16 addr, u32 *data)
  88. {
  89. u16 length = 4;
  90. u8 command;
  91. mutex_lock(&lock);
  92. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  93. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  94. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  95. FC8080_PPI_REG_OUT(addr & 0x0f);
  96. command = (u8) (PPI_READ | PPI_AINC);
  97. FC8080_PPI_REG_OUT(command >> 4);
  98. FC8080_PPI_REG_OUT(command);
  99. FC8080_PPI_REG_OUT(length >> 4);
  100. FC8080_PPI_REG_OUT(length);
  101. *data = (FC8080_PPI_REG_IN & 0x0f) << 4;
  102. *data |= FC8080_PPI_REG_IN & 0x0f;
  103. *data |= (FC8080_PPI_REG_IN & 0x0f) << 12;
  104. *data |= (FC8080_PPI_REG_IN & 0x0f) << 8;
  105. *data |= (FC8080_PPI_REG_IN & 0x0f) << 20;
  106. *data |= (FC8080_PPI_REG_IN & 0x0f) << 16;
  107. *data |= (FC8080_PPI_REG_IN & 0x0f) << 28;
  108. *data |= (FC8080_PPI_REG_IN & 0x0f) << 24;
  109. mutex_unlock(&lock);
  110. return BBM_OK;
  111. }
  112. s32 fc8080_ppi_bulkread(HANDLE handle, u16 addr, u8 *data, u16 length)
  113. {
  114. s32 i, j;
  115. u8 command;
  116. u16 x, y;
  117. x = length / 255;
  118. y = length % 255;
  119. mutex_lock(&lock);
  120. for (i = 0; i < x; i++, addr += 255) {
  121. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  122. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  123. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  124. FC8080_PPI_REG_OUT(addr & 0x0f);
  125. command = (u8) (PPI_READ | PPI_AINC);
  126. FC8080_PPI_REG_OUT(command >> 4);
  127. FC8080_PPI_REG_OUT(command);
  128. FC8080_PPI_REG_OUT((255 >> 4) & 0x0f);
  129. FC8080_PPI_REG_OUT(255 & 0x0f);
  130. for (j = 0; j < 255; j++) {
  131. data[i * 255 + j] =
  132. (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
  133. data[i * 255 + j] |=
  134. (u8) (FC8080_PPI_REG_IN & 0x0f);
  135. }
  136. }
  137. if (y) {
  138. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  139. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  140. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  141. FC8080_PPI_REG_OUT(addr & 0x0f);
  142. command = (u8) (PPI_READ | PPI_AINC);
  143. FC8080_PPI_REG_OUT(command >> 4);
  144. FC8080_PPI_REG_OUT(command);
  145. FC8080_PPI_REG_OUT((y >> 4) & 0x0f);
  146. FC8080_PPI_REG_OUT(y & 0x0f);
  147. for (j = 0; j < y; j++) {
  148. data[x * 255 + j] =
  149. (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
  150. data[x * 255 + j] |=
  151. (u8) (FC8080_PPI_REG_IN & 0x0f);
  152. }
  153. }
  154. mutex_unlock(&lock);
  155. return BBM_OK;
  156. }
  157. s32 fc8080_ppi_bytewrite(HANDLE handle, u16 addr, u8 data)
  158. {
  159. u16 length = 1;
  160. u8 command;
  161. mutex_lock(&lock);
  162. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  163. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  164. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  165. FC8080_PPI_REG_OUT(addr & 0x0f);
  166. command = (u8) (PPI_WRITE);
  167. FC8080_PPI_REG_OUT(command >> 4);
  168. FC8080_PPI_REG_OUT(command);
  169. FC8080_PPI_REG_OUT(length >> 4);
  170. FC8080_PPI_REG_OUT(length);
  171. FC8080_PPI_REG_OUT(data >> 4);
  172. FC8080_PPI_REG_OUT(data);
  173. mutex_unlock(&lock);
  174. return BBM_OK;
  175. }
  176. s32 fc8080_ppi_wordwrite(HANDLE handle, u16 addr, u16 data)
  177. {
  178. u16 length = 2;
  179. u8 command;
  180. mutex_lock(&lock);
  181. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  182. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  183. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  184. FC8080_PPI_REG_OUT(addr & 0x0f);
  185. command = (u8) (PPI_WRITE | PPI_AINC);
  186. FC8080_PPI_REG_OUT(command >> 4);
  187. FC8080_PPI_REG_OUT(command);
  188. FC8080_PPI_REG_OUT(length >> 4);
  189. FC8080_PPI_REG_OUT(length);
  190. FC8080_PPI_REG_OUT(data >> 4);
  191. FC8080_PPI_REG_OUT(data);
  192. FC8080_PPI_REG_OUT(data >> 12);
  193. FC8080_PPI_REG_OUT(data >> 8);
  194. mutex_unlock(&lock);
  195. return BBM_OK;
  196. }
  197. s32 fc8080_ppi_longwrite(HANDLE handle, u16 addr, u32 data)
  198. {
  199. u16 length = 4;
  200. u8 command;
  201. mutex_lock(&lock);
  202. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  203. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  204. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  205. FC8080_PPI_REG_OUT(addr & 0x0f);
  206. command = (u8) (PPI_WRITE | PPI_AINC);
  207. FC8080_PPI_REG_OUT(command >> 4);
  208. FC8080_PPI_REG_OUT(command);
  209. FC8080_PPI_REG_OUT(length >> 4);
  210. FC8080_PPI_REG_OUT(length);
  211. FC8080_PPI_REG_OUT(data >> 4);
  212. FC8080_PPI_REG_OUT(data);
  213. FC8080_PPI_REG_OUT(data >> 12);
  214. FC8080_PPI_REG_OUT(data >> 8);
  215. FC8080_PPI_REG_OUT(data >> 20);
  216. FC8080_PPI_REG_OUT(data >> 16);
  217. FC8080_PPI_REG_OUT(data >> 28);
  218. FC8080_PPI_REG_OUT(data >> 24);
  219. mutex_unlock(&lock);
  220. return BBM_OK;
  221. }
  222. s32 fc8080_ppi_bulkwrite(HANDLE handle, u16 addr, u8 *data, u16 length)
  223. {
  224. s32 i, j;
  225. u8 command;
  226. u16 x, y;
  227. x = length / 255;
  228. y = length % 255;
  229. mutex_lock(&lock);
  230. for (i = 0; i < x; i++, addr += 255) {
  231. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  232. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  233. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  234. FC8080_PPI_REG_OUT(addr & 0x0f);
  235. command = (u8) (PPI_WRITE | PPI_AINC);
  236. FC8080_PPI_REG_OUT(command >> 4);
  237. FC8080_PPI_REG_OUT(command);
  238. FC8080_PPI_REG_OUT((255 >> 4) & 0x0f);
  239. FC8080_PPI_REG_OUT(255 & 0x0f);
  240. for (j = 0; j < 255; j++) {
  241. FC8080_PPI_REG_OUT((data[i * 255 + j] >> 4) & 0x0f);
  242. FC8080_PPI_REG_OUT(data[i * 255 + j] & 0x0f);
  243. }
  244. }
  245. if (y) {
  246. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  247. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  248. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  249. FC8080_PPI_REG_OUT(addr & 0x0f);
  250. command = (u8) (PPI_WRITE | PPI_AINC);
  251. FC8080_PPI_REG_OUT(command >> 4);
  252. FC8080_PPI_REG_OUT(command);
  253. FC8080_PPI_REG_OUT((y >> 4) & 0x0f);
  254. FC8080_PPI_REG_OUT(y & 0x0f);
  255. for (j = 0; j < y; j++) {
  256. FC8080_PPI_REG_OUT((data[x * 255 + j] >> 4) & 0x0f);
  257. FC8080_PPI_REG_OUT(data[x * 255 + j] & 0x0f);
  258. }
  259. }
  260. mutex_unlock(&lock);
  261. return BBM_OK;
  262. }
  263. s32 fc8080_ppi_dataread(HANDLE handle, u16 addr, u8 *data, u32 length)
  264. {
  265. s32 i;
  266. u8 command;
  267. mutex_lock(&lock);
  268. FC8080_PPI_REG_OUT((addr >> 12) & 0x0f);
  269. FC8080_PPI_REG_OUT((addr >> 8) & 0x0f);
  270. FC8080_PPI_REG_OUT((addr >> 4) & 0x0f);
  271. FC8080_PPI_REG_OUT(addr & 0x0f);
  272. command = (u8) (PPI_READ | PPI_RD_THRESH);
  273. FC8080_PPI_REG_OUT(command >> 4);
  274. FC8080_PPI_REG_OUT(command);
  275. FC8080_PPI_REG_OUT(0);
  276. FC8080_PPI_REG_OUT(0);
  277. for (i = 0; i < length; i++) {
  278. data[i] = (u8) ((FC8080_PPI_REG_IN & 0x0f) << 4);
  279. data[i] |= (u8) (FC8080_PPI_REG_IN & 0x0f);
  280. }
  281. mutex_unlock(&lock);
  282. return BBM_OK;
  283. }
  284. s32 fc8080_ppi_deinit(HANDLE handle)
  285. {
  286. base_address = 0;
  287. return BBM_OK;
  288. }