--- linux-2.4.paul/drivers/char/planb.c Thu Aug 10 06:06:39 2000 +++ linux/drivers/char/planb.c Sat Aug 12 17:59:40 2000 @@ -1,15 +1,16 @@ /* - planb - PlanB frame grabber driver + planb - v4l-compatible frame grabber driver for the PlanB hardware PlanB is used in the 7x00/8x00 series of PowerMacintosh Computers as video input DMA controller. - Copyright (C) 1998 Michel Lanners (mlan@cpu.lu) + Copyright (C) 1998, 1999 Michel Lanners (mlan@cpu.lu) Based largely on the bttv driver by Ralph Metzler (rjkm@thp.uni-koeln.de) Additional debugging and coding by Takashi Oe (toe@unlserve.unl.edu) + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -25,7 +26,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: planb.c,v 1.18 1999/05/02 17:36:34 mlan Exp $ */ +/* $Id: planb.c,v 2.5 1999/12/22 20:29:35 mlan Exp mlan $ */ #include #include @@ -40,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -51,15 +53,25 @@ #include #include -#include "planb.h" -#include "saa7196.h" +/* Define these to get general / interrupt debugging */ +#undef DEBUG +#undef IDEBUG +#define DEBUG -/* Would you mind for some ugly debugging? */ -//#define DEBUG(x...) printk(KERN_DEBUG ## x) /* Debug driver */ -#define DEBUG(x...) /* Don't debug driver */ -//#define IDEBUG(x...) printk(KERN_DEBUG ## x) /* Debug interrupt part */ -#define IDEBUG(x...) /* Don't debug interrupt part */ +#ifdef DEBUG +#define DBG(x...) printk(KERN_DEBUG ## x) +#else +#define DBG(x...) +#endif +#ifdef DEBUG +#define IDBG(x...) printk(KERN_DEBUG ## x) +#else +#define IDBG(x...) +#endif + +#include "planb.h" +#include "saa7196.h" /* Ever seen a Mac with more than 1 of these? */ #define PLANB_MAX 1 @@ -73,6 +85,9 @@ MODULE_PARM(def_norm, "i"); MODULE_PARM_DESC(def_norm, "Default startup norm (0=PAL, 1=NTSC, 2=SECAM)"); +MODULE_DESCRIPTION("planb - v4l driver module for Apple PlanB video in"); +MODULE_AUTHOR("Michel Lanners & Takashi Oe - see: http://www.cpu.lu/planb.html"); + /* ------------------ PlanB Exported Functions ------------------ */ static long planb_write(struct video_device *, const char *, unsigned long, int); static long planb_read(struct video_device *, char *, unsigned long, int); @@ -82,12 +97,22 @@ static int planb_init_done(struct video_device *); static int planb_mmap(struct video_device *, const char *, unsigned long); static void planb_irq(int, void *, struct pt_regs *); +static int planb_vbi_open(struct video_device *, int); +static void planb_vbi_close(struct video_device *); +static long planb_vbi_read(struct video_device *, char *, unsigned long, int); +static unsigned int planb_vbi_poll(struct video_device *, struct file *, + poll_table *); +static int planb_vbi_ioctl(struct video_device *, unsigned int, void *); static void release_planb(void); int init_planbs(struct video_init *); /* ------------------ PlanB Internal Functions ------------------ */ static int planb_prepare_open(struct planb *); +static int planb_prepare_vbi(struct planb *); +static int planb_prepare_video(struct planb *); static void planb_prepare_close(struct planb *); +static void planb_close_vbi(struct planb *); +static void planb_close_video(struct planb *); static void saa_write_reg(unsigned char, unsigned char); static unsigned char saa_status(int, struct planb *); static void saa_set(unsigned char, unsigned char, struct planb *); @@ -97,21 +122,20 @@ static void add_clip(struct planb *, struct video_clip *); static void fill_cmd_buff(struct planb *); static void cmd_buff(struct planb *); -static volatile struct dbdma_cmd *setup_grab_cmd(int, struct planb *); +static dbdma_cmd_ptr setup_grab_cmd(int, struct planb *); static void overlay_start(struct planb *); static void overlay_stop(struct planb *); -static inline void tab_cmd_dbdma(volatile struct dbdma_cmd *, unsigned short, - unsigned int); -static inline void tab_cmd_store(volatile struct dbdma_cmd *, unsigned int, - unsigned int); -static inline void tab_cmd_gen(volatile struct dbdma_cmd *, unsigned short, - unsigned short, unsigned int, unsigned int); +static inline void tab_cmd_dbdma(dbdma_cmd_ptr, unsigned short, unsigned int); +static inline void tab_cmd_store(dbdma_cmd_ptr, unsigned int, unsigned int); +static inline void tab_cmd_gen(dbdma_cmd_ptr, unsigned short, unsigned short, + unsigned int, unsigned int); static int init_planb(struct planb *); static int find_planb(void); static void planb_pre_capture(int, int, struct planb *); -static volatile struct dbdma_cmd *cmd_geo_setup(volatile struct dbdma_cmd *, - int, int, int, int, int, struct planb *); -static inline void planb_dbdma_stop(volatile struct dbdma_regs *); +static dbdma_cmd_ptr cmd_geo_setup(dbdma_cmd_ptr, int, int, int, int, int, + struct planb *); +static inline void planb_dbdma_stop(dbdma_regs_ptr); +static inline void planb_dbdma_restart(dbdma_regs_ptr); static unsigned int saa_geo_setup(int, int, int, int, struct planb *); static inline int overlay_is_active(struct planb *); @@ -119,6 +143,18 @@ /* Memory management functions */ /*******************************/ +/* I know this is not the right way to allocate memory. Whoever knows + the right way to allocate a huge buffer for DMA that can be mapped + to user space, please tell me... or better, modify the code. + + Michel Lanners (mlan@cpu.lu) */ + +/* FIXME: As subsequent calls to __get_free_pages don't necessarily return + contiguous pages, we need to do horrible things later on when setting + up DMA, to make sure a single DMA transfer doesn't cross a page boundary. + At least, I hope it's done right later on ;-) ...... + Anyway, there should be a way to get hold of a large buffer of contiguous + pages for DMA.... */ static int grabbuf_alloc(struct planb *pb) { int i, npage; @@ -139,7 +175,7 @@ mem_map_reserve(virt_to_page(pb->rawbuf[i])); } if (i-- < npage) { - printk(KERN_DEBUG "PlanB: init_grab: grab buffer not allocated\n"); + DBG("PlanB: init_grab: grab buffer not allocated\n"); for (; i > 0; i--) { mem_map_unreserve(virt_to_page(pb->rawbuf[i])); free_pages((unsigned long)pb->rawbuf[i], 0); @@ -209,6 +245,7 @@ saa_regs[norm][SAA7196_FMTS] &= ~0x3; break; case 1: + /* FIXME: shouldn't we set monochrome mode here? */ case 4: /* RGB888 1x24-bit + 8-bit transparent */ saa_regs[norm][SAA7196_FMTS] &= ~0x1; @@ -238,57 +275,61 @@ /* DBDMA support functions */ /***************************/ -static inline void planb_dbdma_restart(volatile struct dbdma_regs *ch) +static inline void planb_dbdma_restart(dbdma_regs_ptr ch) { - out_le32(&ch->control, PLANB_CLR(RUN)); - out_le32(&ch->control, PLANB_SET(RUN|WAKE) | PLANB_CLR(PAUSE)); + writel(PLANB_CLR(RUN), &ch->control); + writel(PLANB_SET(RUN|WAKE) | PLANB_CLR(PAUSE), &ch->control); } -static inline void planb_dbdma_stop(volatile struct dbdma_regs *ch) +static inline void planb_dbdma_stop(dbdma_regs_ptr ch) { int i = 0; - out_le32(&ch->control, PLANB_CLR(RUN) | PLANB_SET(FLUSH)); - while((in_le32(&ch->status) == (ACTIVE | FLUSH)) && (i < 999)) { - IDEBUG("PlanB: waiting for DMA to stop\n"); + writel(PLANB_CLR(RUN) | PLANB_SET(FLUSH), &ch->control); + while((readl(&ch->status) == (ACTIVE | FLUSH)) && (i < 999)) { + IDBG("PlanB: waiting for DMA to stop\n"); i++; } } -static inline void tab_cmd_dbdma(volatile struct dbdma_cmd *ch, - unsigned short command, unsigned int cmd_dep) +static inline void tab_cmd_dbdma(dbdma_cmd_ptr ch, unsigned short command, + unsigned int cmd_dep) { st_le16(&ch->command, command); + st_le16(&ch->req_count, 0); + st_le32(&ch->phy_addr, 0); st_le32(&ch->cmd_dep, cmd_dep); + /* really clears res_count & xfer_status */ + st_le32((unsigned int *)&ch->res_count, 0); } -static inline void tab_cmd_store(volatile struct dbdma_cmd *ch, - unsigned int phy_addr, unsigned int cmd_dep) +static inline void tab_cmd_store(dbdma_cmd_ptr ch, unsigned int phy_addr, + unsigned int cmd_dep) { st_le16(&ch->command, STORE_WORD | KEY_SYSTEM); st_le16(&ch->req_count, 4); st_le32(&ch->phy_addr, phy_addr); st_le32(&ch->cmd_dep, cmd_dep); + st_le32((unsigned int *)&ch->res_count, 0); } -static inline void tab_cmd_gen(volatile struct dbdma_cmd *ch, - unsigned short command, unsigned short req_count, - unsigned int phy_addr, unsigned int cmd_dep) +static inline void tab_cmd_gen(dbdma_cmd_ptr ch, unsigned short command, + unsigned short req_count, unsigned int phy_addr, unsigned int cmd_dep) { st_le16(&ch->command, command); st_le16(&ch->req_count, req_count); st_le32(&ch->phy_addr, phy_addr); st_le32(&ch->cmd_dep, cmd_dep); + st_le32((unsigned int *)&ch->res_count, 0); } -static volatile struct dbdma_cmd *cmd_geo_setup( - volatile struct dbdma_cmd *c1, int width, int height, int interlace, - int bpp, int clip, struct planb *pb) +static dbdma_cmd_ptr cmd_geo_setup(dbdma_cmd_ptr c1, int width, int height, + int interlace, int bpp, int clip, struct planb *pb) { int norm = pb->win.norm; if((saa_geo_setup(width, height, interlace, bpp, pb)) != 0) - return (volatile struct dbdma_cmd *)NULL; + return (dbdma_cmd_ptr)NULL; tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr), SAA7196_FMTS); tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval), @@ -336,19 +377,19 @@ goto repeat; } remove_wait_queue(&pb->lockq, &wait); - current->state = TASK_RUNNING; + set_current_state(TASK_RUNNING); } static inline void planb_wait(struct planb *pb) { - DEBUG("PlanB: planb_wait\n"); + DBG("PlanB: planb_wait\n"); if(pb->lock) __planb_wait(pb); } static inline void planb_lock(struct planb *pb) { - DEBUG("PlanB: planb_lock\n"); + DBG("PlanB: planb_lock\n"); if(pb->lock) __planb_wait(pb); pb->lock = 1; @@ -356,7 +397,7 @@ static inline void planb_unlock(struct planb *pb) { - DEBUG("PlanB: planb_unlock\n"); + DBG("PlanB: planb_unlock\n"); pb->lock = 0; wake_up(&pb->lockq); } @@ -365,25 +406,88 @@ /* Driver Core */ /***************/ +/* Working here !! */ +#define NUMJUMPS 6 static int planb_prepare_open(struct planb *pb) { + dbdma_cmd_ptr c; + int size, i; + + size = (NUMJUMPS + 1) * sizeof(struct dbdma_cmd); + + if((pb->jump_raw = kmalloc (size, GFP_KERNEL|GFP_DMA)) == 0) + return -ENOMEM; + memset(pb->jump_raw, 0, size); + c = pb->jumpbuf = (dbdma_cmd_ptr) DBDMA_ALIGN (pb->jump_raw); + + /* circular DBDMA command buffer, to hold jumps to transfer commands */ + tab_cmd_dbdma(c++, DBDMA_STOP, 0); + for (i=1; ijumpbuf); + + DBG("PlanB: planb_prepare_open, jumpbuffer at 0x%08x, length %d.\n", + (unsigned int)pb->jumpbuf, size); + return 0; +} + +#define VBIDUMMY 40 /* must be even !! */ +static int planb_prepare_vbi(struct planb *pb) +{ + int size; + + /* allocate VBI comand buffer memory + (2 fields * VBI_MAXLINES + 40 handling + alignment) */ + size = (2*VBI_MAXLINES + VBIDUMMY + 1) * sizeof(struct dbdma_cmd); + + if ((pb->vbi_raw = kmalloc (size, GFP_KERNEL|GFP_DMA)) == 0) + return -ENOMEM; + memset (pb->vbi_raw, 0, size); + size = (VBI_MAXLINES + VBIDUMMY/2) * sizeof(struct dbdma_cmd); + pb->vbi_cbo.start = (dbdma_cmd_ptr) DBDMA_ALIGN (pb->vbi_raw); + pb->vbi_cbo.size = pb->vbi_cbe.size = size; + pb->vbi_cbe.start = pb->vbi_cbo.start + pb->vbi_cbo.size; + pb->vbi_cbo.jumpaddr = pb->jumpbuf + 1; + pb->vbi_cbe.jumpaddr = pb->jumpbuf + 2; + + DBG("PlanB: planb_prepare_vbi, dbdma cmd_buf at 0x%08x, length %d.\n", + (unsigned int)pb->vbi_cbo.start, 2*size); + return 0; +} + +static int planb_prepare_video(struct planb *pb) +{ int i, size; + /* FIXME: This is stressing kmalloc to its limits... + We really should allocate smaller chunks. */ + /* allocate memory for two plus alpha command buffers (size: max lines, plus 40 commands handling, plus 1 alignment), plus dummy command buf, plus clipmask buffer, plus frame grabbing status */ - size = (pb->tab_size*(2+MAX_GBUFFERS*TAB_FACTOR)+1+MAX_GBUFFERS - * PLANB_DUMMY)*sizeof(struct dbdma_cmd) - +(PLANB_MAXLINES*((PLANB_MAXPIXELS+7)& ~7))/8 - +MAX_GBUFFERS*sizeof(unsigned int); - if ((pb->priv_space = kmalloc (size, GFP_KERNEL)) == 0) + size = (pb->tab_size * (2 + MAX_GBUFFERS * TAB_FACTOR) + + MAX_GBUFFERS * PLANB_DUMMY + 1) * sizeof(struct dbdma_cmd) + + (PLANB_MAXLINES * ((PLANB_MAXPIXELS + 7) & ~7)) / 8 + + MAX_GBUFFERS * sizeof(unsigned int); + if ((pb->vid_raw = kmalloc (size, GFP_KERNEL|GFP_DMA)) == 0) return -ENOMEM; - memset ((void *) pb->priv_space, 0, size); - pb->overlay_last1 = pb->ch1_cmd = (volatile struct dbdma_cmd *) - DBDMA_ALIGN (pb->priv_space); - pb->overlay_last2 = pb->ch2_cmd = pb->ch1_cmd + pb->tab_size; - pb->ch1_cmd_phys = virt_to_bus(pb->ch1_cmd); - pb->cap_cmd[0] = pb->ch2_cmd + pb->tab_size; + memset (pb->vid_raw, 0, size); + pb->vid_cbo.start = (dbdma_cmd_ptr) DBDMA_ALIGN (pb->vid_raw); + pb->vid_cbo.size = pb->vid_cbe.size = pb->tab_size/2; + pb->vid_cbe.start = pb->vid_cbo.start + pb->vid_cbo.size; + pb->vid_cbo.jumpaddr = pb->jumpbuf + 3; + pb->vid_cbe.jumpaddr = pb->jumpbuf + 4; + pb->overlay_last1 = pb->vid_cbo.start; + pb->vid_cbo.bus = virt_to_bus(pb->vid_cbo.start); + pb->vid_cbe.bus = virt_to_bus(pb->vid_cbe.start); + pb->clip_cbo.start = pb->vid_cbe.start + pb->vid_cbe.size; + pb->clip_cbo.size = pb->clip_cbe.size = pb->tab_size/2; + pb->clip_cbe.start = pb->clip_cbo.start + pb->clip_cbo.size; + pb->overlay_last2 = pb->clip_cbo.start; + pb->clip_cbo.bus = virt_to_bus(pb->clip_cbo.start); + pb->clip_cbe.bus = virt_to_bus(pb->clip_cbe.start); + pb->cap_cmd[0] = pb->clip_cbe.start + pb->clip_cbe.size; pb->pre_cmd[0] = pb->cap_cmd[0] + pb->tab_size * TAB_FACTOR; for (i = 1; i < MAX_GBUFFERS; i++) { pb->cap_cmd[i] = pb->pre_cmd[i-1] + PLANB_DUMMY; @@ -416,20 +520,61 @@ planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); + DBG("PlanB: planb_prepare_video, dbdma cmd_buf at 0x%08x, " + "length %d.\n", (unsigned int)pb->vid_cbo.start, 2*size); return 0; } static void planb_prepare_close(struct planb *pb) { - int i; - /* make sure the dma's are idle */ planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); - /* free kernel memory of command buffers */ - if(pb->priv_space != 0) { - kfree (pb->priv_space); - pb->priv_space = 0; + + if(pb->jump_raw != 0) { + kfree(pb->jump_raw); + pb->jump_raw = 0; + } + return; +} + +static void planb_close_vbi(struct planb *pb) +{ + /* FIXME: stop running DMA */ + + /* Make sure the DMA controller doesn't jump here anymore */ + tab_cmd_dbdma(pb->vbi_cbo.jumpaddr, DBDMA_NOP, 0); + tab_cmd_dbdma(pb->vbi_cbe.jumpaddr, DBDMA_NOP, 0); + + if(pb->vbi_raw != 0) { + kfree (pb->vbi_raw); + pb->vbi_raw = 0; + } + + /* FIXME: deallocate VBI data buffer */ + + /* FIXME: restart running DMA if app. */ + return; +} + +static void planb_close_video(struct planb *pb) +{ + int i; + + /* FIXME: stop running DMA */ + + /* Make sure the DMA controller doesn't jump here anymore */ + tab_cmd_dbdma(pb->vid_cbo.jumpaddr, DBDMA_NOP, 0); + tab_cmd_dbdma(pb->vid_cbe.jumpaddr, DBDMA_NOP, 0); +/* No clipmask jumpbuffer yet */ +#if 0 + tab_cmd_dbdma(pb->clip_cbo.jumpaddr, DBDMA_NOP, 0); + tab_cmd_dbdma(pb->clip_cbe.jumpaddr, DBDMA_NOP, 0); +#endif + + if(pb->vid_raw != 0) { + kfree (pb->vid_raw); + pb->vid_raw = 0; pb->cmd_buff_inited = 0; } if(pb->rawbuf) { @@ -440,6 +585,9 @@ kfree(pb->rawbuf); } pb->rawbuf = NULL; + + /* FIXME: restart running DMA if app. */ + return; } /*****************************/ @@ -448,43 +596,37 @@ static void overlay_start(struct planb *pb) { + DBG("PlanB: overlay_start()\n"); - DEBUG("PlanB: overlay_start()\n"); + if(ACTIVE & readl(&pb->planb_base->ch1.status)) { - if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) { - - DEBUG("PlanB: presumably, grabbing is in progress...\n"); + DBG("PlanB: presumably, grabbing is in progress...\n"); planb_dbdma_stop(&pb->planb_base->ch2); - out_le32 (&pb->planb_base->ch2.cmdptr, - virt_to_bus(pb->ch2_cmd)); + writel(pb->clip_cbo.bus, &pb->planb_base->ch2.cmdptr); planb_dbdma_restart(&pb->planb_base->ch2); - st_le16 (&pb->ch1_cmd->command, DBDMA_NOP); + st_le16 (&pb->vid_cbo.start->command, DBDMA_NOP); tab_cmd_dbdma(pb->last_cmd[pb->last_fr], - DBDMA_NOP | BR_ALWAYS, - virt_to_bus(pb->ch1_cmd)); + DBDMA_NOP | BR_ALWAYS, pb->vid_cbo.bus); eieio(); pb->prev_last_fr = pb->last_fr; pb->last_fr = -2; - if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) { - IDEBUG("PlanB: became inactive " + if(!(ACTIVE & readl(&pb->planb_base->ch1.status))) { + IDBG("PlanB: became inactive " "in the mean time... reactivating\n"); planb_dbdma_stop(&pb->planb_base->ch1); - out_le32 (&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->ch1_cmd)); + writel(pb->vid_cbo.bus, &pb->planb_base->ch1.cmdptr); planb_dbdma_restart(&pb->planb_base->ch1); } } else { - DEBUG("PlanB: currently idle, so can do whatever\n"); + DBG("PlanB: currently idle, so can do whatever\n"); planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); - st_le32 (&pb->planb_base->ch2.cmdptr, - virt_to_bus(pb->ch2_cmd)); - st_le32 (&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->ch1_cmd)); - out_le16 (&pb->ch1_cmd->command, DBDMA_NOP); + st_le32(&pb->planb_base->ch2.cmdptr, pb->clip_cbo.bus); + st_le32(&pb->planb_base->ch1.cmdptr, pb->vid_cbo.bus); + writew(DBDMA_NOP, &pb->vid_cbo.start->command); planb_dbdma_restart(&pb->planb_base->ch2); planb_dbdma_restart(&pb->planb_base->ch1); pb->last_fr = -1; @@ -494,11 +636,11 @@ static void overlay_stop(struct planb *pb) { - DEBUG("PlanB: overlay_stop()\n"); + DBG("PlanB: overlay_stop()\n"); if(pb->last_fr == -1) { - DEBUG("PlanB: no grabbing, it seems...\n"); + DBG("PlanB: no grabbing, it seems...\n"); planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); @@ -507,16 +649,16 @@ unsigned int cmd_dep; tab_cmd_dbdma(pb->cap_cmd[pb->prev_last_fr], DBDMA_STOP, 0); eieio(); - cmd_dep = (unsigned int)in_le32(&pb->overlay_last1->cmd_dep); + cmd_dep = (unsigned int)readl(&pb->overlay_last1->cmd_dep); if(overlay_is_active(pb)) { - DEBUG("PlanB: overlay is currently active\n"); + DBG("PlanB: overlay is currently active\n"); planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); - if(cmd_dep != pb->ch1_cmd_phys) { - out_le32(&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->overlay_last1)); + if(cmd_dep != pb->vid_cbo.bus) { + writel(virt_to_bus(pb->overlay_last1), + &pb->planb_base->ch1.cmdptr); planb_dbdma_restart(&pb->planb_base->ch1); } } @@ -531,11 +673,11 @@ int fr = -1; struct dbdma_cmd last; - DEBUG("PlanB: suspend_overlay: %d\n", pb->suspend); + DBG("PlanB: suspend_overlay: %d\n", pb->suspend); if(pb->suspend++) return; - if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) { + if(ACTIVE & readl(&pb->planb_base->ch1.status)) { if(pb->last_fr == -2) { fr = pb->prev_last_fr; memcpy(&last, (void*)pb->last_cmd[fr], sizeof(last)); @@ -559,38 +701,38 @@ static void resume_overlay(struct planb *pb) { - DEBUG("PlanB: resume_overlay: %d\n", pb->suspend); + DBG("PlanB: resume_overlay: %d\n", pb->suspend); if(pb->suspend > 1) return; if(pb->suspended.frame != -1) { memcpy((void*)pb->last_cmd[pb->suspended.frame], - &pb->suspended.cmd, sizeof(pb->suspended.cmd)); + &pb->suspended.cmd, sizeof(pb->suspended.cmd)); } - if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) { + if(ACTIVE & readl(&pb->planb_base->ch1.status)) { goto finish; } if(pb->suspended.overlay) { - DEBUG("PlanB: overlay being resumed\n"); + DBG("PlanB: overlay being resumed\n"); - st_le16 (&pb->ch1_cmd->command, DBDMA_NOP); - st_le16 (&pb->ch2_cmd->command, DBDMA_NOP); + st_le16 (&pb->vid_cbo.start->command, DBDMA_NOP); + st_le16 (&pb->clip_cbo.start->command, DBDMA_NOP); /* Set command buffer addresses */ - st_le32(&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->overlay_last1)); - out_le32(&pb->planb_base->ch2.cmdptr, - virt_to_bus(pb->overlay_last2)); + writel(virt_to_bus(pb->overlay_last1), + &pb->planb_base->ch1.cmdptr); + writel(virt_to_bus(pb->overlay_last2), + &pb->planb_base->ch2.cmdptr); /* Start the DMA controller */ - out_le32 (&pb->planb_base->ch2.control, - PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE)); - out_le32 (&pb->planb_base->ch1.control, - PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE)); + writel(PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE), + &pb->planb_base->ch2.control); + writel(PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE), + &pb->planb_base->ch1.control); } else if(pb->suspended.frame != -1) { - out_le32(&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->last_cmd[pb->suspended.frame])); - out_le32 (&pb->planb_base->ch1.control, - PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE)); + writel(virt_to_bus(pb->last_cmd[pb->suspended.frame]), + &pb->planb_base->ch1.cmdptr); + writel(PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE), + &pb->planb_base->ch1.control); } finish: @@ -606,7 +748,7 @@ int ww = pb->win.width, hw = pb->win.height; int x, y, xtmp1, xtmp2; - DEBUG("PlanB: clip %dx%d+%d+%d\n", wc, hc, xc, yc); + DBG("PlanB: clip %dx%d+%d+%d\n", wc, hc, xc, yc); if(xc < 0) { wc += xc; @@ -643,26 +785,26 @@ static void fill_cmd_buff(struct planb *pb) { - int restore = 0; - volatile struct dbdma_cmd last; + int restore = 0; + dbdma_cmd_t last; - DEBUG("PlanB: fill_cmd_buff()\n"); + DBG("PlanB: fill_cmd_buff()\n"); - if(pb->overlay_last1 != pb->ch1_cmd) { + if(pb->overlay_last1 != pb->vid_cbo.start) { restore = 1; last = *(pb->overlay_last1); } - memset ((void *) pb->ch1_cmd, 0, 2 * pb->tab_size + memset ((void *) pb->vid_cbo.start, 0, 2 * pb->tab_size * sizeof(struct dbdma_cmd)); cmd_buff (pb); if(restore) *(pb->overlay_last1) = last; if(pb->suspended.overlay) { - unsigned long jump_addr = in_le32(&pb->overlay_last1->cmd_dep); - if(jump_addr != pb->ch1_cmd_phys) { + unsigned long jump_addr = readl(&pb->overlay_last1->cmd_dep); + if(jump_addr != pb->vid_cbo.bus) { int i; - DEBUG("PlanB: adjusting ch1's jump address\n"); + DBG("PlanB: adjusting ch1's jump address\n"); for(i = 0; i < MAX_GBUFFERS; i++) { if(pb->need_pre_capture[i]) { @@ -674,16 +816,16 @@ } } - DEBUG("PlanB: not found...\n"); + DBG("PlanB: not found...\n"); goto out; found: if(pb->need_pre_capture[i]) - out_le32(&pb->pre_cmd[i]->phy_addr, - virt_to_bus(pb->overlay_last1)); + writel(virt_to_bus(pb->overlay_last1), + &pb->pre_cmd[i]->phy_addr); else - out_le32(&pb->cap_cmd[i]->phy_addr, - virt_to_bus(pb->overlay_last1)); + writel(virt_to_bus(pb->overlay_last1), + &pb->cap_cmd[i]->phy_addr); } } out: @@ -696,8 +838,8 @@ { int i, bpp, count, nlines, stepsize, interlace; unsigned long base, jump, addr_com, addr_dep; - volatile struct dbdma_cmd *c1 = pb->ch1_cmd; - volatile struct dbdma_cmd *c2 = pb->ch2_cmd; + dbdma_cmd_ptr c1 = pb->vid_cbo.start; + dbdma_cmd_ptr c2 = pb->clip_cbo.start; interlace = pb->win.interlace; bpp = pb->win.bpp; @@ -716,8 +858,8 @@ if((c1 = cmd_geo_setup(c1, pb->win.width, pb->win.height, interlace, bpp, 1, pb)) == NULL) { printk(KERN_WARNING "PlanB: encountered serious problems\n"); - tab_cmd_dbdma(pb->ch1_cmd + 1, DBDMA_STOP, 0); - tab_cmd_dbdma(pb->ch2_cmd + 1, DBDMA_STOP, 0); + tab_cmd_dbdma(pb->vid_cbo.start + 1, DBDMA_STOP, 0); + tab_cmd_dbdma(pb->clip_cbo.start + 1, DBDMA_STOP, 0); return; } tab_cmd_store(c1++, addr_com, (unsigned)(DBDMA_NOP | BR_ALWAYS) << 16); @@ -738,8 +880,8 @@ tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel), PLANB_SET(DMA_ABORT)); - base = (pb->frame_buffer_phys + pb->offset + pb->win.y * (pb->win.bpl - + pb->win.pad) + pb->win.x * bpp); + base = (pb->fb.phys + pb->fb.offset + pb->win.y * (pb->win.bpl + + pb->win.pad) + pb->win.x * bpp); if (interlace) { stepsize = 2; @@ -782,7 +924,7 @@ /* And jump back to the start */ cmd_tab_data_end: pb->overlay_last1 = c1; /* keep a pointer to the last command */ - tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, virt_to_bus(pb->ch1_cmd)); + tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, pb->vid_cbo.bus); /* Clipmask command buffer */ @@ -847,7 +989,7 @@ PLANB_SET(RUN)); pb->overlay_last2 = c2; /* keep a pointer to the last command */ /* start over even field clipmasking */ - tab_cmd_dbdma(c2, DBDMA_NOP | BR_ALWAYS, virt_to_bus(pb->ch2_cmd)); + tab_cmd_dbdma(c2, DBDMA_NOP | BR_ALWAYS, pb->clip_cbo.bus); eieio(); return; @@ -880,11 +1022,11 @@ static inline int overlay_is_active(struct planb *pb) { unsigned int size = pb->tab_size * sizeof(struct dbdma_cmd); - unsigned int caddr = (unsigned)in_le32(&pb->planb_base->ch1.cmdptr); + unsigned int caddr = (unsigned)readl(&pb->planb_base->ch1.cmdptr); - return (in_le32(&pb->overlay_last1->cmd_dep) == pb->ch1_cmd_phys) - && (caddr < (pb->ch1_cmd_phys + size)) - && (caddr >= (unsigned)pb->ch1_cmd_phys); + return (readl(&pb->overlay_last1->cmd_dep) == pb->vid_cbo.bus) + && (caddr < (pb->vid_cbo.bus + size)) + && (caddr >= (unsigned)pb->vid_cbo.bus); } static int vgrab(struct planb *pb, struct video_mmap *mp) @@ -898,7 +1040,7 @@ return err; } - IDEBUG("PlanB: grab %d: %dx%d(%u)\n", pb->grabbing, + IDBG("PlanB: grab %d: %dx%d(%u)\n", pb->grabbing, mp->width, mp->height, fr); if(pb->grabbing >= MAX_GBUFFERS) @@ -924,7 +1066,7 @@ unsigned int nsize = mp->width * mp->height * format; #endif - IDEBUG("PlanB: gwidth = %d, gheight = %d, mp->format = %u\n", + IDBG("PlanB: gwidth = %d, gheight = %d, mp->format = %u\n", mp->width, mp->height, mp->format); #ifndef PLANB_GSCANLINE @@ -964,74 +1106,73 @@ } else pb->need_pre_capture[fr] = 0; pb->frame_stat[fr] = GBUFFER_GRABBING; - if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) { + if(!(ACTIVE & readl(&pb->planb_base->ch1.status))) { - IDEBUG("PlanB: ch1 inactive, initiating grabbing\n"); + IDBG("PlanB: ch1 inactive, initiating grabbing\n"); planb_dbdma_stop(&pb->planb_base->ch1); if(pb->need_pre_capture[fr]) { - IDEBUG("PlanB: padding pre-capture sequence\n"); + IDBG("PlanB: padding pre-capture sequence\n"); - out_le32 (&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->pre_cmd[fr])); + writel(virt_to_bus(pb->pre_cmd[fr]), + &pb->planb_base->ch1.cmdptr); } else { tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_STOP, 0); tab_cmd_dbdma(pb->cap_cmd[fr], DBDMA_NOP, 0); /* let's be on the safe side. here is not timing critical. */ tab_cmd_dbdma((pb->cap_cmd[fr] + 1), DBDMA_NOP, 0); - out_le32 (&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->cap_cmd[fr])); + writel(virt_to_bus(pb->cap_cmd[fr]), + &pb->planb_base->ch1.cmdptr); } planb_dbdma_restart(&pb->planb_base->ch1); pb->last_fr = fr; } else { int i; - IDEBUG("PlanB: ch1 active, grabbing being queued\n"); + IDBG("PlanB: ch1 active, grabbing being queued\n"); if((pb->last_fr == -1) || ((pb->last_fr == -2) && overlay_is_active(pb))) { - IDEBUG("PlanB: overlay is active, grabbing defered\n"); + IDBG("PlanB: overlay is active, grabbing defered\n"); - tab_cmd_dbdma(pb->last_cmd[fr], - DBDMA_NOP | BR_ALWAYS, - virt_to_bus(pb->ch1_cmd)); + tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_NOP | BR_ALWAYS, + pb->vid_cbo.bus); if(pb->need_pre_capture[fr]) { - IDEBUG("PlanB: padding pre-capture sequence\n"); + IDBG("PlanB: padding pre-capture sequence\n"); tab_cmd_store(pb->pre_cmd[fr], virt_to_bus(&pb->overlay_last1->cmd_dep), - virt_to_bus(pb->ch1_cmd)); + pb->vid_cbo.bus); eieio(); - out_le32 (&pb->overlay_last1->cmd_dep, - virt_to_bus(pb->pre_cmd[fr])); + writel(virt_to_bus(pb->pre_cmd[fr]), + &pb->overlay_last1->cmd_dep); } else { tab_cmd_store(pb->cap_cmd[fr], virt_to_bus(&pb->overlay_last1->cmd_dep), - virt_to_bus(pb->ch1_cmd)); + pb->vid_cbo.bus); tab_cmd_dbdma((pb->cap_cmd[fr] + 1), DBDMA_NOP, 0); eieio(); - out_le32 (&pb->overlay_last1->cmd_dep, - virt_to_bus(pb->cap_cmd[fr])); + writel(virt_to_bus(pb->cap_cmd[fr]), + &pb->overlay_last1->cmd_dep); } for(i = 0; overlay_is_active(pb) && i < 999; i++) - IDEBUG("PlanB: waiting for overlay done\n"); - tab_cmd_dbdma(pb->ch1_cmd, DBDMA_NOP, 0); + IDBG("PlanB: waiting for overlay done\n"); + tab_cmd_dbdma(pb->vid_cbo.start, DBDMA_NOP, 0); pb->prev_last_fr = fr; pb->last_fr = -2; } else if(pb->last_fr == -2) { - IDEBUG("PlanB: mixed mode detected, grabbing" + IDBG("PlanB: mixed mode detected, grabbing" " will be done before activating overlay\n"); - tab_cmd_dbdma(pb->ch1_cmd, DBDMA_NOP, 0); + tab_cmd_dbdma(pb->vid_cbo.start, DBDMA_NOP, 0); if(pb->need_pre_capture[fr]) { - IDEBUG("PlanB: padding pre-capture sequence\n"); + IDBG("PlanB: padding pre-capture sequence\n"); tab_cmd_dbdma(pb->last_cmd[pb->prev_last_fr], DBDMA_NOP | BR_ALWAYS, @@ -1056,19 +1197,18 @@ virt_to_bus(pb->cap_cmd[fr])); eieio(); } - tab_cmd_dbdma(pb->last_cmd[fr], - DBDMA_NOP | BR_ALWAYS, - virt_to_bus(pb->ch1_cmd)); + tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_NOP | BR_ALWAYS, + pb->vid_cbo.bus); eieio(); pb->prev_last_fr = fr; pb->last_fr = -2; } else { - IDEBUG("PlanB: active grabbing session detected\n"); + IDBG("PlanB: active grabbing session detected\n"); if(pb->need_pre_capture[fr]) { - IDEBUG("PlanB: padding pre-capture sequence\n"); + IDBG("PlanB: padding pre-capture sequence\n"); tab_cmd_dbdma(pb->last_cmd[pb->last_fr], DBDMA_NOP | BR_ALWAYS, @@ -1095,14 +1235,14 @@ } pb->last_fr = fr; } - if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) { + if(!(ACTIVE & readl(&pb->planb_base->ch1.status))) { - IDEBUG("PlanB: became inactive in the mean time..." + IDBG("PlanB: became inactive in the mean time... " "reactivating\n"); planb_dbdma_stop(&pb->planb_base->ch1); - out_le32 (&pb->planb_base->ch1.cmdptr, - virt_to_bus(pb->cap_cmd[fr])); + writel(virt_to_bus(pb->cap_cmd[fr]), + &pb->planb_base->ch1.cmdptr); planb_dbdma_restart(&pb->planb_base->ch1); } } @@ -1114,8 +1254,8 @@ static void planb_pre_capture(int fr, int bpp, struct planb *pb) { - volatile struct dbdma_cmd *c1 = pb->pre_cmd[fr]; - int interlace = (pb->gheight[fr] > pb->maxlines/2)? 1: 0; + dbdma_cmd_ptr c1 = pb->pre_cmd[fr]; + int interlace = (pb->gheight[fr] > pb->maxlines/2)? 1: 0; tab_cmd_dbdma(c1++, DBDMA_NOP, 0); if((c1 = cmd_geo_setup(c1, pb->gwidth[fr], pb->gheight[fr], interlace, @@ -1152,7 +1292,7 @@ eieio(); } -static volatile struct dbdma_cmd *setup_grab_cmd(int fr, struct planb *pb) +static dbdma_cmd_ptr setup_grab_cmd(int fr, struct planb *pb) { int i, bpp, count, nlines, stepsize, interlace; #ifdef PLANB_GSCANLINE @@ -1163,8 +1303,8 @@ #endif unsigned long jump; int pagei; - volatile struct dbdma_cmd *c1; - volatile struct dbdma_cmd *jump_addr; + dbdma_cmd_ptr c1; + dbdma_cmd_ptr jump_addr; c1 = pb->cap_cmd[fr]; interlace = (pb->gheight[fr] > pb->maxlines/2)? 1: 0; @@ -1344,29 +1484,29 @@ unsigned int stat, astat; struct planb *pb = (struct planb *)dev_id; - IDEBUG("PlanB: planb_irq()\n"); + IDBG("PlanB: planb_irq()\n"); /* get/clear interrupt status bits */ eieio(); - stat = in_le32(&pb->planb_base->intr_stat); + stat = readl(&pb->planb_base->intr_stat); astat = stat & pb->intr_mask; - out_le32(&pb->planb_base->intr_stat, PLANB_FRM_IRQ - & ~astat & stat & ~PLANB_GEN_IRQ); - IDEBUG("PlanB: stat = %X, astat = %X\n", stat, astat); + writel(PLANB_FRM_IRQ & ~astat & stat & ~PLANB_GEN_IRQ, + &pb->planb_base->intr_stat); + IDBG("PlanB: stat = %X, astat = %X\n", stat, astat); if(astat & PLANB_FRM_IRQ) { unsigned int fr = stat >> 9; #ifndef PLANB_GSCANLINE int i; #endif - IDEBUG("PlanB: PLANB_FRM_IRQ\n"); + IDBG("PlanB: PLANB_FRM_IRQ\n"); pb->gcount++; - IDEBUG("PlanB: grab %d: fr = %d, gcount = %d\n", + IDBG("PlanB: grab %d: fr = %d, gcount = %d\n", pb->grabbing, fr, pb->gcount); #ifndef PLANB_GSCANLINE - IDEBUG("PlanB: %d * %d bytes are being copied over\n", + IDBG("PlanB: %d * %d bytes are being copied over\n", pb->lnum[fr], pb->lsize[fr]); for(i = 0; i < pb->lnum[fr]; i++) { int first = pb->lsize[fr] - pb->l_to_next_size[fr][i]; @@ -1386,8 +1526,8 @@ } /* incorrect interrupts? */ pb->intr_mask = PLANB_CLR_IRQ; - out_le32(&pb->planb_base->intr_stat, PLANB_CLR_IRQ); - printk(KERN_ERR "PlanB: IRQ lockup, cleared intrrupts" + writel(PLANB_CLR_IRQ, &pb->planb_base->intr_stat); + printk(KERN_ERR "PlanB: IRQ lockup, cleared interrupts" " unconditionally\n"); } @@ -1397,16 +1537,22 @@ static int planb_open(struct video_device *dev, int mode) { - struct planb *pb = (struct planb *)dev; + struct planb *pb = (struct planb *)dev->priv; + int err; - if (pb->user == 0) { - int err; + /* first open on driver? */ + if(pb->vid_user + pb->vbi_user == 0) { if((err = planb_prepare_open(pb)) != 0) return err; } - pb->user++; + /* first open on video dev? */ + if(pb->vid_user == 0) { + if((err = planb_prepare_video(pb)) != 0) + return err; + } + pb->vid_user++; - DEBUG("PlanB: device opened\n"); + DBG("PlanB: device opened\n"); MOD_INC_USE_COUNT; return 0; @@ -1414,44 +1560,46 @@ static void planb_close(struct video_device *dev) { - struct planb *pb = (struct planb *)dev; + struct planb *pb = (struct planb *)dev->priv; - if(pb->user < 1) /* ??? */ - return; planb_lock(pb); - if (pb->user == 1) { - if (pb->overlay) { + /* last close? then stop everything... */ + if(--pb->vid_user == 0) { + if(pb->overlay) { planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); pb->overlay = 0; } - planb_prepare_close(pb); + planb_close_video(pb); } - pb->user--; + /* last open on PlanB hardware? */ + if(pb->vid_user + pb->vbi_user == 0) + planb_prepare_close(pb); planb_unlock(pb); - DEBUG("PlanB: device closed\n"); + DBG("PlanB: device closed\n"); - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; + return; } static long planb_read(struct video_device *v, char *buf, unsigned long count, int nonblock) { - DEBUG("planb: read request\n"); + DBG("planb: read request\n"); return -EINVAL; } static long planb_write(struct video_device *v, const char *buf, unsigned long count, int nonblock) { - DEBUG("planb: write request\n"); + DBG("planb: write request\n"); return -EINVAL; } static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg) { - struct planb *pb=(struct planb *)dev; + struct planb *pb=(struct planb *)dev->priv; switch (cmd) { @@ -1459,7 +1607,7 @@ { struct video_capability b; - DEBUG("PlanB: IOCTL VIDIOCGCAP\n"); + DBG("PlanB: IOCTL VIDIOCGCAP\n"); strcpy (b.name, pb->video_dev.name); b.type = VID_TYPE_OVERLAY | VID_TYPE_CLIPPING | @@ -1481,12 +1629,11 @@ unsigned short bpp; unsigned int fmt; - DEBUG("PlanB: IOCTL VIDIOCSFBUF\n"); + DBG("PlanB: IOCTL VIDIOCSFBUF\n"); - if (!capable(CAP_SYS_ADMIN) - || !capable(CAP_SYS_RAWIO)) + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) return -EPERM; - if (copy_from_user(&v, arg,sizeof(v))) + if (copy_from_user(&v, arg, sizeof(v))) return -EFAULT; planb_lock(pb); switch(v.depth) { @@ -1514,14 +1661,14 @@ } pb->win.bpp = bpp; pb->win.color_fmt = fmt; - pb->frame_buffer_phys = (unsigned long) v.base; + pb->fb.phys = (unsigned long) v.base; pb->win.sheight = v.height; pb->win.swidth = v.width; pb->picture.depth = pb->win.depth = v.depth; pb->win.bpl = pb->win.bpp * pb->win.swidth; pb->win.pad = v.bytesperline - pb->win.bpl; - DEBUG("PlanB: Display at %p is %d by %d, bytedepth %d," + DBG("PlanB: Display at %p is %d by %d, bytedepth %d," " bpl %d (+ %d)\n", v.base, v.width,v.height, pb->win.bpp, pb->win.bpl, pb->win.pad); @@ -1538,9 +1685,9 @@ { struct video_buffer v; - DEBUG("PlanB: IOCTL VIDIOCGFBUF\n"); + DBG("PlanB: IOCTL VIDIOCGFBUF\n"); - v.base = (void *)pb->frame_buffer_phys; + v.base = (void *)pb->fb.phys; v.height = pb->win.sheight; v.width = pb->win.swidth; v.depth = pb->win.depth; @@ -1556,7 +1703,7 @@ if(copy_from_user(&i, arg, sizeof(i))) return -EFAULT; if(i==0) { - DEBUG("PlanB: IOCTL VIDIOCCAPTURE Stop\n"); + DBG("PlanB: IOCTL VIDIOCCAPTURE Stop\n"); if (!(pb->overlay)) return 0; @@ -1565,9 +1712,9 @@ overlay_stop(pb); planb_unlock(pb); } else { - DEBUG("PlanB: IOCTL VIDIOCCAPTURE Start\n"); + DBG("PlanB: IOCTL VIDIOCCAPTURE Start\n"); - if (pb->frame_buffer_phys == 0 || + if (pb->fb.phys == 0 || pb->win.width == 0 || pb->win.height == 0) return -EINVAL; @@ -1586,7 +1733,7 @@ { struct video_channel v; - DEBUG("PlanB: IOCTL VIDIOCGCHAN\n"); + DBG("PlanB: IOCTL VIDIOCGCHAN\n"); if(copy_from_user(&v, arg,sizeof(v))) return -EFAULT; @@ -1615,7 +1762,7 @@ { struct video_channel v; - DEBUG("PlanB: IOCTL VIDIOCSCHAN\n"); + DBG("PlanB: IOCTL VIDIOCSCHAN\n"); if(copy_from_user(&v, arg, sizeof(v))) return -EFAULT; @@ -1678,20 +1825,21 @@ { struct video_picture vp = pb->picture; - DEBUG("PlanB: IOCTL VIDIOCGPICT\n"); + DBG("PlanB: IOCTL VIDIOCGPICT\n"); switch(pb->win.color_fmt) { - case PLANB_GRAY: - vp.palette = VIDEO_PALETTE_GREY; - case PLANB_COLOUR15: - vp.palette = VIDEO_PALETTE_RGB555; - break; - case PLANB_COLOUR32: - vp.palette = VIDEO_PALETTE_RGB32; - break; - default: - vp.palette = 0; - break; + case PLANB_GRAY: + vp.palette = VIDEO_PALETTE_GREY; + break; + case PLANB_COLOUR15: + vp.palette = VIDEO_PALETTE_RGB555; + break; + case PLANB_COLOUR32: + vp.palette = VIDEO_PALETTE_RGB32; + break; + default: + vp.palette = 0; + break; } if(copy_to_user(arg,&vp,sizeof(vp))) @@ -1702,7 +1850,7 @@ { struct video_picture vp; - DEBUG("PlanB: IOCTL VIDIOCSPICT\n"); + DBG("PlanB: IOCTL VIDIOCSPICT\n"); if(copy_from_user(&vp,arg,sizeof(vp))) return -EFAULT; @@ -1725,7 +1873,7 @@ struct video_clip clip; int i; - DEBUG("PlanB: IOCTL VIDIOCSWIN\n"); + DBG("PlanB: IOCTL VIDIOCSWIN\n"); if(copy_from_user(&vw,arg,sizeof(vw))) return -EFAULT; @@ -1764,7 +1912,7 @@ { struct video_window vw; - DEBUG("PlanB: IOCTL VIDIOCGWIN\n"); + DBG("PlanB: IOCTL VIDIOCGWIN\n"); vw.x=pb->win.x; vw.y=pb->win.y; @@ -1781,12 +1929,12 @@ case VIDIOCSYNC: { int i; - IDEBUG("PlanB: IOCTL VIDIOCSYNC\n"); + IDBG("PlanB: IOCTL VIDIOCSYNC\n"); if(copy_from_user((void *)&i,arg,sizeof(int))) return -EFAULT; - IDEBUG("PlanB: sync to frame %d\n", i); + IDBG("PlanB: sync to frame %d\n", i); if(i > (MAX_GBUFFERS - 1) || i < 0) return -EINVAL; @@ -1795,7 +1943,7 @@ case GBUFFER_UNUSED: return -EINVAL; case GBUFFER_GRABBING: - IDEBUG("PlanB: waiting for grab" + IDBG("PlanB: waiting for grab" " done (%d)\n", i); interruptible_sleep_on(&pb->capq); if(signal_pending(current)) @@ -1813,7 +1961,7 @@ struct video_mmap vm; volatile unsigned int status; - IDEBUG("PlanB: IOCTL VIDIOCMCAPTURE\n"); + IDBG("PlanB: IOCTL VIDIOCMCAPTURE\n"); if(copy_from_user((void *) &vm,(void *)arg,sizeof(vm))) return -EFAULT; @@ -1829,7 +1977,7 @@ int i; struct video_mbuf vm; - DEBUG("PlanB: IOCTL VIDIOCGMBUF\n"); + DBG("PlanB: IOCTL VIDIOCGMBUF\n"); memset(&vm, 0 , sizeof(vm)); vm.size = PLANB_MAX_FBUF * MAX_GBUFFERS; @@ -1841,11 +1989,27 @@ return 0; } + case VIDIOCGUNIT: + { + struct video_unit vu; + + DBG("PlanB: IOCTL VIDIOCGUNIT\n"); + + vu.video=pb->video_dev.minor; + vu.vbi=pb->vbi_dev.minor; + vu.radio=VIDEO_NO_UNIT; + vu.audio=VIDEO_NO_UNIT; + vu.teletext=VIDEO_NO_UNIT; + if(copy_to_user((void *)arg, (void *)&vu, sizeof(vu))) + return -EFAULT; + return 0; + } + case PLANBIOCGSAAREGS: { struct planb_saa_regs preg; - DEBUG("PlanB: IOCTL PLANBIOCGSAAREGS\n"); + DBG("PlanB: IOCTL PLANBIOCGSAAREGS\n"); if(copy_from_user(&preg, arg, sizeof(preg))) return -EFAULT; @@ -1862,7 +2026,7 @@ { struct planb_saa_regs preg; - DEBUG("PlanB: IOCTL PLANBIOCSSAAREGS\n"); + DBG("PlanB: IOCTL PLANBIOCSSAAREGS\n"); if(copy_from_user(&preg, arg, sizeof(preg))) return -EFAULT; @@ -1876,10 +2040,14 @@ { struct planb_stat_regs pstat; - DEBUG("PlanB: IOCTL PLANBIOCGSTAT\n"); + DBG("PlanB: IOCTL PLANBIOCGSTAT\n"); - pstat.ch1_stat = in_le32(&pb->planb_base->ch1.status); - pstat.ch2_stat = in_le32(&pb->planb_base->ch2.status); + pstat.ch1_stat = readl(&pb->planb_base->ch1.status); + pstat.ch2_stat = readl(&pb->planb_base->ch2.status); + pstat.ch1_cmdbase = (unsigned long)pb->vid_cbo.start; + pstat.ch2_cmdbase = (unsigned long)pb->clip_cbo.start; + pstat.ch1_cmdptr = readl(&pb->planb_base->ch1.cmdptr); + pstat.ch2_cmdptr = readl(&pb->planb_base->ch2.cmdptr); pstat.saa_stat0 = saa_status(0, pb); pstat.saa_stat1 = saa_status(1, pb); @@ -1888,11 +2056,11 @@ return -EFAULT; return 0; } - + case PLANBIOCSMODE: { int v; - DEBUG("PlanB: IOCTL PLANBIOCSMODE\n"); + DBG("PlanB: IOCTL PLANBIOCSMODE\n"); if(copy_from_user(&v, arg, sizeof(v))) return -EFAULT; @@ -1919,7 +2087,7 @@ case PLANBIOCGMODE: { int v=pb->win.mode; - DEBUG("PlanB: IOCTL PLANBIOCGMODE\n"); + DBG("PlanB: IOCTL PLANBIOCGMODE\n"); if(copy_to_user(arg,&v,sizeof(v))) return -EFAULT; @@ -1929,17 +2097,20 @@ case PLANBG_GRAB_BPL: { int v=pb->gbytes_per_line; - DEBUG("PlanB: IOCTL PLANBG_GRAB_BPL\n"); + DBG("PlanB: IOCTL PLANBG_GRAB_BPL\n"); if(copy_to_user(arg,&v,sizeof(v))) return -EFAULT; return 0; } #endif /* PLANB_GSCANLINE */ + +/* These serve only for debugging... */ +#ifdef DEBUG case PLANB_INTR_DEBUG: { int i; - DEBUG("PlanB: IOCTL PLANB_INTR_DEBUG\n"); + DBG("PlanB: IOCTL PLANB_INTR_DEBUG\n"); if(copy_from_user(&i, arg, sizeof(i))) return -EFAULT; @@ -1959,7 +2130,7 @@ int i; struct planb_any_regs any; - DEBUG("PlanB: IOCTL PLANB_INV_REGS\n"); + DBG("PlanB: IOCTL PLANB_INV_REGS\n"); if(copy_from_user(&any, arg, sizeof(any))) return -EFAULT; @@ -1969,42 +2140,70 @@ return -EINVAL; for (i = 0; i < any.bytes; i++) { any.data[i] = - in_8((unsigned char *)pb->planb_base + readb((unsigned char *)pb->planb_base + any.offset + i); } if(copy_to_user(arg,&any,sizeof(any))) return -EFAULT; return 0; } + case PLANBIOCGDBDMABUF: + { + struct planb_buf_regs buf; + dbdma_cmd_ptr dc; + int i; + + DBG("PlanB: IOCTL PLANBIOCGDBDMABUF\n"); + + if(copy_from_user(&buf, arg, sizeof(buf))) + return -EFAULT; + buf.end &= ~0xf; + if( (buf.start < 0) || (buf.end < 0x10) || + (buf.end < buf.start+0x10) || + (buf.end > 2*pb->tab_size) ) + return -EINVAL; + + printk ("PlanB DBDMA command buffer:\n"); + for (i=(buf.start>>4); i<=(buf.end>>4); i++) { + printk(" 0x%04x:", i<<4); + dc = pb->vid_cbo.start + i; + printk (" %04x %04x %08x %08x %04x %04x\n", + dc->req_count, dc->command, dc->phy_addr, + dc->cmd_dep, dc->res_count, dc->xfer_status); + } + return 0; + } +#endif /* DEBUG */ + default: { - DEBUG("PlanB: Unimplemented IOCTL\n"); + DBG("PlanB: Unimplemented IOCTL\n"); return -ENOIOCTLCMD; } /* Some IOCTLs are currently unsupported on PlanB */ case VIDIOCGTUNER: { - DEBUG("PlanB: IOCTL VIDIOCGTUNER\n"); + DBG("PlanB: IOCTL VIDIOCGTUNER\n"); goto unimplemented; } case VIDIOCSTUNER: { - DEBUG("PlanB: IOCTL VIDIOCSTUNER\n"); + DBG("PlanB: IOCTL VIDIOCSTUNER\n"); goto unimplemented; } case VIDIOCSFREQ: { - DEBUG("PlanB: IOCTL VIDIOCSFREQ\n"); + DBG("PlanB: IOCTL VIDIOCSFREQ\n"); goto unimplemented; } case VIDIOCGFREQ: { - DEBUG("PlanB: IOCTL VIDIOCGFREQ\n"); + DBG("PlanB: IOCTL VIDIOCGFREQ\n"); goto unimplemented; } case VIDIOCKEY: { - DEBUG("PlanB: IOCTL VIDIOCKEY\n"); + DBG("PlanB: IOCTL VIDIOCKEY\n"); goto unimplemented; } case VIDIOCSAUDIO: { - DEBUG("PlanB: IOCTL VIDIOCSAUDIO\n"); + DBG("PlanB: IOCTL VIDIOCSAUDIO\n"); goto unimplemented; } case VIDIOCGAUDIO: { - DEBUG("PlanB: IOCTL VIDIOCGAUDIO\n"); + DBG("PlanB: IOCTL VIDIOCGAUDIO\n"); goto unimplemented; } unimplemented: - DEBUG(" Unimplemented\n"); + DBG(" Unimplemented\n"); return -ENOIOCTLCMD; } return 0; @@ -2012,9 +2211,9 @@ static int planb_mmap(struct video_device *dev, const char *adr, unsigned long size) { - int i; - struct planb *pb = (struct planb *)dev; - unsigned long start = (unsigned long)adr; + struct planb *pb = (struct planb *)dev->priv; + unsigned long start = (unsigned long)adr; + int i; if (size > MAX_GBUFFERS * PLANB_MAX_FBUF) return -EINVAL; @@ -2035,6 +2234,129 @@ return 0; } +/********************************** + * VBI device operation functions * + **********************************/ + +static long planb_vbi_read(struct video_device *dev, char *buf, + unsigned long count, int nonblock) +{ + struct planb *pb = (struct planb *)dev->priv; + unsigned long flags; + int q,todo; + +/* Dummy for now */ + printk ("PlanB: VBI read %li bytes.\n", count); + return (0); + + todo=count; + while (todo && todo>(q=VBIBUF_SIZE-pb->vbip)) + { + if(copy_to_user((void *) buf, (void *) pb->vbibuf+pb->vbip, q)) + return -EFAULT; + todo-=q; + buf+=q; +/* FIXME ?? Interrupt handling OK ??? */ + save_flags(flags); + cli(); + if (todo && q==VBIBUF_SIZE-pb->vbip) { + if(nonblock) { + restore_flags(flags); + if(count==todo) + return -EWOULDBLOCK; + return count-todo; + } + interruptible_sleep_on(&pb->vbiq); + restore_flags(flags); + if(signal_pending(current)) { + if(todo==count) + return -EINTR; + else + return count-todo; + } + } + restore_flags(flags); + } + if (todo) { + if(copy_to_user((void *) buf, (void *) pb->vbibuf+pb->vbip, + todo)) + return -EFAULT; + pb->vbip+=todo; + } + return count; +} + +static unsigned int planb_vbi_poll(struct video_device *dev, + struct file *file, poll_table *wait) +{ + struct planb *pb = (struct planb *)dev->priv; + unsigned int mask = 0; + + printk ("PlanB: VBI poll.\n"); + poll_wait(file, &pb->vbiq, wait); + + if (pb->vbip < VBIBUF_SIZE) + mask |= (POLLIN | POLLRDNORM); + + return mask; +} + +static int planb_vbi_open(struct video_device *dev, int flags) +{ + struct planb *pb = (struct planb *)dev->priv; + int err; + + /* first open on the driver? */ + if(pb->vid_user + pb->vbi_user == 0) { + if((err = planb_prepare_open(pb)) != 0) + return err; + } + /* first open on the vbi device? */ + if(pb->vbi_user == 1) { + if((err = planb_prepare_vbi(pb)) != 0) + return err; + } + ++pb->vbi_user; + + DBG("PlanB: VBI open\n"); + + MOD_INC_USE_COUNT; + return 0; +} + +static void planb_vbi_close(struct video_device *dev) +{ + struct planb *pb = (struct planb *)dev->priv; + + /* last close on vbi device? */ + if(--pb->vbi_user == 0) { + planb_close_vbi(pb); + } + /* last close on any planb device? */ + if(pb->vid_user + pb->vbi_user == 0) { + planb_prepare_close(pb); + } + + DBG("PlanB: VBI close\n"); + + MOD_DEC_USE_COUNT; + return; +} + +static int planb_vbi_ioctl(struct video_device *dev, unsigned int cmd, + void *arg) +{ + switch (cmd) { + /* This is only for alevt */ + case BTTV_VBISIZE: + DBG("PlanB: IOCTL BTTV_VBISIZE.\n"); + return VBIBUF_SIZE; + default: + DBG("PlanB: Unimplemented VBI IOCTL no. %i.\n", cmd); + return -EINVAL; + } +} + /* This gets called upon device registration */ /* we could do some init here */ static int planb_init_done(struct video_device *dev) @@ -2045,30 +2367,52 @@ static struct video_device planb_template= { PLANB_DEVICE_NAME, - VID_TYPE_OVERLAY, + VID_TYPE_CAPTURE|VID_TYPE_OVERLAY, VID_HARDWARE_PLANB, planb_open, planb_close, planb_read, - planb_write, -#if LINUX_VERSION_CODE >= 0x020100 - NULL, /* poll */ -#endif + planb_write, /* not implemented */ + NULL, /* poll */ planb_ioctl, - planb_mmap, /* mmap? */ + planb_mmap, planb_init_done, - NULL, /* pointer to private data */ + NULL, /* pointer to private data */ 0, 0 }; +static struct video_device planb_vbi_template= +{ + PLANB_VBI_NAME, + VID_TYPE_CAPTURE|VID_TYPE_TELETEXT, + VID_HARDWARE_PLANB, + planb_vbi_open, + planb_vbi_close, + planb_vbi_read, + planb_write, /* not implemented */ + planb_vbi_poll, + planb_vbi_ioctl, + NULL, /* no mmap yet */ + planb_init_done, + NULL, + 0, + -1 +}; + static int init_planb(struct planb *pb) { unsigned char saa_rev; int i, result; unsigned long flags; + printk(KERN_INFO "PlanB video input driver rev. %s\n", PLANB_REV); + memset ((void *) &pb->win, 0, sizeof (struct planb_window)); + + pb->video_dev.minor = -1; + pb->vid_user = 0; + /* Simple sanity check */ if(def_norm >= NUM_SUPPORTED_NORM || def_norm < 0) { printk(KERN_ERR "PlanB: Option(s) invalid\n"); @@ -2081,13 +2425,6 @@ pb->win.y=0; pb->win.width=768; /* 640 */ pb->win.height=576; /* 480 */ - pb->maxlines=576; -#if 0 - btv->win.cropwidth=768; /* 640 */ - btv->win.cropheight=576; /* 480 */ - btv->win.cropx=0; - btv->win.cropy=0; -#endif pb->win.pad=0; pb->win.bpp=4; pb->win.depth=32; @@ -2095,6 +2432,7 @@ pb->win.bpl=1024*pb->win.bpp; pb->win.swidth=1024; pb->win.sheight=768; + pb->maxlines=576; #ifdef PLANB_GSCANLINE if((pb->gbytes_per_line = PLANB_MAXPIXELS * 4) > PAGE_SIZE || (pb->gbytes_per_line <= 0)) @@ -2110,16 +2448,23 @@ pb->suspend = 0; pb->lock = 0; init_waitqueue_head(&pb->lockq); - pb->ch1_cmd = 0; - pb->ch2_cmd = 0; + pb->vid_cbo.start = 0; + pb->clip_cbo.start = 0; pb->mask = 0; - pb->priv_space = 0; - pb->offset = 0; - pb->user = 0; + pb->vid_raw = 0; pb->overlay = 0; init_waitqueue_head(&pb->suspendq); pb->cmd_buff_inited = 0; - pb->frame_buffer_phys = 0; + pb->fb.phys = 0; + pb->fb.offset = 0; + + /* VBI stuff: */ + pb->vbi_dev.minor = -1; + pb->vbi_user = 0; + pb->vbirunning = 0; + pb->vbip = 0; + pb->vbibuf = 0; + init_waitqueue_head(&pb->vbiq); /* Reset DMA controllers */ planb_dbdma_stop(&pb->planb_base->ch2); @@ -2148,9 +2493,6 @@ disable_irq(pb->irq); restore_flags(flags); - /* Now add the template and register the device unit. */ - memcpy(&pb->video_dev,&planb_template,sizeof(planb_template)); - pb->picture.brightness=0x90<<8; pb->picture.contrast = 0x70 << 8; pb->picture.colour = 0x70<<8; @@ -2177,12 +2519,22 @@ pb->grabbing=0; /* enable interrupts */ - out_le32(&pb->planb_base->intr_stat, PLANB_CLR_IRQ); + writel(PLANB_CLR_IRQ, &pb->planb_base->intr_stat); pb->intr_mask = PLANB_FRM_IRQ; enable_irq(pb->irq); + /* Now add the templates and register the device units. */ + memcpy(&pb->video_dev,&planb_template,sizeof(planb_template)); + pb->video_dev.priv = pb; + memcpy(&pb->vbi_dev,&planb_vbi_template,sizeof(planb_vbi_template)); + pb->vbi_dev.priv = pb; + if(video_register_device(&pb->video_dev, VFL_TYPE_GRABBER)<0) return -1; + if(video_register_device(&pb->vbi_dev, VFL_TYPE_VBI)<0) { + video_unregister_device(&pb->video_dev); + return -1; + } return 0; } @@ -2238,7 +2590,9 @@ OF assigns the planb controller memory within this space; so we need to change that here in order to access planb. */ - /* We remap to 0xf1000000 in hope that nobody uses it ! */ + /* We remap to 0xf1000000 in hope that nobody uses it. + Once the PCI resource allocation code is in here, we can + drop the ugliness out of this part. */ bus = (planb_devices->addrs[0].space >> 16) & 0xff; dev_fn = (planb_devices->addrs[0].space >> 8) & 0xff; @@ -2246,14 +2600,14 @@ old_base = planb_devices->addrs[0].address; new_base = 0xf1000000; - DEBUG("PlanB: Found on bus %d, dev %d, func %d, " + DBG("PlanB: Found on bus %d, dev %d, func %d, " "membase 0x%x (base reg. 0x%x)\n", bus, PCI_SLOT(dev_fn), PCI_FUNC(dev_fn), old_base, confreg); pdev = pci_find_slot (bus, dev_fn); if (!pdev) { - printk(KERN_ERR "cannot find slot\n"); - /* XXX handle error */ + printk(KERN_ERR "PlanB: cannot find PCI device!\n"); + return 0; } /* Enable response in memory space, bus mastering, @@ -2286,13 +2640,13 @@ { pb=&planbs[i]; - /* stop and flash DMAs unconditionally */ + /* stop and flush DMAs unconditionally */ planb_dbdma_stop(&pb->planb_base->ch2); planb_dbdma_stop(&pb->planb_base->ch1); /* clear and free interrupts */ pb->intr_mask = PLANB_CLR_IRQ; - out_le32 (&pb->planb_base->intr_stat, PLANB_CLR_IRQ); + writel(PLANB_CLR_IRQ, &pb->planb_base->intr_stat); free_irq(pb->irq, pb); /* make sure all allocated memory are freed */ @@ -2300,6 +2654,7 @@ printk(KERN_INFO "PlanB: unregistering with v4l\n"); video_unregister_device(&pb->video_dev); + video_unregister_device(&pb->vbi_dev); /* note that iounmap() does nothing on the PPC right now */ iounmap ((void *)pb->planb_base); @@ -2326,7 +2681,6 @@ release_planb(); return -EIO; } - printk(KERN_INFO "PlanB: registered device %d with v4l\n", i); } return 0; } --- linux-2.4.paul/drivers/char/planb.h Fri Apr 28 05:50:57 2000 +++ linux/drivers/char/planb.h Sat Aug 12 17:59:40 2000 @@ -1,10 +1,10 @@ /* - planb - PlanB frame grabber driver + planb - v4l-compatible frame grabber driver for the PlanB hardware PlanB is used in the 7x00/8x00 series of PowerMacintosh Computers as video input DMA controller. - Copyright (C) 1998 Michel Lanners (mlan@cpu.lu) + Copyright (C) 1998, 1999 Michel Lanners (mlan@cpu.lu) Based largely on the bttv driver by Ralph Metzler (rjkm@thp.uni-koeln.de) @@ -26,18 +26,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: planb.h,v 1.13 1999/05/03 19:28:56 mlan Exp $ */ +/* $Id: planb.h,v 2.5 1999/12/22 20:29:35 mlan Exp mlan $ */ #ifndef _PLANB_H_ #define _PLANB_H_ -#ifdef __KERNEL__ -#include -#include "saa7196.h" -#endif /* __KERNEL__ */ - #define PLANB_DEVICE_NAME "Apple PlanB Video-In" -#define PLANB_REV "1.0" +#define PLANB_VBI_NAME "Apple PlanB VBI" +#define PLANB_REV "2.5" #ifdef __KERNEL__ //#define PLANB_GSCANLINE /* use this if apps have the notion of */ @@ -47,6 +43,15 @@ #define PLANB_MAXLINES 576 #define PLANB_NTSC_MAXLINES 480 +/* Max VBI data buffer size */ +#define VBI_LINESIZE 1024 /* on SAA7196, a line can be max. 1024 pixels */ +#define VBI_START 7 /* VBI starts at line 7 */ +#define VBI_MAXLINES 16 /* 16 lines per field */ +/* We have 2 of these, but return them one at a time */ +#define VBIBUF_SIZE (VBI_LINESIZE * VBI_MAXLINES) + +#define LINE_OFFSET 1 /* between line 1 and SAA's first valid line */ + /* Uncomment your preferred norm ;-) */ #define PLANB_DEF_NORM VIDEO_MODE_PAL //#define PLANB_DEF_NORM VIDEO_MODE_NTSC @@ -87,6 +92,10 @@ struct planb_stat_regs { unsigned int ch1_stat; unsigned int ch2_stat; + unsigned long ch1_cmdbase; + unsigned long ch2_cmdbase; + unsigned int ch1_cmdptr; + unsigned int ch2_cmdptr; unsigned char saa_stat0; unsigned char saa_stat1; }; @@ -97,10 +106,18 @@ unsigned char data[128]; }; +struct planb_buf_regs { + unsigned int start; + unsigned int end; +}; + /* planb private ioctls */ -#define PLANBIOCGSAAREGS _IOWR('v', BASE_VIDIOCPRIVATE, struct planb_saa_regs) /* Read a saa7196 reg value */ -#define PLANBIOCSSAAREGS _IOW('v', BASE_VIDIOCPRIVATE + 1, struct planb_saa_regs) /* Set a saa7196 reg value */ -#define PLANBIOCGSTAT _IOR('v', BASE_VIDIOCPRIVATE + 2, struct planb_stat_regs) /* Read planb status */ +/* Read a saa7196 reg value */ +#define PLANBIOCGSAAREGS _IOWR('v', BASE_VIDIOCPRIVATE, struct planb_saa_regs) +/* Set a saa7196 reg value */ +#define PLANBIOCSSAAREGS _IOW('v', BASE_VIDIOCPRIVATE + 1, struct planb_saa_regs) +/* Read planb status */ +#define PLANBIOCGSTAT _IOR('v', BASE_VIDIOCPRIVATE + 2, struct planb_stat_regs) #define PLANB_TV_MODE 1 #define PLANB_VTR_MODE 2 #define PLANBIOCGMODE _IOR('v', BASE_VIDIOCPRIVATE + 3, int) /* Get TV/VTR mode */ @@ -110,10 +127,19 @@ #define PLANBG_GRAB_BPL _IOR('v', BASE_VIDIOCPRIVATE + 5, int) /* # of bytes per scanline in grab buffer */ #endif +/* This doesn't really belong here, but until someone cleans up (or defines + in the first place ;-) the VBI API, it helps alevt... */ +#define BTTV_VBISIZE _IOR('v', BASE_VIDIOCPRIVATE + 8, int) + +/* Various debugging IOCTLs */ +#ifdef DEBUG /* call wake_up_interruptible() with appropriate actions */ #define PLANB_INTR_DEBUG _IOW('v', BASE_VIDIOCPRIVATE + 20, int) /* investigate which reg does what */ #define PLANB_INV_REGS _IOWR('v', BASE_VIDIOCPRIVATE + 21, struct planb_any_regs) +/* Dump DBDMA command buffer from (int) to (int) */ +#define PLANBIOCGDBDMABUF _IOW('v', BASE_VIDIOCPRIVATE + 22, struct planb_buf_regs) +#endif /* DEBUG */ #ifdef __KERNEL__ @@ -121,27 +147,32 @@ #define PLANB_SET(x) ((x) << 16 | (x)) #define PLANB_CLR(x) ((x) << 16) +typedef volatile struct dbdma_cmd dbdma_cmd_t; +typedef volatile struct dbdma_cmd *dbdma_cmd_ptr; +typedef volatile struct dbdma_regs dbdma_regs_t; +typedef volatile struct dbdma_regs *dbdma_regs_ptr; + /* This represents the physical register layout */ struct planb_registers { - volatile struct dbdma_regs ch1; /* 0x00: video in */ - volatile unsigned int even; /* 0x40: even field setting */ - volatile unsigned int odd; /* 0x44; odd field setting */ - unsigned int pad1[14]; /* empty? */ - volatile struct dbdma_regs ch2; /* 0x80: clipmask out */ - unsigned int pad2[16]; /* 0xc0: empty? */ - volatile unsigned int reg3; /* 0x100: ???? */ - volatile unsigned int intr_stat; /* 0x104: irq status */ + dbdma_regs_t ch1; /* 0x00: video in */ + volatile u32 even; /* 0x40: even field setting */ + volatile u32 odd; /* 0x44; odd field setting */ + u32 pad1[14]; /* empty? */ + dbdma_regs_t ch2; /* 0x80: clipmask out */ + u32 pad2[16]; /* 0xc0: empty? */ + volatile u32 reg3; /* 0x100: ???? */ + volatile u32 intr_stat; /* 0x104: irq status */ #define PLANB_CLR_IRQ 0x00 /* clear Plan B interrupt */ #define PLANB_GEN_IRQ 0x01 /* assert Plan B interrupt */ #define PLANB_FRM_IRQ 0x0100 /* end of frame */ - unsigned int pad3[1]; /* empty? */ - volatile unsigned int reg5; /* 0x10c: ??? */ - unsigned int pad4[60]; /* empty? */ - volatile unsigned char saa_addr; /* 0x200: SAA subadr */ - char pad5[3]; - volatile unsigned char saa_regval; /* SAA7196 write reg. val */ - char pad6[3]; - volatile unsigned char saa_status; /* SAA7196 status byte */ + u32 pad3[1]; /* empty? */ + volatile u32 reg5; /* 0x10c: ??? */ + u32 pad4[60]; /* empty? */ + volatile u8 saa_addr; /* 0x200: SAA subadr */ + u8 pad5[3]; + volatile u8 saa_regval; /* SAA7196 write reg. val */ + u8 pad6[3]; + volatile u8 saa_status; /* SAA7196 status byte */ /* There is more unused stuff here */ }; @@ -163,68 +194,99 @@ struct dbdma_cmd cmd; }; +/* Framebuffer info */ +struct planb_fb { + unsigned long phys; /* Framebuffer phys. base address */ + int offset; /* offset of pixel 1 */ +}; + +/* DBDMA command buffer descriptor */ +struct dbdma_cmd_buf { + dbdma_cmd_ptr start; + dbdma_cmd_ptr jumpaddr; /* where are we called from? */ + unsigned int size; + unsigned long bus; /* start address as seen from the bus */ +}; + struct planb { - struct video_device video_dev; - struct video_picture picture; /* Current picture params */ - struct video_audio audio_dev; /* Current audio params */ +/* the video device: */ + struct video_device video_dev; + struct video_picture picture; /* Current picture params */ + int vid_user; /* Users on video device */ + void *vid_raw; /* Org. alloc. mem for kfree */ + struct dbdma_cmd_buf vid_cbo; /* odd video dbdma cmd buf */ + struct dbdma_cmd_buf vid_cbe; /* even */ + void *clip_raw; + struct dbdma_cmd_buf clip_cbo; /* odd clip dbdma cmd buf */ + struct dbdma_cmd_buf clip_cbe; /* even */ + dbdma_cmd_ptr overlay_last1; + dbdma_cmd_ptr overlay_last2; - volatile struct planb_registers *planb_base; /* virt base of planb */ - struct planb_registers *planb_base_phys; /* phys base of planb */ - void *priv_space; /* Org. alloc. mem for kfree */ - int user; - unsigned int tab_size; - int maxlines; - int lock; - wait_queue_head_t lockq; - unsigned int irq; /* interrupt number */ - volatile unsigned int intr_mask; - - int overlay; /* overlay running? */ - struct planb_window win; - unsigned long frame_buffer_phys; /* We need phys for DMA */ - int offset; /* offset of pixel 1 */ - volatile struct dbdma_cmd *ch1_cmd; /* Video In DMA cmd buffer */ - volatile struct dbdma_cmd *ch2_cmd; /* Clip Out DMA cmd buffer */ - volatile struct dbdma_cmd *overlay_last1; - volatile struct dbdma_cmd *overlay_last2; - unsigned long ch1_cmd_phys; - volatile unsigned char *mask; /* Clipmask buffer */ - int suspend; - wait_queue_head_t suspendq; - struct planb_suspend suspended; - int cmd_buff_inited; /* cmd buffer inited? */ - - int grabbing; - unsigned int gcount; - wait_queue_head_t capq; - int last_fr; - int prev_last_fr; - unsigned char **rawbuf; - int rawbuf_size; - int gbuf_idx[MAX_GBUFFERS]; - volatile struct dbdma_cmd *cap_cmd[MAX_GBUFFERS]; - volatile struct dbdma_cmd *last_cmd[MAX_GBUFFERS]; - volatile struct dbdma_cmd *pre_cmd[MAX_GBUFFERS]; - int need_pre_capture[MAX_GBUFFERS]; +/* the hardware: */ + volatile struct planb_registers + *planb_base; /* virt base of planb */ + struct planb_registers *planb_base_phys; /* phys base of planb */ + unsigned int tab_size; + int maxlines; + unsigned int irq; /* interrupt number */ + volatile unsigned int intr_mask; + struct planb_fb fb; /* Framebuffer info */ + +/* generic stuff: */ + void *jump_raw; /* jump buffer raw space */ + dbdma_cmd_ptr jumpbuf; /* same, DBDMA_ALIGN'ed */ + int lock; + wait_queue_head_t lockq; + int overlay; /* overlay running? */ + struct planb_window win; + volatile unsigned char *mask; /* Clipmask buffer */ + int suspend; + wait_queue_head_t suspendq; + struct planb_suspend suspended; + int cmd_buff_inited; /* cmd buffer inited? */ + + int grabbing; + unsigned int gcount; + wait_queue_head_t capq; + int last_fr; + int prev_last_fr; + unsigned char **rawbuf; + int rawbuf_size; + int gbuf_idx[MAX_GBUFFERS]; + dbdma_cmd_ptr cap_cmd[MAX_GBUFFERS]; + dbdma_cmd_ptr last_cmd[MAX_GBUFFERS]; + dbdma_cmd_ptr pre_cmd[MAX_GBUFFERS]; + int need_pre_capture[MAX_GBUFFERS]; #define PLANB_DUMMY 40 /* # of command buf's allocated for pre-capture seq. */ - int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS]; - unsigned int gfmt[MAX_GBUFFERS]; - int gnorm_switch[MAX_GBUFFERS]; - volatile unsigned int *frame_stat; -#define GBUFFER_UNUSED 0x00U -#define GBUFFER_GRABBING 0x01U -#define GBUFFER_DONE 0x02U + int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS]; + unsigned int gfmt[MAX_GBUFFERS]; + int gnorm_switch[MAX_GBUFFERS]; + volatile unsigned int *frame_stat; +#define GBUFFER_UNUSED 0x00U +#define GBUFFER_GRABBING 0x01U +#define GBUFFER_DONE 0x02U #ifdef PLANB_GSCANLINE - int gbytes_per_line; + int gbytes_per_line; #else #define MAX_LNUM 431 /* change this if PLANB_MAXLINES or */ /* PLANB_MAXPIXELS changes */ - int l_fr_addr_idx[MAX_GBUFFERS]; - unsigned char *l_to_addr[MAX_GBUFFERS][MAX_LNUM]; - int l_to_next_idx[MAX_GBUFFERS][MAX_LNUM]; - int l_to_next_size[MAX_GBUFFERS][MAX_LNUM]; - int lsize[MAX_GBUFFERS], lnum[MAX_GBUFFERS]; -#endif + int l_fr_addr_idx[MAX_GBUFFERS]; + unsigned char *l_to_addr[MAX_GBUFFERS][MAX_LNUM]; + int l_to_next_idx[MAX_GBUFFERS][MAX_LNUM]; + int l_to_next_size[MAX_GBUFFERS][MAX_LNUM]; + int lsize[MAX_GBUFFERS], lnum[MAX_GBUFFERS]; +#endif /* PLANB_GSCANLINE */ + +/* VBI stuff: */ + struct video_device vbi_dev; /* VBI data device */ + int vbi_user; /* Users on vbi device */ + void *vbi_raw; + struct dbdma_cmd_buf vbi_cbo; /* odd VBI dbdma cmd buf */ + struct dbdma_cmd_buf vbi_cbe; /* even */ + int vbirunning; + int vbip; /* pointer into VBI buffer */ + unsigned char *vbibuf; /* buffer for VBI data */ + wait_queue_head_t vbiq; }; #endif /* __KERNEL__ */ --- linux-2.4.paul/drivers/char/saa7196.h Fri May 7 20:05:30 1999 +++ linux/drivers/char/saa7196.h Sat Aug 12 17:59:40 2000 @@ -6,7 +6,7 @@ Copyright (C) 1998 Michel Lanners (mlan@cpu.lu) The register defines are shamelessly copied from the meteor - driver out of NetBSD (with permission), + driver out of FreeBSD (with permission), and are copyrighted (c) 1995 Mark Tinguely and Jim Lowe (Thanks !) @@ -15,7 +15,7 @@ The default values used for PlanB are my mistakes. */ -/* $Id: saa7196.h,v 1.5 1999/03/26 23:28:47 mlan Exp $ */ +/* $Id: saa7196.h,v 1.6 1999/05/26 06:05:20 mlan Exp $ */ #ifndef _SAA7196_H_ #define _SAA7196_H_