5 bt848/bt878/cx2388x risc code generator.
7 (c) 2000-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/interrupt.h>
31 #include <linux/videodev2.h>
33 #include <asm/pgtable.h>
35 #include "btcx-risc.h"
37 static unsigned int btcx_debug
;
38 module_param(btcx_debug
, int, 0644);
39 MODULE_PARM_DESC(btcx_debug
,"debug messages, default is 0 (no)");
41 #define dprintk(fmt, arg...) do { \
43 printk(KERN_DEBUG pr_fmt("%s: " fmt), \
48 /* ---------------------------------------------------------- */
49 /* allocate/free risc memory */
53 void btcx_riscmem_free(struct pci_dev
*pci
,
54 struct btcx_riscmem
*risc
)
56 if (NULL
== risc
->cpu
)
60 dprintk("btcx: riscmem free [%d] dma=%lx\n",
61 memcnt
, (unsigned long)risc
->dma
);
63 pci_free_consistent(pci
, risc
->size
, risc
->cpu
, risc
->dma
);
64 memset(risc
,0,sizeof(*risc
));
67 int btcx_riscmem_alloc(struct pci_dev
*pci
,
68 struct btcx_riscmem
*risc
,
74 if (NULL
!= risc
->cpu
&& risc
->size
< size
)
75 btcx_riscmem_free(pci
,risc
);
76 if (NULL
== risc
->cpu
) {
77 cpu
= pci_alloc_consistent(pci
, size
, &dma
);
85 dprintk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
86 memcnt
, (unsigned long)dma
, cpu
, size
);
88 memset(risc
->cpu
,0,risc
->size
);
92 /* ---------------------------------------------------------- */
93 /* screen overlay helpers */
96 btcx_screen_clips(int swidth
, int sheight
, struct v4l2_rect
*win
,
97 struct v4l2_clip
*clips
, unsigned int n
)
103 clips
[n
].c
.width
= -win
->left
;
104 clips
[n
].c
.height
= win
->height
;
107 if (win
->left
+ win
->width
> swidth
) {
109 clips
[n
].c
.left
= swidth
- win
->left
;
111 clips
[n
].c
.width
= win
->width
- clips
[n
].c
.left
;
112 clips
[n
].c
.height
= win
->height
;
119 clips
[n
].c
.width
= win
->width
;
120 clips
[n
].c
.height
= -win
->top
;
123 if (win
->top
+ win
->height
> sheight
) {
126 clips
[n
].c
.top
= sheight
- win
->top
;
127 clips
[n
].c
.width
= win
->width
;
128 clips
[n
].c
.height
= win
->height
- clips
[n
].c
.top
;
135 btcx_align(struct v4l2_rect
*win
, struct v4l2_clip
*clips
, unsigned int n
, int mask
)
141 nx
= (win
->left
+ mask
) & ~mask
;
142 nw
= (win
->width
) & ~mask
;
143 if (nx
+ nw
> win
->left
+ win
->width
)
148 dprintk("btcx: window align %dx%d+%d+%d [dx=%d]\n",
149 win
->width
, win
->height
, win
->left
, win
->top
, dx
);
152 for (i
= 0; i
< n
; i
++) {
153 nx
= (clips
[i
].c
.left
-dx
) & ~mask
;
154 nw
= (clips
[i
].c
.width
) & ~mask
;
155 if (nx
+ nw
< clips
[i
].c
.left
-dx
+ clips
[i
].c
.width
)
157 clips
[i
].c
.left
= nx
;
158 clips
[i
].c
.width
= nw
;
159 dprintk("btcx: clip align %dx%d+%d+%d\n",
160 clips
[i
].c
.width
, clips
[i
].c
.height
,
161 clips
[i
].c
.left
, clips
[i
].c
.top
);
167 btcx_sort_clips(struct v4l2_clip
*clips
, unsigned int nclips
)
173 for (i
= nclips
-2; i
>= 0; i
--) {
174 for (n
= 0, j
= 0; j
<= i
; j
++) {
175 if (clips
[j
].c
.left
> clips
[j
+1].c
.left
) {
176 swap(clips
[j
], clips
[j
+ 1]);
186 btcx_calc_skips(int line
, int width
, int *maxy
,
187 struct btcx_skiplist
*skips
, unsigned int *nskips
,
188 const struct v4l2_clip
*clips
, unsigned int nclips
)
190 unsigned int clip
,skip
;
195 for (clip
= 0; clip
< nclips
; clip
++) {
198 if (clips
[clip
].c
.left
+ clips
[clip
].c
.width
<= 0)
200 if (clips
[clip
].c
.left
> (signed)width
)
204 if (line
> clips
[clip
].c
.top
+clips
[clip
].c
.height
-1)
206 if (line
< clips
[clip
].c
.top
) {
207 if (maxline
> clips
[clip
].c
.top
-1)
208 maxline
= clips
[clip
].c
.top
-1;
211 if (maxline
> clips
[clip
].c
.top
+clips
[clip
].c
.height
-1)
212 maxline
= clips
[clip
].c
.top
+clips
[clip
].c
.height
-1;
214 /* horizontal range */
215 if (0 == skip
|| clips
[clip
].c
.left
> skips
[skip
-1].end
) {
217 skips
[skip
].start
= clips
[clip
].c
.left
;
218 if (skips
[skip
].start
< 0)
219 skips
[skip
].start
= 0;
220 skips
[skip
].end
= clips
[clip
].c
.left
+ clips
[clip
].c
.width
;
221 if (skips
[skip
].end
> width
)
222 skips
[skip
].end
= width
;
225 /* overlaps -- expand last one */
226 end
= clips
[clip
].c
.left
+ clips
[clip
].c
.width
;
227 if (skips
[skip
-1].end
< end
)
228 skips
[skip
-1].end
= end
;
229 if (skips
[skip
-1].end
> width
)
230 skips
[skip
-1].end
= width
;
237 dprintk("btcx: skips line %d-%d:", line
, maxline
);
238 for (skip
= 0; skip
< *nskips
; skip
++) {
239 pr_cont(" %d-%d", skips
[skip
].start
, skips
[skip
].end
);