diff options
Diffstat (limited to 'drivers/media/video/bt856.c')
-rw-r--r-- | drivers/media/video/bt856.c | 292 |
1 files changed, 129 insertions, 163 deletions
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c index 4213867507f..d0b4d4925ff 100644 --- a/drivers/media/video/bt856.c +++ b/drivers/media/video/bt856.c @@ -34,10 +34,10 @@ #include <asm/uaccess.h> #include <linux/i2c.h> #include <linux/i2c-id.h> -#include <linux/videodev.h> -#include <linux/video_encoder.h> -#include <media/v4l2-common.h> -#include <media/v4l2-i2c-drv-legacy.h> +#include <linux/videodev2.h> +#include <media/v4l2-device.h> +#include <media/v4l2-chip-ident.h> +#include <media/v4l2-i2c-drv.h> MODULE_DESCRIPTION("Brooktree-856A video encoder driver"); MODULE_AUTHOR("Mike Bernson & Dave Perks"); @@ -47,43 +47,46 @@ static int debug; module_param(debug, int, 0); MODULE_PARM_DESC(debug, "Debug level (0-1)"); + /* ----------------------------------------------------------------------- */ #define BT856_REG_OFFSET 0xDA #define BT856_NR_REG 6 struct bt856 { + struct v4l2_subdev sd; unsigned char reg[BT856_NR_REG]; - int norm; - int enable; + v4l2_std_id norm; }; +static inline struct bt856 *to_bt856(struct v4l2_subdev *sd) +{ + return container_of(sd, struct bt856, sd); +} + /* ----------------------------------------------------------------------- */ -static inline int bt856_write(struct i2c_client *client, u8 reg, u8 value) +static inline int bt856_write(struct bt856 *encoder, u8 reg, u8 value) { - struct bt856 *encoder = i2c_get_clientdata(client); + struct i2c_client *client = v4l2_get_subdevdata(&encoder->sd); encoder->reg[reg - BT856_REG_OFFSET] = value; return i2c_smbus_write_byte_data(client, reg, value); } -static inline int bt856_setbit(struct i2c_client *client, u8 reg, u8 bit, u8 value) +static inline int bt856_setbit(struct bt856 *encoder, u8 reg, u8 bit, u8 value) { - struct bt856 *encoder = i2c_get_clientdata(client); - - return bt856_write(client, reg, + return bt856_write(encoder, reg, (encoder->reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) | (value ? (1 << bit) : 0)); } -static void bt856_dump(struct i2c_client *client) +static void bt856_dump(struct bt856 *encoder) { int i; - struct bt856 *encoder = i2c_get_clientdata(client); - v4l_info(client, "register dump:\n"); + v4l2_info(&encoder->sd, "register dump:\n"); for (i = 0; i < BT856_NR_REG; i += 2) printk(KERN_CONT " %02x", encoder->reg[i]); printk(KERN_CONT "\n"); @@ -91,153 +94,121 @@ static void bt856_dump(struct i2c_client *client) /* ----------------------------------------------------------------------- */ -static int bt856_command(struct i2c_client *client, unsigned cmd, void *arg) +static int bt856_init(struct v4l2_subdev *sd, u32 arg) { - struct bt856 *encoder = i2c_get_clientdata(client); - - switch (cmd) { - case 0: - /* This is just for testing!!! */ - v4l_dbg(1, debug, client, "init\n"); - bt856_write(client, 0xdc, 0x18); - bt856_write(client, 0xda, 0); - bt856_write(client, 0xde, 0); - - bt856_setbit(client, 0xdc, 3, 1); - //bt856_setbit(client, 0xdc, 6, 0); - bt856_setbit(client, 0xdc, 4, 1); - - switch (encoder->norm) { - case VIDEO_MODE_NTSC: - bt856_setbit(client, 0xdc, 2, 0); - break; - - case VIDEO_MODE_PAL: - bt856_setbit(client, 0xdc, 2, 1); - break; - } - - bt856_setbit(client, 0xdc, 1, 1); - bt856_setbit(client, 0xde, 4, 0); - bt856_setbit(client, 0xde, 3, 1); - if (debug != 0) - bt856_dump(client); - break; - - case ENCODER_GET_CAPABILITIES: - { - struct video_encoder_capability *cap = arg; - - v4l_dbg(1, debug, client, "get capabilities\n"); + struct bt856 *encoder = to_bt856(sd); + + /* This is just for testing!!! */ + v4l2_dbg(1, debug, sd, "init\n"); + bt856_write(encoder, 0xdc, 0x18); + bt856_write(encoder, 0xda, 0); + bt856_write(encoder, 0xde, 0); + + bt856_setbit(encoder, 0xdc, 3, 1); + /*bt856_setbit(encoder, 0xdc, 6, 0);*/ + bt856_setbit(encoder, 0xdc, 4, 1); + + if (encoder->norm & V4L2_STD_NTSC) + bt856_setbit(encoder, 0xdc, 2, 0); + else + bt856_setbit(encoder, 0xdc, 2, 1); + + bt856_setbit(encoder, 0xdc, 1, 1); + bt856_setbit(encoder, 0xde, 4, 0); + bt856_setbit(encoder, 0xde, 3, 1); + if (debug != 0) + bt856_dump(encoder); + return 0; +} - cap->flags = VIDEO_ENCODER_PAL | - VIDEO_ENCODER_NTSC | - VIDEO_ENCODER_CCIR; - cap->inputs = 2; - cap->outputs = 1; - break; - } +static int bt856_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) +{ + struct bt856 *encoder = to_bt856(sd); - case ENCODER_SET_NORM: - { - int *iarg = arg; - - v4l_dbg(1, debug, client, "set norm %d\n", *iarg); - - switch (*iarg) { - case VIDEO_MODE_NTSC: - bt856_setbit(client, 0xdc, 2, 0); - break; - - case VIDEO_MODE_PAL: - bt856_setbit(client, 0xdc, 2, 1); - bt856_setbit(client, 0xda, 0, 0); - //bt856_setbit(client, 0xda, 0, 1); - break; - - default: - return -EINVAL; - } - encoder->norm = *iarg; - if (debug != 0) - bt856_dump(client); - break; - } + v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std); - case ENCODER_SET_INPUT: - { - int *iarg = arg; - - v4l_dbg(1, debug, client, "set input %d\n", *iarg); - - /* We only have video bus. - * iarg = 0: input is from bt819 - * iarg = 1: input is from ZR36060 */ - switch (*iarg) { - case 0: - bt856_setbit(client, 0xde, 4, 0); - bt856_setbit(client, 0xde, 3, 1); - bt856_setbit(client, 0xdc, 3, 1); - bt856_setbit(client, 0xdc, 6, 0); - break; - case 1: - bt856_setbit(client, 0xde, 4, 0); - bt856_setbit(client, 0xde, 3, 1); - bt856_setbit(client, 0xdc, 3, 1); - bt856_setbit(client, 0xdc, 6, 1); - break; - case 2: // Color bar - bt856_setbit(client, 0xdc, 3, 0); - bt856_setbit(client, 0xde, 4, 1); - break; - default: - return -EINVAL; - } - - if (debug != 0) - bt856_dump(client); - break; + if (std & V4L2_STD_NTSC) { + bt856_setbit(encoder, 0xdc, 2, 0); + } else if (std & V4L2_STD_PAL) { + bt856_setbit(encoder, 0xdc, 2, 1); + bt856_setbit(encoder, 0xda, 0, 0); + /*bt856_setbit(encoder, 0xda, 0, 1);*/ + } else { + return -EINVAL; } + encoder->norm = std; + if (debug != 0) + bt856_dump(encoder); + return 0; +} - case ENCODER_SET_OUTPUT: - { - int *iarg = arg; +static int bt856_s_routing(struct v4l2_subdev *sd, + u32 input, u32 output, u32 config) +{ + struct bt856 *encoder = to_bt856(sd); - v4l_dbg(1, debug, client, "set output %d\n", *iarg); + v4l2_dbg(1, debug, sd, "set input %d\n", input); - /* not much choice of outputs */ - if (*iarg != 0) - return -EINVAL; + /* We only have video bus. + * input= 0: input is from bt819 + * input= 1: input is from ZR36060 */ + switch (input) { + case 0: + bt856_setbit(encoder, 0xde, 4, 0); + bt856_setbit(encoder, 0xde, 3, 1); + bt856_setbit(encoder, 0xdc, 3, 1); + bt856_setbit(encoder, 0xdc, 6, 0); break; - } - - case ENCODER_ENABLE_OUTPUT: - { - int *iarg = arg; - - encoder->enable = !!*iarg; - - v4l_dbg(1, debug, client, "enable output %d\n", encoder->enable); + case 1: + bt856_setbit(encoder, 0xde, 4, 0); + bt856_setbit(encoder, 0xde, 3, 1); + bt856_setbit(encoder, 0xdc, 3, 1); + bt856_setbit(encoder, 0xdc, 6, 1); + break; + case 2: /* Color bar */ + bt856_setbit(encoder, 0xdc, 3, 0); + bt856_setbit(encoder, 0xde, 4, 1); break; - } - default: return -EINVAL; } + if (debug != 0) + bt856_dump(encoder); return 0; } +static int bt856_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_BT856, 0); +} + /* ----------------------------------------------------------------------- */ -static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; +static const struct v4l2_subdev_core_ops bt856_core_ops = { + .g_chip_ident = bt856_g_chip_ident, + .init = bt856_init, +}; + +static const struct v4l2_subdev_video_ops bt856_video_ops = { + .s_std_output = bt856_s_std_output, + .s_routing = bt856_s_routing, +}; -I2C_CLIENT_INSMOD; +static const struct v4l2_subdev_ops bt856_ops = { + .core = &bt856_core_ops, + .video = &bt856_video_ops, +}; + +/* ----------------------------------------------------------------------- */ static int bt856_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct bt856 *encoder; + struct v4l2_subdev *sd; /* Check if the adapter supports the needed features */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -249,41 +220,38 @@ static int bt856_probe(struct i2c_client *client, encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL); if (encoder == NULL) return -ENOMEM; - encoder->norm = VIDEO_MODE_NTSC; - encoder->enable = 1; - i2c_set_clientdata(client, encoder); + sd = &encoder->sd; + v4l2_i2c_subdev_init(sd, client, &bt856_ops); + encoder->norm = V4L2_STD_NTSC; - bt856_write(client, 0xdc, 0x18); - bt856_write(client, 0xda, 0); - bt856_write(client, 0xde, 0); + bt856_write(encoder, 0xdc, 0x18); + bt856_write(encoder, 0xda, 0); + bt856_write(encoder, 0xde, 0); - bt856_setbit(client, 0xdc, 3, 1); - //bt856_setbit(client, 0xdc, 6, 0); - bt856_setbit(client, 0xdc, 4, 1); + bt856_setbit(encoder, 0xdc, 3, 1); + /*bt856_setbit(encoder, 0xdc, 6, 0);*/ + bt856_setbit(encoder, 0xdc, 4, 1); - switch (encoder->norm) { + if (encoder->norm & V4L2_STD_NTSC) + bt856_setbit(encoder, 0xdc, 2, 0); + else + bt856_setbit(encoder, 0xdc, 2, 1); - case VIDEO_MODE_NTSC: - bt856_setbit(client, 0xdc, 2, 0); - break; - - case VIDEO_MODE_PAL: - bt856_setbit(client, 0xdc, 2, 1); - break; - } - - bt856_setbit(client, 0xdc, 1, 1); - bt856_setbit(client, 0xde, 4, 0); - bt856_setbit(client, 0xde, 3, 1); + bt856_setbit(encoder, 0xdc, 1, 1); + bt856_setbit(encoder, 0xde, 4, 0); + bt856_setbit(encoder, 0xde, 3, 1); if (debug != 0) - bt856_dump(client); + bt856_dump(encoder); return 0; } static int bt856_remove(struct i2c_client *client) { - kfree(i2c_get_clientdata(client)); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + + v4l2_device_unregister_subdev(sd); + kfree(to_bt856(sd)); return 0; } @@ -295,8 +263,6 @@ MODULE_DEVICE_TABLE(i2c, bt856_id); static struct v4l2_i2c_driver_data v4l2_i2c_data = { .name = "bt856", - .driverid = I2C_DRIVERID_BT856, - .command = bt856_command, .probe = bt856_probe, .remove = bt856_remove, .id_table = bt856_id, |