blob: 4fd3688e1164e77ee69f8342d0c0125a1b0d01cd [file] [log] [blame]
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001/*
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -02002 * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder driver
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08003 *
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -02004 * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org)
5 * This code is placed under the terms of the GNU General Public License v2
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08006 */
7
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08008#include <linux/i2c.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Hans Verkuil33b687c2008-07-25 05:32:50 -030010#include <linux/videodev2.h>
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080011#include <linux/delay.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040012#include <linux/module.h>
Hans Verkuil6b8fe022008-12-18 11:17:25 -030013#include <media/v4l2-device.h>
Hans Verkuilc7c0b342006-04-02 13:35:00 -030014#include <media/tvp5150.h>
Hans Verkuil6c45ec72010-12-12 08:45:43 -030015#include <media/v4l2-ctrls.h>
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080016
17#include "tvp5150_reg.h"
18
Philipp Zabel785a3de2014-02-27 13:44:47 -030019#define TVP5150_H_MAX 720U
20#define TVP5150_V_MAX_525_60 480U
21#define TVP5150_V_MAX_OTHERS 576U
Javier Martin963ddc62012-01-31 05:23:46 -030022#define TVP5150_MAX_CROP_LEFT 511
23#define TVP5150_MAX_CROP_TOP 127
24#define TVP5150_CROP_SHIFT 2
25
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -020026MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver");
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080027MODULE_AUTHOR("Mauro Carvalho Chehab");
28MODULE_LICENSE("GPL");
29
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080030
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030031static int debug;
Philipp Zabel2a0489d2014-02-27 13:44:48 -030032module_param(debug, int, 0644);
Hans Verkuil6b8fe022008-12-18 11:17:25 -030033MODULE_PARM_DESC(debug, "Debug level (0-2)");
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080034
35struct tvp5150 {
Hans Verkuil6b8fe022008-12-18 11:17:25 -030036 struct v4l2_subdev sd;
Hans Verkuil6c45ec72010-12-12 08:45:43 -030037 struct v4l2_ctrl_handler hdl;
Javier Martin963ddc62012-01-31 05:23:46 -030038 struct v4l2_rect rect;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080039
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -020040 v4l2_std_id norm; /* Current set standard */
Hans Verkuil5325b422009-04-02 11:26:22 -030041 u32 input;
42 u32 output;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080043 int enable;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080044};
45
Hans Verkuil6b8fe022008-12-18 11:17:25 -030046static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080047{
Hans Verkuil6b8fe022008-12-18 11:17:25 -030048 return container_of(sd, struct tvp5150, sd);
49}
50
Hans Verkuil6c45ec72010-12-12 08:45:43 -030051static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
52{
53 return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
54}
55
Hans Verkuil6b8fe022008-12-18 11:17:25 -030056static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
57{
58 struct i2c_client *c = v4l2_get_subdevdata(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080059 unsigned char buffer[1];
60 int rc;
Mauro Carvalho Chehab8de531b2013-12-26 23:07:22 -030061 struct i2c_msg msg[] = {
62 { .addr = c->addr, .flags = 0,
63 .buf = &addr, .len = 1 },
64 { .addr = c->addr, .flags = I2C_M_RD,
65 .buf = buffer, .len = 1 }
66 };
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080067
Mauro Carvalho Chehab8de531b2013-12-26 23:07:22 -030068 rc = i2c_transfer(c->adapter, msg, 2);
69 if (rc < 0 || rc != 2) {
70 v4l2_err(sd, "i2c i/o error: rc == %d (should be 2)\n", rc);
71 return rc < 0 ? rc : -EIO;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -030072 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -020073
Hans Verkuil6b8fe022008-12-18 11:17:25 -030074 v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080075
76 return (buffer[0]);
77}
78
Hans Verkuil6b8fe022008-12-18 11:17:25 -030079static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr,
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080080 unsigned char value)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080081{
Hans Verkuil6b8fe022008-12-18 11:17:25 -030082 struct i2c_client *c = v4l2_get_subdevdata(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080083 unsigned char buffer[2];
84 int rc;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080085
86 buffer[0] = addr;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080087 buffer[1] = value;
Hans Verkuil6b8fe022008-12-18 11:17:25 -030088 v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080089 if (2 != (rc = i2c_master_send(c, buffer, 2)))
Hans Verkuil6b8fe022008-12-18 11:17:25 -030090 v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d (should be 2)\n", rc);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080091}
92
Hans Verkuil6b8fe022008-12-18 11:17:25 -030093static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
94 const u8 end, int max_line)
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -020095{
Hans Verkuil6b8fe022008-12-18 11:17:25 -030096 int i = 0;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -020097
Hans Verkuil6b8fe022008-12-18 11:17:25 -030098 while (init != (u8)(end + 1)) {
99 if ((i % max_line) == 0) {
100 if (i > 0)
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200101 printk("\n");
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300102 printk("tvp5150: %s reg 0x%02x = ", s, init);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200103 }
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300104 printk("%02x ", tvp5150_read(sd, init));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200105
106 init++;
107 i++;
108 }
109 printk("\n");
110}
111
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300112static int tvp5150_log_status(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800113{
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800114 printk("tvp5150: Video input source selection #1 = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300115 tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800116 printk("tvp5150: Analog channel controls = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300117 tvp5150_read(sd, TVP5150_ANAL_CHL_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800118 printk("tvp5150: Operation mode controls = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300119 tvp5150_read(sd, TVP5150_OP_MODE_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800120 printk("tvp5150: Miscellaneous controls = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300121 tvp5150_read(sd, TVP5150_MISC_CTL));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200122 printk("tvp5150: Autoswitch mask= 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300123 tvp5150_read(sd, TVP5150_AUTOSW_MSK));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800124 printk("tvp5150: Color killer threshold control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300125 tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200126 printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300127 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1),
128 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2),
129 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800130 printk("tvp5150: Brightness control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300131 tvp5150_read(sd, TVP5150_BRIGHT_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800132 printk("tvp5150: Color saturation control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300133 tvp5150_read(sd, TVP5150_SATURATION_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800134 printk("tvp5150: Hue control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300135 tvp5150_read(sd, TVP5150_HUE_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800136 printk("tvp5150: Contrast control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300137 tvp5150_read(sd, TVP5150_CONTRAST_CTL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800138 printk("tvp5150: Outputs and data rates select = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300139 tvp5150_read(sd, TVP5150_DATA_RATE_SEL));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800140 printk("tvp5150: Configuration shared pins = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300141 tvp5150_read(sd, TVP5150_CONF_SHARED_PIN));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200142 printk("tvp5150: Active video cropping start = 0x%02x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300143 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB),
144 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200145 printk("tvp5150: Active video cropping stop = 0x%02x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300146 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB),
147 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800148 printk("tvp5150: Genlock/RTC = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300149 tvp5150_read(sd, TVP5150_GENLOCK));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800150 printk("tvp5150: Horizontal sync start = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300151 tvp5150_read(sd, TVP5150_HORIZ_SYNC_START));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800152 printk("tvp5150: Vertical blanking start = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300153 tvp5150_read(sd, TVP5150_VERT_BLANKING_START));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800154 printk("tvp5150: Vertical blanking stop = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300155 tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200156 printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300157 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1),
158 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800159 printk("tvp5150: Interrupt reset register B = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300160 tvp5150_read(sd, TVP5150_INT_RESET_REG_B));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800161 printk("tvp5150: Interrupt enable register B = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300162 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800163 printk("tvp5150: Interrupt configuration register B = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300164 tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800165 printk("tvp5150: Video standard = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300166 tvp5150_read(sd, TVP5150_VIDEO_STD));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200167 printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300168 tvp5150_read(sd, TVP5150_CB_GAIN_FACT),
169 tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800170 printk("tvp5150: Macrovision on counter = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300171 tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800172 printk("tvp5150: Macrovision off counter = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300173 tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200174 printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300175 (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200176 printk("tvp5150: Device ID = %02x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300177 tvp5150_read(sd, TVP5150_MSB_DEV_ID),
178 tvp5150_read(sd, TVP5150_LSB_DEV_ID));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200179 printk("tvp5150: ROM version = (hex) %02x.%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300180 tvp5150_read(sd, TVP5150_ROM_MAJOR_VER),
181 tvp5150_read(sd, TVP5150_ROM_MINOR_VER));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200182 printk("tvp5150: Vertical line count = 0x%02x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300183 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB),
184 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800185 printk("tvp5150: Interrupt status register B = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300186 tvp5150_read(sd, TVP5150_INT_STATUS_REG_B));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800187 printk("tvp5150: Interrupt active register B = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300188 tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200189 printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300190 tvp5150_read(sd, TVP5150_STATUS_REG_1),
191 tvp5150_read(sd, TVP5150_STATUS_REG_2),
192 tvp5150_read(sd, TVP5150_STATUS_REG_3),
193 tvp5150_read(sd, TVP5150_STATUS_REG_4),
194 tvp5150_read(sd, TVP5150_STATUS_REG_5));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200195
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300196 dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
197 TVP5150_TELETEXT_FIL1_END, 8);
198 dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
199 TVP5150_TELETEXT_FIL2_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200200
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800201 printk("tvp5150: Teletext filter enable = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300202 tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800203 printk("tvp5150: Interrupt status register A = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300204 tvp5150_read(sd, TVP5150_INT_STATUS_REG_A));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800205 printk("tvp5150: Interrupt enable register A = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300206 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800207 printk("tvp5150: Interrupt configuration = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300208 tvp5150_read(sd, TVP5150_INT_CONF));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800209 printk("tvp5150: VDP status register = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300210 tvp5150_read(sd, TVP5150_VDP_STATUS_REG));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800211 printk("tvp5150: FIFO word count = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300212 tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800213 printk("tvp5150: FIFO interrupt threshold = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300214 tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800215 printk("tvp5150: FIFO reset = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300216 tvp5150_read(sd, TVP5150_FIFO_RESET));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800217 printk("tvp5150: Line number interrupt = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300218 tvp5150_read(sd, TVP5150_LINE_NUMBER_INT));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200219 printk("tvp5150: Pixel alignment register = 0x%02x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300220 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH),
221 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800222 printk("tvp5150: FIFO output control = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300223 tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200224 printk("tvp5150: Full field enable = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300225 tvp5150_read(sd, TVP5150_FULL_FIELD_ENA));
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800226 printk("tvp5150: Full field mode register = 0x%02x\n",
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300227 tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200228
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300229 dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI,
230 TVP5150_CC_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200231
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300232 dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI,
233 TVP5150_WSS_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200234
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300235 dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI,
236 TVP5150_VPS_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200237
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300238 dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI,
239 TVP5150_VITC_DATA_END, 10);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200240
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300241 dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI,
242 TVP5150_LINE_MODE_END, 8);
243 return 0;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800244}
245
246/****************************************************************************
247 Basic functions
248 ****************************************************************************/
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800249
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300250static inline void tvp5150_selmux(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800251{
Paul Walmsley2962fc02010-10-09 01:31:40 -0300252 int opmode = 0;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300253 struct tvp5150 *decoder = to_tvp5150(sd);
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300254 int input = 0;
Dan Carpenterafcc8e82012-07-12 10:47:28 -0300255 int val;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800256
Hans Verkuil5325b422009-04-02 11:26:22 -0300257 if ((decoder->output & TVP5150_BLACK_SCREEN) || !decoder->enable)
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300258 input = 8;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800259
Hans Verkuil5325b422009-04-02 11:26:22 -0300260 switch (decoder->input) {
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300261 case TVP5150_COMPOSITE1:
262 input |= 2;
263 /* fall through */
264 case TVP5150_COMPOSITE0:
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200265 break;
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300266 case TVP5150_SVIDEO:
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200267 default:
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300268 input |= 1;
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200269 break;
270 }
271
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300272 v4l2_dbg(1, debug, sd, "Selecting video route: route input=%i, output=%i "
Mauro Carvalho Chehab12500f02006-08-18 07:31:10 -0300273 "=> tvp5150 input=%i, opmode=%i\n",
Hans Verkuil5325b422009-04-02 11:26:22 -0300274 decoder->input, decoder->output,
275 input, opmode);
Mauro Carvalho Chehab12500f02006-08-18 07:31:10 -0300276
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300277 tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode);
278 tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input);
Mauro Carvalho Chehabf4b8b3a2007-11-03 22:40:24 -0300279
280 /* Svideo should enable YCrCb output and disable GPCL output
281 * For Composite and TV, it should be the reverse
282 */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300283 val = tvp5150_read(sd, TVP5150_MISC_CTL);
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300284 if (val < 0) {
285 v4l2_err(sd, "%s: failed with error = %d\n", __func__, val);
286 return;
287 }
288
Hans Verkuil5325b422009-04-02 11:26:22 -0300289 if (decoder->input == TVP5150_SVIDEO)
Mauro Carvalho Chehabf4b8b3a2007-11-03 22:40:24 -0300290 val = (val & ~0x40) | 0x10;
291 else
292 val = (val & ~0x10) | 0x40;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300293 tvp5150_write(sd, TVP5150_MISC_CTL, val);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800294};
295
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200296struct i2c_reg_value {
297 unsigned char reg;
298 unsigned char value;
299};
300
301/* Default values as sugested at TVP5150AM1 datasheet */
302static const struct i2c_reg_value tvp5150_init_default[] = {
303 { /* 0x00 */
304 TVP5150_VD_IN_SRC_SEL_1,0x00
305 },
306 { /* 0x01 */
307 TVP5150_ANAL_CHL_CTL,0x15
308 },
309 { /* 0x02 */
310 TVP5150_OP_MODE_CTL,0x00
311 },
312 { /* 0x03 */
313 TVP5150_MISC_CTL,0x01
314 },
315 { /* 0x06 */
316 TVP5150_COLOR_KIL_THSH_CTL,0x10
317 },
318 { /* 0x07 */
319 TVP5150_LUMA_PROC_CTL_1,0x60
320 },
321 { /* 0x08 */
322 TVP5150_LUMA_PROC_CTL_2,0x00
323 },
324 { /* 0x09 */
325 TVP5150_BRIGHT_CTL,0x80
326 },
327 { /* 0x0a */
328 TVP5150_SATURATION_CTL,0x80
329 },
330 { /* 0x0b */
331 TVP5150_HUE_CTL,0x00
332 },
333 { /* 0x0c */
334 TVP5150_CONTRAST_CTL,0x80
335 },
336 { /* 0x0d */
337 TVP5150_DATA_RATE_SEL,0x47
338 },
339 { /* 0x0e */
340 TVP5150_LUMA_PROC_CTL_3,0x00
341 },
342 { /* 0x0f */
343 TVP5150_CONF_SHARED_PIN,0x08
344 },
345 { /* 0x11 */
346 TVP5150_ACT_VD_CROP_ST_MSB,0x00
347 },
348 { /* 0x12 */
349 TVP5150_ACT_VD_CROP_ST_LSB,0x00
350 },
351 { /* 0x13 */
352 TVP5150_ACT_VD_CROP_STP_MSB,0x00
353 },
354 { /* 0x14 */
355 TVP5150_ACT_VD_CROP_STP_LSB,0x00
356 },
357 { /* 0x15 */
358 TVP5150_GENLOCK,0x01
359 },
360 { /* 0x16 */
361 TVP5150_HORIZ_SYNC_START,0x80
362 },
363 { /* 0x18 */
364 TVP5150_VERT_BLANKING_START,0x00
365 },
366 { /* 0x19 */
367 TVP5150_VERT_BLANKING_STOP,0x00
368 },
369 { /* 0x1a */
370 TVP5150_CHROMA_PROC_CTL_1,0x0c
371 },
372 { /* 0x1b */
373 TVP5150_CHROMA_PROC_CTL_2,0x14
374 },
375 { /* 0x1c */
376 TVP5150_INT_RESET_REG_B,0x00
377 },
378 { /* 0x1d */
379 TVP5150_INT_ENABLE_REG_B,0x00
380 },
381 { /* 0x1e */
382 TVP5150_INTT_CONFIG_REG_B,0x00
383 },
384 { /* 0x28 */
385 TVP5150_VIDEO_STD,0x00
386 },
387 { /* 0x2e */
388 TVP5150_MACROVISION_ON_CTR,0x0f
389 },
390 { /* 0x2f */
391 TVP5150_MACROVISION_OFF_CTR,0x01
392 },
393 { /* 0xbb */
394 TVP5150_TELETEXT_FIL_ENA,0x00
395 },
396 { /* 0xc0 */
397 TVP5150_INT_STATUS_REG_A,0x00
398 },
399 { /* 0xc1 */
400 TVP5150_INT_ENABLE_REG_A,0x00
401 },
402 { /* 0xc2 */
403 TVP5150_INT_CONF,0x04
404 },
405 { /* 0xc8 */
406 TVP5150_FIFO_INT_THRESHOLD,0x80
407 },
408 { /* 0xc9 */
409 TVP5150_FIFO_RESET,0x00
410 },
411 { /* 0xca */
412 TVP5150_LINE_NUMBER_INT,0x00
413 },
414 { /* 0xcb */
415 TVP5150_PIX_ALIGN_REG_LOW,0x4e
416 },
417 { /* 0xcc */
418 TVP5150_PIX_ALIGN_REG_HIGH,0x00
419 },
420 { /* 0xcd */
421 TVP5150_FIFO_OUT_CTRL,0x01
422 },
423 { /* 0xcf */
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200424 TVP5150_FULL_FIELD_ENA,0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200425 },
426 { /* 0xd0 */
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200427 TVP5150_LINE_MODE_INI,0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200428 },
429 { /* 0xfc */
430 TVP5150_FULL_FIELD_MODE_REG,0x7f
431 },
432 { /* end of data */
433 0xff,0xff
434 }
435};
436
437/* Default values as sugested at TVP5150AM1 datasheet */
438static const struct i2c_reg_value tvp5150_init_enable[] = {
439 {
440 TVP5150_CONF_SHARED_PIN, 2
441 },{ /* Automatic offset and AGC enabled */
442 TVP5150_ANAL_CHL_CTL, 0x15
443 },{ /* Activate YCrCb output 0x9 or 0xd ? */
444 TVP5150_MISC_CTL, 0x6f
445 },{ /* Activates video std autodetection for all standards */
446 TVP5150_AUTOSW_MSK, 0x0
447 },{ /* Default format: 0x47. For 4:2:2: 0x40 */
448 TVP5150_DATA_RATE_SEL, 0x47
449 },{
450 TVP5150_CHROMA_PROC_CTL_1, 0x0c
451 },{
452 TVP5150_CHROMA_PROC_CTL_2, 0x54
453 },{ /* Non documented, but initialized on WinTV USB2 */
454 0x27, 0x20
455 },{
456 0xff,0xff
457 }
458};
459
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200460struct tvp5150_vbi_type {
461 unsigned int vbi_type;
462 unsigned int ini_line;
463 unsigned int end_line;
464 unsigned int by_field :1;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200465};
466
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200467struct i2c_vbi_ram_value {
468 u16 reg;
469 struct tvp5150_vbi_type type;
470 unsigned char values[16];
471};
472
473/* This struct have the values for each supported VBI Standard
474 * by
475 tvp5150_vbi_types should follow the same order as vbi_ram_default
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200476 * value 0 means rom position 0x10, value 1 means rom position 0x30
477 * and so on. There are 16 possible locations from 0 to 15.
478 */
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200479
Adrian Bunka9cff902006-01-15 06:56:15 -0200480static struct i2c_vbi_ram_value vbi_ram_default[] =
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200481{
Hans Verkuil9bc74002006-03-29 18:02:51 -0300482 /* FIXME: Current api doesn't handle all VBI types, those not
483 yet supported are placed under #if 0 */
484#if 0
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200485 {0x010, /* Teletext, SECAM, WST System A */
486 {V4L2_SLICED_TELETEXT_SECAM,6,23,1},
487 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
488 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200489 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300490#endif
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200491 {0x030, /* Teletext, PAL, WST System B */
Hans Verkuil9bc74002006-03-29 18:02:51 -0300492 {V4L2_SLICED_TELETEXT_B,6,22,1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200493 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
494 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200495 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300496#if 0
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200497 {0x050, /* Teletext, PAL, WST System C */
498 {V4L2_SLICED_TELETEXT_PAL_C,6,22,1},
499 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
500 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200501 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200502 {0x070, /* Teletext, NTSC, WST System B */
503 {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1},
504 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
505 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200506 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200507 {0x090, /* Tetetext, NTSC NABTS System C */
508 {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1},
509 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
510 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200511 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200512 {0x0b0, /* Teletext, NTSC-J, NABTS System D */
513 {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1},
514 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
515 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200516 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200517 {0x0d0, /* Closed Caption, PAL/SECAM */
518 {V4L2_SLICED_CAPTION_625,22,22,1},
519 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
520 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200521 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300522#endif
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200523 {0x0f0, /* Closed Caption, NTSC */
524 {V4L2_SLICED_CAPTION_525,21,21,1},
525 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
526 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200527 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200528 {0x110, /* Wide Screen Signal, PAL/SECAM */
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200529 {V4L2_SLICED_WSS_625,23,23,1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200530 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
531 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200532 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300533#if 0
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200534 {0x130, /* Wide Screen Signal, NTSC C */
535 {V4L2_SLICED_WSS_525,20,20,1},
536 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
537 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200538 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200539 {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
540 {V4l2_SLICED_VITC_625,6,22,0},
541 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
542 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200543 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200544 {0x170, /* Vertical Interval Timecode (VITC), NTSC */
545 {V4l2_SLICED_VITC_525,10,20,0},
546 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
547 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200548 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300549#endif
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200550 {0x190, /* Video Program System (VPS), PAL */
551 {V4L2_SLICED_VPS,16,16,0},
552 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
553 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200554 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200555 /* 0x1d0 User programmable */
556
557 /* End of struct */
558 { (u16)-1 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200559};
560
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300561static int tvp5150_write_inittab(struct v4l2_subdev *sd,
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200562 const struct i2c_reg_value *regs)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200563{
564 while (regs->reg != 0xff) {
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300565 tvp5150_write(sd, regs->reg, regs->value);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200566 regs++;
567 }
568 return 0;
569}
570
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300571static int tvp5150_vdp_init(struct v4l2_subdev *sd,
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200572 const struct i2c_vbi_ram_value *regs)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200573{
574 unsigned int i;
575
576 /* Disable Full Field */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300577 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200578
579 /* Before programming, Line mode should be at 0xff */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300580 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
581 tvp5150_write(sd, i, 0xff);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200582
583 /* Load Ram Table */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300584 while (regs->reg != (u16)-1) {
585 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
586 tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200587
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300588 for (i = 0; i < 16; i++)
589 tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200590
591 regs++;
592 }
593 return 0;
594}
595
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200596/* Fills VBI capabilities based on i2c_vbi_ram_value struct */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300597static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200598 struct v4l2_sliced_vbi_cap *cap)
599{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300600 const struct i2c_vbi_ram_value *regs = vbi_ram_default;
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200601 int line;
602
Hans Verkuilbccfa442009-03-30 06:55:27 -0300603 v4l2_dbg(1, debug, sd, "g_sliced_vbi_cap\n");
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200604 memset(cap, 0, sizeof *cap);
605
606 while (regs->reg != (u16)-1 ) {
607 for (line=regs->type.ini_line;line<=regs->type.end_line;line++) {
608 cap->service_lines[0][line] |= regs->type.vbi_type;
609 }
610 cap->service_set |= regs->type.vbi_type;
611
612 regs++;
613 }
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300614 return 0;
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200615}
616
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200617/* Set vbi processing
618 * type - one of tvp5150_vbi_types
619 * line - line to gather data
620 * fields: bit 0 field1, bit 1, field2
621 * flags (default=0xf0) is a bitmask, were set means:
622 * bit 7: enable filtering null bytes on CC
623 * bit 6: send data also to FIFO
624 * bit 5: don't allow data with errors on FIFO
625 * bit 4: enable ECC when possible
626 * pix_align = pix alignment:
627 * LSB = field1
628 * MSB = field2
629 */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300630static int tvp5150_set_vbi(struct v4l2_subdev *sd,
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200631 const struct i2c_vbi_ram_value *regs,
632 unsigned int type,u8 flags, int line,
633 const int fields)
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200634{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300635 struct tvp5150 *decoder = to_tvp5150(sd);
636 v4l2_std_id std = decoder->norm;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200637 u8 reg;
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200638 int pos=0;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200639
640 if (std == V4L2_STD_ALL) {
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300641 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200642 return 0;
Roel Kluin7d5b7b92008-03-09 21:19:13 -0300643 } else if (std & V4L2_STD_625_50) {
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200644 /* Don't follow NTSC Line number convension */
645 line += 3;
646 }
647
648 if (line<6||line>27)
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200649 return 0;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200650
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200651 while (regs->reg != (u16)-1 ) {
652 if ((type & regs->type.vbi_type) &&
653 (line>=regs->type.ini_line) &&
654 (line<=regs->type.end_line)) {
655 type=regs->type.vbi_type;
656 break;
657 }
658
659 regs++;
660 pos++;
661 }
662 if (regs->reg == (u16)-1)
663 return 0;
664
665 type=pos | (flags & 0xf0);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200666 reg=((line-6)<<1)+TVP5150_LINE_MODE_INI;
667
668 if (fields&1) {
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300669 tvp5150_write(sd, reg, type);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200670 }
671
672 if (fields&2) {
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300673 tvp5150_write(sd, reg+1, type);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200674 }
675
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200676 return type;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200677}
678
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300679static int tvp5150_get_vbi(struct v4l2_subdev *sd,
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200680 const struct i2c_vbi_ram_value *regs, int line)
681{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300682 struct tvp5150 *decoder = to_tvp5150(sd);
683 v4l2_std_id std = decoder->norm;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200684 u8 reg;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300685 int pos, type = 0;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300686 int i, ret = 0;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200687
688 if (std == V4L2_STD_ALL) {
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300689 v4l2_err(sd, "VBI can't be configured without knowing number of lines\n");
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200690 return 0;
Roel Kluin7d5b7b92008-03-09 21:19:13 -0300691 } else if (std & V4L2_STD_625_50) {
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200692 /* Don't follow NTSC Line number convension */
693 line += 3;
694 }
695
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300696 if (line < 6 || line > 27)
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200697 return 0;
698
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300699 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200700
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300701 for (i = 0; i <= 1; i++) {
702 ret = tvp5150_read(sd, reg + i);
703 if (ret < 0) {
704 v4l2_err(sd, "%s: failed with error = %d\n",
705 __func__, ret);
706 return 0;
707 }
708 pos = ret & 0x0f;
709 if (pos < 0x0f)
710 type |= regs[pos].type.vbi_type;
711 }
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200712
713 return type;
714}
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800715
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300716static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
717{
718 struct tvp5150 *decoder = to_tvp5150(sd);
719 int fmt = 0;
720
721 decoder->norm = std;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800722
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200723 /* First tests should be against specific std */
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800724
Hans Verkuil26811ae2013-05-29 10:19:06 -0300725 if (std == V4L2_STD_NTSC_443) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300726 fmt = VIDEO_STD_NTSC_4_43_BIT;
Hans Verkuil26811ae2013-05-29 10:19:06 -0300727 } else if (std == V4L2_STD_PAL_M) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300728 fmt = VIDEO_STD_PAL_M_BIT;
Hans Verkuil26811ae2013-05-29 10:19:06 -0300729 } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300730 fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200731 } else {
732 /* Then, test against generic ones */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300733 if (std & V4L2_STD_NTSC)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300734 fmt = VIDEO_STD_NTSC_MJ_BIT;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300735 else if (std & V4L2_STD_PAL)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300736 fmt = VIDEO_STD_PAL_BDGHIN_BIT;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300737 else if (std & V4L2_STD_SECAM)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300738 fmt = VIDEO_STD_SECAM_BIT;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200739 }
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800740
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300741 v4l2_dbg(1, debug, sd, "Set video std register to %d.\n", fmt);
742 tvp5150_write(sd, TVP5150_VIDEO_STD, fmt);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200743 return 0;
744}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800745
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300746static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200747{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300748 struct tvp5150 *decoder = to_tvp5150(sd);
749
750 if (decoder->norm == std)
751 return 0;
752
Javier Martin963ddc62012-01-31 05:23:46 -0300753 /* Change cropping height limits */
754 if (std & V4L2_STD_525_60)
755 decoder->rect.height = TVP5150_V_MAX_525_60;
756 else
757 decoder->rect.height = TVP5150_V_MAX_OTHERS;
758
759
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300760 return tvp5150_set_std(sd, std);
761}
762
763static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
764{
765 struct tvp5150 *decoder = to_tvp5150(sd);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200766
767 /* Initializes TVP5150 to its default values */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300768 tvp5150_write_inittab(sd, tvp5150_init_default);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200769
770 /* Initializes VDP registers */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300771 tvp5150_vdp_init(sd, vbi_ram_default);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200772
773 /* Selects decoder input */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300774 tvp5150_selmux(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800775
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200776 /* Initializes TVP5150 to stream enabled values */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300777 tvp5150_write_inittab(sd, tvp5150_init_enable);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800778
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200779 /* Initialize image preferences */
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300780 v4l2_ctrl_handler_setup(&decoder->hdl);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200781
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300782 tvp5150_set_std(sd, decoder->norm);
783 return 0;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800784};
785
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300786static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800787{
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300788 struct v4l2_subdev *sd = to_sd(ctrl);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800789
790 switch (ctrl->id) {
791 case V4L2_CID_BRIGHTNESS:
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300792 tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800793 return 0;
794 case V4L2_CID_CONTRAST:
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300795 tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800796 return 0;
797 case V4L2_CID_SATURATION:
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300798 tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800799 return 0;
800 case V4L2_CID_HUE:
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300801 tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800802 return 0;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800803 }
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200804 return -EINVAL;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800805}
806
Javier Martinec2c4f32012-01-05 10:57:39 -0300807static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd)
808{
809 int val = tvp5150_read(sd, TVP5150_STATUS_REG_5);
810
811 switch (val & 0x0F) {
812 case 0x01:
813 return V4L2_STD_NTSC;
814 case 0x03:
815 return V4L2_STD_PAL;
816 case 0x05:
817 return V4L2_STD_PAL_M;
818 case 0x07:
819 return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc;
820 case 0x09:
821 return V4L2_STD_NTSC_443;
822 case 0xb:
823 return V4L2_STD_SECAM;
824 default:
825 return V4L2_STD_UNKNOWN;
826 }
827}
828
829static int tvp5150_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned index,
830 enum v4l2_mbus_pixelcode *code)
831{
832 if (index)
833 return -EINVAL;
834
Javier Martin002eaf92012-03-26 09:17:46 -0300835 *code = V4L2_MBUS_FMT_UYVY8_2X8;
Javier Martinec2c4f32012-01-05 10:57:39 -0300836 return 0;
837}
838
839static int tvp5150_mbus_fmt(struct v4l2_subdev *sd,
840 struct v4l2_mbus_framefmt *f)
841{
842 struct tvp5150 *decoder = to_tvp5150(sd);
Javier Martinec2c4f32012-01-05 10:57:39 -0300843
844 if (f == NULL)
845 return -EINVAL;
846
847 tvp5150_reset(sd, 0);
848
Javier Martin963ddc62012-01-31 05:23:46 -0300849 f->width = decoder->rect.width;
850 f->height = decoder->rect.height;
Javier Martinec2c4f32012-01-05 10:57:39 -0300851
Javier Martin002eaf92012-03-26 09:17:46 -0300852 f->code = V4L2_MBUS_FMT_UYVY8_2X8;
Javier Martinec2c4f32012-01-05 10:57:39 -0300853 f->field = V4L2_FIELD_SEQ_TB;
854 f->colorspace = V4L2_COLORSPACE_SMPTE170M;
855
856 v4l2_dbg(1, debug, sd, "width = %d, height = %d\n", f->width,
857 f->height);
858 return 0;
859}
860
Hans Verkuil4f996592012-09-05 05:10:48 -0300861static int tvp5150_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a)
Javier Martin963ddc62012-01-31 05:23:46 -0300862{
863 struct v4l2_rect rect = a->c;
864 struct tvp5150 *decoder = to_tvp5150(sd);
865 v4l2_std_id std;
Ricardo Ribaldaf90580c2013-11-26 05:31:42 -0300866 unsigned int hmax;
Javier Martin963ddc62012-01-31 05:23:46 -0300867
868 v4l2_dbg(1, debug, sd, "%s left=%d, top=%d, width=%d, height=%d\n",
869 __func__, rect.left, rect.top, rect.width, rect.height);
870
871 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
872 return -EINVAL;
873
874 /* tvp5150 has some special limits */
875 rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT);
Ricardo Ribaldaf90580c2013-11-26 05:31:42 -0300876 rect.width = clamp_t(unsigned int, rect.width,
877 TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
878 TVP5150_H_MAX - rect.left);
Javier Martin963ddc62012-01-31 05:23:46 -0300879 rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
880
881 /* Calculate height based on current standard */
882 if (decoder->norm == V4L2_STD_ALL)
883 std = tvp5150_read_std(sd);
884 else
885 std = decoder->norm;
886
887 if (std & V4L2_STD_525_60)
888 hmax = TVP5150_V_MAX_525_60;
889 else
890 hmax = TVP5150_V_MAX_OTHERS;
891
Ricardo Ribaldaf90580c2013-11-26 05:31:42 -0300892 rect.height = clamp_t(unsigned int, rect.height,
893 hmax - TVP5150_MAX_CROP_TOP - rect.top,
894 hmax - rect.top);
Javier Martin963ddc62012-01-31 05:23:46 -0300895
896 tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top);
897 tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP,
898 rect.top + rect.height - hmax);
899 tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_MSB,
900 rect.left >> TVP5150_CROP_SHIFT);
901 tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_LSB,
902 rect.left | (1 << TVP5150_CROP_SHIFT));
903 tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_MSB,
904 (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >>
905 TVP5150_CROP_SHIFT);
906 tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_LSB,
907 rect.left + rect.width - TVP5150_MAX_CROP_LEFT);
908
909 decoder->rect = rect;
910
911 return 0;
912}
913
914static int tvp5150_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
915{
916 struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd);
917
918 a->c = decoder->rect;
919 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
920
921 return 0;
922}
923
924static int tvp5150_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
925{
926 struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd);
927 v4l2_std_id std;
928
929 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
930 return -EINVAL;
931
932 a->bounds.left = 0;
933 a->bounds.top = 0;
934 a->bounds.width = TVP5150_H_MAX;
935
936 /* Calculate height based on current standard */
937 if (decoder->norm == V4L2_STD_ALL)
938 std = tvp5150_read_std(sd);
939 else
940 std = decoder->norm;
941
942 if (std & V4L2_STD_525_60)
943 a->bounds.height = TVP5150_V_MAX_525_60;
944 else
945 a->bounds.height = TVP5150_V_MAX_OTHERS;
946
947 a->defrect = a->bounds;
948 a->pixelaspect.numerator = 1;
949 a->pixelaspect.denominator = 1;
950
951 return 0;
952}
953
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800954/****************************************************************************
955 I2C Command
956 ****************************************************************************/
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300957
Hans Verkuil5325b422009-04-02 11:26:22 -0300958static int tvp5150_s_routing(struct v4l2_subdev *sd,
959 u32 input, u32 output, u32 config)
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800960{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300961 struct tvp5150 *decoder = to_tvp5150(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800962
Hans Verkuil5325b422009-04-02 11:26:22 -0300963 decoder->input = input;
964 decoder->output = output;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300965 tvp5150_selmux(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800966 return 0;
967}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800968
Hans Verkuild37dad42010-03-14 10:59:16 -0300969static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300970{
Hans Verkuild37dad42010-03-14 10:59:16 -0300971 /* this is for capturing 36 raw vbi lines
972 if there's a way to cut off the beginning 2 vbi lines
973 with the tvp5150 then the vbi line count could be lowered
974 to 17 lines/field again, although I couldn't find a register
975 which could do that cropping */
976 if (fmt->sample_format == V4L2_PIX_FMT_GREY)
977 tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
978 if (fmt->count[0] == 18 && fmt->count[1] == 18) {
979 tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
980 tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
981 }
982 return 0;
983}
984
985static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
986{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300987 int i;
988
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300989 if (svbi->service_set != 0) {
990 for (i = 0; i <= 23; i++) {
991 svbi->service_lines[1][i] = 0;
992 svbi->service_lines[0][i] =
993 tvp5150_set_vbi(sd, vbi_ram_default,
994 svbi->service_lines[0][i], 0xf0, i, 3);
995 }
996 /* Enables FIFO */
997 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1);
998 } else {
999 /* Disables FIFO*/
1000 tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0);
1001
1002 /* Disable Full Field */
1003 tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0);
1004
1005 /* Disable Line modes */
1006 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
1007 tvp5150_write(sd, i, 0xff);
1008 }
1009 return 0;
1010}
1011
Hans Verkuild37dad42010-03-14 10:59:16 -03001012static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
1013{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001014 int i, mask = 0;
1015
Hans Verkuil30634e82012-09-05 10:38:10 -03001016 memset(svbi->service_lines, 0, sizeof(svbi->service_lines));
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001017
1018 for (i = 0; i <= 23; i++) {
1019 svbi->service_lines[0][i] =
1020 tvp5150_get_vbi(sd, vbi_ram_default, i);
1021 mask |= svbi->service_lines[0][i];
1022 }
1023 svbi->service_set = mask;
1024 return 0;
1025}
1026
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001027#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001028static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001029{
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001030 int res;
1031
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001032 res = tvp5150_read(sd, reg->reg & 0xff);
1033 if (res < 0) {
1034 v4l2_err(sd, "%s: failed with error = %d\n", __func__, res);
1035 return res;
1036 }
1037
1038 reg->val = res;
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001039 reg->size = 1;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001040 return 0;
1041}
1042
Hans Verkuil977ba3b2013-03-24 08:28:46 -03001043static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001044{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001045 tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff);
1046 return 0;
1047}
1048#endif
1049
1050static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1051{
1052 int status = tvp5150_read(sd, 0x88);
1053
1054 vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
1055 return 0;
1056}
1057
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001058/* ----------------------------------------------------------------------- */
1059
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001060static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
1061 .s_ctrl = tvp5150_s_ctrl,
1062};
1063
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001064static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1065 .log_status = tvp5150_log_status,
Hans Verkuilf41737e2009-04-01 03:52:39 -03001066 .s_std = tvp5150_s_std,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001067 .reset = tvp5150_reset,
1068#ifdef CONFIG_VIDEO_ADV_DEBUG
1069 .g_register = tvp5150_g_register,
1070 .s_register = tvp5150_s_register,
1071#endif
1072};
1073
1074static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001075 .g_tuner = tvp5150_g_tuner,
1076};
1077
1078static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
1079 .s_routing = tvp5150_s_routing,
Javier Martinec2c4f32012-01-05 10:57:39 -03001080 .enum_mbus_fmt = tvp5150_enum_mbus_fmt,
1081 .s_mbus_fmt = tvp5150_mbus_fmt,
1082 .try_mbus_fmt = tvp5150_mbus_fmt,
Javier Martin0f67a032012-01-31 05:23:47 -03001083 .g_mbus_fmt = tvp5150_mbus_fmt,
Javier Martin963ddc62012-01-31 05:23:46 -03001084 .s_crop = tvp5150_s_crop,
1085 .g_crop = tvp5150_g_crop,
1086 .cropcap = tvp5150_cropcap,
Hans Verkuil32cd5272010-03-14 09:57:30 -03001087};
1088
1089static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001090 .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
Hans Verkuild37dad42010-03-14 10:59:16 -03001091 .g_sliced_fmt = tvp5150_g_sliced_fmt,
1092 .s_sliced_fmt = tvp5150_s_sliced_fmt,
1093 .s_raw_fmt = tvp5150_s_raw_fmt,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001094};
1095
1096static const struct v4l2_subdev_ops tvp5150_ops = {
1097 .core = &tvp5150_core_ops,
1098 .tuner = &tvp5150_tuner_ops,
1099 .video = &tvp5150_video_ops,
Hans Verkuil32cd5272010-03-14 09:57:30 -03001100 .vbi = &tvp5150_vbi_ops,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001101};
1102
1103
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001104/****************************************************************************
1105 I2C Client & Driver
1106 ****************************************************************************/
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001107
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001108static int tvp5150_probe(struct i2c_client *c,
1109 const struct i2c_device_id *id)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001110{
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001111 struct tvp5150 *core;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001112 struct v4l2_subdev *sd;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001113 int tvp5150_id[4];
1114 int i, res;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001115
1116 /* Check if the adapter supports the needed features */
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001117 if (!i2c_check_functionality(c->adapter,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001118 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001119 return -EIO;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001120
Laurent Pinchartc02b2112013-05-02 08:29:43 -03001121 core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
1122 if (!core)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001123 return -ENOMEM;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001124 sd = &core->sd;
1125 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001126
1127 /*
1128 * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
1129 * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
1130 */
1131 for (i = 0; i < 4; i++) {
1132 res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i);
1133 if (res < 0)
Laurent Pinchartc02b2112013-05-02 08:29:43 -03001134 return res;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001135 tvp5150_id[i] = res;
1136 }
1137
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001138 v4l_info(c, "chip found @ 0x%02x (%s)\n",
1139 c->addr << 1, c->adapter->name);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001140
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001141 if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */
1142 v4l2_info(sd, "tvp%02x%02xam1 detected.\n",
1143 tvp5150_id[0], tvp5150_id[1]);
Mauro Carvalho Chehab0e09a3c2011-02-22 00:10:22 -03001144
1145 /* ITU-T BT.656.4 timing */
1146 tvp5150_write(sd, TVP5150_REV_SELECT, 0);
1147 } else {
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001148 /* Is TVP5150A */
1149 if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) {
1150 v4l2_info(sd, "tvp%02x%02xa detected.\n",
1151 tvp5150_id[2], tvp5150_id[3]);
Mauro Carvalho Chehab0e09a3c2011-02-22 00:10:22 -03001152 } else {
1153 v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001154 tvp5150_id[2], tvp5150_id[3]);
1155 v4l2_info(sd, "*** Rom ver is %d.%d\n",
1156 tvp5150_id[2], tvp5150_id[3]);
Mauro Carvalho Chehab0e09a3c2011-02-22 00:10:22 -03001157 }
1158 }
1159
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -02001160 core->norm = V4L2_STD_ALL; /* Default is autodetect */
Hans Verkuil5325b422009-04-02 11:26:22 -03001161 core->input = TVP5150_COMPOSITE1;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001162 core->enable = 1;
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001163
1164 v4l2_ctrl_handler_init(&core->hdl, 4);
1165 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1166 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1167 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1168 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1169 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1170 V4L2_CID_SATURATION, 0, 255, 1, 128);
1171 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1172 V4L2_CID_HUE, -128, 127, 1, 0);
1173 sd->ctrl_handler = &core->hdl;
1174 if (core->hdl.error) {
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001175 res = core->hdl.error;
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001176 v4l2_ctrl_handler_free(&core->hdl);
Laurent Pinchartc02b2112013-05-02 08:29:43 -03001177 return res;
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001178 }
1179 v4l2_ctrl_handler_setup(&core->hdl);
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001180
Javier Martin963ddc62012-01-31 05:23:46 -03001181 /* Default is no cropping */
1182 core->rect.top = 0;
1183 if (tvp5150_read_std(sd) & V4L2_STD_525_60)
1184 core->rect.height = TVP5150_V_MAX_525_60;
1185 else
1186 core->rect.height = TVP5150_V_MAX_OTHERS;
1187 core->rect.left = 0;
1188 core->rect.width = TVP5150_H_MAX;
1189
Markus Rechbergerf1e5ee42006-02-07 04:01:19 +01001190 if (debug > 1)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001191 tvp5150_log_status(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001192 return 0;
1193}
1194
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001195static int tvp5150_remove(struct i2c_client *c)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001196{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001197 struct v4l2_subdev *sd = i2c_get_clientdata(c);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001198 struct tvp5150 *decoder = to_tvp5150(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001199
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001200 v4l2_dbg(1, debug, sd,
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001201 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1202 c->addr << 1);
1203
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001204 v4l2_device_unregister_subdev(sd);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001205 v4l2_ctrl_handler_free(&decoder->hdl);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001206 return 0;
1207}
1208
1209/* ----------------------------------------------------------------------- */
1210
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001211static const struct i2c_device_id tvp5150_id[] = {
1212 { "tvp5150", 0 },
1213 { }
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001214};
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001215MODULE_DEVICE_TABLE(i2c, tvp5150_id);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001216
Hans Verkuilc7711452010-09-15 15:45:20 -03001217static struct i2c_driver tvp5150_driver = {
1218 .driver = {
1219 .owner = THIS_MODULE,
1220 .name = "tvp5150",
1221 },
1222 .probe = tvp5150_probe,
1223 .remove = tvp5150_remove,
1224 .id_table = tvp5150_id,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001225};
Hans Verkuilc7711452010-09-15 15:45:20 -03001226
Axel Linc6e8d862012-02-12 06:56:32 -03001227module_i2c_driver(tvp5150_driver);