sm750_cursor.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/errno.h>
  4. #include <linux/string.h>
  5. #include <linux/mm.h>
  6. #include <linux/slab.h>
  7. #include <linux/delay.h>
  8. #include <linux/fb.h>
  9. #include <linux/ioport.h>
  10. #include <linux/init.h>
  11. #include <linux/pci.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/console.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/screen_info.h>
  17. #include "sm750.h"
  18. #include "sm750_help.h"
  19. #include "sm750_cursor.h"
  20. #define PEEK32(addr) \
  21. readl(cursor->mmio + (addr))
  22. #define POKE32(addr, data) \
  23. writel((data), cursor->mmio + (addr))
  24. /* cursor control for voyager and 718/750*/
  25. #define HWC_ADDRESS 0x0
  26. #define HWC_ADDRESS_ENABLE 31:31
  27. #define HWC_ADDRESS_ENABLE_DISABLE 0
  28. #define HWC_ADDRESS_ENABLE_ENABLE 1
  29. #define HWC_ADDRESS_EXT 27:27
  30. #define HWC_ADDRESS_EXT_LOCAL 0
  31. #define HWC_ADDRESS_EXT_EXTERNAL 1
  32. #define HWC_ADDRESS_CS 26:26
  33. #define HWC_ADDRESS_CS_0 0
  34. #define HWC_ADDRESS_CS_1 1
  35. #define HWC_ADDRESS_ADDRESS 25:0
  36. #define HWC_LOCATION 0x4
  37. #define HWC_LOCATION_TOP 27:27
  38. #define HWC_LOCATION_TOP_INSIDE 0
  39. #define HWC_LOCATION_TOP_OUTSIDE 1
  40. #define HWC_LOCATION_Y 26:16
  41. #define HWC_LOCATION_LEFT 11:11
  42. #define HWC_LOCATION_LEFT_INSIDE 0
  43. #define HWC_LOCATION_LEFT_OUTSIDE 1
  44. #define HWC_LOCATION_X 10:0
  45. #define HWC_COLOR_12 0x8
  46. #define HWC_COLOR_12_2_RGB565 31:16
  47. #define HWC_COLOR_12_1_RGB565 15:0
  48. #define HWC_COLOR_3 0xC
  49. #define HWC_COLOR_3_RGB565 15:0
  50. /* hw_cursor_xxx works for voyager,718 and 750 */
  51. void hw_cursor_enable(struct lynx_cursor *cursor)
  52. {
  53. u32 reg;
  54. reg = FIELD_VALUE(0, HWC_ADDRESS, ADDRESS, cursor->offset)|
  55. FIELD_SET(0, HWC_ADDRESS, EXT, LOCAL)|
  56. FIELD_SET(0, HWC_ADDRESS, ENABLE, ENABLE);
  57. POKE32(HWC_ADDRESS, reg);
  58. }
  59. void hw_cursor_disable(struct lynx_cursor *cursor)
  60. {
  61. POKE32(HWC_ADDRESS, 0);
  62. }
  63. void hw_cursor_setSize(struct lynx_cursor *cursor,
  64. int w, int h)
  65. {
  66. cursor->w = w;
  67. cursor->h = h;
  68. }
  69. void hw_cursor_setPos(struct lynx_cursor *cursor,
  70. int x, int y)
  71. {
  72. u32 reg;
  73. reg = FIELD_VALUE(0, HWC_LOCATION, Y, y)|
  74. FIELD_VALUE(0, HWC_LOCATION, X, x);
  75. POKE32(HWC_LOCATION, reg);
  76. }
  77. void hw_cursor_setColor(struct lynx_cursor *cursor,
  78. u32 fg, u32 bg)
  79. {
  80. POKE32(HWC_COLOR_12, (fg<<16)|(bg&0xffff));
  81. POKE32(HWC_COLOR_3, 0xffe0);
  82. }
  83. void hw_cursor_setData(struct lynx_cursor *cursor,
  84. u16 rop, const u8 *pcol, const u8 *pmsk)
  85. {
  86. int i, j, count, pitch, offset;
  87. u8 color, mask, opr;
  88. u16 data;
  89. void __iomem *pbuffer, *pstart;
  90. /* in byte*/
  91. pitch = cursor->w >> 3;
  92. /* in byte */
  93. count = pitch * cursor->h;
  94. /* in byte */
  95. offset = cursor->maxW * 2 / 8;
  96. data = 0;
  97. pstart = cursor->vstart;
  98. pbuffer = pstart;
  99. /*
  100. if(odd &1){
  101. hw_cursor_setData2(cursor,rop,pcol,pmsk);
  102. }
  103. odd++;
  104. if(odd > 0xfffffff0)
  105. odd=0;
  106. */
  107. for (i = 0; i < count; i++) {
  108. color = *pcol++;
  109. mask = *pmsk++;
  110. data = 0;
  111. for (j = 0; j < 8; j++) {
  112. if (mask & (0x80>>j)) {
  113. if (rop == ROP_XOR)
  114. opr = mask ^ color;
  115. else
  116. opr = mask & color;
  117. /* 2 stands for forecolor and 1 for backcolor */
  118. data |= ((opr & (0x80>>j))?2:1)<<(j*2);
  119. }
  120. }
  121. iowrite16(data, pbuffer);
  122. /* assume pitch is 1,2,4,8,...*/
  123. if ((i+1) % pitch == 0)
  124. {
  125. /* need a return */
  126. pstart += offset;
  127. pbuffer = pstart;
  128. } else {
  129. pbuffer += sizeof(u16);
  130. }
  131. }
  132. }
  133. void hw_cursor_setData2(struct lynx_cursor *cursor,
  134. u16 rop, const u8 *pcol, const u8 *pmsk)
  135. {
  136. int i, j, count, pitch, offset;
  137. u8 color, mask;
  138. u16 data;
  139. void __iomem *pbuffer, *pstart;
  140. /* in byte*/
  141. pitch = cursor->w >> 3;
  142. /* in byte */
  143. count = pitch * cursor->h;
  144. /* in byte */
  145. offset = cursor->maxW * 2 / 8;
  146. data = 0;
  147. pstart = cursor->vstart;
  148. pbuffer = pstart;
  149. for (i = 0; i < count; i++) {
  150. color = *pcol++;
  151. mask = *pmsk++;
  152. data = 0;
  153. for (j = 0; j < 8; j++) {
  154. if (mask & (1<<j))
  155. data |= ((color & (1<<j))?1:2)<<(j*2);
  156. }
  157. iowrite16(data, pbuffer);
  158. /* assume pitch is 1,2,4,8,...*/
  159. if (!(i&(pitch-1))) {
  160. /* need a return */
  161. pstart += offset;
  162. pbuffer = pstart;
  163. } else {
  164. pbuffer += sizeof(u16);
  165. }
  166. }
  167. }