You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
Staging: add the go7007 video driver
Todo: - checkpatch.pl cleanups - sparse cleanups - lots of little modules, should be merged together and added to the build. - testing? - handle churn in v4l layer. Many thanks to Ross Cohen <rcohen@snurgle.org> for cleanup patches on this driver. Cc: Ross Cohen <rcohen@snurgle.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
@@ -31,4 +31,6 @@ source "drivers/staging/sxg/Kconfig"
|
||||
|
||||
source "drivers/staging/me4000/Kconfig"
|
||||
|
||||
source "drivers/staging/go7007/Kconfig"
|
||||
|
||||
endif # STAGING
|
||||
|
||||
@@ -4,3 +4,4 @@ obj-$(CONFIG_ET131X) += et131x/
|
||||
obj-$(CONFIG_SLICOSS) += slicoss/
|
||||
obj-$(CONFIG_SXG) += sxg/
|
||||
obj-$(CONFIG_ME4000) += me4000/
|
||||
obj-$(CONFIG_VIDEO_GO7007) += go7007/
|
||||
|
||||
25
drivers/staging/go7007/Kconfig
Normal file
25
drivers/staging/go7007/Kconfig
Normal file
@@ -0,0 +1,25 @@
|
||||
config VIDEO_GO7007
|
||||
tristate "Go 7007 support"
|
||||
depends on VIDEO_DEV && PCI && I2C && INPUT
|
||||
select VIDEOBUF_DMA_SG
|
||||
select VIDEO_IR
|
||||
select VIDEO_TUNER
|
||||
select VIDEO_TVEEPROM
|
||||
select CRC32
|
||||
default N
|
||||
---help---
|
||||
This is a video4linux driver for some wierd device...
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called go7007
|
||||
|
||||
config VIDEO_GO7007_USB
|
||||
tristate "Go 7007 USB support"
|
||||
depends on VIDEO_GO7007 && USB
|
||||
default N
|
||||
---help---
|
||||
This is a video4linux driver for some wierd device...
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called go7007-usb
|
||||
|
||||
18
drivers/staging/go7007/Makefile
Normal file
18
drivers/staging/go7007/Makefile
Normal file
@@ -0,0 +1,18 @@
|
||||
#obj-m += go7007.o go7007-usb.o snd-go7007.o wis-saa7115.o wis-tw9903.o \
|
||||
wis-uda1342.o wis-sony-tuner.o wis-saa7113.o wis-ov7640.o \
|
||||
wis-tw2804.o
|
||||
|
||||
|
||||
obj-$(CONFIG_VIDEO_GO7007) += go7007.o
|
||||
obj-$(CONFIG_VIDEO_GO7007_USB) += go7007-usb.o
|
||||
|
||||
go7007-objs += go7007-v4l2.o go7007-driver.o go7007-i2c.o go7007-fw.o snd-go7007.o
|
||||
|
||||
|
||||
#ifneq ($(SAA7134_BUILD),)
|
||||
#obj-m += saa7134-go7007.o
|
||||
#endif
|
||||
|
||||
EXTRA_CFLAGS += -Idrivers/staging/saa7134
|
||||
EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
|
||||
EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
|
||||
11
drivers/staging/go7007/README
Normal file
11
drivers/staging/go7007/README
Normal file
@@ -0,0 +1,11 @@
|
||||
Todo:
|
||||
- checkpatch.pl cleanups
|
||||
- sparse cleanups
|
||||
- lots of little modules, should be merged together
|
||||
and added to the build.
|
||||
- testing?
|
||||
- handle churn in v4l layer.
|
||||
|
||||
Please send patchs to Greg Kroah-Hartman <greg@kroah.com> and Cc: Ross
|
||||
Cohen <rcohen@snurgle.org> as well.
|
||||
|
||||
688
drivers/staging/go7007/go7007-driver.c
Normal file
688
drivers/staging/go7007/go7007-driver.c
Normal file
File diff suppressed because it is too large
Load Diff
1639
drivers/staging/go7007/go7007-fw.c
Normal file
1639
drivers/staging/go7007/go7007-fw.c
Normal file
File diff suppressed because it is too large
Load Diff
309
drivers/staging/go7007/go7007-i2c.c
Normal file
309
drivers/staging/go7007/go7007-i2c.c
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/unistd.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <asm/system.h>
|
||||
|
||||
#include "go7007-priv.h"
|
||||
#include "wis-i2c.h"
|
||||
|
||||
/************** Registration interface for I2C client drivers **************/
|
||||
|
||||
/* Since there's no way to auto-probe the I2C devices connected to the I2C
|
||||
* bus on the go7007, we have this silly little registration system that
|
||||
* client drivers can use to register their I2C driver ID and their
|
||||
* detect_client function (the one that's normally passed to i2c_probe).
|
||||
*
|
||||
* When a new go7007 device is connected, we can look up in a board info
|
||||
* table by the USB or PCI vendor/product/revision ID to determine
|
||||
* which I2C client module to load. The client driver module will register
|
||||
* itself here, and then we can call the registered detect_client function
|
||||
* to force-load a new client at the address listed in the board info table.
|
||||
*
|
||||
* Really the I2C subsystem should have a way to force-load I2C client
|
||||
* drivers when we have a priori knowledge of what's on the bus, especially
|
||||
* since the existing I2C auto-probe mechanism is so hokey, but we'll use
|
||||
* our own mechanism for the time being. */
|
||||
|
||||
struct wis_i2c_client_driver {
|
||||
unsigned int id;
|
||||
found_proc found_proc;
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
static LIST_HEAD(i2c_client_drivers);
|
||||
static DECLARE_MUTEX(i2c_client_driver_list_lock);
|
||||
|
||||
/* Client drivers register here by their I2C driver ID */
|
||||
int wis_i2c_add_driver(unsigned int id, found_proc found_proc)
|
||||
{
|
||||
struct wis_i2c_client_driver *driver;
|
||||
|
||||
driver = kmalloc(sizeof(struct wis_i2c_client_driver), GFP_KERNEL);
|
||||
if (driver == NULL)
|
||||
return -ENOMEM;
|
||||
driver->id = id;
|
||||
driver->found_proc = found_proc;
|
||||
|
||||
down(&i2c_client_driver_list_lock);
|
||||
list_add_tail(&driver->list, &i2c_client_drivers);
|
||||
up(&i2c_client_driver_list_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(wis_i2c_add_driver);
|
||||
|
||||
void wis_i2c_del_driver(found_proc found_proc)
|
||||
{
|
||||
struct wis_i2c_client_driver *driver, *next;
|
||||
|
||||
down(&i2c_client_driver_list_lock);
|
||||
list_for_each_entry_safe(driver, next, &i2c_client_drivers, list)
|
||||
if (driver->found_proc == found_proc) {
|
||||
list_del(&driver->list);
|
||||
kfree(driver);
|
||||
}
|
||||
up(&i2c_client_driver_list_lock);
|
||||
}
|
||||
EXPORT_SYMBOL(wis_i2c_del_driver);
|
||||
|
||||
/* The main go7007 driver calls this to instantiate a client by driver
|
||||
* ID and bus address, which are both stored in the board info table */
|
||||
int wis_i2c_probe_device(struct i2c_adapter *adapter,
|
||||
unsigned int id, int addr)
|
||||
{
|
||||
struct wis_i2c_client_driver *driver;
|
||||
int found = 0;
|
||||
|
||||
if (addr < 0 || addr > 0x7f)
|
||||
return -1;
|
||||
down(&i2c_client_driver_list_lock);
|
||||
list_for_each_entry(driver, &i2c_client_drivers, list)
|
||||
if (driver->id == id) {
|
||||
if (driver->found_proc(adapter, addr, 0) == 0)
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
up(&i2c_client_driver_list_lock);
|
||||
return found;
|
||||
}
|
||||
|
||||
/********************* Driver for on-board I2C adapter *********************/
|
||||
|
||||
/* #define GO7007_I2C_DEBUG */
|
||||
|
||||
#define SPI_I2C_ADDR_BASE 0x1400
|
||||
#define STATUS_REG_ADDR (SPI_I2C_ADDR_BASE + 0x2)
|
||||
#define I2C_CTRL_REG_ADDR (SPI_I2C_ADDR_BASE + 0x6)
|
||||
#define I2C_DEV_UP_ADDR_REG_ADDR (SPI_I2C_ADDR_BASE + 0x7)
|
||||
#define I2C_LO_ADDR_REG_ADDR (SPI_I2C_ADDR_BASE + 0x8)
|
||||
#define I2C_DATA_REG_ADDR (SPI_I2C_ADDR_BASE + 0x9)
|
||||
#define I2C_CLKFREQ_REG_ADDR (SPI_I2C_ADDR_BASE + 0xa)
|
||||
|
||||
#define I2C_STATE_MASK 0x0007
|
||||
#define I2C_READ_READY_MASK 0x0008
|
||||
|
||||
/* There is only one I2C port on the TW2804 that feeds all four GO7007 VIPs
|
||||
* on the Adlink PCI-MPG24, so access is shared between all of them. */
|
||||
static DECLARE_MUTEX(adlink_mpg24_i2c_lock);
|
||||
|
||||
static int go7007_i2c_xfer(struct go7007 *go, u16 addr, int read,
|
||||
u16 command, int flags, u8 *data)
|
||||
{
|
||||
int i, ret = -1;
|
||||
u16 val;
|
||||
|
||||
if (go->status == STATUS_SHUTDOWN)
|
||||
return -1;
|
||||
|
||||
#ifdef GO7007_I2C_DEBUG
|
||||
if (read)
|
||||
printk(KERN_DEBUG "go7007-i2c: reading 0x%02x on 0x%02x\n",
|
||||
command, addr);
|
||||
else
|
||||
printk(KERN_DEBUG
|
||||
"go7007-i2c: writing 0x%02x to 0x%02x on 0x%02x\n",
|
||||
*data, command, addr);
|
||||
#endif
|
||||
|
||||
down(&go->hw_lock);
|
||||
|
||||
if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) {
|
||||
/* Bridge the I2C port on this GO7007 to the shared bus */
|
||||
down(&adlink_mpg24_i2c_lock);
|
||||
go7007_write_addr(go, 0x3c82, 0x0020);
|
||||
}
|
||||
|
||||
/* Wait for I2C adapter to be ready */
|
||||
for (i = 0; i < 10; ++i) {
|
||||
if (go7007_read_addr(go, STATUS_REG_ADDR, &val) < 0)
|
||||
goto i2c_done;
|
||||
if (!(val & I2C_STATE_MASK))
|
||||
break;
|
||||
msleep(100);
|
||||
}
|
||||
if (i == 10) {
|
||||
printk(KERN_ERR "go7007-i2c: I2C adapter is hung\n");
|
||||
goto i2c_done;
|
||||
}
|
||||
|
||||
/* Set target register (command) */
|
||||
go7007_write_addr(go, I2C_CTRL_REG_ADDR, flags);
|
||||
go7007_write_addr(go, I2C_LO_ADDR_REG_ADDR, command);
|
||||
|
||||
/* If we're writing, send the data and target address and we're done */
|
||||
if (!read) {
|
||||
go7007_write_addr(go, I2C_DATA_REG_ADDR, *data);
|
||||
go7007_write_addr(go, I2C_DEV_UP_ADDR_REG_ADDR,
|
||||
(addr << 9) | (command >> 8));
|
||||
ret = 0;
|
||||
goto i2c_done;
|
||||
}
|
||||
|
||||
/* Otherwise, we're reading. First clear i2c_rx_data_rdy. */
|
||||
if (go7007_read_addr(go, I2C_DATA_REG_ADDR, &val) < 0)
|
||||
goto i2c_done;
|
||||
|
||||
/* Send the target address plus read flag */
|
||||
go7007_write_addr(go, I2C_DEV_UP_ADDR_REG_ADDR,
|
||||
(addr << 9) | 0x0100 | (command >> 8));
|
||||
|
||||
/* Wait for i2c_rx_data_rdy */
|
||||
for (i = 0; i < 10; ++i) {
|
||||
if (go7007_read_addr(go, STATUS_REG_ADDR, &val) < 0)
|
||||
goto i2c_done;
|
||||
if (val & I2C_READ_READY_MASK)
|
||||
break;
|
||||
msleep(100);
|
||||
}
|
||||
if (i == 10) {
|
||||
printk(KERN_ERR "go7007-i2c: I2C adapter is hung\n");
|
||||
goto i2c_done;
|
||||
}
|
||||
|
||||
/* Retrieve the read byte */
|
||||
if (go7007_read_addr(go, I2C_DATA_REG_ADDR, &val) < 0)
|
||||
goto i2c_done;
|
||||
*data = val;
|
||||
ret = 0;
|
||||
|
||||
i2c_done:
|
||||
if (go->board_id == GO7007_BOARDID_ADLINK_MPG24) {
|
||||
/* Isolate the I2C port on this GO7007 from the shared bus */
|
||||
go7007_write_addr(go, 0x3c82, 0x0000);
|
||||
up(&adlink_mpg24_i2c_lock);
|
||||
}
|
||||
up(&go->hw_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int go7007_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data *data)
|
||||
{
|
||||
struct go7007 *go = i2c_get_adapdata(adapter);
|
||||
|
||||
if (size != I2C_SMBUS_BYTE_DATA)
|
||||
return -1;
|
||||
return go7007_i2c_xfer(go, addr, read_write == I2C_SMBUS_READ, command,
|
||||
flags & I2C_CLIENT_SCCB ? 0x10 : 0x00, &data->byte);
|
||||
}
|
||||
|
||||
/* VERY LIMITED I2C master xfer function -- only needed because the
|
||||
* SMBus functions only support 8-bit commands and the SAA7135 uses
|
||||
* 16-bit commands. The I2C interface on the GO7007, as limited as
|
||||
* it is, does support this mode. */
|
||||
|
||||
static int go7007_i2c_master_xfer(struct i2c_adapter *adapter,
|
||||
struct i2c_msg msgs[], int num)
|
||||
{
|
||||
struct go7007 *go = i2c_get_adapdata(adapter);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num; ++i) {
|
||||
/* We can only do two things here -- write three bytes, or
|
||||
* write two bytes and read one byte. */
|
||||
if (msgs[i].len == 2) {
|
||||
if (i + 1 == num || msgs[i].addr != msgs[i + 1].addr ||
|
||||
(msgs[i].flags & I2C_M_RD) ||
|
||||
!(msgs[i + 1].flags & I2C_M_RD) ||
|
||||
msgs[i + 1].len != 1)
|
||||
return -1;
|
||||
if (go7007_i2c_xfer(go, msgs[i].addr, 1,
|
||||
(msgs[i].buf[0] << 8) | msgs[i].buf[1],
|
||||
0x01, &msgs[i + 1].buf[0]) < 0)
|
||||
return -1;
|
||||
++i;
|
||||
} else if (msgs[i].len == 3) {
|
||||
if (msgs[i].flags & I2C_M_RD)
|
||||
return -1;
|
||||
if (msgs[i].len != 3)
|
||||
return -1;
|
||||
if (go7007_i2c_xfer(go, msgs[i].addr, 0,
|
||||
(msgs[i].buf[0] << 8) | msgs[i].buf[1],
|
||||
0x01, &msgs[i].buf[2]) < 0)
|
||||
return -1;
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 go7007_functionality(struct i2c_adapter *adapter)
|
||||
{
|
||||
return I2C_FUNC_SMBUS_BYTE_DATA;
|
||||
}
|
||||
|
||||
static struct i2c_algorithm go7007_algo = {
|
||||
.smbus_xfer = go7007_smbus_xfer,
|
||||
.master_xfer = go7007_i2c_master_xfer,
|
||||
.functionality = go7007_functionality,
|
||||
};
|
||||
|
||||
static struct i2c_adapter go7007_adap_templ = {
|
||||
.owner = THIS_MODULE,
|
||||
.class = I2C_CLASS_TV_ANALOG,
|
||||
.name = "WIS GO7007SB",
|
||||
.id = I2C_ALGO_GO7007,
|
||||
.algo = &go7007_algo,
|
||||
};
|
||||
|
||||
int go7007_i2c_init(struct go7007 *go)
|
||||
{
|
||||
memcpy(&go->i2c_adapter, &go7007_adap_templ,
|
||||
sizeof(go7007_adap_templ));
|
||||
go->i2c_adapter.dev.parent = go->dev;
|
||||
i2c_set_adapdata(&go->i2c_adapter, go);
|
||||
if (i2c_add_adapter(&go->i2c_adapter) < 0) {
|
||||
printk(KERN_ERR
|
||||
"go7007-i2c: error: i2c_add_adapter failed\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
279
drivers/staging/go7007/go7007-priv.h
Normal file
279
drivers/staging/go7007/go7007-priv.h
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the private include file for the go7007 driver. It should not
|
||||
* be included by anybody but the driver itself, and especially not by
|
||||
* user-space applications.
|
||||
*/
|
||||
|
||||
struct go7007;
|
||||
|
||||
/* IDs to activate board-specific support code */
|
||||
#define GO7007_BOARDID_MATRIX_II 0
|
||||
#define GO7007_BOARDID_MATRIX_RELOAD 1
|
||||
#define GO7007_BOARDID_STAR_TREK 2
|
||||
#define GO7007_BOARDID_PCI_VOYAGER 3
|
||||
#define GO7007_BOARDID_XMEN 4
|
||||
#define GO7007_BOARDID_XMEN_II 5
|
||||
#define GO7007_BOARDID_XMEN_III 6
|
||||
#define GO7007_BOARDID_MATRIX_REV 7
|
||||
#define GO7007_BOARDID_PX_M402U 16
|
||||
#define GO7007_BOARDID_PX_TV402U_ANY 17 /* need to check tuner model */
|
||||
#define GO7007_BOARDID_PX_TV402U_NA 18 /* detected NTSC tuner */
|
||||
#define GO7007_BOARDID_PX_TV402U_EU 19 /* detected PAL tuner */
|
||||
#define GO7007_BOARDID_PX_TV402U_JP 20 /* detected NTSC-J tuner */
|
||||
#define GO7007_BOARDID_LIFEVIEW_LR192 21 /* TV Walker Ultra */
|
||||
#define GO7007_BOARDID_ENDURA 22
|
||||
#define GO7007_BOARDID_ADLINK_MPG24 23
|
||||
|
||||
/* Various characteristics of each board */
|
||||
#define GO7007_BOARD_HAS_AUDIO (1<<0)
|
||||
#define GO7007_BOARD_USE_ONBOARD_I2C (1<<1)
|
||||
#define GO7007_BOARD_HAS_TUNER (1<<2)
|
||||
|
||||
/* Characteristics of sensor devices */
|
||||
#define GO7007_SENSOR_VALID_POLAR (1<<0)
|
||||
#define GO7007_SENSOR_HREF_POLAR (1<<1)
|
||||
#define GO7007_SENSOR_VREF_POLAR (1<<2)
|
||||
#define GO7007_SENSOR_FIELD_ID_POLAR (1<<3)
|
||||
#define GO7007_SENSOR_BIT_WIDTH (1<<4)
|
||||
#define GO7007_SENSOR_VALID_ENABLE (1<<5)
|
||||
#define GO7007_SENSOR_656 (1<<6)
|
||||
#define GO7007_SENSOR_CONFIG_MASK 0x7f
|
||||
#define GO7007_SENSOR_TV (1<<7)
|
||||
#define GO7007_SENSOR_VBI (1<<8)
|
||||
#define GO7007_SENSOR_SCALING (1<<9)
|
||||
|
||||
/* Characteristics of audio sensor devices */
|
||||
#define GO7007_AUDIO_I2S_MODE_1 (1)
|
||||
#define GO7007_AUDIO_I2S_MODE_2 (2)
|
||||
#define GO7007_AUDIO_I2S_MODE_3 (3)
|
||||
#define GO7007_AUDIO_BCLK_POLAR (1<<2)
|
||||
#define GO7007_AUDIO_WORD_14 (14<<4)
|
||||
#define GO7007_AUDIO_WORD_16 (16<<4)
|
||||
#define GO7007_AUDIO_ONE_CHANNEL (1<<11)
|
||||
#define GO7007_AUDIO_I2S_MASTER (1<<16)
|
||||
#define GO7007_AUDIO_OKI_MODE (1<<17)
|
||||
|
||||
struct go7007_board_info {
|
||||
char *firmware;
|
||||
unsigned int flags;
|
||||
int hpi_buffer_cap;
|
||||
unsigned int sensor_flags;
|
||||
int sensor_width;
|
||||
int sensor_height;
|
||||
int sensor_framerate;
|
||||
int sensor_h_offset;
|
||||
int sensor_v_offset;
|
||||
unsigned int audio_flags;
|
||||
int audio_rate;
|
||||
int audio_bclk_div;
|
||||
int audio_main_div;
|
||||
int num_i2c_devs;
|
||||
struct {
|
||||
int id;
|
||||
int addr;
|
||||
} i2c_devs[4];
|
||||
int num_inputs;
|
||||
struct {
|
||||
int video_input;
|
||||
int audio_input;
|
||||
char *name;
|
||||
} inputs[4];
|
||||
};
|
||||
|
||||
struct go7007_hpi_ops {
|
||||
int (*interface_reset)(struct go7007 *go);
|
||||
int (*write_interrupt)(struct go7007 *go, int addr, int data);
|
||||
int (*read_interrupt)(struct go7007 *go);
|
||||
int (*stream_start)(struct go7007 *go);
|
||||
int (*stream_stop)(struct go7007 *go);
|
||||
int (*send_firmware)(struct go7007 *go, u8 *data, int len);
|
||||
};
|
||||
|
||||
/* The video buffer size must be a multiple of PAGE_SIZE */
|
||||
#define GO7007_BUF_PAGES (128 * 1024 / PAGE_SIZE)
|
||||
#define GO7007_BUF_SIZE (GO7007_BUF_PAGES << PAGE_SHIFT)
|
||||
|
||||
struct go7007_buffer {
|
||||
struct go7007 *go; /* Reverse reference for VMA ops */
|
||||
int index; /* Reverse reference for DQBUF */
|
||||
enum { BUF_STATE_IDLE, BUF_STATE_QUEUED, BUF_STATE_DONE } state;
|
||||
u32 seq;
|
||||
struct timeval timestamp;
|
||||
struct list_head stream;
|
||||
struct page *pages[GO7007_BUF_PAGES + 1]; /* extra for straddling */
|
||||
unsigned long user_addr;
|
||||
unsigned int page_count;
|
||||
unsigned int offset;
|
||||
unsigned int bytesused;
|
||||
unsigned int frame_offset;
|
||||
u32 modet_active;
|
||||
int mapped;
|
||||
};
|
||||
|
||||
struct go7007_file {
|
||||
struct go7007 *go;
|
||||
struct semaphore lock;
|
||||
int buf_count;
|
||||
struct go7007_buffer *bufs;
|
||||
};
|
||||
|
||||
#define GO7007_FORMAT_MJPEG 0
|
||||
#define GO7007_FORMAT_MPEG4 1
|
||||
#define GO7007_FORMAT_MPEG1 2
|
||||
#define GO7007_FORMAT_MPEG2 3
|
||||
#define GO7007_FORMAT_H263 4
|
||||
|
||||
#define GO7007_RATIO_1_1 0
|
||||
#define GO7007_RATIO_4_3 1
|
||||
#define GO7007_RATIO_16_9 2
|
||||
|
||||
enum go7007_parser_state {
|
||||
STATE_DATA,
|
||||
STATE_00,
|
||||
STATE_00_00,
|
||||
STATE_00_00_01,
|
||||
STATE_FF,
|
||||
STATE_VBI_LEN_A,
|
||||
STATE_VBI_LEN_B,
|
||||
STATE_MODET_MAP,
|
||||
STATE_UNPARSED,
|
||||
};
|
||||
|
||||
struct go7007 {
|
||||
struct device *dev;
|
||||
struct go7007_board_info *board_info;
|
||||
unsigned int board_id;
|
||||
int tuner_type;
|
||||
int channel_number; /* for multi-channel boards like Adlink PCI-MPG24 */
|
||||
char name[64];
|
||||
struct video_device *video_dev;
|
||||
int ref_count;
|
||||
enum { STATUS_INIT, STATUS_ONLINE, STATUS_SHUTDOWN } status;
|
||||
spinlock_t spinlock;
|
||||
struct semaphore hw_lock;
|
||||
int streaming;
|
||||
int in_use;
|
||||
int audio_enabled;
|
||||
|
||||
/* Video input */
|
||||
int input;
|
||||
enum { GO7007_STD_NTSC, GO7007_STD_PAL, GO7007_STD_OTHER } standard;
|
||||
int sensor_framerate;
|
||||
int width;
|
||||
int height;
|
||||
int encoder_h_offset;
|
||||
int encoder_v_offset;
|
||||
unsigned int encoder_h_halve:1;
|
||||
unsigned int encoder_v_halve:1;
|
||||
unsigned int encoder_subsample:1;
|
||||
|
||||
/* Encoder config */
|
||||
int format;
|
||||
int bitrate;
|
||||
int fps_scale;
|
||||
int pali;
|
||||
int aspect_ratio;
|
||||
int gop_size;
|
||||
unsigned int ipb:1;
|
||||
unsigned int closed_gop:1;
|
||||
unsigned int repeat_seqhead:1;
|
||||
unsigned int seq_header_enable:1;
|
||||
unsigned int gop_header_enable:1;
|
||||
unsigned int dvd_mode:1;
|
||||
unsigned int interlace_coding:1;
|
||||
|
||||
/* Motion detection */
|
||||
unsigned int modet_enable:1;
|
||||
struct {
|
||||
unsigned int enable:1;
|
||||
int pixel_threshold;
|
||||
int motion_threshold;
|
||||
int mb_threshold;
|
||||
} modet[4];
|
||||
unsigned char modet_map[1624];
|
||||
unsigned char active_map[216];
|
||||
|
||||
/* Video streaming */
|
||||
struct go7007_buffer *active_buf;
|
||||
enum go7007_parser_state state;
|
||||
int parse_length;
|
||||
u16 modet_word;
|
||||
int seen_frame;
|
||||
u32 next_seq;
|
||||
struct list_head stream;
|
||||
wait_queue_head_t frame_waitq;
|
||||
|
||||
/* Audio streaming */
|
||||
void (*audio_deliver)(struct go7007 *go, u8 *buf, int length);
|
||||
void *snd_context;
|
||||
|
||||
/* I2C */
|
||||
int i2c_adapter_online;
|
||||
struct i2c_adapter i2c_adapter;
|
||||
|
||||
/* HPI driver */
|
||||
struct go7007_hpi_ops *hpi_ops;
|
||||
void *hpi_context;
|
||||
int interrupt_available;
|
||||
wait_queue_head_t interrupt_waitq;
|
||||
unsigned short interrupt_value;
|
||||
unsigned short interrupt_data;
|
||||
};
|
||||
|
||||
/* All of these must be called with the hpi_lock semaphore held! */
|
||||
#define go7007_interface_reset(go) \
|
||||
((go)->hpi_ops->interface_reset(go))
|
||||
#define go7007_write_interrupt(go, x, y) \
|
||||
((go)->hpi_ops->write_interrupt)((go), (x), (y))
|
||||
#define go7007_stream_start(go) \
|
||||
((go)->hpi_ops->stream_start(go))
|
||||
#define go7007_stream_stop(go) \
|
||||
((go)->hpi_ops->stream_stop(go))
|
||||
#define go7007_send_firmware(go, x, y) \
|
||||
((go)->hpi_ops->send_firmware)((go), (x), (y))
|
||||
#define go7007_write_addr(go, x, y) \
|
||||
((go)->hpi_ops->write_interrupt)((go), (x)|0x8000, (y))
|
||||
|
||||
/* go7007-driver.c */
|
||||
int go7007_read_addr(struct go7007 *go, u16 addr, u16 *data);
|
||||
int go7007_read_interrupt(struct go7007 *go, u16 *value, u16 *data);
|
||||
int go7007_boot_encoder(struct go7007 *go, int init_i2c);
|
||||
int go7007_reset_encoder(struct go7007 *go);
|
||||
int go7007_register_encoder(struct go7007 *go);
|
||||
int go7007_start_encoder(struct go7007 *go);
|
||||
void go7007_parse_video_stream(struct go7007 *go, u8 *buf, int length);
|
||||
struct go7007 *go7007_alloc(struct go7007_board_info *board,
|
||||
struct device *dev);
|
||||
void go7007_remove(struct go7007 *go);
|
||||
|
||||
/* go7007-fw.c */
|
||||
int go7007_construct_fw_image(struct go7007 *go, u8 **fw, int *fwlen);
|
||||
|
||||
/* go7007-i2c.c */
|
||||
int go7007_i2c_init(struct go7007 *go);
|
||||
int go7007_i2c_remove(struct go7007 *go);
|
||||
|
||||
/* go7007-v4l2.c */
|
||||
int go7007_v4l2_init(struct go7007 *go);
|
||||
void go7007_v4l2_remove(struct go7007 *go);
|
||||
|
||||
/* snd-go7007.c */
|
||||
int go7007_snd_init(struct go7007 *go);
|
||||
int go7007_snd_remove(struct go7007 *go);
|
||||
1229
drivers/staging/go7007/go7007-usb.c
Normal file
1229
drivers/staging/go7007/go7007-usb.c
Normal file
File diff suppressed because it is too large
Load Diff
1503
drivers/staging/go7007/go7007-v4l2.c
Normal file
1503
drivers/staging/go7007/go7007-v4l2.c
Normal file
File diff suppressed because it is too large
Load Diff
114
drivers/staging/go7007/go7007.h
Normal file
114
drivers/staging/go7007/go7007.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and the associated README documentation file (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* DEPRECATED -- use V4L2_PIX_FMT_MPEG and then call GO7007IOC_S_MPEG_PARAMS
|
||||
* to select between MPEG1, MPEG2, and MPEG4 */
|
||||
#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG4 */
|
||||
|
||||
/* These will be replaced with a better interface
|
||||
* soon, so don't get too attached to them */
|
||||
#define GO7007IOC_S_BITRATE _IOW('V', BASE_VIDIOC_PRIVATE + 0, int)
|
||||
#define GO7007IOC_G_BITRATE _IOR('V', BASE_VIDIOC_PRIVATE + 1, int)
|
||||
|
||||
enum go7007_aspect_ratio {
|
||||
GO7007_ASPECT_RATIO_1_1 = 0,
|
||||
GO7007_ASPECT_RATIO_4_3_NTSC = 1,
|
||||
GO7007_ASPECT_RATIO_4_3_PAL = 2,
|
||||
GO7007_ASPECT_RATIO_16_9_NTSC = 3,
|
||||
GO7007_ASPECT_RATIO_16_9_PAL = 4,
|
||||
};
|
||||
|
||||
/* Used to set generic compression parameters */
|
||||
struct go7007_comp_params {
|
||||
__u32 gop_size;
|
||||
__u32 max_b_frames;
|
||||
enum go7007_aspect_ratio aspect_ratio;
|
||||
__u32 flags;
|
||||
__u32 reserved[8];
|
||||
};
|
||||
|
||||
#define GO7007_COMP_CLOSED_GOP 0x00000001
|
||||
#define GO7007_COMP_OMIT_SEQ_HEADER 0x00000002
|
||||
|
||||
enum go7007_mpeg_video_standard {
|
||||
GO7007_MPEG_VIDEO_MPEG1 = 0,
|
||||
GO7007_MPEG_VIDEO_MPEG2 = 1,
|
||||
GO7007_MPEG_VIDEO_MPEG4 = 2,
|
||||
};
|
||||
|
||||
/* Used to set parameters for V4L2_PIX_FMT_MPEG format */
|
||||
struct go7007_mpeg_params {
|
||||
enum go7007_mpeg_video_standard mpeg_video_standard;
|
||||
__u32 flags;
|
||||
__u32 pali;
|
||||
__u32 reserved[8];
|
||||
};
|
||||
|
||||
#define GO7007_MPEG_FORCE_DVD_MODE 0x00000001
|
||||
#define GO7007_MPEG_OMIT_GOP_HEADER 0x00000002
|
||||
#define GO7007_MPEG_REPEAT_SEQHEADER 0x00000004
|
||||
|
||||
#define GO7007_MPEG_PROFILE(format, pali) (((format)<<24)|(pali))
|
||||
|
||||
#define GO7007_MPEG2_PROFILE_MAIN_MAIN GO7007_MPEG_PROFILE(2, 0x48)
|
||||
|
||||
#define GO7007_MPEG4_PROFILE_S_L0 GO7007_MPEG_PROFILE(4, 0x08)
|
||||
#define GO7007_MPEG4_PROFILE_S_L1 GO7007_MPEG_PROFILE(4, 0x01)
|
||||
#define GO7007_MPEG4_PROFILE_S_L2 GO7007_MPEG_PROFILE(4, 0x02)
|
||||
#define GO7007_MPEG4_PROFILE_S_L3 GO7007_MPEG_PROFILE(4, 0x03)
|
||||
#define GO7007_MPEG4_PROFILE_ARTS_L1 GO7007_MPEG_PROFILE(4, 0x91)
|
||||
#define GO7007_MPEG4_PROFILE_ARTS_L2 GO7007_MPEG_PROFILE(4, 0x92)
|
||||
#define GO7007_MPEG4_PROFILE_ARTS_L3 GO7007_MPEG_PROFILE(4, 0x93)
|
||||
#define GO7007_MPEG4_PROFILE_ARTS_L4 GO7007_MPEG_PROFILE(4, 0x94)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L0 GO7007_MPEG_PROFILE(4, 0xf0)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L1 GO7007_MPEG_PROFILE(4, 0xf1)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L2 GO7007_MPEG_PROFILE(4, 0xf2)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L3 GO7007_MPEG_PROFILE(4, 0xf3)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L4 GO7007_MPEG_PROFILE(4, 0xf4)
|
||||
#define GO7007_MPEG4_PROFILE_AS_L5 GO7007_MPEG_PROFILE(4, 0xf5)
|
||||
|
||||
struct go7007_md_params {
|
||||
__u16 region;
|
||||
__u16 trigger;
|
||||
__u16 pixel_threshold;
|
||||
__u16 motion_threshold;
|
||||
__u32 reserved[8];
|
||||
};
|
||||
|
||||
struct go7007_md_region {
|
||||
__u16 region;
|
||||
__u16 flags;
|
||||
struct v4l2_clip *clips;
|
||||
__u32 reserved[8];
|
||||
};
|
||||
|
||||
#define GO7007IOC_S_MPEG_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 2, \
|
||||
struct go7007_mpeg_params)
|
||||
#define GO7007IOC_G_MPEG_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 3, \
|
||||
struct go7007_mpeg_params)
|
||||
#define GO7007IOC_S_COMP_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 4, \
|
||||
struct go7007_comp_params)
|
||||
#define GO7007IOC_G_COMP_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 5, \
|
||||
struct go7007_comp_params)
|
||||
#define GO7007IOC_S_MD_PARAMS _IOWR('V', BASE_VIDIOC_PRIVATE + 6, \
|
||||
struct go7007_md_params)
|
||||
#define GO7007IOC_G_MD_PARAMS _IOR('V', BASE_VIDIOC_PRIVATE + 7, \
|
||||
struct go7007_md_params)
|
||||
#define GO7007IOC_S_MD_REGION _IOW('V', BASE_VIDIOC_PRIVATE + 8, \
|
||||
struct go7007_md_region)
|
||||
484
drivers/staging/go7007/saa7134-go7007.c
Normal file
484
drivers/staging/go7007/saa7134-go7007.c
Normal file
@@ -0,0 +1,484 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/wait.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <asm/byteorder.h>
|
||||
#include <media/audiochip.h>
|
||||
|
||||
#include "saa7134-reg.h"
|
||||
#include "saa7134.h"
|
||||
#include "go7007-priv.h"
|
||||
|
||||
#define GO7007_HPI_DEBUG
|
||||
|
||||
enum hpi_address {
|
||||
HPI_ADDR_VIDEO_BUFFER = 0xe4,
|
||||
HPI_ADDR_INIT_BUFFER = 0xea,
|
||||
HPI_ADDR_INTR_RET_VALUE = 0xee,
|
||||
HPI_ADDR_INTR_RET_DATA = 0xec,
|
||||
HPI_ADDR_INTR_STATUS = 0xf4,
|
||||
HPI_ADDR_INTR_WR_PARAM = 0xf6,
|
||||
HPI_ADDR_INTR_WR_INDEX = 0xf8,
|
||||
};
|
||||
|
||||
enum gpio_command {
|
||||
GPIO_COMMAND_RESET = 0x00, /* 000b */
|
||||
GPIO_COMMAND_REQ1 = 0x04, /* 001b */
|
||||
GPIO_COMMAND_WRITE = 0x20, /* 010b */
|
||||
GPIO_COMMAND_REQ2 = 0x24, /* 011b */
|
||||
GPIO_COMMAND_READ = 0x80, /* 100b */
|
||||
GPIO_COMMAND_VIDEO = 0x84, /* 101b */
|
||||
GPIO_COMMAND_IDLE = 0xA0, /* 110b */
|
||||
GPIO_COMMAND_ADDR = 0xA4, /* 111b */
|
||||
};
|
||||
|
||||
struct saa7134_go7007 {
|
||||
struct saa7134_dev *dev;
|
||||
u8 *top;
|
||||
u8 *bottom;
|
||||
dma_addr_t top_dma;
|
||||
dma_addr_t bottom_dma;
|
||||
};
|
||||
|
||||
static struct go7007_board_info board_voyager = {
|
||||
.firmware = "go7007tv.bin",
|
||||
.flags = 0,
|
||||
.sensor_flags = GO7007_SENSOR_656 |
|
||||
GO7007_SENSOR_VALID_ENABLE |
|
||||
GO7007_SENSOR_TV |
|
||||
GO7007_SENSOR_VBI,
|
||||
.audio_flags = GO7007_AUDIO_I2S_MODE_1 |
|
||||
GO7007_AUDIO_WORD_16,
|
||||
.audio_rate = 48000,
|
||||
.audio_bclk_div = 8,
|
||||
.audio_main_div = 2,
|
||||
.hpi_buffer_cap = 7,
|
||||
.num_inputs = 1,
|
||||
.inputs = {
|
||||
{
|
||||
.name = "SAA7134",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
/********************* Driver for GPIO HPI interface *********************/
|
||||
|
||||
static int gpio_write(struct saa7134_dev *dev, u8 addr, u16 data)
|
||||
{
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0xff);
|
||||
|
||||
/* Write HPI address */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, addr);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_ADDR);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
/* Write low byte */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, data & 0xff);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_WRITE);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
/* Write high byte */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, data >> 8);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_WRITE);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gpio_read(struct saa7134_dev *dev, u8 addr, u16 *data)
|
||||
{
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0xff);
|
||||
|
||||
/* Write HPI address */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, addr);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_ADDR);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0x00);
|
||||
|
||||
/* Read low byte */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_READ);
|
||||
saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
*data = saa_readb(SAA7134_GPIO_GPSTATUS0);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
/* Read high byte */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_READ);
|
||||
saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
*data |= saa_readb(SAA7134_GPIO_GPSTATUS0) << 8;
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_interface_reset(struct go7007 *go)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
u32 status;
|
||||
u16 intr_val, intr_data;
|
||||
int count = 20;
|
||||
|
||||
saa_clearb(SAA7134_TS_PARALLEL, 0x80); /* Disable TS interface */
|
||||
saa_writeb(SAA7134_GPIO_GPMODE2, 0xa4);
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0xff);
|
||||
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_REQ1);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_RESET);
|
||||
msleep(1);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_REQ1);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_REQ2);
|
||||
msleep(10);
|
||||
|
||||
saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
|
||||
status = saa_readb(SAA7134_GPIO_GPSTATUS2);
|
||||
/*printk(KERN_DEBUG "status is %s\n", status & 0x40 ? "OK" : "not OK"); */
|
||||
|
||||
/* enter command mode...(?) */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_REQ1);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_REQ2);
|
||||
|
||||
do {
|
||||
saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
|
||||
status = saa_readb(SAA7134_GPIO_GPSTATUS2);
|
||||
/*printk(KERN_INFO "gpio is %08x\n", saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)); */
|
||||
} while (--count > 0);
|
||||
|
||||
/* Wait for an interrupt to indicate successful hardware reset */
|
||||
if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
|
||||
(intr_val & ~0x1) != 0x55aa) {
|
||||
printk(KERN_ERR
|
||||
"saa7134-go7007: unable to reset the GO7007\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_write_interrupt(struct go7007 *go, int addr, int data)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
int i;
|
||||
u16 status_reg;
|
||||
|
||||
#ifdef GO7007_HPI_DEBUG
|
||||
printk(KERN_DEBUG
|
||||
"saa7134-go7007: WriteInterrupt: %04x %04x\n", addr, data);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < 100; ++i) {
|
||||
gpio_read(dev, HPI_ADDR_INTR_STATUS, &status_reg);
|
||||
if (!(status_reg & 0x0010))
|
||||
break;
|
||||
msleep(10);
|
||||
}
|
||||
if (i == 100) {
|
||||
printk(KERN_ERR
|
||||
"saa7134-go7007: device is hung, status reg = 0x%04x\n",
|
||||
status_reg);
|
||||
return -1;
|
||||
}
|
||||
gpio_write(dev, HPI_ADDR_INTR_WR_PARAM, data);
|
||||
gpio_write(dev, HPI_ADDR_INTR_WR_INDEX, addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_read_interrupt(struct go7007 *go)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
|
||||
/* XXX we need to wait if there is no interrupt available */
|
||||
go->interrupt_available = 1;
|
||||
gpio_read(dev, HPI_ADDR_INTR_RET_VALUE, &go->interrupt_value);
|
||||
gpio_read(dev, HPI_ADDR_INTR_RET_DATA, &go->interrupt_data);
|
||||
#ifdef GO7007_HPI_DEBUG
|
||||
printk(KERN_DEBUG "saa7134-go7007: ReadInterrupt: %04x %04x\n",
|
||||
go->interrupt_value, go->interrupt_data);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void saa7134_go7007_irq_ts_done(struct saa7134_dev *dev,
|
||||
unsigned long status)
|
||||
{
|
||||
struct go7007 *go = video_get_drvdata(dev->empress_dev);
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
|
||||
if (!go->streaming)
|
||||
return;
|
||||
if (0 != (status & 0x000f0000))
|
||||
printk(KERN_DEBUG "saa7134-go7007: irq: lost %ld\n",
|
||||
(status >> 16) & 0x0f);
|
||||
if (status & 0x100000) {
|
||||
dma_sync_single(&dev->pci->dev,
|
||||
saa->bottom_dma, PAGE_SIZE, DMA_FROM_DEVICE);
|
||||
go7007_parse_video_stream(go, saa->bottom, PAGE_SIZE);
|
||||
saa_writel(SAA7134_RS_BA2(5), cpu_to_le32(saa->bottom_dma));
|
||||
} else {
|
||||
dma_sync_single(&dev->pci->dev,
|
||||
saa->top_dma, PAGE_SIZE, DMA_FROM_DEVICE);
|
||||
go7007_parse_video_stream(go, saa->top, PAGE_SIZE);
|
||||
saa_writel(SAA7134_RS_BA1(5), cpu_to_le32(saa->top_dma));
|
||||
}
|
||||
}
|
||||
|
||||
static int saa7134_go7007_stream_start(struct go7007 *go)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
|
||||
saa->top_dma = dma_map_page(&dev->pci->dev, virt_to_page(saa->top),
|
||||
0, PAGE_SIZE, DMA_FROM_DEVICE);
|
||||
if (!saa->top_dma)
|
||||
return -ENOMEM;
|
||||
saa->bottom_dma = dma_map_page(&dev->pci->dev,
|
||||
virt_to_page(saa->bottom),
|
||||
0, PAGE_SIZE, DMA_FROM_DEVICE);
|
||||
if (!saa->bottom_dma) {
|
||||
dma_unmap_page(&dev->pci->dev, saa->top_dma, PAGE_SIZE,
|
||||
DMA_FROM_DEVICE);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
saa_writel(SAA7134_VIDEO_PORT_CTRL0 >> 2, 0xA300B000);
|
||||
saa_writel(SAA7134_VIDEO_PORT_CTRL4 >> 2, 0x40000200);
|
||||
|
||||
/* Set HPI interface for video */
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0xff);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, HPI_ADDR_VIDEO_BUFFER);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_ADDR);
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0x00);
|
||||
|
||||
/* Enable TS interface */
|
||||
saa_writeb(SAA7134_TS_PARALLEL, 0xe6);
|
||||
|
||||
/* Reset TS interface */
|
||||
saa_setb(SAA7134_TS_SERIAL1, 0x01);
|
||||
saa_clearb(SAA7134_TS_SERIAL1, 0x01);
|
||||
|
||||
/* Set up transfer block size */
|
||||
saa_writeb(SAA7134_TS_PARALLEL_SERIAL, 128 - 1);
|
||||
saa_writeb(SAA7134_TS_DMA0, (PAGE_SIZE >> 7) - 1);
|
||||
saa_writeb(SAA7134_TS_DMA1, 0);
|
||||
saa_writeb(SAA7134_TS_DMA2, 0);
|
||||
|
||||
/* Enable video streaming mode */
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_VIDEO);
|
||||
|
||||
saa_writel(SAA7134_RS_BA1(5), cpu_to_le32(saa->top_dma));
|
||||
saa_writel(SAA7134_RS_BA2(5), cpu_to_le32(saa->bottom_dma));
|
||||
saa_writel(SAA7134_RS_PITCH(5), 128);
|
||||
saa_writel(SAA7134_RS_CONTROL(5), SAA7134_RS_CONTROL_BURST_MAX);
|
||||
|
||||
/* Enable TS FIFO */
|
||||
saa_setl(SAA7134_MAIN_CTRL, SAA7134_MAIN_CTRL_TE5);
|
||||
|
||||
/* Enable DMA IRQ */
|
||||
saa_setl(SAA7134_IRQ1,
|
||||
SAA7134_IRQ1_INTE_RA2_1 | SAA7134_IRQ1_INTE_RA2_0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_stream_stop(struct go7007 *go)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
|
||||
/* Shut down TS FIFO */
|
||||
saa_clearl(SAA7134_MAIN_CTRL, SAA7134_MAIN_CTRL_TE5);
|
||||
|
||||
/* Disable DMA IRQ */
|
||||
saa_clearl(SAA7134_IRQ1,
|
||||
SAA7134_IRQ1_INTE_RA2_1 | SAA7134_IRQ1_INTE_RA2_0);
|
||||
|
||||
/* Disable TS interface */
|
||||
saa_clearb(SAA7134_TS_PARALLEL, 0x80);
|
||||
|
||||
dma_unmap_page(&dev->pci->dev, saa->top_dma, PAGE_SIZE,
|
||||
DMA_FROM_DEVICE);
|
||||
dma_unmap_page(&dev->pci->dev, saa->bottom_dma, PAGE_SIZE,
|
||||
DMA_FROM_DEVICE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_send_firmware(struct go7007 *go, u8 *data, int len)
|
||||
{
|
||||
struct saa7134_go7007 *saa = go->hpi_context;
|
||||
struct saa7134_dev *dev = saa->dev;
|
||||
u16 status_reg;
|
||||
int i;
|
||||
|
||||
#ifdef GO7007_HPI_DEBUG
|
||||
printk(KERN_DEBUG "saa7134-go7007: DownloadBuffer "
|
||||
"sending %d bytes\n", len);
|
||||
#endif
|
||||
|
||||
while (len > 0) {
|
||||
i = len > 64 ? 64 : len;
|
||||
saa_writeb(SAA7134_GPIO_GPMODE0, 0xff);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, HPI_ADDR_INIT_BUFFER);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_ADDR);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
while (i-- > 0) {
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS0, *data);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_WRITE);
|
||||
saa_writeb(SAA7134_GPIO_GPSTATUS2, GPIO_COMMAND_IDLE);
|
||||
++data;
|
||||
--len;
|
||||
}
|
||||
for (i = 0; i < 100; ++i) {
|
||||
gpio_read(dev, HPI_ADDR_INTR_STATUS, &status_reg);
|
||||
if (!(status_reg & 0x0002))
|
||||
break;
|
||||
}
|
||||
if (i == 100) {
|
||||
printk(KERN_ERR "saa7134-go7007: device is hung, "
|
||||
"status reg = 0x%04x\n", status_reg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct go7007_hpi_ops saa7134_go7007_hpi_ops = {
|
||||
.interface_reset = saa7134_go7007_interface_reset,
|
||||
.write_interrupt = saa7134_go7007_write_interrupt,
|
||||
.read_interrupt = saa7134_go7007_read_interrupt,
|
||||
.stream_start = saa7134_go7007_stream_start,
|
||||
.stream_stop = saa7134_go7007_stream_stop,
|
||||
.send_firmware = saa7134_go7007_send_firmware,
|
||||
};
|
||||
|
||||
/********************* Add/remove functions *********************/
|
||||
|
||||
static int saa7134_go7007_init(struct saa7134_dev *dev)
|
||||
{
|
||||
struct go7007 *go;
|
||||
struct saa7134_go7007 *saa;
|
||||
|
||||
printk(KERN_DEBUG "saa7134-go7007: probing new SAA713X board\n");
|
||||
|
||||
saa = kmalloc(sizeof(struct saa7134_go7007), GFP_KERNEL);
|
||||
if (saa == NULL)
|
||||
return -ENOMEM;
|
||||
memset(saa, 0, sizeof(struct saa7134_go7007));
|
||||
|
||||
/* Allocate a couple pages for receiving the compressed stream */
|
||||
saa->top = (u8 *)get_zeroed_page(GFP_KERNEL);
|
||||
if (!saa->top)
|
||||
goto allocfail;
|
||||
saa->bottom = (u8 *)get_zeroed_page(GFP_KERNEL);
|
||||
if (!saa->bottom)
|
||||
goto allocfail;
|
||||
|
||||
go = go7007_alloc(&board_voyager, &dev->pci->dev);
|
||||
if (go == NULL)
|
||||
goto allocfail;
|
||||
go->board_id = GO7007_BOARDID_PCI_VOYAGER;
|
||||
strncpy(go->name, saa7134_boards[dev->board].name, sizeof(go->name));
|
||||
go->hpi_ops = &saa7134_go7007_hpi_ops;
|
||||
go->hpi_context = saa;
|
||||
saa->dev = dev;
|
||||
|
||||
/* Boot the GO7007 */
|
||||
if (go7007_boot_encoder(go, go->board_info->flags &
|
||||
GO7007_BOARD_USE_ONBOARD_I2C) < 0)
|
||||
goto initfail;
|
||||
|
||||
/* Do any final GO7007 initialization, then register the
|
||||
* V4L2 and ALSA interfaces */
|
||||
if (go7007_register_encoder(go) < 0)
|
||||
goto initfail;
|
||||
dev->empress_dev = go->video_dev;
|
||||
video_set_drvdata(dev->empress_dev, go);
|
||||
|
||||
go->status = STATUS_ONLINE;
|
||||
return 0;
|
||||
|
||||
initfail:
|
||||
go->status = STATUS_SHUTDOWN;
|
||||
return 0;
|
||||
|
||||
allocfail:
|
||||
if (saa->top)
|
||||
free_page((unsigned long)saa->top);
|
||||
if (saa->bottom)
|
||||
free_page((unsigned long)saa->bottom);
|
||||
kfree(saa);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static int saa7134_go7007_fini(struct saa7134_dev *dev)
|
||||
{
|
||||
struct go7007 *go;
|
||||
struct saa7134_go7007 *saa;
|
||||
|
||||
if (NULL == dev->empress_dev)
|
||||
return 0;
|
||||
|
||||
go = video_get_drvdata(dev->empress_dev);
|
||||
saa = go->hpi_context;
|
||||
go->status = STATUS_SHUTDOWN;
|
||||
free_page((unsigned long)saa->top);
|
||||
free_page((unsigned long)saa->bottom);
|
||||
kfree(saa);
|
||||
go7007_remove(go);
|
||||
dev->empress_dev = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct saa7134_mpeg_ops saa7134_go7007_ops = {
|
||||
.type = SAA7134_MPEG_GO7007,
|
||||
.init = saa7134_go7007_init,
|
||||
.fini = saa7134_go7007_fini,
|
||||
.irq_ts_done = saa7134_go7007_irq_ts_done,
|
||||
};
|
||||
|
||||
static int __init saa7134_go7007_mod_init(void)
|
||||
{
|
||||
return saa7134_ts_register(&saa7134_go7007_ops);
|
||||
}
|
||||
|
||||
static void __exit saa7134_go7007_mod_cleanup(void)
|
||||
{
|
||||
saa7134_ts_unregister(&saa7134_go7007_ops);
|
||||
}
|
||||
|
||||
module_init(saa7134_go7007_mod_init);
|
||||
module_exit(saa7134_go7007_mod_cleanup);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
305
drivers/staging/go7007/snd-go7007.c
Normal file
305
drivers/staging/go7007/snd-go7007.c
Normal file
@@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/time.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/semaphore.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <asm/system.h>
|
||||
#include <sound/core.h>
|
||||
#include <sound/pcm.h>
|
||||
#include <sound/initval.h>
|
||||
|
||||
#include "go7007-priv.h"
|
||||
|
||||
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
||||
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
||||
static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
|
||||
|
||||
module_param_array(index, int, NULL, 0444);
|
||||
module_param_array(id, charp, NULL, 0444);
|
||||
module_param_array(enable, bool, NULL, 0444);
|
||||
MODULE_PARM_DESC(index, "Index value for the go7007 audio driver");
|
||||
MODULE_PARM_DESC(index, "ID string for the go7007 audio driver");
|
||||
MODULE_PARM_DESC(index, "Enable for the go7007 audio driver");
|
||||
|
||||
struct go7007_snd {
|
||||
struct snd_card *card;
|
||||
struct snd_pcm *pcm;
|
||||
struct snd_pcm_substream *substream;
|
||||
spinlock_t lock;
|
||||
int w_idx;
|
||||
int hw_ptr;
|
||||
int avail;
|
||||
int capturing;
|
||||
};
|
||||
|
||||
static struct snd_pcm_hardware go7007_snd_capture_hw = {
|
||||
.info = (SNDRV_PCM_INFO_MMAP |
|
||||
SNDRV_PCM_INFO_INTERLEAVED |
|
||||
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
||||
SNDRV_PCM_INFO_MMAP_VALID),
|
||||
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
||||
.rates = SNDRV_PCM_RATE_48000,
|
||||
.rate_min = 48000,
|
||||
.rate_max = 48000,
|
||||
.channels_min = 2,
|
||||
.channels_max = 2,
|
||||
.buffer_bytes_max = (128*1024),
|
||||
.period_bytes_min = 4096,
|
||||
.period_bytes_max = (128*1024),
|
||||
.periods_min = 1,
|
||||
.periods_max = 32,
|
||||
};
|
||||
|
||||
static void parse_audio_stream_data(struct go7007 *go, u8 *buf, int length)
|
||||
{
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
struct snd_pcm_runtime *runtime = gosnd->substream->runtime;
|
||||
int frames = bytes_to_frames(runtime, length);
|
||||
|
||||
spin_lock(&gosnd->lock);
|
||||
gosnd->hw_ptr += frames;
|
||||
if (gosnd->hw_ptr >= runtime->buffer_size)
|
||||
gosnd->hw_ptr -= runtime->buffer_size;
|
||||
gosnd->avail += frames;
|
||||
spin_unlock(&gosnd->lock);
|
||||
if (gosnd->w_idx + length > runtime->dma_bytes) {
|
||||
int cpy = runtime->dma_bytes - gosnd->w_idx;
|
||||
|
||||
memcpy(runtime->dma_area + gosnd->w_idx, buf, cpy);
|
||||
length -= cpy;
|
||||
buf += cpy;
|
||||
gosnd->w_idx = 0;
|
||||
}
|
||||
memcpy(runtime->dma_area + gosnd->w_idx, buf, length);
|
||||
gosnd->w_idx += length;
|
||||
spin_lock(&gosnd->lock);
|
||||
if (gosnd->avail < runtime->period_size) {
|
||||
spin_unlock(&gosnd->lock);
|
||||
return;
|
||||
}
|
||||
gosnd->avail -= runtime->period_size;
|
||||
spin_unlock(&gosnd->lock);
|
||||
if (gosnd->capturing)
|
||||
snd_pcm_period_elapsed(gosnd->substream);
|
||||
}
|
||||
|
||||
static int go7007_snd_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *hw_params)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
unsigned int bytes;
|
||||
|
||||
bytes = params_buffer_bytes(hw_params);
|
||||
if (substream->runtime->dma_bytes > 0)
|
||||
vfree(substream->runtime->dma_area);
|
||||
substream->runtime->dma_bytes = 0;
|
||||
substream->runtime->dma_area = vmalloc(bytes);
|
||||
if (substream->runtime->dma_area == NULL)
|
||||
return -ENOMEM;
|
||||
substream->runtime->dma_bytes = bytes;
|
||||
go->audio_deliver = parse_audio_stream_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int go7007_snd_hw_free(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
|
||||
go->audio_deliver = NULL;
|
||||
if (substream->runtime->dma_bytes > 0)
|
||||
vfree(substream->runtime->dma_area);
|
||||
substream->runtime->dma_bytes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int go7007_snd_capture_open(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
unsigned long flags;
|
||||
int r;
|
||||
|
||||
spin_lock_irqsave(&gosnd->lock, flags);
|
||||
if (gosnd->substream == NULL) {
|
||||
gosnd->substream = substream;
|
||||
substream->runtime->hw = go7007_snd_capture_hw;
|
||||
r = 0;
|
||||
} else
|
||||
r = -EBUSY;
|
||||
spin_unlock_irqrestore(&gosnd->lock, flags);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int go7007_snd_capture_close(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
|
||||
gosnd->substream = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int go7007_snd_pcm_prepare(struct snd_pcm_substream *substream)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int go7007_snd_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
|
||||
switch (cmd) {
|
||||
case SNDRV_PCM_TRIGGER_START:
|
||||
/* Just set a flag to indicate we should signal ALSA when
|
||||
* sound comes in */
|
||||
gosnd->capturing = 1;
|
||||
return 0;
|
||||
case SNDRV_PCM_TRIGGER_STOP:
|
||||
gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
|
||||
gosnd->capturing = 0;
|
||||
return 0;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
static snd_pcm_uframes_t go7007_snd_pcm_pointer(struct snd_pcm_substream *substream)
|
||||
{
|
||||
struct go7007 *go = snd_pcm_substream_chip(substream);
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
|
||||
return gosnd->hw_ptr;
|
||||
}
|
||||
|
||||
static struct page *go7007_snd_pcm_page(struct snd_pcm_substream *substream,
|
||||
unsigned long offset)
|
||||
{
|
||||
return vmalloc_to_page(substream->runtime->dma_area + offset);
|
||||
}
|
||||
|
||||
static struct snd_pcm_ops go7007_snd_capture_ops = {
|
||||
.open = go7007_snd_capture_open,
|
||||
.close = go7007_snd_capture_close,
|
||||
.ioctl = snd_pcm_lib_ioctl,
|
||||
.hw_params = go7007_snd_hw_params,
|
||||
.hw_free = go7007_snd_hw_free,
|
||||
.prepare = go7007_snd_pcm_prepare,
|
||||
.trigger = go7007_snd_pcm_trigger,
|
||||
.pointer = go7007_snd_pcm_pointer,
|
||||
.page = go7007_snd_pcm_page,
|
||||
};
|
||||
|
||||
static int go7007_snd_free(struct snd_device *device)
|
||||
{
|
||||
struct go7007 *go = device->device_data;
|
||||
|
||||
kfree(go->snd_context);
|
||||
go->snd_context = NULL;
|
||||
if (--go->ref_count == 0)
|
||||
kfree(go);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct snd_device_ops go7007_snd_device_ops = {
|
||||
.dev_free = go7007_snd_free,
|
||||
};
|
||||
|
||||
int go7007_snd_init(struct go7007 *go)
|
||||
{
|
||||
static int dev;
|
||||
struct go7007_snd *gosnd;
|
||||
int ret = 0;
|
||||
|
||||
if (dev >= SNDRV_CARDS)
|
||||
return -ENODEV;
|
||||
if (!enable[dev]) {
|
||||
dev++;
|
||||
return -ENOENT;
|
||||
}
|
||||
gosnd = kmalloc(sizeof(struct go7007_snd), GFP_KERNEL);
|
||||
if (gosnd == NULL)
|
||||
return -ENOMEM;
|
||||
spin_lock_init(&gosnd->lock);
|
||||
gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
|
||||
gosnd->capturing = 0;
|
||||
gosnd->card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
|
||||
if (gosnd->card == NULL) {
|
||||
kfree(gosnd);
|
||||
return -ENOMEM;
|
||||
}
|
||||
ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go,
|
||||
&go7007_snd_device_ops);
|
||||
if (ret < 0) {
|
||||
kfree(gosnd);
|
||||
return ret;
|
||||
}
|
||||
snd_card_set_dev(gosnd->card, go->dev);
|
||||
ret = snd_pcm_new(gosnd->card, "go7007", 0, 0, 1, &gosnd->pcm);
|
||||
if (ret < 0) {
|
||||
snd_card_free(gosnd->card);
|
||||
kfree(gosnd);
|
||||
return ret;
|
||||
}
|
||||
strncpy(gosnd->card->driver, "go7007", sizeof(gosnd->card->driver));
|
||||
strncpy(gosnd->card->shortname, go->name, sizeof(gosnd->card->driver));
|
||||
strncpy(gosnd->card->longname, gosnd->card->shortname,
|
||||
sizeof(gosnd->card->longname));
|
||||
|
||||
gosnd->pcm->private_data = go;
|
||||
snd_pcm_set_ops(gosnd->pcm, SNDRV_PCM_STREAM_CAPTURE,
|
||||
&go7007_snd_capture_ops);
|
||||
|
||||
ret = snd_card_register(gosnd->card);
|
||||
if (ret < 0) {
|
||||
snd_card_free(gosnd->card);
|
||||
kfree(gosnd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gosnd->substream = NULL;
|
||||
go->snd_context = gosnd;
|
||||
++dev;
|
||||
++go->ref_count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(go7007_snd_init);
|
||||
|
||||
int go7007_snd_remove(struct go7007 *go)
|
||||
{
|
||||
struct go7007_snd *gosnd = go->snd_context;
|
||||
|
||||
snd_card_disconnect(gosnd->card);
|
||||
snd_card_free_when_closed(gosnd->card);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(go7007_snd_remove);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
55
drivers/staging/go7007/wis-i2c.h
Normal file
55
drivers/staging/go7007/wis-i2c.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Temporary I2C IDs -- these need to be replaced with real registered IDs */
|
||||
#define I2C_DRIVERID_WIS_SAA7115 0xf0f0
|
||||
#define I2C_DRIVERID_WIS_UDA1342 0xf0f1
|
||||
#define I2C_DRIVERID_WIS_SONY_TUNER 0xf0f2
|
||||
#define I2C_DRIVERID_WIS_TW9903 0xf0f3
|
||||
#define I2C_DRIVERID_WIS_SAA7113 0xf0f4
|
||||
#define I2C_DRIVERID_WIS_OV7640 0xf0f5
|
||||
#define I2C_DRIVERID_WIS_TW2804 0xf0f6
|
||||
#define I2C_ALGO_GO7007 0xf00000
|
||||
#define I2C_ALGO_GO7007_USB 0xf10000
|
||||
|
||||
/* Flag to indicate that the client needs to be accessed with SCCB semantics */
|
||||
/* We re-use the I2C_M_TEN value so the flag passes through the masks in the
|
||||
* core I2C code. Major kludge, but the I2C layer ain't exactly flexible. */
|
||||
#define I2C_CLIENT_SCCB 0x10
|
||||
|
||||
typedef int (*found_proc) (struct i2c_adapter *, int, int);
|
||||
int wis_i2c_add_driver(unsigned int id, found_proc found_proc);
|
||||
void wis_i2c_del_driver(found_proc found_proc);
|
||||
|
||||
int wis_i2c_probe_device(struct i2c_adapter *adapter,
|
||||
unsigned int id, int addr);
|
||||
|
||||
/* Definitions for new video decoder commands */
|
||||
|
||||
struct video_decoder_resolution {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
};
|
||||
|
||||
#define DECODER_SET_RESOLUTION _IOW('d', 200, struct video_decoder_resolution)
|
||||
#define DECODER_SET_CHANNEL _IOW('d', 201, int)
|
||||
|
||||
/* Sony tuner types */
|
||||
|
||||
#define TUNER_SONY_BTF_PG472Z 200
|
||||
#define TUNER_SONY_BTF_PK467Z 201
|
||||
#define TUNER_SONY_BTF_PB463Z 202
|
||||
131
drivers/staging/go7007/wis-ov7640.c
Normal file
131
drivers/staging/go7007/wis-ov7640.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/videodev.h>
|
||||
#include <linux/video_decoder.h>
|
||||
|
||||
#include "wis-i2c.h"
|
||||
|
||||
struct wis_ov7640 {
|
||||
int brightness;
|
||||
int contrast;
|
||||
int saturation;
|
||||
int hue;
|
||||
};
|
||||
|
||||
static u8 initial_registers[] =
|
||||
{
|
||||
0x12, 0x80,
|
||||
0x12, 0x54,
|
||||
0x14, 0x24,
|
||||
0x15, 0x01,
|
||||
0x28, 0x20,
|
||||
0x75, 0x82,
|
||||
0xFF, 0xFF, /* Terminator (reg 0xFF is unused) */
|
||||
};
|
||||
|
||||
static int write_regs(struct i2c_client *client, u8 *regs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; regs[i] != 0xFF; i += 2)
|
||||
if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_ov7640_driver;
|
||||
|
||||
static struct i2c_client wis_ov7640_client_templ = {
|
||||
.name = "OV7640 (WIS)",
|
||||
.driver = &wis_ov7640_driver,
|
||||
};
|
||||
|
||||
static int wis_ov7640_detect(struct i2c_adapter *adapter, int addr, int kind)
|
||||
{
|
||||
struct i2c_client *client;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return 0;
|
||||
|
||||
client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
||||
if (client == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(client, &wis_ov7640_client_templ,
|
||||
sizeof(wis_ov7640_client_templ));
|
||||
client->adapter = adapter;
|
||||
client->addr = addr;
|
||||
client->flags = I2C_CLIENT_SCCB;
|
||||
|
||||
printk(KERN_DEBUG
|
||||
"wis-ov7640: initializing OV7640 at address %d on %s\n",
|
||||
addr, adapter->name);
|
||||
|
||||
if (write_regs(client, initial_registers) < 0) {
|
||||
printk(KERN_ERR "wis-ov7640: error initializing OV7640\n");
|
||||
kfree(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_attach_client(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_ov7640_detach(struct i2c_client *client)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = i2c_detach_client(client);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
kfree(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_ov7640_driver = {
|
||||
.driver = {
|
||||
.name = "WIS OV7640 I2C driver",
|
||||
},
|
||||
.id = I2C_DRIVERID_WIS_OV7640,
|
||||
.detach_client = wis_ov7640_detach,
|
||||
};
|
||||
|
||||
static int __init wis_ov7640_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = i2c_add_driver(&wis_ov7640_driver);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return wis_i2c_add_driver(wis_ov7640_driver.id, wis_ov7640_detect);
|
||||
}
|
||||
|
||||
static void __exit wis_ov7640_cleanup(void)
|
||||
{
|
||||
wis_i2c_del_driver(wis_ov7640_detect);
|
||||
i2c_del_driver(&wis_ov7640_driver);
|
||||
}
|
||||
|
||||
module_init(wis_ov7640_init);
|
||||
module_exit(wis_ov7640_cleanup);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
363
drivers/staging/go7007/wis-saa7113.c
Normal file
363
drivers/staging/go7007/wis-saa7113.c
Normal file
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/videodev.h>
|
||||
#include <linux/video_decoder.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#include "wis-i2c.h"
|
||||
|
||||
struct wis_saa7113 {
|
||||
int norm;
|
||||
int brightness;
|
||||
int contrast;
|
||||
int saturation;
|
||||
int hue;
|
||||
};
|
||||
|
||||
static u8 initial_registers[] =
|
||||
{
|
||||
0x01, 0x08,
|
||||
0x02, 0xc0,
|
||||
0x03, 0x33,
|
||||
0x04, 0x00,
|
||||
0x05, 0x00,
|
||||
0x06, 0xe9,
|
||||
0x07, 0x0d,
|
||||
0x08, 0xd8,
|
||||
0x09, 0x40,
|
||||
0x0a, 0x80,
|
||||
0x0b, 0x47,
|
||||
0x0c, 0x40,
|
||||
0x0d, 0x00,
|
||||
0x0e, 0x01,
|
||||
0x0f, 0x2a,
|
||||
0x10, 0x40,
|
||||
0x11, 0x0c,
|
||||
0x12, 0xfe,
|
||||
0x13, 0x00,
|
||||
0x14, 0x00,
|
||||
0x15, 0x04,
|
||||
0x16, 0x00,
|
||||
0x17, 0x00,
|
||||
0x18, 0x00,
|
||||
0x19, 0x00,
|
||||
0x1a, 0x00,
|
||||
0x1b, 0x00,
|
||||
0x1c, 0x00,
|
||||
0x1d, 0x00,
|
||||
0x1e, 0x00,
|
||||
0x1f, 0xc8,
|
||||
0x40, 0x00,
|
||||
0x41, 0xff,
|
||||
0x42, 0xff,
|
||||
0x43, 0xff,
|
||||
0x44, 0xff,
|
||||
0x45, 0xff,
|
||||
0x46, 0xff,
|
||||
0x47, 0xff,
|
||||
0x48, 0xff,
|
||||
0x49, 0xff,
|
||||
0x4a, 0xff,
|
||||
0x4b, 0xff,
|
||||
0x4c, 0xff,
|
||||
0x4d, 0xff,
|
||||
0x4e, 0xff,
|
||||
0x4f, 0xff,
|
||||
0x50, 0xff,
|
||||
0x51, 0xff,
|
||||
0x52, 0xff,
|
||||
0x53, 0xff,
|
||||
0x54, 0xff,
|
||||
0x55, 0xff,
|
||||
0x56, 0xff,
|
||||
0x57, 0xff,
|
||||
0x58, 0x00,
|
||||
0x59, 0x54,
|
||||
0x5a, 0x07,
|
||||
0x5b, 0x83,
|
||||
0x5c, 0x00,
|
||||
0x5d, 0x00,
|
||||
0x5e, 0x00,
|
||||
0x5f, 0x00,
|
||||
0x60, 0x00,
|
||||
0x61, 0x00,
|
||||
0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
|
||||
};
|
||||
|
||||
static int write_reg(struct i2c_client *client, u8 reg, u8 value)
|
||||
{
|
||||
return i2c_smbus_write_byte_data(client, reg, value);
|
||||
}
|
||||
|
||||
static int write_regs(struct i2c_client *client, u8 *regs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; regs[i] != 0x00; i += 2)
|
||||
if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_saa7113_command(struct i2c_client *client,
|
||||
unsigned int cmd, void *arg)
|
||||
{
|
||||
struct wis_saa7113 *dec = i2c_get_clientdata(client);
|
||||
|
||||
switch (cmd) {
|
||||
case DECODER_SET_INPUT:
|
||||
{
|
||||
int *input = arg;
|
||||
|
||||
i2c_smbus_write_byte_data(client, 0x02, 0xC0 | *input);
|
||||
i2c_smbus_write_byte_data(client, 0x09,
|
||||
*input < 6 ? 0x40 : 0x80);
|
||||
break;
|
||||
}
|
||||
case DECODER_SET_NORM:
|
||||
{
|
||||
int *input = arg;
|
||||
dec->norm = *input;
|
||||
switch (dec->norm) {
|
||||
case VIDEO_MODE_PAL:
|
||||
write_reg(client, 0x0e, 0x01);
|
||||
write_reg(client, 0x10, 0x48);
|
||||
break;
|
||||
case VIDEO_MODE_NTSC:
|
||||
write_reg(client, 0x0e, 0x01);
|
||||
write_reg(client, 0x10, 0x40);
|
||||
break;
|
||||
case VIDEO_MODE_SECAM:
|
||||
write_reg(client, 0x0e, 0x50);
|
||||
write_reg(client, 0x10, 0x48);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_QUERYCTRL:
|
||||
{
|
||||
struct v4l2_queryctrl *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 71;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 64;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
|
||||
ctrl->minimum = -128;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 0;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_S_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
if (ctrl->value > 255)
|
||||
dec->brightness = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->brightness = 0;
|
||||
else
|
||||
dec->brightness = ctrl->value;
|
||||
write_reg(client, 0x0a, dec->brightness);
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
if (ctrl->value > 127)
|
||||
dec->contrast = 127;
|
||||
else if (ctrl->value < 0)
|
||||
dec->contrast = 0;
|
||||
else
|
||||
dec->contrast = ctrl->value;
|
||||
write_reg(client, 0x0b, dec->contrast);
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
if (ctrl->value > 127)
|
||||
dec->saturation = 127;
|
||||
else if (ctrl->value < 0)
|
||||
dec->saturation = 0;
|
||||
else
|
||||
dec->saturation = ctrl->value;
|
||||
write_reg(client, 0x0c, dec->saturation);
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
if (ctrl->value > 127)
|
||||
dec->hue = 127;
|
||||
else if (ctrl->value < -128)
|
||||
dec->hue = -128;
|
||||
else
|
||||
dec->hue = ctrl->value;
|
||||
write_reg(client, 0x0d, dec->hue);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_G_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->value = dec->brightness;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->value = dec->contrast;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->value = dec->saturation;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->value = dec->hue;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_saa7113_driver;
|
||||
|
||||
static struct i2c_client wis_saa7113_client_templ = {
|
||||
.name = "SAA7113 (WIS)",
|
||||
.driver = &wis_saa7113_driver,
|
||||
};
|
||||
|
||||
static int wis_saa7113_detect(struct i2c_adapter *adapter, int addr, int kind)
|
||||
{
|
||||
struct i2c_client *client;
|
||||
struct wis_saa7113 *dec;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return 0;
|
||||
|
||||
client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
||||
if (client == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(client, &wis_saa7113_client_templ,
|
||||
sizeof(wis_saa7113_client_templ));
|
||||
client->adapter = adapter;
|
||||
client->addr = addr;
|
||||
|
||||
dec = kmalloc(sizeof(struct wis_saa7113), GFP_KERNEL);
|
||||
if (dec == NULL) {
|
||||
kfree(client);
|
||||
return -ENOMEM;
|
||||
}
|
||||
dec->norm = VIDEO_MODE_NTSC;
|
||||
dec->brightness = 128;
|
||||
dec->contrast = 71;
|
||||
dec->saturation = 64;
|
||||
dec->hue = 0;
|
||||
i2c_set_clientdata(client, dec);
|
||||
|
||||
printk(KERN_DEBUG
|
||||
"wis-saa7113: initializing SAA7113 at address %d on %s\n",
|
||||
addr, adapter->name);
|
||||
|
||||
if (write_regs(client, initial_registers) < 0) {
|
||||
printk(KERN_ERR
|
||||
"wis-saa7113: error initializing SAA7113\n");
|
||||
kfree(client);
|
||||
kfree(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_attach_client(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_saa7113_detach(struct i2c_client *client)
|
||||
{
|
||||
struct wis_saa7113 *dec = i2c_get_clientdata(client);
|
||||
int r;
|
||||
|
||||
r = i2c_detach_client(client);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
kfree(client);
|
||||
kfree(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_saa7113_driver = {
|
||||
.driver = {
|
||||
.name = "WIS SAA7113 I2C driver",
|
||||
},
|
||||
.id = I2C_DRIVERID_WIS_SAA7113,
|
||||
.detach_client = wis_saa7113_detach,
|
||||
.command = wis_saa7113_command,
|
||||
};
|
||||
|
||||
static int __init wis_saa7113_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = i2c_add_driver(&wis_saa7113_driver);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return wis_i2c_add_driver(wis_saa7113_driver.id, wis_saa7113_detect);
|
||||
}
|
||||
|
||||
static void __exit wis_saa7113_cleanup(void)
|
||||
{
|
||||
wis_i2c_del_driver(wis_saa7113_detect);
|
||||
i2c_del_driver(&wis_saa7113_driver);
|
||||
}
|
||||
|
||||
module_init(wis_saa7113_init);
|
||||
module_exit(wis_saa7113_cleanup);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
492
drivers/staging/go7007/wis-saa7115.c
Normal file
492
drivers/staging/go7007/wis-saa7115.c
Normal file
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/videodev.h>
|
||||
#include <linux/video_decoder.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#include "wis-i2c.h"
|
||||
|
||||
struct wis_saa7115 {
|
||||
int norm;
|
||||
int brightness;
|
||||
int contrast;
|
||||
int saturation;
|
||||
int hue;
|
||||
};
|
||||
|
||||
static u8 initial_registers[] =
|
||||
{
|
||||
0x01, 0x08,
|
||||
0x02, 0xc0,
|
||||
0x03, 0x20,
|
||||
0x04, 0x80,
|
||||
0x05, 0x80,
|
||||
0x06, 0xeb,
|
||||
0x07, 0xe0,
|
||||
0x08, 0xf0, /* always toggle FID */
|
||||
0x09, 0x40,
|
||||
0x0a, 0x80,
|
||||
0x0b, 0x40,
|
||||
0x0c, 0x40,
|
||||
0x0d, 0x00,
|
||||
0x0e, 0x03,
|
||||
0x0f, 0x2a,
|
||||
0x10, 0x0e,
|
||||
0x11, 0x00,
|
||||
0x12, 0x8d,
|
||||
0x13, 0x00,
|
||||
0x14, 0x00,
|
||||
0x15, 0x11,
|
||||
0x16, 0x01,
|
||||
0x17, 0xda,
|
||||
0x18, 0x40,
|
||||
0x19, 0x80,
|
||||
0x1a, 0x00,
|
||||
0x1b, 0x42,
|
||||
0x1c, 0xa9,
|
||||
0x30, 0x66,
|
||||
0x31, 0x90,
|
||||
0x32, 0x01,
|
||||
0x34, 0x00,
|
||||
0x35, 0x00,
|
||||
0x36, 0x20,
|
||||
0x38, 0x03,
|
||||
0x39, 0x20,
|
||||
0x3a, 0x88,
|
||||
0x40, 0x00,
|
||||
0x41, 0xff,
|
||||
0x42, 0xff,
|
||||
0x43, 0xff,
|
||||
0x44, 0xff,
|
||||
0x45, 0xff,
|
||||
0x46, 0xff,
|
||||
0x47, 0xff,
|
||||
0x48, 0xff,
|
||||
0x49, 0xff,
|
||||
0x4a, 0xff,
|
||||
0x4b, 0xff,
|
||||
0x4c, 0xff,
|
||||
0x4d, 0xff,
|
||||
0x4e, 0xff,
|
||||
0x4f, 0xff,
|
||||
0x50, 0xff,
|
||||
0x51, 0xff,
|
||||
0x52, 0xff,
|
||||
0x53, 0xff,
|
||||
0x54, 0xf4 /*0xff*/,
|
||||
0x55, 0xff,
|
||||
0x56, 0xff,
|
||||
0x57, 0xff,
|
||||
0x58, 0x40,
|
||||
0x59, 0x47,
|
||||
0x5a, 0x06 /*0x03*/,
|
||||
0x5b, 0x83,
|
||||
0x5d, 0x06,
|
||||
0x5e, 0x00,
|
||||
0x80, 0x30, /* window defined scaler operation, task A and B enabled */
|
||||
0x81, 0x03, /* use scaler datapath generated V */
|
||||
0x83, 0x00,
|
||||
0x84, 0x00,
|
||||
0x85, 0x00,
|
||||
0x86, 0x45,
|
||||
0x87, 0x31,
|
||||
0x88, 0xc0,
|
||||
0x90, 0x02, /* task A process top field */
|
||||
0x91, 0x08,
|
||||
0x92, 0x09,
|
||||
0x93, 0x80,
|
||||
0x94, 0x06,
|
||||
0x95, 0x00,
|
||||
0x96, 0xc0,
|
||||
0x97, 0x02,
|
||||
0x98, 0x12,
|
||||
0x99, 0x00,
|
||||
0x9a, 0xf2,
|
||||
0x9b, 0x00,
|
||||
0x9c, 0xd0,
|
||||
0x9d, 0x02,
|
||||
0x9e, 0xf2,
|
||||
0x9f, 0x00,
|
||||
0xa0, 0x01,
|
||||
0xa1, 0x01,
|
||||
0xa2, 0x01,
|
||||
0xa4, 0x80,
|
||||
0xa5, 0x40,
|
||||
0xa6, 0x40,
|
||||
0xa8, 0x00,
|
||||
0xa9, 0x04,
|
||||
0xaa, 0x00,
|
||||
0xac, 0x00,
|
||||
0xad, 0x02,
|
||||
0xae, 0x00,
|
||||
0xb0, 0x00,
|
||||
0xb1, 0x04,
|
||||
0xb2, 0x00,
|
||||
0xb3, 0x04,
|
||||
0xb4, 0x00,
|
||||
0xb8, 0x00,
|
||||
0xbc, 0x00,
|
||||
0xc0, 0x03, /* task B process bottom field */
|
||||
0xc1, 0x08,
|
||||
0xc2, 0x09,
|
||||
0xc3, 0x80,
|
||||
0xc4, 0x06,
|
||||
0xc5, 0x00,
|
||||
0xc6, 0xc0,
|
||||
0xc7, 0x02,
|
||||
0xc8, 0x12,
|
||||
0xc9, 0x00,
|
||||
0xca, 0xf2,
|
||||
0xcb, 0x00,
|
||||
0xcc, 0xd0,
|
||||
0xcd, 0x02,
|
||||
0xce, 0xf2,
|
||||
0xcf, 0x00,
|
||||
0xd0, 0x01,
|
||||
0xd1, 0x01,
|
||||
0xd2, 0x01,
|
||||
0xd4, 0x80,
|
||||
0xd5, 0x40,
|
||||
0xd6, 0x40,
|
||||
0xd8, 0x00,
|
||||
0xd9, 0x04,
|
||||
0xda, 0x00,
|
||||
0xdc, 0x00,
|
||||
0xdd, 0x02,
|
||||
0xde, 0x00,
|
||||
0xe0, 0x00,
|
||||
0xe1, 0x04,
|
||||
0xe2, 0x00,
|
||||
0xe3, 0x04,
|
||||
0xe4, 0x00,
|
||||
0xe8, 0x00,
|
||||
0x88, 0xf0, /* End of original static list */
|
||||
0x00, 0x00, /* Terminator (reg 0x00 is read-only) */
|
||||
};
|
||||
|
||||
static int write_reg(struct i2c_client *client, u8 reg, u8 value)
|
||||
{
|
||||
return i2c_smbus_write_byte_data(client, reg, value);
|
||||
}
|
||||
|
||||
static int write_regs(struct i2c_client *client, u8 *regs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; regs[i] != 0x00; i += 2)
|
||||
if (i2c_smbus_write_byte_data(client, regs[i], regs[i + 1]) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_saa7115_command(struct i2c_client *client,
|
||||
unsigned int cmd, void *arg)
|
||||
{
|
||||
struct wis_saa7115 *dec = i2c_get_clientdata(client);
|
||||
|
||||
switch (cmd) {
|
||||
case DECODER_SET_INPUT:
|
||||
{
|
||||
int *input = arg;
|
||||
|
||||
i2c_smbus_write_byte_data(client, 0x02, 0xC0 | *input);
|
||||
i2c_smbus_write_byte_data(client, 0x09,
|
||||
*input < 6 ? 0x40 : 0xC0);
|
||||
break;
|
||||
}
|
||||
case DECODER_SET_RESOLUTION:
|
||||
{
|
||||
struct video_decoder_resolution *res = arg;
|
||||
/* Course-grained scaler */
|
||||
int h_integer_scaler = res->width < 704 ? 704 / res->width : 1;
|
||||
/* Fine-grained scaler to take care of remainder */
|
||||
int h_scaling_increment = (704 / h_integer_scaler) *
|
||||
1024 / res->width;
|
||||
/* Fine-grained scaler only */
|
||||
int v_scaling_increment = (dec->norm == VIDEO_MODE_NTSC ?
|
||||
240 : 288) * 1024 / res->height;
|
||||
u8 regs[] = {
|
||||
0x88, 0xc0,
|
||||
0x9c, res->width & 0xff,
|
||||
0x9d, res->width >> 8,
|
||||
0x9e, res->height & 0xff,
|
||||
0x9f, res->height >> 8,
|
||||
0xa0, h_integer_scaler,
|
||||
0xa1, 1,
|
||||
0xa2, 1,
|
||||
0xa8, h_scaling_increment & 0xff,
|
||||
0xa9, h_scaling_increment >> 8,
|
||||
0xac, (h_scaling_increment / 2) & 0xff,
|
||||
0xad, (h_scaling_increment / 2) >> 8,
|
||||
0xb0, v_scaling_increment & 0xff,
|
||||
0xb1, v_scaling_increment >> 8,
|
||||
0xb2, v_scaling_increment & 0xff,
|
||||
0xb3, v_scaling_increment >> 8,
|
||||
0xcc, res->width & 0xff,
|
||||
0xcd, res->width >> 8,
|
||||
0xce, res->height & 0xff,
|
||||
0xcf, res->height >> 8,
|
||||
0xd0, h_integer_scaler,
|
||||
0xd1, 1,
|
||||
0xd2, 1,
|
||||
0xd8, h_scaling_increment & 0xff,
|
||||
0xd9, h_scaling_increment >> 8,
|
||||
0xdc, (h_scaling_increment / 2) & 0xff,
|
||||
0xdd, (h_scaling_increment / 2) >> 8,
|
||||
0xe0, v_scaling_increment & 0xff,
|
||||
0xe1, v_scaling_increment >> 8,
|
||||
0xe2, v_scaling_increment & 0xff,
|
||||
0xe3, v_scaling_increment >> 8,
|
||||
0x88, 0xf0,
|
||||
0, 0,
|
||||
};
|
||||
write_regs(client, regs);
|
||||
break;
|
||||
}
|
||||
case DECODER_SET_NORM:
|
||||
{
|
||||
int *input = arg;
|
||||
u8 regs[] = {
|
||||
0x88, 0xc0,
|
||||
0x98, *input == VIDEO_MODE_NTSC ? 0x12 : 0x16,
|
||||
0x9a, *input == VIDEO_MODE_NTSC ? 0xf2 : 0x20,
|
||||
0x9b, *input == VIDEO_MODE_NTSC ? 0x00 : 0x01,
|
||||
0xc8, *input == VIDEO_MODE_NTSC ? 0x12 : 0x16,
|
||||
0xca, *input == VIDEO_MODE_NTSC ? 0xf2 : 0x20,
|
||||
0xcb, *input == VIDEO_MODE_NTSC ? 0x00 : 0x01,
|
||||
0x88, 0xf0,
|
||||
0x30, *input == VIDEO_MODE_NTSC ? 0x66 : 0x00,
|
||||
0x31, *input == VIDEO_MODE_NTSC ? 0x90 : 0xe0,
|
||||
0, 0,
|
||||
};
|
||||
write_regs(client, regs);
|
||||
dec->norm = *input;
|
||||
break;
|
||||
}
|
||||
case VIDIOC_QUERYCTRL:
|
||||
{
|
||||
struct v4l2_queryctrl *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 64;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 64;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
|
||||
ctrl->minimum = -128;
|
||||
ctrl->maximum = 127;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 0;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_S_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
if (ctrl->value > 255)
|
||||
dec->brightness = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->brightness = 0;
|
||||
else
|
||||
dec->brightness = ctrl->value;
|
||||
write_reg(client, 0x0a, dec->brightness);
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
if (ctrl->value > 127)
|
||||
dec->contrast = 127;
|
||||
else if (ctrl->value < 0)
|
||||
dec->contrast = 0;
|
||||
else
|
||||
dec->contrast = ctrl->value;
|
||||
write_reg(client, 0x0b, dec->contrast);
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
if (ctrl->value > 127)
|
||||
dec->saturation = 127;
|
||||
else if (ctrl->value < 0)
|
||||
dec->saturation = 0;
|
||||
else
|
||||
dec->saturation = ctrl->value;
|
||||
write_reg(client, 0x0c, dec->saturation);
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
if (ctrl->value > 127)
|
||||
dec->hue = 127;
|
||||
else if (ctrl->value < -128)
|
||||
dec->hue = -128;
|
||||
else
|
||||
dec->hue = ctrl->value;
|
||||
write_reg(client, 0x0d, dec->hue);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_G_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->value = dec->brightness;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->value = dec->contrast;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->value = dec->saturation;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->value = dec->hue;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_saa7115_driver;
|
||||
|
||||
static struct i2c_client wis_saa7115_client_templ = {
|
||||
.name = "SAA7115 (WIS)",
|
||||
.driver = &wis_saa7115_driver,
|
||||
};
|
||||
|
||||
static int wis_saa7115_detect(struct i2c_adapter *adapter, int addr, int kind)
|
||||
{
|
||||
struct i2c_client *client;
|
||||
struct wis_saa7115 *dec;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return 0;
|
||||
|
||||
client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
||||
if (client == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(client, &wis_saa7115_client_templ,
|
||||
sizeof(wis_saa7115_client_templ));
|
||||
client->adapter = adapter;
|
||||
client->addr = addr;
|
||||
|
||||
dec = kmalloc(sizeof(struct wis_saa7115), GFP_KERNEL);
|
||||
if (dec == NULL) {
|
||||
kfree(client);
|
||||
return -ENOMEM;
|
||||
}
|
||||
dec->norm = VIDEO_MODE_NTSC;
|
||||
dec->brightness = 128;
|
||||
dec->contrast = 64;
|
||||
dec->saturation = 64;
|
||||
dec->hue = 0;
|
||||
i2c_set_clientdata(client, dec);
|
||||
|
||||
printk(KERN_DEBUG
|
||||
"wis-saa7115: initializing SAA7115 at address %d on %s\n",
|
||||
addr, adapter->name);
|
||||
|
||||
if (write_regs(client, initial_registers) < 0) {
|
||||
printk(KERN_ERR
|
||||
"wis-saa7115: error initializing SAA7115\n");
|
||||
kfree(client);
|
||||
kfree(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i2c_attach_client(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_saa7115_detach(struct i2c_client *client)
|
||||
{
|
||||
struct wis_saa7115 *dec = i2c_get_clientdata(client);
|
||||
int r;
|
||||
|
||||
r = i2c_detach_client(client);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
kfree(client);
|
||||
kfree(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_saa7115_driver = {
|
||||
.driver = {
|
||||
.name = "WIS SAA7115 I2C driver",
|
||||
},
|
||||
.id = I2C_DRIVERID_WIS_SAA7115,
|
||||
.detach_client = wis_saa7115_detach,
|
||||
.command = wis_saa7115_command,
|
||||
};
|
||||
|
||||
static int __init wis_saa7115_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = i2c_add_driver(&wis_saa7115_driver);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return wis_i2c_add_driver(wis_saa7115_driver.id, wis_saa7115_detect);
|
||||
}
|
||||
|
||||
static void __exit wis_saa7115_cleanup(void)
|
||||
{
|
||||
wis_i2c_del_driver(wis_saa7115_detect);
|
||||
i2c_del_driver(&wis_saa7115_driver);
|
||||
}
|
||||
|
||||
module_init(wis_saa7115_init);
|
||||
module_exit(wis_saa7115_cleanup);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
741
drivers/staging/go7007/wis-sony-tuner.c
Normal file
741
drivers/staging/go7007/wis-sony-tuner.c
Normal file
File diff suppressed because it is too large
Load Diff
381
drivers/staging/go7007/wis-tw2804.c
Normal file
381
drivers/staging/go7007/wis-tw2804.c
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Micronas USA Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2) as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/videodev.h>
|
||||
#include <linux/video_decoder.h>
|
||||
#include <linux/ioctl.h>
|
||||
|
||||
#include "wis-i2c.h"
|
||||
|
||||
struct wis_tw2804 {
|
||||
int channel;
|
||||
int norm;
|
||||
int brightness;
|
||||
int contrast;
|
||||
int saturation;
|
||||
int hue;
|
||||
};
|
||||
|
||||
static u8 global_registers[] =
|
||||
{
|
||||
0x39, 0x00,
|
||||
0x3a, 0xff,
|
||||
0x3b, 0x84,
|
||||
0x3c, 0x80,
|
||||
0x3d, 0x80,
|
||||
0x3e, 0x82,
|
||||
0x3f, 0x82,
|
||||
0xff, 0xff, /* Terminator (reg 0xff does not exist) */
|
||||
};
|
||||
|
||||
static u8 channel_registers[] =
|
||||
{
|
||||
0x01, 0xc4,
|
||||
0x02, 0xa5,
|
||||
0x03, 0x20,
|
||||
0x04, 0xd0,
|
||||
0x05, 0x20,
|
||||
0x06, 0xd0,
|
||||
0x07, 0x88,
|
||||
0x08, 0x20,
|
||||
0x09, 0x07,
|
||||
0x0a, 0xf0,
|
||||
0x0b, 0x07,
|
||||
0x0c, 0xf0,
|
||||
0x0d, 0x40,
|
||||
0x0e, 0xd2,
|
||||
0x0f, 0x80,
|
||||
0x10, 0x80,
|
||||
0x11, 0x80,
|
||||
0x12, 0x80,
|
||||
0x13, 0x1f,
|
||||
0x14, 0x00,
|
||||
0x15, 0x00,
|
||||
0x16, 0x00,
|
||||
0x17, 0x00,
|
||||
0x18, 0xff,
|
||||
0x19, 0xff,
|
||||
0x1a, 0xff,
|
||||
0x1b, 0xff,
|
||||
0x1c, 0xff,
|
||||
0x1d, 0xff,
|
||||
0x1e, 0xff,
|
||||
0x1f, 0xff,
|
||||
0x20, 0x07,
|
||||
0x21, 0x07,
|
||||
0x22, 0x00,
|
||||
0x23, 0x91,
|
||||
0x24, 0x51,
|
||||
0x25, 0x03,
|
||||
0x26, 0x00,
|
||||
0x27, 0x00,
|
||||
0x28, 0x00,
|
||||
0x29, 0x00,
|
||||
0x2a, 0x00,
|
||||
0x2b, 0x00,
|
||||
0x2c, 0x00,
|
||||
0x2d, 0x00,
|
||||
0x2e, 0x00,
|
||||
0x2f, 0x00,
|
||||
0x30, 0x00,
|
||||
0x31, 0x00,
|
||||
0x32, 0x00,
|
||||
0x33, 0x00,
|
||||
0x34, 0x00,
|
||||
0x35, 0x00,
|
||||
0x36, 0x00,
|
||||
0x37, 0x00,
|
||||
0xff, 0xff, /* Terminator (reg 0xff does not exist) */
|
||||
};
|
||||
|
||||
static int write_reg(struct i2c_client *client, u8 reg, u8 value, int channel)
|
||||
{
|
||||
return i2c_smbus_write_byte_data(client, reg | (channel << 6), value);
|
||||
}
|
||||
|
||||
static int write_regs(struct i2c_client *client, u8 *regs, int channel)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; regs[i] != 0xff; i += 2)
|
||||
if (i2c_smbus_write_byte_data(client,
|
||||
regs[i] | (channel << 6), regs[i + 1]) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_tw2804_command(struct i2c_client *client,
|
||||
unsigned int cmd, void *arg)
|
||||
{
|
||||
struct wis_tw2804 *dec = i2c_get_clientdata(client);
|
||||
|
||||
if (cmd == DECODER_SET_CHANNEL) {
|
||||
int *input = arg;
|
||||
|
||||
if (*input < 0 || *input > 3) {
|
||||
printk(KERN_ERR "wis-tw2804: channel %d is not "
|
||||
"between 0 and 3!\n", *input);
|
||||
return 0;
|
||||
}
|
||||
dec->channel = *input;
|
||||
printk(KERN_DEBUG "wis-tw2804: initializing TW2804 "
|
||||
"channel %d\n", dec->channel);
|
||||
if (dec->channel == 0 &&
|
||||
write_regs(client, global_registers, 0) < 0) {
|
||||
printk(KERN_ERR "wis-tw2804: error initializing "
|
||||
"TW2804 global registers\n");
|
||||
return 0;
|
||||
}
|
||||
if (write_regs(client, channel_registers, dec->channel) < 0) {
|
||||
printk(KERN_ERR "wis-tw2804: error initializing "
|
||||
"TW2804 channel %d\n", dec->channel);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dec->channel < 0) {
|
||||
printk(KERN_DEBUG "wis-tw2804: ignoring command %08x until "
|
||||
"channel number is set\n", cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case DECODER_SET_NORM:
|
||||
{
|
||||
int *input = arg;
|
||||
u8 regs[] = {
|
||||
0x01, *input == VIDEO_MODE_NTSC ? 0xc4 : 0x84,
|
||||
0x09, *input == VIDEO_MODE_NTSC ? 0x07 : 0x04,
|
||||
0x0a, *input == VIDEO_MODE_NTSC ? 0xf0 : 0x20,
|
||||
0x0b, *input == VIDEO_MODE_NTSC ? 0x07 : 0x04,
|
||||
0x0c, *input == VIDEO_MODE_NTSC ? 0xf0 : 0x20,
|
||||
0x0d, *input == VIDEO_MODE_NTSC ? 0x40 : 0x4a,
|
||||
0x16, *input == VIDEO_MODE_NTSC ? 0x00 : 0x40,
|
||||
0x17, *input == VIDEO_MODE_NTSC ? 0x00 : 0x40,
|
||||
0x20, *input == VIDEO_MODE_NTSC ? 0x07 : 0x0f,
|
||||
0x21, *input == VIDEO_MODE_NTSC ? 0x07 : 0x0f,
|
||||
0xff, 0xff,
|
||||
};
|
||||
write_regs(client, regs, dec->channel);
|
||||
dec->norm = *input;
|
||||
break;
|
||||
}
|
||||
case VIDIOC_QUERYCTRL:
|
||||
{
|
||||
struct v4l2_queryctrl *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Brightness", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Contrast", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Saturation", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->type = V4L2_CTRL_TYPE_INTEGER;
|
||||
strncpy(ctrl->name, "Hue", sizeof(ctrl->name));
|
||||
ctrl->minimum = 0;
|
||||
ctrl->maximum = 255;
|
||||
ctrl->step = 1;
|
||||
ctrl->default_value = 128;
|
||||
ctrl->flags = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_S_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
if (ctrl->value > 255)
|
||||
dec->brightness = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->brightness = 0;
|
||||
else
|
||||
dec->brightness = ctrl->value;
|
||||
write_reg(client, 0x12, dec->brightness, dec->channel);
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
if (ctrl->value > 255)
|
||||
dec->contrast = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->contrast = 0;
|
||||
else
|
||||
dec->contrast = ctrl->value;
|
||||
write_reg(client, 0x11, dec->contrast, dec->channel);
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
if (ctrl->value > 255)
|
||||
dec->saturation = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->saturation = 0;
|
||||
else
|
||||
dec->saturation = ctrl->value;
|
||||
write_reg(client, 0x10, dec->saturation, dec->channel);
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
if (ctrl->value > 255)
|
||||
dec->hue = 255;
|
||||
else if (ctrl->value < 0)
|
||||
dec->hue = 0;
|
||||
else
|
||||
dec->hue = ctrl->value;
|
||||
write_reg(client, 0x0f, dec->hue, dec->channel);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIDIOC_G_CTRL:
|
||||
{
|
||||
struct v4l2_control *ctrl = arg;
|
||||
|
||||
switch (ctrl->id) {
|
||||
case V4L2_CID_BRIGHTNESS:
|
||||
ctrl->value = dec->brightness;
|
||||
break;
|
||||
case V4L2_CID_CONTRAST:
|
||||
ctrl->value = dec->contrast;
|
||||
break;
|
||||
case V4L2_CID_SATURATION:
|
||||
ctrl->value = dec->saturation;
|
||||
break;
|
||||
case V4L2_CID_HUE:
|
||||
ctrl->value = dec->hue;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_tw2804_driver;
|
||||
|
||||
static struct i2c_client wis_tw2804_client_templ = {
|
||||
.name = "TW2804 (WIS)",
|
||||
.driver = &wis_tw2804_driver,
|
||||
};
|
||||
|
||||
static int wis_tw2804_detect(struct i2c_adapter *adapter, int addr, int kind)
|
||||
{
|
||||
struct i2c_client *client;
|
||||
struct wis_tw2804 *dec;
|
||||
|
||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return 0;
|
||||
|
||||
client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
||||
if (client == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(client, &wis_tw2804_client_templ,
|
||||
sizeof(wis_tw2804_client_templ));
|
||||
client->adapter = adapter;
|
||||
client->addr = addr;
|
||||
|
||||
dec = kmalloc(sizeof(struct wis_tw2804), GFP_KERNEL);
|
||||
if (dec == NULL) {
|
||||
kfree(client);
|
||||
return -ENOMEM;
|
||||
}
|
||||
dec->channel = -1;
|
||||
dec->norm = VIDEO_MODE_NTSC;
|
||||
dec->brightness = 128;
|
||||
dec->contrast = 128;
|
||||
dec->saturation = 128;
|
||||
dec->hue = 128;
|
||||
i2c_set_clientdata(client, dec);
|
||||
|
||||
printk(KERN_DEBUG "wis-tw2804: creating TW2804 at address %d on %s\n",
|
||||
addr, adapter->name);
|
||||
|
||||
i2c_attach_client(client);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wis_tw2804_detach(struct i2c_client *client)
|
||||
{
|
||||
struct wis_tw2804 *dec = i2c_get_clientdata(client);
|
||||
int r;
|
||||
|
||||
r = i2c_detach_client(client);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
kfree(client);
|
||||
kfree(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct i2c_driver wis_tw2804_driver = {
|
||||
.driver = {
|
||||
.name = "WIS TW2804 I2C driver",
|
||||
},
|
||||
.id = I2C_DRIVERID_WIS_TW2804,
|
||||
.detach_client = wis_tw2804_detach,
|
||||
.command = wis_tw2804_command,
|
||||
};
|
||||
|
||||
static int __init wis_tw2804_init(void)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = i2c_add_driver(&wis_tw2804_driver);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return wis_i2c_add_driver(wis_tw2804_driver.id, wis_tw2804_detect);
|
||||
}
|
||||
|
||||
static void __exit wis_tw2804_cleanup(void)
|
||||
{
|
||||
wis_i2c_del_driver(wis_tw2804_detect);
|
||||
i2c_del_driver(&wis_tw2804_driver);
|
||||
}
|
||||
|
||||
module_init(wis_tw2804_init);
|
||||
module_exit(wis_tw2804_cleanup);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user