diff -uNr linux-2.4.paul/arch/ppc/kernel/pmac_pci.c 2.4.3-pre2-paul.20010312/arch/ppc/kernel/pmac_pci.c --- linux-2.4.paul/arch/ppc/kernel/pmac_pci.c Wed Feb 7 23:48:50 2001 +++ 2.4.3-pre2-paul.20010312/arch/ppc/kernel/pmac_pci.c Tue Mar 13 23:34:45 2001 @@ -28,10 +28,18 @@ #include "pci.h" #undef DEBUG +#define DEBUG + +#ifdef DEBUG +#define DBG(x...) printk(x) +#else +#define DBG(x...) +#endif extern void process_bridge_ranges(struct pci_controller *hose, struct device_node *dev, int primary); static void add_bridges(struct device_node *dev); +static int chaos_validate_dev(struct pci_dev *dev, int offset); /* XXX Could be per-controller, but I don't think we risk anything by * assuming we won't have both UniNorth and Bandit */ @@ -95,12 +103,17 @@ } /* - * Apple MacRISC (UniNorth, Bandit) PCI controllers. + * Apple MacRISC (UniNorth, Bandit, Chaos) PCI controllers. * * The "Bandit" version is present in all early PCI PowerMacs, * and up to the first ones using Grackle. Some machines may * have 2 bandit controllers (2 PCI busses). * + * "Chaos" is used in some "Bandit"-type machines as a bridge + * for the separate display bus. It is accessed the same + * way as bandit, but cannot be probed for devices. It therefore + * has its own config access functions. + * * The "UniNorth" version is present in all Core99 machines * (iBook, G4, new IMacs, and all the recent Apple machines). * It contains 3 controllers in one ASIC. @@ -198,44 +211,35 @@ * based on what we find in OF device tree */ -static int chaos_config_read_byte(struct pci_dev *dev, int offset, u8 *val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - -static int chaos_config_read_word(struct pci_dev *dev, int offset, u16 *val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - -static int chaos_config_read_dword(struct pci_dev *dev, int offset, u32 *val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - -static int chaos_config_write_byte(struct pci_dev *dev, int offset, u8 val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - -static int chaos_config_write_word(struct pci_dev *dev, int offset, u16 val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - -static int chaos_config_write_dword(struct pci_dev *dev, int offset, u32 val) -{ - return PCIBIOS_DEVICE_NOT_FOUND; -} - +#define CHAOS_PCI_OP(rw, size, type) \ +static int __pmac \ +chaos_##rw##_config_##size(struct pci_dev *dev, int off, type val) \ +{ \ + int result = chaos_validate_dev(dev, off); \ + if(result == PCIBIOS_BAD_REGISTER_NUMBER) { \ + cfg_##rw##_bad(val, size) \ + return PCIBIOS_BAD_REGISTER_NUMBER; \ + } \ + if(result == PCIBIOS_SUCCESSFUL) \ + return macrisc_##rw##_config_##size(dev, off, val); \ + return result; \ +} + +CHAOS_PCI_OP(read, byte, u8 *) +CHAOS_PCI_OP(read, word, u16 *) +CHAOS_PCI_OP(read, dword, u32 *) +CHAOS_PCI_OP(write, byte, u8) +CHAOS_PCI_OP(write, word, u16) +CHAOS_PCI_OP(write, dword, u32) + static struct pci_ops chaos_pci_ops = { - chaos_config_read_byte, - chaos_config_read_word, - chaos_config_read_dword, - chaos_config_write_byte, - chaos_config_write_word, - chaos_config_write_dword + chaos_read_config_byte, + chaos_read_config_word, + chaos_read_config_dword, + chaos_write_config_byte, + chaos_write_config_word, + chaos_write_config_dword }; @@ -290,6 +294,22 @@ /* + * Verifiy that a specific (bus, dev_fn) exists on chaos + */ +static int chaos_validate_dev(struct pci_dev *dev, int offset) +{ + if(pci_device_to_OF_node(dev) == 0) + return PCIBIOS_DEVICE_NOT_FOUND; + if((dev->vendor == 0x106b) && (dev->device == 3) && (offset >= 0x10) && + (offset != 0x14) && (offset != 0x18) && (offset <= 0x24)) { +// DBG("Chaos: refusing access to control.\n"); + return PCIBIOS_BAD_REGISTER_NUMBER; + } + return PCIBIOS_SUCCESSFUL; +} + + +/* * Tweak the PCI-PCI bridge chip on the blue & white G3s. */ static void __init @@ -536,16 +556,21 @@ unsigned char pin; struct device_node* node; +#if 0 if (pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin) || !pin) continue; /* No interrupt generated -> no fixup */ +#endif node = pci_device_to_OF_node(dev); if (!node) { printk("No OF node for device %x:%x\n", dev->bus->number, dev->devfn >> 3); continue; } /* this is the node, see if it has interrupts */ - if (node->n_intrs > 0) + if (node->n_intrs > 0) { dev->irq = node->intrs[0].line; + DBG("PCI: Setting IRQ %d on device %s.\n", + dev->irq, dev->slot_name); + } pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); } } diff -uNr linux-2.4.paul/arch/ppc/kernel/ppc_htab.c 2.4.3-pre2-paul.20010312/arch/ppc/kernel/ppc_htab.c --- linux-2.4.paul/arch/ppc/kernel/ppc_htab.c Tue Oct 31 06:07:36 2000 +++ 2.4.3-pre2-paul.20010312/arch/ppc/kernel/ppc_htab.c Mon Mar 12 20:24:22 2001 @@ -581,6 +581,14 @@ p += sprintf(p,"\n"); + val = _get_HID0(); + p += sprintf(p, "HID0 contents: 0x%08x: ", val); + p += sprintf(p, "\n"); + + val = _get_ICTC(); + p += sprintf(p, "ICTC contents: 0x%08x: ", val); + p += sprintf(p, "\n"); + len = strlen(buf); if (len > left) len = left; diff -uNr linux-2.4.paul/drivers/media/video/planb.c 2.4.3-pre2-paul.20010312/drivers/media/video/planb.c --- linux-2.4.paul/drivers/media/video/planb.c Mon Mar 5 01:01:00 2001 +++ 2.4.3-pre2-paul.20010312/drivers/media/video/planb.c Thu Mar 15 23:00:34 2001 @@ -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,21 +85,33 @@ 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); static int planb_open(struct video_device *, int); static void planb_close(struct video_device *); static int planb_ioctl(struct video_device *, unsigned int, void *); -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 +121,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 +142,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 +174,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 +244,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 +274,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 +376,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 +396,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 +405,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 +519,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 +584,9 @@ kfree(pb->rawbuf); } pb->rawbuf = NULL; + + /* FIXME: restart running DMA if app. */ + return; } /*****************************/ @@ -448,43 +595,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 +635,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 +648,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 +672,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 +700,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 +747,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 +784,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 +815,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 +837,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 +857,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 +879,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 +923,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 +988,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 +1021,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 +1039,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 +1065,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 +1105,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 +1196,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 +1234,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 +1253,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 +1291,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 +1302,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 +1483,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 +1525,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 +1536,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 +1559,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 +1606,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 +1628,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 +1660,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 +1684,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 +1702,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 +1711,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 +1732,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 +1761,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 +1824,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 +1849,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 +1872,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 +1911,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 +1928,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 +1942,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 +1960,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 +1976,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 +1988,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 +2025,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 +2039,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 +2055,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 +2086,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 +2096,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 +2129,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 +2139,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 +2210,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,27 +2233,170 @@ 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; + } +} + static struct video_device planb_template= { owner: THIS_MODULE, name: PLANB_DEVICE_NAME, - type: VID_TYPE_OVERLAY, + type: VID_TYPE_CAPTURE|VID_TYPE_OVERLAY, hardware: VID_HARDWARE_PLANB, open: planb_open, close: planb_close, read: planb_read, - write: planb_write, + write: planb_write, /* not implemented */ ioctl: planb_ioctl, mmap: planb_mmap, /* mmap? */ }; +static struct video_device planb_vbi_template= +{ + owner: THIS_MODULE, + name: PLANB_VBI_NAME, + type: VID_TYPE_CAPTURE|VID_TYPE_TELETEXT, + hardware: VID_HARDWARE_PLANB, + open: planb_vbi_open, + close: planb_vbi_close, + read: planb_vbi_read, + write: planb_write, /* not implemented */ + poll: planb_vbi_poll, + ioctl: planb_vbi_ioctl, +}; + 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"); @@ -2068,13 +2409,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; @@ -2082,6 +2416,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)) @@ -2097,16 +2432,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); @@ -2135,24 +2477,21 @@ 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.brightness=0x90 << 8; pb->picture.contrast = 0x70 << 8; - pb->picture.colour = 0x70<<8; + pb->picture.colour = 0x70 << 8; pb->picture.hue = 0x8000; pb->picture.whiteness = 0; pb->picture.depth = pb->win.depth; - pb->frame_stat=NULL; + pb->frame_stat = NULL; init_waitqueue_head(&pb->capq); for(i=0; igbuf_idx[i] = PLANB_MAX_FBUF * i / PAGE_SIZE; - pb->gwidth[i]=0; - pb->gheight[i]=0; - pb->gfmt[i]=0; - pb->cap_cmd[i]=NULL; + pb->gwidth[i] = 0; + pb->gheight[i] = 0; + pb->gfmt[i] = 0; + pb->cap_cmd[i] = NULL; #ifndef PLANB_GSCANLINE pb->l_fr_addr_idx[i] = MAX_GBUFFERS * (PLANB_MAX_FBUF / PAGE_SIZE + 1) + MAX_LNUM * i; @@ -2160,16 +2499,26 @@ pb->lnum[i] = 0; #endif } - pb->rawbuf=NULL; - pb->grabbing=0; + pb->rawbuf = NULL; + 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; } @@ -2178,6 +2527,7 @@ * Scan for a PlanB controller, request the irq and map the io memory */ +#if 1 static int find_planb(void) { struct planb *pb; @@ -2225,7 +2575,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; @@ -2233,14 +2585,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, @@ -2263,6 +2615,58 @@ return planb_num; } +#endif + +#if 0 +static int find_planb(void) +{ + struct planb *pb; + struct pci_dev *pdev = NULL; + unsigned long base; + + if (_machine != _MACH_Pmac) + return 0; + + planb_num=0; + if (!(pdev = pci_find_device(0x106b, 0x0004, pdev))) { + printk(KERN_WARNING "PlanB: Error: no device found!\n"); + return planb_num; + } + if (pci_find_device(0x106b, 0x0004, pdev)) + printk(KERN_ERR "PlanB: Warning: only using first PlanB device!\n"); + pb = &planbs[0]; + planb_num = 1; + + if (!(pb->irq = pdev->irq)) { + printk(KERN_WARNING "PlanB: Error: no interrupt!\n"); + return 0; + } + + /* Initialize PlanB's PCI registers */ + + base = pdev->resource[0].start; + + DBG("PlanB: Found on bus %d, dev %d, func %d, membase %p\n", + pdev->bus->number, PCI_SLOT(pdev->devfn), + PCI_FUNC(pdev->devfn), (void *)base); + + /* Enable response in memory space, bus mastering, + use memory write and invalidate */ + pci_write_config_word (pdev, PCI_COMMAND, + PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | + PCI_COMMAND_INVALIDATE); + /* Set PCI Cache line size & latency timer */ + pci_write_config_byte (pdev, PCI_CACHE_LINE_SIZE, 0x8); + pci_write_config_byte (pdev, PCI_LATENCY_TIMER, 0x40); + + pb->planb_base = (volatile struct planb_registers *) + ioremap (base, 0x400); + /* FIXME: don't assume 1:1 mapping */ + pb->planb_base_phys = (struct planb_registers *)base; + + return planb_num; +} +#endif static void release_planb(void) { @@ -2273,13 +2677,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 */ @@ -2287,6 +2691,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); @@ -2313,7 +2718,6 @@ release_planb(); return -EIO; } - printk(KERN_INFO "PlanB: registered device %d with v4l\n", i); } return 0; } diff -uNr linux-2.4.paul/drivers/media/video/planb.h 2.4.3-pre2-paul.20010312/drivers/media/video/planb.h --- linux-2.4.paul/drivers/media/video/planb.h Thu Aug 24 02:54:27 2000 +++ 2.4.3-pre2-paul.20010312/drivers/media/video/planb.h Mon Mar 12 20:24:22 2001 @@ -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__ */ diff -uNr linux-2.4.paul/drivers/media/video/saa7196.h 2.4.3-pre2-paul.20010312/drivers/media/video/saa7196.h --- linux-2.4.paul/drivers/media/video/saa7196.h Thu Aug 24 02:54:27 2000 +++ 2.4.3-pre2-paul.20010312/drivers/media/video/saa7196.h Mon Mar 12 20:24:22 2001 @@ -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_ diff -uNr linux-2.4.paul/drivers/pci/pci.c 2.4.3-pre2-paul.20010312/drivers/pci/pci.c --- linux-2.4.paul/drivers/pci/pci.c Mon Mar 5 01:01:04 2001 +++ 2.4.3-pre2-paul.20010312/drivers/pci/pci.c Mon Mar 12 20:24:22 2001 @@ -26,6 +26,7 @@ #include /* isa_dma_bridge_buggy */ #undef DEBUG +#define DEBUG #ifdef DEBUG #define DBG(x...) printk(x) diff -uNr linux-2.4.paul/drivers/video/controlfb.c 2.4.3-pre2-paul.20010312/drivers/video/controlfb.c --- linux-2.4.paul/drivers/video/controlfb.c Sun Feb 11 08:02:24 2001 +++ 2.4.3-pre2-paul.20010312/drivers/video/controlfb.c Mon Mar 12 20:27:44 2001 @@ -110,6 +110,11 @@ } fbcon_cmap; }; +static int vram = 0; /* VRAM config: 1 = 2MB bank1; 2 = 2MB bank2; + 3 = 4MB */ +MODULE_PARM(vram, "i"); +MODULE_PARM_DESC(vram, "Override VRAM detection: 1 = 2MB bank1; 2 = 2MB bank2; 3 = 4MB"); + /******************** Prototypes for exported functions ********************/ static int control_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info); @@ -647,9 +652,9 @@ out_le32(&p->control_regs->mode.r, init->mode[cmode]); out_le32(&p->control_regs->flags.r, flags); out_le32(&p->control_regs->start_addr.r, par->yoffset * pitch); - out_le32(&p->control_regs->reg18.r, 0x1e5); - out_le32(&p->control_regs->reg19.r, 0); - + out_le32(&p->control_regs->refr_cnt.r, 0x1e5); + out_le32(&p->control_regs->int_en.r, 0); + for (i = 0; i < 16; ++i) { controlfb_setcolreg(color_table[i], default_red[i]<<8, default_grn[i]<<8, default_blu[i]<<8, @@ -737,6 +742,9 @@ request_mem_region(p->cmap_regs_phys, 0x1000, "controlfb cmap"); p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000); + printk(KERN_INFO "controlfb: remapped colormap to 0x%p,\n", p->cmap_regs); + printk(KERN_INFO " framebuffer to 0x%p, control regs to0x%p.\n", p->frame_buffer, p->control_regs); + /* Work out which banks of VRAM we have installed. */ /* According to Andrew Fyfe , the VRAM behaves like so: */ /* afyfe: observations from an 8500: @@ -745,14 +753,37 @@ * - with 4M vram, it appears only as a 4M block at offset 0. */ + /* Unfortunately, above is only true on 8x00 machines. 7x00 machines + * behave differently. Until somebody comes up with a way to + * differentiate between the two, you can use the vram= insmod or + * video=controlfb:vram: command-line option to force a specific + * VRAM config. + * Michel Lanners + */ + + if(vram != 0) { + bank1 = vram & 1; + bank2 = (vram & 2) / 2; + printk(KERN_INFO "controlfb: Overriding VRAM detection, set to" + " %s%s%s.\n", (bank1 && bank2) ? "4MB" : "2MB ", + (bank1 && !bank2) ? "(bank1)" : "", + (!bank1 && bank2) ? "(bank2)" : ""); + if(!bank1) { + p->control_use_bank2 = 1; + p->frame_buffer += 0x600000; + p->frame_buffer_phys += 0x600000; + } + goto detect_done; + } + /* We know there is something at 2M if there is something at 0M. */ out_8(&p->frame_buffer[0x200000], 0xa5); out_8(&p->frame_buffer[0x200001], 0x38); - asm volatile("eieio; dcbi 0,%0" : : "r" (&p->frame_buffer[0x200000]) : "memory" ); + asm volatile("eieio; dcbf 0,%0" : : "r" (&p->frame_buffer[0x200000]) : "memory" ); out_8(&p->frame_buffer[0], 0x5a); out_8(&p->frame_buffer[1], 0xc7); - asm volatile("eieio; dcbi 0,%0" : : "r" (&p->frame_buffer[0]) : "memory" ); + asm volatile("eieio; dcbf 0,%0" : : "r" (&p->frame_buffer[0]) : "memory" ); bank1 = (in_8(&p->frame_buffer[0x000000]) == 0x5a) && (in_8(&p->frame_buffer[0x000001]) == 0xc7); @@ -765,7 +796,7 @@ if(!bank1) { out_8(&p->frame_buffer[0x600000], 0xa5); out_8(&p->frame_buffer[0x600001], 0x38); - asm volatile("eieio; dcbi 0,%0" : : "r" (&p->frame_buffer[0x600000]) : "memory" ); + asm volatile("eieio; dcbf 0,%0" : : "r" (&p->frame_buffer[0x600000]) : "memory" ); bank2 = (in_8(&p->frame_buffer[0x600000]) == 0xa5) && (in_8(&p->frame_buffer[0x600001]) == 0x38); /* If we don't have bank 1 installed, we hope we have bank 2 :-) */ @@ -773,7 +804,8 @@ p->frame_buffer += 0x600000; p->frame_buffer_phys += 0x600000; } - + +detect_done: p->total_vram = (bank1 + bank2) * 0x200000; printk(KERN_INFO "controlfb: Memory bank 1 %s, bank 2 %s, total VRAM %dMB\n", @@ -1234,11 +1266,10 @@ break; memcpy(fontname, this_opt + 5, i); fontname[i] = 0; - } - if (!strncmp(this_opt, "vmode:", 6)) { + } else if (!strncmp(this_opt, "vmode:", 6)) { int vmode = simple_strtoul(this_opt+6, NULL, 0); - if (vmode > 0 && vmode <= VMODE_MAX) - default_vmode = vmode; + if (vmode > 0 && vmode <= VMODE_MAX) + default_vmode = vmode; } else if (!strncmp(this_opt, "cmode:", 6)) { int depth = simple_strtoul(this_opt+6, NULL, 0); switch (depth) { @@ -1259,6 +1290,8 @@ default_cmode = CMODE_32; break; } + } else if (!strncmp(this_opt, "vram:", 5)) { + vram = 3 & simple_strtoul(this_opt+5, NULL, 0); } } } diff -uNr linux-2.4.paul/drivers/video/controlfb.h 2.4.3-pre2-paul.20010312/drivers/video/controlfb.h --- linux-2.4.paul/drivers/video/controlfb.h Mon Jan 4 01:44:06 1999 +++ 2.4.3-pre2-paul.20010312/drivers/video/controlfb.h Mon Mar 12 20:24:22 2001 @@ -21,13 +21,13 @@ * Structure of the registers for the RADACAL colormap device. */ struct cmap_regs { - unsigned char addr; + unsigned char addr; /* REG-ADDR */ char pad1[15]; - unsigned char d1; + unsigned char d1; /* CRSR-PALETTE */ char pad2[15]; - unsigned char d2; + unsigned char d2; /* REG-DATA */ char pad3[15]; - unsigned char lut; + unsigned char lut; /* COLOR-PALETTE */ char pad4[15]; }; @@ -51,26 +51,27 @@ struct preg vesync; /* vert end sync */ struct preg vssync; /* vert start sync */ struct preg vperiod; /* vert period */ - struct preg reg8; + struct preg reg8; /* PipeDelayHWCursor */ /* Horizontal params are in units of 2 pixels */ struct preg hperiod; /* horiz period - 2 */ struct preg hsblank; /* horiz start blank */ struct preg heblank; /* horiz end blank */ struct preg hesync; /* horiz end sync */ struct preg hssync; /* horiz start sync */ - struct preg rege; - struct preg regf; - struct preg reg10; - struct preg reg11; + struct preg rege; /* HEQ */ + struct preg regf; /* HLFLN */ + struct preg reg10; /* HSERR */ + struct preg reg11; /* CNTTST */ struct preg ctrl; /* display control */ struct preg start_addr; /* start address: 5 lsbs zero */ struct preg pitch; /* addrs diff between scan lines */ struct preg mon_sense; /* monitor sense bits */ struct preg flags; struct preg mode; - struct preg reg18; - struct preg reg19; - struct preg res[6]; + struct preg refr_cnt; /* REFRESH-COUNT */ + struct preg int_en; /* interrupt enable */ + struct preg int_st; /* interrupt status */ + struct preg res[5]; }; struct control_regints { @@ -114,6 +115,7 @@ unsigned char clock_params[3]; int hres; int vres; + unsigned long sync; }; /* Register values for 1280x1024, 75Hz mode (20) */ @@ -124,7 +126,8 @@ { 1, 1, 1}, { 0x50, 0x64, 0x64 }, { 13, 56, 3 }, /* pixel clock = 134.61MHz for V=74.81Hz */ - 1280, 1024 + 1280, 1024, + 3 }; /* Register values for 1280x960, 75Hz mode (19) */ @@ -135,7 +138,8 @@ { 1, 1, 1 }, { 0x50, 0x64, 0x64 }, { 31, 125, 3 }, /* pixel clock = 126.01MHz for V=75.01 Hz */ - 1280, 960 + 1280, 960, + 0 }; /* Register values for 1152x870, 75Hz mode (18) */ @@ -146,7 +150,8 @@ { 2, 1, 1 }, { 0x10, 0x14, 0x28 }, { 19, 61, 3 }, /* pixel clock = 100.33MHz for V=75.31Hz */ - 1152, 870 + 1152, 870, + 3 }; /* Register values for 1024x768, 75Hz mode (17) */ @@ -157,10 +162,23 @@ { 2, 1, 1 }, { 0x10, 0x14, 0x28 }, { 11, 28, 3 }, /* pixel clock = 79.55MHz for V=74.50Hz */ - 1024, 768 + 1024, 768, + 3 }; -/* Register values for 1024x768, 72Hz mode 16 (15?) */ +/* Register values for 1024x768, 72Hz mode (16) */ +static struct control_regvals control_reg_init_16 = { + { 0x10, 0x28, 0x50 }, + { 1607, 1604, 68, 39, 10, 1610, 1612, 132, + 670, 653, 141, 67, 671, 34, 336, 604, }, + { 2, 1, 1 }, + { 0x10, 0x14, 0x28 }, + { 12, 30, 3 }, /* pixel clock = 78.12MHz for V=72.12Hz */ + 1024, 768, + 3 +}; + +/* Register values for 1024x768, 72Hz mode (15) */ static struct control_regvals control_reg_init_15 = { { 0x10, 0x28, 0x50 }, { 1607, 1604, 68, 39, 10, 1610, 1612, 132, @@ -168,7 +186,8 @@ { 2, 1, 1 }, { 0x10, 0x14, 0x28 }, { 12, 30, 3 }, /* pixel clock = 78.12MHz for V=72.12Hz */ - 1024, 768 + 1024, 768, + 0 }; /* Register values for 1024x768, 60Hz mode (14) */ @@ -179,7 +198,8 @@ { 2, 1, 1 }, { 0x10, 0x14, 0x28 }, { 15, 31, 3 }, /* pixel clock = 64.58MHz for V=59.62Hz */ - 1024, 768 + 1024, 768, + 0 }; /* Register values for 832x624, 75Hz mode (13) */ @@ -189,7 +209,8 @@ 574, 553, 137, 31, 575, 16, 288, 544 }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 23, 42, 3 }, /* pixel clock = 57.07MHz for V=74.27Hz */ - 832, 624 + 832, 624, + 0 }; /* Register values for 800x600, 75Hz mode (12) */ @@ -199,7 +220,8 @@ 526, 513, 113, 39, 527, 20, 264, 488, }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 7, 11, 3 }, /* pixel clock = 49.11MHz for V=74.40Hz */ - 800, 600 + 800, 600, + 3 }; /* Register values for 800x600, 72Hz mode (11) */ @@ -209,7 +231,8 @@ 518, 485, 85, 59, 519, 30, 260, 460, }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 17, 27, 3 }, /* pixel clock = 49.63MHz for V=71.66Hz */ - 800, 600 + 800, 600, + 3 }; /* Register values for 800x600, 60Hz mode (10) */ @@ -219,7 +242,8 @@ 518, 485, 85, 59, 519, 30, 260, 460, }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 20, 53, 2 }, /* pixel clock = 41.41MHz for V=59.78Hz */ - 800, 600 + 800, 600, + 3 }; /* Register values for 640x870, 75Hz Full Page Display (7) */ @@ -229,7 +253,8 @@ 0x19e, 0x18c, 0x4c, 0x27, 0x19f, 0x14, 0xd0, 0x178 }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 9, 33, 2 }, /* pixel clock = 57.29MHz for V=75.01Hz */ - 640, 870 + 640, 870, + 0 }; /* Register values for 640x480, 67Hz mode (6) */ @@ -239,7 +264,8 @@ 430, 393, 73, 31, 431, 16, 216, 400 }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 14, 27, 2 }, /* pixel clock = 30.13MHz for V=66.43Hz */ - 640, 480 + 640, 480, + 0 }; /* Register values for 640x480, 60Hz mode (5) */ @@ -249,7 +275,8 @@ 398, 385, 65, 47, 399, 24, 200, 352, }, { 2, 1, 0 }, { 0x10, 0x14, 0x18 }, { 23, 37, 2 }, /* pixel clock = 25.14MHz for V=59.85Hz */ - 640, 480 + 640, 480, + 0 }; static struct control_regvals *control_reg_init[VMODE_MAX] = { @@ -264,7 +291,7 @@ &control_reg_init_13, &control_reg_init_14, &control_reg_init_15, - &control_reg_init_15, + &control_reg_init_16, &control_reg_init_17, &control_reg_init_18, &control_reg_init_19,