Thomas Gleixner | f2e3bd9 | 2019-06-04 10:11:19 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 2 | /* |
Mauro Carvalho Chehab | cb7a01a | 2012-08-14 16:23:43 -0300 | [diff] [blame] | 3 | * drivers/media/i2c/tvp514x.c |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 4 | * |
| 5 | * TI TVP5146/47 decoder driver |
| 6 | * |
| 7 | * Copyright (C) 2008 Texas Instruments Inc |
| 8 | * Author: Vaibhav Hiremath <hvaibhav@ti.com> |
| 9 | * |
| 10 | * Contributors: |
| 11 | * Sivaraj R <sivaraj@ti.com> |
| 12 | * Brijesh R Jadav <brijesh.j@ti.com> |
| 13 | * Hardik Shah <hardik.shah@ti.com> |
| 14 | * Manjunath Hadli <mrh@ti.com> |
| 15 | * Karicheri Muralidharan <m-karicheri2@ti.com> |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 16 | * Prabhakar Lad <prabhakar.lad@ti.com> |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 21 | #include <linux/delay.h> |
| 22 | #include <linux/videodev2.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 23 | #include <linux/module.h> |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 24 | #include <linux/v4l2-mediabus.h> |
Sachin Kamat | 098bcba | 2013-10-18 00:07:13 -0300 | [diff] [blame] | 25 | #include <linux/of.h> |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 26 | #include <linux/of_graph.h> |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 27 | |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 28 | #include <media/v4l2-async.h> |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 29 | #include <media/v4l2-device.h> |
| 30 | #include <media/v4l2-common.h> |
Hans Verkuil | 8381191 | 2010-05-09 06:50:25 -0300 | [diff] [blame] | 31 | #include <media/v4l2-mediabus.h> |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 32 | #include <media/v4l2-fwnode.h> |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 33 | #include <media/v4l2-ctrls.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 34 | #include <media/i2c/tvp514x.h> |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 35 | #include <media/media-entity.h> |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 36 | |
| 37 | #include "tvp514x_regs.h" |
| 38 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 39 | /* Private macros for TVP */ |
| 40 | #define I2C_RETRY_COUNT (5) |
| 41 | #define LOCK_RETRY_COUNT (5) |
| 42 | #define LOCK_RETRY_DELAY (200) |
| 43 | |
| 44 | /* Debug functions */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 45 | static bool debug; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 46 | module_param(debug, bool, 0644); |
| 47 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 48 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 49 | MODULE_AUTHOR("Texas Instruments"); |
| 50 | MODULE_DESCRIPTION("TVP514X linux decoder driver"); |
| 51 | MODULE_LICENSE("GPL"); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 52 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 53 | /* enum tvp514x_std - enum for supported standards */ |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 54 | enum tvp514x_std { |
| 55 | STD_NTSC_MJ = 0, |
| 56 | STD_PAL_BDGHIN, |
| 57 | STD_INVALID |
| 58 | }; |
| 59 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 60 | /** |
Mauro Carvalho Chehab | f8a7647 | 2019-02-18 14:28:58 -0500 | [diff] [blame] | 61 | * struct tvp514x_std_info - Structure to store standard information |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 62 | * @width: Line width in pixels |
| 63 | * @height:Number of active lines |
| 64 | * @video_std: Value to write in REG_VIDEO_STD register |
| 65 | * @standard: v4l2 standard structure information |
| 66 | */ |
| 67 | struct tvp514x_std_info { |
| 68 | unsigned long width; |
| 69 | unsigned long height; |
| 70 | u8 video_std; |
| 71 | struct v4l2_standard standard; |
| 72 | }; |
| 73 | |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 74 | static struct tvp514x_reg tvp514x_reg_list_default[0x40]; |
Vaibhav Hiremath | 63b59ce | 2010-03-27 09:37:54 -0300 | [diff] [blame] | 75 | |
| 76 | static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable); |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 77 | /** |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 78 | * struct tvp514x_decoder - TVP5146/47 decoder object |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 79 | * @sd: Subdevice Slave handle |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 80 | * @hdl: embedded &struct v4l2_ctrl_handler |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 81 | * @tvp514x_regs: copy of hw's regs with preset values. |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 82 | * @pdata: Board specific |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 83 | * @ver: Chip version |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 84 | * @streaming: TVP5146/47 decoder streaming - enabled or disabled. |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 85 | * @pix: Current pixel format |
| 86 | * @num_fmts: Number of formats |
| 87 | * @fmt_list: Format list |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 88 | * @current_std: Current standard |
| 89 | * @num_stds: Number of standards |
| 90 | * @std_list: Standards list |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 91 | * @input: Input routing at chip level |
| 92 | * @output: Output routing at chip level |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 93 | * @pad: subdev media pad associated with the decoder |
| 94 | * @format: media bus frame format |
| 95 | * @int_seq: driver's register init sequence |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 96 | */ |
| 97 | struct tvp514x_decoder { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 98 | struct v4l2_subdev sd; |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 99 | struct v4l2_ctrl_handler hdl; |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 100 | struct tvp514x_reg tvp514x_regs[ARRAY_SIZE(tvp514x_reg_list_default)]; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 101 | const struct tvp514x_platform_data *pdata; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 102 | |
| 103 | int ver; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 104 | int streaming; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 105 | |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 106 | struct v4l2_pix_format pix; |
| 107 | int num_fmts; |
| 108 | const struct v4l2_fmtdesc *fmt_list; |
| 109 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 110 | enum tvp514x_std current_std; |
| 111 | int num_stds; |
Hans Verkuil | a75ffc1 | 2010-05-09 06:32:47 -0300 | [diff] [blame] | 112 | const struct tvp514x_std_info *std_list; |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 113 | /* Input and Output Routing parameters */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 114 | u32 input; |
| 115 | u32 output; |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 116 | |
| 117 | /* mc related members */ |
| 118 | struct media_pad pad; |
| 119 | struct v4l2_mbus_framefmt format; |
Lars-Peter Clausen | f0a12d0 | 2013-06-23 10:01:35 -0300 | [diff] [blame] | 120 | |
| 121 | struct tvp514x_reg *int_seq; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | /* TVP514x default register values */ |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 125 | static struct tvp514x_reg tvp514x_reg_list_default[] = { |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 126 | /* Composite selected */ |
| 127 | {TOK_WRITE, REG_INPUT_SEL, 0x05}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 128 | {TOK_WRITE, REG_AFE_GAIN_CTRL, 0x0F}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 129 | /* Auto mode */ |
| 130 | {TOK_WRITE, REG_VIDEO_STD, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 131 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, |
| 132 | {TOK_SKIP, REG_AUTOSWITCH_MASK, 0x3F}, |
| 133 | {TOK_WRITE, REG_COLOR_KILLER, 0x10}, |
| 134 | {TOK_WRITE, REG_LUMA_CONTROL1, 0x00}, |
| 135 | {TOK_WRITE, REG_LUMA_CONTROL2, 0x00}, |
| 136 | {TOK_WRITE, REG_LUMA_CONTROL3, 0x02}, |
| 137 | {TOK_WRITE, REG_BRIGHTNESS, 0x80}, |
| 138 | {TOK_WRITE, REG_CONTRAST, 0x80}, |
| 139 | {TOK_WRITE, REG_SATURATION, 0x80}, |
| 140 | {TOK_WRITE, REG_HUE, 0x00}, |
| 141 | {TOK_WRITE, REG_CHROMA_CONTROL1, 0x00}, |
| 142 | {TOK_WRITE, REG_CHROMA_CONTROL2, 0x0E}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 143 | /* Reserved */ |
| 144 | {TOK_SKIP, 0x0F, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 145 | {TOK_WRITE, REG_COMP_PR_SATURATION, 0x80}, |
| 146 | {TOK_WRITE, REG_COMP_Y_CONTRAST, 0x80}, |
| 147 | {TOK_WRITE, REG_COMP_PB_SATURATION, 0x80}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 148 | /* Reserved */ |
| 149 | {TOK_SKIP, 0x13, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 150 | {TOK_WRITE, REG_COMP_Y_BRIGHTNESS, 0x80}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 151 | /* Reserved */ |
| 152 | {TOK_SKIP, 0x15, 0x00}, |
| 153 | /* NTSC timing */ |
| 154 | {TOK_SKIP, REG_AVID_START_PIXEL_LSB, 0x55}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 155 | {TOK_SKIP, REG_AVID_START_PIXEL_MSB, 0x00}, |
| 156 | {TOK_SKIP, REG_AVID_STOP_PIXEL_LSB, 0x25}, |
| 157 | {TOK_SKIP, REG_AVID_STOP_PIXEL_MSB, 0x03}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 158 | /* NTSC timing */ |
| 159 | {TOK_SKIP, REG_HSYNC_START_PIXEL_LSB, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 160 | {TOK_SKIP, REG_HSYNC_START_PIXEL_MSB, 0x00}, |
| 161 | {TOK_SKIP, REG_HSYNC_STOP_PIXEL_LSB, 0x40}, |
| 162 | {TOK_SKIP, REG_HSYNC_STOP_PIXEL_MSB, 0x00}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 163 | /* NTSC timing */ |
| 164 | {TOK_SKIP, REG_VSYNC_START_LINE_LSB, 0x04}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 165 | {TOK_SKIP, REG_VSYNC_START_LINE_MSB, 0x00}, |
| 166 | {TOK_SKIP, REG_VSYNC_STOP_LINE_LSB, 0x07}, |
| 167 | {TOK_SKIP, REG_VSYNC_STOP_LINE_MSB, 0x00}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 168 | /* NTSC timing */ |
| 169 | {TOK_SKIP, REG_VBLK_START_LINE_LSB, 0x01}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 170 | {TOK_SKIP, REG_VBLK_START_LINE_MSB, 0x00}, |
| 171 | {TOK_SKIP, REG_VBLK_STOP_LINE_LSB, 0x15}, |
| 172 | {TOK_SKIP, REG_VBLK_STOP_LINE_MSB, 0x00}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 173 | /* Reserved */ |
| 174 | {TOK_SKIP, 0x26, 0x00}, |
| 175 | /* Reserved */ |
| 176 | {TOK_SKIP, 0x27, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 177 | {TOK_SKIP, REG_FAST_SWTICH_CONTROL, 0xCC}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 178 | /* Reserved */ |
| 179 | {TOK_SKIP, 0x29, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 180 | {TOK_SKIP, REG_FAST_SWTICH_SCART_DELAY, 0x00}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 181 | /* Reserved */ |
| 182 | {TOK_SKIP, 0x2B, 0x00}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 183 | {TOK_SKIP, REG_SCART_DELAY, 0x00}, |
| 184 | {TOK_SKIP, REG_CTI_DELAY, 0x00}, |
| 185 | {TOK_SKIP, REG_CTI_CONTROL, 0x00}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 186 | /* Reserved */ |
| 187 | {TOK_SKIP, 0x2F, 0x00}, |
| 188 | /* Reserved */ |
| 189 | {TOK_SKIP, 0x30, 0x00}, |
| 190 | /* Reserved */ |
| 191 | {TOK_SKIP, 0x31, 0x00}, |
| 192 | /* HS, VS active high */ |
| 193 | {TOK_WRITE, REG_SYNC_CONTROL, 0x00}, |
| 194 | /* 10-bit BT.656 */ |
| 195 | {TOK_WRITE, REG_OUTPUT_FORMATTER1, 0x00}, |
| 196 | /* Enable clk & data */ |
| 197 | {TOK_WRITE, REG_OUTPUT_FORMATTER2, 0x11}, |
| 198 | /* Enable AVID & FLD */ |
| 199 | {TOK_WRITE, REG_OUTPUT_FORMATTER3, 0xEE}, |
| 200 | /* Enable VS & HS */ |
| 201 | {TOK_WRITE, REG_OUTPUT_FORMATTER4, 0xAF}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 202 | {TOK_WRITE, REG_OUTPUT_FORMATTER5, 0xFF}, |
| 203 | {TOK_WRITE, REG_OUTPUT_FORMATTER6, 0xFF}, |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 204 | /* Clear status */ |
| 205 | {TOK_WRITE, REG_CLEAR_LOST_LOCK, 0x01}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 206 | {TOK_TERM, 0, 0}, |
| 207 | }; |
| 208 | |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 209 | /* |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 210 | * List of image formats supported by TVP5146/47 decoder |
| 211 | * Currently we are using 8 bit mode only, but can be |
| 212 | * extended to 10/20 bit mode. |
| 213 | */ |
| 214 | static const struct v4l2_fmtdesc tvp514x_fmt_list[] = { |
| 215 | { |
| 216 | .index = 0, |
| 217 | .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, |
| 218 | .flags = 0, |
| 219 | .description = "8-bit UYVY 4:2:2 Format", |
| 220 | .pixelformat = V4L2_PIX_FMT_UYVY, |
| 221 | }, |
| 222 | }; |
| 223 | |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 224 | /* |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 225 | * Supported standards - |
| 226 | * |
| 227 | * Currently supports two standards only, need to add support for rest of the |
| 228 | * modes, like SECAM, etc... |
| 229 | */ |
Hans Verkuil | a75ffc1 | 2010-05-09 06:32:47 -0300 | [diff] [blame] | 230 | static const struct tvp514x_std_info tvp514x_std_list[] = { |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 231 | /* Standard: STD_NTSC_MJ */ |
| 232 | [STD_NTSC_MJ] = { |
| 233 | .width = NTSC_NUM_ACTIVE_PIXELS, |
| 234 | .height = NTSC_NUM_ACTIVE_LINES, |
| 235 | .video_std = VIDEO_STD_NTSC_MJ_BIT, |
| 236 | .standard = { |
| 237 | .index = 0, |
| 238 | .id = V4L2_STD_NTSC, |
| 239 | .name = "NTSC", |
| 240 | .frameperiod = {1001, 30000}, |
| 241 | .framelines = 525 |
| 242 | }, |
| 243 | /* Standard: STD_PAL_BDGHIN */ |
| 244 | }, |
| 245 | [STD_PAL_BDGHIN] = { |
| 246 | .width = PAL_NUM_ACTIVE_PIXELS, |
| 247 | .height = PAL_NUM_ACTIVE_LINES, |
| 248 | .video_std = VIDEO_STD_PAL_BDGHIN_BIT, |
| 249 | .standard = { |
| 250 | .index = 1, |
| 251 | .id = V4L2_STD_PAL, |
| 252 | .name = "PAL", |
| 253 | .frameperiod = {1, 25}, |
| 254 | .framelines = 625 |
| 255 | }, |
| 256 | }, |
| 257 | /* Standard: need to add for additional standard */ |
| 258 | }; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 259 | |
| 260 | |
| 261 | static inline struct tvp514x_decoder *to_decoder(struct v4l2_subdev *sd) |
| 262 | { |
| 263 | return container_of(sd, struct tvp514x_decoder, sd); |
| 264 | } |
| 265 | |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 266 | static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) |
| 267 | { |
| 268 | return &container_of(ctrl->handler, struct tvp514x_decoder, hdl)->sd; |
| 269 | } |
| 270 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 271 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 272 | /** |
| 273 | * tvp514x_read_reg() - Read a value from a register in an TVP5146/47. |
| 274 | * @sd: ptr to v4l2_subdev struct |
| 275 | * @reg: TVP5146/47 register address |
| 276 | * |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 277 | * Returns value read if successful, or non-zero (-1) otherwise. |
| 278 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 279 | static int tvp514x_read_reg(struct v4l2_subdev *sd, u8 reg) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 280 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 281 | int err, retry = 0; |
| 282 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 283 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 284 | read_again: |
| 285 | |
| 286 | err = i2c_smbus_read_byte_data(client, reg); |
Sebastian Andrzej Siewior | 6f901a9 | 2009-11-04 15:35:09 -0300 | [diff] [blame] | 287 | if (err < 0) { |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 288 | if (retry <= I2C_RETRY_COUNT) { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 289 | v4l2_warn(sd, "Read: retry ... %d\n", retry); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 290 | retry++; |
| 291 | msleep_interruptible(10); |
| 292 | goto read_again; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | return err; |
| 297 | } |
| 298 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 299 | /** |
| 300 | * dump_reg() - dump the register content of TVP5146/47. |
| 301 | * @sd: ptr to v4l2_subdev struct |
| 302 | * @reg: TVP5146/47 register address |
| 303 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 304 | static void dump_reg(struct v4l2_subdev *sd, u8 reg) |
| 305 | { |
| 306 | u32 val; |
| 307 | |
| 308 | val = tvp514x_read_reg(sd, reg); |
| 309 | v4l2_info(sd, "Reg(0x%.2X): 0x%.2X\n", reg, val); |
| 310 | } |
| 311 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 312 | /** |
| 313 | * tvp514x_write_reg() - Write a value to a register in TVP5146/47 |
| 314 | * @sd: ptr to v4l2_subdev struct |
| 315 | * @reg: TVP5146/47 register address |
| 316 | * @val: value to be written to the register |
| 317 | * |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 318 | * Write a value to a register in an TVP5146/47 decoder device. |
| 319 | * Returns zero if successful, or non-zero otherwise. |
| 320 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 321 | static int tvp514x_write_reg(struct v4l2_subdev *sd, u8 reg, u8 val) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 322 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 323 | int err, retry = 0; |
| 324 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 325 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 326 | write_again: |
| 327 | |
| 328 | err = i2c_smbus_write_byte_data(client, reg, val); |
| 329 | if (err) { |
| 330 | if (retry <= I2C_RETRY_COUNT) { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 331 | v4l2_warn(sd, "Write: retry ... %d\n", retry); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 332 | retry++; |
| 333 | msleep_interruptible(10); |
| 334 | goto write_again; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return err; |
| 339 | } |
| 340 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 341 | /** |
| 342 | * tvp514x_write_regs() : Initializes a list of TVP5146/47 registers |
| 343 | * @sd: ptr to v4l2_subdev struct |
| 344 | * @reglist: list of TVP5146/47 registers and values |
| 345 | * |
| 346 | * Initializes a list of TVP5146/47 registers:- |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 347 | * if token is TOK_TERM, then entire write operation terminates |
| 348 | * if token is TOK_DELAY, then a delay of 'val' msec is introduced |
| 349 | * if token is TOK_SKIP, then the register write is skipped |
| 350 | * if token is TOK_WRITE, then the register write is performed |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 351 | * Returns zero if successful, or non-zero otherwise. |
| 352 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 353 | static int tvp514x_write_regs(struct v4l2_subdev *sd, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 354 | const struct tvp514x_reg reglist[]) |
| 355 | { |
| 356 | int err; |
| 357 | const struct tvp514x_reg *next = reglist; |
| 358 | |
| 359 | for (; next->token != TOK_TERM; next++) { |
| 360 | if (next->token == TOK_DELAY) { |
| 361 | msleep(next->val); |
| 362 | continue; |
| 363 | } |
| 364 | |
| 365 | if (next->token == TOK_SKIP) |
| 366 | continue; |
| 367 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 368 | err = tvp514x_write_reg(sd, next->reg, (u8) next->val); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 369 | if (err) { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 370 | v4l2_err(sd, "Write failed. Err[%d]\n", err); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 371 | return err; |
| 372 | } |
| 373 | } |
| 374 | return 0; |
| 375 | } |
| 376 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 377 | /** |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 378 | * tvp514x_query_current_std() : Query the current standard detected by TVP5146/47 |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 379 | * @sd: ptr to v4l2_subdev struct |
| 380 | * |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 381 | * Returns the current standard detected by TVP5146/47, STD_INVALID if there is no |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 382 | * standard detected. |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 383 | */ |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 384 | static enum tvp514x_std tvp514x_query_current_std(struct v4l2_subdev *sd) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 385 | { |
| 386 | u8 std, std_status; |
| 387 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 388 | std = tvp514x_read_reg(sd, REG_VIDEO_STD); |
| 389 | if ((std & VIDEO_STD_MASK) == VIDEO_STD_AUTO_SWITCH_BIT) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 390 | /* use the standard status register */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 391 | std_status = tvp514x_read_reg(sd, REG_VIDEO_STD_STATUS); |
| 392 | else |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 393 | /* use the standard register itself */ |
| 394 | std_status = std; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 395 | |
| 396 | switch (std_status & VIDEO_STD_MASK) { |
| 397 | case VIDEO_STD_NTSC_MJ_BIT: |
| 398 | return STD_NTSC_MJ; |
| 399 | |
| 400 | case VIDEO_STD_PAL_BDGHIN_BIT: |
| 401 | return STD_PAL_BDGHIN; |
| 402 | |
| 403 | default: |
| 404 | return STD_INVALID; |
| 405 | } |
| 406 | |
| 407 | return STD_INVALID; |
| 408 | } |
| 409 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 410 | /* TVP5146/47 register dump function */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 411 | static void tvp514x_reg_dump(struct v4l2_subdev *sd) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 412 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 413 | dump_reg(sd, REG_INPUT_SEL); |
| 414 | dump_reg(sd, REG_AFE_GAIN_CTRL); |
| 415 | dump_reg(sd, REG_VIDEO_STD); |
| 416 | dump_reg(sd, REG_OPERATION_MODE); |
| 417 | dump_reg(sd, REG_COLOR_KILLER); |
| 418 | dump_reg(sd, REG_LUMA_CONTROL1); |
| 419 | dump_reg(sd, REG_LUMA_CONTROL2); |
| 420 | dump_reg(sd, REG_LUMA_CONTROL3); |
| 421 | dump_reg(sd, REG_BRIGHTNESS); |
| 422 | dump_reg(sd, REG_CONTRAST); |
| 423 | dump_reg(sd, REG_SATURATION); |
| 424 | dump_reg(sd, REG_HUE); |
| 425 | dump_reg(sd, REG_CHROMA_CONTROL1); |
| 426 | dump_reg(sd, REG_CHROMA_CONTROL2); |
| 427 | dump_reg(sd, REG_COMP_PR_SATURATION); |
| 428 | dump_reg(sd, REG_COMP_Y_CONTRAST); |
| 429 | dump_reg(sd, REG_COMP_PB_SATURATION); |
| 430 | dump_reg(sd, REG_COMP_Y_BRIGHTNESS); |
| 431 | dump_reg(sd, REG_AVID_START_PIXEL_LSB); |
| 432 | dump_reg(sd, REG_AVID_START_PIXEL_MSB); |
| 433 | dump_reg(sd, REG_AVID_STOP_PIXEL_LSB); |
| 434 | dump_reg(sd, REG_AVID_STOP_PIXEL_MSB); |
| 435 | dump_reg(sd, REG_HSYNC_START_PIXEL_LSB); |
| 436 | dump_reg(sd, REG_HSYNC_START_PIXEL_MSB); |
| 437 | dump_reg(sd, REG_HSYNC_STOP_PIXEL_LSB); |
| 438 | dump_reg(sd, REG_HSYNC_STOP_PIXEL_MSB); |
| 439 | dump_reg(sd, REG_VSYNC_START_LINE_LSB); |
| 440 | dump_reg(sd, REG_VSYNC_START_LINE_MSB); |
| 441 | dump_reg(sd, REG_VSYNC_STOP_LINE_LSB); |
| 442 | dump_reg(sd, REG_VSYNC_STOP_LINE_MSB); |
| 443 | dump_reg(sd, REG_VBLK_START_LINE_LSB); |
| 444 | dump_reg(sd, REG_VBLK_START_LINE_MSB); |
| 445 | dump_reg(sd, REG_VBLK_STOP_LINE_LSB); |
| 446 | dump_reg(sd, REG_VBLK_STOP_LINE_MSB); |
| 447 | dump_reg(sd, REG_SYNC_CONTROL); |
| 448 | dump_reg(sd, REG_OUTPUT_FORMATTER1); |
| 449 | dump_reg(sd, REG_OUTPUT_FORMATTER2); |
| 450 | dump_reg(sd, REG_OUTPUT_FORMATTER3); |
| 451 | dump_reg(sd, REG_OUTPUT_FORMATTER4); |
| 452 | dump_reg(sd, REG_OUTPUT_FORMATTER5); |
| 453 | dump_reg(sd, REG_OUTPUT_FORMATTER6); |
| 454 | dump_reg(sd, REG_CLEAR_LOST_LOCK); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 455 | } |
| 456 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 457 | /** |
| 458 | * tvp514x_configure() - Configure the TVP5146/47 registers |
| 459 | * @sd: ptr to v4l2_subdev struct |
| 460 | * @decoder: ptr to tvp514x_decoder structure |
| 461 | * |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 462 | * Returns zero if successful, or non-zero otherwise. |
| 463 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 464 | static int tvp514x_configure(struct v4l2_subdev *sd, |
| 465 | struct tvp514x_decoder *decoder) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 466 | { |
| 467 | int err; |
| 468 | |
| 469 | /* common register initialization */ |
| 470 | err = |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 471 | tvp514x_write_regs(sd, decoder->tvp514x_regs); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 472 | if (err) |
| 473 | return err; |
| 474 | |
| 475 | if (debug) |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 476 | tvp514x_reg_dump(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 481 | /** |
| 482 | * tvp514x_detect() - Detect if an tvp514x is present, and if so which revision. |
| 483 | * @sd: pointer to standard V4L2 sub-device structure |
| 484 | * @decoder: pointer to tvp514x_decoder structure |
| 485 | * |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 486 | * A device is considered to be detected if the chip ID (LSB and MSB) |
| 487 | * registers match the expected values. |
| 488 | * Any value of the rom version register is accepted. |
| 489 | * Returns ENODEV error number if no device is detected, or zero |
| 490 | * if a device is detected. |
| 491 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 492 | static int tvp514x_detect(struct v4l2_subdev *sd, |
| 493 | struct tvp514x_decoder *decoder) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 494 | { |
| 495 | u8 chip_id_msb, chip_id_lsb, rom_ver; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 496 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 497 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 498 | chip_id_msb = tvp514x_read_reg(sd, REG_CHIP_ID_MSB); |
| 499 | chip_id_lsb = tvp514x_read_reg(sd, REG_CHIP_ID_LSB); |
| 500 | rom_ver = tvp514x_read_reg(sd, REG_ROM_VERSION); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 501 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 502 | v4l2_dbg(1, debug, sd, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 503 | "chip id detected msb:0x%x lsb:0x%x rom version:0x%x\n", |
| 504 | chip_id_msb, chip_id_lsb, rom_ver); |
| 505 | if ((chip_id_msb != TVP514X_CHIP_ID_MSB) |
| 506 | || ((chip_id_lsb != TVP5146_CHIP_ID_LSB) |
| 507 | && (chip_id_lsb != TVP5147_CHIP_ID_LSB))) { |
| 508 | /* We didn't read the values we expected, so this must not be |
| 509 | * an TVP5146/47. |
| 510 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 511 | v4l2_err(sd, "chip id mismatch msb:0x%x lsb:0x%x\n", |
| 512 | chip_id_msb, chip_id_lsb); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 513 | return -ENODEV; |
| 514 | } |
| 515 | |
| 516 | decoder->ver = rom_ver; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 517 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 518 | v4l2_info(sd, "%s (Version - 0x%.2x) found at 0x%x (%s)\n", |
| 519 | client->name, decoder->ver, |
| 520 | client->addr << 1, client->adapter->name); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 524 | /** |
| 525 | * tvp514x_querystd() - V4L2 decoder interface handler for querystd |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 526 | * @sd: pointer to standard V4L2 sub-device structure |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 527 | * @std_id: standard V4L2 std_id ioctl enum |
| 528 | * |
| 529 | * Returns the current standard detected by TVP5146/47. If no active input is |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 530 | * detected then *std_id is set to 0 and the function returns 0. |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 531 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 532 | static int tvp514x_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 533 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 534 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 535 | enum tvp514x_std current_std; |
| 536 | enum tvp514x_input input_sel; |
| 537 | u8 sync_lock_status, lock_mask; |
| 538 | |
| 539 | if (std_id == NULL) |
| 540 | return -EINVAL; |
| 541 | |
Hans Verkuil | c389648 | 2012-09-20 09:06:33 -0300 | [diff] [blame] | 542 | /* To query the standard the TVP514x must power on the ADCs. */ |
| 543 | if (!decoder->streaming) { |
| 544 | tvp514x_s_stream(sd, 1); |
| 545 | msleep(LOCK_RETRY_DELAY); |
| 546 | } |
| 547 | |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 548 | /* query the current standard */ |
| 549 | current_std = tvp514x_query_current_std(sd); |
Hans Verkuil | 55852cb | 2013-05-29 10:19:00 -0300 | [diff] [blame] | 550 | if (current_std == STD_INVALID) { |
| 551 | *std_id = V4L2_STD_UNKNOWN; |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 552 | return 0; |
Hans Verkuil | 55852cb | 2013-05-29 10:19:00 -0300 | [diff] [blame] | 553 | } |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 554 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 555 | input_sel = decoder->input; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 556 | |
| 557 | switch (input_sel) { |
| 558 | case INPUT_CVBS_VI1A: |
| 559 | case INPUT_CVBS_VI1B: |
| 560 | case INPUT_CVBS_VI1C: |
| 561 | case INPUT_CVBS_VI2A: |
| 562 | case INPUT_CVBS_VI2B: |
| 563 | case INPUT_CVBS_VI2C: |
| 564 | case INPUT_CVBS_VI3A: |
| 565 | case INPUT_CVBS_VI3B: |
| 566 | case INPUT_CVBS_VI3C: |
| 567 | case INPUT_CVBS_VI4A: |
| 568 | lock_mask = STATUS_CLR_SUBCAR_LOCK_BIT | |
| 569 | STATUS_HORZ_SYNC_LOCK_BIT | |
| 570 | STATUS_VIRT_SYNC_LOCK_BIT; |
| 571 | break; |
| 572 | |
| 573 | case INPUT_SVIDEO_VI2A_VI1A: |
| 574 | case INPUT_SVIDEO_VI2B_VI1B: |
| 575 | case INPUT_SVIDEO_VI2C_VI1C: |
| 576 | case INPUT_SVIDEO_VI2A_VI3A: |
| 577 | case INPUT_SVIDEO_VI2B_VI3B: |
| 578 | case INPUT_SVIDEO_VI2C_VI3C: |
| 579 | case INPUT_SVIDEO_VI4A_VI1A: |
| 580 | case INPUT_SVIDEO_VI4A_VI1B: |
| 581 | case INPUT_SVIDEO_VI4A_VI1C: |
| 582 | case INPUT_SVIDEO_VI4A_VI3A: |
| 583 | case INPUT_SVIDEO_VI4A_VI3B: |
| 584 | case INPUT_SVIDEO_VI4A_VI3C: |
| 585 | lock_mask = STATUS_HORZ_SYNC_LOCK_BIT | |
| 586 | STATUS_VIRT_SYNC_LOCK_BIT; |
| 587 | break; |
| 588 | /*Need to add other interfaces*/ |
| 589 | default: |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | /* check whether signal is locked */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 593 | sync_lock_status = tvp514x_read_reg(sd, REG_STATUS1); |
Hans Verkuil | 55852cb | 2013-05-29 10:19:00 -0300 | [diff] [blame] | 594 | if (lock_mask != (sync_lock_status & lock_mask)) { |
| 595 | *std_id = V4L2_STD_UNKNOWN; |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 596 | return 0; /* No input detected */ |
Hans Verkuil | 55852cb | 2013-05-29 10:19:00 -0300 | [diff] [blame] | 597 | } |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 598 | |
Hans Verkuil | 55852cb | 2013-05-29 10:19:00 -0300 | [diff] [blame] | 599 | *std_id &= decoder->std_list[current_std].standard.id; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 600 | |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 601 | v4l2_dbg(1, debug, sd, "Current STD: %s\n", |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 602 | decoder->std_list[current_std].standard.name); |
| 603 | return 0; |
| 604 | } |
| 605 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 606 | /** |
| 607 | * tvp514x_s_std() - V4L2 decoder interface handler for s_std |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 608 | * @sd: pointer to standard V4L2 sub-device structure |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 609 | * @std_id: standard V4L2 v4l2_std_id ioctl enum |
| 610 | * |
| 611 | * If std_id is supported, sets the requested standard. Otherwise, returns |
| 612 | * -EINVAL |
| 613 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 614 | static int tvp514x_s_std(struct v4l2_subdev *sd, v4l2_std_id std_id) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 615 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 616 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 617 | int err, i; |
| 618 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 619 | for (i = 0; i < decoder->num_stds; i++) |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 620 | if (std_id & decoder->std_list[i].standard.id) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 621 | break; |
| 622 | |
| 623 | if ((i == decoder->num_stds) || (i == STD_INVALID)) |
| 624 | return -EINVAL; |
| 625 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 626 | err = tvp514x_write_reg(sd, REG_VIDEO_STD, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 627 | decoder->std_list[i].video_std); |
| 628 | if (err) |
| 629 | return err; |
| 630 | |
| 631 | decoder->current_std = i; |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 632 | decoder->tvp514x_regs[REG_VIDEO_STD].val = |
| 633 | decoder->std_list[i].video_std; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 634 | |
Hans Verkuil | 3907b07 | 2010-05-09 06:39:44 -0300 | [diff] [blame] | 635 | v4l2_dbg(1, debug, sd, "Standard set to: %s\n", |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 636 | decoder->std_list[i].standard.name); |
| 637 | return 0; |
| 638 | } |
| 639 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 640 | /** |
| 641 | * tvp514x_s_routing() - V4L2 decoder interface handler for s_routing |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 642 | * @sd: pointer to standard V4L2 sub-device structure |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 643 | * @input: input selector for routing the signal |
| 644 | * @output: output selector for routing the signal |
| 645 | * @config: config value. Not used |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 646 | * |
| 647 | * If index is valid, selects the requested input. Otherwise, returns -EINVAL if |
| 648 | * the input is not supported or there is no active signal present in the |
| 649 | * selected input. |
| 650 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 651 | static int tvp514x_s_routing(struct v4l2_subdev *sd, |
| 652 | u32 input, u32 output, u32 config) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 653 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 654 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 655 | int err; |
| 656 | enum tvp514x_input input_sel; |
| 657 | enum tvp514x_output output_sel; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 658 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 659 | if ((input >= INPUT_INVALID) || |
| 660 | (output >= OUTPUT_INVALID)) |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 661 | /* Index out of bound */ |
| 662 | return -EINVAL; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 663 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 664 | input_sel = input; |
| 665 | output_sel = output; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 666 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 667 | err = tvp514x_write_reg(sd, REG_INPUT_SEL, input_sel); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 668 | if (err) |
| 669 | return err; |
| 670 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 671 | output_sel |= tvp514x_read_reg(sd, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 672 | REG_OUTPUT_FORMATTER1) & 0x7; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 673 | err = tvp514x_write_reg(sd, REG_OUTPUT_FORMATTER1, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 674 | output_sel); |
| 675 | if (err) |
| 676 | return err; |
| 677 | |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 678 | decoder->tvp514x_regs[REG_INPUT_SEL].val = input_sel; |
| 679 | decoder->tvp514x_regs[REG_OUTPUT_FORMATTER1].val = output_sel; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 680 | decoder->input = input; |
| 681 | decoder->output = output; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 682 | |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 683 | v4l2_dbg(1, debug, sd, "Input set to: %d\n", input_sel); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 684 | |
| 685 | return 0; |
| 686 | } |
| 687 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 688 | /** |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 689 | * tvp514x_s_ctrl() - V4L2 decoder interface handler for s_ctrl |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 690 | * @ctrl: pointer to v4l2_ctrl structure |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 691 | * |
| 692 | * If the requested control is supported, sets the control's current |
| 693 | * value in HW. Otherwise, returns -EINVAL if the control is not supported. |
| 694 | */ |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 695 | static int tvp514x_s_ctrl(struct v4l2_ctrl *ctrl) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 696 | { |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 697 | struct v4l2_subdev *sd = to_sd(ctrl); |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 698 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 699 | int err = -EINVAL, value; |
| 700 | |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 701 | value = ctrl->val; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 702 | |
| 703 | switch (ctrl->id) { |
| 704 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 705 | err = tvp514x_write_reg(sd, REG_BRIGHTNESS, value); |
| 706 | if (!err) |
| 707 | decoder->tvp514x_regs[REG_BRIGHTNESS].val = value; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 708 | break; |
| 709 | case V4L2_CID_CONTRAST: |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 710 | err = tvp514x_write_reg(sd, REG_CONTRAST, value); |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 711 | if (!err) |
| 712 | decoder->tvp514x_regs[REG_CONTRAST].val = value; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 713 | break; |
| 714 | case V4L2_CID_SATURATION: |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 715 | err = tvp514x_write_reg(sd, REG_SATURATION, value); |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 716 | if (!err) |
| 717 | decoder->tvp514x_regs[REG_SATURATION].val = value; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 718 | break; |
| 719 | case V4L2_CID_HUE: |
| 720 | if (value == 180) |
| 721 | value = 0x7F; |
| 722 | else if (value == -180) |
| 723 | value = 0x80; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 724 | err = tvp514x_write_reg(sd, REG_HUE, value); |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 725 | if (!err) |
| 726 | decoder->tvp514x_regs[REG_HUE].val = value; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 727 | break; |
| 728 | case V4L2_CID_AUTOGAIN: |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 729 | err = tvp514x_write_reg(sd, REG_AFE_GAIN_CTRL, value ? 0x0f : 0x0c); |
| 730 | if (!err) |
| 731 | decoder->tvp514x_regs[REG_AFE_GAIN_CTRL].val = value; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 732 | break; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 733 | } |
| 734 | |
Hans Verkuil | 3907b07 | 2010-05-09 06:39:44 -0300 | [diff] [blame] | 735 | v4l2_dbg(1, debug, sd, "Set Control: ID - %d - %d\n", |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 736 | ctrl->id, ctrl->val); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 737 | return err; |
| 738 | } |
| 739 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 740 | /** |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 741 | * tvp514x_g_frame_interval() - V4L2 decoder interface handler |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 742 | * @sd: pointer to standard V4L2 sub-device structure |
Mauro Carvalho Chehab | 225fe21 | 2018-02-26 08:31:28 -0500 | [diff] [blame] | 743 | * @ival: pointer to a v4l2_subdev_frame_interval structure |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 744 | * |
| 745 | * Returns the decoder's video CAPTURE parameters. |
| 746 | */ |
| 747 | static int |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 748 | tvp514x_g_frame_interval(struct v4l2_subdev *sd, |
| 749 | struct v4l2_subdev_frame_interval *ival) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 750 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 751 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 752 | enum tvp514x_std current_std; |
| 753 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 754 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 755 | /* get the current standard */ |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 756 | current_std = decoder->current_std; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 757 | |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 758 | ival->interval = |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 759 | decoder->std_list[current_std].standard.frameperiod; |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 764 | /** |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 765 | * tvp514x_s_frame_interval() - V4L2 decoder interface handler |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 766 | * @sd: pointer to standard V4L2 sub-device structure |
Mauro Carvalho Chehab | 225fe21 | 2018-02-26 08:31:28 -0500 | [diff] [blame] | 767 | * @ival: pointer to a v4l2_subdev_frame_interval structure |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 768 | * |
| 769 | * Configures the decoder to use the input parameters, if possible. If |
| 770 | * not possible, returns the appropriate error code. |
| 771 | */ |
| 772 | static int |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 773 | tvp514x_s_frame_interval(struct v4l2_subdev *sd, |
| 774 | struct v4l2_subdev_frame_interval *ival) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 775 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 776 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 777 | struct v4l2_fract *timeperframe; |
| 778 | enum tvp514x_std current_std; |
| 779 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 780 | |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 781 | timeperframe = &ival->interval; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 782 | |
| 783 | /* get the current standard */ |
Hans Verkuil | 2db4e78 | 2010-05-09 06:30:15 -0300 | [diff] [blame] | 784 | current_std = decoder->current_std; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 785 | |
| 786 | *timeperframe = |
| 787 | decoder->std_list[current_std].standard.frameperiod; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 792 | /** |
| 793 | * tvp514x_s_stream() - V4L2 decoder i/f handler for s_stream |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 794 | * @sd: pointer to standard V4L2 sub-device structure |
| 795 | * @enable: streaming enable or disable |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 796 | * |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 797 | * Sets streaming to enable or disable, if possible. |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 798 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 799 | static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 800 | { |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 801 | int err = 0; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 802 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 803 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 804 | if (decoder->streaming == enable) |
| 805 | return 0; |
| 806 | |
| 807 | switch (enable) { |
| 808 | case 0: |
| 809 | { |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 810 | /* Power Down Sequence */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 811 | err = tvp514x_write_reg(sd, REG_OPERATION_MODE, 0x01); |
| 812 | if (err) { |
| 813 | v4l2_err(sd, "Unable to turn off decoder\n"); |
| 814 | return err; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 815 | } |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 816 | decoder->streaming = enable; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 817 | break; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 818 | } |
| 819 | case 1: |
| 820 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 821 | /* Power Up Sequence */ |
Lars-Peter Clausen | f0a12d0 | 2013-06-23 10:01:35 -0300 | [diff] [blame] | 822 | err = tvp514x_write_regs(sd, decoder->int_seq); |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 823 | if (err) { |
| 824 | v4l2_err(sd, "Unable to turn on decoder\n"); |
| 825 | return err; |
| 826 | } |
| 827 | /* Detect if not already detected */ |
| 828 | err = tvp514x_detect(sd, decoder); |
| 829 | if (err) { |
| 830 | v4l2_err(sd, "Unable to detect decoder\n"); |
| 831 | return err; |
| 832 | } |
| 833 | err = tvp514x_configure(sd, decoder); |
| 834 | if (err) { |
| 835 | v4l2_err(sd, "Unable to configure decoder\n"); |
| 836 | return err; |
| 837 | } |
| 838 | decoder->streaming = enable; |
| 839 | break; |
| 840 | } |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 841 | default: |
| 842 | err = -ENODEV; |
| 843 | break; |
| 844 | } |
| 845 | |
| 846 | return err; |
| 847 | } |
| 848 | |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 849 | static const struct v4l2_ctrl_ops tvp514x_ctrl_ops = { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 850 | .s_ctrl = tvp514x_s_ctrl, |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 851 | }; |
| 852 | |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 853 | /** |
| 854 | * tvp514x_enum_mbus_code() - V4L2 decoder interface handler for enum_mbus_code |
| 855 | * @sd: pointer to standard V4L2 sub-device structure |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 856 | * @sd_state: subdev state |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 857 | * @code: pointer to v4l2_subdev_mbus_code_enum structure |
| 858 | * |
| 859 | * Enumertaes mbus codes supported |
| 860 | */ |
| 861 | static int tvp514x_enum_mbus_code(struct v4l2_subdev *sd, |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 862 | struct v4l2_subdev_state *sd_state, |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 863 | struct v4l2_subdev_mbus_code_enum *code) |
| 864 | { |
| 865 | u32 pad = code->pad; |
| 866 | u32 index = code->index; |
| 867 | |
| 868 | memset(code, 0, sizeof(*code)); |
| 869 | code->index = index; |
| 870 | code->pad = pad; |
| 871 | |
| 872 | if (index != 0) |
| 873 | return -EINVAL; |
| 874 | |
Benoit Parrot | 1a33ac0 | 2016-09-14 17:03:13 -0300 | [diff] [blame] | 875 | code->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | /** |
| 881 | * tvp514x_get_pad_format() - V4L2 decoder interface handler for get pad format |
| 882 | * @sd: pointer to standard V4L2 sub-device structure |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 883 | * @sd_state: subdev state |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 884 | * @format: pointer to v4l2_subdev_format structure |
| 885 | * |
| 886 | * Retrieves pad format which is active or tried based on requirement |
| 887 | */ |
| 888 | static int tvp514x_get_pad_format(struct v4l2_subdev *sd, |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 889 | struct v4l2_subdev_state *sd_state, |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 890 | struct v4l2_subdev_format *format) |
| 891 | { |
| 892 | struct tvp514x_decoder *decoder = to_decoder(sd); |
| 893 | __u32 which = format->which; |
| 894 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 895 | if (format->pad) |
| 896 | return -EINVAL; |
| 897 | |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 898 | if (which == V4L2_SUBDEV_FORMAT_ACTIVE) { |
| 899 | format->format = decoder->format; |
| 900 | return 0; |
| 901 | } |
| 902 | |
Benoit Parrot | 1a33ac0 | 2016-09-14 17:03:13 -0300 | [diff] [blame] | 903 | format->format.code = MEDIA_BUS_FMT_UYVY8_2X8; |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 904 | format->format.width = tvp514x_std_list[decoder->current_std].width; |
| 905 | format->format.height = tvp514x_std_list[decoder->current_std].height; |
| 906 | format->format.colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 907 | format->format.field = V4L2_FIELD_INTERLACED; |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * tvp514x_set_pad_format() - V4L2 decoder interface handler for set pad format |
| 914 | * @sd: pointer to standard V4L2 sub-device structure |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 915 | * @sd_state: subdev state |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 916 | * @fmt: pointer to v4l2_subdev_format structure |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 917 | * |
| 918 | * Set pad format for the output pad |
| 919 | */ |
| 920 | static int tvp514x_set_pad_format(struct v4l2_subdev *sd, |
Tomi Valkeinen | 0d346d2 | 2021-06-10 17:55:58 +0300 | [diff] [blame] | 921 | struct v4l2_subdev_state *sd_state, |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 922 | struct v4l2_subdev_format *fmt) |
| 923 | { |
| 924 | struct tvp514x_decoder *decoder = to_decoder(sd); |
| 925 | |
| 926 | if (fmt->format.field != V4L2_FIELD_INTERLACED || |
Benoit Parrot | 1a33ac0 | 2016-09-14 17:03:13 -0300 | [diff] [blame] | 927 | fmt->format.code != MEDIA_BUS_FMT_UYVY8_2X8 || |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 928 | fmt->format.colorspace != V4L2_COLORSPACE_SMPTE170M || |
| 929 | fmt->format.width != tvp514x_std_list[decoder->current_std].width || |
| 930 | fmt->format.height != tvp514x_std_list[decoder->current_std].height) |
| 931 | return -EINVAL; |
| 932 | |
| 933 | decoder->format = fmt->format; |
| 934 | |
| 935 | return 0; |
| 936 | } |
| 937 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 938 | static const struct v4l2_subdev_video_ops tvp514x_video_ops = { |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 939 | .s_std = tvp514x_s_std, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 940 | .s_routing = tvp514x_s_routing, |
| 941 | .querystd = tvp514x_querystd, |
Hans Verkuil | 4471109 | 2018-01-22 04:00:45 -0500 | [diff] [blame] | 942 | .g_frame_interval = tvp514x_g_frame_interval, |
| 943 | .s_frame_interval = tvp514x_s_frame_interval, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 944 | .s_stream = tvp514x_s_stream, |
| 945 | }; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 946 | |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 947 | static const struct v4l2_subdev_pad_ops tvp514x_pad_ops = { |
| 948 | .enum_mbus_code = tvp514x_enum_mbus_code, |
| 949 | .get_fmt = tvp514x_get_pad_format, |
| 950 | .set_fmt = tvp514x_set_pad_format, |
| 951 | }; |
| 952 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 953 | static const struct v4l2_subdev_ops tvp514x_ops = { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 954 | .video = &tvp514x_video_ops, |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 955 | .pad = &tvp514x_pad_ops, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 956 | }; |
| 957 | |
Julia Lawall | db83d08 | 2016-09-11 10:05:55 -0300 | [diff] [blame] | 958 | static const struct tvp514x_decoder tvp514x_dev = { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 959 | .streaming = 0, |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 960 | .fmt_list = tvp514x_fmt_list, |
| 961 | .num_fmts = ARRAY_SIZE(tvp514x_fmt_list), |
| 962 | .pix = { |
| 963 | /* Default to NTSC 8-bit YUV 422 */ |
| 964 | .width = NTSC_NUM_ACTIVE_PIXELS, |
| 965 | .height = NTSC_NUM_ACTIVE_LINES, |
| 966 | .pixelformat = V4L2_PIX_FMT_UYVY, |
| 967 | .field = V4L2_FIELD_INTERLACED, |
| 968 | .bytesperline = NTSC_NUM_ACTIVE_PIXELS * 2, |
| 969 | .sizeimage = NTSC_NUM_ACTIVE_PIXELS * 2 * |
| 970 | NTSC_NUM_ACTIVE_LINES, |
| 971 | .colorspace = V4L2_COLORSPACE_SMPTE170M, |
| 972 | }, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 973 | .current_std = STD_NTSC_MJ, |
| 974 | .std_list = tvp514x_std_list, |
| 975 | .num_stds = ARRAY_SIZE(tvp514x_std_list), |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 976 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 977 | }; |
| 978 | |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 979 | static struct tvp514x_platform_data * |
| 980 | tvp514x_get_pdata(struct i2c_client *client) |
| 981 | { |
Javier Martinez Canillas | fe1e6ac | 2016-01-11 14:47:13 -0200 | [diff] [blame] | 982 | struct tvp514x_platform_data *pdata = NULL; |
Sakari Ailus | 60359a2 | 2018-07-31 05:15:50 -0400 | [diff] [blame] | 983 | struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 }; |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 984 | struct device_node *endpoint; |
| 985 | unsigned int flags; |
| 986 | |
| 987 | if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) |
| 988 | return client->dev.platform_data; |
| 989 | |
Philipp Zabel | fd9fdb7 | 2014-02-10 22:01:48 +0100 | [diff] [blame] | 990 | endpoint = of_graph_get_next_endpoint(client->dev.of_node, NULL); |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 991 | if (!endpoint) |
| 992 | return NULL; |
| 993 | |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 994 | if (v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint), &bus_cfg)) |
Javier Martinez Canillas | fe1e6ac | 2016-01-11 14:47:13 -0200 | [diff] [blame] | 995 | goto done; |
| 996 | |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 997 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); |
| 998 | if (!pdata) |
| 999 | goto done; |
| 1000 | |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1001 | flags = bus_cfg.bus.parallel.flags; |
| 1002 | |
| 1003 | if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) |
| 1004 | pdata->hs_polarity = 1; |
| 1005 | |
| 1006 | if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) |
| 1007 | pdata->vs_polarity = 1; |
| 1008 | |
| 1009 | if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) |
| 1010 | pdata->clk_polarity = 1; |
| 1011 | |
| 1012 | done: |
| 1013 | of_node_put(endpoint); |
| 1014 | return pdata; |
| 1015 | } |
| 1016 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1017 | /** |
| 1018 | * tvp514x_probe() - decoder driver i2c probe handler |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1019 | * @client: i2c driver client device structure |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1020 | * @id: i2c driver id table |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1021 | * |
| 1022 | * Register decoder as an i2c client device and V4L2 |
| 1023 | * device. |
| 1024 | */ |
| 1025 | static int |
| 1026 | tvp514x_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 1027 | { |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1028 | struct tvp514x_platform_data *pdata = tvp514x_get_pdata(client); |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1029 | struct tvp514x_decoder *decoder; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1030 | struct v4l2_subdev *sd; |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1031 | int ret; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1032 | |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1033 | if (pdata == NULL) { |
| 1034 | dev_err(&client->dev, "No platform data\n"); |
| 1035 | return -EINVAL; |
| 1036 | } |
| 1037 | |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1038 | /* Check if the adapter supports the needed features */ |
| 1039 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 1040 | return -EIO; |
| 1041 | |
Lad, Prabhakar | 08754d3 | 2013-01-03 10:04:57 -0300 | [diff] [blame] | 1042 | decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL); |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1043 | if (!decoder) |
| 1044 | return -ENOMEM; |
| 1045 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1046 | /* Initialize the tvp514x_decoder with default configuration */ |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1047 | *decoder = tvp514x_dev; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1048 | /* Copy default register configuration */ |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1049 | memcpy(decoder->tvp514x_regs, tvp514x_reg_list_default, |
| 1050 | sizeof(tvp514x_reg_list_default)); |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1051 | |
Lars-Peter Clausen | f0a12d0 | 2013-06-23 10:01:35 -0300 | [diff] [blame] | 1052 | decoder->int_seq = (struct tvp514x_reg *)id->driver_data; |
| 1053 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1054 | /* Copy board specific information here */ |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1055 | decoder->pdata = pdata; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1056 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1057 | /** |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1058 | * Fetch platform specific data, and configure the |
| 1059 | * tvp514x_reg_list[] accordingly. Since this is one |
| 1060 | * time configuration, no need to preserve. |
| 1061 | */ |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1062 | decoder->tvp514x_regs[REG_OUTPUT_FORMATTER2].val |= |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1063 | (decoder->pdata->clk_polarity << 1); |
Sebastian Andrzej Siewior | 6722e0e | 2009-01-12 06:17:43 -0300 | [diff] [blame] | 1064 | decoder->tvp514x_regs[REG_SYNC_CONTROL].val |= |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1065 | ((decoder->pdata->hs_polarity << 2) | |
| 1066 | (decoder->pdata->vs_polarity << 3)); |
| 1067 | /* Set default standard to auto */ |
| 1068 | decoder->tvp514x_regs[REG_VIDEO_STD].val = |
| 1069 | VIDEO_STD_AUTO_SWITCH_BIT; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1070 | |
| 1071 | /* Register with V4L2 layer as slave device */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1072 | sd = &decoder->sd; |
| 1073 | v4l2_i2c_subdev_init(sd, client, &tvp514x_ops); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1074 | |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1075 | #if defined(CONFIG_MEDIA_CONTROLLER) |
| 1076 | decoder->pad.flags = MEDIA_PAD_FL_SOURCE; |
| 1077 | decoder->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
Hans Verkuil | ca0fa5f | 2018-06-18 05:09:45 -0400 | [diff] [blame] | 1078 | decoder->sd.entity.function = MEDIA_ENT_F_ATV_DECODER; |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1079 | |
Mauro Carvalho Chehab | ab22e77 | 2015-12-11 07:44:40 -0200 | [diff] [blame] | 1080 | ret = media_entity_pads_init(&decoder->sd.entity, 1, &decoder->pad); |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1081 | if (ret < 0) { |
| 1082 | v4l2_err(sd, "%s decoder driver failed to register !!\n", |
| 1083 | sd->name); |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1084 | return ret; |
| 1085 | } |
| 1086 | #endif |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 1087 | v4l2_ctrl_handler_init(&decoder->hdl, 5); |
| 1088 | v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, |
| 1089 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
| 1090 | v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, |
| 1091 | V4L2_CID_CONTRAST, 0, 255, 1, 128); |
| 1092 | v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, |
| 1093 | V4L2_CID_SATURATION, 0, 255, 1, 128); |
| 1094 | v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, |
| 1095 | V4L2_CID_HUE, -180, 180, 180, 0); |
| 1096 | v4l2_ctrl_new_std(&decoder->hdl, &tvp514x_ctrl_ops, |
| 1097 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
| 1098 | sd->ctrl_handler = &decoder->hdl; |
| 1099 | if (decoder->hdl.error) { |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1100 | ret = decoder->hdl.error; |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1101 | goto done; |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 1102 | } |
| 1103 | v4l2_ctrl_handler_setup(&decoder->hdl); |
| 1104 | |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1105 | ret = v4l2_async_register_subdev(&decoder->sd); |
| 1106 | if (!ret) |
| 1107 | v4l2_info(sd, "%s decoder driver registered !!\n", sd->name); |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1108 | |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1109 | done: |
| 1110 | if (ret < 0) { |
| 1111 | v4l2_ctrl_handler_free(&decoder->hdl); |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1112 | media_entity_cleanup(&decoder->sd.entity); |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1113 | } |
| 1114 | return ret; |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1115 | } |
| 1116 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1117 | /** |
| 1118 | * tvp514x_remove() - decoder driver i2c remove handler |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1119 | * @client: i2c driver client device structure |
| 1120 | * |
| 1121 | * Unregister decoder as an i2c client device and V4L2 |
| 1122 | * device. Complement of tvp514x_probe(). |
| 1123 | */ |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1124 | static int tvp514x_remove(struct i2c_client *client) |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1125 | { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1126 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 1127 | struct tvp514x_decoder *decoder = to_decoder(sd); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1128 | |
Lad, Prabhakar | 8f23acb | 2013-06-24 11:51:39 -0300 | [diff] [blame] | 1129 | v4l2_async_unregister_subdev(&decoder->sd); |
Manjunath Hadli | 5b38b0f | 2013-03-08 04:13:35 -0300 | [diff] [blame] | 1130 | media_entity_cleanup(&decoder->sd.entity); |
Hans Verkuil | cf6832a | 2010-12-12 08:45:22 -0300 | [diff] [blame] | 1131 | v4l2_ctrl_handler_free(&decoder->hdl); |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1132 | return 0; |
| 1133 | } |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1134 | /* TVP5146 Init/Power on Sequence */ |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1135 | static const struct tvp514x_reg tvp5146_init_reg_seq[] = { |
| 1136 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02}, |
| 1137 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1138 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80}, |
| 1139 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, |
| 1140 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, |
| 1141 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1142 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, |
| 1143 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, |
| 1144 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, |
| 1145 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, |
| 1146 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1147 | {TOK_TERM, 0, 0}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1148 | }; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1149 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1150 | /* TVP5147 Init/Power on Sequence */ |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1151 | static const struct tvp514x_reg tvp5147_init_reg_seq[] = { |
| 1152 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x02}, |
| 1153 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1154 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0x80}, |
| 1155 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, |
| 1156 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, |
| 1157 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1158 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, |
| 1159 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x01}, |
| 1160 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x16}, |
| 1161 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1162 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xA0}, |
| 1163 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x16}, |
| 1164 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS1, 0x60}, |
| 1165 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS2, 0x00}, |
| 1166 | {TOK_WRITE, REG_VBUS_ADDRESS_ACCESS3, 0xB0}, |
| 1167 | {TOK_WRITE, REG_VBUS_DATA_ACCESS_NO_VBUS_ADDR_INCR, 0x00}, |
| 1168 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, |
| 1169 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1170 | {TOK_TERM, 0, 0}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1171 | }; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1172 | |
Muralidharan Karicheri | c1c9d09 | 2009-07-01 04:20:43 -0300 | [diff] [blame] | 1173 | /* TVP5146M2/TVP5147M1 Init/Power on Sequence */ |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1174 | static const struct tvp514x_reg tvp514xm_init_reg_seq[] = { |
| 1175 | {TOK_WRITE, REG_OPERATION_MODE, 0x01}, |
| 1176 | {TOK_WRITE, REG_OPERATION_MODE, 0x00}, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1177 | {TOK_TERM, 0, 0}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1178 | }; |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1179 | |
Mauro Carvalho Chehab | c5bb831 | 2017-11-29 09:26:20 -0500 | [diff] [blame] | 1180 | /* |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1181 | * I2C Device Table - |
| 1182 | * |
| 1183 | * name - Name of the actual device/chip. |
| 1184 | * driver_data - Driver data |
| 1185 | */ |
| 1186 | static const struct i2c_device_id tvp514x_id[] = { |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1187 | {"tvp5146", (unsigned long)tvp5146_init_reg_seq}, |
| 1188 | {"tvp5146m2", (unsigned long)tvp514xm_init_reg_seq}, |
| 1189 | {"tvp5147", (unsigned long)tvp5147_init_reg_seq}, |
| 1190 | {"tvp5147m1", (unsigned long)tvp514xm_init_reg_seq}, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1191 | {}, |
| 1192 | }; |
| 1193 | |
| 1194 | MODULE_DEVICE_TABLE(i2c, tvp514x_id); |
| 1195 | |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1196 | #if IS_ENABLED(CONFIG_OF) |
| 1197 | static const struct of_device_id tvp514x_of_match[] = { |
| 1198 | { .compatible = "ti,tvp5146", }, |
| 1199 | { .compatible = "ti,tvp5146m2", }, |
| 1200 | { .compatible = "ti,tvp5147", }, |
| 1201 | { .compatible = "ti,tvp5147m1", }, |
| 1202 | { /* sentinel */ }, |
| 1203 | }; |
| 1204 | MODULE_DEVICE_TABLE(of, tvp514x_of_match); |
| 1205 | #endif |
| 1206 | |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1207 | static struct i2c_driver tvp514x_driver = { |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1208 | .driver = { |
Lad, Prabhakar | b610b59 | 2013-06-04 12:26:23 -0300 | [diff] [blame] | 1209 | .of_match_table = of_match_ptr(tvp514x_of_match), |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1210 | .name = TVP514X_MODULE_NAME, |
| 1211 | }, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1212 | .probe = tvp514x_probe, |
Muralidharan Karicheri | 62ef80a | 2009-06-19 07:13:44 -0300 | [diff] [blame] | 1213 | .remove = tvp514x_remove, |
Vaibhav Hiremath | 07b1747 | 2008-12-05 10:19:36 -0300 | [diff] [blame] | 1214 | .id_table = tvp514x_id, |
| 1215 | }; |
| 1216 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 1217 | module_i2c_driver(tvp514x_driver); |