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>
19 #include "sm750_cursor.h"
21 #define poke32(addr, data) \
22 writel((data), cursor->mmio + (addr))
24 /* cursor control for voyager and 718/750*/
25 #define HWC_ADDRESS 0x0
26 #define HWC_ADDRESS_ENABLE BIT(31)
27 #define HWC_ADDRESS_EXT BIT(27)
28 #define HWC_ADDRESS_CS BIT(26)
29 #define HWC_ADDRESS_ADDRESS_MASK 0x3ffffff
31 #define HWC_LOCATION 0x4
32 #define HWC_LOCATION_TOP BIT(27)
33 #define HWC_LOCATION_Y_SHIFT 16
34 #define HWC_LOCATION_Y_MASK (0x7ff << 16)
35 #define HWC_LOCATION_LEFT BIT(11)
36 #define HWC_LOCATION_X_MASK 0x7ff
38 #define HWC_COLOR_12 0x8
39 #define HWC_COLOR_12_2_RGB565_SHIFT 16
40 #define HWC_COLOR_12_2_RGB565_MASK (0xffff << 16)
41 #define HWC_COLOR_12_1_RGB565_MASK 0xffff
43 #define HWC_COLOR_3 0xC
44 #define HWC_COLOR_3_RGB565_MASK 0xffff
46 /* hw_cursor_xxx works for voyager,718 and 750 */
47 void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
51 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
52 poke32(HWC_ADDRESS, reg);
55 void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
57 poke32(HWC_ADDRESS, 0);
60 void sm750_hw_cursor_setSize(struct lynx_cursor *cursor, int w, int h)
66 void sm750_hw_cursor_setPos(struct lynx_cursor *cursor, int x, int y)
70 reg = ((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
71 (x & HWC_LOCATION_X_MASK);
72 poke32(HWC_LOCATION, reg);
75 void sm750_hw_cursor_setColor(struct lynx_cursor *cursor, u32 fg, u32 bg)
77 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
78 HWC_COLOR_12_2_RGB565_MASK;
80 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
81 poke32(HWC_COLOR_3, 0xffe0);
84 void sm750_hw_cursor_setData(struct lynx_cursor *cursor, u16 rop,
85 const u8 *pcol, const u8 *pmsk)
87 int i, j, count, pitch, offset;
90 void __iomem *pbuffer, *pstart;
93 pitch = cursor->w >> 3;
96 count = pitch * cursor->h;
99 offset = cursor->max_w * 2 / 8;
102 pstart = cursor->vstart;
105 for (i = 0; i < count; i++) {
110 for (j = 0; j < 8; j++) {
111 if (mask & (0x80 >> j)) {
117 /* 2 stands for forecolor and 1 for backcolor */
118 data |= ((opr & (0x80 >> j)) ? 2 : 1) << (j * 2);
121 iowrite16(data, pbuffer);
123 /* assume pitch is 1,2,4,8,...*/
124 if ((i + 1) % pitch == 0) {
129 pbuffer += sizeof(u16);
134 void sm750_hw_cursor_setData2(struct lynx_cursor *cursor, u16 rop,
135 const u8 *pcol, const u8 *pmsk)
137 int i, j, count, pitch, offset;
140 void __iomem *pbuffer, *pstart;
143 pitch = cursor->w >> 3;
146 count = pitch * cursor->h;
149 offset = cursor->max_w * 2 / 8;
152 pstart = cursor->vstart;
155 for (i = 0; i < count; i++) {
160 for (j = 0; j < 8; j++) {
162 data |= ((color & (1 << j)) ? 1 : 2) << (j * 2);
164 iowrite16(data, pbuffer);
166 /* assume pitch is 1,2,4,8,...*/
167 if (!(i & (pitch - 1))) {
172 pbuffer += sizeof(u16);