]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/staging/sm750fb/sm750_cursor.c
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[mirror_ubuntu-artful-kernel.git] / drivers / staging / sm750fb / sm750_cursor.c
CommitLineData
67088d49
MR
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>
81dee67e 14#include <linux/console.h>
67088d49
MR
15#include <linux/platform_device.h>
16#include <linux/screen_info.h>
81dee67e
SM
17
18#include "sm750.h"
81dee67e
SM
19#include "sm750_cursor.h"
20
21
81dee67e 22
c075b6f2 23#define poke32(addr, data) \
c97b2c15 24writel((data), cursor->mmio + (addr))
81dee67e
SM
25
26/* cursor control for voyager and 718/750*/
27#define HWC_ADDRESS 0x0
672f75b0
MR
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
81dee67e
SM
32
33#define HWC_LOCATION 0x4
fe3bd267
MR
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
81dee67e
SM
39
40#define HWC_COLOR_12 0x8
6aa178ee
MR
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
81dee67e
SM
44
45#define HWC_COLOR_3 0xC
6aa178ee 46#define HWC_COLOR_3_RGB565_MASK 0xffff
81dee67e
SM
47
48
49/* hw_cursor_xxx works for voyager,718 and 750 */
52d0744d 50void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
81dee67e
SM
51{
52 u32 reg;
40403c1b 53
672f75b0 54 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
c075b6f2 55 poke32(HWC_ADDRESS, reg);
81dee67e 56}
52d0744d 57void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
81dee67e 58{
c075b6f2 59 poke32(HWC_ADDRESS, 0);
81dee67e
SM
60}
61
52d0744d 62void sm750_hw_cursor_setSize(struct lynx_cursor *cursor,
c97b2c15 63 int w, int h)
81dee67e
SM
64{
65 cursor->w = w;
66 cursor->h = h;
67}
52d0744d 68void sm750_hw_cursor_setPos(struct lynx_cursor *cursor,
c97b2c15 69 int x, int y)
81dee67e
SM
70{
71 u32 reg;
40403c1b 72
fe3bd267
MR
73 reg = (((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
74 (x & HWC_LOCATION_X_MASK));
c075b6f2 75 poke32(HWC_LOCATION, reg);
81dee67e 76}
52d0744d 77void sm750_hw_cursor_setColor(struct lynx_cursor *cursor,
c97b2c15 78 u32 fg, u32 bg)
81dee67e 79{
6aa178ee
MR
80 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
81 HWC_COLOR_12_2_RGB565_MASK;
82
c075b6f2
MS
83 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
84 poke32(HWC_COLOR_3, 0xffe0);
81dee67e
SM
85}
86
52d0744d 87void sm750_hw_cursor_setData(struct lynx_cursor *cursor,
cc6c16df 88 u16 rop, const u8 *pcol, const u8 *pmsk)
81dee67e 89{
c97b2c15
IA
90 int i, j, count, pitch, offset;
91 u8 color, mask, opr;
81dee67e 92 u16 data;
35fb80b9 93 void __iomem *pbuffer, *pstart;
81dee67e
SM
94
95 /* in byte*/
96 pitch = cursor->w >> 3;
97
98 /* in byte */
99 count = pitch * cursor->h;
100
35fb80b9
LS
101 /* in byte */
102 offset = cursor->maxW * 2 / 8;
81dee67e
SM
103
104 data = 0;
35fb80b9 105 pstart = cursor->vstart;
81dee67e
SM
106 pbuffer = pstart;
107
259fef35 108 for (i = 0; i < count; i++) {
81dee67e
SM
109 color = *pcol++;
110 mask = *pmsk++;
111 data = 0;
112
adbb90e8 113 for (j = 0; j < 8; j++) {
8c11f5a2 114 if (mask & (0x80>>j)) {
9ccc5f44 115 if (rop == ROP_XOR)
81dee67e
SM
116 opr = mask ^ color;
117 else
118 opr = mask & color;
119
120 /* 2 stands for forecolor and 1 for backcolor */
121 data |= ((opr & (0x80>>j))?2:1)<<(j*2);
122 }
123 }
35fb80b9 124 iowrite16(data, pbuffer);
81dee67e
SM
125
126 /* assume pitch is 1,2,4,8,...*/
04c73f28 127 if ((i + 1) % pitch == 0) {
81dee67e
SM
128 /* need a return */
129 pstart += offset;
130 pbuffer = pstart;
6338a781 131 } else {
35fb80b9 132 pbuffer += sizeof(u16);
81dee67e
SM
133 }
134
135 }
136
137
138}
139
140
52d0744d 141void sm750_hw_cursor_setData2(struct lynx_cursor *cursor,
cc6c16df 142 u16 rop, const u8 *pcol, const u8 *pmsk)
81dee67e 143{
c97b2c15 144 int i, j, count, pitch, offset;
041d3a42 145 u8 color, mask;
81dee67e 146 u16 data;
35fb80b9 147 void __iomem *pbuffer, *pstart;
81dee67e
SM
148
149 /* in byte*/
150 pitch = cursor->w >> 3;
151
152 /* in byte */
153 count = pitch * cursor->h;
154
35fb80b9
LS
155 /* in byte */
156 offset = cursor->maxW * 2 / 8;
81dee67e
SM
157
158 data = 0;
35fb80b9 159 pstart = cursor->vstart;
81dee67e
SM
160 pbuffer = pstart;
161
259fef35 162 for (i = 0; i < count; i++) {
81dee67e
SM
163 color = *pcol++;
164 mask = *pmsk++;
165 data = 0;
166
adbb90e8 167 for (j = 0; j < 8; j++) {
9ccc5f44 168 if (mask & (1<<j))
81dee67e
SM
169 data |= ((color & (1<<j))?1:2)<<(j*2);
170 }
35fb80b9 171 iowrite16(data, pbuffer);
81dee67e
SM
172
173 /* assume pitch is 1,2,4,8,...*/
259fef35 174 if (!(i&(pitch-1))) {
81dee67e
SM
175 /* need a return */
176 pstart += offset;
177 pbuffer = pstart;
6338a781 178 } else {
35fb80b9 179 pbuffer += sizeof(u16);
81dee67e
SM
180 }
181
182 }
81dee67e 183}