Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1 | /* cx25840 - Conexant CX25840 audio/video decoder driver |
| 2 | * |
| 3 | * Copyright (C) 2004 Ulf Eklund |
| 4 | * |
| 5 | * Based on the saa7115 driver and on the first verison of Chris Kennedy's |
| 6 | * cx25840 driver. |
| 7 | * |
| 8 | * Changes by Tyler Trafford <tatrafford@comcast.net> |
| 9 | * - cleanup/rewrite for V4L2 API (2005) |
| 10 | * |
| 11 | * VBI support by Hans Verkuil <hverkuil@xs4all.nl>. |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License |
| 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | * of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/videodev2.h> |
| 33 | #include <linux/i2c.h> |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 34 | #include <media/v4l2-common.h> |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 35 | #include <media/cx25840.h> |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 36 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 37 | #include "cx25840-core.h" |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 38 | |
| 39 | MODULE_DESCRIPTION("Conexant CX25840 audio/video decoder driver"); |
Hans Verkuil | 1f4b336 | 2005-11-13 16:08:05 -0800 | [diff] [blame] | 40 | MODULE_AUTHOR("Ulf Eklund, Chris Kennedy, Hans Verkuil, Tyler Trafford"); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 41 | MODULE_LICENSE("GPL"); |
| 42 | |
| 43 | static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; |
| 44 | |
| 45 | |
Adrian Bunk | a9cff90 | 2006-01-15 06:56:15 -0200 | [diff] [blame] | 46 | static int cx25840_debug; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 47 | |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 48 | module_param_named(debug,cx25840_debug, int, 0644); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 49 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 50 | MODULE_PARM_DESC(debug, "Debugging messages [0=Off (default) 1=On]"); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 51 | |
| 52 | I2C_CLIENT_INSMOD; |
| 53 | |
| 54 | /* ----------------------------------------------------------------------- */ |
| 55 | |
| 56 | int cx25840_write(struct i2c_client *client, u16 addr, u8 value) |
| 57 | { |
| 58 | u8 buffer[3]; |
| 59 | buffer[0] = addr >> 8; |
| 60 | buffer[1] = addr & 0xff; |
| 61 | buffer[2] = value; |
| 62 | return i2c_master_send(client, buffer, 3); |
| 63 | } |
| 64 | |
| 65 | int cx25840_write4(struct i2c_client *client, u16 addr, u32 value) |
| 66 | { |
| 67 | u8 buffer[6]; |
| 68 | buffer[0] = addr >> 8; |
| 69 | buffer[1] = addr & 0xff; |
| 70 | buffer[2] = value >> 24; |
| 71 | buffer[3] = (value >> 16) & 0xff; |
| 72 | buffer[4] = (value >> 8) & 0xff; |
| 73 | buffer[5] = value & 0xff; |
| 74 | return i2c_master_send(client, buffer, 6); |
| 75 | } |
| 76 | |
| 77 | u8 cx25840_read(struct i2c_client * client, u16 addr) |
| 78 | { |
| 79 | u8 buffer[2]; |
| 80 | buffer[0] = addr >> 8; |
| 81 | buffer[1] = addr & 0xff; |
| 82 | |
| 83 | if (i2c_master_send(client, buffer, 2) < 2) |
| 84 | return 0; |
| 85 | |
| 86 | if (i2c_master_recv(client, buffer, 1) < 1) |
| 87 | return 0; |
| 88 | |
| 89 | return buffer[0]; |
| 90 | } |
| 91 | |
| 92 | u32 cx25840_read4(struct i2c_client * client, u16 addr) |
| 93 | { |
| 94 | u8 buffer[4]; |
| 95 | buffer[0] = addr >> 8; |
| 96 | buffer[1] = addr & 0xff; |
| 97 | |
| 98 | if (i2c_master_send(client, buffer, 2) < 2) |
| 99 | return 0; |
| 100 | |
| 101 | if (i2c_master_recv(client, buffer, 4) < 4) |
| 102 | return 0; |
| 103 | |
| 104 | return (buffer[0] << 24) | (buffer[1] << 16) | |
| 105 | (buffer[2] << 8) | buffer[3]; |
| 106 | } |
| 107 | |
| 108 | int cx25840_and_or(struct i2c_client *client, u16 addr, u8 and_mask, |
| 109 | u8 or_value) |
| 110 | { |
| 111 | return cx25840_write(client, addr, |
| 112 | (cx25840_read(client, addr) & and_mask) | |
| 113 | or_value); |
| 114 | } |
| 115 | |
| 116 | /* ----------------------------------------------------------------------- */ |
| 117 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 118 | static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input, |
| 119 | enum cx25840_audio_input aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 120 | static void log_status(struct i2c_client *client); |
| 121 | |
| 122 | /* ----------------------------------------------------------------------- */ |
| 123 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 124 | static void init_dll1(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 125 | { |
| 126 | /* This is the Hauppauge sequence used to |
| 127 | * initialize the Delay Lock Loop 1 (ADC DLL). */ |
| 128 | cx25840_write(client, 0x159, 0x23); |
| 129 | cx25840_write(client, 0x15a, 0x87); |
| 130 | cx25840_write(client, 0x15b, 0x06); |
| 131 | cx25840_write(client, 0x159, 0xe1); |
| 132 | cx25840_write(client, 0x15a, 0x86); |
| 133 | cx25840_write(client, 0x159, 0xe0); |
| 134 | cx25840_write(client, 0x159, 0xe1); |
| 135 | cx25840_write(client, 0x15b, 0x10); |
| 136 | } |
| 137 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 138 | static void init_dll2(struct i2c_client *client) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 139 | { |
| 140 | /* This is the Hauppauge sequence used to |
| 141 | * initialize the Delay Lock Loop 2 (ADC DLL). */ |
| 142 | cx25840_write(client, 0x15d, 0xe3); |
| 143 | cx25840_write(client, 0x15e, 0x86); |
| 144 | cx25840_write(client, 0x15f, 0x06); |
| 145 | cx25840_write(client, 0x15d, 0xe1); |
| 146 | cx25840_write(client, 0x15d, 0xe0); |
| 147 | cx25840_write(client, 0x15d, 0xe1); |
| 148 | } |
| 149 | |
| 150 | static void cx25840_initialize(struct i2c_client *client, int loadfw) |
| 151 | { |
| 152 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 153 | |
| 154 | /* datasheet startup in numbered steps, refer to page 3-77 */ |
| 155 | /* 2. */ |
| 156 | cx25840_and_or(client, 0x803, ~0x10, 0x00); |
| 157 | /* The default of this register should be 4, but I get 0 instead. |
| 158 | * Set this register to 4 manually. */ |
| 159 | cx25840_write(client, 0x000, 0x04); |
| 160 | /* 3. */ |
| 161 | init_dll1(client); |
| 162 | init_dll2(client); |
| 163 | cx25840_write(client, 0x136, 0x0a); |
| 164 | /* 4. */ |
| 165 | cx25840_write(client, 0x13c, 0x01); |
| 166 | cx25840_write(client, 0x13c, 0x00); |
| 167 | /* 5. */ |
| 168 | if (loadfw) |
| 169 | cx25840_loadfw(client); |
| 170 | /* 6. */ |
| 171 | cx25840_write(client, 0x115, 0x8c); |
| 172 | cx25840_write(client, 0x116, 0x07); |
| 173 | cx25840_write(client, 0x118, 0x02); |
| 174 | /* 7. */ |
| 175 | cx25840_write(client, 0x4a5, 0x80); |
| 176 | cx25840_write(client, 0x4a5, 0x00); |
| 177 | cx25840_write(client, 0x402, 0x00); |
| 178 | /* 8. */ |
Hans Verkuil | 73dcddc | 2006-03-16 20:23:47 -0300 | [diff] [blame] | 179 | cx25840_and_or(client, 0x401, ~0x18, 0); |
| 180 | cx25840_and_or(client, 0x4a2, ~0x10, 0x10); |
| 181 | /* steps 8c and 8d are done in change_input() */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 182 | /* 10. */ |
| 183 | cx25840_write(client, 0x8d3, 0x1f); |
| 184 | cx25840_write(client, 0x8e3, 0x03); |
| 185 | |
| 186 | cx25840_vbi_setup(client); |
| 187 | |
| 188 | /* trial and error says these are needed to get audio */ |
| 189 | cx25840_write(client, 0x914, 0xa0); |
| 190 | cx25840_write(client, 0x918, 0xa0); |
| 191 | cx25840_write(client, 0x919, 0x01); |
| 192 | |
| 193 | /* stereo prefered */ |
| 194 | cx25840_write(client, 0x809, 0x04); |
| 195 | /* AC97 shift */ |
| 196 | cx25840_write(client, 0x8cf, 0x0f); |
| 197 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 198 | /* (re)set input */ |
| 199 | set_input(client, state->vid_input, state->aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 200 | |
| 201 | /* start microcontroller */ |
| 202 | cx25840_and_or(client, 0x803, ~0x10, 0x10); |
| 203 | } |
| 204 | |
| 205 | /* ----------------------------------------------------------------------- */ |
| 206 | |
| 207 | static void input_change(struct i2c_client *client) |
| 208 | { |
Hans Verkuil | f95006f | 2005-12-01 00:51:42 -0800 | [diff] [blame] | 209 | struct cx25840_state *state = i2c_get_clientdata(client); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 210 | v4l2_std_id std = cx25840_get_v4lstd(client); |
| 211 | |
Hans Verkuil | 73dcddc | 2006-03-16 20:23:47 -0300 | [diff] [blame] | 212 | /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */ |
| 213 | if (std & V4L2_STD_SECAM) { |
| 214 | cx25840_write(client, 0x402, 0); |
| 215 | } |
| 216 | else { |
| 217 | cx25840_write(client, 0x402, 0x04); |
| 218 | cx25840_write(client, 0x49f, (std & V4L2_STD_NTSC) ? 0x14 : 0x11); |
| 219 | } |
| 220 | cx25840_and_or(client, 0x401, ~0x60, 0); |
| 221 | cx25840_and_or(client, 0x401, ~0x60, 0x60); |
| 222 | |
Hans Verkuil | f95006f | 2005-12-01 00:51:42 -0800 | [diff] [blame] | 223 | /* Note: perhaps V4L2_STD_PAL_M should be handled as V4L2_STD_NTSC |
| 224 | instead of V4L2_STD_PAL. Someone needs to test this. */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 225 | if (std & V4L2_STD_PAL) { |
| 226 | /* Follow tuner change procedure for PAL */ |
| 227 | cx25840_write(client, 0x808, 0xff); |
| 228 | cx25840_write(client, 0x80b, 0x10); |
| 229 | } else if (std & V4L2_STD_SECAM) { |
| 230 | /* Select autodetect for SECAM */ |
| 231 | cx25840_write(client, 0x808, 0xff); |
| 232 | cx25840_write(client, 0x80b, 0x10); |
| 233 | } else if (std & V4L2_STD_NTSC) { |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 234 | /* Certain Hauppauge PVR150 models have a hardware bug |
| 235 | that causes audio to drop out. For these models the |
| 236 | audio standard must be set explicitly. |
| 237 | To be precise: it affects cards with tuner models |
| 238 | 85, 99 and 112 (model numbers from tveeprom). */ |
| 239 | int hw_fix = state->pvr150_workaround; |
| 240 | |
| 241 | if (std == V4L2_STD_NTSC_M_JP) { |
Hans Verkuil | f95006f | 2005-12-01 00:51:42 -0800 | [diff] [blame] | 242 | /* Japan uses EIAJ audio standard */ |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 243 | cx25840_write(client, 0x808, hw_fix ? 0x2f : 0xf7); |
| 244 | } else if (std == V4L2_STD_NTSC_M_KR) { |
| 245 | /* South Korea uses A2 audio standard */ |
| 246 | cx25840_write(client, 0x808, hw_fix ? 0x3f : 0xf8); |
Hans Verkuil | f95006f | 2005-12-01 00:51:42 -0800 | [diff] [blame] | 247 | } else { |
| 248 | /* Others use the BTSC audio standard */ |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 249 | cx25840_write(client, 0x808, hw_fix ? 0x1f : 0xf6); |
Hans Verkuil | f95006f | 2005-12-01 00:51:42 -0800 | [diff] [blame] | 250 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 251 | cx25840_write(client, 0x80b, 0x00); |
| 252 | } |
| 253 | |
| 254 | if (cx25840_read(client, 0x803) & 0x10) { |
| 255 | /* restart audio decoder microcontroller */ |
| 256 | cx25840_and_or(client, 0x803, ~0x10, 0x00); |
| 257 | cx25840_and_or(client, 0x803, ~0x10, 0x10); |
| 258 | } |
| 259 | } |
| 260 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 261 | static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input, |
| 262 | enum cx25840_audio_input aud_input) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 263 | { |
| 264 | struct cx25840_state *state = i2c_get_clientdata(client); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 265 | u8 is_composite = (vid_input >= CX25840_COMPOSITE1 && |
| 266 | vid_input <= CX25840_COMPOSITE8); |
| 267 | u8 reg; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 268 | |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 269 | v4l_dbg(1, cx25840_debug, client, "decoder set video input %d, audio input %d\n", |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 270 | vid_input, aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 271 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 272 | if (is_composite) { |
| 273 | reg = 0xf0 + (vid_input - CX25840_COMPOSITE1); |
| 274 | } else { |
| 275 | int luma = vid_input & 0xf0; |
| 276 | int chroma = vid_input & 0xf00; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 277 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 278 | if ((vid_input & ~0xff0) || |
| 279 | luma < CX25840_SVIDEO_LUMA1 || luma > CX25840_SVIDEO_LUMA4 || |
| 280 | chroma < CX25840_SVIDEO_CHROMA4 || chroma > CX25840_SVIDEO_CHROMA8) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 281 | v4l_err(client, "0x%04x is not a valid video input!\n", vid_input); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 282 | return -EINVAL; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 283 | } |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 284 | reg = 0xf0 + ((luma - CX25840_SVIDEO_LUMA1) >> 4); |
| 285 | if (chroma >= CX25840_SVIDEO_CHROMA7) { |
| 286 | reg &= 0x3f; |
| 287 | reg |= (chroma - CX25840_SVIDEO_CHROMA7) >> 2; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 288 | } else { |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 289 | reg &= 0xcf; |
| 290 | reg |= (chroma - CX25840_SVIDEO_CHROMA4) >> 4; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 291 | } |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 292 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 293 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 294 | switch (aud_input) { |
| 295 | case CX25840_AUDIO_SERIAL: |
| 296 | /* do nothing, use serial audio input */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 297 | break; |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 298 | case CX25840_AUDIO4: reg &= ~0x30; break; |
| 299 | case CX25840_AUDIO5: reg &= ~0x30; reg |= 0x10; break; |
| 300 | case CX25840_AUDIO6: reg &= ~0x30; reg |= 0x20; break; |
| 301 | case CX25840_AUDIO7: reg &= ~0xc0; break; |
| 302 | case CX25840_AUDIO8: reg &= ~0xc0; reg |= 0x40; break; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 303 | |
| 304 | default: |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 305 | v4l_err(client, "0x%04x is not a valid audio input!\n", aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 306 | return -EINVAL; |
| 307 | } |
| 308 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 309 | cx25840_write(client, 0x103, reg); |
| 310 | /* Set INPUT_MODE to Composite (0) or S-Video (1) */ |
| 311 | cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02); |
| 312 | /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */ |
| 313 | cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0); |
| 314 | /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2 and CH3 */ |
| 315 | if ((reg & 0xc0) != 0xc0 && (reg & 0x30) != 0x30) |
| 316 | cx25840_and_or(client, 0x102, ~0x4, 4); |
| 317 | else |
| 318 | cx25840_and_or(client, 0x102, ~0x4, 0); |
| 319 | |
| 320 | state->vid_input = vid_input; |
| 321 | state->aud_input = aud_input; |
| 322 | cx25840_audio_set_path(client); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 323 | input_change(client); |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | /* ----------------------------------------------------------------------- */ |
| 328 | |
| 329 | static int set_v4lstd(struct i2c_client *client, v4l2_std_id std) |
| 330 | { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 331 | u8 fmt=0; /* zero is autodetect */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 333 | /* First tests should be against specific std */ |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 334 | if (std == V4L2_STD_NTSC_M_JP) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 335 | fmt=0x2; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 336 | } else if (std == V4L2_STD_NTSC_443) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 337 | fmt=0x3; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 338 | } else if (std == V4L2_STD_PAL_M) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 339 | fmt=0x5; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 340 | } else if (std == V4L2_STD_PAL_N) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 341 | fmt=0x6; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 342 | } else if (std == V4L2_STD_PAL_Nc) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 343 | fmt=0x7; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 344 | } else if (std == V4L2_STD_PAL_60) { |
Mauro Carvalho Chehab | 468a0a5 | 2005-12-19 08:54:11 -0200 | [diff] [blame] | 345 | fmt=0x8; |
| 346 | } else { |
| 347 | /* Then, test against generic ones */ |
| 348 | if (std & V4L2_STD_NTSC) { |
| 349 | fmt=0x1; |
| 350 | } else if (std & V4L2_STD_PAL) { |
| 351 | fmt=0x4; |
| 352 | } else if (std & V4L2_STD_SECAM) { |
| 353 | fmt=0xc; |
| 354 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Hans Verkuil | 73dcddc | 2006-03-16 20:23:47 -0300 | [diff] [blame] | 357 | /* Follow step 9 of section 3.16 in the cx25840 datasheet. |
| 358 | Without this PAL may display a vertical ghosting effect. |
| 359 | This happens for example with the Yuan MPC622. */ |
| 360 | if (fmt >= 4 && fmt < 8) { |
| 361 | /* Set format to NTSC-M */ |
| 362 | cx25840_and_or(client, 0x400, ~0xf, 1); |
| 363 | /* Turn off LCOMB */ |
| 364 | cx25840_and_or(client, 0x47b, ~6, 0); |
| 365 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 366 | cx25840_and_or(client, 0x400, ~0xf, fmt); |
| 367 | cx25840_vbi_setup(client); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client) |
| 372 | { |
| 373 | /* check VID_FMT_SEL first */ |
| 374 | u8 fmt = cx25840_read(client, 0x400) & 0xf; |
| 375 | |
| 376 | if (!fmt) { |
| 377 | /* check AFD_FMT_STAT if set to autodetect */ |
| 378 | fmt = cx25840_read(client, 0x40d) & 0xf; |
| 379 | } |
| 380 | |
| 381 | switch (fmt) { |
Hans Verkuil | 73dcddc | 2006-03-16 20:23:47 -0300 | [diff] [blame] | 382 | case 0x1: |
| 383 | { |
| 384 | /* if the audio std is A2-M, then this is the South Korean |
| 385 | NTSC standard */ |
| 386 | if (cx25840_read(client, 0x805) == 2) |
| 387 | return V4L2_STD_NTSC_M_KR; |
| 388 | return V4L2_STD_NTSC_M; |
| 389 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 390 | case 0x2: return V4L2_STD_NTSC_M_JP; |
| 391 | case 0x3: return V4L2_STD_NTSC_443; |
| 392 | case 0x4: return V4L2_STD_PAL; |
| 393 | case 0x5: return V4L2_STD_PAL_M; |
| 394 | case 0x6: return V4L2_STD_PAL_N; |
| 395 | case 0x7: return V4L2_STD_PAL_Nc; |
| 396 | case 0x8: return V4L2_STD_PAL_60; |
| 397 | case 0xc: return V4L2_STD_SECAM; |
| 398 | default: return V4L2_STD_UNKNOWN; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /* ----------------------------------------------------------------------- */ |
| 403 | |
| 404 | static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl) |
| 405 | { |
| 406 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 407 | |
| 408 | switch (ctrl->id) { |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 409 | case CX25840_CID_ENABLE_PVR150_WORKAROUND: |
| 410 | state->pvr150_workaround = ctrl->value; |
| 411 | set_input(client, state->vid_input, state->aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 412 | break; |
| 413 | |
| 414 | case V4L2_CID_BRIGHTNESS: |
| 415 | if (ctrl->value < 0 || ctrl->value > 255) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 416 | v4l_err(client, "invalid brightness setting %d\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 417 | ctrl->value); |
| 418 | return -ERANGE; |
| 419 | } |
| 420 | |
| 421 | cx25840_write(client, 0x414, ctrl->value - 128); |
| 422 | break; |
| 423 | |
| 424 | case V4L2_CID_CONTRAST: |
| 425 | if (ctrl->value < 0 || ctrl->value > 127) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 426 | v4l_err(client, "invalid contrast setting %d\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 427 | ctrl->value); |
| 428 | return -ERANGE; |
| 429 | } |
| 430 | |
| 431 | cx25840_write(client, 0x415, ctrl->value << 1); |
| 432 | break; |
| 433 | |
| 434 | case V4L2_CID_SATURATION: |
| 435 | if (ctrl->value < 0 || ctrl->value > 127) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 436 | v4l_err(client, "invalid saturation setting %d\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 437 | ctrl->value); |
| 438 | return -ERANGE; |
| 439 | } |
| 440 | |
| 441 | cx25840_write(client, 0x420, ctrl->value << 1); |
| 442 | cx25840_write(client, 0x421, ctrl->value << 1); |
| 443 | break; |
| 444 | |
| 445 | case V4L2_CID_HUE: |
| 446 | if (ctrl->value < -127 || ctrl->value > 127) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 447 | v4l_err(client, "invalid hue setting %d\n", ctrl->value); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 448 | return -ERANGE; |
| 449 | } |
| 450 | |
| 451 | cx25840_write(client, 0x422, ctrl->value); |
| 452 | break; |
| 453 | |
| 454 | case V4L2_CID_AUDIO_VOLUME: |
| 455 | case V4L2_CID_AUDIO_BASS: |
| 456 | case V4L2_CID_AUDIO_TREBLE: |
| 457 | case V4L2_CID_AUDIO_BALANCE: |
| 458 | case V4L2_CID_AUDIO_MUTE: |
| 459 | return cx25840_audio(client, VIDIOC_S_CTRL, ctrl); |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 460 | |
| 461 | default: |
| 462 | return -EINVAL; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | return 0; |
| 466 | } |
| 467 | |
| 468 | static int get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl) |
| 469 | { |
| 470 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 471 | |
| 472 | switch (ctrl->id) { |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 473 | case CX25840_CID_ENABLE_PVR150_WORKAROUND: |
| 474 | ctrl->value = state->pvr150_workaround; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 475 | break; |
| 476 | case V4L2_CID_BRIGHTNESS: |
Hans Verkuil | 0de7122 | 2006-01-09 15:32:44 -0200 | [diff] [blame] | 477 | ctrl->value = (s8)cx25840_read(client, 0x414) + 128; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 478 | break; |
| 479 | case V4L2_CID_CONTRAST: |
| 480 | ctrl->value = cx25840_read(client, 0x415) >> 1; |
| 481 | break; |
| 482 | case V4L2_CID_SATURATION: |
| 483 | ctrl->value = cx25840_read(client, 0x420) >> 1; |
| 484 | break; |
| 485 | case V4L2_CID_HUE: |
Hans Verkuil | c5099a6 | 2006-01-09 15:32:43 -0200 | [diff] [blame] | 486 | ctrl->value = (s8)cx25840_read(client, 0x422); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 487 | break; |
| 488 | case V4L2_CID_AUDIO_VOLUME: |
| 489 | case V4L2_CID_AUDIO_BASS: |
| 490 | case V4L2_CID_AUDIO_TREBLE: |
| 491 | case V4L2_CID_AUDIO_BALANCE: |
| 492 | case V4L2_CID_AUDIO_MUTE: |
| 493 | return cx25840_audio(client, VIDIOC_G_CTRL, ctrl); |
| 494 | default: |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /* ----------------------------------------------------------------------- */ |
| 502 | |
| 503 | static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) |
| 504 | { |
| 505 | switch (fmt->type) { |
| 506 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 507 | return cx25840_vbi(client, VIDIOC_G_FMT, fmt); |
| 508 | default: |
| 509 | return -EINVAL; |
| 510 | } |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) |
| 516 | { |
| 517 | struct v4l2_pix_format *pix; |
| 518 | int HSC, VSC, Vsrc, Hsrc, filter, Vlines; |
| 519 | int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_NTSC); |
| 520 | |
| 521 | switch (fmt->type) { |
| 522 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 523 | pix = &(fmt->fmt.pix); |
| 524 | |
| 525 | Vsrc = (cx25840_read(client, 0x476) & 0x3f) << 4; |
| 526 | Vsrc |= (cx25840_read(client, 0x475) & 0xf0) >> 4; |
| 527 | |
| 528 | Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4; |
| 529 | Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4; |
| 530 | |
| 531 | Vlines = pix->height + (is_pal ? 4 : 7); |
| 532 | |
| 533 | if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) || |
| 534 | (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 535 | v4l_err(client, "%dx%d is not a valid size!\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 536 | pix->width, pix->height); |
| 537 | return -ERANGE; |
| 538 | } |
| 539 | |
| 540 | HSC = (Hsrc * (1 << 20)) / pix->width - (1 << 20); |
| 541 | VSC = (1 << 16) - (Vsrc * (1 << 9) / Vlines - (1 << 9)); |
| 542 | VSC &= 0x1fff; |
| 543 | |
| 544 | if (pix->width >= 385) |
| 545 | filter = 0; |
| 546 | else if (pix->width > 192) |
| 547 | filter = 1; |
| 548 | else if (pix->width > 96) |
| 549 | filter = 2; |
| 550 | else |
| 551 | filter = 3; |
| 552 | |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 553 | v4l_dbg(1, cx25840_debug, client, "decoder set size %dx%d -> scale %ux%u\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 554 | pix->width, pix->height, HSC, VSC); |
| 555 | |
| 556 | /* HSCALE=HSC */ |
| 557 | cx25840_write(client, 0x418, HSC & 0xff); |
| 558 | cx25840_write(client, 0x419, (HSC >> 8) & 0xff); |
| 559 | cx25840_write(client, 0x41a, HSC >> 16); |
| 560 | /* VSCALE=VSC */ |
| 561 | cx25840_write(client, 0x41c, VSC & 0xff); |
| 562 | cx25840_write(client, 0x41d, VSC >> 8); |
| 563 | /* VS_INTRLACE=1 VFILT=filter */ |
| 564 | cx25840_write(client, 0x41e, 0x8 | filter); |
| 565 | break; |
| 566 | |
| 567 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 568 | return cx25840_vbi(client, VIDIOC_S_FMT, fmt); |
| 569 | |
| 570 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 571 | return cx25840_vbi(client, VIDIOC_S_FMT, fmt); |
| 572 | |
| 573 | default: |
| 574 | return -EINVAL; |
| 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /* ----------------------------------------------------------------------- */ |
| 581 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 582 | static struct v4l2_queryctrl cx25840_qctrl[] = { |
| 583 | { |
| 584 | .id = V4L2_CID_BRIGHTNESS, |
| 585 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 586 | .name = "Brightness", |
| 587 | .minimum = 0, |
| 588 | .maximum = 255, |
| 589 | .step = 1, |
| 590 | .default_value = 128, |
| 591 | .flags = 0, |
| 592 | }, { |
| 593 | .id = V4L2_CID_CONTRAST, |
| 594 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 595 | .name = "Contrast", |
| 596 | .minimum = 0, |
Hans Verkuil | ecc0b94 | 2006-02-27 00:08:20 -0300 | [diff] [blame] | 597 | .maximum = 127, |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 598 | .step = 1, |
| 599 | .default_value = 64, |
| 600 | .flags = 0, |
| 601 | }, { |
| 602 | .id = V4L2_CID_SATURATION, |
| 603 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 604 | .name = "Saturation", |
| 605 | .minimum = 0, |
Hans Verkuil | ecc0b94 | 2006-02-27 00:08:20 -0300 | [diff] [blame] | 606 | .maximum = 127, |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 607 | .step = 1, |
| 608 | .default_value = 64, |
| 609 | .flags = 0, |
| 610 | }, { |
| 611 | .id = V4L2_CID_HUE, |
| 612 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 613 | .name = "Hue", |
| 614 | .minimum = -128, |
| 615 | .maximum = 127, |
| 616 | .step = 1, |
| 617 | .default_value = 0, |
| 618 | .flags = 0, |
| 619 | }, { |
| 620 | .id = V4L2_CID_AUDIO_VOLUME, |
| 621 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 622 | .name = "Volume", |
| 623 | .minimum = 0, |
| 624 | .maximum = 65535, |
| 625 | .step = 65535/100, |
| 626 | .default_value = 58880, |
| 627 | .flags = 0, |
| 628 | }, { |
| 629 | .id = V4L2_CID_AUDIO_BALANCE, |
| 630 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 631 | .name = "Balance", |
| 632 | .minimum = 0, |
| 633 | .maximum = 65535, |
| 634 | .step = 65535/100, |
| 635 | .default_value = 32768, |
| 636 | .flags = 0, |
| 637 | }, { |
| 638 | .id = V4L2_CID_AUDIO_MUTE, |
| 639 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 640 | .name = "Mute", |
| 641 | .minimum = 0, |
| 642 | .maximum = 1, |
| 643 | .step = 1, |
| 644 | .default_value = 1, |
| 645 | .flags = 0, |
| 646 | }, { |
| 647 | .id = V4L2_CID_AUDIO_BASS, |
| 648 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 649 | .name = "Bass", |
| 650 | .minimum = 0, |
| 651 | .maximum = 65535, |
| 652 | .step = 65535/100, |
| 653 | .default_value = 32768, |
| 654 | }, { |
| 655 | .id = V4L2_CID_AUDIO_TREBLE, |
| 656 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 657 | .name = "Treble", |
| 658 | .minimum = 0, |
| 659 | .maximum = 65535, |
| 660 | .step = 65535/100, |
| 661 | .default_value = 32768, |
| 662 | }, |
| 663 | }; |
| 664 | |
| 665 | /* ----------------------------------------------------------------------- */ |
| 666 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 667 | static int cx25840_command(struct i2c_client *client, unsigned int cmd, |
| 668 | void *arg) |
| 669 | { |
| 670 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 671 | struct v4l2_tuner *vt = arg; |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 672 | struct v4l2_routing *route = arg; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 673 | |
| 674 | switch (cmd) { |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 675 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 676 | /* ioctls to allow direct access to the |
| 677 | * cx25840 registers for testing */ |
| 678 | case VIDIOC_INT_G_REGISTER: |
| 679 | { |
| 680 | struct v4l2_register *reg = arg; |
| 681 | |
| 682 | if (reg->i2c_id != I2C_DRIVERID_CX25840) |
| 683 | return -EINVAL; |
| 684 | reg->val = cx25840_read(client, reg->reg & 0x0fff); |
| 685 | break; |
| 686 | } |
| 687 | |
| 688 | case VIDIOC_INT_S_REGISTER: |
| 689 | { |
| 690 | struct v4l2_register *reg = arg; |
| 691 | |
| 692 | if (reg->i2c_id != I2C_DRIVERID_CX25840) |
| 693 | return -EINVAL; |
| 694 | if (!capable(CAP_SYS_ADMIN)) |
| 695 | return -EPERM; |
| 696 | cx25840_write(client, reg->reg & 0x0fff, reg->val & 0xff); |
| 697 | break; |
| 698 | } |
| 699 | #endif |
| 700 | |
| 701 | case VIDIOC_INT_DECODE_VBI_LINE: |
| 702 | return cx25840_vbi(client, cmd, arg); |
| 703 | |
| 704 | case VIDIOC_INT_AUDIO_CLOCK_FREQ: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 705 | return cx25840_audio(client, cmd, arg); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 706 | |
| 707 | case VIDIOC_STREAMON: |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 708 | v4l_dbg(1, cx25840_debug, client, "enable output\n"); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 709 | cx25840_write(client, 0x115, 0x8c); |
| 710 | cx25840_write(client, 0x116, 0x07); |
| 711 | break; |
| 712 | |
| 713 | case VIDIOC_STREAMOFF: |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 714 | v4l_dbg(1, cx25840_debug, client, "disable output\n"); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 715 | cx25840_write(client, 0x115, 0x00); |
| 716 | cx25840_write(client, 0x116, 0x00); |
| 717 | break; |
| 718 | |
| 719 | case VIDIOC_LOG_STATUS: |
| 720 | log_status(client); |
| 721 | break; |
| 722 | |
| 723 | case VIDIOC_G_CTRL: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 724 | return get_v4lctrl(client, (struct v4l2_control *)arg); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 725 | |
| 726 | case VIDIOC_S_CTRL: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 727 | return set_v4lctrl(client, (struct v4l2_control *)arg); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 728 | |
Hans Verkuil | d92c20e | 2006-01-09 15:32:41 -0200 | [diff] [blame] | 729 | case VIDIOC_QUERYCTRL: |
| 730 | { |
| 731 | struct v4l2_queryctrl *qc = arg; |
| 732 | int i; |
| 733 | |
| 734 | for (i = 0; i < ARRAY_SIZE(cx25840_qctrl); i++) |
| 735 | if (qc->id && qc->id == cx25840_qctrl[i].id) { |
| 736 | memcpy(qc, &cx25840_qctrl[i], sizeof(*qc)); |
| 737 | return 0; |
| 738 | } |
| 739 | return -EINVAL; |
| 740 | } |
| 741 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 742 | case VIDIOC_G_STD: |
| 743 | *(v4l2_std_id *)arg = cx25840_get_v4lstd(client); |
| 744 | break; |
| 745 | |
| 746 | case VIDIOC_S_STD: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 747 | state->radio = 0; |
| 748 | return set_v4lstd(client, *(v4l2_std_id *)arg); |
| 749 | |
| 750 | case AUDC_SET_RADIO: |
| 751 | state->radio = 1; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 754 | case VIDIOC_INT_G_VIDEO_ROUTING: |
| 755 | route->input = state->vid_input; |
| 756 | route->output = 0; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 757 | break; |
| 758 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 759 | case VIDIOC_INT_S_VIDEO_ROUTING: |
| 760 | return set_input(client, route->input, state->aud_input); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 761 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 762 | case VIDIOC_INT_G_AUDIO_ROUTING: |
| 763 | route->input = state->aud_input; |
| 764 | route->output = 0; |
| 765 | break; |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 766 | |
Hans Verkuil | 31bc09b | 2006-03-25 10:26:09 -0300 | [diff] [blame] | 767 | case VIDIOC_INT_S_AUDIO_ROUTING: |
| 768 | return set_input(client, state->vid_input, route->input); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 769 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 770 | case VIDIOC_S_FREQUENCY: |
| 771 | input_change(client); |
| 772 | break; |
| 773 | |
| 774 | case VIDIOC_G_TUNER: |
| 775 | { |
| 776 | u8 mode = cx25840_read(client, 0x804); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 777 | u8 vpres = cx25840_read(client, 0x80a) & 0x10; |
| 778 | int val = 0; |
| 779 | |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 780 | if (state->radio) |
| 781 | break; |
| 782 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 783 | vt->capability |= |
| 784 | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 | |
| 785 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP; |
| 786 | |
| 787 | vt->signal = vpres ? 0xffff : 0x0; |
| 788 | |
| 789 | /* get rxsubchans and audmode */ |
| 790 | if ((mode & 0xf) == 1) |
| 791 | val |= V4L2_TUNER_SUB_STEREO; |
| 792 | else |
| 793 | val |= V4L2_TUNER_SUB_MONO; |
| 794 | |
| 795 | if (mode == 2 || mode == 4) |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 796 | val = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 797 | |
| 798 | if (mode & 0x10) |
| 799 | val |= V4L2_TUNER_SUB_SAP; |
| 800 | |
| 801 | vt->rxsubchans = val; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 802 | vt->audmode = state->audmode; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | |
| 806 | case VIDIOC_S_TUNER: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 807 | if (state->radio) |
| 808 | break; |
| 809 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 810 | switch (vt->audmode) { |
| 811 | case V4L2_TUNER_MODE_MONO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 812 | /* mono -> mono |
| 813 | stereo -> mono |
| 814 | bilingual -> lang1 */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 815 | cx25840_and_or(client, 0x809, ~0xf, 0x00); |
| 816 | break; |
Hans Verkuil | 301e22d | 2006-03-18 17:15:00 -0300 | [diff] [blame] | 817 | case V4L2_TUNER_MODE_STEREO: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 818 | case V4L2_TUNER_MODE_LANG1: |
| 819 | /* mono -> mono |
| 820 | stereo -> stereo |
| 821 | bilingual -> lang1 */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 822 | cx25840_and_or(client, 0x809, ~0xf, 0x04); |
| 823 | break; |
Hans Verkuil | 301e22d | 2006-03-18 17:15:00 -0300 | [diff] [blame] | 824 | case V4L2_TUNER_MODE_LANG1_LANG2: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 825 | /* mono -> mono |
| 826 | stereo -> stereo |
| 827 | bilingual -> lang1/lang2 */ |
| 828 | cx25840_and_or(client, 0x809, ~0xf, 0x07); |
| 829 | break; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 830 | case V4L2_TUNER_MODE_LANG2: |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 831 | /* mono -> mono |
Hans Verkuil | 301e22d | 2006-03-18 17:15:00 -0300 | [diff] [blame] | 832 | stereo -> stereo |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 833 | bilingual -> lang2 */ |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 834 | cx25840_and_or(client, 0x809, ~0xf, 0x01); |
| 835 | break; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 836 | default: |
| 837 | return -EINVAL; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 838 | } |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 839 | state->audmode = vt->audmode; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case VIDIOC_G_FMT: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 843 | return get_v4lfmt(client, (struct v4l2_format *)arg); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 844 | |
| 845 | case VIDIOC_S_FMT: |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 846 | return set_v4lfmt(client, (struct v4l2_format *)arg); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 847 | |
| 848 | case VIDIOC_INT_RESET: |
| 849 | cx25840_initialize(client, 0); |
| 850 | break; |
| 851 | |
| 852 | case VIDIOC_INT_G_CHIP_IDENT: |
| 853 | *(enum v4l2_chip_ident *)arg = |
| 854 | V4L2_IDENT_CX25840 + ((cx25840_read(client, 0x100) >> 4) & 0xf); |
| 855 | break; |
| 856 | |
| 857 | default: |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 858 | return -EINVAL; |
| 859 | } |
| 860 | |
Hans Verkuil | 3faeeae | 2006-01-09 15:25:44 -0200 | [diff] [blame] | 861 | return 0; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | /* ----------------------------------------------------------------------- */ |
| 865 | |
Mauro Carvalho Chehab | 769e243 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 866 | static struct i2c_driver i2c_driver_cx25840; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 867 | |
| 868 | static int cx25840_detect_client(struct i2c_adapter *adapter, int address, |
| 869 | int kind) |
| 870 | { |
| 871 | struct i2c_client *client; |
| 872 | struct cx25840_state *state; |
| 873 | u16 device_id; |
| 874 | |
| 875 | /* Check if the adapter supports the needed features |
| 876 | * Not until kernel version 2.6.11 did the bit-algo |
| 877 | * correctly report that it would do an I2C-level xfer */ |
| 878 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) |
| 879 | return 0; |
| 880 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 881 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 882 | if (client == 0) |
| 883 | return -ENOMEM; |
| 884 | |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 885 | client->addr = address; |
| 886 | client->adapter = adapter; |
| 887 | client->driver = &i2c_driver_cx25840; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 888 | snprintf(client->name, sizeof(client->name) - 1, "cx25840"); |
| 889 | |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 890 | v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 891 | |
| 892 | device_id = cx25840_read(client, 0x101) << 8; |
| 893 | device_id |= cx25840_read(client, 0x100); |
| 894 | |
| 895 | /* The high byte of the device ID should be |
| 896 | * 0x84 if chip is present */ |
| 897 | if ((device_id & 0xff00) != 0x8400) { |
Hans Verkuil | b5fc714 | 2006-01-11 22:41:36 -0200 | [diff] [blame] | 898 | v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n"); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 899 | kfree(client); |
| 900 | return 0; |
| 901 | } |
| 902 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 903 | v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 904 | (device_id & 0xfff0) >> 4, |
| 905 | (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : 3, |
| 906 | address << 1, adapter->name); |
| 907 | |
| 908 | state = kmalloc(sizeof(struct cx25840_state), GFP_KERNEL); |
| 909 | if (state == NULL) { |
| 910 | kfree(client); |
| 911 | return -ENOMEM; |
| 912 | } |
| 913 | |
| 914 | i2c_set_clientdata(client, state); |
| 915 | memset(state, 0, sizeof(struct cx25840_state)); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 916 | state->vid_input = CX25840_COMPOSITE7; |
| 917 | state->aud_input = CX25840_AUDIO8; |
Hans Verkuil | 3578d3d | 2006-01-09 15:25:41 -0200 | [diff] [blame] | 918 | state->audclk_freq = 48000; |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 919 | state->pvr150_workaround = 0; |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 920 | state->audmode = V4L2_TUNER_MODE_LANG1; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 921 | |
| 922 | cx25840_initialize(client, 1); |
| 923 | |
| 924 | i2c_attach_client(client); |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static int cx25840_attach_adapter(struct i2c_adapter *adapter) |
| 930 | { |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 931 | if (adapter->class & I2C_CLASS_TV_ANALOG) |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 932 | return i2c_probe(adapter, &addr_data, &cx25840_detect_client); |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | static int cx25840_detach_client(struct i2c_client *client) |
| 937 | { |
| 938 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 939 | int err; |
| 940 | |
| 941 | err = i2c_detach_client(client); |
| 942 | if (err) { |
| 943 | return err; |
| 944 | } |
| 945 | |
| 946 | kfree(state); |
| 947 | kfree(client); |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | /* ----------------------------------------------------------------------- */ |
| 953 | |
Mauro Carvalho Chehab | 769e243 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 954 | static struct i2c_driver i2c_driver_cx25840 = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 955 | .driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 956 | .name = "cx25840", |
| 957 | }, |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 958 | .id = I2C_DRIVERID_CX25840, |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 959 | .attach_adapter = cx25840_attach_adapter, |
| 960 | .detach_client = cx25840_detach_client, |
| 961 | .command = cx25840_command, |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 962 | }; |
| 963 | |
| 964 | |
| 965 | static int __init m__init(void) |
| 966 | { |
| 967 | return i2c_add_driver(&i2c_driver_cx25840); |
| 968 | } |
| 969 | |
| 970 | static void __exit m__exit(void) |
| 971 | { |
| 972 | i2c_del_driver(&i2c_driver_cx25840); |
| 973 | } |
| 974 | |
| 975 | module_init(m__init); |
| 976 | module_exit(m__exit); |
| 977 | |
| 978 | /* ----------------------------------------------------------------------- */ |
| 979 | |
| 980 | static void log_status(struct i2c_client *client) |
| 981 | { |
| 982 | static const char *const fmt_strs[] = { |
| 983 | "0x0", |
| 984 | "NTSC-M", "NTSC-J", "NTSC-4.43", |
| 985 | "PAL-BDGHI", "PAL-M", "PAL-N", "PAL-Nc", "PAL-60", |
| 986 | "0x9", "0xA", "0xB", |
| 987 | "SECAM", |
| 988 | "0xD", "0xE", "0xF" |
| 989 | }; |
| 990 | |
| 991 | struct cx25840_state *state = i2c_get_clientdata(client); |
| 992 | u8 microctrl_vidfmt = cx25840_read(client, 0x80a); |
| 993 | u8 vidfmt_sel = cx25840_read(client, 0x400) & 0xf; |
| 994 | u8 gen_stat1 = cx25840_read(client, 0x40d); |
| 995 | u8 download_ctl = cx25840_read(client, 0x803); |
| 996 | u8 mod_det_stat0 = cx25840_read(client, 0x804); |
| 997 | u8 mod_det_stat1 = cx25840_read(client, 0x805); |
| 998 | u8 audio_config = cx25840_read(client, 0x808); |
| 999 | u8 pref_mode = cx25840_read(client, 0x809); |
| 1000 | u8 afc0 = cx25840_read(client, 0x80b); |
| 1001 | u8 mute_ctl = cx25840_read(client, 0x8d3); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1002 | int vid_input = state->vid_input; |
| 1003 | int aud_input = state->aud_input; |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1004 | char *p; |
| 1005 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1006 | v4l_info(client, "Video signal: %spresent\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1007 | (microctrl_vidfmt & 0x10) ? "" : "not "); |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1008 | v4l_info(client, "Detected format: %s\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1009 | fmt_strs[gen_stat1 & 0xf]); |
| 1010 | |
| 1011 | switch (mod_det_stat0) { |
| 1012 | case 0x00: p = "mono"; break; |
| 1013 | case 0x01: p = "stereo"; break; |
| 1014 | case 0x02: p = "dual"; break; |
| 1015 | case 0x04: p = "tri"; break; |
| 1016 | case 0x10: p = "mono with SAP"; break; |
| 1017 | case 0x11: p = "stereo with SAP"; break; |
| 1018 | case 0x12: p = "dual with SAP"; break; |
| 1019 | case 0x14: p = "tri with SAP"; break; |
| 1020 | case 0xfe: p = "forced mode"; break; |
| 1021 | default: p = "not defined"; |
| 1022 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1023 | v4l_info(client, "Detected audio mode: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1024 | |
| 1025 | switch (mod_det_stat1) { |
| 1026 | case 0x00: p = "not defined"; break; |
| 1027 | case 0x01: p = "EIAJ"; break; |
| 1028 | case 0x02: p = "A2-M"; break; |
| 1029 | case 0x03: p = "A2-BG"; break; |
| 1030 | case 0x04: p = "A2-DK1"; break; |
| 1031 | case 0x05: p = "A2-DK2"; break; |
| 1032 | case 0x06: p = "A2-DK3"; break; |
| 1033 | case 0x07: p = "A1 (6.0 MHz FM Mono)"; break; |
| 1034 | case 0x08: p = "AM-L"; break; |
| 1035 | case 0x09: p = "NICAM-BG"; break; |
| 1036 | case 0x0a: p = "NICAM-DK"; break; |
| 1037 | case 0x0b: p = "NICAM-I"; break; |
| 1038 | case 0x0c: p = "NICAM-L"; break; |
| 1039 | case 0x0d: p = "BTSC/EIAJ/A2-M Mono (4.5 MHz FMMono)"; break; |
| 1040 | case 0x0e: p = "IF FM Radio"; break; |
| 1041 | case 0x0f: p = "BTSC"; break; |
| 1042 | case 0x10: p = "high-deviation FM"; break; |
| 1043 | case 0x11: p = "very high-deviation FM"; break; |
| 1044 | case 0xfd: p = "unknown audio standard"; break; |
| 1045 | case 0xfe: p = "forced audio standard"; break; |
| 1046 | case 0xff: p = "no detected audio standard"; break; |
| 1047 | default: p = "not defined"; |
| 1048 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1049 | v4l_info(client, "Detected audio standard: %s\n", p); |
| 1050 | v4l_info(client, "Audio muted: %s\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1051 | (mute_ctl & 0x2) ? "yes" : "no"); |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1052 | v4l_info(client, "Audio microcontroller: %s\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1053 | (download_ctl & 0x10) ? "running" : "stopped"); |
| 1054 | |
| 1055 | switch (audio_config >> 4) { |
| 1056 | case 0x00: p = "undefined"; break; |
| 1057 | case 0x01: p = "BTSC"; break; |
| 1058 | case 0x02: p = "EIAJ"; break; |
| 1059 | case 0x03: p = "A2-M"; break; |
| 1060 | case 0x04: p = "A2-BG"; break; |
| 1061 | case 0x05: p = "A2-DK1"; break; |
| 1062 | case 0x06: p = "A2-DK2"; break; |
| 1063 | case 0x07: p = "A2-DK3"; break; |
| 1064 | case 0x08: p = "A1 (6.0 MHz FM Mono)"; break; |
| 1065 | case 0x09: p = "AM-L"; break; |
| 1066 | case 0x0a: p = "NICAM-BG"; break; |
| 1067 | case 0x0b: p = "NICAM-DK"; break; |
| 1068 | case 0x0c: p = "NICAM-I"; break; |
| 1069 | case 0x0d: p = "NICAM-L"; break; |
| 1070 | case 0x0e: p = "FM radio"; break; |
| 1071 | case 0x0f: p = "automatic detection"; break; |
| 1072 | default: p = "undefined"; |
| 1073 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1074 | v4l_info(client, "Configured audio standard: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1075 | |
| 1076 | if ((audio_config >> 4) < 0xF) { |
| 1077 | switch (audio_config & 0xF) { |
| 1078 | case 0x00: p = "MONO1 (LANGUAGE A/Mono L+R channel for BTSC, EIAJ, A2)"; break; |
| 1079 | case 0x01: p = "MONO2 (LANGUAGE B)"; break; |
| 1080 | case 0x02: p = "MONO3 (STEREO forced MONO)"; break; |
| 1081 | case 0x03: p = "MONO4 (NICAM ANALOG-Language C/Analog Fallback)"; break; |
| 1082 | case 0x04: p = "STEREO"; break; |
| 1083 | case 0x05: p = "DUAL1 (AB)"; break; |
| 1084 | case 0x06: p = "DUAL2 (AC) (FM)"; break; |
| 1085 | case 0x07: p = "DUAL3 (BC) (FM)"; break; |
| 1086 | case 0x08: p = "DUAL4 (AC) (AM)"; break; |
| 1087 | case 0x09: p = "DUAL5 (BC) (AM)"; break; |
| 1088 | case 0x0a: p = "SAP"; break; |
| 1089 | default: p = "undefined"; |
| 1090 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1091 | v4l_info(client, "Configured audio mode: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1092 | } else { |
| 1093 | switch (audio_config & 0xF) { |
| 1094 | case 0x00: p = "BG"; break; |
| 1095 | case 0x01: p = "DK1"; break; |
| 1096 | case 0x02: p = "DK2"; break; |
| 1097 | case 0x03: p = "DK3"; break; |
| 1098 | case 0x04: p = "I"; break; |
| 1099 | case 0x05: p = "L"; break; |
| 1100 | case 0x06: p = "BTSC"; break; |
| 1101 | case 0x07: p = "EIAJ"; break; |
| 1102 | case 0x08: p = "A2-M"; break; |
| 1103 | case 0x09: p = "FM Radio"; break; |
| 1104 | case 0x0f: p = "automatic standard and mode detection"; break; |
| 1105 | default: p = "undefined"; |
| 1106 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1107 | v4l_info(client, "Configured audio system: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1110 | v4l_info(client, "Specified standard: %s\n", |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1111 | vidfmt_sel ? fmt_strs[vidfmt_sel] : "automatic detection"); |
| 1112 | |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1113 | if (vid_input >= CX25840_COMPOSITE1 && |
| 1114 | vid_input <= CX25840_COMPOSITE8) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1115 | v4l_info(client, "Specified video input: Composite %d\n", |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1116 | vid_input - CX25840_COMPOSITE1 + 1); |
| 1117 | } else { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1118 | v4l_info(client, "Specified video input: S-Video (Luma In%d, Chroma In%d)\n", |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1119 | (vid_input & 0xf0) >> 4, (vid_input & 0xf00) >> 8); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1120 | } |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1121 | if (aud_input) { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1122 | v4l_info(client, "Specified audio input: Tuner (In%d)\n", aud_input); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1123 | } else { |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1124 | v4l_info(client, "Specified audio input: External\n"); |
Hans Verkuil | a8bbf12 | 2006-01-09 15:25:42 -0200 | [diff] [blame] | 1125 | } |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1126 | |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1127 | v4l_info(client, "Specified audioclock freq: %d Hz\n", state->audclk_freq); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1128 | |
| 1129 | switch (pref_mode & 0xf) { |
| 1130 | case 0: p = "mono/language A"; break; |
| 1131 | case 1: p = "language B"; break; |
| 1132 | case 2: p = "language C"; break; |
| 1133 | case 3: p = "analog fallback"; break; |
| 1134 | case 4: p = "stereo"; break; |
| 1135 | case 5: p = "language AC"; break; |
| 1136 | case 6: p = "language BC"; break; |
| 1137 | case 7: p = "language AB"; break; |
| 1138 | default: p = "undefined"; |
| 1139 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1140 | v4l_info(client, "Preferred audio mode: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1141 | |
| 1142 | if ((audio_config & 0xf) == 0xf) { |
| 1143 | switch ((afc0 >> 3) & 0x3) { |
| 1144 | case 0: p = "system DK"; break; |
| 1145 | case 1: p = "system L"; break; |
| 1146 | case 2: p = "autodetect"; break; |
| 1147 | default: p = "undefined"; |
| 1148 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1149 | v4l_info(client, "Selected 65 MHz format: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1150 | |
| 1151 | switch (afc0 & 0x7) { |
| 1152 | case 0: p = "chroma"; break; |
| 1153 | case 1: p = "BTSC"; break; |
| 1154 | case 2: p = "EIAJ"; break; |
| 1155 | case 3: p = "A2-M"; break; |
| 1156 | case 4: p = "autodetect"; break; |
| 1157 | default: p = "undefined"; |
| 1158 | } |
Hans Verkuil | fac9e89 | 2006-01-09 15:32:40 -0200 | [diff] [blame] | 1159 | v4l_info(client, "Selected 45 MHz format: %s\n", p); |
Hans Verkuil | bd98516 | 2005-11-13 16:07:56 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |