Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 2 | * tvp5150 - Texas Instruments TVP5150A/AM1 video decoder driver |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 3 | * |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 4 | * Copyright (c) 2005,2006 Mauro Carvalho Chehab (mchehab@infradead.org) |
| 5 | * This code is placed under the terms of the GNU General Public License v2 |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
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> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 12 | #include <linux/module.h> |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 13 | #include <media/v4l2-async.h> |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 14 | #include <media/v4l2-device.h> |
Mauro Carvalho Chehab | b5dcee2 | 2015-11-10 12:01:44 -0200 | [diff] [blame] | 15 | #include <media/i2c/tvp5150.h> |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 16 | #include <media/v4l2-ctrls.h> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 17 | |
| 18 | #include "tvp5150_reg.h" |
| 19 | |
Philipp Zabel | 785a3de | 2014-02-27 13:44:47 -0300 | [diff] [blame] | 20 | #define TVP5150_H_MAX 720U |
| 21 | #define TVP5150_V_MAX_525_60 480U |
| 22 | #define TVP5150_V_MAX_OTHERS 576U |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 23 | #define TVP5150_MAX_CROP_LEFT 511 |
| 24 | #define TVP5150_MAX_CROP_TOP 127 |
| 25 | #define TVP5150_CROP_SHIFT 2 |
| 26 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 27 | MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 28 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
| 29 | MODULE_LICENSE("GPL"); |
| 30 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 31 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 32 | static int debug; |
Philipp Zabel | 2a0489d | 2014-02-27 13:44:48 -0300 | [diff] [blame] | 33 | module_param(debug, int, 0644); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 34 | MODULE_PARM_DESC(debug, "Debug level (0-2)"); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 35 | |
| 36 | struct tvp5150 { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 37 | struct v4l2_subdev sd; |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 38 | struct v4l2_ctrl_handler hdl; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 39 | struct v4l2_rect rect; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 41 | v4l2_std_id norm; /* Current set standard */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 42 | u32 input; |
| 43 | u32 output; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 44 | int enable; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 47 | static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 48 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 49 | return container_of(sd, struct tvp5150, sd); |
| 50 | } |
| 51 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 52 | static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) |
| 53 | { |
| 54 | return &container_of(ctrl->handler, struct tvp5150, hdl)->sd; |
| 55 | } |
| 56 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 57 | static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr) |
| 58 | { |
| 59 | struct i2c_client *c = v4l2_get_subdevdata(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 60 | int rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 61 | |
Laurent Pinchart | e35ce2e | 2014-05-26 16:31:28 -0300 | [diff] [blame] | 62 | rc = i2c_smbus_read_byte_data(c, addr); |
| 63 | if (rc < 0) { |
| 64 | v4l2_err(sd, "i2c i/o error: rc == %d\n", rc); |
| 65 | return rc; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 66 | } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 67 | |
Laurent Pinchart | e35ce2e | 2014-05-26 16:31:28 -0300 | [diff] [blame] | 68 | v4l2_dbg(2, debug, sd, "tvp5150: read 0x%02x = 0x%02x\n", addr, rc); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 69 | |
Laurent Pinchart | e35ce2e | 2014-05-26 16:31:28 -0300 | [diff] [blame] | 70 | return rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 73 | static inline void tvp5150_write(struct v4l2_subdev *sd, unsigned char addr, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 74 | unsigned char value) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 75 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 76 | struct i2c_client *c = v4l2_get_subdevdata(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 77 | int rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 78 | |
Laurent Pinchart | e35ce2e | 2014-05-26 16:31:28 -0300 | [diff] [blame] | 79 | v4l2_dbg(2, debug, sd, "tvp5150: writing 0x%02x 0x%02x\n", addr, value); |
| 80 | rc = i2c_smbus_write_byte_data(c, addr, value); |
| 81 | if (rc < 0) |
| 82 | v4l2_dbg(0, debug, sd, "i2c i/o error: rc == %d\n", rc); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 85 | static void dump_reg_range(struct v4l2_subdev *sd, char *s, u8 init, |
| 86 | const u8 end, int max_line) |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 87 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 88 | int i = 0; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 89 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 90 | while (init != (u8)(end + 1)) { |
| 91 | if ((i % max_line) == 0) { |
| 92 | if (i > 0) |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 93 | printk("\n"); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 94 | printk("tvp5150: %s reg 0x%02x = ", s, init); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 95 | } |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 96 | printk("%02x ", tvp5150_read(sd, init)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 97 | |
| 98 | init++; |
| 99 | i++; |
| 100 | } |
| 101 | printk("\n"); |
| 102 | } |
| 103 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 104 | static int tvp5150_log_status(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 105 | { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 106 | printk("tvp5150: Video input source selection #1 = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 107 | tvp5150_read(sd, TVP5150_VD_IN_SRC_SEL_1)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 108 | printk("tvp5150: Analog channel controls = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 109 | tvp5150_read(sd, TVP5150_ANAL_CHL_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 110 | printk("tvp5150: Operation mode controls = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 111 | tvp5150_read(sd, TVP5150_OP_MODE_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 112 | printk("tvp5150: Miscellaneous controls = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 113 | tvp5150_read(sd, TVP5150_MISC_CTL)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 114 | printk("tvp5150: Autoswitch mask= 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 115 | tvp5150_read(sd, TVP5150_AUTOSW_MSK)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 116 | printk("tvp5150: Color killer threshold control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 117 | tvp5150_read(sd, TVP5150_COLOR_KIL_THSH_CTL)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 118 | printk("tvp5150: Luminance processing controls #1 #2 and #3 = %02x %02x %02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 119 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_1), |
| 120 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_2), |
| 121 | tvp5150_read(sd, TVP5150_LUMA_PROC_CTL_3)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 122 | printk("tvp5150: Brightness control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 123 | tvp5150_read(sd, TVP5150_BRIGHT_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 124 | printk("tvp5150: Color saturation control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 125 | tvp5150_read(sd, TVP5150_SATURATION_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 126 | printk("tvp5150: Hue control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 127 | tvp5150_read(sd, TVP5150_HUE_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 128 | printk("tvp5150: Contrast control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 129 | tvp5150_read(sd, TVP5150_CONTRAST_CTL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 130 | printk("tvp5150: Outputs and data rates select = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 131 | tvp5150_read(sd, TVP5150_DATA_RATE_SEL)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 132 | printk("tvp5150: Configuration shared pins = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 133 | tvp5150_read(sd, TVP5150_CONF_SHARED_PIN)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 134 | printk("tvp5150: Active video cropping start = 0x%02x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 135 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_MSB), |
| 136 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_ST_LSB)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 137 | printk("tvp5150: Active video cropping stop = 0x%02x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 138 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_MSB), |
| 139 | tvp5150_read(sd, TVP5150_ACT_VD_CROP_STP_LSB)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 140 | printk("tvp5150: Genlock/RTC = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 141 | tvp5150_read(sd, TVP5150_GENLOCK)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 142 | printk("tvp5150: Horizontal sync start = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 143 | tvp5150_read(sd, TVP5150_HORIZ_SYNC_START)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 144 | printk("tvp5150: Vertical blanking start = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 145 | tvp5150_read(sd, TVP5150_VERT_BLANKING_START)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 146 | printk("tvp5150: Vertical blanking stop = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 147 | tvp5150_read(sd, TVP5150_VERT_BLANKING_STOP)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 148 | printk("tvp5150: Chrominance processing control #1 and #2 = %02x %02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 149 | tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_1), |
| 150 | tvp5150_read(sd, TVP5150_CHROMA_PROC_CTL_2)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 151 | printk("tvp5150: Interrupt reset register B = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 152 | tvp5150_read(sd, TVP5150_INT_RESET_REG_B)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 153 | printk("tvp5150: Interrupt enable register B = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 154 | tvp5150_read(sd, TVP5150_INT_ENABLE_REG_B)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 155 | printk("tvp5150: Interrupt configuration register B = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 156 | tvp5150_read(sd, TVP5150_INTT_CONFIG_REG_B)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 157 | printk("tvp5150: Video standard = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 158 | tvp5150_read(sd, TVP5150_VIDEO_STD)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 159 | printk("tvp5150: Chroma gain factor: Cb=0x%02x Cr=0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 160 | tvp5150_read(sd, TVP5150_CB_GAIN_FACT), |
| 161 | tvp5150_read(sd, TVP5150_CR_GAIN_FACTOR)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 162 | printk("tvp5150: Macrovision on counter = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 163 | tvp5150_read(sd, TVP5150_MACROVISION_ON_CTR)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 164 | printk("tvp5150: Macrovision off counter = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 165 | tvp5150_read(sd, TVP5150_MACROVISION_OFF_CTR)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 166 | printk("tvp5150: ITU-R BT.656.%d timing(TVP5150AM1 only)\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 167 | (tvp5150_read(sd, TVP5150_REV_SELECT) & 1) ? 3 : 4); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 168 | printk("tvp5150: Device ID = %02x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 169 | tvp5150_read(sd, TVP5150_MSB_DEV_ID), |
| 170 | tvp5150_read(sd, TVP5150_LSB_DEV_ID)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 171 | printk("tvp5150: ROM version = (hex) %02x.%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 172 | tvp5150_read(sd, TVP5150_ROM_MAJOR_VER), |
| 173 | tvp5150_read(sd, TVP5150_ROM_MINOR_VER)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 174 | printk("tvp5150: Vertical line count = 0x%02x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 175 | tvp5150_read(sd, TVP5150_VERT_LN_COUNT_MSB), |
| 176 | tvp5150_read(sd, TVP5150_VERT_LN_COUNT_LSB)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 177 | printk("tvp5150: Interrupt status register B = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 178 | tvp5150_read(sd, TVP5150_INT_STATUS_REG_B)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 179 | printk("tvp5150: Interrupt active register B = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 180 | tvp5150_read(sd, TVP5150_INT_ACTIVE_REG_B)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 181 | printk("tvp5150: Status regs #1 to #5 = %02x %02x %02x %02x %02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 182 | tvp5150_read(sd, TVP5150_STATUS_REG_1), |
| 183 | tvp5150_read(sd, TVP5150_STATUS_REG_2), |
| 184 | tvp5150_read(sd, TVP5150_STATUS_REG_3), |
| 185 | tvp5150_read(sd, TVP5150_STATUS_REG_4), |
| 186 | tvp5150_read(sd, TVP5150_STATUS_REG_5)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 187 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 188 | dump_reg_range(sd, "Teletext filter 1", TVP5150_TELETEXT_FIL1_INI, |
| 189 | TVP5150_TELETEXT_FIL1_END, 8); |
| 190 | dump_reg_range(sd, "Teletext filter 2", TVP5150_TELETEXT_FIL2_INI, |
| 191 | TVP5150_TELETEXT_FIL2_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 192 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 193 | printk("tvp5150: Teletext filter enable = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 194 | tvp5150_read(sd, TVP5150_TELETEXT_FIL_ENA)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 195 | printk("tvp5150: Interrupt status register A = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 196 | tvp5150_read(sd, TVP5150_INT_STATUS_REG_A)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 197 | printk("tvp5150: Interrupt enable register A = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 198 | tvp5150_read(sd, TVP5150_INT_ENABLE_REG_A)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 199 | printk("tvp5150: Interrupt configuration = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 200 | tvp5150_read(sd, TVP5150_INT_CONF)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 201 | printk("tvp5150: VDP status register = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 202 | tvp5150_read(sd, TVP5150_VDP_STATUS_REG)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 203 | printk("tvp5150: FIFO word count = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 204 | tvp5150_read(sd, TVP5150_FIFO_WORD_COUNT)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 205 | printk("tvp5150: FIFO interrupt threshold = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 206 | tvp5150_read(sd, TVP5150_FIFO_INT_THRESHOLD)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 207 | printk("tvp5150: FIFO reset = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 208 | tvp5150_read(sd, TVP5150_FIFO_RESET)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 209 | printk("tvp5150: Line number interrupt = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 210 | tvp5150_read(sd, TVP5150_LINE_NUMBER_INT)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 211 | printk("tvp5150: Pixel alignment register = 0x%02x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 212 | tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_HIGH), |
| 213 | tvp5150_read(sd, TVP5150_PIX_ALIGN_REG_LOW)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 214 | printk("tvp5150: FIFO output control = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 215 | tvp5150_read(sd, TVP5150_FIFO_OUT_CTRL)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 216 | printk("tvp5150: Full field enable = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 217 | tvp5150_read(sd, TVP5150_FULL_FIELD_ENA)); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 218 | printk("tvp5150: Full field mode register = 0x%02x\n", |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 219 | tvp5150_read(sd, TVP5150_FULL_FIELD_MODE_REG)); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 220 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 221 | dump_reg_range(sd, "CC data", TVP5150_CC_DATA_INI, |
| 222 | TVP5150_CC_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 223 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 224 | dump_reg_range(sd, "WSS data", TVP5150_WSS_DATA_INI, |
| 225 | TVP5150_WSS_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 226 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 227 | dump_reg_range(sd, "VPS data", TVP5150_VPS_DATA_INI, |
| 228 | TVP5150_VPS_DATA_END, 8); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 229 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 230 | dump_reg_range(sd, "VITC data", TVP5150_VITC_DATA_INI, |
| 231 | TVP5150_VITC_DATA_END, 10); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 232 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 233 | dump_reg_range(sd, "Line mode", TVP5150_LINE_MODE_INI, |
| 234 | TVP5150_LINE_MODE_END, 8); |
| 235 | return 0; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /**************************************************************************** |
| 239 | Basic functions |
| 240 | ****************************************************************************/ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 241 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 242 | static inline void tvp5150_selmux(struct v4l2_subdev *sd) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 243 | { |
Paul Walmsley | 2962fc0 | 2010-10-09 01:31:40 -0300 | [diff] [blame] | 244 | int opmode = 0; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 245 | struct tvp5150 *decoder = to_tvp5150(sd); |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 246 | int input = 0; |
Dan Carpenter | afcc8e8 | 2012-07-12 10:47:28 -0300 | [diff] [blame] | 247 | int val; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 248 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 249 | if ((decoder->output & TVP5150_BLACK_SCREEN) || !decoder->enable) |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 250 | input = 8; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 251 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 252 | switch (decoder->input) { |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 253 | case TVP5150_COMPOSITE1: |
| 254 | input |= 2; |
| 255 | /* fall through */ |
| 256 | case TVP5150_COMPOSITE0: |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 257 | break; |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 258 | case TVP5150_SVIDEO: |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 259 | default: |
Hans Verkuil | c7c0b34 | 2006-04-02 13:35:00 -0300 | [diff] [blame] | 260 | input |= 1; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 261 | break; |
| 262 | } |
| 263 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 264 | v4l2_dbg(1, debug, sd, "Selecting video route: route input=%i, output=%i " |
Mauro Carvalho Chehab | 12500f0 | 2006-08-18 07:31:10 -0300 | [diff] [blame] | 265 | "=> tvp5150 input=%i, opmode=%i\n", |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 266 | decoder->input, decoder->output, |
| 267 | input, opmode); |
Mauro Carvalho Chehab | 12500f0 | 2006-08-18 07:31:10 -0300 | [diff] [blame] | 268 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 269 | tvp5150_write(sd, TVP5150_OP_MODE_CTL, opmode); |
| 270 | tvp5150_write(sd, TVP5150_VD_IN_SRC_SEL_1, input); |
Mauro Carvalho Chehab | f4b8b3a | 2007-11-03 22:40:24 -0300 | [diff] [blame] | 271 | |
| 272 | /* Svideo should enable YCrCb output and disable GPCL output |
| 273 | * For Composite and TV, it should be the reverse |
| 274 | */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 275 | val = tvp5150_read(sd, TVP5150_MISC_CTL); |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 276 | if (val < 0) { |
| 277 | v4l2_err(sd, "%s: failed with error = %d\n", __func__, val); |
| 278 | return; |
| 279 | } |
| 280 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 281 | if (decoder->input == TVP5150_SVIDEO) |
Mauro Carvalho Chehab | f4b8b3a | 2007-11-03 22:40:24 -0300 | [diff] [blame] | 282 | val = (val & ~0x40) | 0x10; |
| 283 | else |
| 284 | val = (val & ~0x10) | 0x40; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 285 | tvp5150_write(sd, TVP5150_MISC_CTL, val); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 286 | }; |
| 287 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 288 | struct i2c_reg_value { |
| 289 | unsigned char reg; |
| 290 | unsigned char value; |
| 291 | }; |
| 292 | |
| 293 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 294 | static const struct i2c_reg_value tvp5150_init_default[] = { |
| 295 | { /* 0x00 */ |
| 296 | TVP5150_VD_IN_SRC_SEL_1,0x00 |
| 297 | }, |
| 298 | { /* 0x01 */ |
| 299 | TVP5150_ANAL_CHL_CTL,0x15 |
| 300 | }, |
| 301 | { /* 0x02 */ |
| 302 | TVP5150_OP_MODE_CTL,0x00 |
| 303 | }, |
| 304 | { /* 0x03 */ |
| 305 | TVP5150_MISC_CTL,0x01 |
| 306 | }, |
| 307 | { /* 0x06 */ |
| 308 | TVP5150_COLOR_KIL_THSH_CTL,0x10 |
| 309 | }, |
| 310 | { /* 0x07 */ |
| 311 | TVP5150_LUMA_PROC_CTL_1,0x60 |
| 312 | }, |
| 313 | { /* 0x08 */ |
| 314 | TVP5150_LUMA_PROC_CTL_2,0x00 |
| 315 | }, |
| 316 | { /* 0x09 */ |
| 317 | TVP5150_BRIGHT_CTL,0x80 |
| 318 | }, |
| 319 | { /* 0x0a */ |
| 320 | TVP5150_SATURATION_CTL,0x80 |
| 321 | }, |
| 322 | { /* 0x0b */ |
| 323 | TVP5150_HUE_CTL,0x00 |
| 324 | }, |
| 325 | { /* 0x0c */ |
| 326 | TVP5150_CONTRAST_CTL,0x80 |
| 327 | }, |
| 328 | { /* 0x0d */ |
| 329 | TVP5150_DATA_RATE_SEL,0x47 |
| 330 | }, |
| 331 | { /* 0x0e */ |
| 332 | TVP5150_LUMA_PROC_CTL_3,0x00 |
| 333 | }, |
| 334 | { /* 0x0f */ |
| 335 | TVP5150_CONF_SHARED_PIN,0x08 |
| 336 | }, |
| 337 | { /* 0x11 */ |
| 338 | TVP5150_ACT_VD_CROP_ST_MSB,0x00 |
| 339 | }, |
| 340 | { /* 0x12 */ |
| 341 | TVP5150_ACT_VD_CROP_ST_LSB,0x00 |
| 342 | }, |
| 343 | { /* 0x13 */ |
| 344 | TVP5150_ACT_VD_CROP_STP_MSB,0x00 |
| 345 | }, |
| 346 | { /* 0x14 */ |
| 347 | TVP5150_ACT_VD_CROP_STP_LSB,0x00 |
| 348 | }, |
| 349 | { /* 0x15 */ |
| 350 | TVP5150_GENLOCK,0x01 |
| 351 | }, |
| 352 | { /* 0x16 */ |
| 353 | TVP5150_HORIZ_SYNC_START,0x80 |
| 354 | }, |
| 355 | { /* 0x18 */ |
| 356 | TVP5150_VERT_BLANKING_START,0x00 |
| 357 | }, |
| 358 | { /* 0x19 */ |
| 359 | TVP5150_VERT_BLANKING_STOP,0x00 |
| 360 | }, |
| 361 | { /* 0x1a */ |
| 362 | TVP5150_CHROMA_PROC_CTL_1,0x0c |
| 363 | }, |
| 364 | { /* 0x1b */ |
| 365 | TVP5150_CHROMA_PROC_CTL_2,0x14 |
| 366 | }, |
| 367 | { /* 0x1c */ |
| 368 | TVP5150_INT_RESET_REG_B,0x00 |
| 369 | }, |
| 370 | { /* 0x1d */ |
| 371 | TVP5150_INT_ENABLE_REG_B,0x00 |
| 372 | }, |
| 373 | { /* 0x1e */ |
| 374 | TVP5150_INTT_CONFIG_REG_B,0x00 |
| 375 | }, |
| 376 | { /* 0x28 */ |
| 377 | TVP5150_VIDEO_STD,0x00 |
| 378 | }, |
| 379 | { /* 0x2e */ |
| 380 | TVP5150_MACROVISION_ON_CTR,0x0f |
| 381 | }, |
| 382 | { /* 0x2f */ |
| 383 | TVP5150_MACROVISION_OFF_CTR,0x01 |
| 384 | }, |
| 385 | { /* 0xbb */ |
| 386 | TVP5150_TELETEXT_FIL_ENA,0x00 |
| 387 | }, |
| 388 | { /* 0xc0 */ |
| 389 | TVP5150_INT_STATUS_REG_A,0x00 |
| 390 | }, |
| 391 | { /* 0xc1 */ |
| 392 | TVP5150_INT_ENABLE_REG_A,0x00 |
| 393 | }, |
| 394 | { /* 0xc2 */ |
| 395 | TVP5150_INT_CONF,0x04 |
| 396 | }, |
| 397 | { /* 0xc8 */ |
| 398 | TVP5150_FIFO_INT_THRESHOLD,0x80 |
| 399 | }, |
| 400 | { /* 0xc9 */ |
| 401 | TVP5150_FIFO_RESET,0x00 |
| 402 | }, |
| 403 | { /* 0xca */ |
| 404 | TVP5150_LINE_NUMBER_INT,0x00 |
| 405 | }, |
| 406 | { /* 0xcb */ |
| 407 | TVP5150_PIX_ALIGN_REG_LOW,0x4e |
| 408 | }, |
| 409 | { /* 0xcc */ |
| 410 | TVP5150_PIX_ALIGN_REG_HIGH,0x00 |
| 411 | }, |
| 412 | { /* 0xcd */ |
| 413 | TVP5150_FIFO_OUT_CTRL,0x01 |
| 414 | }, |
| 415 | { /* 0xcf */ |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 416 | TVP5150_FULL_FIELD_ENA,0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 417 | }, |
| 418 | { /* 0xd0 */ |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 419 | TVP5150_LINE_MODE_INI,0x00 |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 420 | }, |
| 421 | { /* 0xfc */ |
| 422 | TVP5150_FULL_FIELD_MODE_REG,0x7f |
| 423 | }, |
| 424 | { /* end of data */ |
| 425 | 0xff,0xff |
| 426 | } |
| 427 | }; |
| 428 | |
| 429 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 430 | static const struct i2c_reg_value tvp5150_init_enable[] = { |
| 431 | { |
| 432 | TVP5150_CONF_SHARED_PIN, 2 |
| 433 | },{ /* Automatic offset and AGC enabled */ |
| 434 | TVP5150_ANAL_CHL_CTL, 0x15 |
| 435 | },{ /* Activate YCrCb output 0x9 or 0xd ? */ |
| 436 | TVP5150_MISC_CTL, 0x6f |
| 437 | },{ /* Activates video std autodetection for all standards */ |
| 438 | TVP5150_AUTOSW_MSK, 0x0 |
| 439 | },{ /* Default format: 0x47. For 4:2:2: 0x40 */ |
| 440 | TVP5150_DATA_RATE_SEL, 0x47 |
| 441 | },{ |
| 442 | TVP5150_CHROMA_PROC_CTL_1, 0x0c |
| 443 | },{ |
| 444 | TVP5150_CHROMA_PROC_CTL_2, 0x54 |
| 445 | },{ /* Non documented, but initialized on WinTV USB2 */ |
| 446 | 0x27, 0x20 |
| 447 | },{ |
| 448 | 0xff,0xff |
| 449 | } |
| 450 | }; |
| 451 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 452 | struct tvp5150_vbi_type { |
| 453 | unsigned int vbi_type; |
| 454 | unsigned int ini_line; |
| 455 | unsigned int end_line; |
| 456 | unsigned int by_field :1; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 457 | }; |
| 458 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 459 | struct i2c_vbi_ram_value { |
| 460 | u16 reg; |
| 461 | struct tvp5150_vbi_type type; |
| 462 | unsigned char values[16]; |
| 463 | }; |
| 464 | |
| 465 | /* This struct have the values for each supported VBI Standard |
| 466 | * by |
| 467 | 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] | 468 | * value 0 means rom position 0x10, value 1 means rom position 0x30 |
| 469 | * and so on. There are 16 possible locations from 0 to 15. |
| 470 | */ |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 471 | |
Adrian Bunk | a9cff90 | 2006-01-15 06:56:15 -0200 | [diff] [blame] | 472 | static struct i2c_vbi_ram_value vbi_ram_default[] = |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 473 | { |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 474 | /* FIXME: Current api doesn't handle all VBI types, those not |
| 475 | yet supported are placed under #if 0 */ |
| 476 | #if 0 |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 477 | {0x010, /* Teletext, SECAM, WST System A */ |
| 478 | {V4L2_SLICED_TELETEXT_SECAM,6,23,1}, |
| 479 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x26, |
| 480 | 0xe6, 0xb4, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 481 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 482 | #endif |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 483 | {0x030, /* Teletext, PAL, WST System B */ |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 484 | {V4L2_SLICED_TELETEXT_B,6,22,1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 485 | { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x2b, |
| 486 | 0xa6, 0x72, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 487 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 488 | #if 0 |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 489 | {0x050, /* Teletext, PAL, WST System C */ |
| 490 | {V4L2_SLICED_TELETEXT_PAL_C,6,22,1}, |
| 491 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, |
| 492 | 0xa6, 0x98, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 493 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 494 | {0x070, /* Teletext, NTSC, WST System B */ |
| 495 | {V4L2_SLICED_TELETEXT_NTSC_B,10,21,1}, |
| 496 | { 0xaa, 0xaa, 0xff, 0xff, 0x27, 0x2e, 0x20, 0x23, |
| 497 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 498 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 499 | {0x090, /* Tetetext, NTSC NABTS System C */ |
| 500 | {V4L2_SLICED_TELETEXT_NTSC_C,10,21,1}, |
| 501 | { 0xaa, 0xaa, 0xff, 0xff, 0xe7, 0x2e, 0x20, 0x22, |
| 502 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x15, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 503 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 504 | {0x0b0, /* Teletext, NTSC-J, NABTS System D */ |
| 505 | {V4L2_SLICED_TELETEXT_NTSC_D,10,21,1}, |
| 506 | { 0xaa, 0xaa, 0xff, 0xff, 0xa7, 0x2e, 0x20, 0x23, |
| 507 | 0x69, 0x93, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 508 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 509 | {0x0d0, /* Closed Caption, PAL/SECAM */ |
| 510 | {V4L2_SLICED_CAPTION_625,22,22,1}, |
| 511 | { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, |
| 512 | 0xa6, 0x7b, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 513 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 514 | #endif |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 515 | {0x0f0, /* Closed Caption, NTSC */ |
| 516 | {V4L2_SLICED_CAPTION_525,21,21,1}, |
| 517 | { 0xaa, 0x2a, 0xff, 0x3f, 0x04, 0x51, 0x6e, 0x02, |
| 518 | 0x69, 0x8c, 0x09, 0x00, 0x00, 0x00, 0x27, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 519 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 520 | {0x110, /* Wide Screen Signal, PAL/SECAM */ |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 521 | {V4L2_SLICED_WSS_625,23,23,1}, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 522 | { 0x5b, 0x55, 0xc5, 0xff, 0x00, 0x71, 0x6e, 0x42, |
| 523 | 0xa6, 0xcd, 0x0f, 0x00, 0x00, 0x00, 0x3a, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 524 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 525 | #if 0 |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 526 | {0x130, /* Wide Screen Signal, NTSC C */ |
| 527 | {V4L2_SLICED_WSS_525,20,20,1}, |
| 528 | { 0x38, 0x00, 0x3f, 0x00, 0x00, 0x71, 0x6e, 0x43, |
| 529 | 0x69, 0x7c, 0x08, 0x00, 0x00, 0x00, 0x39, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 530 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 531 | {0x150, /* Vertical Interval Timecode (VITC), PAL/SECAM */ |
| 532 | {V4l2_SLICED_VITC_625,6,22,0}, |
| 533 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, |
| 534 | 0xa6, 0x85, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 535 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 536 | {0x170, /* Vertical Interval Timecode (VITC), NTSC */ |
| 537 | {V4l2_SLICED_VITC_525,10,20,0}, |
| 538 | { 0x00, 0x00, 0x00, 0x00, 0x00, 0x8f, 0x6d, 0x49, |
| 539 | 0x69, 0x94, 0x08, 0x00, 0x00, 0x00, 0x4c, 0x00 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 540 | }, |
Hans Verkuil | 9bc7400 | 2006-03-29 18:02:51 -0300 | [diff] [blame] | 541 | #endif |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 542 | {0x190, /* Video Program System (VPS), PAL */ |
| 543 | {V4L2_SLICED_VPS,16,16,0}, |
| 544 | { 0xaa, 0xaa, 0xff, 0xff, 0xba, 0xce, 0x2b, 0x0d, |
| 545 | 0xa6, 0xda, 0x0b, 0x00, 0x00, 0x00, 0x60, 0x00 } |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 546 | }, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 547 | /* 0x1d0 User programmable */ |
| 548 | |
| 549 | /* End of struct */ |
| 550 | { (u16)-1 } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 551 | }; |
| 552 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 553 | static int tvp5150_write_inittab(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 554 | const struct i2c_reg_value *regs) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 555 | { |
| 556 | while (regs->reg != 0xff) { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 557 | tvp5150_write(sd, regs->reg, regs->value); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 558 | regs++; |
| 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 563 | static int tvp5150_vdp_init(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 564 | const struct i2c_vbi_ram_value *regs) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 565 | { |
| 566 | unsigned int i; |
| 567 | |
| 568 | /* Disable Full Field */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 569 | tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 570 | |
| 571 | /* Before programming, Line mode should be at 0xff */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 572 | for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++) |
| 573 | tvp5150_write(sd, i, 0xff); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 574 | |
| 575 | /* Load Ram Table */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 576 | while (regs->reg != (u16)-1) { |
| 577 | tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_HIGH, regs->reg >> 8); |
| 578 | tvp5150_write(sd, TVP5150_CONF_RAM_ADDR_LOW, regs->reg); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 579 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 580 | for (i = 0; i < 16; i++) |
| 581 | tvp5150_write(sd, TVP5150_VDP_CONF_RAM_DATA, regs->values[i]); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 582 | |
| 583 | regs++; |
| 584 | } |
| 585 | return 0; |
| 586 | } |
| 587 | |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 588 | /* Fills VBI capabilities based on i2c_vbi_ram_value struct */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 589 | static int tvp5150_g_sliced_vbi_cap(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 590 | struct v4l2_sliced_vbi_cap *cap) |
| 591 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 592 | const struct i2c_vbi_ram_value *regs = vbi_ram_default; |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 593 | int line; |
| 594 | |
Hans Verkuil | bccfa44 | 2009-03-30 06:55:27 -0300 | [diff] [blame] | 595 | v4l2_dbg(1, debug, sd, "g_sliced_vbi_cap\n"); |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 596 | memset(cap, 0, sizeof *cap); |
| 597 | |
| 598 | while (regs->reg != (u16)-1 ) { |
| 599 | for (line=regs->type.ini_line;line<=regs->type.end_line;line++) { |
| 600 | cap->service_lines[0][line] |= regs->type.vbi_type; |
| 601 | } |
| 602 | cap->service_set |= regs->type.vbi_type; |
| 603 | |
| 604 | regs++; |
| 605 | } |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 606 | return 0; |
Mauro Carvalho Chehab | 6ac48b4 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 607 | } |
| 608 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 609 | /* Set vbi processing |
| 610 | * type - one of tvp5150_vbi_types |
| 611 | * line - line to gather data |
| 612 | * fields: bit 0 field1, bit 1, field2 |
| 613 | * flags (default=0xf0) is a bitmask, were set means: |
| 614 | * bit 7: enable filtering null bytes on CC |
| 615 | * bit 6: send data also to FIFO |
| 616 | * bit 5: don't allow data with errors on FIFO |
| 617 | * bit 4: enable ECC when possible |
| 618 | * pix_align = pix alignment: |
| 619 | * LSB = field1 |
| 620 | * MSB = field2 |
| 621 | */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 622 | static int tvp5150_set_vbi(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 623 | const struct i2c_vbi_ram_value *regs, |
| 624 | unsigned int type,u8 flags, int line, |
| 625 | const int fields) |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 626 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 627 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 628 | v4l2_std_id std = decoder->norm; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 629 | u8 reg; |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 630 | int pos=0; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 631 | |
| 632 | if (std == V4L2_STD_ALL) { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 633 | v4l2_err(sd, "VBI can't be configured without knowing number of lines\n"); |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 634 | return 0; |
Roel Kluin | 7d5b7b9 | 2008-03-09 21:19:13 -0300 | [diff] [blame] | 635 | } else if (std & V4L2_STD_625_50) { |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 636 | /* Don't follow NTSC Line number convension */ |
| 637 | line += 3; |
| 638 | } |
| 639 | |
| 640 | if (line<6||line>27) |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 641 | return 0; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 642 | |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 643 | while (regs->reg != (u16)-1 ) { |
| 644 | if ((type & regs->type.vbi_type) && |
| 645 | (line>=regs->type.ini_line) && |
| 646 | (line<=regs->type.end_line)) { |
| 647 | type=regs->type.vbi_type; |
| 648 | break; |
| 649 | } |
| 650 | |
| 651 | regs++; |
| 652 | pos++; |
| 653 | } |
| 654 | if (regs->reg == (u16)-1) |
| 655 | return 0; |
| 656 | |
| 657 | type=pos | (flags & 0xf0); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 658 | reg=((line-6)<<1)+TVP5150_LINE_MODE_INI; |
| 659 | |
| 660 | if (fields&1) { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 661 | tvp5150_write(sd, reg, type); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | if (fields&2) { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 665 | tvp5150_write(sd, reg+1, type); |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 666 | } |
| 667 | |
Mauro Carvalho Chehab | 2701dac | 2006-01-23 17:11:06 -0200 | [diff] [blame] | 668 | return type; |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 669 | } |
| 670 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 671 | static int tvp5150_get_vbi(struct v4l2_subdev *sd, |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 672 | const struct i2c_vbi_ram_value *regs, int line) |
| 673 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 674 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 675 | v4l2_std_id std = decoder->norm; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 676 | u8 reg; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 677 | int pos, type = 0; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 678 | int i, ret = 0; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 679 | |
| 680 | if (std == V4L2_STD_ALL) { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 681 | v4l2_err(sd, "VBI can't be configured without knowing number of lines\n"); |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 682 | return 0; |
Roel Kluin | 7d5b7b9 | 2008-03-09 21:19:13 -0300 | [diff] [blame] | 683 | } else if (std & V4L2_STD_625_50) { |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 684 | /* Don't follow NTSC Line number convension */ |
| 685 | line += 3; |
| 686 | } |
| 687 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 688 | if (line < 6 || line > 27) |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 689 | return 0; |
| 690 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 691 | reg = ((line - 6) << 1) + TVP5150_LINE_MODE_INI; |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 692 | |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 693 | for (i = 0; i <= 1; i++) { |
| 694 | ret = tvp5150_read(sd, reg + i); |
| 695 | if (ret < 0) { |
| 696 | v4l2_err(sd, "%s: failed with error = %d\n", |
| 697 | __func__, ret); |
| 698 | return 0; |
| 699 | } |
| 700 | pos = ret & 0x0f; |
| 701 | if (pos < 0x0f) |
| 702 | type |= regs[pos].type.vbi_type; |
| 703 | } |
Mauro Carvalho Chehab | 12db560 | 2006-01-23 17:11:08 -0200 | [diff] [blame] | 704 | |
| 705 | return type; |
| 706 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 707 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 708 | static int tvp5150_set_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 709 | { |
| 710 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 711 | int fmt = 0; |
| 712 | |
| 713 | decoder->norm = std; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 714 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 715 | /* First tests should be against specific std */ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 716 | |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 717 | if (std == V4L2_STD_NTSC_443) { |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 718 | fmt = VIDEO_STD_NTSC_4_43_BIT; |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 719 | } else if (std == V4L2_STD_PAL_M) { |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 720 | fmt = VIDEO_STD_PAL_M_BIT; |
Hans Verkuil | 26811ae | 2013-05-29 10:19:06 -0300 | [diff] [blame] | 721 | } 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] | 722 | fmt = VIDEO_STD_PAL_COMBINATION_N_BIT; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 723 | } else { |
| 724 | /* Then, test against generic ones */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 725 | if (std & V4L2_STD_NTSC) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 726 | fmt = VIDEO_STD_NTSC_MJ_BIT; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 727 | else if (std & V4L2_STD_PAL) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 728 | fmt = VIDEO_STD_PAL_BDGHIN_BIT; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 729 | else if (std & V4L2_STD_SECAM) |
Javier Martinez Canillas | 2da12fc | 2011-11-04 13:23:21 -0300 | [diff] [blame] | 730 | fmt = VIDEO_STD_SECAM_BIT; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 731 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 732 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 733 | v4l2_dbg(1, debug, sd, "Set video std register to %d.\n", fmt); |
| 734 | tvp5150_write(sd, TVP5150_VIDEO_STD, fmt); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 735 | return 0; |
| 736 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 737 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 738 | 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] | 739 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 740 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 741 | |
| 742 | if (decoder->norm == std) |
| 743 | return 0; |
| 744 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 745 | /* Change cropping height limits */ |
| 746 | if (std & V4L2_STD_525_60) |
| 747 | decoder->rect.height = TVP5150_V_MAX_525_60; |
| 748 | else |
| 749 | decoder->rect.height = TVP5150_V_MAX_OTHERS; |
| 750 | |
| 751 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 752 | return tvp5150_set_std(sd, std); |
| 753 | } |
| 754 | |
| 755 | static int tvp5150_reset(struct v4l2_subdev *sd, u32 val) |
| 756 | { |
| 757 | struct tvp5150 *decoder = to_tvp5150(sd); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 758 | |
| 759 | /* Initializes TVP5150 to its default values */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 760 | tvp5150_write_inittab(sd, tvp5150_init_default); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 761 | |
| 762 | /* Initializes VDP registers */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 763 | tvp5150_vdp_init(sd, vbi_ram_default); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 764 | |
| 765 | /* Selects decoder input */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 766 | tvp5150_selmux(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 767 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 768 | /* Initializes TVP5150 to stream enabled values */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 769 | tvp5150_write_inittab(sd, tvp5150_init_enable); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 770 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 771 | /* Initialize image preferences */ |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 772 | v4l2_ctrl_handler_setup(&decoder->hdl); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 773 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 774 | tvp5150_set_std(sd, decoder->norm); |
| 775 | return 0; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 776 | }; |
| 777 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 778 | static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 779 | { |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 780 | struct v4l2_subdev *sd = to_sd(ctrl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 781 | |
| 782 | switch (ctrl->id) { |
| 783 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 784 | tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 785 | return 0; |
| 786 | case V4L2_CID_CONTRAST: |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 787 | tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 788 | return 0; |
| 789 | case V4L2_CID_SATURATION: |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 790 | tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 791 | return 0; |
| 792 | case V4L2_CID_HUE: |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 793 | tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 794 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 795 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 796 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 797 | } |
| 798 | |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 799 | static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd) |
| 800 | { |
| 801 | int val = tvp5150_read(sd, TVP5150_STATUS_REG_5); |
| 802 | |
| 803 | switch (val & 0x0F) { |
| 804 | case 0x01: |
| 805 | return V4L2_STD_NTSC; |
| 806 | case 0x03: |
| 807 | return V4L2_STD_PAL; |
| 808 | case 0x05: |
| 809 | return V4L2_STD_PAL_M; |
| 810 | case 0x07: |
| 811 | return V4L2_STD_PAL_N | V4L2_STD_PAL_Nc; |
| 812 | case 0x09: |
| 813 | return V4L2_STD_NTSC_443; |
| 814 | case 0xb: |
| 815 | return V4L2_STD_SECAM; |
| 816 | default: |
| 817 | return V4L2_STD_UNKNOWN; |
| 818 | } |
| 819 | } |
| 820 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 821 | static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd, |
| 822 | struct v4l2_subdev_pad_config *cfg, |
| 823 | struct v4l2_subdev_mbus_code_enum *code) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 824 | { |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 825 | if (code->pad || code->index) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 826 | return -EINVAL; |
| 827 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 828 | code->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 829 | return 0; |
| 830 | } |
| 831 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 832 | static int tvp5150_fill_fmt(struct v4l2_subdev *sd, |
| 833 | struct v4l2_subdev_pad_config *cfg, |
| 834 | struct v4l2_subdev_format *format) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 835 | { |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 836 | struct v4l2_mbus_framefmt *f; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 837 | struct tvp5150 *decoder = to_tvp5150(sd); |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 838 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 839 | if (!format || format->pad) |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 840 | return -EINVAL; |
| 841 | |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 842 | f = &format->format; |
| 843 | |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 844 | tvp5150_reset(sd, 0); |
| 845 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 846 | f->width = decoder->rect.width; |
| 847 | f->height = decoder->rect.height; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 848 | |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 849 | f->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Javier Martin | ec2c4f3 | 2012-01-05 10:57:39 -0300 | [diff] [blame] | 850 | f->field = V4L2_FIELD_SEQ_TB; |
| 851 | f->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 852 | |
| 853 | v4l2_dbg(1, debug, sd, "width = %d, height = %d\n", f->width, |
| 854 | f->height); |
| 855 | return 0; |
| 856 | } |
| 857 | |
Hans Verkuil | 4f99659 | 2012-09-05 05:10:48 -0300 | [diff] [blame] | 858 | static int tvp5150_s_crop(struct v4l2_subdev *sd, const struct v4l2_crop *a) |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 859 | { |
| 860 | struct v4l2_rect rect = a->c; |
| 861 | struct tvp5150 *decoder = to_tvp5150(sd); |
| 862 | v4l2_std_id std; |
Ricardo Ribalda | f90580c | 2013-11-26 05:31:42 -0300 | [diff] [blame] | 863 | unsigned int hmax; |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 864 | |
| 865 | v4l2_dbg(1, debug, sd, "%s left=%d, top=%d, width=%d, height=%d\n", |
| 866 | __func__, rect.left, rect.top, rect.width, rect.height); |
| 867 | |
| 868 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 869 | return -EINVAL; |
| 870 | |
| 871 | /* tvp5150 has some special limits */ |
| 872 | rect.left = clamp(rect.left, 0, TVP5150_MAX_CROP_LEFT); |
Ricardo Ribalda | f90580c | 2013-11-26 05:31:42 -0300 | [diff] [blame] | 873 | rect.width = clamp_t(unsigned int, rect.width, |
| 874 | TVP5150_H_MAX - TVP5150_MAX_CROP_LEFT - rect.left, |
| 875 | TVP5150_H_MAX - rect.left); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 876 | rect.top = clamp(rect.top, 0, TVP5150_MAX_CROP_TOP); |
| 877 | |
| 878 | /* Calculate height based on current standard */ |
| 879 | if (decoder->norm == V4L2_STD_ALL) |
| 880 | std = tvp5150_read_std(sd); |
| 881 | else |
| 882 | std = decoder->norm; |
| 883 | |
| 884 | if (std & V4L2_STD_525_60) |
| 885 | hmax = TVP5150_V_MAX_525_60; |
| 886 | else |
| 887 | hmax = TVP5150_V_MAX_OTHERS; |
| 888 | |
Ricardo Ribalda | f90580c | 2013-11-26 05:31:42 -0300 | [diff] [blame] | 889 | rect.height = clamp_t(unsigned int, rect.height, |
| 890 | hmax - TVP5150_MAX_CROP_TOP - rect.top, |
| 891 | hmax - rect.top); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 892 | |
| 893 | tvp5150_write(sd, TVP5150_VERT_BLANKING_START, rect.top); |
| 894 | tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, |
| 895 | rect.top + rect.height - hmax); |
| 896 | tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_MSB, |
| 897 | rect.left >> TVP5150_CROP_SHIFT); |
| 898 | tvp5150_write(sd, TVP5150_ACT_VD_CROP_ST_LSB, |
| 899 | rect.left | (1 << TVP5150_CROP_SHIFT)); |
| 900 | tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_MSB, |
| 901 | (rect.left + rect.width - TVP5150_MAX_CROP_LEFT) >> |
| 902 | TVP5150_CROP_SHIFT); |
| 903 | tvp5150_write(sd, TVP5150_ACT_VD_CROP_STP_LSB, |
| 904 | rect.left + rect.width - TVP5150_MAX_CROP_LEFT); |
| 905 | |
| 906 | decoder->rect = rect; |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int tvp5150_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) |
| 912 | { |
Laurent Pinchart | 12bd10c | 2014-05-15 22:53:31 -0300 | [diff] [blame] | 913 | struct tvp5150 *decoder = to_tvp5150(sd); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 914 | |
| 915 | a->c = decoder->rect; |
| 916 | a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 917 | |
| 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | static int tvp5150_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) |
| 922 | { |
Laurent Pinchart | 12bd10c | 2014-05-15 22:53:31 -0300 | [diff] [blame] | 923 | struct tvp5150 *decoder = to_tvp5150(sd); |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 924 | v4l2_std_id std; |
| 925 | |
| 926 | if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 927 | return -EINVAL; |
| 928 | |
| 929 | a->bounds.left = 0; |
| 930 | a->bounds.top = 0; |
| 931 | a->bounds.width = TVP5150_H_MAX; |
| 932 | |
| 933 | /* Calculate height based on current standard */ |
| 934 | if (decoder->norm == V4L2_STD_ALL) |
| 935 | std = tvp5150_read_std(sd); |
| 936 | else |
| 937 | std = decoder->norm; |
| 938 | |
| 939 | if (std & V4L2_STD_525_60) |
| 940 | a->bounds.height = TVP5150_V_MAX_525_60; |
| 941 | else |
| 942 | a->bounds.height = TVP5150_V_MAX_OTHERS; |
| 943 | |
| 944 | a->defrect = a->bounds; |
| 945 | a->pixelaspect.numerator = 1; |
| 946 | a->pixelaspect.denominator = 1; |
| 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 951 | /**************************************************************************** |
| 952 | I2C Command |
| 953 | ****************************************************************************/ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 954 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 955 | static int tvp5150_s_routing(struct v4l2_subdev *sd, |
| 956 | u32 input, u32 output, u32 config) |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 957 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 958 | struct tvp5150 *decoder = to_tvp5150(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 959 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 960 | decoder->input = input; |
| 961 | decoder->output = output; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 962 | tvp5150_selmux(sd); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 963 | return 0; |
| 964 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 965 | |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 966 | 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] | 967 | { |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 968 | /* this is for capturing 36 raw vbi lines |
| 969 | if there's a way to cut off the beginning 2 vbi lines |
| 970 | with the tvp5150 then the vbi line count could be lowered |
| 971 | to 17 lines/field again, although I couldn't find a register |
| 972 | which could do that cropping */ |
| 973 | if (fmt->sample_format == V4L2_PIX_FMT_GREY) |
| 974 | tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70); |
| 975 | if (fmt->count[0] == 18 && fmt->count[1] == 18) { |
| 976 | tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00); |
| 977 | tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01); |
| 978 | } |
| 979 | return 0; |
| 980 | } |
| 981 | |
| 982 | static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi) |
| 983 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 984 | int i; |
| 985 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 986 | if (svbi->service_set != 0) { |
| 987 | for (i = 0; i <= 23; i++) { |
| 988 | svbi->service_lines[1][i] = 0; |
| 989 | svbi->service_lines[0][i] = |
| 990 | tvp5150_set_vbi(sd, vbi_ram_default, |
| 991 | svbi->service_lines[0][i], 0xf0, i, 3); |
| 992 | } |
| 993 | /* Enables FIFO */ |
| 994 | tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 1); |
| 995 | } else { |
| 996 | /* Disables FIFO*/ |
| 997 | tvp5150_write(sd, TVP5150_FIFO_OUT_CTRL, 0); |
| 998 | |
| 999 | /* Disable Full Field */ |
| 1000 | tvp5150_write(sd, TVP5150_FULL_FIELD_ENA, 0); |
| 1001 | |
| 1002 | /* Disable Line modes */ |
| 1003 | for (i = TVP5150_LINE_MODE_INI; i <= TVP5150_LINE_MODE_END; i++) |
| 1004 | tvp5150_write(sd, i, 0xff); |
| 1005 | } |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1009 | static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi) |
| 1010 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1011 | int i, mask = 0; |
| 1012 | |
Hans Verkuil | 30634e8 | 2012-09-05 10:38:10 -0300 | [diff] [blame] | 1013 | memset(svbi->service_lines, 0, sizeof(svbi->service_lines)); |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1014 | |
| 1015 | for (i = 0; i <= 23; i++) { |
| 1016 | svbi->service_lines[0][i] = |
| 1017 | tvp5150_get_vbi(sd, vbi_ram_default, i); |
| 1018 | mask |= svbi->service_lines[0][i]; |
| 1019 | } |
| 1020 | svbi->service_set = mask; |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1024 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1025 | 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] | 1026 | { |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1027 | int res; |
| 1028 | |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1029 | res = tvp5150_read(sd, reg->reg & 0xff); |
| 1030 | if (res < 0) { |
| 1031 | v4l2_err(sd, "%s: failed with error = %d\n", __func__, res); |
| 1032 | return res; |
| 1033 | } |
| 1034 | |
| 1035 | reg->val = res; |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1036 | reg->size = 1; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1037 | return 0; |
| 1038 | } |
| 1039 | |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 1040 | 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] | 1041 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1042 | tvp5150_write(sd, reg->reg & 0xff, reg->val & 0xff); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | #endif |
| 1046 | |
| 1047 | static int tvp5150_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) |
| 1048 | { |
| 1049 | int status = tvp5150_read(sd, 0x88); |
| 1050 | |
| 1051 | vt->signal = ((status & 0x04) && (status & 0x02)) ? 0xffff : 0x0; |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1055 | /* ----------------------------------------------------------------------- */ |
| 1056 | |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1057 | static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = { |
| 1058 | .s_ctrl = tvp5150_s_ctrl, |
| 1059 | }; |
| 1060 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1061 | static const struct v4l2_subdev_core_ops tvp5150_core_ops = { |
| 1062 | .log_status = tvp5150_log_status, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1063 | .reset = tvp5150_reset, |
| 1064 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 1065 | .g_register = tvp5150_g_register, |
| 1066 | .s_register = tvp5150_s_register, |
| 1067 | #endif |
| 1068 | }; |
| 1069 | |
| 1070 | static const struct v4l2_subdev_tuner_ops tvp5150_tuner_ops = { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1071 | .g_tuner = tvp5150_g_tuner, |
| 1072 | }; |
| 1073 | |
| 1074 | static const struct v4l2_subdev_video_ops tvp5150_video_ops = { |
Laurent Pinchart | 8774bed | 2014-04-28 16:53:01 -0300 | [diff] [blame] | 1075 | .s_std = tvp5150_s_std, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1076 | .s_routing = tvp5150_s_routing, |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1077 | .s_crop = tvp5150_s_crop, |
| 1078 | .g_crop = tvp5150_g_crop, |
| 1079 | .cropcap = tvp5150_cropcap, |
Hans Verkuil | 32cd527 | 2010-03-14 09:57:30 -0300 | [diff] [blame] | 1080 | }; |
| 1081 | |
| 1082 | static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1083 | .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap, |
Hans Verkuil | d37dad4 | 2010-03-14 10:59:16 -0300 | [diff] [blame] | 1084 | .g_sliced_fmt = tvp5150_g_sliced_fmt, |
| 1085 | .s_sliced_fmt = tvp5150_s_sliced_fmt, |
| 1086 | .s_raw_fmt = tvp5150_s_raw_fmt, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1087 | }; |
| 1088 | |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1089 | static const struct v4l2_subdev_pad_ops tvp5150_pad_ops = { |
| 1090 | .enum_mbus_code = tvp5150_enum_mbus_code, |
Hans Verkuil | da298c6 | 2015-04-09 04:02:34 -0300 | [diff] [blame] | 1091 | .set_fmt = tvp5150_fill_fmt, |
| 1092 | .get_fmt = tvp5150_fill_fmt, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1093 | }; |
| 1094 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1095 | static const struct v4l2_subdev_ops tvp5150_ops = { |
| 1096 | .core = &tvp5150_core_ops, |
| 1097 | .tuner = &tvp5150_tuner_ops, |
| 1098 | .video = &tvp5150_video_ops, |
Hans Verkuil | 32cd527 | 2010-03-14 09:57:30 -0300 | [diff] [blame] | 1099 | .vbi = &tvp5150_vbi_ops, |
Hans Verkuil | ebcff5f | 2015-04-09 04:01:33 -0300 | [diff] [blame] | 1100 | .pad = &tvp5150_pad_ops, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1101 | }; |
| 1102 | |
| 1103 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1104 | /**************************************************************************** |
| 1105 | I2C Client & Driver |
| 1106 | ****************************************************************************/ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1107 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1108 | static int tvp5150_probe(struct i2c_client *c, |
| 1109 | const struct i2c_device_id *id) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1110 | { |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1111 | struct tvp5150 *core; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1112 | struct v4l2_subdev *sd; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1113 | int tvp5150_id[4]; |
| 1114 | int i, res; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1115 | |
| 1116 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1117 | if (!i2c_check_functionality(c->adapter, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1118 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1119 | return -EIO; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1120 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 1121 | core = devm_kzalloc(&c->dev, sizeof(*core), GFP_KERNEL); |
| 1122 | if (!core) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1123 | return -ENOMEM; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1124 | sd = &core->sd; |
| 1125 | v4l2_i2c_subdev_init(sd, c, &tvp5150_ops); |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1126 | |
| 1127 | /* |
| 1128 | * Read consequent registers - TVP5150_MSB_DEV_ID, TVP5150_LSB_DEV_ID, |
| 1129 | * TVP5150_ROM_MAJOR_VER, TVP5150_ROM_MINOR_VER |
| 1130 | */ |
| 1131 | for (i = 0; i < 4; i++) { |
| 1132 | res = tvp5150_read(sd, TVP5150_MSB_DEV_ID + i); |
| 1133 | if (res < 0) |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 1134 | return res; |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1135 | tvp5150_id[i] = res; |
| 1136 | } |
| 1137 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1138 | v4l_info(c, "chip found @ 0x%02x (%s)\n", |
| 1139 | c->addr << 1, c->adapter->name); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1140 | |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1141 | if (tvp5150_id[2] == 4 && tvp5150_id[3] == 0) { /* Is TVP5150AM1 */ |
| 1142 | v4l2_info(sd, "tvp%02x%02xam1 detected.\n", |
| 1143 | tvp5150_id[0], tvp5150_id[1]); |
Mauro Carvalho Chehab | 0e09a3c | 2011-02-22 00:10:22 -0300 | [diff] [blame] | 1144 | |
| 1145 | /* ITU-T BT.656.4 timing */ |
| 1146 | tvp5150_write(sd, TVP5150_REV_SELECT, 0); |
| 1147 | } else { |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1148 | /* Is TVP5150A */ |
| 1149 | if (tvp5150_id[2] == 3 || tvp5150_id[3] == 0x21) { |
| 1150 | v4l2_info(sd, "tvp%02x%02xa detected.\n", |
Laurent Pinchart | 385dded | 2014-05-26 16:28:31 -0300 | [diff] [blame] | 1151 | tvp5150_id[0], tvp5150_id[1]); |
Mauro Carvalho Chehab | 0e09a3c | 2011-02-22 00:10:22 -0300 | [diff] [blame] | 1152 | } else { |
| 1153 | v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n", |
Laurent Pinchart | 385dded | 2014-05-26 16:28:31 -0300 | [diff] [blame] | 1154 | tvp5150_id[0], tvp5150_id[1]); |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1155 | v4l2_info(sd, "*** Rom ver is %d.%d\n", |
| 1156 | tvp5150_id[2], tvp5150_id[3]); |
Mauro Carvalho Chehab | 0e09a3c | 2011-02-22 00:10:22 -0300 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | |
Mauro Carvalho Chehab | 3ad9683 | 2006-01-23 17:11:05 -0200 | [diff] [blame] | 1160 | core->norm = V4L2_STD_ALL; /* Default is autodetect */ |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 1161 | core->input = TVP5150_COMPOSITE1; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1162 | core->enable = 1; |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1163 | |
| 1164 | v4l2_ctrl_handler_init(&core->hdl, 4); |
| 1165 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1166 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); |
| 1167 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1168 | V4L2_CID_CONTRAST, 0, 255, 1, 128); |
| 1169 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1170 | V4L2_CID_SATURATION, 0, 255, 1, 128); |
| 1171 | v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops, |
| 1172 | V4L2_CID_HUE, -128, 127, 1, 0); |
| 1173 | sd->ctrl_handler = &core->hdl; |
| 1174 | if (core->hdl.error) { |
Dmitry Lifshitz | 8cd0d4c | 2012-06-13 07:49:30 -0300 | [diff] [blame] | 1175 | res = core->hdl.error; |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1176 | goto err; |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1177 | } |
| 1178 | v4l2_ctrl_handler_setup(&core->hdl); |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1179 | |
Javier Martin | 963ddc6 | 2012-01-31 05:23:46 -0300 | [diff] [blame] | 1180 | /* Default is no cropping */ |
| 1181 | core->rect.top = 0; |
| 1182 | if (tvp5150_read_std(sd) & V4L2_STD_525_60) |
| 1183 | core->rect.height = TVP5150_V_MAX_525_60; |
| 1184 | else |
| 1185 | core->rect.height = TVP5150_V_MAX_OTHERS; |
| 1186 | core->rect.left = 0; |
| 1187 | core->rect.width = TVP5150_H_MAX; |
| 1188 | |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1189 | res = v4l2_async_register_subdev(sd); |
| 1190 | if (res < 0) |
| 1191 | goto err; |
| 1192 | |
Markus Rechberger | f1e5ee4 | 2006-02-07 04:01:19 +0100 | [diff] [blame] | 1193 | if (debug > 1) |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1194 | tvp5150_log_status(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1195 | return 0; |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1196 | |
| 1197 | err: |
| 1198 | v4l2_ctrl_handler_free(&core->hdl); |
| 1199 | return res; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1200 | } |
| 1201 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1202 | static int tvp5150_remove(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1203 | { |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1204 | struct v4l2_subdev *sd = i2c_get_clientdata(c); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1205 | struct tvp5150 *decoder = to_tvp5150(sd); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1206 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1207 | v4l2_dbg(1, debug, sd, |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1208 | "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", |
| 1209 | c->addr << 1); |
| 1210 | |
Javier Martinez Canillas | c7d9749 | 2015-09-21 08:23:09 -0300 | [diff] [blame] | 1211 | v4l2_async_unregister_subdev(sd); |
Hans Verkuil | 6c45ec7 | 2010-12-12 08:45:43 -0300 | [diff] [blame] | 1212 | v4l2_ctrl_handler_free(&decoder->hdl); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | /* ----------------------------------------------------------------------- */ |
| 1217 | |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1218 | static const struct i2c_device_id tvp5150_id[] = { |
| 1219 | { "tvp5150", 0 }, |
| 1220 | { } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1221 | }; |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1222 | MODULE_DEVICE_TABLE(i2c, tvp5150_id); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1223 | |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1224 | static struct i2c_driver tvp5150_driver = { |
| 1225 | .driver = { |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1226 | .name = "tvp5150", |
| 1227 | }, |
| 1228 | .probe = tvp5150_probe, |
| 1229 | .remove = tvp5150_remove, |
| 1230 | .id_table = tvp5150_id, |
Hans Verkuil | 6b8fe02 | 2008-12-18 11:17:25 -0300 | [diff] [blame] | 1231 | }; |
Hans Verkuil | c771145 | 2010-09-15 15:45:20 -0300 | [diff] [blame] | 1232 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 1233 | module_i2c_driver(tvp5150_driver); |