blob: 82ecbbfd45f37e0bce0c1dabbaffa5dbd67836a7 [file] [log] [blame]
Mauro Carvalho Chehab459ee172017-12-01 08:47:12 -05001// SPDX-License-Identifier: GPL-2.0
2//
3// tvp5150 - Texas Instruments TVP5150A/AM1 and TVP5151 video decoder driver
4//
Mauro Carvalho Chehab32590812018-04-25 05:34:48 -04005// Copyright (c) 2005,2006 Mauro Carvalho Chehab <mchehab@kernel.org>
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08006
Javier Martinez Canillasb802fb92016-02-05 17:09:56 -02007#include <dt-bindings/media/tvp5150.h>
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>
Javier Martinez Canillas09aa2602016-01-07 10:46:49 -020012#include <linux/gpio/consumer.h>
Paul Gortmaker7a707b82011-07-03 14:03:12 -040013#include <linux/module.h>
Sakari Ailus859969b2016-08-26 20:17:25 -030014#include <linux/of_graph.h>
Philipp Zabel28b9e222018-06-28 12:20:35 -040015#include <linux/regmap.h>
Javier Martinez Canillasc7d97492015-09-21 08:23:09 -030016#include <media/v4l2-async.h>
Hans Verkuil6b8fe022008-12-18 11:17:25 -030017#include <media/v4l2-device.h>
Hans Verkuil6c45ec72010-12-12 08:45:43 -030018#include <media/v4l2-ctrls.h>
Sakari Ailus859969b2016-08-26 20:17:25 -030019#include <media/v4l2-fwnode.h>
Mauro Carvalho Chehab55606312016-01-27 12:08:13 -020020#include <media/v4l2-mc.h>
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080021
22#include "tvp5150_reg.h"
23
Philipp Zabel785a3de2014-02-27 13:44:47 -030024#define TVP5150_H_MAX 720U
25#define TVP5150_V_MAX_525_60 480U
26#define TVP5150_V_MAX_OTHERS 576U
Javier Martin963ddc62012-01-31 05:23:46 -030027#define TVP5150_MAX_CROP_LEFT 511
28#define TVP5150_MAX_CROP_TOP 127
29#define TVP5150_CROP_SHIFT 2
Marco Felsch5cb82942018-06-28 12:20:39 -040030#define TVP5150_MBUS_FMT MEDIA_BUS_FMT_UYVY8_2X8
31#define TVP5150_FIELD V4L2_FIELD_ALTERNATE
32#define TVP5150_COLORSPACE V4L2_COLORSPACE_SMPTE170M
Javier Martin963ddc62012-01-31 05:23:46 -030033
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -020034MODULE_DESCRIPTION("Texas Instruments TVP5150A/TVP5150AM1/TVP5151 video decoder driver");
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080035MODULE_AUTHOR("Mauro Carvalho Chehab");
Mauro Carvalho Chehab459ee172017-12-01 08:47:12 -050036MODULE_LICENSE("GPL v2");
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080037
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080038
Douglas Schilling Landgrafff699e62008-04-22 14:41:48 -030039static int debug;
Philipp Zabel2a0489d2014-02-27 13:44:48 -030040module_param(debug, int, 0644);
Hans Verkuil6b8fe022008-12-18 11:17:25 -030041MODULE_PARM_DESC(debug, "Debug level (0-2)");
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080042
Mauro Carvalho Chehabad0e3742016-11-13 05:34:12 -020043#define dprintk0(__dev, __arg...) dev_dbg_lvl(__dev, 0, 0, __arg)
44
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -040045enum tvp5150_pads {
46 TVP5150_PAD_IF_INPUT,
47 TVP5150_PAD_VID_OUT,
48 TVP5150_NUM_PADS
49};
50
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080051struct tvp5150 {
Hans Verkuil6b8fe022008-12-18 11:17:25 -030052 struct v4l2_subdev sd;
Mauro Carvalho Chehab55606312016-01-27 12:08:13 -020053#ifdef CONFIG_MEDIA_CONTROLLER
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -040054 struct media_pad pads[TVP5150_NUM_PADS];
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -020055 struct media_entity input_ent[TVP5150_INPUT_NUM];
56 struct media_pad input_pad[TVP5150_INPUT_NUM];
Mauro Carvalho Chehab55606312016-01-27 12:08:13 -020057#endif
Hans Verkuil6c45ec72010-12-12 08:45:43 -030058 struct v4l2_ctrl_handler hdl;
Javier Martin963ddc62012-01-31 05:23:46 -030059 struct v4l2_rect rect;
Philipp Zabel28b9e222018-06-28 12:20:35 -040060 struct regmap *regmap;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080061
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -020062 v4l2_std_id norm; /* Current set standard */
Philipp Zabelb440b732018-06-28 12:20:40 -040063 v4l2_std_id detected_norm;
Hans Verkuil5325b422009-04-02 11:26:22 -030064 u32 input;
65 u32 output;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080066 int enable;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -020067
Javier Martinez Canillas82275132016-02-05 17:09:54 -020068 u16 dev_id;
69 u16 rom_ver;
70
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -020071 enum v4l2_mbus_type mbus_type;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080072};
73
Hans Verkuil6b8fe022008-12-18 11:17:25 -030074static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080075{
Hans Verkuil6b8fe022008-12-18 11:17:25 -030076 return container_of(sd, struct tvp5150, sd);
77}
78
Hans Verkuil6c45ec72010-12-12 08:45:43 -030079static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
80{
81 return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
82}
83
Hans Verkuil6b8fe022008-12-18 11:17:25 -030084static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
85{
Philipp Zabel28b9e222018-06-28 12:20:35 -040086 struct tvp5150 *decoder = to_tvp5150(sd);
87 int ret, val;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080088
Philipp Zabel28b9e222018-06-28 12:20:35 -040089 ret = regmap_read(decoder->regmap, addr, &val);
90 if (ret < 0)
91 return ret;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -020092
Philipp Zabel28b9e222018-06-28 12:20:35 -040093 return val;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080094}
95
Hans Verkuil6b8fe022008-12-18 11:17:25 -030096static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init,
97 const u8 end, int max_line)
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -020098{
Mauro Carvalho Chehabe5134112016-10-20 11:36:42 -020099 u8 buf[16];
100 int i = 0, j, len;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200101
Mauro Carvalho Chehabe5134112016-10-20 11:36:42 -0200102 if (max_line > 16) {
103 dprintk0(sd->dev, "too much data to dump\n");
104 return;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200105 }
Mauro Carvalho Chehabe5134112016-10-20 11:36:42 -0200106
107 for (i = init; i < end; i += max_line) {
108 len = (end - i > max_line) ? max_line : end - i;
109
110 for (j = 0; j < len; j++)
111 buf[j] = tvp5150_read(sd, i + j);
112
113 dprintk0(sd->dev, "%s reg %02x = %*ph\n", s, i, len, buf);
114 }
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200115}
116
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300117static int tvp5150_log_status(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800118{
Mauro Carvalho Chehabad0e3742016-11-13 05:34:12 -0200119 dprintk0(sd->dev, "tvp5150: Video input source selection #1 = 0x%02x\n",
120 tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1));
121 dprintk0(sd->dev, "tvp5150: Analog channel controls = 0x%02x\n",
122 tvp5150_read(sd, TVP5150_ANAL_CHL_CTL));
123 dprintk0(sd->dev, "tvp5150: Operation mode controls = 0x%02x\n",
124 tvp5150_read(sd, TVP5150_OP_MODE_CTL));
125 dprintk0(sd->dev, "tvp5150: Miscellaneous controls = 0x%02x\n",
126 tvp5150_read(sd, TVP5150_MISC_CTL));
127 dprintk0(sd->dev, "tvp5150: Autoswitch mask= 0x%02x\n",
128 tvp5150_read(sd, TVP5150_AUTOSW_MSK));
129 dprintk0(sd->dev, "tvp5150: Color killer threshold control = 0x%02x\n",
130 tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL));
131 dprintk0(sd->dev, "tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n",
132 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1),
133 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2),
134 tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3));
135 dprintk0(sd->dev, "tvp5150: Brightness control = 0x%02x\n",
136 tvp5150_read(sd, TVP5150_BRIGHT_CTL));
137 dprintk0(sd->dev, "tvp5150: Color saturation control = 0x%02x\n",
138 tvp5150_read(sd, TVP5150_SATURATION_CTL));
139 dprintk0(sd->dev, "tvp5150: Hue control = 0x%02x\n",
140 tvp5150_read(sd, TVP5150_HUE_CTL));
141 dprintk0(sd->dev, "tvp5150: Contrast control = 0x%02x\n",
142 tvp5150_read(sd, TVP5150_CONTRAST_CTL));
143 dprintk0(sd->dev, "tvp5150: Outputs and data rates select = 0x%02x\n",
144 tvp5150_read(sd, TVP5150_DATA_RATE_SEL));
145 dprintk0(sd->dev, "tvp5150: Configuration shared pins = 0x%02x\n",
146 tvp5150_read(sd, TVP5150_CONF_SHARED_PIN));
147 dprintk0(sd->dev, "tvp5150: Active video cropping start = 0x%02x%02x\n",
148 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB),
149 tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB));
150 dprintk0(sd->dev, "tvp5150: Active video cropping stop = 0x%02x%02x\n",
151 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB),
152 tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB));
153 dprintk0(sd->dev, "tvp5150: Genlock/RTC = 0x%02x\n",
154 tvp5150_read(sd, TVP5150_GENLOCK));
155 dprintk0(sd->dev, "tvp5150: Horizontal sync start = 0x%02x\n",
156 tvp5150_read(sd, TVP5150_HORIZ_SYNC_START));
157 dprintk0(sd->dev, "tvp5150: Vertical blanking start = 0x%02x\n",
158 tvp5150_read(sd, TVP5150_VERT_BLANKING_START));
159 dprintk0(sd->dev, "tvp5150: Vertical blanking stop = 0x%02x\n",
160 tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP));
161 dprintk0(sd->dev, "tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n",
162 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1),
163 tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2));
164 dprintk0(sd->dev, "tvp5150: Interrupt reset register B = 0x%02x\n",
165 tvp5150_read(sd, TVP5150_INT_RESET_REG_B));
166 dprintk0(sd->dev, "tvp5150: Interrupt enable register B = 0x%02x\n",
167 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B));
168 dprintk0(sd->dev, "tvp5150: Interrupt configuration register B = 0x%02x\n",
169 tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B));
170 dprintk0(sd->dev, "tvp5150: Video standard = 0x%02x\n",
171 tvp5150_read(sd, TVP5150_VIDEO_STD));
172 dprintk0(sd->dev, "tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n",
173 tvp5150_read(sd, TVP5150_CB_GAIN_FACT),
174 tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR));
175 dprintk0(sd->dev, "tvp5150: Macrovision on counter = 0x%02x\n",
176 tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR));
177 dprintk0(sd->dev, "tvp5150: Macrovision off counter = 0x%02x\n",
178 tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR));
179 dprintk0(sd->dev, "tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n",
180 (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4);
181 dprintk0(sd->dev, "tvp5150: Device ID = %02x%02x\n",
182 tvp5150_read(sd, TVP5150_MSB_DEV_ID),
183 tvp5150_read(sd, TVP5150_LSB_DEV_ID));
184 dprintk0(sd->dev, "tvp5150: ROM version = (hex) %02x.%02x\n",
185 tvp5150_read(sd, TVP5150_ROM_MAJOR_VER),
186 tvp5150_read(sd, TVP5150_ROM_MINOR_VER));
187 dprintk0(sd->dev, "tvp5150: Vertical line count = 0x%02x%02x\n",
188 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB),
189 tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB));
190 dprintk0(sd->dev, "tvp5150: Interrupt status register B = 0x%02x\n",
191 tvp5150_read(sd, TVP5150_INT_STATUS_REG_B));
192 dprintk0(sd->dev, "tvp5150: Interrupt active register B = 0x%02x\n",
193 tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B));
194 dprintk0(sd->dev, "tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n",
195 tvp5150_read(sd, TVP5150_STATUS_REG_1),
196 tvp5150_read(sd, TVP5150_STATUS_REG_2),
197 tvp5150_read(sd, TVP5150_STATUS_REG_3),
198 tvp5150_read(sd, TVP5150_STATUS_REG_4),
199 tvp5150_read(sd, TVP5150_STATUS_REG_5));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200200
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300201 dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI,
202 TVP5150_TELETEXT_FIL1_END, 8);
203 dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI,
204 TVP5150_TELETEXT_FIL2_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200205
Mauro Carvalho Chehabad0e3742016-11-13 05:34:12 -0200206 dprintk0(sd->dev, "tvp5150: Teletext filter enable = 0x%02x\n",
207 tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA));
208 dprintk0(sd->dev, "tvp5150: Interrupt status register A = 0x%02x\n",
209 tvp5150_read(sd, TVP5150_INT_STATUS_REG_A));
210 dprintk0(sd->dev, "tvp5150: Interrupt enable register A = 0x%02x\n",
211 tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A));
212 dprintk0(sd->dev, "tvp5150: Interrupt configuration = 0x%02x\n",
213 tvp5150_read(sd, TVP5150_INT_CONF));
214 dprintk0(sd->dev, "tvp5150: VDP status register = 0x%02x\n",
215 tvp5150_read(sd, TVP5150_VDP_STATUS_REG));
216 dprintk0(sd->dev, "tvp5150: FIFO word count = 0x%02x\n",
217 tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT));
218 dprintk0(sd->dev, "tvp5150: FIFO interrupt threshold = 0x%02x\n",
219 tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD));
220 dprintk0(sd->dev, "tvp5150: FIFO reset = 0x%02x\n",
221 tvp5150_read(sd, TVP5150_FIFO_RESET));
222 dprintk0(sd->dev, "tvp5150: Line number interrupt = 0x%02x\n",
223 tvp5150_read(sd, TVP5150_LINE_NUMBER_INT));
224 dprintk0(sd->dev, "tvp5150: Pixel alignment register = 0x%02x%02x\n",
225 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH),
226 tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW));
227 dprintk0(sd->dev, "tvp5150: FIFO output control = 0x%02x\n",
228 tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL));
229 dprintk0(sd->dev, "tvp5150: Full field enable = 0x%02x\n",
230 tvp5150_read(sd, TVP5150_FULL_FIELD_ENA));
231 dprintk0(sd->dev, "tvp5150: Full field mode register = 0x%02x\n",
232 tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG));
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200233
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300234 dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI,
235 TVP5150_CC_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200236
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300237 dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI,
238 TVP5150_WSS_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200239
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300240 dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI,
241 TVP5150_VPS_DATA_END, 8);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200242
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300243 dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI,
244 TVP5150_VITC_DATA_END, 10);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200245
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300246 dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI,
247 TVP5150_LINE_MODE_END, 8);
248 return 0;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800249}
250
251/****************************************************************************
252 Basic functions
253 ****************************************************************************/
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800254
Laurent Pinchart6e98bee2016-12-08 20:22:42 -0200255static void tvp5150_selmux(struct v4l2_subdev *sd)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800256{
Paul Walmsley2962fc02010-10-09 01:31:40 -0300257 int opmode = 0;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300258 struct tvp5150 *decoder = to_tvp5150(sd);
Marco Felsch8a7441b2018-06-28 12:20:36 -0400259 unsigned int mask, val;
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300260 int input = 0;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800261
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -0200262 /* Only tvp5150am1 and tvp5151 have signal generator support */
263 if ((decoder->dev_id == 0x5150 && decoder->rom_ver == 0x0400) ||
264 (decoder->dev_id == 0x5151 && decoder->rom_ver == 0x0100)) {
265 if (!decoder->enable)
266 input = 8;
267 }
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800268
Hans Verkuil5325b422009-04-02 11:26:22 -0300269 switch (decoder->input) {
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300270 case TVP5150_COMPOSITE1:
271 input |= 2;
272 /* fall through */
273 case TVP5150_COMPOSITE0:
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200274 break;
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300275 case TVP5150_SVIDEO:
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200276 default:
Hans Verkuilc7c0b342006-04-02 13:35:00 -0300277 input |= 1;
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200278 break;
279 }
280
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200281 dev_dbg_lvl(sd->dev, 1, debug, "Selecting video route: route input=%i, output=%i => tvp5150 input=%i, opmode=%i\n",
Hans Verkuil5325b422009-04-02 11:26:22 -0300282 decoder->input, decoder->output,
283 input, opmode);
Mauro Carvalho Chehab12500f02006-08-18 07:31:10 -0300284
Philipp Zabel28b9e222018-06-28 12:20:35 -0400285 regmap_write(decoder->regmap, TVP5150_OP_MODE_CTL, opmode);
286 regmap_write(decoder->regmap, TVP5150_VD_IN_SRC_SEL_1, input);
Mauro Carvalho Chehabf4b8b3a2007-11-03 22:40:24 -0300287
Laurent Pinchartb4b2de32016-12-09 09:47:18 -0200288 /*
289 * Setup the FID/GLCO/VLK/HVLK and INTREQ/GPCL/VBLK output signals. For
290 * S-Video we output the vertical lock (VLK) signal on FID/GLCO/VLK/HVLK
291 * and set INTREQ/GPCL/VBLK to logic 0. For composite we output the
292 * field indicator (FID) signal on FID/GLCO/VLK/HVLK and set
293 * INTREQ/GPCL/VBLK to logic 1.
Mauro Carvalho Chehabf4b8b3a2007-11-03 22:40:24 -0300294 */
Marco Felsch8a7441b2018-06-28 12:20:36 -0400295 mask = TVP5150_MISC_CTL_GPCL | TVP5150_MISC_CTL_HVLK;
Hans Verkuil5325b422009-04-02 11:26:22 -0300296 if (decoder->input == TVP5150_SVIDEO)
Marco Felsch8a7441b2018-06-28 12:20:36 -0400297 val = TVP5150_MISC_CTL_HVLK;
Mauro Carvalho Chehabf4b8b3a2007-11-03 22:40:24 -0300298 else
Marco Felsch8a7441b2018-06-28 12:20:36 -0400299 val = TVP5150_MISC_CTL_GPCL;
300 regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800301};
302
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200303struct i2c_reg_value {
304 unsigned char reg;
305 unsigned char value;
306};
307
308/* Default values as sugested at TVP5150AM1 datasheet */
309static const struct i2c_reg_value tvp5150_init_default[] = {
310 { /* 0x00 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400311 TVP5150_VD_IN_SRC_SEL_1, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200312 },
313 { /* 0x01 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400314 TVP5150_ANAL_CHL_CTL, 0x15
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200315 },
316 { /* 0x02 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400317 TVP5150_OP_MODE_CTL, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200318 },
319 { /* 0x03 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400320 TVP5150_MISC_CTL, 0x01
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200321 },
322 { /* 0x06 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400323 TVP5150_COLOR_KIL_THSH_CTL, 0x10
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200324 },
325 { /* 0x07 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400326 TVP5150_LUMA_PROC_CTL_1, 0x60
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200327 },
328 { /* 0x08 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400329 TVP5150_LUMA_PROC_CTL_2, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200330 },
331 { /* 0x09 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400332 TVP5150_BRIGHT_CTL, 0x80
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200333 },
334 { /* 0x0a */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400335 TVP5150_SATURATION_CTL, 0x80
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200336 },
337 { /* 0x0b */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400338 TVP5150_HUE_CTL, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200339 },
340 { /* 0x0c */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400341 TVP5150_CONTRAST_CTL, 0x80
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200342 },
343 { /* 0x0d */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400344 TVP5150_DATA_RATE_SEL, 0x47
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200345 },
346 { /* 0x0e */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400347 TVP5150_LUMA_PROC_CTL_3, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200348 },
349 { /* 0x0f */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400350 TVP5150_CONF_SHARED_PIN, 0x08
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200351 },
352 { /* 0x11 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400353 TVP5150_ACT_VD_CROP_ST_MSB, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200354 },
355 { /* 0x12 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400356 TVP5150_ACT_VD_CROP_ST_LSB, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200357 },
358 { /* 0x13 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400359 TVP5150_ACT_VD_CROP_STP_MSB, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200360 },
361 { /* 0x14 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400362 TVP5150_ACT_VD_CROP_STP_LSB, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200363 },
364 { /* 0x15 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400365 TVP5150_GENLOCK, 0x01
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200366 },
367 { /* 0x16 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400368 TVP5150_HORIZ_SYNC_START, 0x80
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200369 },
370 { /* 0x18 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400371 TVP5150_VERT_BLANKING_START, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200372 },
373 { /* 0x19 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400374 TVP5150_VERT_BLANKING_STOP, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200375 },
376 { /* 0x1a */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400377 TVP5150_CHROMA_PROC_CTL_1, 0x0c
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200378 },
379 { /* 0x1b */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400380 TVP5150_CHROMA_PROC_CTL_2, 0x14
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200381 },
382 { /* 0x1c */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400383 TVP5150_INT_RESET_REG_B, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200384 },
385 { /* 0x1d */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400386 TVP5150_INT_ENABLE_REG_B, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200387 },
388 { /* 0x1e */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400389 TVP5150_INTT_CONFIG_REG_B, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200390 },
391 { /* 0x28 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400392 TVP5150_VIDEO_STD, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200393 },
394 { /* 0x2e */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400395 TVP5150_MACROVISION_ON_CTR, 0x0f
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200396 },
397 { /* 0x2f */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400398 TVP5150_MACROVISION_OFF_CTR, 0x01
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200399 },
400 { /* 0xbb */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400401 TVP5150_TELETEXT_FIL_ENA, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200402 },
403 { /* 0xc0 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400404 TVP5150_INT_STATUS_REG_A, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200405 },
406 { /* 0xc1 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400407 TVP5150_INT_ENABLE_REG_A, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200408 },
409 { /* 0xc2 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400410 TVP5150_INT_CONF, 0x04
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200411 },
412 { /* 0xc8 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400413 TVP5150_FIFO_INT_THRESHOLD, 0x80
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200414 },
415 { /* 0xc9 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400416 TVP5150_FIFO_RESET, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200417 },
418 { /* 0xca */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400419 TVP5150_LINE_NUMBER_INT, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200420 },
421 { /* 0xcb */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400422 TVP5150_PIX_ALIGN_REG_LOW, 0x4e
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200423 },
424 { /* 0xcc */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400425 TVP5150_PIX_ALIGN_REG_HIGH, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200426 },
427 { /* 0xcd */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400428 TVP5150_FIFO_OUT_CTRL, 0x01
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200429 },
430 { /* 0xcf */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400431 TVP5150_FULL_FIELD_ENA, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200432 },
433 { /* 0xd0 */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400434 TVP5150_LINE_MODE_INI, 0x00
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200435 },
436 { /* 0xfc */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400437 TVP5150_FULL_FIELD_MODE_REG, 0x7f
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200438 },
439 { /* end of data */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400440 0xff, 0xff
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200441 }
442};
443
444/* Default values as sugested at TVP5150AM1 datasheet */
445static const struct i2c_reg_value tvp5150_init_enable[] = {
446 {
447 TVP5150_CONF_SHARED_PIN, 2
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400448 }, { /* Automatic offset and AGC enabled */
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200449 TVP5150_ANAL_CHL_CTL, 0x15
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400450 }, { /* Activate YCrCb output 0x9 or 0xd ? */
Laurent Pinchartb4b2de32016-12-09 09:47:18 -0200451 TVP5150_MISC_CTL, TVP5150_MISC_CTL_GPCL |
452 TVP5150_MISC_CTL_INTREQ_OE |
453 TVP5150_MISC_CTL_YCBCR_OE |
454 TVP5150_MISC_CTL_SYNC_OE |
455 TVP5150_MISC_CTL_VBLANK |
456 TVP5150_MISC_CTL_CLOCK_OE,
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400457 }, { /* Activates video std autodetection for all standards */
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200458 TVP5150_AUTOSW_MSK, 0x0
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400459 }, { /* Default format: 0x47. For 4:2:2: 0x40 */
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200460 TVP5150_DATA_RATE_SEL, 0x47
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400461 }, {
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200462 TVP5150_CHROMA_PROC_CTL_1, 0x0c
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400463 }, {
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200464 TVP5150_CHROMA_PROC_CTL_2, 0x54
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400465 }, { /* Non documented, but initialized on WinTV USB2 */
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200466 0x27, 0x20
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400467 }, {
468 0xff, 0xff
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200469 }
470};
471
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200472struct tvp5150_vbi_type {
473 unsigned int vbi_type;
474 unsigned int ini_line;
475 unsigned int end_line;
476 unsigned int by_field :1;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200477};
478
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200479struct i2c_vbi_ram_value {
480 u16 reg;
481 struct tvp5150_vbi_type type;
482 unsigned char values[16];
483};
484
485/* This struct have the values for each supported VBI Standard
486 * by
487 tvp5150_vbi_types should follow the same order as vbi_ram_default
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200488 * value 0 means rom position 0x10, value 1 means rom position 0x30
489 * and so on. There are 16 possible locations from 0 to 15.
490 */
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200491
Nasser Afshin65dc7602018-04-02 18:23:19 -0400492static struct i2c_vbi_ram_value vbi_ram_default[] = {
493
Nasser Afshin9bfd8f82018-04-02 18:23:18 -0400494 /*
495 * FIXME: Current api doesn't handle all VBI types, those not
496 * yet supported are placed under #if 0
497 */
Hans Verkuil9bc74002006-03-29 18:02:51 -0300498#if 0
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500499 [0] = {0x010, /* Teletext, SECAM, WST System A */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400500 {V4L2_SLICED_TELETEXT_SECAM, 6, 23, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200501 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26,
502 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200503 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300504#endif
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500505 [1] = {0x030, /* Teletext, PAL, WST System B */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400506 {V4L2_SLICED_TELETEXT_B, 6, 22, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200507 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b,
508 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200509 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300510#if 0
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500511 [2] = {0x050, /* Teletext, PAL, WST System C */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400512 {V4L2_SLICED_TELETEXT_PAL_C, 6, 22, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200513 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
514 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200515 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500516 [3] = {0x070, /* Teletext, NTSC, WST System B */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400517 {V4L2_SLICED_TELETEXT_NTSC_B, 10, 21, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200518 { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23,
519 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200520 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500521 [4] = {0x090, /* Tetetext, NTSC NABTS System C */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400522 {V4L2_SLICED_TELETEXT_NTSC_C, 10, 21, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200523 { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22,
524 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200525 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500526 [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400527 {V4L2_SLICED_TELETEXT_NTSC_D, 10, 21, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200528 { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23,
529 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200530 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500531 [6] = {0x0d0, /* Closed Caption, PAL/SECAM */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400532 {V4L2_SLICED_CAPTION_625, 22, 22, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200533 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
534 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200535 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300536#endif
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500537 [7] = {0x0f0, /* Closed Caption, NTSC */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400538 {V4L2_SLICED_CAPTION_525, 21, 21, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200539 { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02,
540 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200541 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500542 [8] = {0x110, /* Wide Screen Signal, PAL/SECAM */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400543 {V4L2_SLICED_WSS_625, 23, 23, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200544 { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42,
545 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200546 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300547#if 0
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500548 [9] = {0x130, /* Wide Screen Signal, NTSC C */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400549 {V4L2_SLICED_WSS_525, 20, 20, 1},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200550 { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43,
551 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200552 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500553 [10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400554 {V4l2_SLICED_VITC_625, 6, 22, 0},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200555 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
556 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200557 },
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500558 [11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400559 {V4l2_SLICED_VITC_525, 10, 20, 0},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200560 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49,
561 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200562 },
Hans Verkuil9bc74002006-03-29 18:02:51 -0300563#endif
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500564 [12] = {0x190, /* Video Program System (VPS), PAL */
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400565 {V4L2_SLICED_VPS, 16, 16, 0},
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200566 { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d,
567 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 }
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200568 },
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200569 /* 0x1d0 User programmable */
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200570};
571
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300572static int tvp5150_write_inittab(struct v4l2_subdev *sd,
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200573 const struct i2c_reg_value *regs)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200574{
Philipp Zabel28b9e222018-06-28 12:20:35 -0400575 struct tvp5150 *decoder = to_tvp5150(sd);
576
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200577 while (regs->reg != 0xff) {
Philipp Zabel28b9e222018-06-28 12:20:35 -0400578 regmap_write(decoder->regmap, regs->reg, regs->value);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200579 regs++;
580 }
581 return 0;
582}
583
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500584static int tvp5150_vdp_init(struct v4l2_subdev *sd)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200585{
Philipp Zabel28b9e222018-06-28 12:20:35 -0400586 struct tvp5150 *decoder = to_tvp5150(sd);
587 struct regmap *map = decoder->regmap;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200588 unsigned int i;
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500589 int j;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200590
591 /* Disable Full Field */
Philipp Zabel28b9e222018-06-28 12:20:35 -0400592 regmap_write(map, TVP5150_FULL_FIELD_ENA, 0);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200593
594 /* Before programming, Line mode should be at 0xff */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300595 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
Philipp Zabel28b9e222018-06-28 12:20:35 -0400596 regmap_write(map, i, 0xff);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200597
598 /* Load Ram Table */
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500599 for (j = 0; j < ARRAY_SIZE(vbi_ram_default); j++) {
600 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[j];
601
602 if (!regs->type.vbi_type)
603 continue;
604
Philipp Zabel28b9e222018-06-28 12:20:35 -0400605 regmap_write(map, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8);
606 regmap_write(map, TVP5150_CONF_RAM_ADDR_LOW, regs->reg);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200607
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300608 for (i = 0; i < 16; i++)
Philipp Zabel28b9e222018-06-28 12:20:35 -0400609 regmap_write(map, TVP5150_VDP_CONF_RAM_DATA,
610 regs->values[i]);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200611 }
612 return 0;
613}
614
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200615/* Fills VBI capabilities based on i2c_vbi_ram_value struct */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300616static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd,
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200617 struct v4l2_sliced_vbi_cap *cap)
618{
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500619 int line, i;
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200620
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200621 dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n");
Nasser Afshinbb7a3682018-04-02 18:23:20 -0400622 memset(cap, 0, sizeof(*cap));
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200623
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500624 for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
625 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
626
627 if (!regs->type.vbi_type)
628 continue;
629
630 for (line = regs->type.ini_line;
631 line <= regs->type.end_line;
632 line++) {
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200633 cap->service_lines[0][line] |= regs->type.vbi_type;
634 }
635 cap->service_set |= regs->type.vbi_type;
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200636 }
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300637 return 0;
Mauro Carvalho Chehab6ac48b42006-01-23 17:11:05 -0200638}
639
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200640/* Set vbi processing
641 * type - one of tvp5150_vbi_types
642 * line - line to gather data
643 * fields: bit 0 field1, bit 1, field2
644 * flags (default=0xf0) is a bitmask, were set means:
645 * bit 7: enable filtering null bytes on CC
646 * bit 6: send data also to FIFO
647 * bit 5: don't allow data with errors on FIFO
648 * bit 4: enable ECC when possible
649 * pix_align = pix alignment:
650 * LSB = field1
651 * MSB = field2
652 */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300653static int tvp5150_set_vbi(struct v4l2_subdev *sd,
Nasser Afshin4efcd5e2018-04-02 18:23:17 -0400654 unsigned int type, u8 flags, int line,
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200655 const int fields)
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200656{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300657 struct tvp5150 *decoder = to_tvp5150(sd);
658 v4l2_std_id std = decoder->norm;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200659 u8 reg;
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500660 int i, pos = 0;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200661
662 if (std == V4L2_STD_ALL) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200663 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200664 return 0;
Roel Kluin7d5b7b92008-03-09 21:19:13 -0300665 } else if (std & V4L2_STD_625_50) {
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200666 /* Don't follow NTSC Line number convension */
667 line += 3;
668 }
669
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300670 if (line < 6 || line > 27)
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200671 return 0;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200672
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500673 for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) {
674 const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i];
675
676 if (!regs->type.vbi_type)
677 continue;
678
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200679 if ((type & regs->type.vbi_type) &&
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300680 (line >= regs->type.ini_line) &&
681 (line <= regs->type.end_line))
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200682 break;
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200683 pos++;
684 }
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300685
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300686 type = pos | (flags & 0xf0);
687 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200688
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300689 if (fields & 1)
Philipp Zabel28b9e222018-06-28 12:20:35 -0400690 regmap_write(decoder->regmap, reg, type);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200691
Gustavo A. R. Silvab3d930aa2017-06-23 19:37:00 -0300692 if (fields & 2)
Philipp Zabel28b9e222018-06-28 12:20:35 -0400693 regmap_write(decoder->regmap, reg + 1, type);
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200694
Mauro Carvalho Chehab2701dac2006-01-23 17:11:06 -0200695 return type;
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -0200696}
697
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500698static int tvp5150_get_vbi(struct v4l2_subdev *sd, int line)
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200699{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300700 struct tvp5150 *decoder = to_tvp5150(sd);
701 v4l2_std_id std = decoder->norm;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200702 u8 reg;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300703 int pos, type = 0;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300704 int i, ret = 0;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200705
706 if (std == V4L2_STD_ALL) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200707 dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n");
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200708 return 0;
Roel Kluin7d5b7b92008-03-09 21:19:13 -0300709 } else if (std & V4L2_STD_625_50) {
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200710 /* Don't follow NTSC Line number convension */
711 line += 3;
712 }
713
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300714 if (line < 6 || line > 27)
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200715 return 0;
716
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300717 reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI;
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200718
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300719 for (i = 0; i <= 1; i++) {
720 ret = tvp5150_read(sd, reg + i);
721 if (ret < 0) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200722 dev_err(sd->dev, "%s: failed with error = %d\n",
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300723 __func__, ret);
724 return 0;
725 }
726 pos = ret & 0x0f;
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500727 if (pos < ARRAY_SIZE(vbi_ram_default))
728 type |= vbi_ram_default[pos].type.vbi_type;
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -0300729 }
Mauro Carvalho Chehab12db5602006-01-23 17:11:08 -0200730
731 return type;
732}
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800733
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300734static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std)
735{
736 struct tvp5150 *decoder = to_tvp5150(sd);
737 int fmt = 0;
738
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200739 /* First tests should be against specific std */
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800740
Hans Verkuil26811ae2013-05-29 10:19:06 -0300741 if (std == V4L2_STD_NTSC_443) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300742 fmt = VIDEO_STD_NTSC_4_43_BIT;
Hans Verkuil26811ae2013-05-29 10:19:06 -0300743 } else if (std == V4L2_STD_PAL_M) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300744 fmt = VIDEO_STD_PAL_M_BIT;
Hans Verkuil26811ae2013-05-29 10:19:06 -0300745 } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) {
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300746 fmt = VIDEO_STD_PAL_COMBINATION_N_BIT;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200747 } else {
748 /* Then, test against generic ones */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300749 if (std & V4L2_STD_NTSC)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300750 fmt = VIDEO_STD_NTSC_MJ_BIT;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300751 else if (std & V4L2_STD_PAL)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300752 fmt = VIDEO_STD_PAL_BDGHIN_BIT;
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300753 else if (std & V4L2_STD_SECAM)
Javier Martinez Canillas2da12fc2011-11-04 13:23:21 -0300754 fmt = VIDEO_STD_SECAM_BIT;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200755 }
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800756
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200757 dev_dbg_lvl(sd->dev, 1, debug, "Set video std register to %d.\n", fmt);
Philipp Zabel28b9e222018-06-28 12:20:35 -0400758 regmap_write(decoder->regmap, TVP5150_VIDEO_STD, fmt);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200759 return 0;
760}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800761
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300762static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200763{
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300764 struct tvp5150 *decoder = to_tvp5150(sd);
765
766 if (decoder->norm == std)
767 return 0;
768
Javier Martin963ddc62012-01-31 05:23:46 -0300769 /* Change cropping height limits */
770 if (std & V4L2_STD_525_60)
771 decoder->rect.height = TVP5150_V_MAX_525_60;
772 else
773 decoder->rect.height = TVP5150_V_MAX_OTHERS;
774
Philipp Zabel15695862018-06-28 12:20:41 -0400775 decoder->norm = std;
Javier Martin963ddc62012-01-31 05:23:46 -0300776
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300777 return tvp5150_set_std(sd, std);
778}
779
Philipp Zabel15695862018-06-28 12:20:41 -0400780static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd)
781{
782 int val = tvp5150_read(sd, TVP5150_STATUS_REG_5);
783
784 switch (val & 0x0F) {
785 case 0x01:
786 return V4L2_STD_NTSC;
787 case 0x03:
788 return V4L2_STD_PAL;
789 case 0x05:
790 return V4L2_STD_PAL_M;
791 case 0x07:
792 return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc;
793 case 0x09:
794 return V4L2_STD_NTSC_443;
795 case 0xb:
796 return V4L2_STD_SECAM;
797 default:
798 return V4L2_STD_UNKNOWN;
799 }
800}
801
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300802static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
803{
804 struct tvp5150 *decoder = to_tvp5150(sd);
Philipp Zabel15695862018-06-28 12:20:41 -0400805 v4l2_std_id std;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200806
807 /* Initializes TVP5150 to its default values */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300808 tvp5150_write_inittab(sd, tvp5150_init_default);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200809
810 /* Initializes VDP registers */
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -0500811 tvp5150_vdp_init(sd);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200812
813 /* Selects decoder input */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300814 tvp5150_selmux(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800815
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200816 /* Initializes TVP5150 to stream enabled values */
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300817 tvp5150_write_inittab(sd, tvp5150_init_enable);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800818
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200819 /* Initialize image preferences */
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300820 v4l2_ctrl_handler_setup(&decoder->hdl);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200821
Philipp Zabel15695862018-06-28 12:20:41 -0400822 if (decoder->norm == V4L2_STD_ALL)
823 std = tvp5150_read_std(sd);
824 else
825 std = decoder->norm;
826
827 /* Disable autoswitch mode */
828 tvp5150_set_std(sd, std);
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -0200829
830 if (decoder->mbus_type == V4L2_MBUS_PARALLEL)
Marco Felsch8a7441b2018-06-28 12:20:36 -0400831 /* 8-bit 4:2:2 YUV with discrete sync output */
832 regmap_update_bits(decoder->regmap, TVP5150_DATA_RATE_SEL,
833 0x7, 0x0);
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -0200834
Hans Verkuil6b8fe022008-12-18 11:17:25 -0300835 return 0;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800836};
837
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300838static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800839{
Hans Verkuil6c45ec72010-12-12 08:45:43 -0300840 struct v4l2_subdev *sd = to_sd(ctrl);
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -0200841 struct tvp5150 *decoder = to_tvp5150(sd);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800842
843 switch (ctrl->id) {
844 case V4L2_CID_BRIGHTNESS:
Philipp Zabel28b9e222018-06-28 12:20:35 -0400845 regmap_write(decoder->regmap, TVP5150_BRIGHT_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800846 return 0;
847 case V4L2_CID_CONTRAST:
Philipp Zabel28b9e222018-06-28 12:20:35 -0400848 regmap_write(decoder->regmap, TVP5150_CONTRAST_CTL, ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800849 return 0;
850 case V4L2_CID_SATURATION:
Philipp Zabel28b9e222018-06-28 12:20:35 -0400851 regmap_write(decoder->regmap, TVP5150_SATURATION_CTL,
852 ctrl->val);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800853 return 0;
854 case V4L2_CID_HUE:
Philipp Zabel28b9e222018-06-28 12:20:35 -0400855 regmap_write(decoder->regmap, TVP5150_HUE_CTL, ctrl->val);
Marco Felsch2d29bcc2018-06-28 12:20:34 -0400856 return 0;
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -0200857 case V4L2_CID_TEST_PATTERN:
858 decoder->enable = ctrl->val ? false : true;
859 tvp5150_selmux(sd);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800860 return 0;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800861 }
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200862 return -EINVAL;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800863}
864
Marco Felsch5cb82942018-06-28 12:20:39 -0400865static void tvp5150_set_default(v4l2_std_id std, struct v4l2_rect *crop)
866{
867 /* Default is no cropping */
868 crop->top = 0;
869 crop->left = 0;
870 crop->width = TVP5150_H_MAX;
871 if (std & V4L2_STD_525_60)
872 crop->height = TVP5150_V_MAX_525_60;
873 else
874 crop->height = TVP5150_V_MAX_OTHERS;
875}
876
Hans Verkuilda298c62015-04-09 04:02:34 -0300877static int tvp5150_fill_fmt(struct v4l2_subdev *sd,
Marco Felsch5cb82942018-06-28 12:20:39 -0400878 struct v4l2_subdev_pad_config *cfg,
879 struct v4l2_subdev_format *format)
Javier Martinec2c4f32012-01-05 10:57:39 -0300880{
Hans Verkuilda298c62015-04-09 04:02:34 -0300881 struct v4l2_mbus_framefmt *f;
Javier Martinec2c4f32012-01-05 10:57:39 -0300882 struct tvp5150 *decoder = to_tvp5150(sd);
Javier Martinec2c4f32012-01-05 10:57:39 -0300883
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -0400884 if (!format || (format->pad != TVP5150_PAD_VID_OUT))
Javier Martinec2c4f32012-01-05 10:57:39 -0300885 return -EINVAL;
886
Hans Verkuilda298c62015-04-09 04:02:34 -0300887 f = &format->format;
888
Javier Martin963ddc62012-01-31 05:23:46 -0300889 f->width = decoder->rect.width;
Javier Martinez Canillas1831af02018-06-10 16:43:02 -0400890 f->height = decoder->rect.height / 2;
Javier Martinec2c4f32012-01-05 10:57:39 -0300891
Marco Felsch5cb82942018-06-28 12:20:39 -0400892 f->code = TVP5150_MBUS_FMT;
893 f->field = TVP5150_FIELD;
894 f->colorspace = TVP5150_COLORSPACE;
Javier Martinec2c4f32012-01-05 10:57:39 -0300895
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200896 dev_dbg_lvl(sd->dev, 1, debug, "width = %d, height = %d\n", f->width,
Marco Felsch5cb82942018-06-28 12:20:39 -0400897 f->height);
Javier Martinec2c4f32012-01-05 10:57:39 -0300898 return 0;
899}
900
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200901static int tvp5150_set_selection(struct v4l2_subdev *sd,
902 struct v4l2_subdev_pad_config *cfg,
903 struct v4l2_subdev_selection *sel)
Javier Martin963ddc62012-01-31 05:23:46 -0300904{
Javier Martin963ddc62012-01-31 05:23:46 -0300905 struct tvp5150 *decoder = to_tvp5150(sd);
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200906 struct v4l2_rect rect = sel->r;
Javier Martin963ddc62012-01-31 05:23:46 -0300907 v4l2_std_id std;
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200908 int hmax;
909
910 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE ||
911 sel->target != V4L2_SEL_TGT_CROP)
912 return -EINVAL;
Javier Martin963ddc62012-01-31 05:23:46 -0300913
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -0200914 dev_dbg_lvl(sd->dev, 1, debug, "%s left=%d, top=%d, width=%d, height=%d\n",
Javier Martin963ddc62012-01-31 05:23:46 -0300915 __func__, rect.left, rect.top, rect.width, rect.height);
916
Javier Martin963ddc62012-01-31 05:23:46 -0300917 /* tvp5150 has some special limits */
918 rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT);
Javier Martin963ddc62012-01-31 05:23:46 -0300919 rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP);
920
921 /* Calculate height based on current standard */
922 if (decoder->norm == V4L2_STD_ALL)
923 std = tvp5150_read_std(sd);
924 else
925 std = decoder->norm;
926
927 if (std & V4L2_STD_525_60)
928 hmax = TVP5150_V_MAX_525_60;
929 else
930 hmax = TVP5150_V_MAX_OTHERS;
931
Marco Felschbd24db02018-06-28 12:20:33 -0400932 /*
933 * alignments:
934 * - width = 2 due to UYVY colorspace
935 * - height, image = no special alignment
936 */
937 v4l_bound_align_image(&rect.width,
938 TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left,
939 TVP5150_H_MAX - rect.left, 1, &rect.height,
Ricardo Ribaldaf90580c2013-11-26 05:31:42 -0300940 hmax - TVP5150_MAX_CROP_TOP - rect.top,
Marco Felschbd24db02018-06-28 12:20:33 -0400941 hmax - rect.top, 0, 0);
Javier Martin963ddc62012-01-31 05:23:46 -0300942
Philipp Zabel28b9e222018-06-28 12:20:35 -0400943 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START, rect.top);
944 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP,
945 rect.top + rect.height - hmax);
946 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_MSB,
947 rect.left >> TVP5150_CROP_SHIFT);
948 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_LSB,
949 rect.left | (1 << TVP5150_CROP_SHIFT));
950 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_MSB,
951 (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >>
952 TVP5150_CROP_SHIFT);
953 regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_LSB,
954 rect.left + rect.width - TVP5150_MAX_CROP_LEFT);
Javier Martin963ddc62012-01-31 05:23:46 -0300955
956 decoder->rect = rect;
957
958 return 0;
959}
960
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200961static int tvp5150_get_selection(struct v4l2_subdev *sd,
962 struct v4l2_subdev_pad_config *cfg,
963 struct v4l2_subdev_selection *sel)
Javier Martin963ddc62012-01-31 05:23:46 -0300964{
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200965 struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd);
Javier Martin963ddc62012-01-31 05:23:46 -0300966 v4l2_std_id std;
967
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200968 if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
Javier Martin963ddc62012-01-31 05:23:46 -0300969 return -EINVAL;
970
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200971 switch (sel->target) {
972 case V4L2_SEL_TGT_CROP_BOUNDS:
973 case V4L2_SEL_TGT_CROP_DEFAULT:
974 sel->r.left = 0;
975 sel->r.top = 0;
976 sel->r.width = TVP5150_H_MAX;
Javier Martin963ddc62012-01-31 05:23:46 -0300977
Hans Verkuil10d5509c2015-12-14 08:25:32 -0200978 /* Calculate height based on current standard */
979 if (decoder->norm == V4L2_STD_ALL)
980 std = tvp5150_read_std(sd);
981 else
982 std = decoder->norm;
983 if (std & V4L2_STD_525_60)
984 sel->r.height = TVP5150_V_MAX_525_60;
985 else
986 sel->r.height = TVP5150_V_MAX_OTHERS;
987 return 0;
988 case V4L2_SEL_TGT_CROP:
989 sel->r = decoder->rect;
990 return 0;
991 default:
992 return -EINVAL;
993 }
Javier Martin963ddc62012-01-31 05:23:46 -0300994}
995
Laurent Pinchartdd3a46b2016-01-07 10:46:46 -0200996static int tvp5150_g_mbus_config(struct v4l2_subdev *sd,
997 struct v4l2_mbus_config *cfg)
998{
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -0200999 struct tvp5150 *decoder = to_tvp5150(sd);
1000
1001 cfg->type = decoder->mbus_type;
Laurent Pinchartdd3a46b2016-01-07 10:46:46 -02001002 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING
1003 | V4L2_MBUS_FIELD_EVEN_LOW | V4L2_MBUS_DATA_ACTIVE_HIGH;
1004
1005 return 0;
1006}
1007
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001008/****************************************************************************
Laurent Pincharte545ac82016-01-26 10:46:24 -02001009 V4L2 subdev pad ops
1010 ****************************************************************************/
Philipp Zabelb440b732018-06-28 12:20:40 -04001011static int tvp5150_init_cfg(struct v4l2_subdev *sd,
1012 struct v4l2_subdev_pad_config *cfg)
1013{
1014 struct tvp5150 *decoder = to_tvp5150(sd);
1015 v4l2_std_id std;
1016
1017 /*
1018 * Reset selection to maximum on subdev_open() if autodetection is on
1019 * and a standard change is detected.
1020 */
1021 if (decoder->norm == V4L2_STD_ALL) {
1022 std = tvp5150_read_std(sd);
1023 if (std != decoder->detected_norm) {
1024 decoder->detected_norm = std;
1025 tvp5150_set_default(std, &decoder->rect);
1026 }
1027 }
1028
1029 return 0;
1030}
1031
Laurent Pincharte545ac82016-01-26 10:46:24 -02001032static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd,
1033 struct v4l2_subdev_pad_config *cfg,
1034 struct v4l2_subdev_mbus_code_enum *code)
1035{
1036 if (code->pad || code->index)
1037 return -EINVAL;
1038
Marco Felsch5cb82942018-06-28 12:20:39 -04001039 code->code = TVP5150_MBUS_FMT;
Laurent Pincharte545ac82016-01-26 10:46:24 -02001040 return 0;
1041}
1042
1043static int tvp5150_enum_frame_size(struct v4l2_subdev *sd,
1044 struct v4l2_subdev_pad_config *cfg,
1045 struct v4l2_subdev_frame_size_enum *fse)
1046{
1047 struct tvp5150 *decoder = to_tvp5150(sd);
1048
Marco Felsch5cb82942018-06-28 12:20:39 -04001049 if (fse->index >= 8 || fse->code != TVP5150_MBUS_FMT)
Laurent Pincharte545ac82016-01-26 10:46:24 -02001050 return -EINVAL;
1051
Marco Felsch5cb82942018-06-28 12:20:39 -04001052 fse->code = TVP5150_MBUS_FMT;
Laurent Pincharte545ac82016-01-26 10:46:24 -02001053 fse->min_width = decoder->rect.width;
1054 fse->max_width = decoder->rect.width;
1055 fse->min_height = decoder->rect.height / 2;
1056 fse->max_height = decoder->rect.height / 2;
1057
1058 return 0;
1059}
1060
1061/****************************************************************************
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001062 Media entity ops
1063 ****************************************************************************/
1064
Laurent Pinchart406ff672016-12-08 20:22:41 -02001065#ifdef CONFIG_MEDIA_CONTROLLER
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001066static int tvp5150_link_setup(struct media_entity *entity,
1067 const struct media_pad *local,
1068 const struct media_pad *remote, u32 flags)
1069{
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001070 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1071 struct tvp5150 *decoder = to_tvp5150(sd);
1072 int i;
1073
1074 for (i = 0; i < TVP5150_INPUT_NUM; i++) {
1075 if (remote->entity == &decoder->input_ent[i])
1076 break;
1077 }
1078
1079 /* Do nothing for entities that are not input connectors */
1080 if (i == TVP5150_INPUT_NUM)
1081 return 0;
1082
1083 decoder->input = i;
1084
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001085 tvp5150_selmux(sd);
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001086
1087 return 0;
1088}
1089
1090static const struct media_entity_operations tvp5150_sd_media_ops = {
1091 .link_setup = tvp5150_link_setup,
1092};
Laurent Pinchart406ff672016-12-08 20:22:41 -02001093#endif
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001094
1095/****************************************************************************
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001096 I2C Command
1097 ****************************************************************************/
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001098
Laurent Pinchart460b6c02016-01-07 10:46:45 -02001099static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable)
1100{
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001101 struct tvp5150 *decoder = to_tvp5150(sd);
Marco Felsch8a7441b2018-06-28 12:20:36 -04001102 unsigned int mask, val = 0;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001103
Marco Felsch8a7441b2018-06-28 12:20:36 -04001104 mask = TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE |
1105 TVP5150_MISC_CTL_CLOCK_OE;
Laurent Pinchart460b6c02016-01-07 10:46:45 -02001106
Laurent Pinchart79d62052016-12-09 09:47:19 -02001107 if (enable) {
1108 /*
1109 * Enable the YCbCr and clock outputs. In discrete sync mode
1110 * (non-BT.656) additionally enable the the sync outputs.
1111 */
Marco Felsch8a7441b2018-06-28 12:20:36 -04001112 val = TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_CLOCK_OE;
Laurent Pinchart79d62052016-12-09 09:47:19 -02001113 if (decoder->mbus_type == V4L2_MBUS_PARALLEL)
1114 val |= TVP5150_MISC_CTL_SYNC_OE;
1115 }
1116
Marco Felsch8a7441b2018-06-28 12:20:36 -04001117 regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val);
Laurent Pinchart460b6c02016-01-07 10:46:45 -02001118
1119 return 0;
1120}
1121
Hans Verkuil5325b422009-04-02 11:26:22 -03001122static int tvp5150_s_routing(struct v4l2_subdev *sd,
1123 u32 input, u32 output, u32 config)
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001124{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001125 struct tvp5150 *decoder = to_tvp5150(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001126
Hans Verkuil5325b422009-04-02 11:26:22 -03001127 decoder->input = input;
1128 decoder->output = output;
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -02001129
1130 if (output == TVP5150_BLACK_SCREEN)
1131 decoder->enable = false;
1132 else
1133 decoder->enable = true;
1134
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001135 tvp5150_selmux(sd);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001136 return 0;
1137}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001138
Hans Verkuild37dad42010-03-14 10:59:16 -03001139static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001140{
Philipp Zabel28b9e222018-06-28 12:20:35 -04001141 struct tvp5150 *decoder = to_tvp5150(sd);
1142
Nasser Afshin9bfd8f82018-04-02 18:23:18 -04001143 /*
1144 * this is for capturing 36 raw vbi lines
1145 * if there's a way to cut off the beginning 2 vbi lines
1146 * with the tvp5150 then the vbi line count could be lowered
1147 * to 17 lines/field again, although I couldn't find a register
1148 * which could do that cropping
1149 */
1150
Hans Verkuild37dad42010-03-14 10:59:16 -03001151 if (fmt->sample_format == V4L2_PIX_FMT_GREY)
Philipp Zabel28b9e222018-06-28 12:20:35 -04001152 regmap_write(decoder->regmap, TVP5150_LUMA_PROC_CTL_1, 0x70);
Hans Verkuild37dad42010-03-14 10:59:16 -03001153 if (fmt->count[0] == 18 && fmt->count[1] == 18) {
Philipp Zabel28b9e222018-06-28 12:20:35 -04001154 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START,
1155 0x00);
1156 regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP, 0x01);
Hans Verkuild37dad42010-03-14 10:59:16 -03001157 }
1158 return 0;
1159}
1160
1161static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
1162{
Philipp Zabel28b9e222018-06-28 12:20:35 -04001163 struct tvp5150 *decoder = to_tvp5150(sd);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001164 int i;
1165
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001166 if (svbi->service_set != 0) {
1167 for (i = 0; i <= 23; i++) {
1168 svbi->service_lines[1][i] = 0;
1169 svbi->service_lines[0][i] =
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -05001170 tvp5150_set_vbi(sd, svbi->service_lines[0][i],
1171 0xf0, i, 3);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001172 }
1173 /* Enables FIFO */
Philipp Zabel28b9e222018-06-28 12:20:35 -04001174 regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 1);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001175 } else {
1176 /* Disables FIFO*/
Philipp Zabel28b9e222018-06-28 12:20:35 -04001177 regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 0);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001178
1179 /* Disable Full Field */
Philipp Zabel28b9e222018-06-28 12:20:35 -04001180 regmap_write(decoder->regmap, TVP5150_FULL_FIELD_ENA, 0);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001181
1182 /* Disable Line modes */
1183 for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++)
Philipp Zabel28b9e222018-06-28 12:20:35 -04001184 regmap_write(decoder->regmap, i, 0xff);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001185 }
1186 return 0;
1187}
1188
Hans Verkuild37dad42010-03-14 10:59:16 -03001189static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
1190{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001191 int i, mask = 0;
1192
Hans Verkuil30634e82012-09-05 10:38:10 -03001193 memset(svbi->service_lines, 0, sizeof(svbi->service_lines));
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001194
1195 for (i = 0; i <= 23; i++) {
1196 svbi->service_lines[0][i] =
Mauro Carvalho Chehab3dd6b562018-02-19 13:23:39 -05001197 tvp5150_get_vbi(sd, i);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001198 mask |= svbi->service_lines[0][i];
1199 }
1200 svbi->service_set = mask;
1201 return 0;
1202}
1203
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001204#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001205static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001206{
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001207 int res;
1208
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001209 res = tvp5150_read(sd, reg->reg & 0xff);
1210 if (res < 0) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001211 dev_err(sd->dev, "%s: failed with error = %d\n", __func__, res);
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001212 return res;
1213 }
1214
1215 reg->val = res;
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001216 reg->size = 1;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001217 return 0;
1218}
1219
Hans Verkuil977ba3b12013-03-24 08:28:46 -03001220static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001221{
Philipp Zabel28b9e222018-06-28 12:20:35 -04001222 struct tvp5150 *decoder = to_tvp5150(sd);
1223
1224 return regmap_write(decoder->regmap, reg->reg & 0xff, reg->val & 0xff);
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001225}
1226#endif
1227
1228static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
1229{
1230 int status = tvp5150_read(sd, 0x88);
1231
1232 vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0;
1233 return 0;
1234}
1235
Javier Martinez Canillas5a08bc02016-08-11 13:28:15 -03001236static int tvp5150_registered(struct v4l2_subdev *sd)
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001237{
1238#ifdef CONFIG_MEDIA_CONTROLLER
1239 struct tvp5150 *decoder = to_tvp5150(sd);
1240 int ret = 0;
1241 int i;
1242
1243 for (i = 0; i < TVP5150_INPUT_NUM; i++) {
1244 struct media_entity *input = &decoder->input_ent[i];
1245 struct media_pad *pad = &decoder->input_pad[i];
1246
1247 if (!input->name)
1248 continue;
1249
1250 decoder->input_pad[i].flags = MEDIA_PAD_FL_SOURCE;
1251
1252 ret = media_entity_pads_init(input, 1, pad);
1253 if (ret < 0)
1254 return ret;
1255
1256 ret = media_device_register_entity(sd->v4l2_dev->mdev, input);
1257 if (ret < 0)
1258 return ret;
1259
1260 ret = media_create_pad_link(input, 0, &sd->entity,
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -04001261 TVP5150_PAD_IF_INPUT, 0);
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001262 if (ret < 0) {
1263 media_device_unregister_entity(input);
1264 return ret;
1265 }
1266 }
1267#endif
1268
1269 return 0;
1270}
1271
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001272/* ----------------------------------------------------------------------- */
1273
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001274static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
1275 .s_ctrl = tvp5150_s_ctrl,
1276};
1277
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001278static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1279 .log_status = tvp5150_log_status,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001280 .reset = tvp5150_reset,
1281#ifdef CONFIG_VIDEO_ADV_DEBUG
1282 .g_register = tvp5150_g_register,
1283 .s_register = tvp5150_s_register,
1284#endif
1285};
1286
1287static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = {
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001288 .g_tuner = tvp5150_g_tuner,
1289};
1290
1291static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
Laurent Pinchart8774bed2014-04-28 16:53:01 -03001292 .s_std = tvp5150_s_std,
Laurent Pinchart460b6c02016-01-07 10:46:45 -02001293 .s_stream = tvp5150_s_stream,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001294 .s_routing = tvp5150_s_routing,
Laurent Pinchartdd3a46b2016-01-07 10:46:46 -02001295 .g_mbus_config = tvp5150_g_mbus_config,
Hans Verkuil32cd5272010-03-14 09:57:30 -03001296};
1297
1298static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001299 .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
Hans Verkuild37dad42010-03-14 10:59:16 -03001300 .g_sliced_fmt = tvp5150_g_sliced_fmt,
1301 .s_sliced_fmt = tvp5150_s_sliced_fmt,
1302 .s_raw_fmt = tvp5150_s_raw_fmt,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001303};
1304
Hans Verkuilebcff5f2015-04-09 04:01:33 -03001305static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = {
Philipp Zabelb440b732018-06-28 12:20:40 -04001306 .init_cfg = tvp5150_init_cfg,
Hans Verkuilebcff5f2015-04-09 04:01:33 -03001307 .enum_mbus_code = tvp5150_enum_mbus_code,
Laurent Pincharte545ac82016-01-26 10:46:24 -02001308 .enum_frame_size = tvp5150_enum_frame_size,
Hans Verkuilda298c62015-04-09 04:02:34 -03001309 .set_fmt = tvp5150_fill_fmt,
1310 .get_fmt = tvp5150_fill_fmt,
Hans Verkuil10d5509c2015-12-14 08:25:32 -02001311 .get_selection = tvp5150_get_selection,
1312 .set_selection = tvp5150_set_selection,
Hans Verkuilebcff5f2015-04-09 04:01:33 -03001313};
1314
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001315static const struct v4l2_subdev_ops tvp5150_ops = {
1316 .core = &tvp5150_core_ops,
1317 .tuner = &tvp5150_tuner_ops,
1318 .video = &tvp5150_video_ops,
Hans Verkuil32cd5272010-03-14 09:57:30 -03001319 .vbi = &tvp5150_vbi_ops,
Hans Verkuilebcff5f2015-04-09 04:01:33 -03001320 .pad = &tvp5150_pad_ops,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001321};
1322
Javier Martinez Canillas5a08bc02016-08-11 13:28:15 -03001323static const struct v4l2_subdev_internal_ops tvp5150_internal_ops = {
1324 .registered = tvp5150_registered,
1325};
1326
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001327
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001328/****************************************************************************
1329 I2C Client & Driver
1330 ****************************************************************************/
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001331
Philipp Zabel28b9e222018-06-28 12:20:35 -04001332static const struct regmap_range tvp5150_readable_ranges[] = {
1333 {
1334 .range_min = TVP5150_VD_IN_SRC_SEL_1,
1335 .range_max = TVP5150_AUTOSW_MSK,
1336 }, {
1337 .range_min = TVP5150_COLOR_KIL_THSH_CTL,
1338 .range_max = TVP5150_CONF_SHARED_PIN,
1339 }, {
1340 .range_min = TVP5150_ACT_VD_CROP_ST_MSB,
1341 .range_max = TVP5150_HORIZ_SYNC_START,
1342 }, {
1343 .range_min = TVP5150_VERT_BLANKING_START,
1344 .range_max = TVP5150_INTT_CONFIG_REG_B,
1345 }, {
1346 .range_min = TVP5150_VIDEO_STD,
1347 .range_max = TVP5150_VIDEO_STD,
1348 }, {
1349 .range_min = TVP5150_CB_GAIN_FACT,
1350 .range_max = TVP5150_REV_SELECT,
1351 }, {
1352 .range_min = TVP5150_MSB_DEV_ID,
1353 .range_max = TVP5150_STATUS_REG_5,
1354 }, {
1355 .range_min = TVP5150_CC_DATA_INI,
1356 .range_max = TVP5150_TELETEXT_FIL_ENA,
1357 }, {
1358 .range_min = TVP5150_INT_STATUS_REG_A,
1359 .range_max = TVP5150_FIFO_OUT_CTRL,
1360 }, {
1361 .range_min = TVP5150_FULL_FIELD_ENA,
1362 .range_max = TVP5150_FULL_FIELD_MODE_REG,
1363 },
1364};
1365
1366bool tvp5150_volatile_reg(struct device *dev, unsigned int reg)
1367{
1368 switch (reg) {
1369 case TVP5150_VERT_LN_COUNT_MSB:
1370 case TVP5150_VERT_LN_COUNT_LSB:
1371 case TVP5150_INT_STATUS_REG_A:
1372 case TVP5150_INT_STATUS_REG_B:
1373 case TVP5150_INT_ACTIVE_REG_B:
1374 case TVP5150_STATUS_REG_1:
1375 case TVP5150_STATUS_REG_2:
1376 case TVP5150_STATUS_REG_3:
1377 case TVP5150_STATUS_REG_4:
1378 case TVP5150_STATUS_REG_5:
1379 /* CC, WSS, VPS, VITC data? */
1380 case TVP5150_VBI_FIFO_READ_DATA:
1381 case TVP5150_VDP_STATUS_REG:
1382 case TVP5150_FIFO_WORD_COUNT:
1383 return true;
1384 default:
1385 return false;
1386 }
1387}
1388
1389static const struct regmap_access_table tvp5150_readable_table = {
1390 .yes_ranges = tvp5150_readable_ranges,
1391 .n_yes_ranges = ARRAY_SIZE(tvp5150_readable_ranges),
1392};
1393
1394static struct regmap_config tvp5150_config = {
1395 .reg_bits = 8,
1396 .val_bits = 8,
1397 .max_register = 0xff,
1398
1399 .cache_type = REGCACHE_RBTREE,
1400
1401 .rd_table = &tvp5150_readable_table,
1402 .volatile_reg = tvp5150_volatile_reg,
1403};
1404
Laurent Pinchart78715972016-01-07 10:46:41 -02001405static int tvp5150_detect_version(struct tvp5150 *core)
1406{
1407 struct v4l2_subdev *sd = &core->sd;
1408 struct i2c_client *c = v4l2_get_subdevdata(sd);
Laurent Pinchart78715972016-01-07 10:46:41 -02001409 u8 regs[4];
1410 int res;
1411
1412 /*
1413 * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID,
1414 * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER
1415 */
Philipp Zabel28b9e222018-06-28 12:20:35 -04001416 res = regmap_bulk_read(core->regmap, TVP5150_MSB_DEV_ID, regs, 4);
1417 if (res < 0) {
1418 dev_err(&c->dev, "reading ID registers failed: %d\n", res);
1419 return res;
Laurent Pinchart78715972016-01-07 10:46:41 -02001420 }
1421
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001422 core->dev_id = (regs[0] << 8) | regs[1];
1423 core->rom_ver = (regs[2] << 8) | regs[3];
Laurent Pinchart78715972016-01-07 10:46:41 -02001424
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001425 dev_info(sd->dev, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n",
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001426 core->dev_id, regs[2], regs[3], c->addr << 1,
1427 c->adapter->name);
Laurent Pinchart78715972016-01-07 10:46:41 -02001428
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001429 if (core->dev_id == 0x5150 && core->rom_ver == 0x0321) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001430 dev_info(sd->dev, "tvp5150a detected.\n");
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001431 } else if (core->dev_id == 0x5150 && core->rom_ver == 0x0400) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001432 dev_info(sd->dev, "tvp5150am1 detected.\n");
Laurent Pinchart78715972016-01-07 10:46:41 -02001433
1434 /* ITU-T BT.656.4 timing */
Philipp Zabel28b9e222018-06-28 12:20:35 -04001435 regmap_write(core->regmap, TVP5150_REV_SELECT, 0);
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001436 } else if (core->dev_id == 0x5151 && core->rom_ver == 0x0100) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001437 dev_info(sd->dev, "tvp5151 detected.\n");
Laurent Pinchart78715972016-01-07 10:46:41 -02001438 } else {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001439 dev_info(sd->dev, "*** unknown tvp%04x chip detected.\n",
Javier Martinez Canillas82275132016-02-05 17:09:54 -02001440 core->dev_id);
Laurent Pinchart78715972016-01-07 10:46:41 -02001441 }
1442
1443 return 0;
1444}
1445
Javier Martinez Canillas09aa2602016-01-07 10:46:49 -02001446static int tvp5150_init(struct i2c_client *c)
1447{
1448 struct gpio_desc *pdn_gpio;
1449 struct gpio_desc *reset_gpio;
1450
1451 pdn_gpio = devm_gpiod_get_optional(&c->dev, "pdn", GPIOD_OUT_HIGH);
1452 if (IS_ERR(pdn_gpio))
1453 return PTR_ERR(pdn_gpio);
1454
1455 if (pdn_gpio) {
1456 gpiod_set_value_cansleep(pdn_gpio, 0);
1457 /* Delay time between power supplies active and reset */
1458 msleep(20);
1459 }
1460
1461 reset_gpio = devm_gpiod_get_optional(&c->dev, "reset", GPIOD_OUT_HIGH);
1462 if (IS_ERR(reset_gpio))
1463 return PTR_ERR(reset_gpio);
1464
1465 if (reset_gpio) {
1466 /* RESETB pulse duration */
1467 ndelay(500);
1468 gpiod_set_value_cansleep(reset_gpio, 0);
1469 /* Delay time between end of reset to I2C active */
1470 usleep_range(200, 250);
1471 }
1472
1473 return 0;
1474}
1475
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001476static int tvp5150_parse_dt(struct tvp5150 *decoder, struct device_node *np)
1477{
Sakari Ailus859969b2016-08-26 20:17:25 -03001478 struct v4l2_fwnode_endpoint bus_cfg;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001479 struct device_node *ep;
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001480#ifdef CONFIG_MEDIA_CONTROLLER
1481 struct device_node *connectors, *child;
1482 struct media_entity *input;
1483 const char *name;
1484 u32 input_type;
1485#endif
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001486 unsigned int flags;
1487 int ret = 0;
1488
1489 ep = of_graph_get_next_endpoint(np, NULL);
1490 if (!ep)
1491 return -EINVAL;
1492
Sakari Ailus859969b2016-08-26 20:17:25 -03001493 ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg);
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001494 if (ret)
1495 goto err;
1496
1497 flags = bus_cfg.bus.parallel.flags;
1498
1499 if (bus_cfg.bus_type == V4L2_MBUS_PARALLEL &&
1500 !(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH &&
1501 flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH &&
Javier Martinez Canillas2bd5e432016-02-05 17:09:53 -02001502 flags & V4L2_MBUS_FIELD_EVEN_LOW)) {
1503 ret = -EINVAL;
1504 goto err;
1505 }
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001506
1507 decoder->mbus_type = bus_cfg.bus_type;
1508
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001509#ifdef CONFIG_MEDIA_CONTROLLER
1510 connectors = of_get_child_by_name(np, "connectors");
1511
1512 if (!connectors)
1513 goto err;
1514
1515 for_each_available_child_of_node(connectors, child) {
1516 ret = of_property_read_u32(child, "input", &input_type);
1517 if (ret) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001518 dev_err(decoder->sd.dev,
Rob Herringf764e6d2018-08-27 21:52:29 -04001519 "missing type property in node %pOFn\n",
1520 child);
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001521 goto err_connector;
1522 }
1523
Mauro Carvalho Chehab60ad7682016-02-19 15:02:30 -02001524 if (input_type >= TVP5150_INPUT_NUM) {
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001525 ret = -EINVAL;
1526 goto err_connector;
1527 }
1528
1529 input = &decoder->input_ent[input_type];
1530
1531 /* Each input connector can only be defined once */
1532 if (input->name) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001533 dev_err(decoder->sd.dev,
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001534 "input %s with same type already exists\n",
1535 input->name);
1536 ret = -EINVAL;
1537 goto err_connector;
1538 }
1539
1540 switch (input_type) {
1541 case TVP5150_COMPOSITE0:
1542 case TVP5150_COMPOSITE1:
1543 input->function = MEDIA_ENT_F_CONN_COMPOSITE;
1544 break;
1545 case TVP5150_SVIDEO:
1546 input->function = MEDIA_ENT_F_CONN_SVIDEO;
1547 break;
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001548 }
1549
1550 input->flags = MEDIA_ENT_FL_CONNECTOR;
1551
1552 ret = of_property_read_string(child, "label", &name);
1553 if (ret < 0) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001554 dev_err(decoder->sd.dev,
Rob Herringf764e6d2018-08-27 21:52:29 -04001555 "missing label property in node %pOFn\n",
1556 child);
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001557 goto err_connector;
1558 }
1559
1560 input->name = name;
1561 }
1562
1563err_connector:
1564 of_node_put(connectors);
1565#endif
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001566err:
1567 of_node_put(ep);
1568 return ret;
1569}
1570
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -02001571static const char * const tvp5150_test_patterns[2] = {
1572 "Disabled",
1573 "Black screen"
1574};
1575
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001576static int tvp5150_probe(struct i2c_client *c,
1577 const struct i2c_device_id *id)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001578{
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001579 struct tvp5150 *core;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001580 struct v4l2_subdev *sd;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001581 struct device_node *np = c->dev.of_node;
Philipp Zabel28b9e222018-06-28 12:20:35 -04001582 struct regmap *map;
Laurent Pinchart78715972016-01-07 10:46:41 -02001583 int res;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001584
1585 /* Check if the adapter supports the needed features */
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001586 if (!i2c_check_functionality(c->adapter,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001587 I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001588 return -EIO;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001589
Javier Martinez Canillas09aa2602016-01-07 10:46:49 -02001590 res = tvp5150_init(c);
1591 if (res)
1592 return res;
1593
Laurent Pinchartc02b2112013-05-02 08:29:43 -03001594 core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL);
1595 if (!core)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001596 return -ENOMEM;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001597
Philipp Zabel28b9e222018-06-28 12:20:35 -04001598 map = devm_regmap_init_i2c(c, &tvp5150_config);
1599 if (IS_ERR(map))
1600 return PTR_ERR(map);
1601
1602 core->regmap = map;
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001603 sd = &core->sd;
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001604
1605 if (IS_ENABLED(CONFIG_OF) && np) {
1606 res = tvp5150_parse_dt(core, np);
1607 if (res) {
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001608 dev_err(sd->dev, "DT parsing error: %d\n", res);
Javier Martinez Canillasa2e5f1b2016-01-07 10:46:50 -02001609 return res;
1610 }
1611 } else {
1612 /* Default to BT.656 embedded sync */
1613 core->mbus_type = V4L2_MBUS_BT656;
1614 }
1615
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001616 v4l2_i2c_subdev_init(sd, c, &tvp5150_ops);
Javier Martinez Canillas5a08bc02016-08-11 13:28:15 -03001617 sd->internal_ops = &tvp5150_internal_ops;
Laurent Pincharte545ac82016-01-26 10:46:24 -02001618 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1619
1620#if defined(CONFIG_MEDIA_CONTROLLER)
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -04001621 core->pads[TVP5150_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK;
1622 core->pads[TVP5150_PAD_IF_INPUT].sig_type = PAD_SIGNAL_ANALOG;
1623 core->pads[TVP5150_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE;
1624 core->pads[TVP5150_PAD_VID_OUT].sig_type = PAD_SIGNAL_DV;
Mauro Carvalho Chehabf92c70a2016-01-27 15:09:15 -02001625
1626 sd->entity.function = MEDIA_ENT_F_ATV_DECODER;
1627
Mauro Carvalho Chehabbc322c02018-08-01 06:10:05 -04001628 res = media_entity_pads_init(&sd->entity, TVP5150_NUM_PADS, core->pads);
Laurent Pincharte545ac82016-01-26 10:46:24 -02001629 if (res < 0)
1630 return res;
Javier Martinez Canillasf7b4b542016-02-05 17:09:58 -02001631
1632 sd->entity.ops = &tvp5150_sd_media_ops;
Laurent Pincharte545ac82016-01-26 10:46:24 -02001633#endif
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001634
Laurent Pinchart78715972016-01-07 10:46:41 -02001635 res = tvp5150_detect_version(core);
1636 if (res < 0)
1637 return res;
Mauro Carvalho Chehab0e09a3c2011-02-22 00:10:22 -03001638
Mauro Carvalho Chehab3ad96832006-01-23 17:11:05 -02001639 core->norm = V4L2_STD_ALL; /* Default is autodetect */
Philipp Zabelb440b732018-06-28 12:20:40 -04001640 core->detected_norm = V4L2_STD_UNKNOWN;
Hans Verkuil5325b422009-04-02 11:26:22 -03001641 core->input = TVP5150_COMPOSITE1;
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -02001642 core->enable = true;
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001643
Laurent Pinchartb1950b82016-01-07 10:46:44 -02001644 v4l2_ctrl_handler_init(&core->hdl, 5);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001645 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1646 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1647 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1648 V4L2_CID_CONTRAST, 0, 255, 1, 128);
1649 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1650 V4L2_CID_SATURATION, 0, 255, 1, 128);
1651 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1652 V4L2_CID_HUE, -128, 127, 1, 0);
Laurent Pinchartb1950b82016-01-07 10:46:44 -02001653 v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
1654 V4L2_CID_PIXEL_RATE, 27000000,
1655 27000000, 1, 27000000);
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -02001656 v4l2_ctrl_new_std_menu_items(&core->hdl, &tvp5150_ctrl_ops,
1657 V4L2_CID_TEST_PATTERN,
Mauro Carvalho Chehab5c4c4502018-09-13 16:49:51 -04001658 ARRAY_SIZE(tvp5150_test_patterns) - 1,
Mauro Carvalho Chehabc43875f2016-02-12 15:42:02 -02001659 0, 0, tvp5150_test_patterns);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001660 sd->ctrl_handler = &core->hdl;
1661 if (core->hdl.error) {
Dmitry Lifshitz8cd0d4c2012-06-13 07:49:30 -03001662 res = core->hdl.error;
Javier Martinez Canillasc7d97492015-09-21 08:23:09 -03001663 goto err;
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001664 }
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001665
Marco Felsch5cb82942018-06-28 12:20:39 -04001666 tvp5150_set_default(tvp5150_read_std(sd), &core->rect);
Javier Martin963ddc62012-01-31 05:23:46 -03001667
Laurent Pinchartaff808e2016-12-09 09:47:17 -02001668 tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */
1669
Javier Martinez Canillasc7d97492015-09-21 08:23:09 -03001670 res = v4l2_async_register_subdev(sd);
1671 if (res < 0)
1672 goto err;
1673
Markus Rechbergerf1e5ee42006-02-07 04:01:19 +01001674 if (debug > 1)
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001675 tvp5150_log_status(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001676 return 0;
Javier Martinez Canillasc7d97492015-09-21 08:23:09 -03001677
1678err:
1679 v4l2_ctrl_handler_free(&core->hdl);
1680 return res;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001681}
1682
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001683static int tvp5150_remove(struct i2c_client *c)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001684{
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001685 struct v4l2_subdev *sd = i2c_get_clientdata(c);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001686 struct tvp5150 *decoder = to_tvp5150(sd);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001687
Mauro Carvalho Chehab257e29f2016-11-16 08:58:05 -02001688 dev_dbg_lvl(sd->dev, 1, debug,
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001689 "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1690 c->addr << 1);
1691
Javier Martinez Canillasc7d97492015-09-21 08:23:09 -03001692 v4l2_async_unregister_subdev(sd);
Hans Verkuil6c45ec72010-12-12 08:45:43 -03001693 v4l2_ctrl_handler_free(&decoder->hdl);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001694 return 0;
1695}
1696
1697/* ----------------------------------------------------------------------- */
1698
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001699static const struct i2c_device_id tvp5150_id[] = {
1700 { "tvp5150", 0 },
1701 { }
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001702};
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001703MODULE_DEVICE_TABLE(i2c, tvp5150_id);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001704
Eduard Gavin7ef930a2016-01-07 10:46:48 -02001705#if IS_ENABLED(CONFIG_OF)
1706static const struct of_device_id tvp5150_of_match[] = {
1707 { .compatible = "ti,tvp5150", },
1708 { /* sentinel */ },
1709};
1710MODULE_DEVICE_TABLE(of, tvp5150_of_match);
1711#endif
1712
Hans Verkuilc7711452010-09-15 15:45:20 -03001713static struct i2c_driver tvp5150_driver = {
1714 .driver = {
Eduard Gavin7ef930a2016-01-07 10:46:48 -02001715 .of_match_table = of_match_ptr(tvp5150_of_match),
Hans Verkuilc7711452010-09-15 15:45:20 -03001716 .name = "tvp5150",
1717 },
1718 .probe = tvp5150_probe,
1719 .remove = tvp5150_remove,
1720 .id_table = tvp5150_id,
Hans Verkuil6b8fe022008-12-18 11:17:25 -03001721};
Hans Verkuilc7711452010-09-15 15:45:20 -03001722
Axel Linc6e8d862012-02-12 06:56:32 -03001723module_i2c_driver(tvp5150_driver);