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