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