mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-18 18:23:53 +08:00
V4L/DVB (10721): bt856: convert to v4l2_subdev.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
2883913c5e
commit
a91f56e7eb
@ -34,9 +34,9 @@
|
||||
#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 <linux/videodev2.h>
|
||||
#include <media/v4l2-device.h>
|
||||
#include <media/v4l2-chip-ident.h>
|
||||
#include <media/v4l2-i2c-drv-legacy.h>
|
||||
|
||||
MODULE_DESCRIPTION("Brooktree-856A video encoder driver");
|
||||
@ -47,42 +47,49 @@ static int debug;
|
||||
module_param(debug, int, 0);
|
||||
MODULE_PARM_DESC(debug, "Debug level (0-1)");
|
||||
|
||||
static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
|
||||
|
||||
I2C_CLIENT_INSMOD;
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#define BT856_REG_OFFSET 0xDA
|
||||
#define BT856_NR_REG 6
|
||||
|
||||
struct bt856 {
|
||||
struct v4l2_subdev sd;
|
||||
unsigned char reg[BT856_NR_REG];
|
||||
|
||||
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");
|
||||
@ -90,107 +97,125 @@ 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);
|
||||
struct bt856 *encoder = to_bt856(sd);
|
||||
|
||||
switch (cmd) {
|
||||
case VIDIOC_INT_INIT:
|
||||
/* 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);
|
||||
/* 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(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);
|
||||
|
||||
if (encoder->norm & V4L2_STD_NTSC)
|
||||
bt856_setbit(client, 0xdc, 2, 0);
|
||||
else
|
||||
bt856_setbit(client, 0xdc, 2, 1);
|
||||
if (encoder->norm & V4L2_STD_NTSC)
|
||||
bt856_setbit(encoder, 0xdc, 2, 0);
|
||||
else
|
||||
bt856_setbit(encoder, 0xdc, 2, 1);
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
case VIDIOC_INT_S_STD_OUTPUT:
|
||||
{
|
||||
v4l2_std_id *iarg = arg;
|
||||
static int bt856_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
|
||||
{
|
||||
struct bt856 *encoder = to_bt856(sd);
|
||||
|
||||
v4l_dbg(1, debug, client, "set norm %llx\n", *iarg);
|
||||
v4l2_dbg(1, debug, sd, "set norm %llx\n", std);
|
||||
|
||||
if (*iarg & V4L2_STD_NTSC) {
|
||||
bt856_setbit(client, 0xdc, 2, 0);
|
||||
} else if (*iarg & V4L2_STD_PAL) {
|
||||
bt856_setbit(client, 0xdc, 2, 1);
|
||||
bt856_setbit(client, 0xda, 0, 0);
|
||||
//bt856_setbit(client, 0xda, 0, 1);
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
encoder->norm = *iarg;
|
||||
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 VIDIOC_INT_S_VIDEO_ROUTING:
|
||||
{
|
||||
struct v4l2_routing *route = arg;
|
||||
static int bt856_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
|
||||
{
|
||||
struct bt856 *encoder = to_bt856(sd);
|
||||
|
||||
v4l_dbg(1, debug, client, "set input %d\n", route->input);
|
||||
v4l2_dbg(1, debug, sd, "set input %d\n", route->input);
|
||||
|
||||
/* We only have video bus.
|
||||
* route->input= 0: input is from bt819
|
||||
* route->input= 1: input is from ZR36060 */
|
||||
switch (route->input) {
|
||||
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);
|
||||
/* We only have video bus.
|
||||
* route->input= 0: input is from bt819
|
||||
* route->input= 1: input is from ZR36060 */
|
||||
switch (route->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 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 int bt856_command(struct i2c_client *client, unsigned cmd, void *arg)
|
||||
{
|
||||
return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
I2C_CLIENT_INSMOD;
|
||||
static const struct v4l2_subdev_video_ops bt856_video_ops = {
|
||||
.s_std_output = bt856_s_std_output,
|
||||
.s_routing = bt856_s_routing,
|
||||
};
|
||||
|
||||
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))
|
||||
@ -202,34 +227,38 @@ static int bt856_probe(struct i2c_client *client,
|
||||
encoder = kzalloc(sizeof(struct bt856), GFP_KERNEL);
|
||||
if (encoder == NULL)
|
||||
return -ENOMEM;
|
||||
sd = &encoder->sd;
|
||||
v4l2_i2c_subdev_init(sd, client, &bt856_ops);
|
||||
encoder->norm = V4L2_STD_NTSC;
|
||||
i2c_set_clientdata(client, encoder);
|
||||
|
||||
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);
|
||||
|
||||
if (encoder->norm & V4L2_STD_NTSC)
|
||||
bt856_setbit(client, 0xdc, 2, 0);
|
||||
bt856_setbit(encoder, 0xdc, 2, 0);
|
||||
else
|
||||
bt856_setbit(client, 0xdc, 2, 1);
|
||||
bt856_setbit(encoder, 0xdc, 2, 1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,9 @@ enum {
|
||||
V4L2_IDENT_BT817A = 817,
|
||||
V4L2_IDENT_BT819A = 819,
|
||||
|
||||
/* module bt856: just ident 856 */
|
||||
V4L2_IDENT_BT856 = 856,
|
||||
|
||||
/* module bt866: just ident 866 */
|
||||
V4L2_IDENT_BT866 = 866,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user