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"
22 #define poke32(addr, data) \
23 writel((data), cursor->mmio + (addr))
25 /* cursor control for voyager and 718/750*/
26 #define HWC_ADDRESS 0x0
27 #define HWC_ADDRESS_ENABLE BIT(31)
28 #define HWC_ADDRESS_EXT BIT(27)
29 #define HWC_ADDRESS_CS BIT(26)
30 #define HWC_ADDRESS_ADDRESS_MASK 0x3ffffff
32 #define HWC_LOCATION 0x4
33 #define HWC_LOCATION_TOP BIT(27)
34 #define HWC_LOCATION_Y_SHIFT 16
35 #define HWC_LOCATION_Y_MASK (0x7ff << 16)
36 #define HWC_LOCATION_LEFT BIT(11)
37 #define HWC_LOCATION_X_MASK 0x7ff
39 #define HWC_COLOR_12 0x8
40 #define HWC_COLOR_12_2_RGB565_SHIFT 16
41 #define HWC_COLOR_12_2_RGB565_MASK (0xffff << 16)
42 #define HWC_COLOR_12_1_RGB565_MASK 0xffff
44 #define HWC_COLOR_3 0xC
45 #define HWC_COLOR_3_RGB565_MASK 0xffff
47 /* hw_cursor_xxx works for voyager,718 and 750 */
48 void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
52 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
53 poke32(HWC_ADDRESS, reg);
56 void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
58 poke32(HWC_ADDRESS, 0);
61 void sm750_hw_cursor_setSize(struct lynx_cursor *cursor, int w, int h)
67 void sm750_hw_cursor_setPos(struct lynx_cursor *cursor, int x, int y)
71 reg = ((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
72 (x & HWC_LOCATION_X_MASK);
73 poke32(HWC_LOCATION, reg);
76 void sm750_hw_cursor_setColor(struct lynx_cursor *cursor, u32 fg, u32 bg)
78 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
79 HWC_COLOR_12_2_RGB565_MASK;
81 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
82 poke32(HWC_COLOR_3, 0xffe0);
85 void sm750_hw_cursor_setData(struct lynx_cursor *cursor, u16 rop,
86 const u8 *pcol, const u8 *pmsk)
88 int i, j, count, pitch, offset;
91 void __iomem *pbuffer, *pstart;
94 pitch = cursor->w >> 3;
97 count = pitch * cursor->h;
100 offset = cursor->maxW * 2 / 8;
103 pstart = cursor->vstart;
106 for (i = 0; i < count; i++) {
111 for (j = 0; j < 8; j++) {
112 if (mask & (0x80 >> j)) {
118 /* 2 stands for forecolor and 1 for backcolor */
119 data |= ((opr & (0x80 >> j)) ? 2 : 1) << (j * 2);
122 iowrite16(data, pbuffer);
124 /* assume pitch is 1,2,4,8,...*/
125 if ((i + 1) % pitch == 0) {
130 pbuffer += sizeof(u16);
135 void sm750_hw_cursor_setData2(struct lynx_cursor *cursor, u16 rop,
136 const u8 *pcol, const u8 *pmsk)
138 int i, j, count, pitch, offset;
141 void __iomem *pbuffer, *pstart;
144 pitch = cursor->w >> 3;
147 count = pitch * cursor->h;
150 offset = cursor->maxW * 2 / 8;
153 pstart = cursor->vstart;
156 for (i = 0; i < count; i++) {
161 for (j = 0; j < 8; j++) {
163 data |= ((color & (1 << j)) ? 1 : 2) << (j * 2);
165 iowrite16(data, pbuffer);
167 /* assume pitch is 1,2,4,8,...*/
168 if (!(i & (pitch - 1))) {
173 pbuffer += sizeof(u16);