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