Commit e15d1c12 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] tw68: refactor and cleanup the tw68 driver

Refactor and clean up the tw68 driver. It's now using the proper
V4L2 core frameworks.

Tested with my Techwell tw6805a and tw6816 grabber boards.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 5740f4e7
...@@ -20,6 +20,7 @@ source "drivers/media/pci/ivtv/Kconfig" ...@@ -20,6 +20,7 @@ source "drivers/media/pci/ivtv/Kconfig"
source "drivers/media/pci/zoran/Kconfig" source "drivers/media/pci/zoran/Kconfig"
source "drivers/media/pci/saa7146/Kconfig" source "drivers/media/pci/saa7146/Kconfig"
source "drivers/media/pci/solo6x10/Kconfig" source "drivers/media/pci/solo6x10/Kconfig"
source "drivers/media/pci/tw68/Kconfig"
endif endif
if MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT if MEDIA_ANALOG_TV_SUPPORT || MEDIA_DIGITAL_TV_SUPPORT
......
...@@ -21,6 +21,7 @@ obj-$(CONFIG_VIDEO_CX88) += cx88/ ...@@ -21,6 +21,7 @@ obj-$(CONFIG_VIDEO_CX88) += cx88/
obj-$(CONFIG_VIDEO_BT848) += bt8xx/ obj-$(CONFIG_VIDEO_BT848) += bt8xx/
obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ obj-$(CONFIG_VIDEO_SAA7134) += saa7134/
obj-$(CONFIG_VIDEO_SAA7164) += saa7164/ obj-$(CONFIG_VIDEO_SAA7164) += saa7164/
obj-$(CONFIG_VIDEO_TW68) += tw68/
obj-$(CONFIG_VIDEO_MEYE) += meye/ obj-$(CONFIG_VIDEO_MEYE) += meye/
obj-$(CONFIG_STA2X11_VIP) += sta2x11/ obj-$(CONFIG_STA2X11_VIP) += sta2x11/
obj-$(CONFIG_VIDEO_SOLO6X10) += solo6x10/ obj-$(CONFIG_VIDEO_SOLO6X10) += solo6x10/
config VIDEO_TW68
tristate "Techwell tw68x Video For Linux"
depends on VIDEO_DEV && PCI && VIDEO_V4L2
select I2C_ALGOBIT
select VIDEOBUF2_DMA_SG
---help---
Support for Techwell tw68xx based frame grabber boards.
To compile this driver as a module, choose M here: the
module will be called tw68.
tw68-objs := tw68-core.o tw68-video.o tw68-risc.o
obj-$(CONFIG_VIDEO_TW68) += tw68.o
/*
* device driver for Techwell 68xx based cards
*
* Much of this code is derived from the cx88 and sa7134 drivers, which
* were in turn derived from the bt87x driver. The original work was by
* Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
* Hans Verkuil, Andy Walls and many others. Their work is gratefully
* acknowledged. Full credit goes to them - any problems within this code
* are mine.
*
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/i2c.h> /* must appear before i2c-algo-bit.h */
#include <linux/i2c-algo-bit.h>
#include <media/v4l2-common.h>
#include <media/tveeprom.h>
#include "tw68.h"
#include "tw68-reg.h"
/* commly used strings */
#if 0
static char name_mute[] = "mute";
static char name_radio[] = "Radio";
static char name_tv[] = "Television";
static char name_tv_mono[] = "TV (mono only)";
static char name_svideo[] = "S-Video";
static char name_comp[] = "Composite";
#endif
static char name_comp1[] = "Composite1";
static char name_comp2[] = "Composite2";
static char name_comp3[] = "Composite3";
static char name_comp4[] = "Composite4";
/* ------------------------------------------------------------------ */
/* board config info */
/* If radio_type !=UNSET, radio_addr should be specified
*/
struct tw68_board tw68_boards[] = {
[TW68_BOARD_UNKNOWN] = {
.name = "GENERIC",
.tuner_type = TUNER_ABSENT,
.radio_type = UNSET,
.tuner_addr = ADDR_UNSET,
.radio_addr = ADDR_UNSET,
.inputs = {
{
.name = name_comp1,
.vmux = 0,
}, {
.name = name_comp2,
.vmux = 1,
}, {
.name = name_comp3,
.vmux = 2,
}, {
.name = name_comp4,
.vmux = 3,
}, { /* Must have a NULL entry at end of list */
.name = NULL,
.vmux = 0,
}
},
},
};
const unsigned int tw68_bcount = ARRAY_SIZE(tw68_boards);
/*
* Please add any new PCI IDs to: http://pci-ids.ucw.cz. This keeps
* the PCI ID database up to date. Note that the entries must be
* added under vendor 0x1797 (Techwell Inc.) as subsystem IDs.
*/
struct pci_device_id tw68_pci_tbl[] = {
{
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6800,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6801,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6804,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6816_1,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6816_2,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6816_3,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
.vendor = PCI_VENDOR_ID_TECHWELL,
.device = PCI_DEVICE_ID_6816_4,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.driver_data = TW68_BOARD_UNKNOWN,
}, {
/* end of list */
}
};
MODULE_DEVICE_TABLE(pci, tw68_pci_tbl);
/* ------------------------------------------------------------ */
/* stuff done before i2c enabled */
int tw68_board_init1(struct tw68_dev *dev)
{
/* Clear GPIO outputs */
tw_writel(TW68_GPOE, 0);
/* Remainder of setup according to board ID */
switch (dev->board) {
case TW68_BOARD_UNKNOWN:
printk(KERN_INFO "%s: Unable to determine board type, "
"using generic values\n", dev->name);
break;
}
dev->input = dev->hw_input = &card_in(dev,0);
return 0;
}
int tw68_tuner_setup(struct tw68_dev *dev)
{
return 0;
}
/* stuff which needs working i2c */
int tw68_board_init2(struct tw68_dev *dev)
{
return 0;
}
This diff is collapsed.
/*
* tw68 code to handle the i2c interface.
*
* Much of this code is derived from the bt87x driver. The original
* work was by Gerd Knorr; more recently the code was enhanced by Mauro
* Carvalho Chehab. Their work is gratefully acknowledged. Full credit
* goes to them - any problems within this code are mine.
*
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <linux/init.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include "tw68.h"
#include <media/v4l2-common.h>
#include <linux/i2c-algo-bit.h>
/*----------------------------------------------------------------*/
static unsigned int i2c_debug;
module_param(i2c_debug, int, 0644);
MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
#if 0
static unsigned int i2c_scan;
module_param(i2c_scan, int, 0444);
MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
#endif
#define d1printk if (1 == i2c_debug) printk
#define I2C_CLOCK 0xa6 /* 99.4 kHz */
/*----------------------------------------------------------------------*/
/* Although the TW68xx i2c controller has a "hardware" mode, where all of
* the low-level i2c/smbbus is handled by the chip, it appears that mode
* is not suitable for linux i2c handling routines because extended "bursts"
* of data (sequences of bytes without intervening START/STOP bits) are
* not possible. Instead, we put the chip into "software" mode, and handle
* the i2c bus at a low level. To accomplish this, we use the routines
* from the i2c modules.
*
* Because the particular boards which I had for testing did not have any
* devices attached to the i2c bus, I have been unable to test these
* routines.
*/
/*----------------------------------------------------------------------*/
/* I2C functions - "bit-banging" adapter (software i2c) */
/* tw68_bit_setcl
* Handles "toggling" the i2c clock bit
*/
static void tw68_bit_setscl(void *data, int state)
{
struct tw68_dev *dev = data;
tw_andorb(TW68_SBUSC, (state ? 1 : 0) << TW68_SSCLK, TW68_SSCLK_B);
}
/* tw68_bit_setsda
* Handles "toggling" the i2c data bit
*/
static void tw68_bit_setsda(void *data, int state)
{
struct tw68_dev *dev = data;
tw_andorb(TW68_SBUSC, (state ? 1 : 0) << TW68_SSDAT, TW68_SSDAT_B);
}
/* tw68_bit_getscl
*
* Returns the current state of the clock bit
*/
static int tw68_bit_getscl(void *data)
{
struct tw68_dev *dev = data;
return (tw_readb(TW68_SBUSC) & TW68_SSCLK_B) ? 1 : 0;
}
/* tw68_bit_getsda
*
* Returns the current state of the data bit
*/
static int tw68_bit_getsda(void *data)
{
struct tw68_dev *dev = data;
return (tw_readb(TW68_SBUSC) & TW68_SSDAT_B) ? 1 : 0;
}
static struct i2c_algo_bit_data __devinitdata tw68_i2c_algo_bit_template = {
.setsda = tw68_bit_setsda,
.setscl = tw68_bit_setscl,
.getsda = tw68_bit_getsda,
.getscl = tw68_bit_getscl,
.udelay = 16,
.timeout = 200,
};
static struct i2c_client tw68_client_template = {
.name = "tw68 internal",
};
/*----------------------------------------------------------------*/
static int attach_inform(struct i2c_client *client)
{
/* struct tw68_dev *dev = client->adapter->algo_data; */
d1printk("%s i2c attach [addr=0x%x,client=%s]\n",
client->driver->driver.name, client->addr, client->name);
switch (client->addr) {
/* No info yet on what addresses to expect */
}
return 0;
}
static struct i2c_adapter tw68_adap_sw_template = {
.owner = THIS_MODULE,
.name = "tw68_sw",
.client_register = attach_inform,
};
static int tw68_i2c_eeprom(struct tw68_dev *dev, unsigned char *eedata,
int len)
{
unsigned char buf;
int i, err;
dev->i2c_client.addr = 0xa0 >> 1;
buf = 256 - len;
err = i2c_master_send(&dev->i2c_client, &buf, 1);
if (1 != err) {
printk(KERN_INFO "%s: Huh, no eeprom present (err = %d)?\n",
dev->name, err);
return -1;
}
err = i2c_master_recv(&dev->i2c_client, eedata, len);
if (len != err) {
printk(KERN_WARNING "%s: i2c eeprom read error (err=%d)\n",
dev->name, err);
return -1;
}
for (i = 0; i < len; i++) {
if (0 == (i % 16))
printk(KERN_INFO "%s: i2c eeprom %02x:",
dev->name, i);
printk(KERN_INFO " %02x", eedata[i]);
if (15 == (i % 16))
printk("\n");
}
return 0;
}
#if 0
static char *i2c_devs[128] = {
[0xa0 >> 1] = "eeprom",
};
static void do_i2c_scan(char *name, struct i2c_client *c)
{
unsigned char buf;
int i, rc;
for (i = 0; i < ARRAY_SIZE(i2c_devs); i++) {
c->addr = i;
rc = i2c_master_recv(c, &buf, 1);
if (rc < 0)
continue;
printk(KERN_INFO "%s: i2c scan: found device "
"@ 0x%x [%s]\n", name, i << 1,
i2c_devs[i] ? i2c_devs[i] : "???");
}
}
#endif
int __devinit tw68_i2c_register(struct tw68_dev *dev)
{
int rc;
printk(KERN_DEBUG "%s: Registering i2c module\n", __func__);
tw_writeb(TW68_I2C_RST, 1); /* reset the i2c module */
memcpy(&dev->i2c_client, &tw68_client_template,
sizeof(tw68_client_template));
memcpy(&dev->i2c_adap, &tw68_adap_sw_template,
sizeof(tw68_adap_sw_template));
dev->i2c_adap.algo_data = &dev->i2c_algo;
dev->i2c_adap.dev.parent = &dev->pci->dev;
memcpy(&dev->i2c_algo, &tw68_i2c_algo_bit_template,
sizeof(tw68_i2c_algo_bit_template));
dev->i2c_algo.data = dev;
/* TODO - may want to set better name (see bttv code) */
i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
dev->i2c_client.adapter = &dev->i2c_adap;
/* Assure chip is in "software" mode */
tw_writel(TW68_SBUSC, TW68_SSDAT | TW68_SSCLK);
tw68_bit_setscl(dev, 1);
tw68_bit_setsda(dev, 1);
rc = i2c_bit_add_bus(&dev->i2c_adap);
tw68_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
#if 0
if (i2c_scan)
do_i2c_scan(dev->name, &dev->i2c_client);
#endif
return rc;
}
int tw68_i2c_unregister(struct tw68_dev *dev)
{
i2c_del_adapter(&dev->i2c_adap);
return 0;
}
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
* acknowledged. Full credit goes to them - any problems within this code * acknowledged. Full credit goes to them - any problems within this code
* are mine. * are mine.
* *
* Copyright (C) William M. Brack <wbrack@mmm.com.hk> * Copyright (C) William M. Brack
*
* Refactored and updated to the latest v4l core frameworks:
*
* Copyright (C) 2014 Hans Verkuil <hverkuil@xs4all.nl>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -19,10 +23,6 @@ ...@@ -19,10 +23,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#ifndef _TW68_REG_H_ #ifndef _TW68_REG_H_
......
...@@ -9,7 +9,11 @@ ...@@ -9,7 +9,11 @@
* acknowledged. Full credit goes to them - any problems within this code * acknowledged. Full credit goes to them - any problems within this code
* are mine. * are mine.
* *
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk> * Copyright (C) 2009 William M. Brack
*
* Refactored and updated to the latest v4l core frameworks:
*
* Copyright (C) 2014 Hans Verkuil <hverkuil@xs4all.nl>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -20,16 +24,10 @@ ...@@ -20,16 +24,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "tw68.h" #include "tw68.h"
#define NO_SYNC_LINE (-1U)
/** /**
* @rp pointer to current risc program position * @rp pointer to current risc program position
* @sglist pointer to "scatter-gather list" of buffer pointers * @sglist pointer to "scatter-gather list" of buffer pointers
...@@ -38,32 +36,35 @@ ...@@ -38,32 +36,35 @@
* @bpl number of bytes per scan line * @bpl number of bytes per scan line
* @padding number of bytes of padding to add * @padding number of bytes of padding to add
* @lines number of lines in field * @lines number of lines in field
* @lpi lines per IRQ, or 0 to not generate irqs * @jump insert a jump at the start
* Note: IRQ to be generated _after_ lpi lines are transferred
*/ */
static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist, static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
unsigned int offset, u32 sync_line, unsigned int offset, u32 sync_line,
unsigned int bpl, unsigned int padding, unsigned int bpl, unsigned int padding,
unsigned int lines, unsigned int lpi) unsigned int lines, bool jump)
{ {
struct scatterlist *sg; struct scatterlist *sg;
unsigned int line, todo, done; unsigned int line, todo, done;
if (jump) {
*(rp++) = cpu_to_le32(RISC_JUMP);
*(rp++) = 0;
}
/* sync instruction */ /* sync instruction */
if (sync_line != NO_SYNC_LINE) {
if (sync_line == 1) if (sync_line == 1)
*(rp++) = cpu_to_le32(RISC_SYNCO); *(rp++) = cpu_to_le32(RISC_SYNCO);
else else
*(rp++) = cpu_to_le32(RISC_SYNCE); *(rp++) = cpu_to_le32(RISC_SYNCE);
*(rp++) = 0; *(rp++) = 0;
}
/* scan lines */ /* scan lines */
sg = sglist; sg = sglist;
for (line = 0; line < lines; line++) { for (line = 0; line < lines; line++) {
/* calculate next starting position */ /* calculate next starting position */
while (offset && offset >= sg_dma_len(sg)) { while (offset && offset >= sg_dma_len(sg)) {
offset -= sg_dma_len(sg); offset -= sg_dma_len(sg);
sg++; sg = sg_next(sg);
} }
if (bpl <= sg_dma_len(sg) - offset) { if (bpl <= sg_dma_len(sg) - offset) {
/* fits into current chunk */ /* fits into current chunk */
...@@ -86,7 +87,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist, ...@@ -86,7 +87,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
done); done);
*(rp++) = cpu_to_le32(sg_dma_address(sg) + offset); *(rp++) = cpu_to_le32(sg_dma_address(sg) + offset);
todo -= done; todo -= done;
sg++; sg = sg_next(sg);
/* succeeding fragments have no offset */ /* succeeding fragments have no offset */
while (todo > sg_dma_len(sg)) { while (todo > sg_dma_len(sg)) {
*(rp++) = cpu_to_le32(RISC_INLINE | *(rp++) = cpu_to_le32(RISC_INLINE |
...@@ -94,7 +95,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist, ...@@ -94,7 +95,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
sg_dma_len(sg)); sg_dma_len(sg));
*(rp++) = cpu_to_le32(sg_dma_address(sg)); *(rp++) = cpu_to_le32(sg_dma_address(sg));
todo -= sg_dma_len(sg); todo -= sg_dma_len(sg);
sg++; sg = sg_next(sg);
done += sg_dma_len(sg); done += sg_dma_len(sg);
} }
if (todo) { if (todo) {
...@@ -107,9 +108,6 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist, ...@@ -107,9 +108,6 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
offset = todo; offset = todo;
} }
offset += padding; offset += padding;
/* If this line needs an interrupt, put it in */
if (lpi && line > 0 && !(line % lpi))
*(rp-2) |= RISC_INT_BIT;
} }
return rp; return rp;
...@@ -136,7 +134,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist, ...@@ -136,7 +134,7 @@ static __le32 *tw68_risc_field(__le32 *rp, struct scatterlist *sglist,
* @lines number of scan lines * @lines number of scan lines
*/ */
int tw68_risc_buffer(struct pci_dev *pci, int tw68_risc_buffer(struct pci_dev *pci,
struct btcx_riscmem *risc, struct tw68_buf *buf,
struct scatterlist *sglist, struct scatterlist *sglist,
unsigned int top_offset, unsigned int top_offset,
unsigned int bottom_offset, unsigned int bottom_offset,
...@@ -146,7 +144,6 @@ int tw68_risc_buffer(struct pci_dev *pci, ...@@ -146,7 +144,6 @@ int tw68_risc_buffer(struct pci_dev *pci,
{ {
u32 instructions, fields; u32 instructions, fields;
__le32 *rp; __le32 *rp;
int rc;
fields = 0; fields = 0;
if (UNSET != top_offset) if (UNSET != top_offset)
...@@ -155,29 +152,31 @@ int tw68_risc_buffer(struct pci_dev *pci, ...@@ -155,29 +152,31 @@ int tw68_risc_buffer(struct pci_dev *pci,
fields++; fields++;
/* /*
* estimate risc mem: worst case is one write per page border + * estimate risc mem: worst case is one write per page border +
* one write per scan line + syncs + jump (all 2 dwords). * one write per scan line + syncs + 2 jumps (all 2 dwords).
* Padding can cause next bpl to start close to a page border. * Padding can cause next bpl to start close to a page border.
* First DMA region may be smaller than PAGE_SIZE * First DMA region may be smaller than PAGE_SIZE
*/ */
instructions = fields * (1 + (((bpl + padding) * lines) / instructions = fields * (1 + (((bpl + padding) * lines) /
PAGE_SIZE) + lines) + 2; PAGE_SIZE) + lines) + 4;
rc = btcx_riscmem_alloc(pci, risc, instructions * 8); buf->size = instructions * 8;
if (rc < 0) buf->cpu = pci_alloc_consistent(pci, buf->size, &buf->dma);
return rc; if (buf->cpu == NULL)
return -ENOMEM;
/* write risc instructions */ /* write risc instructions */
rp = risc->cpu; rp = buf->cpu;
if (UNSET != top_offset) /* generates SYNCO */ if (UNSET != top_offset) /* generates SYNCO */
rp = tw68_risc_field(rp, sglist, top_offset, 1, rp = tw68_risc_field(rp, sglist, top_offset, 1,
bpl, padding, lines, 0); bpl, padding, lines, true);
if (UNSET != bottom_offset) /* generates SYNCE */ if (UNSET != bottom_offset) /* generates SYNCE */
rp = tw68_risc_field(rp, sglist, bottom_offset, 2, rp = tw68_risc_field(rp, sglist, bottom_offset, 2,
bpl, padding, lines, 0); bpl, padding, lines, top_offset == UNSET);
/* save pointer to jmp instruction address */ /* save pointer to jmp instruction address */
risc->jmp = rp; buf->jmp = rp;
buf->cpu[1] = cpu_to_le32(buf->dma + 8);
/* assure risc buffer hasn't overflowed */ /* assure risc buffer hasn't overflowed */
BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); BUG_ON((buf->jmp - buf->cpu + 2) * sizeof(buf->cpu[0]) > buf->size);
return 0; return 0;
} }
...@@ -204,65 +203,28 @@ static void tw68_risc_decode(u32 risc, u32 addr) ...@@ -204,65 +203,28 @@ static void tw68_risc_decode(u32 risc, u32 addr)
p = RISC_OP(risc); p = RISC_OP(risc);
if (!(risc & 0x80000000) || !instr[p].name) { if (!(risc & 0x80000000) || !instr[p].name) {
printk(KERN_DEBUG "0x%08x [ INVALID ]\n", risc); pr_debug("0x%08x [ INVALID ]\n", risc);
return; return;
} }
printk(KERN_DEBUG "0x%08x %-9s IRQ=%d", pr_debug("0x%08x %-9s IRQ=%d",
risc, instr[p].name, (risc >> 27) & 1); risc, instr[p].name, (risc >> 27) & 1);
if (instr[p].has_data_type) if (instr[p].has_data_type)
printk(KERN_DEBUG " Type=%d", (risc >> 24) & 7); pr_debug(" Type=%d", (risc >> 24) & 7);
if (instr[p].has_byte_info) if (instr[p].has_byte_info)
printk(KERN_DEBUG " Start=0x%03x Count=%03u", pr_debug(" Start=0x%03x Count=%03u",
(risc >> 12) & 0xfff, risc & 0xfff); (risc >> 12) & 0xfff, risc & 0xfff);
if (instr[p].has_addr) if (instr[p].has_addr)
printk(KERN_DEBUG " StartAddr=0x%08x", addr); pr_debug(" StartAddr=0x%08x", addr);
printk(KERN_DEBUG "\n"); pr_debug("\n");
} }
void tw68_risc_program_dump(struct tw68_core *core, void tw68_risc_program_dump(struct tw68_core *core, struct tw68_buf *buf)
struct btcx_riscmem *risc)
{ {
__le32 *addr; const __le32 *addr;
printk(KERN_DEBUG "%s: risc_program_dump: risc=%p, " pr_debug("%s: risc_program_dump: risc=%p, buf->cpu=0x%p, buf->jmp=0x%p\n",
"risc->cpu=0x%p, risc->jmp=0x%p\n", core->name, buf, buf->cpu, buf->jmp);
core->name, risc, risc->cpu, risc->jmp); for (addr = buf->cpu; addr <= buf->jmp; addr += 2)
for (addr = risc->cpu; addr <= risc->jmp; addr += 2)
tw68_risc_decode(*addr, *(addr+1)); tw68_risc_decode(*addr, *(addr+1));
} }
EXPORT_SYMBOL_GPL(tw68_risc_program_dump);
#endif #endif
/*
* tw68_risc_stopper
* Normally, the risc code generated for a buffer ends with a
* JUMP instruction to direct the DMAP processor to the code for
* the next buffer. However, when there is no additional buffer
* currently available, the code instead jumps to this routine.
*
* My first try for a "stopper" program was just a simple
* "jump to self" instruction. Unfortunately, this caused the
* video FIFO to overflow. My next attempt was to just disable
* the DMAP processor. Unfortunately, this caused the video
* decoder to lose its synchronization. The solution to this was to
* add a "Sync-Odd" instruction, which "eats" all the video data
* until the start of the next odd field.
*/
int tw68_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc)
{
__le32 *rp;
int rc;
rc = btcx_riscmem_alloc(pci, risc, 8*4);
if (rc < 0)
return rc;
/* write risc inststructions */
rp = risc->cpu;
*(rp++) = cpu_to_le32(RISC_SYNCO);
*(rp++) = 0;
*(rp++) = cpu_to_le32(RISC_JUMP);
*(rp++) = cpu_to_le32(risc->dma);
risc->jmp = risc->cpu;
return 0;
}
/*
* tw68_ts.c
* Part of the device driver for Techwell 68xx based cards
*
* Much of this code is derived from the cx88 and sa7134 drivers, which
* were in turn derived from the bt87x driver. The original work was by
* Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
* Hans Verkuil, Andy Walls and many others. Their work is gratefully
* acknowledged. Full credit goes to them - any problems within this code
* are mine.
*
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "tw68.h"
int tw68_ts_init1(struct tw68_dev *dev)
{
return 0;
}
int tw68_ts_ini(struct tw68_dev *dev)
{
return 0;
}
int tw68_ts_fini(struct tw68_dev *dev)
{
return 0;
}
void tw68_irq_ts_done(struct tw68_dev *dev, unsigned long status)
{
return;
}
int tw68_ts_register(struct tw68_mpeg_ops *ops)
{
return 0;
}
void tw68_ts_unregister(struct tw68_mpeg_ops *ops)
{
return;
}
int tw68_ts_init_hw(struct tw68_dev *dev)
{
return 0;
}
/*
* tw68_controls.c
* Part of the device driver for Techwell 68xx based cards
*
* Much of this code is derived from the cx88 and sa7134 drivers, which
* were in turn derived from the bt87x driver. The original work was by
* Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
* Hans Verkuil, Andy Walls and many others. Their work is gratefully
* acknowledged. Full credit goes to them - any problems within this code
* are mine.
*
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "tw68.h"
int tw68_tvaudio_rx2mode(u32 rx)
{
return 0;
}
void tw68_tvaudio_setmute(struct tw68_dev *dev)
{
return;
}
void tw68_tvaudio_setinput(struct tw68_dev *dev, struct tw68_input *in)
{
return;
}
void tw68_tvaudio_setvolume(struct tw68_dev *dev, int level)
{
return;
}
int tw68_tvaudio_getstereo(struct tw68_dev *dev)
{
return 0;
}
void tw68_tvaudio_init(struct tw68_dev *dev)
{
return;
}
int tw68_tvaudio_init2(struct tw68_dev *dev)
{
return 0;
}
int tw68_tvaudio_fini(struct tw68_dev *dev)
{
return 0;
}
int tw68_tvaudio_do_scan(struct tw68_dev *dev)
{
return 0;
}
void tw68_enable_i2s(struct tw68_dev *dev)
{
return;
}
/*
* tw68_controls.c
* Part of the device driver for Techwell 68xx based cards
*
* Much of this code is derived from the cx88 and sa7134 drivers, which
* were in turn derived from the bt87x driver. The original work was by
* Gerd Knorr; more recently the code was enhanced by Mauro Carvalho Chehab,
* Hans Verkuil, Andy Walls and many others. Their work is gratefully
* acknowledged. Full credit goes to them - any problems within this code
* are mine.
*
* Copyright (C) 2009 William M. Brack <wbrack@mmm.com.hk>
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "tw68.h"
static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
unsigned int *size) {
printk(KERN_INFO "%s: shouldn't be here!\n", __func__);
return 0;
}
static int buffer_prepare(struct videobuf_queue *q,
struct videobuf_buffer *vb,
enum v4l2_field field)
{
printk(KERN_INFO "%s: shouldn't be here!\n", __func__);
return 0;
}
static void buffer_queue(struct videobuf_queue *q,
struct videobuf_buffer *vb)
{
printk(KERN_INFO "%s: shouldn't be here!\n", __func__);
}
static void buffer_release(struct videobuf_queue *q,
struct videobuf_buffer *vb)
{
printk(KERN_INFO "%s: shouldn't be here!\n", __func__);
}
struct videobuf_queue_ops tw68_vbi_qops = {
.buf_setup = buffer_setup,
.buf_prepare = buffer_prepare,
.buf_queue = buffer_queue,
.buf_release = buffer_release,
};
/* ------------------------------------------------------------------ */
int tw68_vbi_init1(struct tw68_dev *dev)
{
return 0;
}
int tw68_vbi_fini(struct tw68_dev *dev)
{
return 0;
}
void tw68_irq_vbi_done(struct tw68_dev *dev, unsigned long status)
{
return;
}
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment