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