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 18 #include "sm750.h" 19 #include "sm750_help.h" 20 #include "sm750_cursor.h" 21 22 23 #define PEEK32(addr) \ 24 readl(cursor->mmio + (addr)) 25 26 #define POKE32(addr, data) \ 27 writel((data), cursor->mmio + (addr)) 28 29 /* cursor control for voyager and 718/750*/ 30 #define HWC_ADDRESS 0x0 31 #define HWC_ADDRESS_ENABLE BIT(31) 32 #define HWC_ADDRESS_EXT BIT(27) 33 #define HWC_ADDRESS_CS BIT(26) 34 #define HWC_ADDRESS_ADDRESS_MASK 0x3ffffff 35 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 46 #define HWC_COLOR_12 0x8 47 #define HWC_COLOR_12_2_RGB565 31:16 48 #define HWC_COLOR_12_1_RGB565 15:0 49 50 #define HWC_COLOR_3 0xC 51 #define HWC_COLOR_3_RGB565 15:0 52 53 54 /* hw_cursor_xxx works for voyager,718 and 750 */ 55 void hw_cursor_enable(struct lynx_cursor *cursor) 56 { 57 u32 reg; 58 59 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE; 60 POKE32(HWC_ADDRESS, reg); 61 } 62 void hw_cursor_disable(struct lynx_cursor *cursor) 63 { 64 POKE32(HWC_ADDRESS, 0); 65 } 66 67 void hw_cursor_setSize(struct lynx_cursor *cursor, 68 int w, int h) 69 { 70 cursor->w = w; 71 cursor->h = h; 72 } 73 void hw_cursor_setPos(struct lynx_cursor *cursor, 74 int x, int y) 75 { 76 u32 reg; 77 78 reg = FIELD_VALUE(0, HWC_LOCATION, Y, y)| 79 FIELD_VALUE(0, HWC_LOCATION, X, x); 80 POKE32(HWC_LOCATION, reg); 81 } 82 void hw_cursor_setColor(struct lynx_cursor *cursor, 83 u32 fg, u32 bg) 84 { 85 POKE32(HWC_COLOR_12, (fg<<16)|(bg&0xffff)); 86 POKE32(HWC_COLOR_3, 0xffe0); 87 } 88 89 void hw_cursor_setData(struct lynx_cursor *cursor, 90 u16 rop, const u8 *pcol, const u8 *pmsk) 91 { 92 int i, j, count, pitch, offset; 93 u8 color, mask, opr; 94 u16 data; 95 void __iomem *pbuffer, *pstart; 96 97 /* in byte*/ 98 pitch = cursor->w >> 3; 99 100 /* in byte */ 101 count = pitch * cursor->h; 102 103 /* in byte */ 104 offset = cursor->maxW * 2 / 8; 105 106 data = 0; 107 pstart = cursor->vstart; 108 pbuffer = pstart; 109 110 for (i = 0; i < count; i++) { 111 color = *pcol++; 112 mask = *pmsk++; 113 data = 0; 114 115 for (j = 0; j < 8; j++) { 116 if (mask & (0x80>>j)) { 117 if (rop == ROP_XOR) 118 opr = mask ^ color; 119 else 120 opr = mask & color; 121 122 /* 2 stands for forecolor and 1 for backcolor */ 123 data |= ((opr & (0x80>>j))?2:1)<<(j*2); 124 } 125 } 126 iowrite16(data, pbuffer); 127 128 /* assume pitch is 1,2,4,8,...*/ 129 if ((i + 1) % pitch == 0) { 130 /* need a return */ 131 pstart += offset; 132 pbuffer = pstart; 133 } else { 134 pbuffer += sizeof(u16); 135 } 136 137 } 138 139 140 } 141 142 143 void hw_cursor_setData2(struct lynx_cursor *cursor, 144 u16 rop, const u8 *pcol, const u8 *pmsk) 145 { 146 int i, j, count, pitch, offset; 147 u8 color, mask; 148 u16 data; 149 void __iomem *pbuffer, *pstart; 150 151 /* in byte*/ 152 pitch = cursor->w >> 3; 153 154 /* in byte */ 155 count = pitch * cursor->h; 156 157 /* in byte */ 158 offset = cursor->maxW * 2 / 8; 159 160 data = 0; 161 pstart = cursor->vstart; 162 pbuffer = pstart; 163 164 for (i = 0; i < count; i++) { 165 color = *pcol++; 166 mask = *pmsk++; 167 data = 0; 168 169 for (j = 0; j < 8; j++) { 170 if (mask & (1<<j)) 171 data |= ((color & (1<<j))?1:2)<<(j*2); 172 } 173 iowrite16(data, pbuffer); 174 175 /* assume pitch is 1,2,4,8,...*/ 176 if (!(i&(pitch-1))) { 177 /* need a return */ 178 pstart += offset; 179 pbuffer = pstart; 180 } else { 181 pbuffer += sizeof(u16); 182 } 183 184 } 185 } 186