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 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/pci.h>
29 #include <linux/interrupt.h>
30 #include <linux/videodev2.h>
32 #include <asm/pgtable.h>
34 #include "btcx-risc.h"
36 MODULE_DESCRIPTION("some code shared by bttv and cx88xx drivers");
37 MODULE_AUTHOR("Gerd Knorr");
38 MODULE_LICENSE("GPL");
40 static unsigned int debug;
41 module_param(debug, int, 0644);
42 MODULE_PARM_DESC(debug,"debug messages, default is 0 (no)");
44 /* ---------------------------------------------------------- */
45 /* allocate/free risc memory */
49 void btcx_riscmem_free(struct pci_dev *pci,
50 struct btcx_riscmem *risc)
52 if (NULL == risc->cpu)
56 printk("btcx: riscmem free [%d] dma=%lx\n",
57 memcnt, (unsigned long)risc->dma);
59 pci_free_consistent(pci, risc->size, risc->cpu, risc->dma);
60 memset(risc,0,sizeof(*risc));
63 int btcx_riscmem_alloc(struct pci_dev *pci,
64 struct btcx_riscmem *risc,
70 if (NULL != risc->cpu && risc->size < size)
71 btcx_riscmem_free(pci,risc);
72 if (NULL == risc->cpu) {
73 cpu = pci_alloc_consistent(pci, size, &dma);
81 printk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
82 memcnt, (unsigned long)dma, cpu, size);
85 memset(risc->cpu,0,risc->size);
89 /* ---------------------------------------------------------- */
90 /* screen overlay helpers */
93 btcx_screen_clips(int swidth, int sheight, struct v4l2_rect *win,
94 struct v4l2_clip *clips, unsigned int n)
100 clips[n].c.width = -win->left;
101 clips[n].c.height = win->height;
104 if (win->left + win->width > swidth) {
106 clips[n].c.left = swidth - win->left;
108 clips[n].c.width = win->width - clips[n].c.left;
109 clips[n].c.height = win->height;
116 clips[n].c.width = win->width;
117 clips[n].c.height = -win->top;
120 if (win->top + win->height > sheight) {
123 clips[n].c.top = sheight - win->top;
124 clips[n].c.width = win->width;
125 clips[n].c.height = win->height - clips[n].c.top;
132 btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips, unsigned int n, int mask)
138 nx = (win->left + mask) & ~mask;
139 nw = (win->width) & ~mask;
140 if (nx + nw > win->left + win->width)
146 printk(KERN_DEBUG "btcx: window align %dx%d+%d+%d [dx=%d]\n",
147 win->width, win->height, win->left, win->top, dx);
150 for (i = 0; i < n; i++) {
151 nx = (clips[i].c.left-dx) & ~mask;
152 nw = (clips[i].c.width) & ~mask;
153 if (nx + nw < clips[i].c.left-dx + clips[i].c.width)
155 clips[i].c.left = nx;
156 clips[i].c.width = nw;
158 printk(KERN_DEBUG "btcx: clip align %dx%d+%d+%d\n",
159 clips[i].c.width, clips[i].c.height,
160 clips[i].c.left, clips[i].c.top);
166 btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips)
168 struct v4l2_clip swap;
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) {
177 clips[j] = clips[j+1];
188 btcx_calc_skips(int line, int width, unsigned int *maxy,
189 struct btcx_skiplist *skips, unsigned int *nskips,
190 const struct v4l2_clip *clips, unsigned int nclips)
192 unsigned int clip,skip;
197 for (clip = 0; clip < nclips; clip++) {
200 if (clips[clip].c.left + clips[clip].c.width <= 0)
202 if (clips[clip].c.left > (signed)width)
206 if (line > clips[clip].c.top+clips[clip].c.height-1)
208 if (line < clips[clip].c.top) {
209 if (maxline > clips[clip].c.top-1)
210 maxline = clips[clip].c.top-1;
213 if (maxline > clips[clip].c.top+clips[clip].c.height-1)
214 maxline = clips[clip].c.top+clips[clip].c.height-1;
216 /* horizontal range */
217 if (0 == skip || clips[clip].c.left > skips[skip-1].end) {
219 skips[skip].start = clips[clip].c.left;
220 if (skips[skip].start < 0)
221 skips[skip].start = 0;
222 skips[skip].end = clips[clip].c.left + clips[clip].c.width;
223 if (skips[skip].end > width)
224 skips[skip].end = width;
227 /* overlaps -- expand last one */
228 end = clips[clip].c.left + clips[clip].c.width;
229 if (skips[skip-1].end < end)
230 skips[skip-1].end = end;
231 if (skips[skip-1].end > width)
232 skips[skip-1].end = width;
239 printk(KERN_DEBUG "btcx: skips line %d-%d:",line,maxline);
240 for (skip = 0; skip < *nskips; skip++) {
241 printk(" %d-%d",skips[skip].start,skips[skip].end);
247 /* ---------------------------------------------------------- */
249 EXPORT_SYMBOL(btcx_riscmem_alloc);
250 EXPORT_SYMBOL(btcx_riscmem_free);
252 EXPORT_SYMBOL(btcx_screen_clips);
253 EXPORT_SYMBOL(btcx_align);
254 EXPORT_SYMBOL(btcx_sort_clips);
255 EXPORT_SYMBOL(btcx_calc_skips);