2 $Id: btcx-risc.c,v 1.6 2005/02/21 13:57:59 kraxel Exp $
6 bt848/bt878/cx2388x risc code generator.
8 (c) 2000-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/module.h>
27 #include <linux/moduleparam.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 MODULE_DESCRIPTION("some code shared by bttv and cx88xx drivers");
38 MODULE_AUTHOR("Gerd Knorr");
39 MODULE_LICENSE("GPL");
41 static unsigned int debug
= 0;
42 module_param(debug
, int, 0644);
43 MODULE_PARM_DESC(debug
,"debug messages, default is 0 (no)");
45 /* ---------------------------------------------------------- */
46 /* allocate/free risc memory */
50 void btcx_riscmem_free(struct pci_dev
*pci
,
51 struct btcx_riscmem
*risc
)
53 if (NULL
== risc
->cpu
)
57 printk("btcx: riscmem free [%d] dma=%lx\n",
58 memcnt
, (unsigned long)risc
->dma
);
60 pci_free_consistent(pci
, risc
->size
, risc
->cpu
, risc
->dma
);
61 memset(risc
,0,sizeof(*risc
));
64 int btcx_riscmem_alloc(struct pci_dev
*pci
,
65 struct btcx_riscmem
*risc
,
71 if (NULL
!= risc
->cpu
&& risc
->size
< size
)
72 btcx_riscmem_free(pci
,risc
);
73 if (NULL
== risc
->cpu
) {
74 cpu
= pci_alloc_consistent(pci
, size
, &dma
);
82 printk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
83 memcnt
, (unsigned long)dma
, cpu
, size
);
86 memset(risc
->cpu
,0,risc
->size
);
90 /* ---------------------------------------------------------- */
91 /* screen overlay helpers */
94 btcx_screen_clips(int swidth
, int sheight
, struct v4l2_rect
*win
,
95 struct v4l2_clip
*clips
, unsigned int n
)
101 clips
[n
].c
.width
= -win
->left
;
102 clips
[n
].c
.height
= win
->height
;
105 if (win
->left
+ win
->width
> swidth
) {
107 clips
[n
].c
.left
= swidth
- win
->left
;
109 clips
[n
].c
.width
= win
->width
- clips
[n
].c
.left
;
110 clips
[n
].c
.height
= win
->height
;
117 clips
[n
].c
.width
= win
->width
;
118 clips
[n
].c
.height
= -win
->top
;
121 if (win
->top
+ win
->height
> sheight
) {
124 clips
[n
].c
.top
= sheight
- win
->top
;
125 clips
[n
].c
.width
= win
->width
;
126 clips
[n
].c
.height
= win
->height
- clips
[n
].c
.top
;
133 btcx_align(struct v4l2_rect
*win
, struct v4l2_clip
*clips
, unsigned int n
, int mask
)
139 nx
= (win
->left
+ mask
) & ~mask
;
140 nw
= (win
->width
) & ~mask
;
141 if (nx
+ nw
> win
->left
+ win
->width
)
147 printk(KERN_DEBUG
"btcx: window align %dx%d+%d+%d [dx=%d]\n",
148 win
->width
, win
->height
, win
->left
, win
->top
, dx
);
151 for (i
= 0; i
< n
; i
++) {
152 nx
= (clips
[i
].c
.left
-dx
) & ~mask
;
153 nw
= (clips
[i
].c
.width
) & ~mask
;
154 if (nx
+ nw
< clips
[i
].c
.left
-dx
+ clips
[i
].c
.width
)
156 clips
[i
].c
.left
= nx
;
157 clips
[i
].c
.width
= nw
;
159 printk(KERN_DEBUG
"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
)
169 struct v4l2_clip swap
;
174 for (i
= nclips
-2; i
>= 0; i
--) {
175 for (n
= 0, j
= 0; j
<= i
; j
++) {
176 if (clips
[j
].c
.left
> clips
[j
+1].c
.left
) {
178 clips
[j
] = clips
[j
+1];
189 btcx_calc_skips(int line
, int width
, unsigned int *maxy
,
190 struct btcx_skiplist
*skips
, unsigned int *nskips
,
191 const struct v4l2_clip
*clips
, unsigned int nclips
)
193 unsigned int clip
,skip
;
198 for (clip
= 0; clip
< nclips
; clip
++) {
201 if (clips
[clip
].c
.left
+ clips
[clip
].c
.width
<= 0)
203 if (clips
[clip
].c
.left
> (signed)width
)
207 if (line
> clips
[clip
].c
.top
+clips
[clip
].c
.height
-1)
209 if (line
< clips
[clip
].c
.top
) {
210 if (maxline
> clips
[clip
].c
.top
-1)
211 maxline
= clips
[clip
].c
.top
-1;
214 if (maxline
> clips
[clip
].c
.top
+clips
[clip
].c
.height
-1)
215 maxline
= clips
[clip
].c
.top
+clips
[clip
].c
.height
-1;
217 /* horizontal range */
218 if (0 == skip
|| clips
[clip
].c
.left
> skips
[skip
-1].end
) {
220 skips
[skip
].start
= clips
[clip
].c
.left
;
221 if (skips
[skip
].start
< 0)
222 skips
[skip
].start
= 0;
223 skips
[skip
].end
= clips
[clip
].c
.left
+ clips
[clip
].c
.width
;
224 if (skips
[skip
].end
> width
)
225 skips
[skip
].end
= width
;
228 /* overlaps -- expand last one */
229 end
= clips
[clip
].c
.left
+ clips
[clip
].c
.width
;
230 if (skips
[skip
-1].end
< end
)
231 skips
[skip
-1].end
= end
;
232 if (skips
[skip
-1].end
> width
)
233 skips
[skip
-1].end
= width
;
240 printk(KERN_DEBUG
"btcx: skips line %d-%d:",line
,maxline
);
241 for (skip
= 0; skip
< *nskips
; skip
++) {
242 printk(" %d-%d",skips
[skip
].start
,skips
[skip
].end
);
248 /* ---------------------------------------------------------- */
250 EXPORT_SYMBOL(btcx_riscmem_alloc
);
251 EXPORT_SYMBOL(btcx_riscmem_free
);
253 EXPORT_SYMBOL(btcx_screen_clips
);
254 EXPORT_SYMBOL(btcx_align
);
255 EXPORT_SYMBOL(btcx_sort_clips
);
256 EXPORT_SYMBOL(btcx_calc_skips
);