2 * ths7303- THS7303 Video Amplifier driver
4 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation version 2.
10 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
11 * kind, whether express or implied; without even the implied warranty
12 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/ctype.h>
19 #include <linux/slab.h>
20 #include <linux/i2c.h>
21 #include <linux/device.h>
22 #include <linux/delay.h>
23 #include <linux/module.h>
24 #include <linux/uaccess.h>
25 #include <linux/videodev2.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-subdev.h>
29 #include <media/v4l2-chip-ident.h>
31 #define THS7303_CHANNEL_1 1
32 #define THS7303_CHANNEL_2 2
33 #define THS7303_CHANNEL_3 3
35 enum ths7303_filter_mode {
36 THS7303_FILTER_MODE_480I_576I,
37 THS7303_FILTER_MODE_480P_576P,
38 THS7303_FILTER_MODE_720P_1080I,
39 THS7303_FILTER_MODE_1080P,
40 THS7303_FILTER_MODE_DISABLE
43 MODULE_DESCRIPTION("TI THS7303 video amplifier driver");
44 MODULE_AUTHOR("Chaithrika U S");
45 MODULE_LICENSE("GPL");
48 module_param(debug, int, 0644);
49 MODULE_PARM_DESC(debug, "Debug level 0-1");
51 /* following function is used to set ths7303 */
52 int ths7303_setval(struct v4l2_subdev *sd, enum ths7303_filter_mode mode)
54 u8 input_bias_chroma = 3;
55 u8 input_bias_luma = 3;
61 struct i2c_client *client = v4l2_get_subdevdata(sd);
67 case THS7303_FILTER_MODE_1080P:
71 case THS7303_FILTER_MODE_720P_1080I:
75 case THS7303_FILTER_MODE_480P_576P:
79 case THS7303_FILTER_MODE_480I_576I:
81 case THS7303_FILTER_MODE_DISABLE:
82 pr_info("mode disabled\n");
83 /* disable all channels */
86 /* disable all channels */
89 /* Setup channel 2 - Luma - Green */
92 val |= input_bias_luma;
93 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_2, val);
97 /* setup two chroma channels */
99 temp |= input_bias_chroma;
101 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_1, temp);
105 err = i2c_smbus_write_byte_data(client, THS7303_CHANNEL_3, temp);
110 pr_info("write byte data failed\n");
114 static int ths7303_s_std_output(struct v4l2_subdev *sd, v4l2_std_id norm)
116 if (norm & (V4L2_STD_ALL & ~V4L2_STD_SECAM))
117 return ths7303_setval(sd, THS7303_FILTER_MODE_480I_576I);
119 return ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
122 /* for setting filter for HD output */
123 static int ths7303_s_dv_timings(struct v4l2_subdev *sd,
124 struct v4l2_dv_timings *dv_timings)
126 u32 height = dv_timings->bt.height;
127 int interlaced = dv_timings->bt.interlaced;
130 if (height == 1080 && !interlaced)
131 res = ths7303_setval(sd, THS7303_FILTER_MODE_1080P);
132 else if ((height == 720 && !interlaced) ||
133 (height == 1080 && interlaced))
134 res = ths7303_setval(sd, THS7303_FILTER_MODE_720P_1080I);
135 else if ((height == 480 || height == 576) && !interlaced)
136 res = ths7303_setval(sd, THS7303_FILTER_MODE_480P_576P);
138 /* disable all channels */
139 res = ths7303_setval(sd, THS7303_FILTER_MODE_DISABLE);
144 static int ths7303_g_chip_ident(struct v4l2_subdev *sd,
145 struct v4l2_dbg_chip_ident *chip)
147 struct i2c_client *client = v4l2_get_subdevdata(sd);
149 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_THS7303, 0);
152 static const struct v4l2_subdev_video_ops ths7303_video_ops = {
153 .s_std_output = ths7303_s_std_output,
154 .s_dv_timings = ths7303_s_dv_timings,
157 static const struct v4l2_subdev_core_ops ths7303_core_ops = {
158 .g_chip_ident = ths7303_g_chip_ident,
161 static const struct v4l2_subdev_ops ths7303_ops = {
162 .core = &ths7303_core_ops,
163 .video = &ths7303_video_ops,
166 static int ths7303_probe(struct i2c_client *client,
167 const struct i2c_device_id *id)
169 struct v4l2_subdev *sd;
170 v4l2_std_id std_id = V4L2_STD_NTSC;
172 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
175 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name);
178 sd = kzalloc(sizeof(struct v4l2_subdev), GFP_KERNEL);
182 v4l2_i2c_subdev_init(sd, client, &ths7303_ops);
184 return ths7303_s_std_output(sd, std_id);
187 static int ths7303_remove(struct i2c_client *client)
189 struct v4l2_subdev *sd = i2c_get_clientdata(client);
191 v4l2_device_unregister_subdev(sd);
197 static const struct i2c_device_id ths7303_id[] = {
202 MODULE_DEVICE_TABLE(i2c, ths7303_id);
204 static struct i2c_driver ths7303_driver = {
206 .owner = THIS_MODULE,
209 .probe = ths7303_probe,
210 .remove = ths7303_remove,
211 .id_table = ths7303_id,
214 module_i2c_driver(ths7303_driver);