4 bt848/bt878/cx2388x risc code generator.
6 (c) 2000-03 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28 #include <linux/videodev2.h>
30 #include <asm/pgtable.h>
32 #include "btcx-risc.h"
34 MODULE_DESCRIPTION("some code shared by bttv and cx88xx drivers");
35 MODULE_AUTHOR("Gerd Knorr");
36 MODULE_LICENSE("GPL");
38 static unsigned int debug = 0;
39 MODULE_PARM(debug,"i");
40 MODULE_PARM_DESC(debug,"debug messages, default is 0 (no)");
42 /* ---------------------------------------------------------- */
43 /* allocate/free risc memory */
47 void btcx_riscmem_free(struct pci_dev *pci,
48 struct btcx_riscmem *risc)
50 if (NULL == risc->cpu)
52 pci_free_consistent(pci, risc->size, risc->cpu, risc->dma);
53 memset(risc,0,sizeof(*risc));
56 printk("btcx: riscmem free [%d]\n",memcnt);
60 int btcx_riscmem_alloc(struct pci_dev *pci,
61 struct btcx_riscmem *risc,
67 if (NULL != risc->cpu && risc->size < size)
68 btcx_riscmem_free(pci,risc);
69 if (NULL == risc->cpu) {
70 cpu = pci_alloc_consistent(pci, size, &dma);
78 printk("btcx: riscmem alloc size=%d [%d]\n",size,memcnt);
81 memset(risc->cpu,0,risc->size);
85 /* ---------------------------------------------------------- */
86 /* screen overlay helpers */
89 btcx_screen_clips(int swidth, int sheight, struct v4l2_rect *win,
90 struct v4l2_clip *clips, unsigned int n)
96 clips[n].c.width = -win->left;
97 clips[n].c.height = win->height;
100 if (win->left + win->width > swidth) {
102 clips[n].c.left = swidth - win->left;
104 clips[n].c.width = win->width - clips[n].c.left;
105 clips[n].c.height = win->height;
112 clips[n].c.width = win->width;
113 clips[n].c.height = -win->top;
116 if (win->top + win->height > sheight) {
119 clips[n].c.top = sheight - win->top;
120 clips[n].c.width = win->width;
121 clips[n].c.height = win->height - clips[n].c.top;
128 btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips, unsigned int n, int mask)
134 nx = (win->left + mask) & ~mask;
135 nw = (win->width) & ~mask;
136 if (nx + nw > win->left + win->width)
142 printk(KERN_DEBUG "btcx: window align %dx%d+%d+%d [dx=%d]\n",
143 win->width, win->height, win->left, win->top, dx);
146 for (i = 0; i < n; i++) {
147 nx = (clips[i].c.left-dx) & ~mask;
148 nw = (clips[i].c.width) & ~mask;
149 if (nx + nw < clips[i].c.left-dx + clips[i].c.width)
151 clips[i].c.left = nx;
152 clips[i].c.width = nw;
154 printk(KERN_DEBUG "btcx: clip align %dx%d+%d+%d\n",
155 clips[i].c.width, clips[i].c.height,
156 clips[i].c.left, clips[i].c.top);
162 btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips)
164 struct v4l2_clip swap;
169 for (i = nclips-2; i >= 0; i--) {
170 for (n = 0, j = 0; j <= i; j++) {
171 if (clips[j].c.left > clips[j+1].c.left) {
173 clips[j] = clips[j+1];
184 btcx_calc_skips(int line, int width, unsigned int *maxy,
185 struct btcx_skiplist *skips, unsigned int *nskips,
186 const struct v4l2_clip *clips, unsigned int nclips)
188 unsigned int clip,skip;
193 for (clip = 0; clip < nclips; clip++) {
196 if (clips[clip].c.left + clips[clip].c.width <= 0)
198 if (clips[clip].c.left > (signed)width)
202 if (line > clips[clip].c.top+clips[clip].c.height-1)
204 if (line < clips[clip].c.top) {
205 if (maxline > clips[clip].c.top-1)
206 maxline = clips[clip].c.top-1;
209 if (maxline > clips[clip].c.top+clips[clip].c.height-1)
210 maxline = clips[clip].c.top+clips[clip].c.height-1;
212 /* horizontal range */
213 if (0 == skip || clips[clip].c.left > skips[skip-1].end) {
215 skips[skip].start = clips[clip].c.left;
216 if (skips[skip].start < 0)
217 skips[skip].start = 0;
218 skips[skip].end = clips[clip].c.left + clips[clip].c.width;
219 if (skips[skip].end > width)
220 skips[skip].end = width;
223 /* overlaps -- expand last one */
224 end = clips[clip].c.left + clips[clip].c.width;
225 if (skips[skip-1].end < end)
226 skips[skip-1].end = end;
227 if (skips[skip-1].end > width)
228 skips[skip-1].end = width;
235 printk(KERN_DEBUG "btcx: skips line %d-%d:",line,maxline);
236 for (skip = 0; skip < *nskips; skip++) {
237 printk(" %d-%d",skips[skip].start,skips[skip].end);
243 /* ---------------------------------------------------------- */
245 EXPORT_SYMBOL(btcx_riscmem_alloc);
246 EXPORT_SYMBOL(btcx_riscmem_free);
248 EXPORT_SYMBOL(btcx_screen_clips);
249 EXPORT_SYMBOL(btcx_align);
250 EXPORT_SYMBOL(btcx_sort_clips);
251 EXPORT_SYMBOL(btcx_calc_skips);