1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/module.h>
3 #include <linux/kernel.h>
4 #include <linux/errno.h>
5 #include <linux/string.h>
7 #include <linux/slab.h>
8 #include <linux/delay.h>
10 #include <linux/ioport.h>
11 #include <linux/init.h>
12 #include <linux/pci.h>
13 #include <linux/vmalloc.h>
14 #include <linux/pagemap.h>
15 #include <linux/console.h>
16 #include <linux/platform_device.h>
17 #include <linux/screen_info.h>
20 #include "sm750_cursor.h"
24 #define poke32(addr, data) \
25 writel((data), cursor->mmio + (addr))
27 /* cursor control for voyager and 718/750*/
28 #define HWC_ADDRESS 0x0
29 #define HWC_ADDRESS_ENABLE BIT(31)
30 #define HWC_ADDRESS_EXT BIT(27)
31 #define HWC_ADDRESS_CS BIT(26)
32 #define HWC_ADDRESS_ADDRESS_MASK 0x3ffffff
34 #define HWC_LOCATION 0x4
35 #define HWC_LOCATION_TOP BIT(27)
36 #define HWC_LOCATION_Y_SHIFT 16
37 #define HWC_LOCATION_Y_MASK (0x7ff << 16)
38 #define HWC_LOCATION_LEFT BIT(11)
39 #define HWC_LOCATION_X_MASK 0x7ff
41 #define HWC_COLOR_12 0x8
42 #define HWC_COLOR_12_2_RGB565_SHIFT 16
43 #define HWC_COLOR_12_2_RGB565_MASK (0xffff << 16)
44 #define HWC_COLOR_12_1_RGB565_MASK 0xffff
46 #define HWC_COLOR_3 0xC
47 #define HWC_COLOR_3_RGB565_MASK 0xffff
50 /* hw_cursor_xxx works for voyager,718 and 750 */
51 void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
55 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
56 poke32(HWC_ADDRESS, reg);
59 void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
61 poke32(HWC_ADDRESS, 0);
64 void sm750_hw_cursor_setSize(struct lynx_cursor *cursor, int w, int h)
70 void sm750_hw_cursor_setPos(struct lynx_cursor *cursor, int x, int y)
74 reg = ((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
75 (x & HWC_LOCATION_X_MASK);
76 poke32(HWC_LOCATION, reg);
79 void sm750_hw_cursor_setColor(struct lynx_cursor *cursor, u32 fg, u32 bg)
81 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
82 HWC_COLOR_12_2_RGB565_MASK;
84 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
85 poke32(HWC_COLOR_3, 0xffe0);
88 void sm750_hw_cursor_setData(struct lynx_cursor *cursor, u16 rop,
89 const u8 *pcol, const u8 *pmsk)
91 int i, j, count, pitch, offset;
94 void __iomem *pbuffer, *pstart;
97 pitch = cursor->w >> 3;
100 count = pitch * cursor->h;
103 offset = cursor->maxW * 2 / 8;
106 pstart = cursor->vstart;
109 for (i = 0; i < count; i++) {
114 for (j = 0; j < 8; j++) {
115 if (mask & (0x80 >> j)) {
121 /* 2 stands for forecolor and 1 for backcolor */
122 data |= ((opr & (0x80 >> j)) ? 2 : 1) << (j * 2);
125 iowrite16(data, pbuffer);
127 /* assume pitch is 1,2,4,8,...*/
128 if ((i + 1) % pitch == 0) {
133 pbuffer += sizeof(u16);
139 void sm750_hw_cursor_setData2(struct lynx_cursor *cursor, u16 rop,
140 const u8 *pcol, const u8 *pmsk)
142 int i, j, count, pitch, offset;
145 void __iomem *pbuffer, *pstart;
148 pitch = cursor->w >> 3;
151 count = pitch * cursor->h;
154 offset = cursor->maxW * 2 / 8;
157 pstart = cursor->vstart;
160 for (i = 0; i < count; i++) {
165 for (j = 0; j < 8; j++) {
167 data |= ((color & (1 << j)) ? 1 : 2) << (j * 2);
169 iowrite16(data, pbuffer);
171 /* assume pitch is 1,2,4,8,...*/
172 if (!(i & (pitch - 1))) {
177 pbuffer += sizeof(u16);