Skip to contentSkip to conversation

ARM: DaVinci: DM646x Video: THS7303 video amplifier driver

RFC In review [email protected] 2 participants 3 messages Mar 13, 2009 – Mar 17, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

RFC 3/7 ARM: DaVinci: DM646x Video: THS7303 video amplifier driver

From: Chaithrika U S <[email protected]>

THS7303 video amplifier driver code

This patch implements driver for TI THS7303 video amplifier . This driver is implemented as a v4l2-subdev.
---
Applies to v4l-dvb repository located at
http://linuxtv.org/hg/v4l-dvb/rev/1fd54a62abde

 drivers/media/video/Kconfig   |    9 ++
 drivers/media/video/Makefile  |    1 +
 drivers/media/video/ths7303.c |  179 +++++++++++++++++++++++++++++++++++++++++
 include/media/ths7303.h       |   26 ++++++
 4 files changed, 215 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/ths7303.c
 create mode 100644 include/media/ths7303.h
drivers/media/video/Kconfig +9 -0
index 16019e9..b3b591d 100644
@@ -435,6 +435,15 @@ config VIDEO_ADV7343
           To compile this driver as a module, choose M here: the
           module will be called adv7473.
 
+config VIDEO_THS7303
+	tristate "THS7303 Video Amplifier"
+	depends on I2C
+	help
+	  Support for TI  THS7303 video amplifier
+
+	  To compile this driver as a module, choose M here: the
+          module will be called ths7303.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
drivers/media/video/Makefile +1 -0
index 7f9fc62..1ed9c2c 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
 obj-$(CONFIG_VIDEO_BT866) += bt866.o
 obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
+obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
 
 obj-$(CONFIG_VIDEO_ZORAN) += zoran/
 
drivers/media/video/ths7303.c new file +179 -0

179 lines not on this page · raw message

include/media/ths7303.h new file +26 -0
new file mode 100644
index 0000000..5426941
@@ -0,0 +1,26 @@
+/*
+ * THS7303 header file
+ *
+ * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed .as is. WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef THS7303_H
+#define THS7303_H
+
+#include <linux/videodev2.h>
+
+#define THS7303_NAME	"ths7303"
+
+#define THS7303_SETVALUE	_IOW('e', BASE_VIDIOC_PRIVATE + 1,\
+							v4l2_std_id *)
+
+#endif
Signature · 1 line
1.5.6
#1 lore raw

Hi Chaithrika,

This is the first pass of this i2c driver. Note that several of the comments here also apply to adv7343.

Quoted 73 lines · On Friday 13 March 2009 10:01:06 [email protected] wrote:

From: Chaithrika U S <[email protected]>

THS7303 video amplifier driver code

This patch implements driver for TI THS7303 video amplifier . This driver is implemented as a v4l2-subdev.
---
Applies to v4l-dvb repository located at
http://linuxtv.org/hg/v4l-dvb/rev/1fd54a62abde

 drivers/media/video/Kconfig   |    9 ++
 drivers/media/video/Makefile  |    1 +
 drivers/media/video/ths7303.c |  179 +++++++++++++++++++++++++++++++++++++++++
 include/media/ths7303.h       |   26 ++++++
 4 files changed, 215 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/ths7303.c
 create mode 100644 include/media/ths7303.h
drivers/media/video/Kconfig +9 -0
index 16019e9..b3b591d 100644
@@ -435,6 +435,15 @@ config VIDEO_ADV7343
           To compile this driver as a module, choose M here: the
           module will be called adv7473.
 
+config VIDEO_THS7303
+	tristate "THS7303 Video Amplifier"
+	depends on I2C
+	help
+	  Support for TI  THS7303 video amplifier
+
+	  To compile this driver as a module, choose M here: the
+          module will be called ths7303.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
drivers/media/video/Makefile +1 -0
index 7f9fc62..1ed9c2c 100644
@@ -55,6 +55,7 @@ obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
 obj-$(CONFIG_VIDEO_BT866) += bt866.o
 obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
+obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
 
 obj-$(CONFIG_VIDEO_ZORAN) += zoran/
 
drivers/media/video/ths7303.c new file +17 -0
new file mode 100644
index 0000000..a78b450
@@ -0,0 +1,179 @@
+/*
+ * ths7303- THS7303 Video Amplifier driver
+ *
+ * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed .as is. WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>

drivers/media/video/ths7303.c line 27

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+#include <linux/ctype.h>
+#include <linux/i2c.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/videodev2.h>
+
+#include <media/v4l2-device.h>
+#include <media/v4l2-i2c-drv.h>

Don't use v4l2-i2c-drv.h: that's for legacy kernel support only (e.g. when the i2c driver has to run on pre-2.6.22 kernels as well). You can just write this as a normal i2c driver.

I hope that this header can be removed in the near future to prevent this confusion.

drivers/media/video/ths7303.c line 31

Quoted 4 lines
drivers/media/video/ths7303.c new file +4 -0
+#include <media/v4l2-subdev.h>
+#include <media/ths7303.h>
+
+static int debug;

Hmm, debug is not setup as a module option, so this doesn't do a lot. You need to add something like this:

module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Debug level (0-1)");

drivers/media/video/ths7303.c line 34

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+
+struct ths7303_state {
+	struct i2c_client	*client;

Don't store the i2c_client pointer here. It can be obtained from v4l2_subdev.

In this case that reduces the state information to just struct v4l2_subdev...

drivers/media/video/ths7303.c line 41

Quoted 7 lines
drivers/media/video/ths7303.c new file +7 -0
+	struct v4l2_subdev sd;
+};
+
+static inline struct ths7303_state *to_state(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct ths7303_state, sd);
+}

...and that means that this function is not needed for this driver.

Quoted 6 lines
drivers/media/video/ths7303.c new file +6 -0
+
+/* following function is used to set ths7303 */
+static int ths7303_setvalue(struct v4l2_subdev *sd, v4l2_std_id std)
+{
+	int err = 0;
+	u8 val;

drivers/media/video/ths7303.c line 57

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+	struct ths7303_state *state;
+	struct i2c_client *client;
+
+	state = to_state(sd);
+	client = state->client;
+
+	if (client == NULL) {
+		printk(KERN_ERR "THS7303 Client not found\n");
+		return -ENODEV;
+	}

Just use:

	struct i2c_client *client = v4l2_get_subdevdata(sd);

There is no need to check for a valid client pointer. If you have a subdev, then you have by definition an i2c_client pointer.

drivers/media/video/ths7303.c line 60

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+
+	if ((std == V4L2_STD_NTSC) || (std == V4L2_STD_PAL))
+		val = 0x02;

Use 'std & V4L2_STD_NTSC' since v4l2_std_id is a bitmask. I suspect that what you really want is to AND with '(V4L2_STD_525_60 | V4L2_STD_625_50)'.

drivers/media/video/ths7303.c line 71

Quoted 11 lines
drivers/media/video/ths7303.c new file +11 -0
+	else if ((std == V4L2_STD_480P_60) || (std == V4L2_STD_576P_50))
+		val = 0x4A;
+	else
+		val = 0x92;
+
+	err |= i2c_smbus_write_byte_data(client, 0x01, val);
+	err |= i2c_smbus_write_byte_data(client, 0x02, val);
+	err |= i2c_smbus_write_byte_data(client, 0x03, val);
+
+	if (err)
+		printk(KERN_ERR "ths7303 write\n");

Use: v4l2_err(sd, "write failed\n");

drivers/media/video/ths7303.c line 73

Quoted 2 lines
drivers/media/video/ths7303.c new file +2 -0
+
+	mdelay(100);

Is this just a random number, or does this correspond to what the datasheet says? 100 ms is fairly long.

I think you should also use msleep() instead of mdelay: both mdelay and udelay implement the delay using a busy-loop rather than using a timer.

A comment why this delay/sleep is needed is probably also a good idea.

drivers/media/video/ths7303.c line 81

Quoted 8 lines
drivers/media/video/ths7303.c new file +8 -0
+
+	return err;
+}
+
+static long ths7303_ioctl(struct v4l2_subdev *sd, unsigned cmd, void *arg)
+{
+	int err = 0;
+	v4l2_dbg(1, debug, sd, "ioctl\n");

This v4l2_dbg doesn't seem very useful. It might be more useful to stick it in ths7303_setvalue() and show what register value is set there. Or remove it altogether.

Quoted 8 lines
drivers/media/video/ths7303.c new file +8 -0
+	switch (cmd) {
+
+	case THS7303_SETVALUE:
+		err = ths7303_setvalue(sd, *(v4l2_std_id *) arg);
+		break;
+
+	default:
+		break;

drivers/media/video/ths7303.c line 99

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+	}
+
+	return err;
+}
+
+static int ths7303_initialize(struct v4l2_subdev *sd, u32 val)
+{
+	v4l2_std_id id = V4L2_STD_NTSC;
+	return (int) ths7303_ioctl(sd, THS7303_SETVALUE, &id);
+}

Avoid using the .init callback. It's better to just set this from ths7303_probe() function. The .init callback is likely to be removed. It is generally used incorrectly and once all legacy drivers are converted to v4l2_subdev I'll go through all drivers and see which ones really need this, and whether init is really a good name. For example, there is at least one driver that uses init to load firmware. But having a proper .load_fw callback for that is much more understandable.

drivers/media/video/ths7303.c line 104

Quoted 5 lines
drivers/media/video/ths7303.c new file +5 -0
+
+static const struct v4l2_subdev_core_ops ths7303_core_ops = {
+	.ioctl	= ths7303_ioctl,
+	.init	= ths7303_initialize,
+};

A note on .ioctl: why not use the tuner.s_std callback instead? Whenever the driver changes the standard you want this driver to be called as well.

No need to create a new command for that.

Minor note: the s_std callback really belongs to v4l2_subdev_video_ops, but I'm postponing that move until all legacy drivers are converted.

drivers/media/video/ths7303.c line 113

Quoted 9 lines
drivers/media/video/ths7303.c new file +9 -0
+
+static const struct v4l2_subdev_ops ths7303_ops = {
+	.core	= &ths7303_core_ops,
+};
+
+static int ths7303_command(struct i2c_client *client, unsigned cmd, void *arg)
+{
+	return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
+}

Don't use this function. It is only needed to provide support for legacy drivers and so is not needed for new drivers.

drivers/media/video/ths7303.c line 124

Quoted 11 lines
drivers/media/video/ths7303.c new file +11 -0
+
+static int ths7303_probe(struct i2c_client *client,
+			const struct i2c_device_id *id)
+{
+	struct ths7303_state *state;
+
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return -ENODEV;
+
+	v4l2_info(client, "chip found @ 0x%x (%s)\n",
+			client->addr << 1, client->adapter->name);

Use v4l_info in combination with an i2c_client pointer, and v4l2_info in combination with a v4l2_device or v4l2_subdev pointer.

Yes, I know it is confusing. It is on my (very long) TODO list to clean this up. Note the v4l2_info will work, but the formatting of the i2c name will be missing the i2c address that v4l_info adds.

drivers/media/video/ths7303.c line 132

Quoted 8 lines
drivers/media/video/ths7303.c new file +8 -0
+
+	state = kzalloc(sizeof(struct ths7303_state), GFP_KERNEL);
+	if (state == NULL)
+		return -ENOMEM;
+
+	state->client = client;
+	v4l2_i2c_subdev_init(&state->sd, client, &ths7303_ops);
+	v4l2_dbg(1, debug, client, "Registered video amplifier\n");

This v4l2_dbg call doesn't add anything that the v4l2_info above already did. Just remove this.

Quoted 19 lines
drivers/media/video/ths7303.c new file +19 -0
+
+	return 0;
+}
+
+static int ths7303_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+
+	v4l2_device_unregister_subdev(sd);
+	kfree(to_state(sd));
+
+	return 0;
+}
+
+static const struct i2c_device_id ths7303_id[] = {
+	{THS7303_NAME, 0},
+	{},
+};
+

drivers/media/video/ths7303.c line 161

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+MODULE_DEVICE_TABLE(i2c, ths7303_id);
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+	.name		= THS7303_NAME,
+	.command	= ths7303_command,
+	.probe		= ths7303_probe,
+	.remove		= ths7303_remove,
+	.legacy_class	= I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
+	.id_table	= ths7303_id,
+};

Replace this v4l2_i2c_driver_data struct with a normal i2c_driver struct:

static struct i2c_driver ths7303_driver = {
        .name = THS7303_NAME,
        .probe = ths7303_probe,
        .remove = ths7303_remove,
        .id_table = ths7303_id,
};

drivers/media/video/ths7303.c line 171

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+
+static int __init ths7303_init(void)
+{
+	return 0;
+}
+
+static void __exit ths7303_exit(void)
+{
+
+}

Change these to:

static int __init ths7303_init(void)

{
	return i2c_add_driver(&ths7303_driver);
}

static void __exit ths7303_exit(void)

{
	i2c_del_driver(&ths7303_driver);
}

drivers/media/video/ths7303.c line 178

Quoted 7 lines
drivers/media/video/ths7303.c new file +7 -0
+
+module_init(ths7303_init);
+module_exit(ths7303_exit);
+
+MODULE_DESCRIPTION("THS7303 video amplifier driver");
+MODULE_AUTHOR("Chaithrika U S");
+MODULE_LICENSE("GPL");

It might be me, but I prefer to have these lines at the top of the driver, right after the includes. That way I can quickly see what the driver does and who the author is when I open the source.

Regards,

Hans

Quoted 33 lines
drivers/media/video/ths7303.c new file +1 -0
+
include/media/ths7303.h new file +26 -0
new file mode 100644
index 0000000..5426941
@@ -0,0 +1,26 @@
+/*
+ * THS7303 header file
+ *
+ * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed .as is. WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef THS7303_H
+#define THS7303_H
+
+#include <linux/videodev2.h>
+
+#define THS7303_NAME	"ths7303"
+
+#define THS7303_SETVALUE	_IOW('e', BASE_VIDIOC_PRIVATE + 1,\
+							v4l2_std_id *)
+
+#endif
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG
#2 lore raw

Hans,

Thank you for the comments. Please see my response inline.
I have agreed to most of your comments and will do the changes accordingly.

Quoted 6 lines

Hi Chaithrika,

This is the first pass of this i2c driver. Note that several of the comments
here also apply to adv7343.

OK, will do the modifications to ADV7343 driver wherever applicable.

Quoted 97 lines · On Friday 13 March 2009 10:01:06 [email protected] wrote:
Quoted 5 lines

From: Chaithrika U S <[email protected]>

THS7303 video amplifier driver code

This patch implements driver for TI THS7303 video amplifier . This

driver is

Quoted 8 lines

implemented as a v4l2-subdev.
---
Applies to v4l-dvb repository located at
http://linuxtv.org/hg/v4l-dvb/rev/1fd54a62abde

 drivers/media/video/Kconfig   |    9 ++
 drivers/media/video/Makefile  |    1 +
 drivers/media/video/ths7303.c |  179

+++++++++++++++++++++++++++++++++++++++++

Review

Quoted 6 lines
 include/media/ths7303.h       |   26 ++++++
 4 files changed, 215 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/video/ths7303.c
 create mode 100644 include/media/ths7303.h
(quoted diff) +0 -0

b/drivers/media/video/Kconfig

Review

Quoted 20 lines

index 16019e9..b3b591d 100644

drivers/media/video/Kconfig +9 -0
@@ -435,6 +435,15 @@ config VIDEO_ADV7343
           To compile this driver as a module, choose M here: the
           module will be called adv7473.
 
+config VIDEO_THS7303
+     tristate "THS7303 Video Amplifier"
+     depends on I2C
+     help
+       Support for TI  THS7303 video amplifier
+
+       To compile this driver as a module, choose M here: the
+          module will be called ths7303.
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
(quoted diff) +0 -0

b/drivers/media/video/Makefile

Review

Quoted 12 lines

index 7f9fc62..1ed9c2c 100644

drivers/media/video/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_VIDEO_BT819) += bt819.o
 obj-$(CONFIG_VIDEO_BT856) += bt856.o
 obj-$(CONFIG_VIDEO_BT866) += bt866.o
 obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
+obj-$(CONFIG_VIDEO_THS7303) += ths7303.o
 
 obj-$(CONFIG_VIDEO_ZORAN) += zoran/
 
(quoted diff) +0 -0

b/drivers/media/video/ths7303.c

drivers/media/video/ths7303.c line 4

Quoted 9 lines

new file mode 100644
index 0000000..a78b450

drivers/media/video/ths7303.c new file +4 -0
@@ -0,0 +1,179 @@
+/*
+ * ths7303- THS7303 Video Amplifier driver
+ *
+ * Copyright (C) 2009 Texas Instruments Incorporated -

http://www.ti.com/

drivers/media/video/ths7303.c

Quoted 7 lines
drivers/media/video/ths7303.c new file +7 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed .as is. WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied

warranty

Quoted 6 lines
drivers/media/video/ths7303.c new file +6 -0
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>

drivers/media/video/ths7303.c line 27

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+#include <linux/ctype.h>
+#include <linux/i2c.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/uaccess.h>
+#include <linux/videodev2.h>
+
+#include <media/v4l2-device.h>
+#include <media/v4l2-i2c-drv.h>

Don't use v4l2-i2c-drv.h: that's for legacy kernel support only (e.g. when
the i2c driver has to run on pre-2.6.22 kernels as well). You can just write this as a normal i2c driver.

Quoted 3 lines

I hope that this header can be removed in the near future to prevent this
confusion.

OK, will correct this.

Quoted 9 lines

drivers/media/video/ths7303.c line 31

Quoted 5 lines
drivers/media/video/ths7303.c new file +4 -0
+#include <media/v4l2-subdev.h>
+#include <media/ths7303.h>
+
+static int debug;

Hmm, debug is not setup as a module option, so this doesn't do a lot. You need to add something like this:

Quoted 3 lines

module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Debug level (0-1)");

OK, thanks for helping out on this.

Quoted 10 lines

drivers/media/video/ths7303.c line 34

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+
+struct ths7303_state {
+     struct i2c_client       *client;

Don't store the i2c_client pointer here. It can be obtained from v4l2_subdev.

In this case that reduces the state information to just struct v4l2_subdev...

Quoted 10 lines

drivers/media/video/ths7303.c line 41

Quoted 7 lines
drivers/media/video/ths7303.c new file +7 -0
+     struct v4l2_subdev sd;
+};
+
+static inline struct ths7303_state *to_state(struct v4l2_subdev *sd)
+{
+     return container_of(sd, struct ths7303_state, sd);
+}

...and that means that this function is not needed for this driver.

OK, will update this.

Quoted 19 lines
Quoted 6 lines
drivers/media/video/ths7303.c new file +6 -0
+
+/* following function is used to set ths7303 */
+static int ths7303_setvalue(struct v4l2_subdev *sd, v4l2_std_id std)
+{
+     int err = 0;
+     u8 val;

drivers/media/video/ths7303.c line 57

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+     struct ths7303_state *state;
+     struct i2c_client *client;
+
+     state = to_state(sd);
+     client = state->client;
+
+     if (client == NULL) {
+             printk(KERN_ERR "THS7303 Client not found\n");
+             return -ENODEV;
+     }

Just use:

Quoted 6 lines
        struct i2c_client *client = v4l2_get_subdevdata(sd);

There is no need to check for a valid client pointer. If you have a subdev,
then you have by definition an i2c_client pointer.

OK.

Quoted 8 lines

drivers/media/video/ths7303.c line 60

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+
+     if ((std == V4L2_STD_NTSC) || (std == V4L2_STD_PAL))
+             val = 0x02;

Use 'std & V4L2_STD_NTSC' since v4l2_std_id is a bitmask. I suspect that what
you really want is to AND with '(V4L2_STD_525_60 | V4L2_STD_625_50)'.

Agree, this has to be corrected.

Quoted 14 lines

drivers/media/video/ths7303.c line 61

Quoted 1 line
drivers/media/video/ths7303.c new file +1 -0
+     else if ((std == V4L2_STD_480P_60) || (std ==

V4L2_STD_576P_50))

drivers/media/video/ths7303.c line 71

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+             val = 0x4A;
+     else
+             val = 0x92;
+
+     err |= i2c_smbus_write_byte_data(client, 0x01, val);
+     err |= i2c_smbus_write_byte_data(client, 0x02, val);
+     err |= i2c_smbus_write_byte_data(client, 0x03, val);
+
+     if (err)
+             printk(KERN_ERR "ths7303 write\n");

Use: v4l2_err(sd, "write failed\n");

OK.

Quoted 8 lines

drivers/media/video/ths7303.c line 73

Quoted 3 lines
drivers/media/video/ths7303.c new file +2 -0
+
+     mdelay(100);

Is this just a random number, or does this correspond to what the datasheet
says? 100 ms is fairly long.

Quoted 6 lines

I think you should also use msleep() instead of mdelay: both mdelay and udelay
implement the delay using a busy-loop rather than using a timer.

A comment why this delay/sleep is needed is probably also a good idea.

Will look into this.

Quoted 10 lines

drivers/media/video/ths7303.c

Quoted 5 lines
drivers/media/video/ths7303.c new file +5 -0
+
+     return err;
+}
+
+static long ths7303_ioctl(struct v4l2_subdev *sd, unsigned cmd, void

*arg)

drivers/media/video/ths7303.c line 81

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+{
+     int err = 0;
+     v4l2_dbg(1, debug, sd, "ioctl\n");
Quoted 6 lines

This v4l2_dbg doesn't seem very useful. It might be more useful to stick it
in ths7303_setvalue() and show what register value is set there. Or remove
it altogether.

OK.

Quoted 22 lines
Quoted 8 lines
drivers/media/video/ths7303.c new file +8 -0
+     switch (cmd) {
+
+     case THS7303_SETVALUE:
+             err = ths7303_setvalue(sd, *(v4l2_std_id *) arg);
+             break;
+
+     default:
+             break;

drivers/media/video/ths7303.c line 99

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+     }
+
+     return err;
+}
+
+static int ths7303_initialize(struct v4l2_subdev *sd, u32 val)
+{
+     v4l2_std_id id = V4L2_STD_NTSC;
+     return (int) ths7303_ioctl(sd, THS7303_SETVALUE, &id);
+}

Avoid using the .init callback. It's better to just set this from ths7303_probe() function. The .init callback is likely to be removed. It is

Quoted 9 lines

generally used incorrectly and once all legacy drivers are converted to v4l2_subdev I'll go through all drivers and see which ones really need this,
and whether init is really a good name. For example, there is at least one
driver that uses init to load firmware. But having a proper .load_fw callback
for that is much more understandable.

OK, will do the initialization in the probe function.

Quoted 10 lines

drivers/media/video/ths7303.c line 104

Quoted 5 lines
drivers/media/video/ths7303.c new file +5 -0
+
+static const struct v4l2_subdev_core_ops ths7303_core_ops = {
+     .ioctl  = ths7303_ioctl,
+     .init   = ths7303_initialize,
+};

A note on .ioctl: why not use the tuner.s_std callback instead? Whenever the
driver changes the standard you want this driver to be called as well.

Quoted 6 lines

No need to create a new command for that.

Minor note: the s_std callback really belongs to v4l2_subdev_video_ops, but
I'm postponing that move until all legacy drivers are converted.

OK.

Quoted 7 lines

drivers/media/video/ths7303.c

Quoted 6 lines
drivers/media/video/ths7303.c new file +6 -0
+
+static const struct v4l2_subdev_ops ths7303_ops = {
+     .core   = &ths7303_core_ops,
+};
+
+static int ths7303_command(struct i2c_client *client, unsigned cmd,

void *arg)

Quoted 9 lines

drivers/media/video/ths7303.c line 112

Quoted 2 lines
drivers/media/video/ths7303.c new file +2 -0
+{
+     return v4l2_subdev_command(i2c_get_clientdata(client), cmd,

arg);

drivers/media/video/ths7303.c line 113

Quoted 1 line
drivers/media/video/ths7303.c new file +1 -0
+}

Don't use this function. It is only needed to provide support for legacy
drivers and so is not needed for new drivers.

OK.

Quoted 17 lines

drivers/media/video/ths7303.c

Quoted 7 lines
drivers/media/video/ths7303.c new file +7 -0
+
+static int ths7303_probe(struct i2c_client *client,
+                     const struct i2c_device_id *id)
+{
+     struct ths7303_state *state;
+
+     if (!i2c_check_functionality(client->adapter,

I2C_FUNC_SMBUS_BYTE_DATA))

drivers/media/video/ths7303.c line 124

Quoted 4 lines
drivers/media/video/ths7303.c new file +4 -0
+             return -ENODEV;
+
+     v4l2_info(client, "chip found @ 0x%x (%s)\n",
+                     client->addr << 1, client->adapter->name);

Use v4l_info in combination with an i2c_client pointer, and v4l2_info in
combination with a v4l2_device or v4l2_subdev pointer.

Quoted 6 lines

Yes, I know it is confusing. It is on my (very long) TODO list to clean this
up. Note the v4l2_info will work, but the formatting of the i2c name will be
missing the i2c address that v4l_info adds.

OK, will update this.

Quoted 4 lines
Quoted 4 lines
drivers/media/video/ths7303.c new file +4 -0
+
+     state = kzalloc(sizeof(struct ths7303_state), GFP_KERNEL);
+     if (state == NULL)
+             return -ENOMEM;
Quoted 9 lines

drivers/media/video/ths7303.c line 132

Quoted 4 lines
drivers/media/video/ths7303.c new file +4 -0
+
+     state->client = client;
+     v4l2_i2c_subdev_init(&state->sd, client, &ths7303_ops);
+     v4l2_dbg(1, debug, client, "Registered video amplifier\n");

This v4l2_dbg call doesn't add anything that the v4l2_info above already did.
Just remove this.

OK

Quoted 33 lines
Quoted 19 lines
drivers/media/video/ths7303.c new file +19 -0
+
+     return 0;
+}
+
+static int ths7303_remove(struct i2c_client *client)
+{
+     struct v4l2_subdev *sd = i2c_get_clientdata(client);
+
+     v4l2_device_unregister_subdev(sd);
+     kfree(to_state(sd));
+
+     return 0;
+}
+
+static const struct i2c_device_id ths7303_id[] = {
+     {THS7303_NAME, 0},
+     {},
+};
+

drivers/media/video/ths7303.c line 161

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+MODULE_DEVICE_TABLE(i2c, ths7303_id);
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+     .name           = THS7303_NAME,
+     .command        = ths7303_command,
+     .probe          = ths7303_probe,
+     .remove         = ths7303_remove,
+     .legacy_class   = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
+     .id_table       = ths7303_id,
+};

Replace this v4l2_i2c_driver_data struct with a normal i2c_driver struct:

Quoted 8 lines
static struct i2c_driver ths7303_driver = {
        .name = THS7303_NAME,
        .probe = ths7303_probe,
        .remove = ths7303_remove,
        .id_table = ths7303_id,
};

OK.

Quoted 14 lines

drivers/media/video/ths7303.c line 171

Quoted 10 lines
drivers/media/video/ths7303.c new file +10 -0
+
+static int __init ths7303_init(void)
+{
+     return 0;
+}
+
+static void __exit ths7303_exit(void)
+{
+
+}

Change these to:

static int __init ths7303_init(void)

Quoted 9 lines
{
        return i2c_add_driver(&ths7303_driver);
}

static void __exit ths7303_exit(void)

{
        i2c_del_driver(&ths7303_driver);
}

OK.

Quoted 4 lines
Quoted 4 lines
drivers/media/video/ths7303.c new file +4 -0
+
+module_init(ths7303_init);
+module_exit(ths7303_exit);
+
Quoted 9 lines

drivers/media/video/ths7303.c line 178

Quoted 3 lines
drivers/media/video/ths7303.c new file +3 -0
+MODULE_DESCRIPTION("THS7303 video amplifier driver");
+MODULE_AUTHOR("Chaithrika U S");
+MODULE_LICENSE("GPL");

It might be me, but I prefer to have these lines at the top of the driver,
right after the includes. That way I can quickly see what the driver does and who the author is when I open the source.

OK, will move this to the beginning of the file.

Thanks,
Chaithrika

Quoted 44 lines

Regards,

Hans

include/media/ths7303.h line 4

Quoted 11 lines
drivers/media/video/ths7303.c new file +1 -0
+
include/media/ths7303.h new file +4 -0
new file mode 100644
index 0000000..5426941
@@ -0,0 +1,26 @@
+/*
+ * THS7303 header file
+ *
+ * Copyright (C) 2009 Texas Instruments Incorporated -

http://www.ti.com/

include/media/ths7303.h line 11

Quoted 7 lines
include/media/ths7303.h new file +7 -0
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed .as is. WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied

warranty

Quoted 5 lines
include/media/ths7303.h new file +5 -0
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef THS7303_H

include/media/ths7303.h line 26

Quoted 10 lines
include/media/ths7303.h new file +10 -0
+#define THS7303_H
+
+#include <linux/videodev2.h>
+
+#define THS7303_NAME "ths7303"
+
+#define THS7303_SETVALUE     _IOW('e', BASE_VIDIOC_PRIVATE + 1,\
+                                                     v4l2_std_id *)
+
+#endif

--
Hans Verkuil - video4linux developer - sponsored by TANDBERG