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