提交 4e1a04d9 编写于 作者: H Hans Verkuil 提交者: Mauro Carvalho Chehab

V4L/DVB (9205): saa7111: 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: NHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 85ede69f
...@@ -28,43 +28,24 @@ ...@@ -28,43 +28,24 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/signal.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/i2c.h> #include <linux/ioctl.h>
#include <asm/io.h>
#include <asm/pgtable.h>
#include <asm/page.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/i2c.h>
#include <linux/i2c-id.h>
#include <linux/videodev.h> #include <linux/videodev.h>
#include <linux/video_decoder.h> #include <linux/video_decoder.h>
#include <media/v4l2-common.h>
#include <media/v4l2-i2c-drv-legacy.h>
MODULE_DESCRIPTION("Philips SAA7111 video decoder driver"); MODULE_DESCRIPTION("Philips SAA7111 video decoder driver");
MODULE_AUTHOR("Dave Perks"); MODULE_AUTHOR("Dave Perks");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
#define I2C_NAME(s) (s)->name
static int debug; static int debug;
module_param(debug, int, 0644); module_param(debug, int, 0644);
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 SAA7111_NR_REG 0x18 #define SAA7111_NR_REG 0x18
...@@ -77,14 +58,9 @@ struct saa7111 { ...@@ -77,14 +58,9 @@ struct saa7111 {
int enable; int enable;
}; };
#define I2C_SAA7111 0x48
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static inline int static inline int saa7111_write(struct i2c_client *client, u8 reg, u8 value)
saa7111_write (struct i2c_client *client,
u8 reg,
u8 value)
{ {
struct saa7111 *decoder = i2c_get_clientdata(client); struct saa7111 *decoder = i2c_get_clientdata(client);
...@@ -92,8 +68,7 @@ saa7111_write (struct i2c_client *client, ...@@ -92,8 +68,7 @@ saa7111_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 void static inline void saa7111_write_if_changed(struct i2c_client *client, u8 reg, u8 value)
saa7111_write_if_changed(struct i2c_client *client, u8 reg, u8 value)
{ {
struct saa7111 *decoder = i2c_get_clientdata(client); struct saa7111 *decoder = i2c_get_clientdata(client);
...@@ -103,10 +78,7 @@ saa7111_write_if_changed(struct i2c_client *client, u8 reg, u8 value) ...@@ -103,10 +78,7 @@ saa7111_write_if_changed(struct i2c_client *client, u8 reg, u8 value)
} }
} }
static int static int saa7111_write_block(struct i2c_client *client, const u8 *data, unsigned int len)
saa7111_write_block (struct i2c_client *client,
const u8 *data,
unsigned int len)
{ {
int ret = -1; int ret = -1;
u8 reg; u8 reg;
...@@ -127,18 +99,17 @@ saa7111_write_block (struct i2c_client *client, ...@@ -127,18 +99,17 @@ saa7111_write_block (struct i2c_client *client,
decoder->reg[reg++] = data[1]; decoder->reg[reg++] = data[1];
len -= 2; len -= 2;
data += 2; data += 2;
} while (len >= 2 && data[0] == reg && } while (len >= 2 && data[0] == reg && block_len < 32);
block_len < 32); ret = i2c_master_send(client, block_data, block_len);
if ((ret = i2c_master_send(client, block_data, if (ret < 0)
block_len)) < 0)
break; break;
} }
} else { } else {
/* do some slow I2C emulation kind of thing */ /* do some slow I2C emulation kind of thing */
while (len >= 2) { while (len >= 2) {
reg = *data++; reg = *data++;
if ((ret = saa7111_write(client, reg, ret = saa7111_write(client, reg, *data++);
*data++)) < 0) if (ret < 0)
break; break;
len -= 2; len -= 2;
} }
...@@ -147,16 +118,13 @@ saa7111_write_block (struct i2c_client *client, ...@@ -147,16 +118,13 @@ saa7111_write_block (struct i2c_client *client,
return ret; return ret;
} }
static int static int saa7111_init_decoder(struct i2c_client *client,
saa7111_init_decoder (struct i2c_client *client, struct video_decoder_init *init)
struct video_decoder_init *init)
{ {
return saa7111_write_block(client, init->data, init->len); return saa7111_write_block(client, init->data, init->len);
} }
static inline int static inline int saa7111_read(struct i2c_client *client, u8 reg)
saa7111_read (struct i2c_client *client,
u8 reg)
{ {
return i2c_smbus_read_byte_data(client, reg); return i2c_smbus_read_byte_data(client, reg);
} }
...@@ -203,28 +171,23 @@ static const unsigned char saa7111_i2c_init[] = { ...@@ -203,28 +171,23 @@ static const unsigned char saa7111_i2c_init[] = {
0x17, 0x00, /* 17 - VBI */ 0x17, 0x00, /* 17 - VBI */
}; };
static int static int saa7111_command(struct i2c_client *client, unsigned cmd, void *arg)
saa7111_command (struct i2c_client *client,
unsigned int cmd,
void *arg)
{ {
struct saa7111 *decoder = i2c_get_clientdata(client); struct saa7111 *decoder = i2c_get_clientdata(client);
switch (cmd) { switch (cmd) {
case 0: case 0:
break; break;
case DECODER_INIT: case DECODER_INIT:
{ {
struct video_decoder_init *init = arg; struct video_decoder_init *init = arg;
struct video_decoder_init vdi;
if (NULL != init) if (NULL != init)
return saa7111_init_decoder(client, init); return saa7111_init_decoder(client, init);
else { vdi.data = saa7111_i2c_init;
struct video_decoder_init vdi; vdi.len = sizeof(saa7111_i2c_init);
vdi.data = saa7111_i2c_init; return saa7111_init_decoder(client, &vdi);
vdi.len = sizeof(saa7111_i2c_init);
return saa7111_init_decoder(client, &vdi);
}
} }
case DECODER_DUMP: case DECODER_DUMP:
...@@ -234,15 +197,15 @@ saa7111_command (struct i2c_client *client, ...@@ -234,15 +197,15 @@ saa7111_command (struct i2c_client *client,
for (i = 0; i < SAA7111_NR_REG; i += 16) { for (i = 0; i < SAA7111_NR_REG; i += 16) {
int j; int j;
printk(KERN_DEBUG "%s: %03x", I2C_NAME(client), i); v4l_info(client, "%03x", i);
for (j = 0; j < 16 && i + j < SAA7111_NR_REG; ++j) { for (j = 0; j < 16 && i + j < SAA7111_NR_REG; ++j) {
printk(" %02x", printk(KERN_CONT " %02x",
saa7111_read(client, i + j)); saa7111_read(client, i + j));
} }
printk("\n"); printk(KERN_CONT "\n");
} }
}
break; break;
}
case DECODER_GET_CAPABILITIES: case DECODER_GET_CAPABILITIES:
{ {
...@@ -255,8 +218,8 @@ saa7111_command (struct i2c_client *client, ...@@ -255,8 +218,8 @@ saa7111_command (struct i2c_client *client,
VIDEO_DECODER_CCIR; VIDEO_DECODER_CCIR;
cap->inputs = 8; cap->inputs = 8;
cap->outputs = 1; cap->outputs = 1;
}
break; break;
}
case DECODER_GET_STATUS: case DECODER_GET_STATUS:
{ {
...@@ -265,8 +228,7 @@ saa7111_command (struct i2c_client *client, ...@@ -265,8 +228,7 @@ saa7111_command (struct i2c_client *client,
int res; int res;
status = saa7111_read(client, 0x1f); status = saa7111_read(client, 0x1f);
dprintk(1, KERN_DEBUG "%s status: 0x%02x\n", I2C_NAME(client), v4l_dbg(1, debug, client, "status: 0x%02x\n", status);
status);
res = 0; res = 0;
if ((status & (1 << 6)) == 0) { if ((status & (1 << 6)) == 0) {
res |= DECODER_STATUS_GOOD; res |= DECODER_STATUS_GOOD;
...@@ -294,8 +256,8 @@ saa7111_command (struct i2c_client *client, ...@@ -294,8 +256,8 @@ saa7111_command (struct i2c_client *client,
res |= DECODER_STATUS_COLOR; res |= DECODER_STATUS_COLOR;
} }
*iarg = res; *iarg = res;
}
break; break;
}
case DECODER_SET_GPIO: case DECODER_SET_GPIO:
{ {
...@@ -362,8 +324,8 @@ saa7111_command (struct i2c_client *client, ...@@ -362,8 +324,8 @@ saa7111_command (struct i2c_client *client,
} }
decoder->norm = *iarg; decoder->norm = *iarg;
}
break; break;
}
case DECODER_SET_INPUT: case DECODER_SET_INPUT:
{ {
...@@ -387,8 +349,8 @@ saa7111_command (struct i2c_client *client, ...@@ -387,8 +349,8 @@ saa7111_command (struct i2c_client *client,
3) ? 0x80 : 3) ? 0x80 :
0)); 0));
} }
}
break; break;
}
case DECODER_SET_OUTPUT: case DECODER_SET_OUTPUT:
{ {
...@@ -398,8 +360,8 @@ saa7111_command (struct i2c_client *client, ...@@ -398,8 +360,8 @@ saa7111_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:
{ {
...@@ -439,8 +401,8 @@ saa7111_command (struct i2c_client *client, ...@@ -439,8 +401,8 @@ saa7111_command (struct i2c_client *client,
(decoder->reg[0x11] & 0xf3)); (decoder->reg[0x11] & 0xf3));
} }
} }
}
break; break;
}
case DECODER_SET_PICTURE: case DECODER_SET_PICTURE:
{ {
...@@ -454,8 +416,8 @@ saa7111_command (struct i2c_client *client, ...@@ -454,8 +416,8 @@ saa7111_command (struct i2c_client *client,
saa7111_write(client, 0x0c, pic->colour >> 9); saa7111_write(client, 0x0c, pic->colour >> 9);
/* We want -128 to 127 we get 0-65535 */ /* We want -128 to 127 we get 0-65535 */
saa7111_write(client, 0x0d, (pic->hue - 32768) >> 8); saa7111_write(client, 0x0d, (pic->hue - 32768) >> 8);
}
break; break;
}
default: default:
return -EINVAL; return -EINVAL;
...@@ -466,48 +428,23 @@ saa7111_command (struct i2c_client *client, ...@@ -466,48 +428,23 @@ saa7111_command (struct i2c_client *client,
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* static unsigned short normal_i2c[] = { 0x48 >> 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_SAA7111 >> 1, I2C_CLIENT_END };
static unsigned short ignore = I2C_CLIENT_END;
static struct i2c_client_address_data addr_data = {
.normal_i2c = normal_i2c,
.probe = &ignore,
.ignore = &ignore,
};
static struct i2c_driver i2c_driver_saa7111; I2C_CLIENT_INSMOD;
static int static int saa7111_probe(struct i2c_client *client,
saa7111_detect_client (struct i2c_adapter *adapter, const struct i2c_device_id *id)
int address,
int kind)
{ {
int i; int i;
struct i2c_client *client;
struct saa7111 *decoder; struct saa7111 *decoder;
struct video_decoder_init vdi; struct video_decoder_init vdi;
dprintk(1,
KERN_INFO
"saa7111.c: detecting saa7111 client on address 0x%x\n",
address << 1);
/* Check if the adapter supports the needed features */ /* Check if the adapter supports the needed features */
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return 0; return -ENODEV;
client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); v4l_info(client, "chip found @ 0x%x (%s)\n",
if (!client) client->addr << 1, client->adapter->name);
return -ENOMEM;
client->addr = address;
client->adapter = adapter;
client->driver = &i2c_driver_saa7111;
strlcpy(I2C_NAME(client), "saa7111", sizeof(I2C_NAME(client)));
decoder = kzalloc(sizeof(struct saa7111), GFP_KERNEL); decoder = kzalloc(sizeof(struct saa7111), GFP_KERNEL);
if (decoder == NULL) { if (decoder == NULL) {
...@@ -519,82 +456,37 @@ saa7111_detect_client (struct i2c_adapter *adapter, ...@@ -519,82 +456,37 @@ saa7111_detect_client (struct i2c_adapter *adapter,
decoder->enable = 1; decoder->enable = 1;
i2c_set_clientdata(client, decoder); i2c_set_clientdata(client, decoder);
i = i2c_attach_client(client);
if (i) {
kfree(client);
kfree(decoder);
return i;
}
vdi.data = saa7111_i2c_init; vdi.data = saa7111_i2c_init;
vdi.len = sizeof(saa7111_i2c_init); vdi.len = sizeof(saa7111_i2c_init);
i = saa7111_init_decoder(client, &vdi); i = saa7111_init_decoder(client, &vdi);
if (i < 0) { if (i < 0) {
dprintk(1, KERN_ERR "%s_attach error: init status %d\n", v4l_dbg(1, debug, client, "init status %d\n", i);
I2C_NAME(client), i);
} else { } else {
dprintk(1, v4l_dbg(1, debug, client, "revision %x\n",
KERN_INFO saa7111_read(client, 0x00) >> 4);
"%s_attach: chip version %x at address 0x%x\n",
I2C_NAME(client), saa7111_read(client, 0x00) >> 4,
client->addr << 1);
} }
return 0; return 0;
} }
static int static int saa7111_remove(struct i2c_client *client)
saa7111_attach_adapter (struct i2c_adapter *adapter)
{ {
dprintk(1, kfree(i2c_get_clientdata(client));
KERN_INFO
"saa7111.c: starting probe for adapter %s (0x%x)\n",
I2C_NAME(adapter), adapter->id);
return i2c_probe(adapter, &addr_data, &saa7111_detect_client);
}
static int
saa7111_detach_client (struct i2c_client *client)
{
struct saa7111 *decoder = i2c_get_clientdata(client);
int err;
err = i2c_detach_client(client);
if (err) {
return err;
}
kfree(decoder);
kfree(client);
return 0; return 0;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static struct i2c_driver i2c_driver_saa7111 = { static const struct i2c_device_id saa7111_id[] = {
.driver = { { "saa7111_old", 0 }, /* "saa7111" maps to the saa7115 driver */
.name = "saa7111", { }
}, };
MODULE_DEVICE_TABLE(i2c, saa7111_id);
.id = I2C_DRIVERID_SAA7111A,
.attach_adapter = saa7111_attach_adapter, static struct v4l2_i2c_driver_data v4l2_i2c_data = {
.detach_client = saa7111_detach_client, .name = "saa7111",
.driverid = I2C_DRIVERID_SAA7111A,
.command = saa7111_command, .command = saa7111_command,
.probe = saa7111_probe,
.remove = saa7111_remove,
.id_table = saa7111_id,
}; };
static int __init
saa7111_init (void)
{
return i2c_add_driver(&i2c_driver_saa7111);
}
static void __exit
saa7111_exit (void)
{
i2c_del_driver(&i2c_driver_saa7111);
}
module_init(saa7111_init);
module_exit(saa7111_exit);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册