1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/string.h>
6 #include <linux/slab.h>
7 #include <linux/delay.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>
19 #include "sm750_cursor.h"
23 #define poke32(addr, data) \
24 writel((data), cursor->mmio + (addr))
26 /* cursor control for voyager and 718/750*/
27 #define HWC_ADDRESS 0x0
28 #define HWC_ADDRESS_ENABLE BIT(31)
29 #define HWC_ADDRESS_EXT BIT(27)
30 #define HWC_ADDRESS_CS BIT(26)
31 #define HWC_ADDRESS_ADDRESS_MASK 0x3ffffff
33 #define HWC_LOCATION 0x4
34 #define HWC_LOCATION_TOP BIT(27)
35 #define HWC_LOCATION_Y_SHIFT 16
36 #define HWC_LOCATION_Y_MASK (0x7ff << 16)
37 #define HWC_LOCATION_LEFT BIT(11)
38 #define HWC_LOCATION_X_MASK 0x7ff
40 #define HWC_COLOR_12 0x8
41 #define HWC_COLOR_12_2_RGB565_SHIFT 16
42 #define HWC_COLOR_12_2_RGB565_MASK (0xffff << 16)
43 #define HWC_COLOR_12_1_RGB565_MASK 0xffff
45 #define HWC_COLOR_3 0xC
46 #define HWC_COLOR_3_RGB565_MASK 0xffff
49 /* hw_cursor_xxx works for voyager,718 and 750 */
50 void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
54 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
55 poke32(HWC_ADDRESS, reg);
58 void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
60 poke32(HWC_ADDRESS, 0);
63 void sm750_hw_cursor_setSize(struct lynx_cursor *cursor, int w, int h)
69 void sm750_hw_cursor_setPos(struct lynx_cursor *cursor, int x, int y)
73 reg = ((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
74 (x & HWC_LOCATION_X_MASK);
75 poke32(HWC_LOCATION, reg);
78 void sm750_hw_cursor_setColor(struct lynx_cursor *cursor, u32 fg, u32 bg)
80 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
81 HWC_COLOR_12_2_RGB565_MASK;
83 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
84 poke32(HWC_COLOR_3, 0xffe0);
87 void sm750_hw_cursor_setData(struct lynx_cursor *cursor, u16 rop,
88 const u8 *pcol, const u8 *pmsk)
90 int i, j, count, pitch, offset;
93 void __iomem *pbuffer, *pstart;
96 pitch = cursor->w >> 3;
99 count = pitch * cursor->h;
102 offset = cursor->maxW * 2 / 8;
105 pstart = cursor->vstart;
108 for (i = 0; i < count; i++) {
113 for (j = 0; j < 8; j++) {
114 if (mask & (0x80 >> j)) {
120 /* 2 stands for forecolor and 1 for backcolor */
121 data |= ((opr & (0x80 >> j)) ? 2 : 1) << (j * 2);
124 iowrite16(data, pbuffer);
126 /* assume pitch is 1,2,4,8,...*/
127 if ((i + 1) % pitch == 0) {
132 pbuffer += sizeof(u16);
138 void sm750_hw_cursor_setData2(struct lynx_cursor *cursor, u16 rop,
139 const u8 *pcol, const u8 *pmsk)
141 int i, j, count, pitch, offset;
144 void __iomem *pbuffer, *pstart;
147 pitch = cursor->w >> 3;
150 count = pitch * cursor->h;
153 offset = cursor->maxW * 2 / 8;
156 pstart = cursor->vstart;
159 for (i = 0; i < count; i++) {
164 for (j = 0; j < 8; j++) {
166 data |= ((color & (1 << j)) ? 1 : 2) << (j * 2);
168 iowrite16(data, pbuffer);
170 /* assume pitch is 1,2,4,8,...*/
171 if (!(i & (pitch - 1))) {
176 pbuffer += sizeof(u16);