V4L/DVB (9208): vpx3220: convert i2c driver for new i2c API
- Convert to use v4l2-i2c-drv-legacy.h to be able to handle the new i2c API - Cleanups - Use v4l_dbg/v4l_info to have uniform kernel messages Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
committed by
Mauro Carvalho Chehab
parent
0afb351e62
commit
23848b655a
@@ -22,32 +22,21 @@
|
|||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/slab.h>
|
|
||||||
|
|
||||||
#include <asm/io.h>
|
|
||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
|
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
|
|
||||||
#define I2C_NAME(x) (x)->name
|
|
||||||
|
|
||||||
#include <linux/videodev.h>
|
|
||||||
#include <media/v4l2-common.h>
|
#include <media/v4l2-common.h>
|
||||||
|
#include <media/v4l2-i2c-drv-legacy.h>
|
||||||
|
#include <linux/videodev.h>
|
||||||
#include <linux/video_decoder.h>
|
#include <linux/video_decoder.h>
|
||||||
|
|
||||||
#define I2C_VPX3220 0x86
|
MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver");
|
||||||
#define VPX3220_DEBUG KERN_DEBUG "vpx3220: "
|
MODULE_AUTHOR("Laurent Pinchart");
|
||||||
|
MODULE_LICENSE("GPL");
|
||||||
|
|
||||||
static int debug;
|
static int debug;
|
||||||
module_param(debug, int, 0);
|
module_param(debug, int, 0);
|
||||||
MODULE_PARM_DESC(debug, "Debug level (0-1)");
|
MODULE_PARM_DESC(debug, "Debug level (0-1)");
|
||||||
|
|
||||||
#define dprintk(num, format, args...) \
|
|
||||||
do { \
|
|
||||||
if (debug >= num) \
|
|
||||||
printk(format, ##args); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define VPX_TIMEOUT_COUNT 10
|
#define VPX_TIMEOUT_COUNT 10
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
@@ -67,10 +56,8 @@ struct vpx3220 {
|
|||||||
static char *inputs[] = { "internal", "composite", "svideo" };
|
static char *inputs[] = { "internal", "composite", "svideo" };
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------- */
|
/* ----------------------------------------------------------------------- */
|
||||||
static inline int
|
|
||||||
vpx3220_write (struct i2c_client *client,
|
static inline int vpx3220_write(struct i2c_client *client, u8 reg, u8 value)
|
||||||
u8 reg,
|
|
||||||
u8 value)
|
|
||||||
{
|
{
|
||||||
struct vpx3220 *decoder = i2c_get_clientdata(client);
|
struct vpx3220 *decoder = i2c_get_clientdata(client);
|
||||||
|
|
||||||
@@ -78,15 +65,12 @@ vpx3220_write (struct i2c_client *client,
|
|||||||
return i2c_smbus_write_byte_data(client, reg, value);
|
return i2c_smbus_write_byte_data(client, reg, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int vpx3220_read(struct i2c_client *client, u8 reg)
|
||||||
vpx3220_read (struct i2c_client *client,
|
|
||||||
u8 reg)
|
|
||||||
{
|
{
|
||||||
return i2c_smbus_read_byte_data(client, reg);
|
return i2c_smbus_read_byte_data(client, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_fp_status(struct i2c_client *client)
|
||||||
vpx3220_fp_status (struct i2c_client *client)
|
|
||||||
{
|
{
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@@ -106,14 +90,11 @@ vpx3220_fp_status (struct i2c_client *client)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_fp_write(struct i2c_client *client, u8 fpaddr, u16 data)
|
||||||
vpx3220_fp_write (struct i2c_client *client,
|
|
||||||
u8 fpaddr,
|
|
||||||
u16 data)
|
|
||||||
{
|
{
|
||||||
/* Write the 16-bit address to the FPWR register */
|
/* Write the 16-bit address to the FPWR register */
|
||||||
if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) {
|
if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) {
|
||||||
dprintk(1, VPX3220_DEBUG "%s: failed\n", __func__);
|
v4l_dbg(1, debug, client, "%s: failed\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,22 +103,20 @@ vpx3220_fp_write (struct i2c_client *client,
|
|||||||
|
|
||||||
/* Write the 16-bit data to the FPDAT register */
|
/* Write the 16-bit data to the FPDAT register */
|
||||||
if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) {
|
if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) {
|
||||||
dprintk(1, VPX3220_DEBUG "%s: failed\n", __func__);
|
v4l_dbg(1, debug, client, "%s: failed\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static u16
|
static u16 vpx3220_fp_read(struct i2c_client *client, u16 fpaddr)
|
||||||
vpx3220_fp_read (struct i2c_client *client,
|
|
||||||
u16 fpaddr)
|
|
||||||
{
|
{
|
||||||
s16 data;
|
s16 data;
|
||||||
|
|
||||||
/* Write the 16-bit address to the FPRD register */
|
/* Write the 16-bit address to the FPRD register */
|
||||||
if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) {
|
if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) {
|
||||||
dprintk(1, VPX3220_DEBUG "%s: failed\n", __func__);
|
v4l_dbg(1, debug, client, "%s: failed\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,25 +126,22 @@ vpx3220_fp_read (struct i2c_client *client,
|
|||||||
/* Read the 16-bit data from the FPDAT register */
|
/* Read the 16-bit data from the FPDAT register */
|
||||||
data = i2c_smbus_read_word_data(client, 0x28);
|
data = i2c_smbus_read_word_data(client, 0x28);
|
||||||
if (data == -1) {
|
if (data == -1) {
|
||||||
dprintk(1, VPX3220_DEBUG "%s: failed\n", __func__);
|
v4l_dbg(1, debug, client, "%s: failed\n", __func__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return swab16(data);
|
return swab16(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_write_block(struct i2c_client *client, const u8 *data, unsigned int len)
|
||||||
vpx3220_write_block (struct i2c_client *client,
|
|
||||||
const u8 *data,
|
|
||||||
unsigned int len)
|
|
||||||
{
|
{
|
||||||
u8 reg;
|
u8 reg;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
while (len >= 2) {
|
while (len >= 2) {
|
||||||
reg = *data++;
|
reg = *data++;
|
||||||
if ((ret =
|
ret = vpx3220_write(client, reg, *data++);
|
||||||
vpx3220_write(client, reg, *data++)) < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
len -= 2;
|
len -= 2;
|
||||||
}
|
}
|
||||||
@@ -173,10 +149,8 @@ vpx3220_write_block (struct i2c_client *client,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_write_fp_block(struct i2c_client *client,
|
||||||
vpx3220_write_fp_block (struct i2c_client *client,
|
const u16 *data, unsigned int len)
|
||||||
const u16 *data,
|
|
||||||
unsigned int len)
|
|
||||||
{
|
{
|
||||||
u8 reg;
|
u8 reg;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@@ -285,25 +259,20 @@ static const unsigned short init_fp[] = {
|
|||||||
0x4b, 0x298, /* PLL gain */
|
0x4b, 0x298, /* PLL gain */
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void vpx3220_dump_i2c(struct i2c_client *client)
|
||||||
vpx3220_dump_i2c (struct i2c_client *client)
|
|
||||||
{
|
{
|
||||||
int len = sizeof(init_common);
|
int len = sizeof(init_common);
|
||||||
const unsigned char *data = init_common;
|
const unsigned char *data = init_common;
|
||||||
|
|
||||||
while (len > 1) {
|
while (len > 1) {
|
||||||
dprintk(1,
|
v4l_dbg(1, debug, client, "i2c reg 0x%02x data 0x%02x\n",
|
||||||
KERN_DEBUG "vpx3216b i2c reg 0x%02x data 0x%02x\n",
|
|
||||||
*data, vpx3220_read(client, *data));
|
*data, vpx3220_read(client, *data));
|
||||||
data += 2;
|
data += 2;
|
||||||
len -= 2;
|
len -= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_command(struct i2c_client *client, unsigned cmd, void *arg)
|
||||||
vpx3220_command (struct i2c_client *client,
|
|
||||||
unsigned int cmd,
|
|
||||||
void *arg)
|
|
||||||
{
|
{
|
||||||
struct vpx3220 *decoder = i2c_get_clientdata(client);
|
struct vpx3220 *decoder = i2c_get_clientdata(client);
|
||||||
|
|
||||||
@@ -315,7 +284,6 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
vpx3220_write_fp_block(client, init_fp,
|
vpx3220_write_fp_block(client, init_fp,
|
||||||
sizeof(init_fp) >> 1);
|
sizeof(init_fp) >> 1);
|
||||||
switch (decoder->norm) {
|
switch (decoder->norm) {
|
||||||
|
|
||||||
case VIDEO_MODE_NTSC:
|
case VIDEO_MODE_NTSC:
|
||||||
vpx3220_write_fp_block(client, init_ntsc,
|
vpx3220_write_fp_block(client, init_ntsc,
|
||||||
sizeof(init_ntsc) >> 1);
|
sizeof(init_ntsc) >> 1);
|
||||||
@@ -334,21 +302,20 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
sizeof(init_pal) >> 1);
|
sizeof(init_pal) >> 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_DUMP:
|
case DECODER_DUMP:
|
||||||
{
|
{
|
||||||
vpx3220_dump_i2c(client);
|
vpx3220_dump_i2c(client);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_GET_CAPABILITIES:
|
case DECODER_GET_CAPABILITIES:
|
||||||
{
|
{
|
||||||
struct video_decoder_capability *cap = arg;
|
struct video_decoder_capability *cap = arg;
|
||||||
|
|
||||||
dprintk(1, KERN_DEBUG "%s: DECODER_GET_CAPABILITIES\n",
|
v4l_dbg(1, debug, client, "DECODER_GET_CAPABILITIES\n");
|
||||||
I2C_NAME(client));
|
|
||||||
|
|
||||||
cap->flags = VIDEO_DECODER_PAL |
|
cap->flags = VIDEO_DECODER_PAL |
|
||||||
VIDEO_DECODER_NTSC |
|
VIDEO_DECODER_NTSC |
|
||||||
@@ -357,20 +324,18 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
VIDEO_DECODER_CCIR;
|
VIDEO_DECODER_CCIR;
|
||||||
cap->inputs = 3;
|
cap->inputs = 3;
|
||||||
cap->outputs = 1;
|
cap->outputs = 1;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_GET_STATUS:
|
case DECODER_GET_STATUS:
|
||||||
{
|
{
|
||||||
int res = 0, status;
|
int res = 0, status;
|
||||||
|
|
||||||
dprintk(1, KERN_INFO "%s: DECODER_GET_STATUS\n",
|
v4l_dbg(1, debug, client, "DECODER_GET_STATUS\n");
|
||||||
I2C_NAME(client));
|
|
||||||
|
|
||||||
status = vpx3220_fp_read(client, 0x0f3);
|
status = vpx3220_fp_read(client, 0x0f3);
|
||||||
|
|
||||||
dprintk(1, KERN_INFO "%s: status: 0x%04x\n", I2C_NAME(client),
|
v4l_dbg(1, debug, client, "status: 0x%04x\n", status);
|
||||||
status);
|
|
||||||
|
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
@@ -379,7 +344,6 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
res |= DECODER_STATUS_GOOD | DECODER_STATUS_COLOR;
|
res |= DECODER_STATUS_GOOD | DECODER_STATUS_COLOR;
|
||||||
|
|
||||||
switch (status & 0x18) {
|
switch (status & 0x18) {
|
||||||
|
|
||||||
case 0x00:
|
case 0x00:
|
||||||
case 0x10:
|
case 0x10:
|
||||||
case 0x14:
|
case 0x14:
|
||||||
@@ -400,8 +364,8 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*(int *) arg = res;
|
*(int *) arg = res;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_SET_NORM:
|
case DECODER_SET_NORM:
|
||||||
{
|
{
|
||||||
@@ -413,50 +377,43 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
choosen video norm */
|
choosen video norm */
|
||||||
temp_input = vpx3220_fp_read(client, 0xf2);
|
temp_input = vpx3220_fp_read(client, 0xf2);
|
||||||
|
|
||||||
dprintk(1, KERN_DEBUG "%s: DECODER_SET_NORM %d\n",
|
v4l_dbg(1, debug, client, "DECODER_SET_NORM %d\n", *iarg);
|
||||||
I2C_NAME(client), *iarg);
|
|
||||||
switch (*iarg) {
|
switch (*iarg) {
|
||||||
|
|
||||||
case VIDEO_MODE_NTSC:
|
case VIDEO_MODE_NTSC:
|
||||||
vpx3220_write_fp_block(client, init_ntsc,
|
vpx3220_write_fp_block(client, init_ntsc,
|
||||||
sizeof(init_ntsc) >> 1);
|
sizeof(init_ntsc) >> 1);
|
||||||
dprintk(1, KERN_INFO "%s: norm switched to NTSC\n",
|
v4l_dbg(1, debug, client, "norm switched to NTSC\n");
|
||||||
I2C_NAME(client));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIDEO_MODE_PAL:
|
case VIDEO_MODE_PAL:
|
||||||
vpx3220_write_fp_block(client, init_pal,
|
vpx3220_write_fp_block(client, init_pal,
|
||||||
sizeof(init_pal) >> 1);
|
sizeof(init_pal) >> 1);
|
||||||
dprintk(1, KERN_INFO "%s: norm switched to PAL\n",
|
v4l_dbg(1, debug, client, "norm switched to PAL\n");
|
||||||
I2C_NAME(client));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIDEO_MODE_SECAM:
|
case VIDEO_MODE_SECAM:
|
||||||
vpx3220_write_fp_block(client, init_secam,
|
vpx3220_write_fp_block(client, init_secam,
|
||||||
sizeof(init_secam) >> 1);
|
sizeof(init_secam) >> 1);
|
||||||
dprintk(1, KERN_INFO "%s: norm switched to SECAM\n",
|
v4l_dbg(1, debug, client, "norm switched to SECAM\n");
|
||||||
I2C_NAME(client));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIDEO_MODE_AUTO:
|
case VIDEO_MODE_AUTO:
|
||||||
/* FIXME This is only preliminary support */
|
/* FIXME This is only preliminary support */
|
||||||
data = vpx3220_fp_read(client, 0xf2) & 0x20;
|
data = vpx3220_fp_read(client, 0xf2) & 0x20;
|
||||||
vpx3220_fp_write(client, 0xf2, 0x00c0 | data);
|
vpx3220_fp_write(client, 0xf2, 0x00c0 | data);
|
||||||
dprintk(1, KERN_INFO "%s: norm switched to Auto\n",
|
v4l_dbg(1, debug, client, "norm switched to AUTO\n");
|
||||||
I2C_NAME(client));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
}
|
}
|
||||||
decoder->norm = *iarg;
|
decoder->norm = *iarg;
|
||||||
|
|
||||||
/* And here we set the backed up video input again */
|
/* And here we set the backed up video input again */
|
||||||
vpx3220_fp_write(client, 0xf2, temp_input | 0x0010);
|
vpx3220_fp_write(client, 0xf2, temp_input | 0x0010);
|
||||||
udelay(10);
|
udelay(10);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_SET_INPUT:
|
case DECODER_SET_INPUT:
|
||||||
{
|
{
|
||||||
@@ -475,8 +432,7 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
if (*iarg < 0 || *iarg > 2)
|
if (*iarg < 0 || *iarg > 2)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
dprintk(1, KERN_INFO "%s: input switched to %s\n",
|
v4l_dbg(1, debug, client, "input switched to %s\n", inputs[*iarg]);
|
||||||
I2C_NAME(client), inputs[*iarg]);
|
|
||||||
|
|
||||||
vpx3220_write(client, 0x33, input[*iarg][0]);
|
vpx3220_write(client, 0x33, input[*iarg][0]);
|
||||||
|
|
||||||
@@ -488,8 +444,8 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
data | (input[*iarg][1] << 5) | 0x0010);
|
data | (input[*iarg][1] << 5) | 0x0010);
|
||||||
|
|
||||||
udelay(10);
|
udelay(10);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_SET_OUTPUT:
|
case DECODER_SET_OUTPUT:
|
||||||
{
|
{
|
||||||
@@ -499,19 +455,18 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
if (*iarg != 0) {
|
if (*iarg != 0) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_ENABLE_OUTPUT:
|
case DECODER_ENABLE_OUTPUT:
|
||||||
{
|
{
|
||||||
int *iarg = arg;
|
int *iarg = arg;
|
||||||
|
|
||||||
dprintk(1, KERN_DEBUG "%s: DECODER_ENABLE_OUTPUT %d\n",
|
v4l_dbg(1, debug, client, "DECODER_ENABLE_OUTPUT %d\n", *iarg);
|
||||||
I2C_NAME(client), *iarg);
|
|
||||||
|
|
||||||
vpx3220_write(client, 0xf2, (*iarg ? 0x1b : 0x00));
|
vpx3220_write(client, 0xf2, (*iarg ? 0x1b : 0x00));
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case DECODER_SET_PICTURE:
|
case DECODER_SET_PICTURE:
|
||||||
{
|
{
|
||||||
@@ -542,8 +497,8 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
vpx3220_fp_write(client, 0x1c,
|
vpx3220_fp_write(client, 0x1c,
|
||||||
((decoder->hue - 32768) >> 6) & 0xFFF);
|
((decoder->hue - 32768) >> 6) & 0xFFF);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -552,8 +507,7 @@ vpx3220_command (struct i2c_client *client,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_init_client(struct i2c_client *client)
|
||||||
vpx3220_init_client (struct i2c_client *client)
|
|
||||||
{
|
{
|
||||||
vpx3220_write_block(client, init_common, sizeof(init_common));
|
vpx3220_write_block(client, init_common, sizeof(init_common));
|
||||||
vpx3220_write_fp_block(client, init_fp, sizeof(init_fp) >> 1);
|
vpx3220_write_fp_block(client, init_fp, sizeof(init_fp) >> 1);
|
||||||
@@ -567,115 +521,26 @@ vpx3220_init_client (struct i2c_client *client)
|
|||||||
* Client management code
|
* Client management code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
static unsigned short normal_i2c[] = { 0x86 >> 1, 0x8e >> 1, I2C_CLIENT_END };
|
||||||
* Generic i2c probe
|
|
||||||
* concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
|
|
||||||
*/
|
|
||||||
static unsigned short normal_i2c[] =
|
|
||||||
{ I2C_VPX3220 >> 1, (I2C_VPX3220 >> 1) + 4,
|
|
||||||
I2C_CLIENT_END
|
|
||||||
};
|
|
||||||
|
|
||||||
static unsigned short ignore = I2C_CLIENT_END;
|
I2C_CLIENT_INSMOD;
|
||||||
|
|
||||||
static struct i2c_client_address_data addr_data = {
|
static int vpx3220_probe(struct i2c_client *client,
|
||||||
.normal_i2c = normal_i2c,
|
const struct i2c_device_id *id)
|
||||||
.probe = &ignore,
|
|
||||||
.ignore = &ignore,
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct i2c_driver vpx3220_i2c_driver;
|
|
||||||
|
|
||||||
static int
|
|
||||||
vpx3220_detach_client (struct i2c_client *client)
|
|
||||||
{
|
{
|
||||||
struct vpx3220 *decoder = i2c_get_clientdata(client);
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = i2c_detach_client(client);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
kfree(decoder);
|
|
||||||
kfree(client);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
vpx3220_detect_client (struct i2c_adapter *adapter,
|
|
||||||
int address,
|
|
||||||
int kind)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
struct i2c_client *client;
|
|
||||||
struct vpx3220 *decoder;
|
struct vpx3220 *decoder;
|
||||||
|
const char *name = NULL;
|
||||||
dprintk(1, VPX3220_DEBUG "%s\n", __func__);
|
u8 ver;
|
||||||
|
u16 pn;
|
||||||
|
|
||||||
/* Check if the adapter supports the needed features */
|
/* Check if the adapter supports the needed features */
|
||||||
if (!i2c_check_functionality
|
if (!i2c_check_functionality(client->adapter,
|
||||||
(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
|
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
|
||||||
return 0;
|
return -ENODEV;
|
||||||
|
|
||||||
client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
|
||||||
if (client == NULL) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
client->addr = address;
|
|
||||||
client->adapter = adapter;
|
|
||||||
client->driver = &vpx3220_i2c_driver;
|
|
||||||
|
|
||||||
/* Check for manufacture ID and part number */
|
|
||||||
if (kind < 0) {
|
|
||||||
u8 id;
|
|
||||||
u16 pn;
|
|
||||||
|
|
||||||
id = vpx3220_read(client, 0x00);
|
|
||||||
if (id != 0xec) {
|
|
||||||
dprintk(1,
|
|
||||||
KERN_INFO
|
|
||||||
"vpx3220_attach: Wrong manufacturer ID (0x%02x)\n",
|
|
||||||
id);
|
|
||||||
kfree(client);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pn = (vpx3220_read(client, 0x02) << 8) +
|
|
||||||
vpx3220_read(client, 0x01);
|
|
||||||
switch (pn) {
|
|
||||||
case 0x4680:
|
|
||||||
strlcpy(I2C_NAME(client), "vpx3220a",
|
|
||||||
sizeof(I2C_NAME(client)));
|
|
||||||
break;
|
|
||||||
case 0x4260:
|
|
||||||
strlcpy(I2C_NAME(client), "vpx3216b",
|
|
||||||
sizeof(I2C_NAME(client)));
|
|
||||||
break;
|
|
||||||
case 0x4280:
|
|
||||||
strlcpy(I2C_NAME(client), "vpx3214c",
|
|
||||||
sizeof(I2C_NAME(client)));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dprintk(1,
|
|
||||||
KERN_INFO
|
|
||||||
"%s: Wrong part number (0x%04x)\n",
|
|
||||||
__func__, pn);
|
|
||||||
kfree(client);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
strlcpy(I2C_NAME(client), "forced vpx32xx",
|
|
||||||
sizeof(I2C_NAME(client)));
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL);
|
decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL);
|
||||||
if (decoder == NULL) {
|
if (decoder == NULL)
|
||||||
kfree(client);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
decoder->norm = VIDEO_MODE_PAL;
|
decoder->norm = VIDEO_MODE_PAL;
|
||||||
decoder->input = 0;
|
decoder->input = 0;
|
||||||
decoder->enable = 1;
|
decoder->enable = 1;
|
||||||
@@ -685,63 +550,52 @@ vpx3220_detect_client (struct i2c_adapter *adapter,
|
|||||||
decoder->sat = 32768;
|
decoder->sat = 32768;
|
||||||
i2c_set_clientdata(client, decoder);
|
i2c_set_clientdata(client, decoder);
|
||||||
|
|
||||||
err = i2c_attach_client(client);
|
ver = i2c_smbus_read_byte_data(client, 0x00);
|
||||||
if (err) {
|
pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) +
|
||||||
kfree(client);
|
i2c_smbus_read_byte_data(client, 0x01);
|
||||||
kfree(decoder);
|
if (ver == 0xec) {
|
||||||
return err;
|
switch (pn) {
|
||||||
|
case 0x4680:
|
||||||
|
name = "vpx3220a";
|
||||||
|
break;
|
||||||
|
case 0x4260:
|
||||||
|
name = "vpx3216b";
|
||||||
|
break;
|
||||||
|
case 0x4280:
|
||||||
|
name = "vpx3214c";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (name)
|
||||||
dprintk(1, KERN_INFO "%s: vpx32xx client found at address 0x%02x\n",
|
v4l_info(client, "%s found @ 0x%x (%s)\n", name,
|
||||||
I2C_NAME(client), client->addr << 1);
|
client->addr << 1, client->adapter->name);
|
||||||
|
else
|
||||||
|
v4l_info(client, "chip (%02x:%04x) found @ 0x%x (%s)\n",
|
||||||
|
ver, pn, client->addr << 1, client->adapter->name);
|
||||||
|
|
||||||
vpx3220_init_client(client);
|
vpx3220_init_client(client);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int vpx3220_remove(struct i2c_client *client)
|
||||||
vpx3220_attach_adapter (struct i2c_adapter *adapter)
|
|
||||||
{
|
{
|
||||||
int ret;
|
kfree(i2c_get_clientdata(client));
|
||||||
|
return 0;
|
||||||
ret = i2c_probe(adapter, &addr_data, &vpx3220_detect_client);
|
|
||||||
dprintk(1, VPX3220_DEBUG "%s: i2c_probe returned %d\n",
|
|
||||||
__func__, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------
|
static const struct i2c_device_id vpx3220_id[] = {
|
||||||
* Driver initialization and cleanup code
|
{ "vpx3220a", 0 },
|
||||||
*/
|
{ "vpx3216b", 0 },
|
||||||
|
{ "vpx3214c", 0 },
|
||||||
static struct i2c_driver vpx3220_i2c_driver = {
|
{ }
|
||||||
.driver = {
|
|
||||||
.name = "vpx3220",
|
|
||||||
},
|
|
||||||
|
|
||||||
.id = I2C_DRIVERID_VPX3220,
|
|
||||||
|
|
||||||
.attach_adapter = vpx3220_attach_adapter,
|
|
||||||
.detach_client = vpx3220_detach_client,
|
|
||||||
.command = vpx3220_command,
|
|
||||||
};
|
};
|
||||||
|
MODULE_DEVICE_TABLE(i2c, vpx3220_id);
|
||||||
|
|
||||||
static int __init
|
static struct v4l2_i2c_driver_data v4l2_i2c_data = {
|
||||||
vpx3220_init (void)
|
.name = "vpx3220",
|
||||||
{
|
.driverid = I2C_DRIVERID_VPX3220,
|
||||||
return i2c_add_driver(&vpx3220_i2c_driver);
|
.command = vpx3220_command,
|
||||||
}
|
.probe = vpx3220_probe,
|
||||||
|
.remove = vpx3220_remove,
|
||||||
static void __exit
|
.id_table = vpx3220_id,
|
||||||
vpx3220_cleanup (void)
|
};
|
||||||
{
|
|
||||||
i2c_del_driver(&vpx3220_i2c_driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
module_init(vpx3220_init);
|
|
||||||
module_exit(vpx3220_cleanup);
|
|
||||||
|
|
||||||
MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver");
|
|
||||||
MODULE_AUTHOR("Laurent Pinchart");
|
|
||||||
MODULE_LICENSE("GPL");
|
|
||||||
|
Reference in New Issue
Block a user