Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 137978
b: refs/heads/master
c: a91f56e
h: refs/heads/master
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Mar 30, 2009
1 parent 1785067 commit 4915de2
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 108 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2883913c5e06a04d04eeeae9ad7ff9b737559355
refs/heads/master: a91f56e7ebe8f33861c613f03faee0b354bea6c1
243 changes: 136 additions & 107 deletions trunk/drivers/media/video/bt856.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -47,150 +47,175 @@ 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");
}

/* ----------------------------------------------------------------------- */

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 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);

bt856_setbit(client, 0xdc, 3, 1);
//bt856_setbit(client, 0xdc, 6, 0);
bt856_setbit(client, 0xdc, 4, 1);

if (encoder->norm & V4L2_STD_NTSC)
bt856_setbit(client, 0xdc, 2, 0);
else
bt856_setbit(client, 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;
struct bt856 *encoder = to_bt856(sd);

case VIDIOC_INT_S_STD_OUTPUT:
{
v4l2_std_id *iarg = arg;

v4l_dbg(1, debug, client, "set norm %llx\n", *iarg);

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;
}
/* 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);

case VIDIOC_INT_S_VIDEO_ROUTING:
{
struct v4l2_routing *route = arg;

v4l_dbg(1, debug, client, "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);
break;
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;
}

static int bt856_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
{
struct bt856 *encoder = to_bt856(sd);

v4l2_dbg(1, debug, sd, "set norm %llx\n", std);

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;
}

static int bt856_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route)
{
struct bt856 *encoder = to_bt856(sd);

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(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))
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions trunk/include/media/v4l2-chip-ident.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 4915de2

Please sign in to comment.