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