Mauro Carvalho Chehab | 459ee17 | 2017-12-01 08:47:12 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // tvp5150 - Texas Instruments TVP5150A/AM1 and TVP5151 video decoder driver |
| 4 | // |
Mauro Carvalho Chehab | 3259081 | 2018-04-25 05:34:48 -0400 | [diff] [blame] | 5 | // Copyright (c) 2005,2006 Mauro Carvalho Chehab <mchehab@kernel.org> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 6 | |
Javier Martinez Canillas | b802fb9 | 2016-02-05 17:09:56 -0200 | [diff] [blame] | 7 | #include <dt-bindings/media/tvp5150.h> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 8 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Hans Verkuil | 33b687c | 2008-07-25 05:32:50 -0300 | [diff] [blame] | 10 | #include <linux/videodev2.h> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 11 | #include <linux/delay.h> |
Javier Martinez Canillas | 09aa260 | 2016-01-07 10:46:49 -0200 | [diff] [blame] | 12 | #include <linux/gpio/consumer.h> |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 15 | #include <linux/of_graph.h> |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 16 | #include <linux/regmap.h> |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 17 | #include <media/v4l2-async.h> |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 18 | #include <media/v4l2-device.h> |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 19 | #include <media/v4l2-ctrls.h> |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 20 | #include <media/v4l2-fwnode.h> |
Mauro Carvalho Chehab | 5560631 | 2016-01-27 12:08:13 -0200 | [diff] [blame] | 21 | #include <media/v4l2-mc.h> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 22 | |
| 23 | #include "tvp5150_reg.h" |
| 24 | |
Philipp Zabel | 785a3de | 2014-02-27 13:44:47 -0300 | [diff] [blame] | 25 | #define TVP5150_H_MAX 720U |
| 26 | #define TVP5150_V_MAX_525_60 480U |
| 27 | #define TVP5150_V_MAX_OTHERS 576U |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 28 | #define TVP5150_MAX_CROP_LEFT 511 |
| 29 | #define TVP5150_MAX_CROP_TOP 127 |
| 30 | #define TVP5150_CROP_SHIFT 2 |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 31 | #define TVP5150_MBUS_FMT MEDIA_BUS_FMT_UYVY8_2X8 |
| 32 | #define TVP5150_FIELD V4L2_FIELD_ALTERNATE |
| 33 | #define TVP5150_COLORSPACE V4L2_COLORSPACE_SMPTE170M |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 34 | |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 35 | MODULE_DESCRIPTION("Texas Instruments TVP5150A/TVP5150AM1/TVP5151 video decoder driver"); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 36 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
Mauro Carvalho Chehab | 459ee17 | 2017-12-01 08:47:12 -0500 | [diff] [blame] | 37 | MODULE_LICENSE("GPL v2"); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 38 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 39 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 40 | static int debug; |
Philipp Zabel | 2a0489d | 2014-02-27 13:44:48 -0300 | [diff] [blame] | 41 | module_param(debug, int, 0644); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 42 | MODULE_PARM_DESC(debug, "Debug level (0-2)"); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 43 | |
Mauro Carvalho Chehab | ad0e374 | 2016-11-13 05:34:12 -0200 | [diff] [blame] | 44 | #define dprintk0(__dev, __arg...) dev_dbg_lvl(__dev, 0, 0, __arg) |
| 45 | |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 46 | enum tvp5150_pads { |
| 47 | TVP5150_PAD_IF_INPUT, |
| 48 | TVP5150_PAD_VID_OUT, |
| 49 | TVP5150_NUM_PADS |
| 50 | }; |
| 51 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 52 | struct tvp5150 { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 53 | struct v4l2_subdev sd; |
Mauro Carvalho Chehab | 5560631 | 2016-01-27 12:08:13 -0200 | [diff] [blame] | 54 | #ifdef CONFIG_MEDIA_CONTROLLER |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 55 | struct media_pad pads[TVP5150_NUM_PADS]; |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 56 | struct media_entity input_ent[TVP5150_INPUT_NUM]; |
| 57 | struct media_pad input_pad[TVP5150_INPUT_NUM]; |
Mauro Carvalho Chehab | 5560631 | 2016-01-27 12:08:13 -0200 | [diff] [blame] | 58 | #endif |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 59 | struct v4l2_ctrl_handler hdl; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 60 | struct v4l2_rect rect; |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 61 | struct regmap *regmap; |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 62 | int irq; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 63 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 64 | v4l2_std_id norm; /* Current set standard */ |
Philipp Zabel | b440b73 | 2018-06-28 12:20:40 -0400 | [diff] [blame] | 65 | v4l2_std_id detected_norm; |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 66 | u32 input; |
| 67 | u32 output; |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 68 | u32 oe; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 69 | int enable; |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 70 | bool lock; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 71 | |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 72 | u16 dev_id; |
| 73 | u16 rom_ver; |
| 74 | |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 75 | enum v4l2_mbus_type mbus_type; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 78 | static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 79 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 80 | return container_of(sd, struct tvp5150, sd); |
| 81 | } |
| 82 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 83 | static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) |
| 84 | { |
| 85 | return &container_of(ctrl->handler, struct tvp5150, hdl)->sd; |
| 86 | } |
| 87 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 88 | static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr) |
| 89 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 90 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 91 | int ret, val; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 92 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 93 | ret = regmap_read(decoder->regmap, addr, &val); |
| 94 | if (ret < 0) |
| 95 | return ret; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 96 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 97 | return val; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 100 | static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init, |
| 101 | const u8 end, int max_line) |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 102 | { |
Mauro Carvalho Chehab | e513411 | 2016-10-20 11:36:42 -0200 | [diff] [blame] | 103 | u8 buf[16]; |
| 104 | int i = 0, j, len; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 105 | |
Mauro Carvalho Chehab | e513411 | 2016-10-20 11:36:42 -0200 | [diff] [blame] | 106 | if (max_line > 16) { |
| 107 | dprintk0(sd->dev, "too much data to dump\n"); |
| 108 | return; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 109 | } |
Mauro Carvalho Chehab | e513411 | 2016-10-20 11:36:42 -0200 | [diff] [blame] | 110 | |
| 111 | for (i = init; i < end; i += max_line) { |
| 112 | len = (end - i > max_line) ? max_line : end - i; |
| 113 | |
| 114 | for (j = 0; j < len; j++) |
| 115 | buf[j] = tvp5150_read(sd, i + j); |
| 116 | |
| 117 | dprintk0(sd->dev, "%s reg %02x = %*ph\n", s, i, len, buf); |
| 118 | } |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 119 | } |
| 120 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 121 | static int tvp5150_log_status(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 122 | { |
Mauro Carvalho Chehab | ad0e374 | 2016-11-13 05:34:12 -0200 | [diff] [blame] | 123 | dprintk0(sd->dev, "tvp5150: Video input source selection #1 = 0x%02x\n", |
| 124 | tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1)); |
| 125 | dprintk0(sd->dev, "tvp5150: Analog channel controls = 0x%02x\n", |
| 126 | tvp5150_read(sd, TVP5150_ANAL_CHL_CTL)); |
| 127 | dprintk0(sd->dev, "tvp5150: Operation mode controls = 0x%02x\n", |
| 128 | tvp5150_read(sd, TVP5150_OP_MODE_CTL)); |
| 129 | dprintk0(sd->dev, "tvp5150: Miscellaneous controls = 0x%02x\n", |
| 130 | tvp5150_read(sd, TVP5150_MISC_CTL)); |
| 131 | dprintk0(sd->dev, "tvp5150: Autoswitch mask= 0x%02x\n", |
| 132 | tvp5150_read(sd, TVP5150_AUTOSW_MSK)); |
| 133 | dprintk0(sd->dev, "tvp5150: Color killer threshold control = 0x%02x\n", |
| 134 | tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL)); |
| 135 | dprintk0(sd->dev, "tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n", |
| 136 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1), |
| 137 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2), |
| 138 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3)); |
| 139 | dprintk0(sd->dev, "tvp5150: Brightness control = 0x%02x\n", |
| 140 | tvp5150_read(sd, TVP5150_BRIGHT_CTL)); |
| 141 | dprintk0(sd->dev, "tvp5150: Color saturation control = 0x%02x\n", |
| 142 | tvp5150_read(sd, TVP5150_SATURATION_CTL)); |
| 143 | dprintk0(sd->dev, "tvp5150: Hue control = 0x%02x\n", |
| 144 | tvp5150_read(sd, TVP5150_HUE_CTL)); |
| 145 | dprintk0(sd->dev, "tvp5150: Contrast control = 0x%02x\n", |
| 146 | tvp5150_read(sd, TVP5150_CONTRAST_CTL)); |
| 147 | dprintk0(sd->dev, "tvp5150: Outputs and data rates select = 0x%02x\n", |
| 148 | tvp5150_read(sd, TVP5150_DATA_RATE_SEL)); |
| 149 | dprintk0(sd->dev, "tvp5150: Configuration shared pins = 0x%02x\n", |
| 150 | tvp5150_read(sd, TVP5150_CONF_SHARED_PIN)); |
| 151 | dprintk0(sd->dev, "tvp5150: Active video cropping start = 0x%02x%02x\n", |
| 152 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB), |
| 153 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB)); |
| 154 | dprintk0(sd->dev, "tvp5150: Active video cropping stop = 0x%02x%02x\n", |
| 155 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB), |
| 156 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB)); |
| 157 | dprintk0(sd->dev, "tvp5150: Genlock/RTC = 0x%02x\n", |
| 158 | tvp5150_read(sd, TVP5150_GENLOCK)); |
| 159 | dprintk0(sd->dev, "tvp5150: Horizontal sync start = 0x%02x\n", |
| 160 | tvp5150_read(sd, TVP5150_HORIZ_SYNC_START)); |
| 161 | dprintk0(sd->dev, "tvp5150: Vertical blanking start = 0x%02x\n", |
| 162 | tvp5150_read(sd, TVP5150_VERT_BLANKING_START)); |
| 163 | dprintk0(sd->dev, "tvp5150: Vertical blanking stop = 0x%02x\n", |
| 164 | tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP)); |
| 165 | dprintk0(sd->dev, "tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n", |
| 166 | tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1), |
| 167 | tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2)); |
| 168 | dprintk0(sd->dev, "tvp5150: Interrupt reset register B = 0x%02x\n", |
| 169 | tvp5150_read(sd, TVP5150_INT_RESET_REG_B)); |
| 170 | dprintk0(sd->dev, "tvp5150: Interrupt enable register B = 0x%02x\n", |
| 171 | tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B)); |
| 172 | dprintk0(sd->dev, "tvp5150: Interrupt configuration register B = 0x%02x\n", |
| 173 | tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B)); |
| 174 | dprintk0(sd->dev, "tvp5150: Video standard = 0x%02x\n", |
| 175 | tvp5150_read(sd, TVP5150_VIDEO_STD)); |
| 176 | dprintk0(sd->dev, "tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n", |
| 177 | tvp5150_read(sd, TVP5150_CB_GAIN_FACT), |
| 178 | tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR)); |
| 179 | dprintk0(sd->dev, "tvp5150: Macrovision on counter = 0x%02x\n", |
| 180 | tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR)); |
| 181 | dprintk0(sd->dev, "tvp5150: Macrovision off counter = 0x%02x\n", |
| 182 | tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR)); |
| 183 | dprintk0(sd->dev, "tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n", |
| 184 | (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4); |
| 185 | dprintk0(sd->dev, "tvp5150: Device ID = %02x%02x\n", |
| 186 | tvp5150_read(sd, TVP5150_MSB_DEV_ID), |
| 187 | tvp5150_read(sd, TVP5150_LSB_DEV_ID)); |
| 188 | dprintk0(sd->dev, "tvp5150: ROM version = (hex) %02x.%02x\n", |
| 189 | tvp5150_read(sd, TVP5150_ROM_MAJOR_VER), |
| 190 | tvp5150_read(sd, TVP5150_ROM_MINOR_VER)); |
| 191 | dprintk0(sd->dev, "tvp5150: Vertical line count = 0x%02x%02x\n", |
| 192 | tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB), |
| 193 | tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB)); |
| 194 | dprintk0(sd->dev, "tvp5150: Interrupt status register B = 0x%02x\n", |
| 195 | tvp5150_read(sd, TVP5150_INT_STATUS_REG_B)); |
| 196 | dprintk0(sd->dev, "tvp5150: Interrupt active register B = 0x%02x\n", |
| 197 | tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B)); |
| 198 | dprintk0(sd->dev, "tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n", |
| 199 | tvp5150_read(sd, TVP5150_STATUS_REG_1), |
| 200 | tvp5150_read(sd, TVP5150_STATUS_REG_2), |
| 201 | tvp5150_read(sd, TVP5150_STATUS_REG_3), |
| 202 | tvp5150_read(sd, TVP5150_STATUS_REG_4), |
| 203 | tvp5150_read(sd, TVP5150_STATUS_REG_5)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 204 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 205 | dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI, |
| 206 | TVP5150_TELETEXT_FIL1_END, 8); |
| 207 | dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI, |
| 208 | TVP5150_TELETEXT_FIL2_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 209 | |
Mauro Carvalho Chehab | ad0e374 | 2016-11-13 05:34:12 -0200 | [diff] [blame] | 210 | dprintk0(sd->dev, "tvp5150: Teletext filter enable = 0x%02x\n", |
| 211 | tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA)); |
| 212 | dprintk0(sd->dev, "tvp5150: Interrupt status register A = 0x%02x\n", |
| 213 | tvp5150_read(sd, TVP5150_INT_STATUS_REG_A)); |
| 214 | dprintk0(sd->dev, "tvp5150: Interrupt enable register A = 0x%02x\n", |
| 215 | tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A)); |
| 216 | dprintk0(sd->dev, "tvp5150: Interrupt configuration = 0x%02x\n", |
| 217 | tvp5150_read(sd, TVP5150_INT_CONF)); |
| 218 | dprintk0(sd->dev, "tvp5150: VDP status register = 0x%02x\n", |
| 219 | tvp5150_read(sd, TVP5150_VDP_STATUS_REG)); |
| 220 | dprintk0(sd->dev, "tvp5150: FIFO word count = 0x%02x\n", |
| 221 | tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT)); |
| 222 | dprintk0(sd->dev, "tvp5150: FIFO interrupt threshold = 0x%02x\n", |
| 223 | tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD)); |
| 224 | dprintk0(sd->dev, "tvp5150: FIFO reset = 0x%02x\n", |
| 225 | tvp5150_read(sd, TVP5150_FIFO_RESET)); |
| 226 | dprintk0(sd->dev, "tvp5150: Line number interrupt = 0x%02x\n", |
| 227 | tvp5150_read(sd, TVP5150_LINE_NUMBER_INT)); |
| 228 | dprintk0(sd->dev, "tvp5150: Pixel alignment register = 0x%02x%02x\n", |
| 229 | tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH), |
| 230 | tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW)); |
| 231 | dprintk0(sd->dev, "tvp5150: FIFO output control = 0x%02x\n", |
| 232 | tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL)); |
| 233 | dprintk0(sd->dev, "tvp5150: Full field enable = 0x%02x\n", |
| 234 | tvp5150_read(sd, TVP5150_FULL_FIELD_ENA)); |
| 235 | dprintk0(sd->dev, "tvp5150: Full field mode register = 0x%02x\n", |
| 236 | tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 237 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 238 | dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI, |
| 239 | TVP5150_CC_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 240 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 241 | dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI, |
| 242 | TVP5150_WSS_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 243 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 244 | dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI, |
| 245 | TVP5150_VPS_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 246 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 247 | dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI, |
| 248 | TVP5150_VITC_DATA_END, 10); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 249 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 250 | dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI, |
| 251 | TVP5150_LINE_MODE_END, 8); |
| 252 | return 0; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /**************************************************************************** |
| 256 | Basic functions |
| 257 | ****************************************************************************/ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 258 | |
Laurent Pinchart | 6e98bee | 2016-12-08 20:22:42 -0200 | [diff] [blame] | 259 | static void tvp5150_selmux(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 260 | { |
Paul Walmsley | 2962fc0 | 2010-10-09 01:31:40 -0300 | [diff] [blame] | 261 | int opmode = 0; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 262 | struct tvp5150 *decoder = to_tvp5150(sd); |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 263 | unsigned int mask, val; |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 264 | int input = 0; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 265 | |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 266 | /* Only tvp5150am1 and tvp5151 have signal generator support */ |
| 267 | if ((decoder->dev_id == 0x5150 && decoder->rom_ver == 0x0400) || |
| 268 | (decoder->dev_id == 0x5151 && decoder->rom_ver == 0x0100)) { |
| 269 | if (!decoder->enable) |
| 270 | input = 8; |
| 271 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 272 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 273 | switch (decoder->input) { |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 274 | case TVP5150_COMPOSITE1: |
| 275 | input |= 2; |
| 276 | /* fall through */ |
| 277 | case TVP5150_COMPOSITE0: |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 278 | break; |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 279 | case TVP5150_SVIDEO: |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 280 | default: |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 281 | input |= 1; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 282 | break; |
| 283 | } |
| 284 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 285 | dev_dbg_lvl(sd->dev, 1, debug, "Selecting video route: route input=%i, output=%i => tvp5150 input=%i, opmode=%i\n", |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 286 | decoder->input, decoder->output, |
| 287 | input, opmode); |
Mauro Carvalho Chehab | 12500f0 | 2006-08-18 07:31:10 -0300 | [diff] [blame] | 288 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 289 | regmap_write(decoder->regmap, TVP5150_OP_MODE_CTL, opmode); |
| 290 | regmap_write(decoder->regmap, TVP5150_VD_IN_SRC_SEL_1, input); |
Mauro Carvalho Chehab | f4b8b3a | 2007-11-03 22:40:24 -0300 | [diff] [blame] | 291 | |
Laurent Pinchart | b4b2de3 | 2016-12-09 09:47:18 -0200 | [diff] [blame] | 292 | /* |
| 293 | * Setup the FID/GLCO/VLK/HVLK and INTREQ/GPCL/VBLK output signals. For |
| 294 | * S-Video we output the vertical lock (VLK) signal on FID/GLCO/VLK/HVLK |
| 295 | * and set INTREQ/GPCL/VBLK to logic 0. For composite we output the |
| 296 | * field indicator (FID) signal on FID/GLCO/VLK/HVLK and set |
| 297 | * INTREQ/GPCL/VBLK to logic 1. |
Mauro Carvalho Chehab | f4b8b3a | 2007-11-03 22:40:24 -0300 | [diff] [blame] | 298 | */ |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 299 | mask = TVP5150_MISC_CTL_GPCL | TVP5150_MISC_CTL_HVLK; |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 300 | if (decoder->input == TVP5150_SVIDEO) |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 301 | val = TVP5150_MISC_CTL_HVLK; |
Mauro Carvalho Chehab | f4b8b3a | 2007-11-03 22:40:24 -0300 | [diff] [blame] | 302 | else |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 303 | val = TVP5150_MISC_CTL_GPCL; |
| 304 | regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 305 | }; |
| 306 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 307 | struct i2c_reg_value { |
| 308 | unsigned char reg; |
| 309 | unsigned char value; |
| 310 | }; |
| 311 | |
| 312 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 313 | static const struct i2c_reg_value tvp5150_init_default[] = { |
| 314 | { /* 0x00 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 315 | TVP5150_VD_IN_SRC_SEL_1, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 316 | }, |
| 317 | { /* 0x01 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 318 | TVP5150_ANAL_CHL_CTL, 0x15 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 319 | }, |
| 320 | { /* 0x02 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 321 | TVP5150_OP_MODE_CTL, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 322 | }, |
| 323 | { /* 0x03 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 324 | TVP5150_MISC_CTL, 0x01 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 325 | }, |
| 326 | { /* 0x06 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 327 | TVP5150_COLOR_KIL_THSH_CTL, 0x10 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 328 | }, |
| 329 | { /* 0x07 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 330 | TVP5150_LUMA_PROC_CTL_1, 0x60 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 331 | }, |
| 332 | { /* 0x08 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 333 | TVP5150_LUMA_PROC_CTL_2, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 334 | }, |
| 335 | { /* 0x09 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 336 | TVP5150_BRIGHT_CTL, 0x80 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 337 | }, |
| 338 | { /* 0x0a */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 339 | TVP5150_SATURATION_CTL, 0x80 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 340 | }, |
| 341 | { /* 0x0b */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 342 | TVP5150_HUE_CTL, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 343 | }, |
| 344 | { /* 0x0c */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 345 | TVP5150_CONTRAST_CTL, 0x80 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 346 | }, |
| 347 | { /* 0x0d */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 348 | TVP5150_DATA_RATE_SEL, 0x47 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 349 | }, |
| 350 | { /* 0x0e */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 351 | TVP5150_LUMA_PROC_CTL_3, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 352 | }, |
| 353 | { /* 0x0f */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 354 | TVP5150_CONF_SHARED_PIN, 0x08 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 355 | }, |
| 356 | { /* 0x11 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 357 | TVP5150_ACT_VD_CROP_ST_MSB, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 358 | }, |
| 359 | { /* 0x12 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 360 | TVP5150_ACT_VD_CROP_ST_LSB, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 361 | }, |
| 362 | { /* 0x13 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 363 | TVP5150_ACT_VD_CROP_STP_MSB, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 364 | }, |
| 365 | { /* 0x14 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 366 | TVP5150_ACT_VD_CROP_STP_LSB, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 367 | }, |
| 368 | { /* 0x15 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 369 | TVP5150_GENLOCK, 0x01 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 370 | }, |
| 371 | { /* 0x16 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 372 | TVP5150_HORIZ_SYNC_START, 0x80 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 373 | }, |
| 374 | { /* 0x18 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 375 | TVP5150_VERT_BLANKING_START, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 376 | }, |
| 377 | { /* 0x19 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 378 | TVP5150_VERT_BLANKING_STOP, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 379 | }, |
| 380 | { /* 0x1a */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 381 | TVP5150_CHROMA_PROC_CTL_1, 0x0c |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 382 | }, |
| 383 | { /* 0x1b */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 384 | TVP5150_CHROMA_PROC_CTL_2, 0x14 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 385 | }, |
| 386 | { /* 0x1c */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 387 | TVP5150_INT_RESET_REG_B, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 388 | }, |
| 389 | { /* 0x1d */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 390 | TVP5150_INT_ENABLE_REG_B, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 391 | }, |
| 392 | { /* 0x1e */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 393 | TVP5150_INTT_CONFIG_REG_B, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 394 | }, |
| 395 | { /* 0x28 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 396 | TVP5150_VIDEO_STD, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 397 | }, |
| 398 | { /* 0x2e */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 399 | TVP5150_MACROVISION_ON_CTR, 0x0f |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 400 | }, |
| 401 | { /* 0x2f */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 402 | TVP5150_MACROVISION_OFF_CTR, 0x01 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 403 | }, |
| 404 | { /* 0xbb */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 405 | TVP5150_TELETEXT_FIL_ENA, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 406 | }, |
| 407 | { /* 0xc0 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 408 | TVP5150_INT_STATUS_REG_A, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 409 | }, |
| 410 | { /* 0xc1 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 411 | TVP5150_INT_ENABLE_REG_A, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 412 | }, |
| 413 | { /* 0xc2 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 414 | TVP5150_INT_CONF, 0x04 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 415 | }, |
| 416 | { /* 0xc8 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 417 | TVP5150_FIFO_INT_THRESHOLD, 0x80 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 418 | }, |
| 419 | { /* 0xc9 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 420 | TVP5150_FIFO_RESET, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 421 | }, |
| 422 | { /* 0xca */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 423 | TVP5150_LINE_NUMBER_INT, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 424 | }, |
| 425 | { /* 0xcb */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 426 | TVP5150_PIX_ALIGN_REG_LOW, 0x4e |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 427 | }, |
| 428 | { /* 0xcc */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 429 | TVP5150_PIX_ALIGN_REG_HIGH, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 430 | }, |
| 431 | { /* 0xcd */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 432 | TVP5150_FIFO_OUT_CTRL, 0x01 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 433 | }, |
| 434 | { /* 0xcf */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 435 | TVP5150_FULL_FIELD_ENA, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 436 | }, |
| 437 | { /* 0xd0 */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 438 | TVP5150_LINE_MODE_INI, 0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 439 | }, |
| 440 | { /* 0xfc */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 441 | TVP5150_FULL_FIELD_MODE_REG, 0x7f |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 442 | }, |
| 443 | { /* end of data */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 444 | 0xff, 0xff |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 445 | } |
| 446 | }; |
| 447 | |
| 448 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 449 | static const struct i2c_reg_value tvp5150_init_enable[] = { |
Philipp Zabel | 8105e1b | 2018-06-28 12:20:43 -0400 | [diff] [blame] | 450 | { /* Automatic offset and AGC enabled */ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 451 | TVP5150_ANAL_CHL_CTL, 0x15 |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 452 | }, { /* Activate YCrCb output 0x9 or 0xd ? */ |
Laurent Pinchart | b4b2de3 | 2016-12-09 09:47:18 -0200 | [diff] [blame] | 453 | TVP5150_MISC_CTL, TVP5150_MISC_CTL_GPCL | |
| 454 | TVP5150_MISC_CTL_INTREQ_OE | |
| 455 | TVP5150_MISC_CTL_YCBCR_OE | |
| 456 | TVP5150_MISC_CTL_SYNC_OE | |
| 457 | TVP5150_MISC_CTL_VBLANK | |
| 458 | TVP5150_MISC_CTL_CLOCK_OE, |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 459 | }, { /* Activates video std autodetection for all standards */ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 460 | TVP5150_AUTOSW_MSK, 0x0 |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 461 | }, { /* Default format: 0x47. For 4:2:2: 0x40 */ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 462 | TVP5150_DATA_RATE_SEL, 0x47 |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 463 | }, { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 464 | TVP5150_CHROMA_PROC_CTL_1, 0x0c |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 465 | }, { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 466 | TVP5150_CHROMA_PROC_CTL_2, 0x54 |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 467 | }, { /* Non documented, but initialized on WinTV USB2 */ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 468 | 0x27, 0x20 |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 469 | }, { |
| 470 | 0xff, 0xff |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 471 | } |
| 472 | }; |
| 473 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 474 | struct tvp5150_vbi_type { |
| 475 | unsigned int vbi_type; |
| 476 | unsigned int ini_line; |
| 477 | unsigned int end_line; |
| 478 | unsigned int by_field :1; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 479 | }; |
| 480 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 481 | struct i2c_vbi_ram_value { |
| 482 | u16 reg; |
| 483 | struct tvp5150_vbi_type type; |
| 484 | unsigned char values[16]; |
| 485 | }; |
| 486 | |
| 487 | /* This struct have the values for each supported VBI Standard |
| 488 | * by |
| 489 | tvp5150_vbi_types should follow the same order as vbi_ram_default |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 490 | * value 0 means rom position 0x10, value 1 means rom position 0x30 |
| 491 | * and so on. There are 16 possible locations from 0 to 15. |
| 492 | */ |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 493 | |
Nasser Afshin | 65dc760 | 2018-04-02 18:23:19 -0400 | [diff] [blame] | 494 | static struct i2c_vbi_ram_value vbi_ram_default[] = { |
| 495 | |
Nasser Afshin | 9bfd8f8 | 2018-04-02 18:23:18 -0400 | [diff] [blame] | 496 | /* |
| 497 | * FIXME: Current api doesn't handle all VBI types, those not |
| 498 | * yet supported are placed under #if 0 |
| 499 | */ |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 500 | #if 0 |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 501 | [0] = {0x010, /* Teletext, SECAM, WST System A */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 502 | {V4L2_SLICED_TELETEXT_SECAM, 6, 23, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 503 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26, |
| 504 | 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 505 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 506 | #endif |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 507 | [1] = {0x030, /* Teletext, PAL, WST System B */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 508 | {V4L2_SLICED_TELETEXT_B, 6, 22, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 509 | { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b, |
| 510 | 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 511 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 512 | #if 0 |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 513 | [2] = {0x050, /* Teletext, PAL, WST System C */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 514 | {V4L2_SLICED_TELETEXT_PAL_C, 6, 22, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 515 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, |
| 516 | 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 517 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 518 | [3] = {0x070, /* Teletext, NTSC, WST System B */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 519 | {V4L2_SLICED_TELETEXT_NTSC_B, 10, 21, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 520 | { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23, |
| 521 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 522 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 523 | [4] = {0x090, /* Tetetext, NTSC NABTS System C */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 524 | {V4L2_SLICED_TELETEXT_NTSC_C, 10, 21, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 525 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, |
| 526 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 527 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 528 | [5] = {0x0b0, /* Teletext, NTSC-J, NABTS System D */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 529 | {V4L2_SLICED_TELETEXT_NTSC_D, 10, 21, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 530 | { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23, |
| 531 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 532 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 533 | [6] = {0x0d0, /* Closed Caption, PAL/SECAM */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 534 | {V4L2_SLICED_CAPTION_625, 22, 22, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 535 | { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, |
| 536 | 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 537 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 538 | #endif |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 539 | [7] = {0x0f0, /* Closed Caption, NTSC */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 540 | {V4L2_SLICED_CAPTION_525, 21, 21, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 541 | { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, |
| 542 | 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 543 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 544 | [8] = {0x110, /* Wide Screen Signal, PAL/SECAM */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 545 | {V4L2_SLICED_WSS_625, 23, 23, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 546 | { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42, |
| 547 | 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 548 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 549 | #if 0 |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 550 | [9] = {0x130, /* Wide Screen Signal, NTSC C */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 551 | {V4L2_SLICED_WSS_525, 20, 20, 1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 552 | { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43, |
| 553 | 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 554 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 555 | [10] = {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 556 | {V4l2_SLICED_VITC_625, 6, 22, 0}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 557 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, |
| 558 | 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 559 | }, |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 560 | [11] = {0x170, /* Vertical Interval Timecode (VITC), NTSC */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 561 | {V4l2_SLICED_VITC_525, 10, 20, 0}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 562 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, |
| 563 | 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 564 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 565 | #endif |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 566 | [12] = {0x190, /* Video Program System (VPS), PAL */ |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 567 | {V4L2_SLICED_VPS, 16, 16, 0}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 568 | { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, |
| 569 | 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 } |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 570 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 571 | /* 0x1d0 User programmable */ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 572 | }; |
| 573 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 574 | static int tvp5150_write_inittab(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 575 | const struct i2c_reg_value *regs) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 576 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 577 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 578 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 579 | while (regs->reg != 0xff) { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 580 | regmap_write(decoder->regmap, regs->reg, regs->value); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 581 | regs++; |
| 582 | } |
| 583 | return 0; |
| 584 | } |
| 585 | |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 586 | static int tvp5150_vdp_init(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 587 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 588 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 589 | struct regmap *map = decoder->regmap; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 590 | unsigned int i; |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 591 | int j; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 592 | |
| 593 | /* Disable Full Field */ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 594 | regmap_write(map, TVP5150_FULL_FIELD_ENA, 0); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 595 | |
| 596 | /* Before programming, Line mode should be at 0xff */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 597 | for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 598 | regmap_write(map, i, 0xff); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 599 | |
| 600 | /* Load Ram Table */ |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 601 | for (j = 0; j < ARRAY_SIZE(vbi_ram_default); j++) { |
| 602 | const struct i2c_vbi_ram_value *regs = &vbi_ram_default[j]; |
| 603 | |
| 604 | if (!regs->type.vbi_type) |
| 605 | continue; |
| 606 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 607 | regmap_write(map, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8); |
| 608 | regmap_write(map, TVP5150_CONF_RAM_ADDR_LOW, regs->reg); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 609 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 610 | for (i = 0; i < 16; i++) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 611 | regmap_write(map, TVP5150_VDP_CONF_RAM_DATA, |
| 612 | regs->values[i]); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 613 | } |
| 614 | return 0; |
| 615 | } |
| 616 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 617 | /* Fills VBI capabilities based on i2c_vbi_ram_value struct */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 618 | static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 619 | struct v4l2_sliced_vbi_cap *cap) |
| 620 | { |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 621 | int line, i; |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 622 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 623 | dev_dbg_lvl(sd->dev, 1, debug, "g_sliced_vbi_cap\n"); |
Nasser Afshin | bb7a368 | 2018-04-02 18:23:20 -0400 | [diff] [blame] | 624 | memset(cap, 0, sizeof(*cap)); |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 625 | |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 626 | for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) { |
| 627 | const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i]; |
| 628 | |
| 629 | if (!regs->type.vbi_type) |
| 630 | continue; |
| 631 | |
| 632 | for (line = regs->type.ini_line; |
| 633 | line <= regs->type.end_line; |
| 634 | line++) { |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 635 | cap->service_lines[0][line] |= regs->type.vbi_type; |
| 636 | } |
| 637 | cap->service_set |= regs->type.vbi_type; |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 638 | } |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 639 | return 0; |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 640 | } |
| 641 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 642 | /* Set vbi processing |
| 643 | * type - one of tvp5150_vbi_types |
| 644 | * line - line to gather data |
| 645 | * fields: bit 0 field1, bit 1, field2 |
| 646 | * flags (default=0xf0) is a bitmask, were set means: |
| 647 | * bit 7: enable filtering null bytes on CC |
| 648 | * bit 6: send data also to FIFO |
| 649 | * bit 5: don't allow data with errors on FIFO |
| 650 | * bit 4: enable ECC when possible |
| 651 | * pix_align = pix alignment: |
| 652 | * LSB = field1 |
| 653 | * MSB = field2 |
| 654 | */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 655 | static int tvp5150_set_vbi(struct v4l2_subdev *sd, |
Nasser Afshin | 4efcd5e | 2018-04-02 18:23:17 -0400 | [diff] [blame] | 656 | unsigned int type, u8 flags, int line, |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 657 | const int fields) |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 658 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 659 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 660 | v4l2_std_id std = decoder->norm; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 661 | u8 reg; |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 662 | int i, pos = 0; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 663 | |
| 664 | if (std == V4L2_STD_ALL) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 665 | dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n"); |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 666 | return 0; |
Roel Kluin | 7d5b7b9 | 2008-03-09 21:19:13 -0300 | [diff] [blame] | 667 | } else if (std & V4L2_STD_625_50) { |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 668 | /* Don't follow NTSC Line number convension */ |
| 669 | line += 3; |
| 670 | } |
| 671 | |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 672 | if (line < 6 || line > 27) |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 673 | return 0; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 674 | |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 675 | for (i = 0; i < ARRAY_SIZE(vbi_ram_default); i++) { |
| 676 | const struct i2c_vbi_ram_value *regs = &vbi_ram_default[i]; |
| 677 | |
| 678 | if (!regs->type.vbi_type) |
| 679 | continue; |
| 680 | |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 681 | if ((type & regs->type.vbi_type) && |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 682 | (line >= regs->type.ini_line) && |
| 683 | (line <= regs->type.end_line)) |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 684 | break; |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 685 | pos++; |
| 686 | } |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 687 | |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 688 | type = pos | (flags & 0xf0); |
| 689 | reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 690 | |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 691 | if (fields & 1) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 692 | regmap_write(decoder->regmap, reg, type); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 693 | |
Gustavo A. R. Silva | b3d930aa | 2017-06-23 19:37:00 -0300 | [diff] [blame] | 694 | if (fields & 2) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 695 | regmap_write(decoder->regmap, reg + 1, type); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 696 | |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 697 | return type; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 698 | } |
| 699 | |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 700 | static int tvp5150_get_vbi(struct v4l2_subdev *sd, int line) |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 701 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 702 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 703 | v4l2_std_id std = decoder->norm; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 704 | u8 reg; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 705 | int pos, type = 0; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 706 | int i, ret = 0; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 707 | |
| 708 | if (std == V4L2_STD_ALL) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 709 | dev_err(sd->dev, "VBI can't be configured without knowing number of lines\n"); |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 710 | return 0; |
Roel Kluin | 7d5b7b9 | 2008-03-09 21:19:13 -0300 | [diff] [blame] | 711 | } else if (std & V4L2_STD_625_50) { |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 712 | /* Don't follow NTSC Line number convension */ |
| 713 | line += 3; |
| 714 | } |
| 715 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 716 | if (line < 6 || line > 27) |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 717 | return 0; |
| 718 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 719 | reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 720 | |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 721 | for (i = 0; i <= 1; i++) { |
| 722 | ret = tvp5150_read(sd, reg + i); |
| 723 | if (ret < 0) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 724 | dev_err(sd->dev, "%s: failed with error = %d\n", |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 725 | __func__, ret); |
| 726 | return 0; |
| 727 | } |
| 728 | pos = ret & 0x0f; |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 729 | if (pos < ARRAY_SIZE(vbi_ram_default)) |
| 730 | type |= vbi_ram_default[pos].type.vbi_type; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 731 | } |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 732 | |
| 733 | return type; |
| 734 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 735 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 736 | static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 737 | { |
| 738 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 739 | int fmt = 0; |
| 740 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 741 | /* First tests should be against specific std */ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 742 | |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 743 | if (std == V4L2_STD_NTSC_443) { |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 744 | fmt = VIDEO_STD_NTSC_4_43_BIT; |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 745 | } else if (std == V4L2_STD_PAL_M) { |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 746 | fmt = VIDEO_STD_PAL_M_BIT; |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 747 | } else if (std == V4L2_STD_PAL_N || std == V4L2_STD_PAL_Nc) { |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 748 | fmt = VIDEO_STD_PAL_COMBINATION_N_BIT; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 749 | } else { |
| 750 | /* Then, test against generic ones */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 751 | if (std & V4L2_STD_NTSC) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 752 | fmt = VIDEO_STD_NTSC_MJ_BIT; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 753 | else if (std & V4L2_STD_PAL) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 754 | fmt = VIDEO_STD_PAL_BDGHIN_BIT; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 755 | else if (std & V4L2_STD_SECAM) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 756 | fmt = VIDEO_STD_SECAM_BIT; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 757 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 758 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 759 | dev_dbg_lvl(sd->dev, 1, debug, "Set video std register to %d.\n", fmt); |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 760 | regmap_write(decoder->regmap, TVP5150_VIDEO_STD, fmt); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 761 | return 0; |
| 762 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 763 | |
Marco Felsch | 0db87cc | 2018-06-28 12:20:49 -0400 | [diff] [blame] | 764 | static int tvp5150_g_std(struct v4l2_subdev *sd, v4l2_std_id *std) |
| 765 | { |
| 766 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 767 | |
| 768 | *std = decoder->norm; |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 773 | static int tvp5150_s_std(struct v4l2_subdev *sd, v4l2_std_id std) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 774 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 775 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 776 | |
| 777 | if (decoder->norm == std) |
| 778 | return 0; |
| 779 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 780 | /* Change cropping height limits */ |
| 781 | if (std & V4L2_STD_525_60) |
| 782 | decoder->rect.height = TVP5150_V_MAX_525_60; |
| 783 | else |
| 784 | decoder->rect.height = TVP5150_V_MAX_OTHERS; |
| 785 | |
Philipp Zabel | 1569586 | 2018-06-28 12:20:41 -0400 | [diff] [blame] | 786 | decoder->norm = std; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 787 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 788 | return tvp5150_set_std(sd, std); |
| 789 | } |
| 790 | |
Philipp Zabel | 1569586 | 2018-06-28 12:20:41 -0400 | [diff] [blame] | 791 | static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd) |
| 792 | { |
| 793 | int val = tvp5150_read(sd, TVP5150_STATUS_REG_5); |
| 794 | |
| 795 | switch (val & 0x0F) { |
| 796 | case 0x01: |
| 797 | return V4L2_STD_NTSC; |
| 798 | case 0x03: |
| 799 | return V4L2_STD_PAL; |
| 800 | case 0x05: |
| 801 | return V4L2_STD_PAL_M; |
| 802 | case 0x07: |
| 803 | return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc; |
| 804 | case 0x09: |
| 805 | return V4L2_STD_NTSC_443; |
| 806 | case 0xb: |
| 807 | return V4L2_STD_SECAM; |
| 808 | default: |
| 809 | return V4L2_STD_UNKNOWN; |
| 810 | } |
| 811 | } |
| 812 | |
Philipp Zabel | ee9a6ff | 2018-06-28 12:20:48 -0400 | [diff] [blame^] | 813 | static int tvp5150_querystd(struct v4l2_subdev *sd, v4l2_std_id *std_id) |
| 814 | { |
| 815 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 816 | |
| 817 | *std_id = decoder->lock ? tvp5150_read_std(sd) : V4L2_STD_UNKNOWN; |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Philipp Zabel | 2f0a5c6 | 2018-06-28 12:20:46 -0400 | [diff] [blame] | 822 | static const struct v4l2_event tvp5150_ev_fmt = { |
| 823 | .type = V4L2_EVENT_SOURCE_CHANGE, |
| 824 | .u.src_change.changes = V4L2_EVENT_SRC_CH_RESOLUTION, |
| 825 | }; |
| 826 | |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 827 | static irqreturn_t tvp5150_isr(int irq, void *dev_id) |
| 828 | { |
| 829 | struct tvp5150 *decoder = dev_id; |
| 830 | struct regmap *map = decoder->regmap; |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 831 | unsigned int mask, active = 0, status = 0; |
| 832 | |
| 833 | mask = TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE | |
| 834 | TVP5150_MISC_CTL_CLOCK_OE; |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 835 | |
| 836 | regmap_read(map, TVP5150_INT_STATUS_REG_A, &status); |
| 837 | if (status) { |
| 838 | regmap_write(map, TVP5150_INT_STATUS_REG_A, status); |
| 839 | |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 840 | if (status & TVP5150_INT_A_LOCK) { |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 841 | decoder->lock = !!(status & TVP5150_INT_A_LOCK_STATUS); |
Philipp Zabel | 7bb3c33 | 2018-06-28 12:20:47 -0400 | [diff] [blame] | 842 | dev_dbg_lvl(decoder->sd.dev, 1, debug, |
| 843 | "sync lo%s signal\n", |
| 844 | decoder->lock ? "ck" : "ss"); |
Philipp Zabel | 2f0a5c6 | 2018-06-28 12:20:46 -0400 | [diff] [blame] | 845 | v4l2_subdev_notify_event(&decoder->sd, &tvp5150_ev_fmt); |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 846 | regmap_update_bits(map, TVP5150_MISC_CTL, mask, |
| 847 | decoder->lock ? decoder->oe : 0); |
| 848 | } |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 849 | |
| 850 | return IRQ_HANDLED; |
| 851 | } |
| 852 | |
| 853 | regmap_read(map, TVP5150_INT_ACTIVE_REG_B, &active); |
| 854 | if (active) { |
| 855 | status = 0; |
| 856 | regmap_read(map, TVP5150_INT_STATUS_REG_B, &status); |
| 857 | if (status) |
| 858 | regmap_write(map, TVP5150_INT_RESET_REG_B, status); |
| 859 | } |
| 860 | |
| 861 | return IRQ_HANDLED; |
| 862 | } |
| 863 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 864 | static int tvp5150_reset(struct v4l2_subdev *sd, u32 val) |
| 865 | { |
| 866 | struct tvp5150 *decoder = to_tvp5150(sd); |
Philipp Zabel | 8105e1b | 2018-06-28 12:20:43 -0400 | [diff] [blame] | 867 | struct regmap *map = decoder->regmap; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 868 | |
| 869 | /* Initializes TVP5150 to its default values */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 870 | tvp5150_write_inittab(sd, tvp5150_init_default); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 871 | |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 872 | if (decoder->irq) { |
| 873 | /* Configure pins: FID, VSYNC, INTREQ, SCLK */ |
| 874 | regmap_write(map, TVP5150_CONF_SHARED_PIN, 0x0); |
| 875 | /* Set interrupt polarity to active high */ |
| 876 | regmap_write(map, TVP5150_INT_CONF, TVP5150_VDPOE | 0x1); |
| 877 | regmap_write(map, TVP5150_INTT_CONFIG_REG_B, 0x1); |
| 878 | } else { |
| 879 | /* Configure pins: FID, VSYNC, GPCL/VBLK, SCLK */ |
| 880 | regmap_write(map, TVP5150_CONF_SHARED_PIN, 0x2); |
| 881 | /* Keep interrupt polarity active low */ |
| 882 | regmap_write(map, TVP5150_INT_CONF, TVP5150_VDPOE); |
| 883 | regmap_write(map, TVP5150_INTT_CONFIG_REG_B, 0x0); |
| 884 | } |
Philipp Zabel | 8105e1b | 2018-06-28 12:20:43 -0400 | [diff] [blame] | 885 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 886 | /* Initializes VDP registers */ |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 887 | tvp5150_vdp_init(sd); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 888 | |
| 889 | /* Selects decoder input */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 890 | tvp5150_selmux(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 891 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 892 | /* Initialize image preferences */ |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 893 | v4l2_ctrl_handler_setup(&decoder->hdl); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 894 | |
Philipp Zabel | 1bb086b | 2018-06-28 12:20:42 -0400 | [diff] [blame] | 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | static int tvp5150_enable(struct v4l2_subdev *sd) |
| 899 | { |
| 900 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 901 | v4l2_std_id std; |
| 902 | |
| 903 | /* Initializes TVP5150 to stream enabled values */ |
| 904 | tvp5150_write_inittab(sd, tvp5150_init_enable); |
| 905 | |
Philipp Zabel | 1569586 | 2018-06-28 12:20:41 -0400 | [diff] [blame] | 906 | if (decoder->norm == V4L2_STD_ALL) |
| 907 | std = tvp5150_read_std(sd); |
| 908 | else |
| 909 | std = decoder->norm; |
| 910 | |
| 911 | /* Disable autoswitch mode */ |
| 912 | tvp5150_set_std(sd, std); |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 913 | |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 914 | /* |
| 915 | * Enable the YCbCr and clock outputs. In discrete sync mode |
| 916 | * (non-BT.656) additionally enable the the sync outputs. |
| 917 | */ |
| 918 | switch (decoder->mbus_type) { |
| 919 | case V4L2_MBUS_PARALLEL: |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 920 | /* 8-bit 4:2:2 YUV with discrete sync output */ |
| 921 | regmap_update_bits(decoder->regmap, TVP5150_DATA_RATE_SEL, |
| 922 | 0x7, 0x0); |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 923 | decoder->oe = TVP5150_MISC_CTL_YCBCR_OE | |
| 924 | TVP5150_MISC_CTL_CLOCK_OE | |
| 925 | TVP5150_MISC_CTL_SYNC_OE; |
| 926 | break; |
| 927 | case V4L2_MBUS_BT656: |
| 928 | decoder->oe = TVP5150_MISC_CTL_YCBCR_OE | |
| 929 | TVP5150_MISC_CTL_CLOCK_OE; |
| 930 | break; |
| 931 | default: |
| 932 | return -EINVAL; |
| 933 | } |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 934 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 935 | return 0; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 936 | }; |
| 937 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 938 | static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 939 | { |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 940 | struct v4l2_subdev *sd = to_sd(ctrl); |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 941 | struct tvp5150 *decoder = to_tvp5150(sd); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 942 | |
| 943 | switch (ctrl->id) { |
| 944 | case V4L2_CID_BRIGHTNESS: |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 945 | regmap_write(decoder->regmap, TVP5150_BRIGHT_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 946 | return 0; |
| 947 | case V4L2_CID_CONTRAST: |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 948 | regmap_write(decoder->regmap, TVP5150_CONTRAST_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 949 | return 0; |
| 950 | case V4L2_CID_SATURATION: |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 951 | regmap_write(decoder->regmap, TVP5150_SATURATION_CTL, |
| 952 | ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 953 | return 0; |
| 954 | case V4L2_CID_HUE: |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 955 | regmap_write(decoder->regmap, TVP5150_HUE_CTL, ctrl->val); |
Marco Felsch | 2d29bcc | 2018-06-28 12:20:34 -0400 | [diff] [blame] | 956 | return 0; |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 957 | case V4L2_CID_TEST_PATTERN: |
| 958 | decoder->enable = ctrl->val ? false : true; |
| 959 | tvp5150_selmux(sd); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 960 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 961 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 962 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 965 | static void tvp5150_set_default(v4l2_std_id std, struct v4l2_rect *crop) |
| 966 | { |
| 967 | /* Default is no cropping */ |
| 968 | crop->top = 0; |
| 969 | crop->left = 0; |
| 970 | crop->width = TVP5150_H_MAX; |
| 971 | if (std & V4L2_STD_525_60) |
| 972 | crop->height = TVP5150_V_MAX_525_60; |
| 973 | else |
| 974 | crop->height = TVP5150_V_MAX_OTHERS; |
| 975 | } |
| 976 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 977 | static int tvp5150_fill_fmt(struct v4l2_subdev *sd, |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 978 | struct v4l2_subdev_pad_config *cfg, |
| 979 | struct v4l2_subdev_format *format) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 980 | { |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 981 | struct v4l2_mbus_framefmt *f; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 982 | struct tvp5150 *decoder = to_tvp5150(sd); |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 983 | |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 984 | if (!format || (format->pad != TVP5150_PAD_VID_OUT)) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 985 | return -EINVAL; |
| 986 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 987 | f = &format->format; |
| 988 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 989 | f->width = decoder->rect.width; |
Javier Martinez Canillas | 1831af0 | 2018-06-10 16:43:02 -0400 | [diff] [blame] | 990 | f->height = decoder->rect.height / 2; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 991 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 992 | f->code = TVP5150_MBUS_FMT; |
| 993 | f->field = TVP5150_FIELD; |
| 994 | f->colorspace = TVP5150_COLORSPACE; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 995 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 996 | dev_dbg_lvl(sd->dev, 1, debug, "width = %d, height = %d\n", f->width, |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 997 | f->height); |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 998 | return 0; |
| 999 | } |
| 1000 | |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1001 | static int tvp5150_set_selection(struct v4l2_subdev *sd, |
| 1002 | struct v4l2_subdev_pad_config *cfg, |
| 1003 | struct v4l2_subdev_selection *sel) |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1004 | { |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1005 | struct tvp5150 *decoder = to_tvp5150(sd); |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1006 | struct v4l2_rect rect = sel->r; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1007 | v4l2_std_id std; |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1008 | int hmax; |
| 1009 | |
| 1010 | if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE || |
| 1011 | sel->target != V4L2_SEL_TGT_CROP) |
| 1012 | return -EINVAL; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1013 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1014 | dev_dbg_lvl(sd->dev, 1, debug, "%s left=%d, top=%d, width=%d, height=%d\n", |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1015 | __func__, rect.left, rect.top, rect.width, rect.height); |
| 1016 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1017 | /* tvp5150 has some special limits */ |
| 1018 | rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1019 | rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP); |
| 1020 | |
| 1021 | /* Calculate height based on current standard */ |
| 1022 | if (decoder->norm == V4L2_STD_ALL) |
| 1023 | std = tvp5150_read_std(sd); |
| 1024 | else |
| 1025 | std = decoder->norm; |
| 1026 | |
| 1027 | if (std & V4L2_STD_525_60) |
| 1028 | hmax = TVP5150_V_MAX_525_60; |
| 1029 | else |
| 1030 | hmax = TVP5150_V_MAX_OTHERS; |
| 1031 | |
Marco Felsch | bd24db0 | 2018-06-28 12:20:33 -0400 | [diff] [blame] | 1032 | /* |
| 1033 | * alignments: |
| 1034 | * - width = 2 due to UYVY colorspace |
| 1035 | * - height, image = no special alignment |
| 1036 | */ |
| 1037 | v4l_bound_align_image(&rect.width, |
| 1038 | TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left, |
| 1039 | TVP5150_H_MAX - rect.left, 1, &rect.height, |
Ricardo Ribalda | f90580c | 2013-11-26 05:31:42 -0300 | [diff] [blame] | 1040 | hmax - TVP5150_MAX_CROP_TOP - rect.top, |
Marco Felsch | bd24db0 | 2018-06-28 12:20:33 -0400 | [diff] [blame] | 1041 | hmax - rect.top, 0, 0); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1042 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1043 | regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START, rect.top); |
| 1044 | regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP, |
| 1045 | rect.top + rect.height - hmax); |
| 1046 | regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_MSB, |
| 1047 | rect.left >> TVP5150_CROP_SHIFT); |
| 1048 | regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_ST_LSB, |
| 1049 | rect.left | (1 << TVP5150_CROP_SHIFT)); |
| 1050 | regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_MSB, |
| 1051 | (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >> |
| 1052 | TVP5150_CROP_SHIFT); |
| 1053 | regmap_write(decoder->regmap, TVP5150_ACT_VD_CROP_STP_LSB, |
| 1054 | rect.left + rect.width - TVP5150_MAX_CROP_LEFT); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1055 | |
| 1056 | decoder->rect = rect; |
| 1057 | |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1061 | static int tvp5150_get_selection(struct v4l2_subdev *sd, |
| 1062 | struct v4l2_subdev_pad_config *cfg, |
| 1063 | struct v4l2_subdev_selection *sel) |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1064 | { |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1065 | struct tvp5150 *decoder = container_of(sd, struct tvp5150, sd); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1066 | v4l2_std_id std; |
| 1067 | |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1068 | if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1069 | return -EINVAL; |
| 1070 | |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1071 | switch (sel->target) { |
| 1072 | case V4L2_SEL_TGT_CROP_BOUNDS: |
| 1073 | case V4L2_SEL_TGT_CROP_DEFAULT: |
| 1074 | sel->r.left = 0; |
| 1075 | sel->r.top = 0; |
| 1076 | sel->r.width = TVP5150_H_MAX; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1077 | |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1078 | /* Calculate height based on current standard */ |
| 1079 | if (decoder->norm == V4L2_STD_ALL) |
| 1080 | std = tvp5150_read_std(sd); |
| 1081 | else |
| 1082 | std = decoder->norm; |
| 1083 | if (std & V4L2_STD_525_60) |
| 1084 | sel->r.height = TVP5150_V_MAX_525_60; |
| 1085 | else |
| 1086 | sel->r.height = TVP5150_V_MAX_OTHERS; |
| 1087 | return 0; |
| 1088 | case V4L2_SEL_TGT_CROP: |
| 1089 | sel->r = decoder->rect; |
| 1090 | return 0; |
| 1091 | default: |
| 1092 | return -EINVAL; |
| 1093 | } |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1094 | } |
| 1095 | |
Laurent Pinchart | dd3a46b | 2016-01-07 10:46:46 -0200 | [diff] [blame] | 1096 | static int tvp5150_g_mbus_config(struct v4l2_subdev *sd, |
| 1097 | struct v4l2_mbus_config *cfg) |
| 1098 | { |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1099 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1100 | |
| 1101 | cfg->type = decoder->mbus_type; |
Laurent Pinchart | dd3a46b | 2016-01-07 10:46:46 -0200 | [diff] [blame] | 1102 | cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
| 1103 | | V4L2_MBUS_FIELD_EVEN_LOW | V4L2_MBUS_DATA_ACTIVE_HIGH; |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1108 | /**************************************************************************** |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1109 | V4L2 subdev pad ops |
| 1110 | ****************************************************************************/ |
Philipp Zabel | b440b73 | 2018-06-28 12:20:40 -0400 | [diff] [blame] | 1111 | static int tvp5150_init_cfg(struct v4l2_subdev *sd, |
| 1112 | struct v4l2_subdev_pad_config *cfg) |
| 1113 | { |
| 1114 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1115 | v4l2_std_id std; |
| 1116 | |
| 1117 | /* |
| 1118 | * Reset selection to maximum on subdev_open() if autodetection is on |
| 1119 | * and a standard change is detected. |
| 1120 | */ |
| 1121 | if (decoder->norm == V4L2_STD_ALL) { |
| 1122 | std = tvp5150_read_std(sd); |
| 1123 | if (std != decoder->detected_norm) { |
| 1124 | decoder->detected_norm = std; |
| 1125 | tvp5150_set_default(std, &decoder->rect); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1132 | static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd, |
| 1133 | struct v4l2_subdev_pad_config *cfg, |
| 1134 | struct v4l2_subdev_mbus_code_enum *code) |
| 1135 | { |
| 1136 | if (code->pad || code->index) |
| 1137 | return -EINVAL; |
| 1138 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 1139 | code->code = TVP5150_MBUS_FMT; |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1140 | return 0; |
| 1141 | } |
| 1142 | |
| 1143 | static int tvp5150_enum_frame_size(struct v4l2_subdev *sd, |
| 1144 | struct v4l2_subdev_pad_config *cfg, |
| 1145 | struct v4l2_subdev_frame_size_enum *fse) |
| 1146 | { |
| 1147 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1148 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 1149 | if (fse->index >= 8 || fse->code != TVP5150_MBUS_FMT) |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1150 | return -EINVAL; |
| 1151 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 1152 | fse->code = TVP5150_MBUS_FMT; |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1153 | fse->min_width = decoder->rect.width; |
| 1154 | fse->max_width = decoder->rect.width; |
| 1155 | fse->min_height = decoder->rect.height / 2; |
| 1156 | fse->max_height = decoder->rect.height / 2; |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | /**************************************************************************** |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1162 | Media entity ops |
| 1163 | ****************************************************************************/ |
| 1164 | |
Laurent Pinchart | 406ff67 | 2016-12-08 20:22:41 -0200 | [diff] [blame] | 1165 | #ifdef CONFIG_MEDIA_CONTROLLER |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1166 | static int tvp5150_link_setup(struct media_entity *entity, |
| 1167 | const struct media_pad *local, |
| 1168 | const struct media_pad *remote, u32 flags) |
| 1169 | { |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1170 | struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); |
| 1171 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1172 | int i; |
| 1173 | |
| 1174 | for (i = 0; i < TVP5150_INPUT_NUM; i++) { |
| 1175 | if (remote->entity == &decoder->input_ent[i]) |
| 1176 | break; |
| 1177 | } |
| 1178 | |
| 1179 | /* Do nothing for entities that are not input connectors */ |
| 1180 | if (i == TVP5150_INPUT_NUM) |
| 1181 | return 0; |
| 1182 | |
| 1183 | decoder->input = i; |
| 1184 | |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1185 | tvp5150_selmux(sd); |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1186 | |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | static const struct media_entity_operations tvp5150_sd_media_ops = { |
| 1191 | .link_setup = tvp5150_link_setup, |
| 1192 | }; |
Laurent Pinchart | 406ff67 | 2016-12-08 20:22:41 -0200 | [diff] [blame] | 1193 | #endif |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1194 | |
| 1195 | /**************************************************************************** |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1196 | I2C Command |
| 1197 | ****************************************************************************/ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1198 | |
Laurent Pinchart | 460b6c0 | 2016-01-07 10:46:45 -0200 | [diff] [blame] | 1199 | static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable) |
| 1200 | { |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1201 | struct tvp5150 *decoder = to_tvp5150(sd); |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 1202 | unsigned int mask, val = 0, int_val = 0; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1203 | |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 1204 | mask = TVP5150_MISC_CTL_YCBCR_OE | TVP5150_MISC_CTL_SYNC_OE | |
| 1205 | TVP5150_MISC_CTL_CLOCK_OE; |
Laurent Pinchart | 460b6c0 | 2016-01-07 10:46:45 -0200 | [diff] [blame] | 1206 | |
Laurent Pinchart | 79d6205 | 2016-12-09 09:47:19 -0200 | [diff] [blame] | 1207 | if (enable) { |
Philipp Zabel | 1bb086b | 2018-06-28 12:20:42 -0400 | [diff] [blame] | 1208 | tvp5150_enable(sd); |
| 1209 | |
Philipp Zabel | 62a764e | 2018-06-28 12:20:45 -0400 | [diff] [blame] | 1210 | /* Enable outputs if decoder is locked */ |
| 1211 | val = decoder->lock ? decoder->oe : 0; |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 1212 | int_val = TVP5150_INT_A_LOCK; |
Philipp Zabel | 2f0a5c6 | 2018-06-28 12:20:46 -0400 | [diff] [blame] | 1213 | v4l2_subdev_notify_event(&decoder->sd, &tvp5150_ev_fmt); |
Laurent Pinchart | 79d6205 | 2016-12-09 09:47:19 -0200 | [diff] [blame] | 1214 | } |
| 1215 | |
Marco Felsch | 8a7441b | 2018-06-28 12:20:36 -0400 | [diff] [blame] | 1216 | regmap_update_bits(decoder->regmap, TVP5150_MISC_CTL, mask, val); |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 1217 | if (decoder->irq) |
| 1218 | /* Enable / Disable lock interrupt */ |
| 1219 | regmap_update_bits(decoder->regmap, TVP5150_INT_ENABLE_REG_A, |
| 1220 | TVP5150_INT_A_LOCK, int_val); |
Laurent Pinchart | 460b6c0 | 2016-01-07 10:46:45 -0200 | [diff] [blame] | 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1225 | static int tvp5150_s_routing(struct v4l2_subdev *sd, |
| 1226 | u32 input, u32 output, u32 config) |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1227 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1228 | struct tvp5150 *decoder = to_tvp5150(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1229 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1230 | decoder->input = input; |
| 1231 | decoder->output = output; |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 1232 | |
| 1233 | if (output == TVP5150_BLACK_SCREEN) |
| 1234 | decoder->enable = false; |
| 1235 | else |
| 1236 | decoder->enable = true; |
| 1237 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1238 | tvp5150_selmux(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1239 | return 0; |
| 1240 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1241 | |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1242 | static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1243 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1244 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1245 | |
Nasser Afshin | 9bfd8f8 | 2018-04-02 18:23:18 -0400 | [diff] [blame] | 1246 | /* |
| 1247 | * this is for capturing 36 raw vbi lines |
| 1248 | * if there's a way to cut off the beginning 2 vbi lines |
| 1249 | * with the tvp5150 then the vbi line count could be lowered |
| 1250 | * to 17 lines/field again, although I couldn't find a register |
| 1251 | * which could do that cropping |
| 1252 | */ |
| 1253 | |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1254 | if (fmt->sample_format == V4L2_PIX_FMT_GREY) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1255 | regmap_write(decoder->regmap, TVP5150_LUMA_PROC_CTL_1, 0x70); |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1256 | if (fmt->count[0] == 18 && fmt->count[1] == 18) { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1257 | regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_START, |
| 1258 | 0x00); |
| 1259 | regmap_write(decoder->regmap, TVP5150_VERT_BLANKING_STOP, 0x01); |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1260 | } |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
| 1264 | static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi) |
| 1265 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1266 | struct tvp5150 *decoder = to_tvp5150(sd); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1267 | int i; |
| 1268 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1269 | if (svbi->service_set != 0) { |
| 1270 | for (i = 0; i <= 23; i++) { |
| 1271 | svbi->service_lines[1][i] = 0; |
| 1272 | svbi->service_lines[0][i] = |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 1273 | tvp5150_set_vbi(sd, svbi->service_lines[0][i], |
| 1274 | 0xf0, i, 3); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1275 | } |
| 1276 | /* Enables FIFO */ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1277 | regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 1); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1278 | } else { |
| 1279 | /* Disables FIFO*/ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1280 | regmap_write(decoder->regmap, TVP5150_FIFO_OUT_CTRL, 0); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1281 | |
| 1282 | /* Disable Full Field */ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1283 | regmap_write(decoder->regmap, TVP5150_FULL_FIELD_ENA, 0); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1284 | |
| 1285 | /* Disable Line modes */ |
| 1286 | for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++) |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1287 | regmap_write(decoder->regmap, i, 0xff); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1288 | } |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1292 | static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi) |
| 1293 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1294 | int i, mask = 0; |
| 1295 | |
Hans Verkuil | 30634e8 | 2012-09-05 10:38:10 -0300 | [diff] [blame] | 1296 | memset(svbi->service_lines, 0, sizeof(svbi->service_lines)); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1297 | |
| 1298 | for (i = 0; i <= 23; i++) { |
| 1299 | svbi->service_lines[0][i] = |
Mauro Carvalho Chehab | 3dd6b56 | 2018-02-19 13:23:39 -0500 | [diff] [blame] | 1300 | tvp5150_get_vbi(sd, i); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1301 | mask |= svbi->service_lines[0][i]; |
| 1302 | } |
| 1303 | svbi->service_set = mask; |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1307 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1308 | static int tvp5150_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1309 | { |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1310 | int res; |
| 1311 | |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1312 | res = tvp5150_read(sd, reg->reg & 0xff); |
| 1313 | if (res < 0) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1314 | dev_err(sd->dev, "%s: failed with error = %d\n", __func__, res); |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1315 | return res; |
| 1316 | } |
| 1317 | |
| 1318 | reg->val = res; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1319 | reg->size = 1; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | |
Hans Verkuil | 977ba3b1 | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1323 | static int tvp5150_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1324 | { |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1325 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1326 | |
| 1327 | return regmap_write(decoder->regmap, reg->reg & 0xff, reg->val & 0xff); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1328 | } |
| 1329 | #endif |
| 1330 | |
| 1331 | static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) |
| 1332 | { |
| 1333 | int status = tvp5150_read(sd, 0x88); |
| 1334 | |
| 1335 | vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0; |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
Javier Martinez Canillas | 5a08bc0 | 2016-08-11 13:28:15 -0300 | [diff] [blame] | 1339 | static int tvp5150_registered(struct v4l2_subdev *sd) |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1340 | { |
| 1341 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1342 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 1343 | int ret = 0; |
| 1344 | int i; |
| 1345 | |
| 1346 | for (i = 0; i < TVP5150_INPUT_NUM; i++) { |
| 1347 | struct media_entity *input = &decoder->input_ent[i]; |
| 1348 | struct media_pad *pad = &decoder->input_pad[i]; |
| 1349 | |
| 1350 | if (!input->name) |
| 1351 | continue; |
| 1352 | |
| 1353 | decoder->input_pad[i].flags = MEDIA_PAD_FL_SOURCE; |
| 1354 | |
| 1355 | ret = media_entity_pads_init(input, 1, pad); |
| 1356 | if (ret < 0) |
| 1357 | return ret; |
| 1358 | |
| 1359 | ret = media_device_register_entity(sd->v4l2_dev->mdev, input); |
| 1360 | if (ret < 0) |
| 1361 | return ret; |
| 1362 | |
| 1363 | ret = media_create_pad_link(input, 0, &sd->entity, |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 1364 | TVP5150_PAD_IF_INPUT, 0); |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1365 | if (ret < 0) { |
| 1366 | media_device_unregister_entity(input); |
| 1367 | return ret; |
| 1368 | } |
| 1369 | } |
| 1370 | #endif |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1375 | /* ----------------------------------------------------------------------- */ |
| 1376 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1377 | static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = { |
| 1378 | .s_ctrl = tvp5150_s_ctrl, |
| 1379 | }; |
| 1380 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1381 | static const struct v4l2_subdev_core_ops tvp5150_core_ops = { |
| 1382 | .log_status = tvp5150_log_status, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1383 | .reset = tvp5150_reset, |
| 1384 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1385 | .g_register = tvp5150_g_register, |
| 1386 | .s_register = tvp5150_s_register, |
| 1387 | #endif |
| 1388 | }; |
| 1389 | |
| 1390 | static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1391 | .g_tuner = tvp5150_g_tuner, |
| 1392 | }; |
| 1393 | |
| 1394 | static const struct v4l2_subdev_video_ops tvp5150_video_ops = { |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 1395 | .s_std = tvp5150_s_std, |
Marco Felsch | 0db87cc | 2018-06-28 12:20:49 -0400 | [diff] [blame] | 1396 | .g_std = tvp5150_g_std, |
Philipp Zabel | ee9a6ff | 2018-06-28 12:20:48 -0400 | [diff] [blame^] | 1397 | .querystd = tvp5150_querystd, |
Laurent Pinchart | 460b6c0 | 2016-01-07 10:46:45 -0200 | [diff] [blame] | 1398 | .s_stream = tvp5150_s_stream, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1399 | .s_routing = tvp5150_s_routing, |
Laurent Pinchart | dd3a46b | 2016-01-07 10:46:46 -0200 | [diff] [blame] | 1400 | .g_mbus_config = tvp5150_g_mbus_config, |
Hans Verkuil | 32cd527 | 2010-03-14 09:57:30 -0300 | [diff] [blame] | 1401 | }; |
| 1402 | |
| 1403 | static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1404 | .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap, |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1405 | .g_sliced_fmt = tvp5150_g_sliced_fmt, |
| 1406 | .s_sliced_fmt = tvp5150_s_sliced_fmt, |
| 1407 | .s_raw_fmt = tvp5150_s_raw_fmt, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1408 | }; |
| 1409 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1410 | static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = { |
Philipp Zabel | b440b73 | 2018-06-28 12:20:40 -0400 | [diff] [blame] | 1411 | .init_cfg = tvp5150_init_cfg, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1412 | .enum_mbus_code = tvp5150_enum_mbus_code, |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1413 | .enum_frame_size = tvp5150_enum_frame_size, |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 1414 | .set_fmt = tvp5150_fill_fmt, |
| 1415 | .get_fmt = tvp5150_fill_fmt, |
Hans Verkuil | 10d5509c | 2015-12-14 08:25:32 -0200 | [diff] [blame] | 1416 | .get_selection = tvp5150_get_selection, |
| 1417 | .set_selection = tvp5150_set_selection, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1418 | }; |
| 1419 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1420 | static const struct v4l2_subdev_ops tvp5150_ops = { |
| 1421 | .core = &tvp5150_core_ops, |
| 1422 | .tuner = &tvp5150_tuner_ops, |
| 1423 | .video = &tvp5150_video_ops, |
Hans Verkuil | 32cd527 | 2010-03-14 09:57:30 -0300 | [diff] [blame] | 1424 | .vbi = &tvp5150_vbi_ops, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1425 | .pad = &tvp5150_pad_ops, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1426 | }; |
| 1427 | |
Javier Martinez Canillas | 5a08bc0 | 2016-08-11 13:28:15 -0300 | [diff] [blame] | 1428 | static const struct v4l2_subdev_internal_ops tvp5150_internal_ops = { |
| 1429 | .registered = tvp5150_registered, |
| 1430 | }; |
| 1431 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1432 | /**************************************************************************** |
| 1433 | I2C Client & Driver |
| 1434 | ****************************************************************************/ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1435 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1436 | static const struct regmap_range tvp5150_readable_ranges[] = { |
| 1437 | { |
| 1438 | .range_min = TVP5150_VD_IN_SRC_SEL_1, |
| 1439 | .range_max = TVP5150_AUTOSW_MSK, |
| 1440 | }, { |
| 1441 | .range_min = TVP5150_COLOR_KIL_THSH_CTL, |
| 1442 | .range_max = TVP5150_CONF_SHARED_PIN, |
| 1443 | }, { |
| 1444 | .range_min = TVP5150_ACT_VD_CROP_ST_MSB, |
| 1445 | .range_max = TVP5150_HORIZ_SYNC_START, |
| 1446 | }, { |
| 1447 | .range_min = TVP5150_VERT_BLANKING_START, |
| 1448 | .range_max = TVP5150_INTT_CONFIG_REG_B, |
| 1449 | }, { |
| 1450 | .range_min = TVP5150_VIDEO_STD, |
| 1451 | .range_max = TVP5150_VIDEO_STD, |
| 1452 | }, { |
| 1453 | .range_min = TVP5150_CB_GAIN_FACT, |
| 1454 | .range_max = TVP5150_REV_SELECT, |
| 1455 | }, { |
| 1456 | .range_min = TVP5150_MSB_DEV_ID, |
| 1457 | .range_max = TVP5150_STATUS_REG_5, |
| 1458 | }, { |
| 1459 | .range_min = TVP5150_CC_DATA_INI, |
| 1460 | .range_max = TVP5150_TELETEXT_FIL_ENA, |
| 1461 | }, { |
| 1462 | .range_min = TVP5150_INT_STATUS_REG_A, |
| 1463 | .range_max = TVP5150_FIFO_OUT_CTRL, |
| 1464 | }, { |
| 1465 | .range_min = TVP5150_FULL_FIELD_ENA, |
| 1466 | .range_max = TVP5150_FULL_FIELD_MODE_REG, |
| 1467 | }, |
| 1468 | }; |
| 1469 | |
| 1470 | bool tvp5150_volatile_reg(struct device *dev, unsigned int reg) |
| 1471 | { |
| 1472 | switch (reg) { |
| 1473 | case TVP5150_VERT_LN_COUNT_MSB: |
| 1474 | case TVP5150_VERT_LN_COUNT_LSB: |
| 1475 | case TVP5150_INT_STATUS_REG_A: |
| 1476 | case TVP5150_INT_STATUS_REG_B: |
| 1477 | case TVP5150_INT_ACTIVE_REG_B: |
| 1478 | case TVP5150_STATUS_REG_1: |
| 1479 | case TVP5150_STATUS_REG_2: |
| 1480 | case TVP5150_STATUS_REG_3: |
| 1481 | case TVP5150_STATUS_REG_4: |
| 1482 | case TVP5150_STATUS_REG_5: |
| 1483 | /* CC, WSS, VPS, VITC data? */ |
| 1484 | case TVP5150_VBI_FIFO_READ_DATA: |
| 1485 | case TVP5150_VDP_STATUS_REG: |
| 1486 | case TVP5150_FIFO_WORD_COUNT: |
| 1487 | return true; |
| 1488 | default: |
| 1489 | return false; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | static const struct regmap_access_table tvp5150_readable_table = { |
| 1494 | .yes_ranges = tvp5150_readable_ranges, |
| 1495 | .n_yes_ranges = ARRAY_SIZE(tvp5150_readable_ranges), |
| 1496 | }; |
| 1497 | |
| 1498 | static struct regmap_config tvp5150_config = { |
| 1499 | .reg_bits = 8, |
| 1500 | .val_bits = 8, |
| 1501 | .max_register = 0xff, |
| 1502 | |
| 1503 | .cache_type = REGCACHE_RBTREE, |
| 1504 | |
| 1505 | .rd_table = &tvp5150_readable_table, |
| 1506 | .volatile_reg = tvp5150_volatile_reg, |
| 1507 | }; |
| 1508 | |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1509 | static int tvp5150_detect_version(struct tvp5150 *core) |
| 1510 | { |
| 1511 | struct v4l2_subdev *sd = &core->sd; |
| 1512 | struct i2c_client *c = v4l2_get_subdevdata(sd); |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1513 | u8 regs[4]; |
| 1514 | int res; |
| 1515 | |
| 1516 | /* |
| 1517 | * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID, |
| 1518 | * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER |
| 1519 | */ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1520 | res = regmap_bulk_read(core->regmap, TVP5150_MSB_DEV_ID, regs, 4); |
| 1521 | if (res < 0) { |
| 1522 | dev_err(&c->dev, "reading ID registers failed: %d\n", res); |
| 1523 | return res; |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1526 | core->dev_id = (regs[0] << 8) | regs[1]; |
| 1527 | core->rom_ver = (regs[2] << 8) | regs[3]; |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1528 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1529 | dev_info(sd->dev, "tvp%04x (%u.%u) chip found @ 0x%02x (%s)\n", |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1530 | core->dev_id, regs[2], regs[3], c->addr << 1, |
| 1531 | c->adapter->name); |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1532 | |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1533 | if (core->dev_id == 0x5150 && core->rom_ver == 0x0321) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1534 | dev_info(sd->dev, "tvp5150a detected.\n"); |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1535 | } else if (core->dev_id == 0x5150 && core->rom_ver == 0x0400) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1536 | dev_info(sd->dev, "tvp5150am1 detected.\n"); |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1537 | |
| 1538 | /* ITU-T BT.656.4 timing */ |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1539 | regmap_write(core->regmap, TVP5150_REV_SELECT, 0); |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1540 | } else if (core->dev_id == 0x5151 && core->rom_ver == 0x0100) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1541 | dev_info(sd->dev, "tvp5151 detected.\n"); |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1542 | } else { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1543 | dev_info(sd->dev, "*** unknown tvp%04x chip detected.\n", |
Javier Martinez Canillas | 8227513 | 2016-02-05 17:09:54 -0200 | [diff] [blame] | 1544 | core->dev_id); |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
Javier Martinez Canillas | 09aa260 | 2016-01-07 10:46:49 -0200 | [diff] [blame] | 1550 | static int tvp5150_init(struct i2c_client *c) |
| 1551 | { |
| 1552 | struct gpio_desc *pdn_gpio; |
| 1553 | struct gpio_desc *reset_gpio; |
| 1554 | |
| 1555 | pdn_gpio = devm_gpiod_get_optional(&c->dev, "pdn", GPIOD_OUT_HIGH); |
| 1556 | if (IS_ERR(pdn_gpio)) |
| 1557 | return PTR_ERR(pdn_gpio); |
| 1558 | |
| 1559 | if (pdn_gpio) { |
| 1560 | gpiod_set_value_cansleep(pdn_gpio, 0); |
| 1561 | /* Delay time between power supplies active and reset */ |
| 1562 | msleep(20); |
| 1563 | } |
| 1564 | |
| 1565 | reset_gpio = devm_gpiod_get_optional(&c->dev, "reset", GPIOD_OUT_HIGH); |
| 1566 | if (IS_ERR(reset_gpio)) |
| 1567 | return PTR_ERR(reset_gpio); |
| 1568 | |
| 1569 | if (reset_gpio) { |
| 1570 | /* RESETB pulse duration */ |
| 1571 | ndelay(500); |
| 1572 | gpiod_set_value_cansleep(reset_gpio, 0); |
| 1573 | /* Delay time between end of reset to I2C active */ |
| 1574 | usleep_range(200, 250); |
| 1575 | } |
| 1576 | |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1580 | static int tvp5150_parse_dt(struct tvp5150 *decoder, struct device_node *np) |
| 1581 | { |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 1582 | struct v4l2_fwnode_endpoint bus_cfg; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1583 | struct device_node *ep; |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1584 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1585 | struct device_node *connectors, *child; |
| 1586 | struct media_entity *input; |
| 1587 | const char *name; |
| 1588 | u32 input_type; |
| 1589 | #endif |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1590 | unsigned int flags; |
| 1591 | int ret = 0; |
| 1592 | |
| 1593 | ep = of_graph_get_next_endpoint(np, NULL); |
| 1594 | if (!ep) |
| 1595 | return -EINVAL; |
| 1596 | |
Sakari Ailus | 859969b | 2016-08-26 20:17:25 -0300 | [diff] [blame] | 1597 | ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &bus_cfg); |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1598 | if (ret) |
| 1599 | goto err; |
| 1600 | |
| 1601 | flags = bus_cfg.bus.parallel.flags; |
| 1602 | |
| 1603 | if (bus_cfg.bus_type == V4L2_MBUS_PARALLEL && |
| 1604 | !(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH && |
| 1605 | flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH && |
Javier Martinez Canillas | 2bd5e43 | 2016-02-05 17:09:53 -0200 | [diff] [blame] | 1606 | flags & V4L2_MBUS_FIELD_EVEN_LOW)) { |
| 1607 | ret = -EINVAL; |
| 1608 | goto err; |
| 1609 | } |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1610 | |
| 1611 | decoder->mbus_type = bus_cfg.bus_type; |
| 1612 | |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1613 | #ifdef CONFIG_MEDIA_CONTROLLER |
| 1614 | connectors = of_get_child_by_name(np, "connectors"); |
| 1615 | |
| 1616 | if (!connectors) |
| 1617 | goto err; |
| 1618 | |
| 1619 | for_each_available_child_of_node(connectors, child) { |
| 1620 | ret = of_property_read_u32(child, "input", &input_type); |
| 1621 | if (ret) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1622 | dev_err(decoder->sd.dev, |
Rob Herring | f764e6d | 2018-08-27 21:52:29 -0400 | [diff] [blame] | 1623 | "missing type property in node %pOFn\n", |
| 1624 | child); |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1625 | goto err_connector; |
| 1626 | } |
| 1627 | |
Mauro Carvalho Chehab | 60ad768 | 2016-02-19 15:02:30 -0200 | [diff] [blame] | 1628 | if (input_type >= TVP5150_INPUT_NUM) { |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1629 | ret = -EINVAL; |
| 1630 | goto err_connector; |
| 1631 | } |
| 1632 | |
| 1633 | input = &decoder->input_ent[input_type]; |
| 1634 | |
| 1635 | /* Each input connector can only be defined once */ |
| 1636 | if (input->name) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1637 | dev_err(decoder->sd.dev, |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1638 | "input %s with same type already exists\n", |
| 1639 | input->name); |
| 1640 | ret = -EINVAL; |
| 1641 | goto err_connector; |
| 1642 | } |
| 1643 | |
| 1644 | switch (input_type) { |
| 1645 | case TVP5150_COMPOSITE0: |
| 1646 | case TVP5150_COMPOSITE1: |
| 1647 | input->function = MEDIA_ENT_F_CONN_COMPOSITE; |
| 1648 | break; |
| 1649 | case TVP5150_SVIDEO: |
| 1650 | input->function = MEDIA_ENT_F_CONN_SVIDEO; |
| 1651 | break; |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | input->flags = MEDIA_ENT_FL_CONNECTOR; |
| 1655 | |
| 1656 | ret = of_property_read_string(child, "label", &name); |
| 1657 | if (ret < 0) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1658 | dev_err(decoder->sd.dev, |
Rob Herring | f764e6d | 2018-08-27 21:52:29 -0400 | [diff] [blame] | 1659 | "missing label property in node %pOFn\n", |
| 1660 | child); |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1661 | goto err_connector; |
| 1662 | } |
| 1663 | |
| 1664 | input->name = name; |
| 1665 | } |
| 1666 | |
| 1667 | err_connector: |
| 1668 | of_node_put(connectors); |
| 1669 | #endif |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1670 | err: |
| 1671 | of_node_put(ep); |
| 1672 | return ret; |
| 1673 | } |
| 1674 | |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 1675 | static const char * const tvp5150_test_patterns[2] = { |
| 1676 | "Disabled", |
| 1677 | "Black screen" |
| 1678 | }; |
| 1679 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1680 | static int tvp5150_probe(struct i2c_client *c, |
| 1681 | const struct i2c_device_id *id) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1682 | { |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1683 | struct tvp5150 *core; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1684 | struct v4l2_subdev *sd; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1685 | struct device_node *np = c->dev.of_node; |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1686 | struct regmap *map; |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1687 | int res; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1688 | |
| 1689 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1690 | if (!i2c_check_functionality(c->adapter, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1691 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1692 | return -EIO; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1693 | |
Javier Martinez Canillas | 09aa260 | 2016-01-07 10:46:49 -0200 | [diff] [blame] | 1694 | res = tvp5150_init(c); |
| 1695 | if (res) |
| 1696 | return res; |
| 1697 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 1698 | core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL); |
| 1699 | if (!core) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1700 | return -ENOMEM; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1701 | |
Philipp Zabel | 28b9e22 | 2018-06-28 12:20:35 -0400 | [diff] [blame] | 1702 | map = devm_regmap_init_i2c(c, &tvp5150_config); |
| 1703 | if (IS_ERR(map)) |
| 1704 | return PTR_ERR(map); |
| 1705 | |
| 1706 | core->regmap = map; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1707 | sd = &core->sd; |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1708 | |
| 1709 | if (IS_ENABLED(CONFIG_OF) && np) { |
| 1710 | res = tvp5150_parse_dt(core, np); |
| 1711 | if (res) { |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1712 | dev_err(sd->dev, "DT parsing error: %d\n", res); |
Javier Martinez Canillas | a2e5f1b | 2016-01-07 10:46:50 -0200 | [diff] [blame] | 1713 | return res; |
| 1714 | } |
| 1715 | } else { |
| 1716 | /* Default to BT.656 embedded sync */ |
| 1717 | core->mbus_type = V4L2_MBUS_BT656; |
| 1718 | } |
| 1719 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1720 | v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); |
Javier Martinez Canillas | 5a08bc0 | 2016-08-11 13:28:15 -0300 | [diff] [blame] | 1721 | sd->internal_ops = &tvp5150_internal_ops; |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1722 | sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; |
| 1723 | |
| 1724 | #if defined(CONFIG_MEDIA_CONTROLLER) |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 1725 | core->pads[TVP5150_PAD_IF_INPUT].flags = MEDIA_PAD_FL_SINK; |
| 1726 | core->pads[TVP5150_PAD_IF_INPUT].sig_type = PAD_SIGNAL_ANALOG; |
| 1727 | core->pads[TVP5150_PAD_VID_OUT].flags = MEDIA_PAD_FL_SOURCE; |
| 1728 | core->pads[TVP5150_PAD_VID_OUT].sig_type = PAD_SIGNAL_DV; |
Mauro Carvalho Chehab | f92c70a | 2016-01-27 15:09:15 -0200 | [diff] [blame] | 1729 | |
| 1730 | sd->entity.function = MEDIA_ENT_F_ATV_DECODER; |
| 1731 | |
Mauro Carvalho Chehab | bc322c0 | 2018-08-01 06:10:05 -0400 | [diff] [blame] | 1732 | res = media_entity_pads_init(&sd->entity, TVP5150_NUM_PADS, core->pads); |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1733 | if (res < 0) |
| 1734 | return res; |
Javier Martinez Canillas | f7b4b54 | 2016-02-05 17:09:58 -0200 | [diff] [blame] | 1735 | |
| 1736 | sd->entity.ops = &tvp5150_sd_media_ops; |
Laurent Pinchart | e545ac8 | 2016-01-26 10:46:24 -0200 | [diff] [blame] | 1737 | #endif |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1738 | |
Laurent Pinchart | 7871597 | 2016-01-07 10:46:41 -0200 | [diff] [blame] | 1739 | res = tvp5150_detect_version(core); |
| 1740 | if (res < 0) |
| 1741 | return res; |
Mauro Carvalho Chehab | 0e09a3c | 2011-02-22 00:10:22 -0300 | [diff] [blame] | 1742 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 1743 | core->norm = V4L2_STD_ALL; /* Default is autodetect */ |
Philipp Zabel | b440b73 | 2018-06-28 12:20:40 -0400 | [diff] [blame] | 1744 | core->detected_norm = V4L2_STD_UNKNOWN; |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1745 | core->input = TVP5150_COMPOSITE1; |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 1746 | core->enable = true; |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1747 | |
Laurent Pinchart | b1950b8 | 2016-01-07 10:46:44 -0200 | [diff] [blame] | 1748 | v4l2_ctrl_handler_init(&core->hdl, 5); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1749 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1750 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
| 1751 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1752 | V4L2_CID_CONTRAST, 0, 255, 1, 128); |
| 1753 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1754 | V4L2_CID_SATURATION, 0, 255, 1, 128); |
| 1755 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1756 | V4L2_CID_HUE, -128, 127, 1, 0); |
Laurent Pinchart | b1950b8 | 2016-01-07 10:46:44 -0200 | [diff] [blame] | 1757 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1758 | V4L2_CID_PIXEL_RATE, 27000000, |
| 1759 | 27000000, 1, 27000000); |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 1760 | v4l2_ctrl_new_std_menu_items(&core->hdl, &tvp5150_ctrl_ops, |
| 1761 | V4L2_CID_TEST_PATTERN, |
Mauro Carvalho Chehab | 5c4c450 | 2018-09-13 16:49:51 -0400 | [diff] [blame] | 1762 | ARRAY_SIZE(tvp5150_test_patterns) - 1, |
Mauro Carvalho Chehab | c43875f | 2016-02-12 15:42:02 -0200 | [diff] [blame] | 1763 | 0, 0, tvp5150_test_patterns); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1764 | sd->ctrl_handler = &core->hdl; |
| 1765 | if (core->hdl.error) { |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1766 | res = core->hdl.error; |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1767 | goto err; |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1768 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1769 | |
Marco Felsch | 5cb8294 | 2018-06-28 12:20:39 -0400 | [diff] [blame] | 1770 | tvp5150_set_default(tvp5150_read_std(sd), &core->rect); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1771 | |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 1772 | core->irq = c->irq; |
Laurent Pinchart | aff808e | 2016-12-09 09:47:17 -0200 | [diff] [blame] | 1773 | tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */ |
Philipp Zabel | 8e4c97e | 2018-06-28 12:20:44 -0400 | [diff] [blame] | 1774 | if (c->irq) { |
| 1775 | res = devm_request_threaded_irq(&c->dev, c->irq, NULL, |
| 1776 | tvp5150_isr, IRQF_TRIGGER_HIGH | |
| 1777 | IRQF_ONESHOT, "tvp5150", core); |
| 1778 | if (res) |
| 1779 | return res; |
| 1780 | } else { |
| 1781 | core->lock = true; |
| 1782 | } |
Laurent Pinchart | aff808e | 2016-12-09 09:47:17 -0200 | [diff] [blame] | 1783 | |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1784 | res = v4l2_async_register_subdev(sd); |
| 1785 | if (res < 0) |
| 1786 | goto err; |
| 1787 | |
Markus Rechberger | f1e5ee4 | 2006-02-07 04:01:19 +0100 | [diff] [blame] | 1788 | if (debug > 1) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1789 | tvp5150_log_status(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1790 | return 0; |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1791 | |
| 1792 | err: |
| 1793 | v4l2_ctrl_handler_free(&core->hdl); |
| 1794 | return res; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1797 | static int tvp5150_remove(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1798 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1799 | struct v4l2_subdev *sd = i2c_get_clientdata(c); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1800 | struct tvp5150 *decoder = to_tvp5150(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1801 | |
Mauro Carvalho Chehab | 257e29f | 2016-11-16 08:58:05 -0200 | [diff] [blame] | 1802 | dev_dbg_lvl(sd->dev, 1, debug, |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1803 | "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", |
| 1804 | c->addr << 1); |
| 1805 | |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1806 | v4l2_async_unregister_subdev(sd); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1807 | v4l2_ctrl_handler_free(&decoder->hdl); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1808 | return 0; |
| 1809 | } |
| 1810 | |
| 1811 | /* ----------------------------------------------------------------------- */ |
| 1812 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1813 | static const struct i2c_device_id tvp5150_id[] = { |
| 1814 | { "tvp5150", 0 }, |
| 1815 | { } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1816 | }; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1817 | MODULE_DEVICE_TABLE(i2c, tvp5150_id); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1818 | |
Eduard Gavin | 7ef930a | 2016-01-07 10:46:48 -0200 | [diff] [blame] | 1819 | #if IS_ENABLED(CONFIG_OF) |
| 1820 | static const struct of_device_id tvp5150_of_match[] = { |
| 1821 | { .compatible = "ti,tvp5150", }, |
| 1822 | { /* sentinel */ }, |
| 1823 | }; |
| 1824 | MODULE_DEVICE_TABLE(of, tvp5150_of_match); |
| 1825 | #endif |
| 1826 | |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1827 | static struct i2c_driver tvp5150_driver = { |
| 1828 | .driver = { |
Eduard Gavin | 7ef930a | 2016-01-07 10:46:48 -0200 | [diff] [blame] | 1829 | .of_match_table = of_match_ptr(tvp5150_of_match), |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1830 | .name = "tvp5150", |
| 1831 | }, |
| 1832 | .probe = tvp5150_probe, |
| 1833 | .remove = tvp5150_remove, |
| 1834 | .id_table = tvp5150_id, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1835 | }; |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1836 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 1837 | module_i2c_driver(tvp5150_driver); |