The patch number 10725 was added via Hans Verkuil <[email protected]>
to http://linuxtv.org/hg/v4l-dvb master development tree.
Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel
If anyone has any objections, please let us know by sending a message to:
Linux Media Mailing List <[email protected]>
------
From: Hans Verkuil <[email protected]>
saa7185: convert to v4l2_subdev.
Priority: normal
Signed-off-by: Hans Verkuil <[email protected]>
---
linux/drivers/media/video/saa7185.c | 251 ++++++++++++++------------
linux/include/media/v4l2-chip-ident.h | 3
2 files changed, 139 insertions(+), 115 deletions(-)
diff -r 3b910cd7cc59 -r b0e701960f26 linux/drivers/media/video/saa7185.c
--- a/linux/drivers/media/video/saa7185.c Thu Feb 19 16:24:27 2009 +0100
+++ b/linux/drivers/media/video/saa7185.c Thu Feb 19 17:24:47 2009 +0100
@@ -30,9 +30,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>
#include "compat.h"
@@ -40,42 +40,52 @@ MODULE_AUTHOR("Dave Perks");
MODULE_AUTHOR("Dave Perks");
MODULE_LICENSE("GPL");
-
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;
+
/* ----------------------------------------------------------------------- */
struct saa7185 {
+ struct v4l2_subdev sd;
unsigned char reg[128];
v4l2_std_id norm;
- int bright;
- int contrast;
- int hue;
- int sat;
-};
-
-/* ----------------------------------------------------------------------- */
-
-static inline int saa7185_read(struct i2c_client *client)
-{
+};
+
+static inline struct saa7185 *to_saa7185(struct v4l2_subdev *sd)
+{
+ return container_of(sd, struct saa7185, sd);
+}
+
+/* ----------------------------------------------------------------------- */
+
+static inline int saa7185_read(struct v4l2_subdev *sd)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+
return i2c_smbus_read_byte(client);
}
-static int saa7185_write(struct i2c_client *client, u8 reg, u8 value)
-{
- struct saa7185 *encoder = i2c_get_clientdata(client);
-
- v4l_dbg(1, debug, client, "%02x set to %02x\n", reg, value);
+static int saa7185_write(struct v4l2_subdev *sd, u8 reg, u8 value)
+{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct saa7185 *encoder = to_saa7185(sd);
+
+ v4l2_dbg(1, debug, sd, "%02x set to %02x\n", reg, value);
encoder->reg[reg] = value;
return i2c_smbus_write_byte_data(client, reg, value);
}
-static int saa7185_write_block(struct i2c_client *client,
+static int saa7185_write_block(struct v4l2_subdev *sd,
const u8 *data, unsigned int len)
{
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ struct saa7185 *encoder = to_saa7185(sd);
int ret = -1;
u8 reg;
@@ -83,7 +93,6 @@ static int saa7185_write_block(struct i2
* the adapter understands raw I2C */
if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
/* do raw I2C, not smbus compatible */
- struct saa7185 *encoder = i2c_get_clientdata(client);
u8 block_data[32];
int block_len;
@@ -104,7 +113,7 @@ static int saa7185_write_block(struct i2
/* do some slow I2C emulation kind of thing */
while (len >= 2) {
reg = *data++;
- ret = saa7185_write(client, reg, *data++);
+ ret = saa7185_write(sd, reg, *data++);
if (ret < 0)
break;
len -= 2;
@@ -213,101 +222,111 @@ static const unsigned char init_ntsc[] =
0x66, 0x21, /* FSC3 */
};
-static int saa7185_command(struct i2c_client *client, unsigned cmd, void *arg)
-{
- struct saa7185 *encoder = i2c_get_clientdata(client);
-
- switch (cmd) {
- case VIDIOC_INT_INIT:
- saa7185_write_block(client, init_common,
- sizeof(init_common));
- if (encoder->norm & V4L2_STD_NTSC)
- saa7185_write_block(client, init_ntsc,
- sizeof(init_ntsc));
- else
- saa7185_write_block(client, init_pal,
- sizeof(init_pal));
+
+static int saa7185_init(struct v4l2_subdev *sd, u32 val)
+{
+ struct saa7185 *encoder = to_saa7185(sd);
+
+ saa7185_write_block(sd, init_common, sizeof(init_common));
+ if (encoder->norm & V4L2_STD_NTSC)
+ saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
+ else
+ saa7185_write_block(sd, init_pal, sizeof(init_pal));
+ return 0;
+}
+
+static int saa7185_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
+{
+ struct saa7185 *encoder = to_saa7185(sd);
+
+ if (std & V4L2_STD_NTSC)
+ saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
+ else if (std & V4L2_STD_PAL)
+ saa7185_write_block(sd, init_pal, sizeof(init_pal));
+ else
+ return -EINVAL;
+ encoder->norm = std;
+ return 0;
+}
+
+static int saa7185_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing
*route)
+{
+ struct saa7185 *encoder = to_saa7185(sd);
+
+ /* RJ: route->input = 0: input is from SA7111
+ route->input = 1: input is from ZR36060 */
+
+ switch (route->input) {
+ case 0:
+ /* turn off colorbar */
+ saa7185_write(sd, 0x3a, 0x0f);
+ /* Switch RTCE to 1 */
+ saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08);
+ saa7185_write(sd, 0x6e, 0x01);
break;
- case VIDIOC_INT_S_STD_OUTPUT:
- {
- v4l2_std_id *iarg = arg;
-
- //saa7185_write_block(client, init_common, sizeof(init_common));
-
- if (*iarg & V4L2_STD_NTSC)
- saa7185_write_block(client, init_ntsc,
- sizeof(init_ntsc));
- else if (*iarg & V4L2_STD_PAL)
- saa7185_write_block(client, init_pal,
- sizeof(init_pal));
- else
- return -EINVAL;
- encoder->norm = *iarg;
+ case 1:
+ /* turn off colorbar */
+ saa7185_write(sd, 0x3a, 0x0f);
+ /* Switch RTCE to 0 */
+ saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x00);
+ /* SW: a slight sync problem... */
+ saa7185_write(sd, 0x6e, 0x00);
break;
- }
-
- case VIDIOC_INT_S_VIDEO_ROUTING:
- {
- struct v4l2_routing *route = arg;
-
- /* RJ: route->input = 0: input is from SA7111
- route->input = 1: input is from ZR36060 */
-
- switch (route->input) {
- case 0:
- /* turn off colorbar */
- saa7185_write(client, 0x3a, 0x0f);
- /* Switch RTCE to 1 */
- saa7185_write(client, 0x61,
- (encoder->reg[0x61] & 0xf7) | 0x08);
- saa7185_write(client, 0x6e, 0x01);
- break;
-
- case 1:
- /* turn off colorbar */
- saa7185_write(client, 0x3a, 0x0f);
- /* Switch RTCE to 0 */
- saa7185_write(client, 0x61,
- (encoder->reg[0x61] & 0xf7) | 0x00);
- /* SW: a slight sync problem... */
- saa7185_write(client, 0x6e, 0x00);
- break;
-
- case 2:
- /* turn on colorbar */
- saa7185_write(client, 0x3a, 0x8f);
- /* Switch RTCE to 0 */
- saa7185_write(client, 0x61,
- (encoder->reg[0x61] & 0xf7) | 0x08);
- /* SW: a slight sync problem... */
- saa7185_write(client, 0x6e, 0x01);
- break;
-
- default:
- return -EINVAL;
- }
+
+ case 2:
+ /* turn on colorbar */
+ saa7185_write(sd, 0x3a, 0x8f);
+ /* Switch RTCE to 0 */
+ saa7185_write(sd, 0x61, (encoder->reg[0x61] & 0xf7) | 0x08);
+ /* SW: a slight sync problem... */
+ saa7185_write(sd, 0x6e, 0x01);
break;
- }
default:
return -EINVAL;
}
-
- return 0;
-}
-
-/* ----------------------------------------------------------------------- */
-
-static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
-
-I2C_CLIENT_INSMOD;
+ return 0;
+}
+
+static int saa7185_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_SAA7185, 0);
+}
+
+static int saa7185_command(struct i2c_client *client, unsigned cmd, void *arg)
+{
+ return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
+}
+
+/* ----------------------------------------------------------------------- */
+
+static const struct v4l2_subdev_core_ops saa7185_core_ops = {
+ .g_chip_ident = saa7185_g_chip_ident,
+ .init = saa7185_init,
+};
+
+static const struct v4l2_subdev_video_ops saa7185_video_ops = {
+ .s_std_output = saa7185_s_std_output,
+ .s_routing = saa7185_s_routing,
+};
+
+static const struct v4l2_subdev_ops saa7185_ops = {
+ .core = &saa7185_core_ops,
+ .video = &saa7185_video_ops,
+};
+
+
+/* ----------------------------------------------------------------------- */
static int saa7185_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
int i;
struct saa7185 *encoder;
+ struct v4l2_subdev *sd;
/* Check if the adapter supports the needed features */
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -320,26 +339,28 @@ static int saa7185_probe(struct i2c_clie
if (encoder == NULL)
return -ENOMEM;
encoder->norm = V4L2_STD_NTSC;
- i2c_set_clientdata(client, encoder);
-
- i = saa7185_write_block(client, init_common, sizeof(init_common));
+ sd = &encoder->sd;
+ v4l2_i2c_subdev_init(sd, client, &saa7185_ops);
+
+ i = saa7185_write_block(sd, init_common, sizeof(init_common));
if (i >= 0)
- i = saa7185_write_block(client, init_ntsc, sizeof(init_ntsc));
+ i = saa7185_write_block(sd, init_ntsc, sizeof(init_ntsc));
if (i < 0)
- v4l_dbg(1, debug, client, "init error %d\n", i);
+ v4l2_dbg(1, debug, sd, "init error %d\n", i);
else
- v4l_dbg(1, debug, client, "revision 0x%x\n",
- saa7185_read(client) >> 5);
+ v4l2_dbg(1, debug, sd, "revision 0x%x\n",
+ saa7185_read(sd) >> 5);
return 0;
}
static int saa7185_remove(struct i2c_client *client)
{
- struct saa7185 *encoder = i2c_get_clientdata(client);
-
- saa7185_write(client, 0x61, (encoder->reg[0x61]) | 0x40); /* SW:
output off is active */
- //saa7185_write(client, 0x3a, (encoder->reg[0x3a]) | 0x80); /* SW:
color bar */
-
+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
+ struct saa7185 *encoder = to_saa7185(sd);
+
+ v4l2_device_unregister_subdev(sd);
+ /* SW: output off is active */
+ saa7185_write(sd, 0x61, (encoder->reg[0x61]) | 0x40);
kfree(encoder);
return 0;
}
diff -r 3b910cd7cc59 -r b0e701960f26 linux/include/media/v4l2-chip-ident.h
--- a/linux/include/media/v4l2-chip-ident.h Thu Feb 19 16:24:27 2009 +0100
+++ b/linux/include/media/v4l2-chip-ident.h Thu Feb 19 17:24:47 2009 +0100
@@ -112,6 +112,9 @@ enum {
/* module saa6752hs: reserved range 6750-6759 */
V4L2_IDENT_SAA6752HS = 6752,
V4L2_IDENT_SAA6752HS_AC3 = 6753,
+
+ /* module saa7185: just ident 7185 */
+ V4L2_IDENT_SAA7185 = 7185,
/* module wm8739: just ident 8739 */
V4L2_IDENT_WM8739 = 8739,
---
Patch is available at:
http://linuxtv.org/hg/v4l-dvb/rev/b0e701960f26cde54c45ade7c233778dd11e4875
_______________________________________________
linuxtv-commits mailing list
[email protected]
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits