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