blob: b8061b5e3eac71785a22c4ca190dd3b09e2a02a8 [file] [log] [blame]
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001/*
Mauro Carvalho Chehabcb7a01a2012-08-14 16:23:43 -03002 * drivers/media/i2c/tvp514x.c
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03003 *
4 * TI TVP5146/47 decoder driver
5 *
6 * Copyright (C) 2008 Texas Instruments Inc
7 * Author: Vaibhav Hiremath <hvaibhav@ti.com>
8 *
9 * Contributors:
10 * Sivaraj R <sivaraj@ti.com>
11 * Brijesh R Jadav <brijesh.j@ti.com>
12 * Hardik Shah <hardik.shah@ti.com>
13 * Manjunath Hadli <mrh@ti.com>
14 * Karicheri Muralidharan <m-karicheri2@ti.com>
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -030015 * Prabhakar Lad <prabhakar.lad@ti.com>
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030016 *
17 * This package is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License version 2 as
19 * published by the Free Software Foundation.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31
32#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030034#include <linux/delay.h>
35#include <linux/videodev2.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040036#include <linux/module.h>
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -030037#include <linux/v4l2-mediabus.h>
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -030038
39#include <media/v4l2-device.h>
40#include <media/v4l2-common.h>
Hans Verkuil83811912010-05-09 06:50:25 -030041#include <media/v4l2-mediabus.h>
Hans Verkuilcf6832a2010-12-12 08:45:22 -030042#include <media/v4l2-ctrls.h>
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030043#include <media/tvp514x.h>
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -030044#include <media/media-entity.h>
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030045
46#include "tvp514x_regs.h"
47
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030048/* Private macros for TVP */
49#define I2C_RETRY_COUNT (5)
50#define LOCK_RETRY_COUNT (5)
51#define LOCK_RETRY_DELAY (200)
52
53/* Debug functions */
Rusty Russell90ab5ee2012-01-13 09:32:20 +103054static bool debug;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030055module_param(debug, bool, 0644);
56MODULE_PARM_DESC(debug, "Debug level (0-1)");
57
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -030058MODULE_AUTHOR("Texas Instruments");
59MODULE_DESCRIPTION("TVP514X linux decoder driver");
60MODULE_LICENSE("GPL");
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030061
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -030062/* enum tvp514x_std - enum for supported standards */
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030063enum tvp514x_std {
64 STD_NTSC_MJ = 0,
65 STD_PAL_BDGHIN,
66 STD_INVALID
67};
68
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -030069/**
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030070 * struct tvp514x_std_info - Structure to store standard informations
71 * @width: Line width in pixels
72 * @height:Number of active lines
73 * @video_std: Value to write in REG_VIDEO_STD register
74 * @standard: v4l2 standard structure information
75 */
76struct tvp514x_std_info {
77 unsigned long width;
78 unsigned long height;
79 u8 video_std;
80 struct v4l2_standard standard;
81};
82
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -030083static struct tvp514x_reg tvp514x_reg_list_default[0x40];
Vaibhav Hiremath63b59ce2010-03-27 09:37:54 -030084
85static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -030086/**
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -030087 * struct tvp514x_decoder - TVP5146/47 decoder object
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -030088 * @sd: Subdevice Slave handle
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -030089 * @tvp514x_regs: copy of hw's regs with preset values.
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030090 * @pdata: Board specific
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030091 * @ver: Chip version
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -030092 * @streaming: TVP5146/47 decoder streaming - enabled or disabled.
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -030093 * @pix: Current pixel format
94 * @num_fmts: Number of formats
95 * @fmt_list: Format list
Vaibhav Hiremath07b17472008-12-05 10:19:36 -030096 * @current_std: Current standard
97 * @num_stds: Number of standards
98 * @std_list: Standards list
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -030099 * @input: Input routing at chip level
100 * @output: Output routing at chip level
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300101 */
102struct tvp514x_decoder {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300103 struct v4l2_subdev sd;
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300104 struct v4l2_ctrl_handler hdl;
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -0300105 struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)];
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300106 const struct tvp514x_platform_data *pdata;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300107
108 int ver;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300109 int streaming;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300110
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300111 struct v4l2_pix_format pix;
112 int num_fmts;
113 const struct v4l2_fmtdesc *fmt_list;
114
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300115 enum tvp514x_std current_std;
116 int num_stds;
Hans Verkuila75ffc12010-05-09 06:32:47 -0300117 const struct tvp514x_std_info *std_list;
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300118 /* Input and Output Routing parameters */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300119 u32 input;
120 u32 output;
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300121
122 /* mc related members */
123 struct media_pad pad;
124 struct v4l2_mbus_framefmt format;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300125};
126
127/* TVP514x default register values */
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -0300128static struct tvp514x_reg tvp514x_reg_list_default[] = {
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300129 /* Composite selected */
130 {TOK_WRITE, REG_INPUT_SEL, 0x05},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300131 {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300132 /* Auto mode */
133 {TOK_WRITE, REG_VIDEO_STD, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300134 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
135 {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F},
136 {TOK_WRITE, REG_COLOR_KILLER, 0x10},
137 {TOK_WRITE, REG_LUMA_CONTROL1, 0x00},
138 {TOK_WRITE, REG_LUMA_CONTROL2, 0x00},
139 {TOK_WRITE, REG_LUMA_CONTROL3, 0x02},
140 {TOK_WRITE, REG_BRIGHTNESS, 0x80},
141 {TOK_WRITE, REG_CONTRAST, 0x80},
142 {TOK_WRITE, REG_SATURATION, 0x80},
143 {TOK_WRITE, REG_HUE, 0x00},
144 {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00},
145 {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300146 /* Reserved */
147 {TOK_SKIP, 0x0F, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300148 {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80},
149 {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80},
150 {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300151 /* Reserved */
152 {TOK_SKIP, 0x13, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300153 {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300154 /* Reserved */
155 {TOK_SKIP, 0x15, 0x00},
156 /* NTSC timing */
157 {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300158 {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00},
159 {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25},
160 {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300161 /* NTSC timing */
162 {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300163 {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00},
164 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40},
165 {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300166 /* NTSC timing */
167 {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300168 {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00},
169 {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07},
170 {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300171 /* NTSC timing */
172 {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300173 {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00},
174 {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15},
175 {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300176 /* Reserved */
177 {TOK_SKIP, 0x26, 0x00},
178 /* Reserved */
179 {TOK_SKIP, 0x27, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300180 {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300181 /* Reserved */
182 {TOK_SKIP, 0x29, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300183 {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300184 /* Reserved */
185 {TOK_SKIP, 0x2B, 0x00},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300186 {TOK_SKIP, REG_SCART_DELAY, 0x00},
187 {TOK_SKIP, REG_CTI_DELAY, 0x00},
188 {TOK_SKIP, REG_CTI_CONTROL, 0x00},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300189 /* Reserved */
190 {TOK_SKIP, 0x2F, 0x00},
191 /* Reserved */
192 {TOK_SKIP, 0x30, 0x00},
193 /* Reserved */
194 {TOK_SKIP, 0x31, 0x00},
195 /* HS, VS active high */
196 {TOK_WRITE, REG_SYNC_CONTROL, 0x00},
197 /* 10-bit BT.656 */
198 {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00},
199 /* Enable clk & data */
200 {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11},
201 /* Enable AVID & FLD */
202 {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE},
203 /* Enable VS & HS */
204 {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300205 {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF},
206 {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF},
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300207 /* Clear status */
208 {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300209 {TOK_TERM, 0, 0},
210};
211
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300212/**
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300213 * List of image formats supported by TVP5146/47 decoder
214 * Currently we are using 8 bit mode only, but can be
215 * extended to 10/20 bit mode.
216 */
217static const struct v4l2_fmtdesc tvp514x_fmt_list[] = {
218 {
219 .index = 0,
220 .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
221 .flags = 0,
222 .description = "8-bit UYVY 4:2:2 Format",
223 .pixelformat = V4L2_PIX_FMT_UYVY,
224 },
225};
226
227/**
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300228 * Supported standards -
229 *
230 * Currently supports two standards only, need to add support for rest of the
231 * modes, like SECAM, etc...
232 */
Hans Verkuila75ffc12010-05-09 06:32:47 -0300233static const struct tvp514x_std_info tvp514x_std_list[] = {
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300234 /* Standard: STD_NTSC_MJ */
235 [STD_NTSC_MJ] = {
236 .width = NTSC_NUM_ACTIVE_PIXELS,
237 .height = NTSC_NUM_ACTIVE_LINES,
238 .video_std = VIDEO_STD_NTSC_MJ_BIT,
239 .standard = {
240 .index = 0,
241 .id = V4L2_STD_NTSC,
242 .name = "NTSC",
243 .frameperiod = {1001, 30000},
244 .framelines = 525
245 },
246 /* Standard: STD_PAL_BDGHIN */
247 },
248 [STD_PAL_BDGHIN] = {
249 .width = PAL_NUM_ACTIVE_PIXELS,
250 .height = PAL_NUM_ACTIVE_LINES,
251 .video_std = VIDEO_STD_PAL_BDGHIN_BIT,
252 .standard = {
253 .index = 1,
254 .id = V4L2_STD_PAL,
255 .name = "PAL",
256 .frameperiod = {1, 25},
257 .framelines = 625
258 },
259 },
260 /* Standard: need to add for additional standard */
261};
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300262
263
264static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd)
265{
266 return container_of(sd, struct tvp514x_decoder, sd);
267}
268
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300269static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
270{
271 return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd;
272}
273
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300274
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300275/**
276 * tvp514x_read_reg() - Read a value from a register in an TVP5146/47.
277 * @sd: ptr to v4l2_subdev struct
278 * @reg: TVP5146/47 register address
279 *
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300280 * Returns value read if successful, or non-zero (-1) otherwise.
281 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300282static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300283{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300284 int err, retry = 0;
285 struct i2c_client *client = v4l2_get_subdevdata(sd);
286
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300287read_again:
288
289 err = i2c_smbus_read_byte_data(client, reg);
Sebastian Andrzej Siewior6f901a92009-11-04 15:35:09 -0300290 if (err < 0) {
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300291 if (retry <= I2C_RETRY_COUNT) {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300292 v4l2_warn(sd, "Read: retry ... %d\n", retry);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300293 retry++;
294 msleep_interruptible(10);
295 goto read_again;
296 }
297 }
298
299 return err;
300}
301
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300302/**
303 * dump_reg() - dump the register content of TVP5146/47.
304 * @sd: ptr to v4l2_subdev struct
305 * @reg: TVP5146/47 register address
306 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300307static void dump_reg(struct v4l2_subdev *sd, u8 reg)
308{
309 u32 val;
310
311 val = tvp514x_read_reg(sd, reg);
312 v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val);
313}
314
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300315/**
316 * tvp514x_write_reg() - Write a value to a register in TVP5146/47
317 * @sd: ptr to v4l2_subdev struct
318 * @reg: TVP5146/47 register address
319 * @val: value to be written to the register
320 *
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300321 * Write a value to a register in an TVP5146/47 decoder device.
322 * Returns zero if successful, or non-zero otherwise.
323 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300324static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300325{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300326 int err, retry = 0;
327 struct i2c_client *client = v4l2_get_subdevdata(sd);
328
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300329write_again:
330
331 err = i2c_smbus_write_byte_data(client, reg, val);
332 if (err) {
333 if (retry <= I2C_RETRY_COUNT) {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300334 v4l2_warn(sd, "Write: retry ... %d\n", retry);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300335 retry++;
336 msleep_interruptible(10);
337 goto write_again;
338 }
339 }
340
341 return err;
342}
343
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300344/**
345 * tvp514x_write_regs() : Initializes a list of TVP5146/47 registers
346 * @sd: ptr to v4l2_subdev struct
347 * @reglist: list of TVP5146/47 registers and values
348 *
349 * Initializes a list of TVP5146/47 registers:-
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300350 * if token is TOK_TERM, then entire write operation terminates
351 * if token is TOK_DELAY, then a delay of 'val' msec is introduced
352 * if token is TOK_SKIP, then the register write is skipped
353 * if token is TOK_WRITE, then the register write is performed
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300354 * Returns zero if successful, or non-zero otherwise.
355 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300356static int tvp514x_write_regs(struct v4l2_subdev *sd,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300357 const struct tvp514x_reg reglist[])
358{
359 int err;
360 const struct tvp514x_reg *next = reglist;
361
362 for (; next->token != TOK_TERM; next++) {
363 if (next->token == TOK_DELAY) {
364 msleep(next->val);
365 continue;
366 }
367
368 if (next->token == TOK_SKIP)
369 continue;
370
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300371 err = tvp514x_write_reg(sd, next->reg, (u8) next->val);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300372 if (err) {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300373 v4l2_err(sd, "Write failed. Err[%d]\n", err);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300374 return err;
375 }
376 }
377 return 0;
378}
379
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300380/**
Hans Verkuil2db4e782010-05-09 06:30:15 -0300381 * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300382 * @sd: ptr to v4l2_subdev struct
383 *
Hans Verkuil2db4e782010-05-09 06:30:15 -0300384 * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300385 * standard detected.
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300386 */
Hans Verkuil2db4e782010-05-09 06:30:15 -0300387static enum tvp514x_std tvp514x_query_current_std(struct v4l2_subdev *sd)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300388{
389 u8 std, std_status;
390
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300391 std = tvp514x_read_reg(sd, REG_VIDEO_STD);
392 if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300393 /* use the standard status register */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300394 std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS);
395 else
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300396 /* use the standard register itself */
397 std_status = std;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300398
399 switch (std_status & VIDEO_STD_MASK) {
400 case VIDEO_STD_NTSC_MJ_BIT:
401 return STD_NTSC_MJ;
402
403 case VIDEO_STD_PAL_BDGHIN_BIT:
404 return STD_PAL_BDGHIN;
405
406 default:
407 return STD_INVALID;
408 }
409
410 return STD_INVALID;
411}
412
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300413/* TVP5146/47 register dump function */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300414static void tvp514x_reg_dump(struct v4l2_subdev *sd)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300415{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300416 dump_reg(sd, REG_INPUT_SEL);
417 dump_reg(sd, REG_AFE_GAIN_CTRL);
418 dump_reg(sd, REG_VIDEO_STD);
419 dump_reg(sd, REG_OPERATION_MODE);
420 dump_reg(sd, REG_COLOR_KILLER);
421 dump_reg(sd, REG_LUMA_CONTROL1);
422 dump_reg(sd, REG_LUMA_CONTROL2);
423 dump_reg(sd, REG_LUMA_CONTROL3);
424 dump_reg(sd, REG_BRIGHTNESS);
425 dump_reg(sd, REG_CONTRAST);
426 dump_reg(sd, REG_SATURATION);
427 dump_reg(sd, REG_HUE);
428 dump_reg(sd, REG_CHROMA_CONTROL1);
429 dump_reg(sd, REG_CHROMA_CONTROL2);
430 dump_reg(sd, REG_COMP_PR_SATURATION);
431 dump_reg(sd, REG_COMP_Y_CONTRAST);
432 dump_reg(sd, REG_COMP_PB_SATURATION);
433 dump_reg(sd, REG_COMP_Y_BRIGHTNESS);
434 dump_reg(sd, REG_AVID_START_PIXEL_LSB);
435 dump_reg(sd, REG_AVID_START_PIXEL_MSB);
436 dump_reg(sd, REG_AVID_STOP_PIXEL_LSB);
437 dump_reg(sd, REG_AVID_STOP_PIXEL_MSB);
438 dump_reg(sd, REG_HSYNC_START_PIXEL_LSB);
439 dump_reg(sd, REG_HSYNC_START_PIXEL_MSB);
440 dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB);
441 dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB);
442 dump_reg(sd, REG_VSYNC_START_LINE_LSB);
443 dump_reg(sd, REG_VSYNC_START_LINE_MSB);
444 dump_reg(sd, REG_VSYNC_STOP_LINE_LSB);
445 dump_reg(sd, REG_VSYNC_STOP_LINE_MSB);
446 dump_reg(sd, REG_VBLK_START_LINE_LSB);
447 dump_reg(sd, REG_VBLK_START_LINE_MSB);
448 dump_reg(sd, REG_VBLK_STOP_LINE_LSB);
449 dump_reg(sd, REG_VBLK_STOP_LINE_MSB);
450 dump_reg(sd, REG_SYNC_CONTROL);
451 dump_reg(sd, REG_OUTPUT_FORMATTER1);
452 dump_reg(sd, REG_OUTPUT_FORMATTER2);
453 dump_reg(sd, REG_OUTPUT_FORMATTER3);
454 dump_reg(sd, REG_OUTPUT_FORMATTER4);
455 dump_reg(sd, REG_OUTPUT_FORMATTER5);
456 dump_reg(sd, REG_OUTPUT_FORMATTER6);
457 dump_reg(sd, REG_CLEAR_LOST_LOCK);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300458}
459
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300460/**
461 * tvp514x_configure() - Configure the TVP5146/47 registers
462 * @sd: ptr to v4l2_subdev struct
463 * @decoder: ptr to tvp514x_decoder structure
464 *
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300465 * Returns zero if successful, or non-zero otherwise.
466 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300467static int tvp514x_configure(struct v4l2_subdev *sd,
468 struct tvp514x_decoder *decoder)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300469{
470 int err;
471
472 /* common register initialization */
473 err =
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300474 tvp514x_write_regs(sd, decoder->tvp514x_regs);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300475 if (err)
476 return err;
477
478 if (debug)
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300479 tvp514x_reg_dump(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300480
481 return 0;
482}
483
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300484/**
485 * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision.
486 * @sd: pointer to standard V4L2 sub-device structure
487 * @decoder: pointer to tvp514x_decoder structure
488 *
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300489 * A device is considered to be detected if the chip ID (LSB and MSB)
490 * registers match the expected values.
491 * Any value of the rom version register is accepted.
492 * Returns ENODEV error number if no device is detected, or zero
493 * if a device is detected.
494 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300495static int tvp514x_detect(struct v4l2_subdev *sd,
496 struct tvp514x_decoder *decoder)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300497{
498 u8 chip_id_msb, chip_id_lsb, rom_ver;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300499 struct i2c_client *client = v4l2_get_subdevdata(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300500
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300501 chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB);
502 chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB);
503 rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300504
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300505 v4l2_dbg(1, debug, sd,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300506 "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n",
507 chip_id_msb, chip_id_lsb, rom_ver);
508 if ((chip_id_msb != TVP514X_CHIP_ID_MSB)
509 || ((chip_id_lsb != TVP5146_CHIP_ID_LSB)
510 && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) {
511 /* We didn't read the values we expected, so this must not be
512 * an TVP5146/47.
513 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300514 v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n",
515 chip_id_msb, chip_id_lsb);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300516 return -ENODEV;
517 }
518
519 decoder->ver = rom_ver;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300520
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300521 v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n",
522 client->name, decoder->ver,
523 client->addr << 1, client->adapter->name);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300524 return 0;
525}
526
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300527/**
528 * tvp514x_querystd() - V4L2 decoder interface handler for querystd
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300529 * @sd: pointer to standard V4L2 sub-device structure
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300530 * @std_id: standard V4L2 std_id ioctl enum
531 *
532 * Returns the current standard detected by TVP5146/47. If no active input is
Hans Verkuil2db4e782010-05-09 06:30:15 -0300533 * detected then *std_id is set to 0 and the function returns 0.
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300534 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300535static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300536{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300537 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300538 enum tvp514x_std current_std;
539 enum tvp514x_input input_sel;
540 u8 sync_lock_status, lock_mask;
541
542 if (std_id == NULL)
543 return -EINVAL;
544
Hans Verkuilc3896482012-09-20 09:06:33 -0300545 /* To query the standard the TVP514x must power on the ADCs. */
546 if (!decoder->streaming) {
547 tvp514x_s_stream(sd, 1);
548 msleep(LOCK_RETRY_DELAY);
549 }
550
Hans Verkuil2db4e782010-05-09 06:30:15 -0300551 /* query the current standard */
552 current_std = tvp514x_query_current_std(sd);
Hans Verkuil55852cb2013-05-29 10:19:00 -0300553 if (current_std == STD_INVALID) {
554 *std_id = V4L2_STD_UNKNOWN;
Hans Verkuil2db4e782010-05-09 06:30:15 -0300555 return 0;
Hans Verkuil55852cb2013-05-29 10:19:00 -0300556 }
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300557
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300558 input_sel = decoder->input;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300559
560 switch (input_sel) {
561 case INPUT_CVBS_VI1A:
562 case INPUT_CVBS_VI1B:
563 case INPUT_CVBS_VI1C:
564 case INPUT_CVBS_VI2A:
565 case INPUT_CVBS_VI2B:
566 case INPUT_CVBS_VI2C:
567 case INPUT_CVBS_VI3A:
568 case INPUT_CVBS_VI3B:
569 case INPUT_CVBS_VI3C:
570 case INPUT_CVBS_VI4A:
571 lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT |
572 STATUS_HORZ_SYNC_LOCK_BIT |
573 STATUS_VIRT_SYNC_LOCK_BIT;
574 break;
575
576 case INPUT_SVIDEO_VI2A_VI1A:
577 case INPUT_SVIDEO_VI2B_VI1B:
578 case INPUT_SVIDEO_VI2C_VI1C:
579 case INPUT_SVIDEO_VI2A_VI3A:
580 case INPUT_SVIDEO_VI2B_VI3B:
581 case INPUT_SVIDEO_VI2C_VI3C:
582 case INPUT_SVIDEO_VI4A_VI1A:
583 case INPUT_SVIDEO_VI4A_VI1B:
584 case INPUT_SVIDEO_VI4A_VI1C:
585 case INPUT_SVIDEO_VI4A_VI3A:
586 case INPUT_SVIDEO_VI4A_VI3B:
587 case INPUT_SVIDEO_VI4A_VI3C:
588 lock_mask = STATUS_HORZ_SYNC_LOCK_BIT |
589 STATUS_VIRT_SYNC_LOCK_BIT;
590 break;
591 /*Need to add other interfaces*/
592 default:
593 return -EINVAL;
594 }
595 /* check whether signal is locked */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300596 sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1);
Hans Verkuil55852cb2013-05-29 10:19:00 -0300597 if (lock_mask != (sync_lock_status & lock_mask)) {
598 *std_id = V4L2_STD_UNKNOWN;
Hans Verkuil2db4e782010-05-09 06:30:15 -0300599 return 0; /* No input detected */
Hans Verkuil55852cb2013-05-29 10:19:00 -0300600 }
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300601
Hans Verkuil55852cb2013-05-29 10:19:00 -0300602 *std_id &= decoder->std_list[current_std].standard.id;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300603
Hans Verkuil2db4e782010-05-09 06:30:15 -0300604 v4l2_dbg(1, debug, sd, "Current STD: %s\n",
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300605 decoder->std_list[current_std].standard.name);
606 return 0;
607}
608
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300609/**
610 * tvp514x_s_std() - V4L2 decoder interface handler for s_std
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300611 * @sd: pointer to standard V4L2 sub-device structure
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300612 * @std_id: standard V4L2 v4l2_std_id ioctl enum
613 *
614 * If std_id is supported, sets the requested standard. Otherwise, returns
615 * -EINVAL
616 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300617static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300618{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300619 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300620 int err, i;
621
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300622 for (i = 0; i < decoder->num_stds; i++)
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300623 if (std_id & decoder->std_list[i].standard.id)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300624 break;
625
626 if ((i == decoder->num_stds) || (i == STD_INVALID))
627 return -EINVAL;
628
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300629 err = tvp514x_write_reg(sd, REG_VIDEO_STD,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300630 decoder->std_list[i].video_std);
631 if (err)
632 return err;
633
634 decoder->current_std = i;
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -0300635 decoder->tvp514x_regs[REG_VIDEO_STD].val =
636 decoder->std_list[i].video_std;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300637
Hans Verkuil3907b072010-05-09 06:39:44 -0300638 v4l2_dbg(1, debug, sd, "Standard set to: %s\n",
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300639 decoder->std_list[i].standard.name);
640 return 0;
641}
642
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300643/**
644 * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300645 * @sd: pointer to standard V4L2 sub-device structure
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300646 * @input: input selector for routing the signal
647 * @output: output selector for routing the signal
648 * @config: config value. Not used
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300649 *
650 * If index is valid, selects the requested input. Otherwise, returns -EINVAL if
651 * the input is not supported or there is no active signal present in the
652 * selected input.
653 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300654static int tvp514x_s_routing(struct v4l2_subdev *sd,
655 u32 input, u32 output, u32 config)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300656{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300657 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300658 int err;
659 enum tvp514x_input input_sel;
660 enum tvp514x_output output_sel;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300661
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300662 if ((input >= INPUT_INVALID) ||
663 (output >= OUTPUT_INVALID))
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300664 /* Index out of bound */
665 return -EINVAL;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300666
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300667 input_sel = input;
668 output_sel = output;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300669
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300670 err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300671 if (err)
672 return err;
673
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300674 output_sel |= tvp514x_read_reg(sd,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300675 REG_OUTPUT_FORMATTER1) & 0x7;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300676 err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300677 output_sel);
678 if (err)
679 return err;
680
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -0300681 decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel;
682 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300683 decoder->input = input;
684 decoder->output = output;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300685
Hans Verkuil2db4e782010-05-09 06:30:15 -0300686 v4l2_dbg(1, debug, sd, "Input set to: %d\n", input_sel);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300687
688 return 0;
689}
690
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300691/**
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300692 * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300693 * @ctrl: pointer to v4l2_ctrl structure
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300694 *
695 * If the requested control is supported, sets the control's current
696 * value in HW. Otherwise, returns -EINVAL if the control is not supported.
697 */
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300698static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300699{
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300700 struct v4l2_subdev *sd = to_sd(ctrl);
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300701 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300702 int err = -EINVAL, value;
703
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300704 value = ctrl->val;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300705
706 switch (ctrl->id) {
707 case V4L2_CID_BRIGHTNESS:
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300708 err = tvp514x_write_reg(sd, REG_BRIGHTNESS, value);
709 if (!err)
710 decoder->tvp514x_regs[REG_BRIGHTNESS].val = value;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300711 break;
712 case V4L2_CID_CONTRAST:
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300713 err = tvp514x_write_reg(sd, REG_CONTRAST, value);
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300714 if (!err)
715 decoder->tvp514x_regs[REG_CONTRAST].val = value;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300716 break;
717 case V4L2_CID_SATURATION:
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300718 err = tvp514x_write_reg(sd, REG_SATURATION, value);
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300719 if (!err)
720 decoder->tvp514x_regs[REG_SATURATION].val = value;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300721 break;
722 case V4L2_CID_HUE:
723 if (value == 180)
724 value = 0x7F;
725 else if (value == -180)
726 value = 0x80;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300727 err = tvp514x_write_reg(sd, REG_HUE, value);
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300728 if (!err)
729 decoder->tvp514x_regs[REG_HUE].val = value;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300730 break;
731 case V4L2_CID_AUTOGAIN:
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300732 err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value ? 0x0f : 0x0c);
733 if (!err)
734 decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300735 break;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300736 }
737
Hans Verkuil3907b072010-05-09 06:39:44 -0300738 v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n",
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300739 ctrl->id, ctrl->val);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300740 return err;
741}
742
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300743/**
Hans Verkuil83811912010-05-09 06:50:25 -0300744 * tvp514x_enum_mbus_fmt() - V4L2 decoder interface handler for enum_mbus_fmt
745 * @sd: pointer to standard V4L2 sub-device structure
746 * @index: index of pixelcode to retrieve
747 * @code: receives the pixelcode
748 *
749 * Enumerates supported mediabus formats
750 */
751static int
752tvp514x_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
753 enum v4l2_mbus_pixelcode *code)
754{
755 if (index)
756 return -EINVAL;
757
758 *code = V4L2_MBUS_FMT_YUYV10_2X10;
759 return 0;
760}
761
762/**
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300763 * tvp514x_mbus_fmt() - V4L2 decoder interface handler for try/s/g_mbus_fmt
Hans Verkuil83811912010-05-09 06:50:25 -0300764 * @sd: pointer to standard V4L2 sub-device structure
765 * @f: pointer to the mediabus format structure
766 *
767 * Negotiates the image capture size and mediabus format.
768 */
769static int
770tvp514x_mbus_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *f)
771{
772 struct tvp514x_decoder *decoder = to_decoder(sd);
773 enum tvp514x_std current_std;
774
775 if (f == NULL)
776 return -EINVAL;
777
778 /* Calculate height and width based on current standard */
779 current_std = decoder->current_std;
780
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300781 f->code = V4L2_MBUS_FMT_YUYV8_2X8;
Hans Verkuil83811912010-05-09 06:50:25 -0300782 f->width = decoder->std_list[current_std].width;
783 f->height = decoder->std_list[current_std].height;
784 f->field = V4L2_FIELD_INTERLACED;
785 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
Hans Verkuil83811912010-05-09 06:50:25 -0300786 v4l2_dbg(1, debug, sd, "MBUS_FMT: Width - %d, Height - %d\n",
787 f->width, f->height);
788 return 0;
789}
790
791/**
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300792 * tvp514x_g_parm() - V4L2 decoder interface handler for g_parm
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300793 * @sd: pointer to standard V4L2 sub-device structure
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300794 * @a: pointer to standard V4L2 VIDIOC_G_PARM ioctl structure
795 *
796 * Returns the decoder's video CAPTURE parameters.
797 */
798static int
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300799tvp514x_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300800{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300801 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300802 struct v4l2_captureparm *cparm;
803 enum tvp514x_std current_std;
804
805 if (a == NULL)
806 return -EINVAL;
807
808 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300809 /* only capture is supported */
810 return -EINVAL;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300811
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300812 /* get the current standard */
Hans Verkuil2db4e782010-05-09 06:30:15 -0300813 current_std = decoder->current_std;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300814
815 cparm = &a->parm.capture;
816 cparm->capability = V4L2_CAP_TIMEPERFRAME;
817 cparm->timeperframe =
818 decoder->std_list[current_std].standard.frameperiod;
819
820 return 0;
821}
822
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300823/**
824 * tvp514x_s_parm() - V4L2 decoder interface handler for s_parm
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300825 * @sd: pointer to standard V4L2 sub-device structure
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300826 * @a: pointer to standard V4L2 VIDIOC_S_PARM ioctl structure
827 *
828 * Configures the decoder to use the input parameters, if possible. If
829 * not possible, returns the appropriate error code.
830 */
831static int
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300832tvp514x_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *a)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300833{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300834 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300835 struct v4l2_fract *timeperframe;
836 enum tvp514x_std current_std;
837
838 if (a == NULL)
839 return -EINVAL;
840
841 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300842 /* only capture is supported */
843 return -EINVAL;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300844
845 timeperframe = &a->parm.capture.timeperframe;
846
847 /* get the current standard */
Hans Verkuil2db4e782010-05-09 06:30:15 -0300848 current_std = decoder->current_std;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300849
850 *timeperframe =
851 decoder->std_list[current_std].standard.frameperiod;
852
853 return 0;
854}
855
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -0300856/**
857 * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300858 * @sd: pointer to standard V4L2 sub-device structure
859 * @enable: streaming enable or disable
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300860 *
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300861 * Sets streaming to enable or disable, if possible.
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300862 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300863static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300864{
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300865 int err = 0;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300866 struct i2c_client *client = v4l2_get_subdevdata(sd);
867 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300868
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300869 if (decoder->streaming == enable)
870 return 0;
871
872 switch (enable) {
873 case 0:
874 {
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300875 /* Power Down Sequence */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300876 err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01);
877 if (err) {
878 v4l2_err(sd, "Unable to turn off decoder\n");
879 return err;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300880 }
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300881 decoder->streaming = enable;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300882 break;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300883 }
884 case 1:
885 {
886 struct tvp514x_reg *int_seq = (struct tvp514x_reg *)
887 client->driver->id_table->driver_data;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300888
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300889 /* Power Up Sequence */
890 err = tvp514x_write_regs(sd, int_seq);
891 if (err) {
892 v4l2_err(sd, "Unable to turn on decoder\n");
893 return err;
894 }
895 /* Detect if not already detected */
896 err = tvp514x_detect(sd, decoder);
897 if (err) {
898 v4l2_err(sd, "Unable to detect decoder\n");
899 return err;
900 }
901 err = tvp514x_configure(sd, decoder);
902 if (err) {
903 v4l2_err(sd, "Unable to configure decoder\n");
904 return err;
905 }
906 decoder->streaming = enable;
907 break;
908 }
Vaibhav Hiremath07b17472008-12-05 10:19:36 -0300909 default:
910 err = -ENODEV;
911 break;
912 }
913
914 return err;
915}
916
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300917static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -0300918 .s_ctrl = tvp514x_s_ctrl,
Hans Verkuilcf6832a2010-12-12 08:45:22 -0300919};
920
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -0300921/**
922 * tvp514x_enum_mbus_code() - V4L2 decoder interface handler for enum_mbus_code
923 * @sd: pointer to standard V4L2 sub-device structure
924 * @fh: file handle
925 * @code: pointer to v4l2_subdev_mbus_code_enum structure
926 *
927 * Enumertaes mbus codes supported
928 */
929static int tvp514x_enum_mbus_code(struct v4l2_subdev *sd,
930 struct v4l2_subdev_fh *fh,
931 struct v4l2_subdev_mbus_code_enum *code)
932{
933 u32 pad = code->pad;
934 u32 index = code->index;
935
936 memset(code, 0, sizeof(*code));
937 code->index = index;
938 code->pad = pad;
939
940 if (index != 0)
941 return -EINVAL;
942
943 code->code = V4L2_MBUS_FMT_YUYV8_2X8;
944
945 return 0;
946}
947
948/**
949 * tvp514x_get_pad_format() - V4L2 decoder interface handler for get pad format
950 * @sd: pointer to standard V4L2 sub-device structure
951 * @fh: file handle
952 * @format: pointer to v4l2_subdev_format structure
953 *
954 * Retrieves pad format which is active or tried based on requirement
955 */
956static int tvp514x_get_pad_format(struct v4l2_subdev *sd,
957 struct v4l2_subdev_fh *fh,
958 struct v4l2_subdev_format *format)
959{
960 struct tvp514x_decoder *decoder = to_decoder(sd);
961 __u32 which = format->which;
962
963 if (which == V4L2_SUBDEV_FORMAT_ACTIVE) {
964 format->format = decoder->format;
965 return 0;
966 }
967
968 format->format.code = V4L2_MBUS_FMT_YUYV8_2X8;
969 format->format.width = tvp514x_std_list[decoder->current_std].width;
970 format->format.height = tvp514x_std_list[decoder->current_std].height;
971 format->format.colorspace = V4L2_COLORSPACE_SMPTE170M;
972 format->format.field = V4L2_FIELD_INTERLACED;
973
974 return 0;
975}
976
977/**
978 * tvp514x_set_pad_format() - V4L2 decoder interface handler for set pad format
979 * @sd: pointer to standard V4L2 sub-device structure
980 * @fh: file handle
981 * @format: pointer to v4l2_subdev_format structure
982 *
983 * Set pad format for the output pad
984 */
985static int tvp514x_set_pad_format(struct v4l2_subdev *sd,
986 struct v4l2_subdev_fh *fh,
987 struct v4l2_subdev_format *fmt)
988{
989 struct tvp514x_decoder *decoder = to_decoder(sd);
990
991 if (fmt->format.field != V4L2_FIELD_INTERLACED ||
992 fmt->format.code != V4L2_MBUS_FMT_YUYV8_2X8 ||
993 fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M ||
994 fmt->format.width != tvp514x_std_list[decoder->current_std].width ||
995 fmt->format.height != tvp514x_std_list[decoder->current_std].height)
996 return -EINVAL;
997
998 decoder->format = fmt->format;
999
1000 return 0;
1001}
1002
Hans Verkuilcf6832a2010-12-12 08:45:22 -03001003static const struct v4l2_subdev_core_ops tvp514x_core_ops = {
1004 .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
1005 .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
1006 .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
1007 .g_ctrl = v4l2_subdev_g_ctrl,
1008 .s_ctrl = v4l2_subdev_s_ctrl,
1009 .queryctrl = v4l2_subdev_queryctrl,
1010 .querymenu = v4l2_subdev_querymenu,
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001011 .s_std = tvp514x_s_std,
1012};
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001013
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001014static const struct v4l2_subdev_video_ops tvp514x_video_ops = {
1015 .s_routing = tvp514x_s_routing,
1016 .querystd = tvp514x_querystd,
Hans Verkuil83811912010-05-09 06:50:25 -03001017 .enum_mbus_fmt = tvp514x_enum_mbus_fmt,
1018 .g_mbus_fmt = tvp514x_mbus_fmt,
1019 .try_mbus_fmt = tvp514x_mbus_fmt,
1020 .s_mbus_fmt = tvp514x_mbus_fmt,
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001021 .g_parm = tvp514x_g_parm,
1022 .s_parm = tvp514x_s_parm,
1023 .s_stream = tvp514x_s_stream,
1024};
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001025
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001026static const struct v4l2_subdev_pad_ops tvp514x_pad_ops = {
1027 .enum_mbus_code = tvp514x_enum_mbus_code,
1028 .get_fmt = tvp514x_get_pad_format,
1029 .set_fmt = tvp514x_set_pad_format,
1030};
1031
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001032static const struct v4l2_subdev_ops tvp514x_ops = {
1033 .core = &tvp514x_core_ops,
1034 .video = &tvp514x_video_ops,
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001035 .pad = &tvp514x_pad_ops,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001036};
1037
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001038static struct tvp514x_decoder tvp514x_dev = {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001039 .streaming = 0,
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001040 .fmt_list = tvp514x_fmt_list,
1041 .num_fmts = ARRAY_SIZE(tvp514x_fmt_list),
1042 .pix = {
1043 /* Default to NTSC 8-bit YUV 422 */
1044 .width = NTSC_NUM_ACTIVE_PIXELS,
1045 .height = NTSC_NUM_ACTIVE_LINES,
1046 .pixelformat = V4L2_PIX_FMT_UYVY,
1047 .field = V4L2_FIELD_INTERLACED,
1048 .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2,
1049 .sizeimage = NTSC_NUM_ACTIVE_PIXELS * 2 *
1050 NTSC_NUM_ACTIVE_LINES,
1051 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1052 },
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001053 .current_std = STD_NTSC_MJ,
1054 .std_list = tvp514x_std_list,
1055 .num_stds = ARRAY_SIZE(tvp514x_std_list),
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001056
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001057};
1058
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001059/**
1060 * tvp514x_probe() - decoder driver i2c probe handler
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001061 * @client: i2c driver client device structure
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001062 * @id: i2c driver id table
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001063 *
1064 * Register decoder as an i2c client device and V4L2
1065 * device.
1066 */
1067static int
1068tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1069{
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001070 struct tvp514x_decoder *decoder;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001071 struct v4l2_subdev *sd;
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001072 int ret;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001073
1074 /* Check if the adapter supports the needed features */
1075 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1076 return -EIO;
1077
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001078 if (!client->dev.platform_data) {
1079 v4l2_err(client, "No platform data!!\n");
1080 return -ENODEV;
1081 }
1082
Lad, Prabhakar08754d32013-01-03 10:04:57 -03001083 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001084 if (!decoder)
1085 return -ENOMEM;
1086
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001087 /* Initialize the tvp514x_decoder with default configuration */
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001088 *decoder = tvp514x_dev;
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001089 /* Copy default register configuration */
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001090 memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default,
1091 sizeof(tvp514x_reg_list_default));
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001092
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001093 /* Copy board specific information here */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001094 decoder->pdata = client->dev.platform_data;
1095
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001096 /**
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001097 * Fetch platform specific data, and configure the
1098 * tvp514x_reg_list[] accordingly. Since this is one
1099 * time configuration, no need to preserve.
1100 */
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001101 decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |=
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001102 (decoder->pdata->clk_polarity << 1);
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001103 decoder->tvp514x_regs[REG_SYNC_CONTROL].val |=
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001104 ((decoder->pdata->hs_polarity << 2) |
1105 (decoder->pdata->vs_polarity << 3));
1106 /* Set default standard to auto */
1107 decoder->tvp514x_regs[REG_VIDEO_STD].val =
1108 VIDEO_STD_AUTO_SWITCH_BIT;
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001109
1110 /* Register with V4L2 layer as slave device */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001111 sd = &decoder->sd;
1112 v4l2_i2c_subdev_init(sd, client, &tvp514x_ops);
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001113 strlcpy(sd->name, TVP514X_MODULE_NAME, sizeof(sd->name));
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001114
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001115#if defined(CONFIG_MEDIA_CONTROLLER)
1116 decoder->pad.flags = MEDIA_PAD_FL_SOURCE;
1117 decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1118 decoder->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
1119
1120 ret = media_entity_init(&decoder->sd.entity, 1, &decoder->pad, 0);
1121 if (ret < 0) {
1122 v4l2_err(sd, "%s decoder driver failed to register !!\n",
1123 sd->name);
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001124 return ret;
1125 }
1126#endif
Hans Verkuilcf6832a2010-12-12 08:45:22 -03001127 v4l2_ctrl_handler_init(&decoder->hdl, 5);
1128 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1129 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1130 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1131 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1132 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1133 V4L2_CID_SATURATION, 0, 255, 1, 128);
1134 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1135 V4L2_CID_HUE, -180, 180, 180, 0);
1136 v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops,
1137 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
1138 sd->ctrl_handler = &decoder->hdl;
1139 if (decoder->hdl.error) {
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001140 ret = decoder->hdl.error;
Hans Verkuilcf6832a2010-12-12 08:45:22 -03001141
1142 v4l2_ctrl_handler_free(&decoder->hdl);
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001143 return ret;
Hans Verkuilcf6832a2010-12-12 08:45:22 -03001144 }
1145 v4l2_ctrl_handler_setup(&decoder->hdl);
1146
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001147 v4l2_info(sd, "%s decoder driver registered !!\n", sd->name);
1148
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001149 return 0;
Sebastian Andrzej Siewior6722e0e2009-01-12 06:17:43 -03001150
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001151}
1152
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001153/**
1154 * tvp514x_remove() - decoder driver i2c remove handler
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001155 * @client: i2c driver client device structure
1156 *
1157 * Unregister decoder as an i2c client device and V4L2
1158 * device. Complement of tvp514x_probe().
1159 */
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001160static int tvp514x_remove(struct i2c_client *client)
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001161{
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001162 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1163 struct tvp514x_decoder *decoder = to_decoder(sd);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001164
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001165 v4l2_device_unregister_subdev(sd);
Manjunath Hadli5b38b0f2013-03-08 04:13:35 -03001166#if defined(CONFIG_MEDIA_CONTROLLER)
1167 media_entity_cleanup(&decoder->sd.entity);
1168#endif
Hans Verkuilcf6832a2010-12-12 08:45:22 -03001169 v4l2_ctrl_handler_free(&decoder->hdl);
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001170 return 0;
1171}
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001172/* TVP5146 Init/Power on Sequence */
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001173static const struct tvp514x_reg tvp5146_init_reg_seq[] = {
1174 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1175 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1176 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1177 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1178 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1179 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1180 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1181 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1182 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1183 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1184 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001185 {TOK_TERM, 0, 0},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001186};
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001187
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001188/* TVP5147 Init/Power on Sequence */
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001189static const struct tvp514x_reg tvp5147_init_reg_seq[] = {
1190 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02},
1191 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1192 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80},
1193 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1194 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1195 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1196 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1197 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01},
1198 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16},
1199 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1200 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0},
1201 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16},
1202 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60},
1203 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00},
1204 {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0},
1205 {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00},
1206 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1207 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001208 {TOK_TERM, 0, 0},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001209};
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001210
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001211/* TVP5146M2/TVP5147M1 Init/Power on Sequence */
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001212static const struct tvp514x_reg tvp514xm_init_reg_seq[] = {
1213 {TOK_WRITE, REG_OPERATION_MODE, 0x01},
1214 {TOK_WRITE, REG_OPERATION_MODE, 0x00},
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001215 {TOK_TERM, 0, 0},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001216};
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001217
Muralidharan Karicheric1c9d092009-07-01 04:20:43 -03001218/**
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001219 * I2C Device Table -
1220 *
1221 * name - Name of the actual device/chip.
1222 * driver_data - Driver data
1223 */
1224static const struct i2c_device_id tvp514x_id[] = {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001225 {"tvp5146", (unsigned long)tvp5146_init_reg_seq},
1226 {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq},
1227 {"tvp5147", (unsigned long)tvp5147_init_reg_seq},
1228 {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq},
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001229 {},
1230};
1231
1232MODULE_DEVICE_TABLE(i2c, tvp514x_id);
1233
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001234static struct i2c_driver tvp514x_driver = {
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001235 .driver = {
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001236 .owner = THIS_MODULE,
1237 .name = TVP514X_MODULE_NAME,
1238 },
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001239 .probe = tvp514x_probe,
Muralidharan Karicheri62ef80a2009-06-19 07:13:44 -03001240 .remove = tvp514x_remove,
Vaibhav Hiremath07b17472008-12-05 10:19:36 -03001241 .id_table = tvp514x_id,
1242};
1243
Axel Linc6e8d862012-02-12 06:56:32 -03001244module_i2c_driver(tvp514x_driver);