bttv-risc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. $Id: bttv-risc.c,v 1.10 2004/11/19 18:07:12 kraxel Exp $
  3. bttv-risc.c -- interfaces to other kernel modules
  4. bttv risc code handling
  5. - memory management
  6. - generation
  7. (c) 2000-2003 Gerd Knorr <kraxel@bytesex.org>
  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.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/pci.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/interrupt.h>
  25. #include <asm/page.h>
  26. #include <asm/pgtable.h>
  27. #include "bttvp.h"
  28. #define VCR_HACK_LINES 4
  29. /* ---------------------------------------------------------- */
  30. /* risc code generators */
  31. int
  32. bttv_risc_packed(struct bttv *btv, struct btcx_riscmem *risc,
  33. struct scatterlist *sglist,
  34. unsigned int offset, unsigned int bpl,
  35. unsigned int padding, unsigned int lines)
  36. {
  37. u32 instructions,line,todo;
  38. struct scatterlist *sg;
  39. u32 *rp;
  40. int rc;
  41. /* estimate risc mem: worst case is one write per page border +
  42. one write per scan line + sync + jump (all 2 dwords) */
  43. instructions = (bpl * lines) / PAGE_SIZE + lines;
  44. instructions += 2;
  45. if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*8)) < 0)
  46. return rc;
  47. /* sync instruction */
  48. rp = risc->cpu;
  49. *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1);
  50. *(rp++) = cpu_to_le32(0);
  51. /* scan lines */
  52. sg = sglist;
  53. for (line = 0; line < lines; line++) {
  54. if ((btv->opt_vcr_hack) &&
  55. (line >= (lines - VCR_HACK_LINES)))
  56. continue;
  57. while (offset && offset >= sg_dma_len(sg)) {
  58. offset -= sg_dma_len(sg);
  59. sg++;
  60. }
  61. if (bpl <= sg_dma_len(sg)-offset) {
  62. /* fits into current chunk */
  63. *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_SOL|
  64. BT848_RISC_EOL|bpl);
  65. *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
  66. offset+=bpl;
  67. } else {
  68. /* scanline needs to be splitted */
  69. todo = bpl;
  70. *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_SOL|
  71. (sg_dma_len(sg)-offset));
  72. *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
  73. todo -= (sg_dma_len(sg)-offset);
  74. offset = 0;
  75. sg++;
  76. while (todo > sg_dma_len(sg)) {
  77. *(rp++)=cpu_to_le32(BT848_RISC_WRITE|
  78. sg_dma_len(sg));
  79. *(rp++)=cpu_to_le32(sg_dma_address(sg));
  80. todo -= sg_dma_len(sg);
  81. sg++;
  82. }
  83. *(rp++)=cpu_to_le32(BT848_RISC_WRITE|BT848_RISC_EOL|
  84. todo);
  85. *(rp++)=cpu_to_le32(sg_dma_address(sg));
  86. offset += todo;
  87. }
  88. offset += padding;
  89. }
  90. /* save pointer to jmp instruction address */
  91. risc->jmp = rp;
  92. BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size);
  93. return 0;
  94. }
  95. static int
  96. bttv_risc_planar(struct bttv *btv, struct btcx_riscmem *risc,
  97. struct scatterlist *sglist,
  98. unsigned int yoffset, unsigned int ybpl,
  99. unsigned int ypadding, unsigned int ylines,
  100. unsigned int uoffset, unsigned int voffset,
  101. unsigned int hshift, unsigned int vshift,
  102. unsigned int cpadding)
  103. {
  104. unsigned int instructions,line,todo,ylen,chroma;
  105. u32 *rp,ri;
  106. struct scatterlist *ysg;
  107. struct scatterlist *usg;
  108. struct scatterlist *vsg;
  109. int topfield = (0 == yoffset);
  110. int rc;
  111. /* estimate risc mem: worst case is one write per page border +
  112. one write per scan line (5 dwords)
  113. plus sync + jump (2 dwords) */
  114. instructions = (ybpl * ylines * 2) / PAGE_SIZE + ylines;
  115. instructions += 2;
  116. if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*4*5)) < 0)
  117. return rc;
  118. /* sync instruction */
  119. rp = risc->cpu;
  120. *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM3);
  121. *(rp++) = cpu_to_le32(0);
  122. /* scan lines */
  123. ysg = sglist;
  124. usg = sglist;
  125. vsg = sglist;
  126. for (line = 0; line < ylines; line++) {
  127. if ((btv->opt_vcr_hack) &&
  128. (line >= (ylines - VCR_HACK_LINES)))
  129. continue;
  130. switch (vshift) {
  131. case 0:
  132. chroma = 1;
  133. break;
  134. case 1:
  135. if (topfield)
  136. chroma = ((line & 1) == 0);
  137. else
  138. chroma = ((line & 1) == 1);
  139. break;
  140. case 2:
  141. if (topfield)
  142. chroma = ((line & 3) == 0);
  143. else
  144. chroma = ((line & 3) == 2);
  145. break;
  146. default:
  147. chroma = 0;
  148. break;
  149. }
  150. for (todo = ybpl; todo > 0; todo -= ylen) {
  151. /* go to next sg entry if needed */
  152. while (yoffset && yoffset >= sg_dma_len(ysg)) {
  153. yoffset -= sg_dma_len(ysg);
  154. ysg++;
  155. }
  156. while (uoffset && uoffset >= sg_dma_len(usg)) {
  157. uoffset -= sg_dma_len(usg);
  158. usg++;
  159. }
  160. while (voffset && voffset >= sg_dma_len(vsg)) {
  161. voffset -= sg_dma_len(vsg);
  162. vsg++;
  163. }
  164. /* calculate max number of bytes we can write */
  165. ylen = todo;
  166. if (yoffset + ylen > sg_dma_len(ysg))
  167. ylen = sg_dma_len(ysg) - yoffset;
  168. if (chroma) {
  169. if (uoffset + (ylen>>hshift) > sg_dma_len(usg))
  170. ylen = (sg_dma_len(usg) - uoffset) << hshift;
  171. if (voffset + (ylen>>hshift) > sg_dma_len(vsg))
  172. ylen = (sg_dma_len(vsg) - voffset) << hshift;
  173. ri = BT848_RISC_WRITE123;
  174. } else {
  175. ri = BT848_RISC_WRITE1S23;
  176. }
  177. if (ybpl == todo)
  178. ri |= BT848_RISC_SOL;
  179. if (ylen == todo)
  180. ri |= BT848_RISC_EOL;
  181. /* write risc instruction */
  182. *(rp++)=cpu_to_le32(ri | ylen);
  183. *(rp++)=cpu_to_le32(((ylen >> hshift) << 16) |
  184. (ylen >> hshift));
  185. *(rp++)=cpu_to_le32(sg_dma_address(ysg)+yoffset);
  186. yoffset += ylen;
  187. if (chroma) {
  188. *(rp++)=cpu_to_le32(sg_dma_address(usg)+uoffset);
  189. uoffset += ylen >> hshift;
  190. *(rp++)=cpu_to_le32(sg_dma_address(vsg)+voffset);
  191. voffset += ylen >> hshift;
  192. }
  193. }
  194. yoffset += ypadding;
  195. if (chroma) {
  196. uoffset += cpadding;
  197. voffset += cpadding;
  198. }
  199. }
  200. /* save pointer to jmp instruction address */
  201. risc->jmp = rp;
  202. BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size);
  203. return 0;
  204. }
  205. static int
  206. bttv_risc_overlay(struct bttv *btv, struct btcx_riscmem *risc,
  207. const struct bttv_format *fmt, struct bttv_overlay *ov,
  208. int skip_even, int skip_odd)
  209. {
  210. int instructions,rc,line,maxy,start,end,skip,nskips;
  211. struct btcx_skiplist *skips;
  212. u32 *rp,ri,ra;
  213. u32 addr;
  214. /* skip list for window clipping */
  215. if (NULL == (skips = kmalloc(sizeof(*skips) * ov->nclips,GFP_KERNEL)))
  216. return -ENOMEM;
  217. /* estimate risc mem: worst case is (clip+1) * lines instructions
  218. + sync + jump (all 2 dwords) */
  219. instructions = (ov->nclips + 1) *
  220. ((skip_even || skip_odd) ? ov->w.height>>1 : ov->w.height);
  221. instructions += 2;
  222. if ((rc = btcx_riscmem_alloc(btv->c.pci,risc,instructions*8)) < 0) {
  223. kfree(skips);
  224. return rc;
  225. }
  226. /* sync instruction */
  227. rp = risc->cpu;
  228. *(rp++) = cpu_to_le32(BT848_RISC_SYNC|BT848_FIFO_STATUS_FM1);
  229. *(rp++) = cpu_to_le32(0);
  230. addr = (unsigned long)btv->fbuf.base;
  231. addr += btv->fbuf.fmt.bytesperline * ov->w.top;
  232. addr += (fmt->depth >> 3) * ov->w.left;
  233. /* scan lines */
  234. for (maxy = -1, line = 0; line < ov->w.height;
  235. line++, addr += btv->fbuf.fmt.bytesperline) {
  236. if ((btv->opt_vcr_hack) &&
  237. (line >= (ov->w.height - VCR_HACK_LINES)))
  238. continue;
  239. if ((line%2) == 0 && skip_even)
  240. continue;
  241. if ((line%2) == 1 && skip_odd)
  242. continue;
  243. /* calculate clipping */
  244. if (line > maxy)
  245. btcx_calc_skips(line, ov->w.width, &maxy,
  246. skips, &nskips, ov->clips, ov->nclips);
  247. /* write out risc code */
  248. for (start = 0, skip = 0; start < ov->w.width; start = end) {
  249. if (skip >= nskips) {
  250. ri = BT848_RISC_WRITE;
  251. end = ov->w.width;
  252. } else if (start < skips[skip].start) {
  253. ri = BT848_RISC_WRITE;
  254. end = skips[skip].start;
  255. } else {
  256. ri = BT848_RISC_SKIP;
  257. end = skips[skip].end;
  258. skip++;
  259. }
  260. if (BT848_RISC_WRITE == ri)
  261. ra = addr + (fmt->depth>>3)*start;
  262. else
  263. ra = 0;
  264. if (0 == start)
  265. ri |= BT848_RISC_SOL;
  266. if (ov->w.width == end)
  267. ri |= BT848_RISC_EOL;
  268. ri |= (fmt->depth>>3) * (end-start);
  269. *(rp++)=cpu_to_le32(ri);
  270. if (0 != ra)
  271. *(rp++)=cpu_to_le32(ra);
  272. }
  273. }
  274. /* save pointer to jmp instruction address */
  275. risc->jmp = rp;
  276. BUG_ON((risc->jmp - risc->cpu + 2) / 4 > risc->size);
  277. kfree(skips);
  278. return 0;
  279. }
  280. /* ---------------------------------------------------------- */
  281. static void
  282. bttv_calc_geo(struct bttv *btv, struct bttv_geometry *geo,
  283. int width, int height, int interleaved, int norm)
  284. {
  285. const struct bttv_tvnorm *tvnorm = &bttv_tvnorms[norm];
  286. u32 xsf, sr;
  287. int vdelay;
  288. int swidth = tvnorm->swidth;
  289. int totalwidth = tvnorm->totalwidth;
  290. int scaledtwidth = tvnorm->scaledtwidth;
  291. if (bttv_tvcards[btv->c.type].muxsel[btv->input] < 0) {
  292. swidth = 720;
  293. totalwidth = 858;
  294. scaledtwidth = 858;
  295. }
  296. vdelay = tvnorm->vdelay;
  297. xsf = (width*scaledtwidth)/swidth;
  298. geo->hscale = ((totalwidth*4096UL)/xsf-4096);
  299. geo->hdelay = tvnorm->hdelayx1;
  300. geo->hdelay = (geo->hdelay*width)/swidth;
  301. geo->hdelay &= 0x3fe;
  302. sr = ((tvnorm->sheight >> (interleaved?0:1))*512)/height - 512;
  303. geo->vscale = (0x10000UL-sr) & 0x1fff;
  304. geo->crop = ((width>>8)&0x03) | ((geo->hdelay>>6)&0x0c) |
  305. ((tvnorm->sheight>>4)&0x30) | ((vdelay>>2)&0xc0);
  306. geo->vscale |= interleaved ? (BT848_VSCALE_INT<<8) : 0;
  307. geo->vdelay = vdelay;
  308. geo->width = width;
  309. geo->sheight = tvnorm->sheight;
  310. geo->vtotal = tvnorm->vtotal;
  311. if (btv->opt_combfilter) {
  312. geo->vtc = (width < 193) ? 2 : ((width < 385) ? 1 : 0);
  313. geo->comb = (width < 769) ? 1 : 0;
  314. } else {
  315. geo->vtc = 0;
  316. geo->comb = 0;
  317. }
  318. }
  319. static void
  320. bttv_apply_geo(struct bttv *btv, struct bttv_geometry *geo, int odd)
  321. {
  322. int off = odd ? 0x80 : 0x00;
  323. if (geo->comb)
  324. btor(BT848_VSCALE_COMB, BT848_E_VSCALE_HI+off);
  325. else
  326. btand(~BT848_VSCALE_COMB, BT848_E_VSCALE_HI+off);
  327. btwrite(geo->vtc, BT848_E_VTC+off);
  328. btwrite(geo->hscale >> 8, BT848_E_HSCALE_HI+off);
  329. btwrite(geo->hscale & 0xff, BT848_E_HSCALE_LO+off);
  330. btaor((geo->vscale>>8), 0xe0, BT848_E_VSCALE_HI+off);
  331. btwrite(geo->vscale & 0xff, BT848_E_VSCALE_LO+off);
  332. btwrite(geo->width & 0xff, BT848_E_HACTIVE_LO+off);
  333. btwrite(geo->hdelay & 0xff, BT848_E_HDELAY_LO+off);
  334. btwrite(geo->sheight & 0xff, BT848_E_VACTIVE_LO+off);
  335. btwrite(geo->vdelay & 0xff, BT848_E_VDELAY_LO+off);
  336. btwrite(geo->crop, BT848_E_CROP+off);
  337. btwrite(geo->vtotal>>8, BT848_VTOTAL_HI);
  338. btwrite(geo->vtotal & 0xff, BT848_VTOTAL_LO);
  339. }
  340. /* ---------------------------------------------------------- */
  341. /* risc group / risc main loop / dma management */
  342. void
  343. bttv_set_dma(struct bttv *btv, int override)
  344. {
  345. unsigned long cmd;
  346. int capctl;
  347. btv->cap_ctl = 0;
  348. if (NULL != btv->curr.top) btv->cap_ctl |= 0x02;
  349. if (NULL != btv->curr.bottom) btv->cap_ctl |= 0x01;
  350. if (NULL != btv->cvbi) btv->cap_ctl |= 0x0c;
  351. capctl = 0;
  352. capctl |= (btv->cap_ctl & 0x03) ? 0x03 : 0x00; /* capture */
  353. capctl |= (btv->cap_ctl & 0x0c) ? 0x0c : 0x00; /* vbi data */
  354. capctl |= override;
  355. d2printk(KERN_DEBUG
  356. "bttv%d: capctl=%x lirq=%d top=%08Lx/%08Lx even=%08Lx/%08Lx\n",
  357. btv->c.nr,capctl,btv->loop_irq,
  358. btv->cvbi ? (unsigned long long)btv->cvbi->top.dma : 0,
  359. btv->curr.top ? (unsigned long long)btv->curr.top->top.dma : 0,
  360. btv->cvbi ? (unsigned long long)btv->cvbi->bottom.dma : 0,
  361. btv->curr.bottom ? (unsigned long long)btv->curr.bottom->bottom.dma : 0);
  362. cmd = BT848_RISC_JUMP;
  363. if (btv->loop_irq) {
  364. cmd |= BT848_RISC_IRQ;
  365. cmd |= (btv->loop_irq & 0x0f) << 16;
  366. cmd |= (~btv->loop_irq & 0x0f) << 20;
  367. }
  368. if (btv->curr.frame_irq || btv->loop_irq || btv->cvbi) {
  369. mod_timer(&btv->timeout, jiffies+BTTV_TIMEOUT);
  370. } else {
  371. del_timer(&btv->timeout);
  372. }
  373. btv->main.cpu[RISC_SLOT_LOOP] = cpu_to_le32(cmd);
  374. btaor(capctl, ~0x0f, BT848_CAP_CTL);
  375. if (capctl) {
  376. if (btv->dma_on)
  377. return;
  378. btwrite(btv->main.dma, BT848_RISC_STRT_ADD);
  379. btor(3, BT848_GPIO_DMA_CTL);
  380. btv->dma_on = 1;
  381. } else {
  382. if (!btv->dma_on)
  383. return;
  384. btand(~3, BT848_GPIO_DMA_CTL);
  385. btv->dma_on = 0;
  386. }
  387. return;
  388. }
  389. int
  390. bttv_risc_init_main(struct bttv *btv)
  391. {
  392. int rc;
  393. if ((rc = btcx_riscmem_alloc(btv->c.pci,&btv->main,PAGE_SIZE)) < 0)
  394. return rc;
  395. dprintk(KERN_DEBUG "bttv%d: risc main @ %08Lx\n",
  396. btv->c.nr,(unsigned long long)btv->main.dma);
  397. btv->main.cpu[0] = cpu_to_le32(BT848_RISC_SYNC | BT848_RISC_RESYNC |
  398. BT848_FIFO_STATUS_VRE);
  399. btv->main.cpu[1] = cpu_to_le32(0);
  400. btv->main.cpu[2] = cpu_to_le32(BT848_RISC_JUMP);
  401. btv->main.cpu[3] = cpu_to_le32(btv->main.dma + (4<<2));
  402. /* top field */
  403. btv->main.cpu[4] = cpu_to_le32(BT848_RISC_JUMP);
  404. btv->main.cpu[5] = cpu_to_le32(btv->main.dma + (6<<2));
  405. btv->main.cpu[6] = cpu_to_le32(BT848_RISC_JUMP);
  406. btv->main.cpu[7] = cpu_to_le32(btv->main.dma + (8<<2));
  407. btv->main.cpu[8] = cpu_to_le32(BT848_RISC_SYNC | BT848_RISC_RESYNC |
  408. BT848_FIFO_STATUS_VRO);
  409. btv->main.cpu[9] = cpu_to_le32(0);
  410. /* bottom field */
  411. btv->main.cpu[10] = cpu_to_le32(BT848_RISC_JUMP);
  412. btv->main.cpu[11] = cpu_to_le32(btv->main.dma + (12<<2));
  413. btv->main.cpu[12] = cpu_to_le32(BT848_RISC_JUMP);
  414. btv->main.cpu[13] = cpu_to_le32(btv->main.dma + (14<<2));
  415. /* jump back to top field */
  416. btv->main.cpu[14] = cpu_to_le32(BT848_RISC_JUMP);
  417. btv->main.cpu[15] = cpu_to_le32(btv->main.dma + (0<<2));
  418. return 0;
  419. }
  420. int
  421. bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
  422. int irqflags)
  423. {
  424. unsigned long cmd;
  425. unsigned long next = btv->main.dma + ((slot+2) << 2);
  426. if (NULL == risc) {
  427. d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=NULL\n",
  428. btv->c.nr,risc,slot);
  429. btv->main.cpu[slot+1] = cpu_to_le32(next);
  430. } else {
  431. d2printk(KERN_DEBUG "bttv%d: risc=%p slot[%d]=%08Lx irq=%d\n",
  432. btv->c.nr,risc,slot,(unsigned long long)risc->dma,irqflags);
  433. cmd = BT848_RISC_JUMP;
  434. if (irqflags) {
  435. cmd |= BT848_RISC_IRQ;
  436. cmd |= (irqflags & 0x0f) << 16;
  437. cmd |= (~irqflags & 0x0f) << 20;
  438. }
  439. risc->jmp[0] = cpu_to_le32(cmd);
  440. risc->jmp[1] = cpu_to_le32(next);
  441. btv->main.cpu[slot+1] = cpu_to_le32(risc->dma);
  442. }
  443. return 0;
  444. }
  445. void
  446. bttv_dma_free(struct bttv *btv, struct bttv_buffer *buf)
  447. {
  448. if (in_interrupt())
  449. BUG();
  450. videobuf_waiton(&buf->vb,0,0);
  451. videobuf_dma_pci_unmap(btv->c.pci, &buf->vb.dma);
  452. videobuf_dma_free(&buf->vb.dma);
  453. btcx_riscmem_free(btv->c.pci,&buf->bottom);
  454. btcx_riscmem_free(btv->c.pci,&buf->top);
  455. buf->vb.state = STATE_NEEDS_INIT;
  456. }
  457. int
  458. bttv_buffer_activate_vbi(struct bttv *btv,
  459. struct bttv_buffer *vbi)
  460. {
  461. /* vbi capture */
  462. if (vbi) {
  463. vbi->vb.state = STATE_ACTIVE;
  464. list_del(&vbi->vb.queue);
  465. bttv_risc_hook(btv, RISC_SLOT_O_VBI, &vbi->top, 0);
  466. bttv_risc_hook(btv, RISC_SLOT_E_VBI, &vbi->bottom, 4);
  467. } else {
  468. bttv_risc_hook(btv, RISC_SLOT_O_VBI, NULL, 0);
  469. bttv_risc_hook(btv, RISC_SLOT_E_VBI, NULL, 0);
  470. }
  471. return 0;
  472. }
  473. int
  474. bttv_buffer_activate_video(struct bttv *btv,
  475. struct bttv_buffer_set *set)
  476. {
  477. /* video capture */
  478. if (NULL != set->top && NULL != set->bottom) {
  479. if (set->top == set->bottom) {
  480. set->top->vb.state = STATE_ACTIVE;
  481. if (set->top->vb.queue.next)
  482. list_del(&set->top->vb.queue);
  483. } else {
  484. set->top->vb.state = STATE_ACTIVE;
  485. set->bottom->vb.state = STATE_ACTIVE;
  486. if (set->top->vb.queue.next)
  487. list_del(&set->top->vb.queue);
  488. if (set->bottom->vb.queue.next)
  489. list_del(&set->bottom->vb.queue);
  490. }
  491. bttv_apply_geo(btv, &set->top->geo, 1);
  492. bttv_apply_geo(btv, &set->bottom->geo,0);
  493. bttv_risc_hook(btv, RISC_SLOT_O_FIELD, &set->top->top,
  494. set->top_irq);
  495. bttv_risc_hook(btv, RISC_SLOT_E_FIELD, &set->bottom->bottom,
  496. set->frame_irq);
  497. btaor((set->top->btformat & 0xf0) | (set->bottom->btformat & 0x0f),
  498. ~0xff, BT848_COLOR_FMT);
  499. btaor((set->top->btswap & 0x0a) | (set->bottom->btswap & 0x05),
  500. ~0x0f, BT848_COLOR_CTL);
  501. } else if (NULL != set->top) {
  502. set->top->vb.state = STATE_ACTIVE;
  503. if (set->top->vb.queue.next)
  504. list_del(&set->top->vb.queue);
  505. bttv_apply_geo(btv, &set->top->geo,1);
  506. bttv_apply_geo(btv, &set->top->geo,0);
  507. bttv_risc_hook(btv, RISC_SLOT_O_FIELD, &set->top->top,
  508. set->frame_irq);
  509. bttv_risc_hook(btv, RISC_SLOT_E_FIELD, NULL, 0);
  510. btaor(set->top->btformat & 0xff, ~0xff, BT848_COLOR_FMT);
  511. btaor(set->top->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL);
  512. } else if (NULL != set->bottom) {
  513. set->bottom->vb.state = STATE_ACTIVE;
  514. if (set->bottom->vb.queue.next)
  515. list_del(&set->bottom->vb.queue);
  516. bttv_apply_geo(btv, &set->bottom->geo,1);
  517. bttv_apply_geo(btv, &set->bottom->geo,0);
  518. bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
  519. bttv_risc_hook(btv, RISC_SLOT_E_FIELD, &set->bottom->bottom,
  520. set->frame_irq);
  521. btaor(set->bottom->btformat & 0xff, ~0xff, BT848_COLOR_FMT);
  522. btaor(set->bottom->btswap & 0x0f, ~0x0f, BT848_COLOR_CTL);
  523. } else {
  524. bttv_risc_hook(btv, RISC_SLOT_O_FIELD, NULL, 0);
  525. bttv_risc_hook(btv, RISC_SLOT_E_FIELD, NULL, 0);
  526. }
  527. return 0;
  528. }
  529. /* ---------------------------------------------------------- */
  530. /* calculate geometry, build risc code */
  531. int
  532. bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
  533. {
  534. const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm;
  535. dprintk(KERN_DEBUG
  536. "bttv%d: buffer field: %s format: %s size: %dx%d\n",
  537. btv->c.nr, v4l2_field_names[buf->vb.field],
  538. buf->fmt->name, buf->vb.width, buf->vb.height);
  539. /* packed pixel modes */
  540. if (buf->fmt->flags & FORMAT_FLAGS_PACKED) {
  541. int bpl = (buf->fmt->depth >> 3) * buf->vb.width;
  542. int bpf = bpl * (buf->vb.height >> 1);
  543. bttv_calc_geo(btv,&buf->geo,buf->vb.width,buf->vb.height,
  544. V4L2_FIELD_HAS_BOTH(buf->vb.field),buf->tvnorm);
  545. switch (buf->vb.field) {
  546. case V4L2_FIELD_TOP:
  547. bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
  548. 0,bpl,0,buf->vb.height);
  549. break;
  550. case V4L2_FIELD_BOTTOM:
  551. bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
  552. 0,bpl,0,buf->vb.height);
  553. break;
  554. case V4L2_FIELD_INTERLACED:
  555. bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
  556. 0,bpl,bpl,buf->vb.height >> 1);
  557. bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
  558. bpl,bpl,bpl,buf->vb.height >> 1);
  559. break;
  560. case V4L2_FIELD_SEQ_TB:
  561. bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist,
  562. 0,bpl,0,buf->vb.height >> 1);
  563. bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist,
  564. bpf,bpl,0,buf->vb.height >> 1);
  565. break;
  566. default:
  567. BUG();
  568. }
  569. }
  570. /* planar modes */
  571. if (buf->fmt->flags & FORMAT_FLAGS_PLANAR) {
  572. int uoffset, voffset;
  573. int ypadding, cpadding, lines;
  574. /* calculate chroma offsets */
  575. uoffset = buf->vb.width * buf->vb.height;
  576. voffset = buf->vb.width * buf->vb.height;
  577. if (buf->fmt->flags & FORMAT_FLAGS_CrCb) {
  578. /* Y-Cr-Cb plane order */
  579. uoffset >>= buf->fmt->hshift;
  580. uoffset >>= buf->fmt->vshift;
  581. uoffset += voffset;
  582. } else {
  583. /* Y-Cb-Cr plane order */
  584. voffset >>= buf->fmt->hshift;
  585. voffset >>= buf->fmt->vshift;
  586. voffset += uoffset;
  587. }
  588. switch (buf->vb.field) {
  589. case V4L2_FIELD_TOP:
  590. bttv_calc_geo(btv,&buf->geo,buf->vb.width,
  591. buf->vb.height,0,buf->tvnorm);
  592. bttv_risc_planar(btv, &buf->top, buf->vb.dma.sglist,
  593. 0,buf->vb.width,0,buf->vb.height,
  594. uoffset,voffset,buf->fmt->hshift,
  595. buf->fmt->vshift,0);
  596. break;
  597. case V4L2_FIELD_BOTTOM:
  598. bttv_calc_geo(btv,&buf->geo,buf->vb.width,
  599. buf->vb.height,0,buf->tvnorm);
  600. bttv_risc_planar(btv, &buf->bottom, buf->vb.dma.sglist,
  601. 0,buf->vb.width,0,buf->vb.height,
  602. uoffset,voffset,buf->fmt->hshift,
  603. buf->fmt->vshift,0);
  604. break;
  605. case V4L2_FIELD_INTERLACED:
  606. bttv_calc_geo(btv,&buf->geo,buf->vb.width,
  607. buf->vb.height,1,buf->tvnorm);
  608. lines = buf->vb.height >> 1;
  609. ypadding = buf->vb.width;
  610. cpadding = buf->vb.width >> buf->fmt->hshift;
  611. bttv_risc_planar(btv,&buf->top,
  612. buf->vb.dma.sglist,
  613. 0,buf->vb.width,ypadding,lines,
  614. uoffset,voffset,
  615. buf->fmt->hshift,
  616. buf->fmt->vshift,
  617. cpadding);
  618. bttv_risc_planar(btv,&buf->bottom,
  619. buf->vb.dma.sglist,
  620. ypadding,buf->vb.width,ypadding,lines,
  621. uoffset+cpadding,
  622. voffset+cpadding,
  623. buf->fmt->hshift,
  624. buf->fmt->vshift,
  625. cpadding);
  626. break;
  627. case V4L2_FIELD_SEQ_TB:
  628. bttv_calc_geo(btv,&buf->geo,buf->vb.width,
  629. buf->vb.height,1,buf->tvnorm);
  630. lines = buf->vb.height >> 1;
  631. ypadding = buf->vb.width;
  632. cpadding = buf->vb.width >> buf->fmt->hshift;
  633. bttv_risc_planar(btv,&buf->top,
  634. buf->vb.dma.sglist,
  635. 0,buf->vb.width,0,lines,
  636. uoffset >> 1,
  637. voffset >> 1,
  638. buf->fmt->hshift,
  639. buf->fmt->vshift,
  640. 0);
  641. bttv_risc_planar(btv,&buf->bottom,
  642. buf->vb.dma.sglist,
  643. lines * ypadding,buf->vb.width,0,lines,
  644. lines * ypadding + (uoffset >> 1),
  645. lines * ypadding + (voffset >> 1),
  646. buf->fmt->hshift,
  647. buf->fmt->vshift,
  648. 0);
  649. break;
  650. default:
  651. BUG();
  652. }
  653. }
  654. /* raw data */
  655. if (buf->fmt->flags & FORMAT_FLAGS_RAW) {
  656. /* build risc code */
  657. buf->vb.field = V4L2_FIELD_SEQ_TB;
  658. bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight,
  659. 1,buf->tvnorm);
  660. bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist,
  661. 0, RAW_BPL, 0, RAW_LINES);
  662. bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist,
  663. buf->vb.size/2 , RAW_BPL, 0, RAW_LINES);
  664. }
  665. /* copy format info */
  666. buf->btformat = buf->fmt->btformat;
  667. buf->btswap = buf->fmt->btswap;
  668. return 0;
  669. }
  670. /* ---------------------------------------------------------- */
  671. /* calculate geometry, build risc code */
  672. int
  673. bttv_overlay_risc(struct bttv *btv,
  674. struct bttv_overlay *ov,
  675. const struct bttv_format *fmt,
  676. struct bttv_buffer *buf)
  677. {
  678. /* check interleave, bottom+top fields */
  679. dprintk(KERN_DEBUG
  680. "bttv%d: overlay fields: %s format: %s size: %dx%d\n",
  681. btv->c.nr, v4l2_field_names[buf->vb.field],
  682. fmt->name,ov->w.width,ov->w.height);
  683. /* calculate geometry */
  684. bttv_calc_geo(btv,&buf->geo,ov->w.width,ov->w.height,
  685. V4L2_FIELD_HAS_BOTH(ov->field), ov->tvnorm);
  686. /* build risc code */
  687. switch (ov->field) {
  688. case V4L2_FIELD_TOP:
  689. bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 0);
  690. break;
  691. case V4L2_FIELD_BOTTOM:
  692. bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 0, 0);
  693. break;
  694. case V4L2_FIELD_INTERLACED:
  695. bttv_risc_overlay(btv, &buf->top, fmt, ov, 0, 1);
  696. bttv_risc_overlay(btv, &buf->bottom, fmt, ov, 1, 0);
  697. break;
  698. default:
  699. BUG();
  700. }
  701. /* copy format info */
  702. buf->btformat = fmt->btformat;
  703. buf->btswap = fmt->btswap;
  704. buf->vb.field = ov->field;
  705. return 0;
  706. }
  707. /*
  708. * Local variables:
  709. * c-basic-offset: 8
  710. * End:
  711. */