aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/saa7134
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/saa7134')
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c440
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c261
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c62
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c52
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c63
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c11
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c210
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c56
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c63
-rw-r--r--drivers/media/video/saa7134/saa7134.h19
10 files changed, 955 insertions, 282 deletions
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 707be175509d..1fb6eccdade3 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -1,3 +1,27 @@
1 /*
2 saa6752hs - i2c-driver for the saa6752hs by Philips
3
4 Copyright (C) 2004 Andrew de Quincey
5
6 AC-3 support:
7
8 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License vs published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA.
23 */
24
1#include <linux/module.h> 25#include <linux/module.h>
2#include <linux/kernel.h> 26#include <linux/kernel.h>
3#include <linux/string.h> 27#include <linux/string.h>
@@ -10,6 +34,8 @@
10#include <linux/types.h> 34#include <linux/types.h>
11#include <linux/videodev2.h> 35#include <linux/videodev2.h>
12#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-chip-ident.h>
38#include <media/v4l2-i2c-drv-legacy.h>
13#include <linux/init.h> 39#include <linux/init.h>
14#include <linux/crc32.h> 40#include <linux/crc32.h>
15 41
@@ -27,9 +53,6 @@ MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
27MODULE_AUTHOR("Andrew de Quincey"); 53MODULE_AUTHOR("Andrew de Quincey");
28MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
29 55
30static struct i2c_driver driver;
31static struct i2c_client client_template;
32
33enum saa6752hs_videoformat { 56enum saa6752hs_videoformat {
34 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */ 57 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */
35 SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */ 58 SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */
@@ -46,7 +69,9 @@ struct saa6752hs_mpeg_params {
46 __u16 ts_pid_pcr; 69 __u16 ts_pid_pcr;
47 70
48 /* audio */ 71 /* audio */
49 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate; 72 enum v4l2_mpeg_audio_encoding au_encoding;
73 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate;
74 enum v4l2_mpeg_audio_ac3_bitrate au_ac3_bitrate;
50 75
51 /* video */ 76 /* video */
52 enum v4l2_mpeg_video_aspect vi_aspect; 77 enum v4l2_mpeg_video_aspect vi_aspect;
@@ -70,7 +95,9 @@ static const struct v4l2_format v4l2_format_table[] =
70}; 95};
71 96
72struct saa6752hs_state { 97struct saa6752hs_state {
73 struct i2c_client client; 98 int chip;
99 u32 revision;
100 int has_ac3;
74 struct saa6752hs_mpeg_params params; 101 struct saa6752hs_mpeg_params params;
75 enum saa6752hs_videoformat video_format; 102 enum saa6752hs_videoformat video_format;
76 v4l2_std_id standard; 103 v4l2_std_id standard;
@@ -145,6 +172,39 @@ static u8 PMT[] = {
145 0x00, 0x00, 0x00, 0x00 /* CRC32 */ 172 0x00, 0x00, 0x00, 0x00 /* CRC32 */
146}; 173};
147 174
175static u8 PMT_AC3[] = {
176 0xc2, /* i2c register */
177 0x01, /* table number for encoder(1) */
178 0x47, /* sync */
179
180 0x40, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0) */
181 0x10, /* PMT PID (0x0010) */
182 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
183
184 0x00, /* PSI pointer to start of table */
185
186 0x02, /* TID (2) */
187 0xb0, 0x1a, /* section_syntax_indicator(1), section_length(26) */
188
189 0x00, 0x01, /* program_number(1) */
190
191 0xc1, /* version_number(0), current_next_indicator(1) */
192
193 0x00, 0x00, /* section_number(0), last_section_number(0) */
194
195 0xe1, 0x04, /* PCR_PID (0x0104) */
196
197 0xf0, 0x00, /* program_info_length(0) */
198
199 0x02, 0xe1, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
200 0x06, 0xe1, 0x03, 0xf0, 0x03, /* audio stream type(6), pid */
201 0x6a, /* AC3 */
202 0x01, /* Descriptor_length(1) */
203 0x00, /* component_type_flag(0), bsid_flag(0), mainid_flag(0), asvc_flag(0), reserved flags(0) */
204
205 0xED, 0xDE, 0x2D, 0xF3 /* CRC32 BE */
206};
207
148static struct saa6752hs_mpeg_params param_defaults = 208static struct saa6752hs_mpeg_params param_defaults =
149{ 209{
150 .ts_pid_pmt = 16, 210 .ts_pid_pmt = 16,
@@ -157,12 +217,14 @@ static struct saa6752hs_mpeg_params param_defaults =
157 .vi_bitrate_peak = 6000, 217 .vi_bitrate_peak = 6000,
158 .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, 218 .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
159 219
220 .au_encoding = V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
160 .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K, 221 .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K,
222 .au_ac3_bitrate = V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
161}; 223};
162 224
163/* ---------------------------------------------------------------------- */ 225/* ---------------------------------------------------------------------- */
164 226
165static int saa6752hs_chip_command(struct i2c_client* client, 227static int saa6752hs_chip_command(struct i2c_client *client,
166 enum saa6752hs_command command) 228 enum saa6752hs_command command)
167{ 229{
168 unsigned char buf[3]; 230 unsigned char buf[3];
@@ -229,45 +291,61 @@ static int saa6752hs_chip_command(struct i2c_client* client,
229} 291}
230 292
231 293
232static int saa6752hs_set_bitrate(struct i2c_client* client, 294static inline void set_reg8(struct i2c_client *client, uint8_t reg, uint8_t val)
233 struct saa6752hs_mpeg_params* params) 295{
296 u8 buf[2];
297
298 buf[0] = reg;
299 buf[1] = val;
300 i2c_master_send(client, buf, 2);
301}
302
303static inline void set_reg16(struct i2c_client *client, uint8_t reg, uint16_t val)
234{ 304{
235 u8 buf[3]; 305 u8 buf[3];
306
307 buf[0] = reg;
308 buf[1] = val >> 8;
309 buf[2] = val & 0xff;
310 i2c_master_send(client, buf, 3);
311}
312
313static int saa6752hs_set_bitrate(struct i2c_client *client,
314 struct saa6752hs_state *h)
315{
316 struct saa6752hs_mpeg_params *params = &h->params;
236 int tot_bitrate; 317 int tot_bitrate;
318 int is_384k;
237 319
238 /* set the bitrate mode */ 320 /* set the bitrate mode */
239 buf[0] = 0x71; 321 set_reg8(client, 0x71,
240 buf[1] = (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) ? 0 : 1; 322 params->vi_bitrate_mode != V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
241 i2c_master_send(client, buf, 2);
242 323
243 /* set the video bitrate */ 324 /* set the video bitrate */
244 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { 325 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) {
245 /* set the target bitrate */ 326 /* set the target bitrate */
246 buf[0] = 0x80; 327 set_reg16(client, 0x80, params->vi_bitrate);
247 buf[1] = params->vi_bitrate >> 8;
248 buf[2] = params->vi_bitrate & 0xff;
249 i2c_master_send(client, buf, 3);
250 328
251 /* set the max bitrate */ 329 /* set the max bitrate */
252 buf[0] = 0x81; 330 set_reg16(client, 0x81, params->vi_bitrate_peak);
253 buf[1] = params->vi_bitrate_peak >> 8;
254 buf[2] = params->vi_bitrate_peak & 0xff;
255 i2c_master_send(client, buf, 3);
256 tot_bitrate = params->vi_bitrate_peak; 331 tot_bitrate = params->vi_bitrate_peak;
257 } else { 332 } else {
258 /* set the target bitrate (no max bitrate for CBR) */ 333 /* set the target bitrate (no max bitrate for CBR) */
259 buf[0] = 0x81; 334 set_reg16(client, 0x81, params->vi_bitrate);
260 buf[1] = params->vi_bitrate >> 8;
261 buf[2] = params->vi_bitrate & 0xff;
262 i2c_master_send(client, buf, 3);
263 tot_bitrate = params->vi_bitrate; 335 tot_bitrate = params->vi_bitrate;
264 } 336 }
265 337
338 /* set the audio encoding */
339 set_reg8(client, 0x93,
340 params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3);
341
266 /* set the audio bitrate */ 342 /* set the audio bitrate */
267 buf[0] = 0x94; 343 if (params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3)
268 buf[1] = (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 0 : 1; 344 is_384k = V4L2_MPEG_AUDIO_AC3_BITRATE_384K == params->au_ac3_bitrate;
269 i2c_master_send(client, buf, 2); 345 else
270 tot_bitrate += (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 256 : 384; 346 is_384k = V4L2_MPEG_AUDIO_L2_BITRATE_384K == params->au_l2_bitrate;
347 set_reg8(client, 0x94, is_384k);
348 tot_bitrate += is_384k ? 384 : 256;
271 349
272 /* Note: the total max bitrate is determined by adding the video and audio 350 /* Note: the total max bitrate is determined by adding the video and audio
273 bitrates together and also adding an extra 768kbit/s to stay on the 351 bitrates together and also adding an extra 768kbit/s to stay on the
@@ -278,16 +356,12 @@ static int saa6752hs_set_bitrate(struct i2c_client* client,
278 tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX; 356 tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX;
279 357
280 /* set the total bitrate */ 358 /* set the total bitrate */
281 buf[0] = 0xb1; 359 set_reg16(client, 0xb1, tot_bitrate);
282 buf[1] = tot_bitrate >> 8;
283 buf[2] = tot_bitrate & 0xff;
284 i2c_master_send(client, buf, 3);
285
286 return 0; 360 return 0;
287} 361}
288 362
289static void saa6752hs_set_subsampling(struct i2c_client* client, 363static void saa6752hs_set_subsampling(struct i2c_client *client,
290 struct v4l2_format* f) 364 struct v4l2_format *f)
291{ 365{
292 struct saa6752hs_state *h = i2c_get_clientdata(client); 366 struct saa6752hs_state *h = i2c_get_clientdata(client);
293 int dist_352, dist_480, dist_720; 367 int dist_352, dist_480, dist_720;
@@ -332,7 +406,7 @@ static void saa6752hs_set_subsampling(struct i2c_client* client,
332} 406}
333 407
334 408
335static int handle_ctrl(struct saa6752hs_mpeg_params *params, 409static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
336 struct v4l2_ext_control *ctrl, unsigned int cmd) 410 struct v4l2_ext_control *ctrl, unsigned int cmd)
337{ 411{
338 int old = 0, new; 412 int old = 0, new;
@@ -379,8 +453,9 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
379 params->ts_pid_pcr = new; 453 params->ts_pid_pcr = new;
380 break; 454 break;
381 case V4L2_CID_MPEG_AUDIO_ENCODING: 455 case V4L2_CID_MPEG_AUDIO_ENCODING:
382 old = V4L2_MPEG_AUDIO_ENCODING_LAYER_2; 456 old = params->au_encoding;
383 if (set && new != old) 457 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
458 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
384 return -ERANGE; 459 return -ERANGE;
385 new = old; 460 new = old;
386 break; 461 break;
@@ -395,6 +470,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
395 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K; 470 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
396 params->au_l2_bitrate = new; 471 params->au_l2_bitrate = new;
397 break; 472 break;
473 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
474 if (!has_ac3)
475 return -EINVAL;
476 old = params->au_ac3_bitrate;
477 if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
478 new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
479 return -ERANGE;
480 if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
481 new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
482 else
483 new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
484 params->au_ac3_bitrate = new;
485 break;
398 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 486 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
399 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000; 487 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
400 if (set && new != old) 488 if (set && new != old)
@@ -448,17 +536,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
448 return 0; 536 return 0;
449} 537}
450 538
451static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params, 539static int saa6752hs_qctrl(struct saa6752hs_state *h,
452 struct v4l2_queryctrl *qctrl) 540 struct v4l2_queryctrl *qctrl)
453{ 541{
542 struct saa6752hs_mpeg_params *params = &h->params;
454 int err; 543 int err;
455 544
456 switch (qctrl->id) { 545 switch (qctrl->id) {
457 case V4L2_CID_MPEG_AUDIO_ENCODING: 546 case V4L2_CID_MPEG_AUDIO_ENCODING:
458 return v4l2_ctrl_query_fill(qctrl, 547 return v4l2_ctrl_query_fill(qctrl,
459 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 548 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
460 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1, 549 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 :
461 V4L2_MPEG_AUDIO_ENCODING_LAYER_2); 550 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
551 1, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
462 552
463 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 553 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
464 return v4l2_ctrl_query_fill(qctrl, 554 return v4l2_ctrl_query_fill(qctrl,
@@ -466,6 +556,14 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
466 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1, 556 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
467 V4L2_MPEG_AUDIO_L2_BITRATE_256K); 557 V4L2_MPEG_AUDIO_L2_BITRATE_256K);
468 558
559 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
560 if (!h->has_ac3)
561 return -EINVAL;
562 return v4l2_ctrl_query_fill(qctrl,
563 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
564 V4L2_MPEG_AUDIO_AC3_BITRATE_384K, 1,
565 V4L2_MPEG_AUDIO_AC3_BITRATE_256K);
566
469 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 567 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
470 return v4l2_ctrl_query_fill(qctrl, 568 return v4l2_ctrl_query_fill(qctrl,
471 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, 569 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
@@ -512,44 +610,57 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
512 return -EINVAL; 610 return -EINVAL;
513} 611}
514 612
515static int saa6752hs_qmenu(struct saa6752hs_mpeg_params *params, 613static int saa6752hs_qmenu(struct saa6752hs_state *h,
516 struct v4l2_querymenu *qmenu) 614 struct v4l2_querymenu *qmenu)
517{ 615{
518 static const char *mpeg_audio_l2_bitrate[] = { 616 static const u32 mpeg_audio_encoding[] = {
519 "", 617 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
520 "", 618 V4L2_CTRL_MENU_IDS_END
521 "", 619 };
522 "", 620 static const u32 mpeg_audio_ac3_encoding[] = {
523 "", 621 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
524 "", 622 V4L2_MPEG_AUDIO_ENCODING_AC3,
525 "", 623 V4L2_CTRL_MENU_IDS_END
526 "", 624 };
527 "", 625 static u32 mpeg_audio_l2_bitrate[] = {
528 "", 626 V4L2_MPEG_AUDIO_L2_BITRATE_256K,
529 "", 627 V4L2_MPEG_AUDIO_L2_BITRATE_384K,
530 "256 kbps", 628 V4L2_CTRL_MENU_IDS_END
531 "", 629 };
532 "384 kbps", 630 static u32 mpeg_audio_ac3_bitrate[] = {
533 NULL 631 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
632 V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
633 V4L2_CTRL_MENU_IDS_END
534 }; 634 };
535 struct v4l2_queryctrl qctrl; 635 struct v4l2_queryctrl qctrl;
536 int err; 636 int err;
537 637
538 qctrl.id = qmenu->id; 638 qctrl.id = qmenu->id;
539 err = saa6752hs_qctrl(params, &qctrl); 639 err = saa6752hs_qctrl(h, &qctrl);
540 if (err) 640 if (err)
541 return err; 641 return err;
542 if (qmenu->id == V4L2_CID_MPEG_AUDIO_L2_BITRATE) 642 switch (qmenu->id) {
543 return v4l2_ctrl_query_menu(qmenu, &qctrl, 643 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
644 return v4l2_ctrl_query_menu_valid_items(qmenu,
544 mpeg_audio_l2_bitrate); 645 mpeg_audio_l2_bitrate);
545 return v4l2_ctrl_query_menu(qmenu, &qctrl, 646 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
546 v4l2_ctrl_get_menu(qmenu->id)); 647 if (!h->has_ac3)
648 return -EINVAL;
649 return v4l2_ctrl_query_menu_valid_items(qmenu,
650 mpeg_audio_ac3_bitrate);
651 case V4L2_CID_MPEG_AUDIO_ENCODING:
652 return v4l2_ctrl_query_menu_valid_items(qmenu,
653 h->has_ac3 ? mpeg_audio_ac3_encoding :
654 mpeg_audio_encoding);
655 }
656 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
547} 657}
548 658
549static int saa6752hs_init(struct i2c_client* client) 659static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
550{ 660{
551 unsigned char buf[9], buf2[4]; 661 unsigned char buf[9], buf2[4];
552 struct saa6752hs_state *h; 662 struct saa6752hs_state *h;
663 unsigned size;
553 u32 crc; 664 u32 crc;
554 unsigned char localPAT[256]; 665 unsigned char localPAT[256];
555 unsigned char localPMT[256]; 666 unsigned char localPMT[256];
@@ -557,45 +668,31 @@ static int saa6752hs_init(struct i2c_client* client)
557 h = i2c_get_clientdata(client); 668 h = i2c_get_clientdata(client);
558 669
559 /* Set video format - must be done first as it resets other settings */ 670 /* Set video format - must be done first as it resets other settings */
560 buf[0] = 0x41; 671 set_reg8(client, 0x41, h->video_format);
561 buf[1] = h->video_format;
562 i2c_master_send(client, buf, 2);
563 672
564 /* Set number of lines in input signal */ 673 /* Set number of lines in input signal */
565 buf[0] = 0x40; 674 set_reg8(client, 0x40, (h->standard & V4L2_STD_525_60) ? 1 : 0);
566 buf[1] = 0x00;
567 if (h->standard & V4L2_STD_525_60)
568 buf[1] = 0x01;
569 i2c_master_send(client, buf, 2);
570 675
571 /* set bitrate */ 676 /* set bitrate */
572 saa6752hs_set_bitrate(client, &h->params); 677 saa6752hs_set_bitrate(client, h);
573 678
574 /* Set GOP structure {3, 13} */ 679 /* Set GOP structure {3, 13} */
575 buf[0] = 0x72; 680 set_reg16(client, 0x72, 0x030d);
576 buf[1] = 0x03;
577 buf[2] = 0x0D;
578 i2c_master_send(client,buf,3);
579 681
580 /* Set minimum Q-scale {4} */ 682 /* Set minimum Q-scale {4} */
581 buf[0] = 0x82; 683 set_reg8(client, 0x82, 0x04);
582 buf[1] = 0x04;
583 i2c_master_send(client,buf,2);
584 684
585 /* Set maximum Q-scale {12} */ 685 /* Set maximum Q-scale {12} */
586 buf[0] = 0x83; 686 set_reg8(client, 0x83, 0x0c);
587 buf[1] = 0x0C;
588 i2c_master_send(client,buf,2);
589 687
590 /* Set Output Protocol */ 688 /* Set Output Protocol */
591 buf[0] = 0xD0; 689 set_reg8(client, 0xd0, 0x81);
592 buf[1] = 0x81;
593 i2c_master_send(client,buf,2);
594 690
595 /* Set video output stream format {TS} */ 691 /* Set video output stream format {TS} */
596 buf[0] = 0xB0; 692 set_reg8(client, 0xb0, 0x05);
597 buf[1] = 0x05; 693
598 i2c_master_send(client,buf,2); 694 /* Set leading null byte for TS */
695 set_reg16(client, 0xf6, leading_null_bytes);
599 696
600 /* compute PAT */ 697 /* compute PAT */
601 memcpy(localPAT, PAT, sizeof(PAT)); 698 memcpy(localPAT, PAT, sizeof(PAT));
@@ -608,7 +705,13 @@ static int saa6752hs_init(struct i2c_client* client)
608 localPAT[sizeof(PAT) - 1] = crc & 0xFF; 705 localPAT[sizeof(PAT) - 1] = crc & 0xFF;
609 706
610 /* compute PMT */ 707 /* compute PMT */
611 memcpy(localPMT, PMT, sizeof(PMT)); 708 if (h->params.au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) {
709 size = sizeof(PMT_AC3);
710 memcpy(localPMT, PMT_AC3, size);
711 } else {
712 size = sizeof(PMT);
713 memcpy(localPMT, PMT, size);
714 }
612 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f); 715 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
613 localPMT[4] = h->params.ts_pid_pmt & 0xff; 716 localPMT[4] = h->params.ts_pid_pmt & 0xff;
614 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F); 717 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F);
@@ -617,40 +720,28 @@ static int saa6752hs_init(struct i2c_client* client)
617 localPMT[21] = h->params.ts_pid_video & 0xFF; 720 localPMT[21] = h->params.ts_pid_video & 0xFF;
618 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F); 721 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F);
619 localPMT[26] = h->params.ts_pid_audio & 0xFF; 722 localPMT[26] = h->params.ts_pid_audio & 0xFF;
620 crc = crc32_be(~0, &localPMT[7], sizeof(PMT) - 7 - 4); 723 crc = crc32_be(~0, &localPMT[7], size - 7 - 4);
621 localPMT[sizeof(PMT) - 4] = (crc >> 24) & 0xFF; 724 localPMT[size - 4] = (crc >> 24) & 0xFF;
622 localPMT[sizeof(PMT) - 3] = (crc >> 16) & 0xFF; 725 localPMT[size - 3] = (crc >> 16) & 0xFF;
623 localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF; 726 localPMT[size - 2] = (crc >> 8) & 0xFF;
624 localPMT[sizeof(PMT) - 1] = crc & 0xFF; 727 localPMT[size - 1] = crc & 0xFF;
625 728
626 /* Set Audio PID */ 729 /* Set Audio PID */
627 buf[0] = 0xC1; 730 set_reg16(client, 0xc1, h->params.ts_pid_audio);
628 buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF;
629 buf[2] = h->params.ts_pid_audio & 0xFF;
630 i2c_master_send(client,buf,3);
631 731
632 /* Set Video PID */ 732 /* Set Video PID */
633 buf[0] = 0xC0; 733 set_reg16(client, 0xc0, h->params.ts_pid_video);
634 buf[1] = (h->params.ts_pid_video >> 8) & 0xFF;
635 buf[2] = h->params.ts_pid_video & 0xFF;
636 i2c_master_send(client,buf,3);
637 734
638 /* Set PCR PID */ 735 /* Set PCR PID */
639 buf[0] = 0xC4; 736 set_reg16(client, 0xc4, h->params.ts_pid_pcr);
640 buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF;
641 buf[2] = h->params.ts_pid_pcr & 0xFF;
642 i2c_master_send(client,buf,3);
643 737
644 /* Send SI tables */ 738 /* Send SI tables */
645 i2c_master_send(client,localPAT,sizeof(PAT)); 739 i2c_master_send(client, localPAT, sizeof(PAT));
646 i2c_master_send(client,localPMT,sizeof(PMT)); 740 i2c_master_send(client, localPMT, size);
647 741
648 /* mute then unmute audio. This removes buzzing artefacts */ 742 /* mute then unmute audio. This removes buzzing artefacts */
649 buf[0] = 0xa4; 743 set_reg8(client, 0xa4, 1);
650 buf[1] = 1; 744 set_reg8(client, 0xa4, 0);
651 i2c_master_send(client, buf, 2);
652 buf[1] = 0;
653 i2c_master_send(client, buf, 2);
654 745
655 /* start it going */ 746 /* start it going */
656 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START); 747 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START);
@@ -688,45 +779,6 @@ static int saa6752hs_init(struct i2c_client* client)
688 return 0; 779 return 0;
689} 780}
690 781
691static int saa6752hs_attach(struct i2c_adapter *adap, int addr, int kind)
692{
693 struct saa6752hs_state *h;
694
695
696 if (NULL == (h = kzalloc(sizeof(*h), GFP_KERNEL)))
697 return -ENOMEM;
698 h->client = client_template;
699 h->params = param_defaults;
700 h->client.adapter = adap;
701 h->client.addr = addr;
702
703 /* Assume 625 input lines */
704 h->standard = 0;
705
706 i2c_set_clientdata(&h->client, h);
707 i2c_attach_client(&h->client);
708
709 v4l_info(&h->client,"saa6752hs: chip found @ 0x%x\n", addr<<1);
710 return 0;
711}
712
713static int saa6752hs_probe(struct i2c_adapter *adap)
714{
715 if (adap->class & I2C_CLASS_TV_ANALOG)
716 return i2c_probe(adap, &addr_data, saa6752hs_attach);
717 return 0;
718}
719
720static int saa6752hs_detach(struct i2c_client *client)
721{
722 struct saa6752hs_state *h;
723
724 h = i2c_get_clientdata(client);
725 i2c_detach_client(client);
726 kfree(h);
727 return 0;
728}
729
730static int 782static int
731saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg) 783saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
732{ 784{
@@ -737,14 +789,13 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
737 int i; 789 int i;
738 790
739 switch (cmd) { 791 switch (cmd) {
792 case VIDIOC_INT_INIT:
793 /* apply settings and start encoder */
794 saa6752hs_init(client, *(u32 *)arg);
795 break;
740 case VIDIOC_S_EXT_CTRLS: 796 case VIDIOC_S_EXT_CTRLS:
741 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 797 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
742 return -EINVAL; 798 return -EINVAL;
743 if (ctrls->count == 0) {
744 /* apply settings and start encoder */
745 saa6752hs_init(client);
746 break;
747 }
748 /* fall through */ 799 /* fall through */
749 case VIDIOC_TRY_EXT_CTRLS: 800 case VIDIOC_TRY_EXT_CTRLS:
750 case VIDIOC_G_EXT_CTRLS: 801 case VIDIOC_G_EXT_CTRLS:
@@ -752,7 +803,8 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
752 return -EINVAL; 803 return -EINVAL;
753 params = h->params; 804 params = h->params;
754 for (i = 0; i < ctrls->count; i++) { 805 for (i = 0; i < ctrls->count; i++) {
755 if ((err = handle_ctrl(&params, ctrls->controls + i, cmd))) { 806 err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, cmd);
807 if (err) {
756 ctrls->error_idx = i; 808 ctrls->error_idx = i;
757 return err; 809 return err;
758 } 810 }
@@ -760,9 +812,9 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
760 h->params = params; 812 h->params = params;
761 break; 813 break;
762 case VIDIOC_QUERYCTRL: 814 case VIDIOC_QUERYCTRL:
763 return saa6752hs_qctrl(&h->params, arg); 815 return saa6752hs_qctrl(h, arg);
764 case VIDIOC_QUERYMENU: 816 case VIDIOC_QUERYMENU:
765 return saa6752hs_qmenu(&h->params, arg); 817 return saa6752hs_qmenu(h, arg);
766 case VIDIOC_G_FMT: 818 case VIDIOC_G_FMT:
767 { 819 {
768 struct v4l2_format *f = arg; 820 struct v4l2_format *f = arg;
@@ -785,6 +837,11 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
785 case VIDIOC_S_STD: 837 case VIDIOC_S_STD:
786 h->standard = *((v4l2_std_id *) arg); 838 h->standard = *((v4l2_std_id *) arg);
787 break; 839 break;
840
841 case VIDIOC_G_CHIP_IDENT:
842 return v4l2_chip_ident_i2c_client(client,
843 arg, h->chip, h->revision);
844
788 default: 845 default:
789 /* nothing */ 846 /* nothing */
790 break; 847 break;
@@ -793,36 +850,55 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
793 return err; 850 return err;
794} 851}
795 852
796/* ----------------------------------------------------------------------- */ 853static int saa6752hs_probe(struct i2c_client *client,
854 const struct i2c_device_id *id)
855{
856 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
857 u8 addr = 0x13;
858 u8 data[12];
797 859
798static struct i2c_driver driver = { 860 v4l_info(client, "chip found @ 0x%x (%s)\n",
799 .driver = { 861 client->addr << 1, client->adapter->name);
800 .name = "saa6752hs", 862 if (h == NULL)
801 }, 863 return -ENOMEM;
802 .id = I2C_DRIVERID_SAA6752HS,
803 .attach_adapter = saa6752hs_probe,
804 .detach_client = saa6752hs_detach,
805 .command = saa6752hs_command,
806};
807 864
808static struct i2c_client client_template = 865 i2c_master_send(client, &addr, 1);
809{ 866 i2c_master_recv(client, data, sizeof(data));
810 .name = "saa6752hs", 867 h->chip = V4L2_IDENT_SAA6752HS;
811 .driver = &driver, 868 h->revision = (data[8] << 8) | data[9];
812}; 869 h->has_ac3 = 0;
870 if (h->revision == 0x0206) {
871 h->chip = V4L2_IDENT_SAA6752HS_AC3;
872 h->has_ac3 = 1;
873 v4l_info(client, "support AC-3\n");
874 }
875 h->params = param_defaults;
876 h->standard = 0; /* Assume 625 input lines */
813 877
814static int __init saa6752hs_init_module(void) 878 i2c_set_clientdata(client, h);
815{ 879 return 0;
816 return i2c_add_driver(&driver);
817} 880}
818 881
819static void __exit saa6752hs_cleanup_module(void) 882static int saa6752hs_remove(struct i2c_client *client)
820{ 883{
821 i2c_del_driver(&driver); 884 kfree(i2c_get_clientdata(client));
885 return 0;
822} 886}
823 887
824module_init(saa6752hs_init_module); 888static const struct i2c_device_id saa6752hs_id[] = {
825module_exit(saa6752hs_cleanup_module); 889 { "saa6752hs", 0 },
890 { }
891};
892MODULE_DEVICE_TABLE(i2c, saa6752hs_id);
893
894static struct v4l2_i2c_driver_data v4l2_i2c_data = {
895 .name = "saa6752hs",
896 .driverid = I2C_DRIVERID_SAA6752HS,
897 .command = saa6752hs_command,
898 .probe = saa6752hs_probe,
899 .remove = saa6752hs_remove,
900 .id_table = saa6752hs_id,
901};
826 902
827/* 903/*
828 * Overrides for Emacs so that we follow Linus's tabbing style. 904 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 98364d171def..ddc5402c5fb0 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -3260,6 +3260,7 @@ struct saa7134_board saa7134_boards[] = {
3260 }, 3260 },
3261 [SAA7134_BOARD_HAUPPAUGE_HVR1110] = { 3261 [SAA7134_BOARD_HAUPPAUGE_HVR1110] = {
3262 /* Thomas Genty <tomlohave@gmail.com> */ 3262 /* Thomas Genty <tomlohave@gmail.com> */
3263 /* David Bentham <db260179@hotmail.com> */
3263 .name = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid", 3264 .name = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid",
3264 .audio_clock = 0x00187de7, 3265 .audio_clock = 0x00187de7,
3265 .tuner_type = TUNER_PHILIPS_TDA8290, 3266 .tuner_type = TUNER_PHILIPS_TDA8290,
@@ -3268,23 +3269,26 @@ struct saa7134_board saa7134_boards[] = {
3268 .radio_addr = ADDR_UNSET, 3269 .radio_addr = ADDR_UNSET,
3269 .tuner_config = 1, 3270 .tuner_config = 1,
3270 .mpeg = SAA7134_MPEG_DVB, 3271 .mpeg = SAA7134_MPEG_DVB,
3272 .gpiomask = 0x0200100,
3271 .inputs = {{ 3273 .inputs = {{
3272 .name = name_tv, 3274 .name = name_tv,
3273 .vmux = 1, 3275 .vmux = 1,
3274 .amux = TV, 3276 .amux = TV,
3275 .tv = 1, 3277 .tv = 1,
3276 },{ 3278 .gpio = 0x0000100,
3277 .name = name_comp1, 3279 }, {
3278 .vmux = 3, 3280 .name = name_comp1,
3279 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */ 3281 .vmux = 3,
3280 },{ 3282 .amux = LINE1,
3281 .name = name_svideo, 3283 }, {
3282 .vmux = 8, 3284 .name = name_svideo,
3283 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */ 3285 .vmux = 8,
3284 }}, 3286 .amux = LINE1,
3287 } },
3285 .radio = { 3288 .radio = {
3286 .name = name_radio, 3289 .name = name_radio,
3287 .amux = TV, 3290 .amux = TV,
3291 .gpio = 0x0200100,
3288 }, 3292 },
3289 }, 3293 },
3290 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = { 3294 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = {
@@ -3388,6 +3392,42 @@ struct saa7134_board saa7134_boards[] = {
3388 .amux = 0, 3392 .amux = 0,
3389 }, 3393 },
3390 }, 3394 },
3395 [SAA7134_BOARD_ENCORE_ENLTV_FM53] = {
3396 .name = "Encore ENLTV-FM v5.3",
3397 .audio_clock = 0x00200000,
3398 .tuner_type = TUNER_TNF_5335MF,
3399 .radio_type = UNSET,
3400 .tuner_addr = ADDR_UNSET,
3401 .radio_addr = ADDR_UNSET,
3402 .gpiomask = 0x7000,
3403 .inputs = { {
3404 .name = name_tv,
3405 .vmux = 1,
3406 .amux = 1,
3407 .tv = 1,
3408 .gpio = 0x50000,
3409 }, {
3410 .name = name_comp1,
3411 .vmux = 3,
3412 .amux = 2,
3413 .gpio = 0x2000,
3414 }, {
3415 .name = name_svideo,
3416 .vmux = 8,
3417 .amux = 2,
3418 .gpio = 0x2000,
3419 } },
3420 .radio = {
3421 .name = name_radio,
3422 .vmux = 1,
3423 .amux = 1,
3424 },
3425 .mute = {
3426 .name = name_mute,
3427 .gpio = 0xf000,
3428 .amux = 0,
3429 },
3430 },
3391 [SAA7134_BOARD_CINERGY_HT_PCI] = { 3431 [SAA7134_BOARD_CINERGY_HT_PCI] = {
3392 .name = "Terratec Cinergy HT PCI", 3432 .name = "Terratec Cinergy HT PCI",
3393 .audio_clock = 0x00187de7, 3433 .audio_clock = 0x00187de7,
@@ -3631,6 +3671,40 @@ struct saa7134_board saa7134_boards[] = {
3631 .tv = 1, 3671 .tv = 1,
3632 }}, 3672 }},
3633 }, 3673 },
3674 [SAA7134_BOARD_AVERMEDIA_M135A] = {
3675 .name = "Avermedia PCI pure analog (M135A)",
3676 .audio_clock = 0x00187de7,
3677 .tuner_type = TUNER_PHILIPS_TDA8290,
3678 .radio_type = UNSET,
3679 .tuner_addr = ADDR_UNSET,
3680 .radio_addr = ADDR_UNSET,
3681 .tuner_config = 2,
3682 .gpiomask = 0x020200000,
3683 .inputs = {{
3684 .name = name_tv,
3685 .vmux = 1,
3686 .amux = TV,
3687 .tv = 1,
3688 }, {
3689 .name = name_comp1,
3690 .vmux = 3,
3691 .amux = LINE1,
3692 }, {
3693 .name = name_svideo,
3694 .vmux = 8,
3695 .amux = LINE1,
3696 } },
3697 .radio = {
3698 .name = name_radio,
3699 .amux = TV,
3700 .gpio = 0x00200000,
3701 },
3702 .mute = {
3703 .name = name_mute,
3704 .amux = TV,
3705 .gpio = 0x01,
3706 },
3707 },
3634 [SAA7134_BOARD_BEHOLD_401] = { 3708 [SAA7134_BOARD_BEHOLD_401] = {
3635 /* Beholder Intl. Ltd. 2008 */ 3709 /* Beholder Intl. Ltd. 2008 */
3636 /*Dmitry Belimov <d.belimov@gmail.com> */ 3710 /*Dmitry Belimov <d.belimov@gmail.com> */
@@ -4409,6 +4483,129 @@ struct saa7134_board saa7134_boards[] = {
4409 /* no DVB support for now */ 4483 /* no DVB support for now */
4410 /* .mpeg = SAA7134_MPEG_DVB, */ 4484 /* .mpeg = SAA7134_MPEG_DVB, */
4411 }, 4485 },
4486 [SAA7134_BOARD_ASUSTeK_TIGER_3IN1] = {
4487 .name = "Asus Tiger 3in1",
4488 .audio_clock = 0x00187de7,
4489 .tuner_type = TUNER_PHILIPS_TDA8290,
4490 .radio_type = UNSET,
4491 .tuner_addr = ADDR_UNSET,
4492 .radio_addr = ADDR_UNSET,
4493 .tuner_config = 2,
4494 .gpiomask = 1 << 21,
4495 .mpeg = SAA7134_MPEG_DVB,
4496 .inputs = {{
4497 .name = name_tv,
4498 .vmux = 1,
4499 .amux = TV,
4500 .tv = 1,
4501 }, {
4502 .name = name_comp,
4503 .vmux = 0,
4504 .amux = LINE2,
4505 }, {
4506 .name = name_svideo,
4507 .vmux = 8,
4508 .amux = LINE2,
4509 } },
4510 .radio = {
4511 .name = name_radio,
4512 .amux = TV,
4513 .gpio = 0x0200000,
4514 },
4515 },
4516 [SAA7134_BOARD_REAL_ANGEL_220] = {
4517 .name = "Zogis Real Angel 220",
4518 .audio_clock = 0x00187de7,
4519 .tuner_type = TUNER_TNF_5335MF,
4520 .radio_type = UNSET,
4521 .tuner_addr = ADDR_UNSET,
4522 .radio_addr = ADDR_UNSET,
4523 .gpiomask = 0x801a8087,
4524 .inputs = { {
4525 .name = name_tv,
4526 .vmux = 3,
4527 .amux = LINE2,
4528 .tv = 1,
4529 .gpio = 0x624000,
4530 }, {
4531 .name = name_comp1,
4532 .vmux = 1,
4533 .amux = LINE1,
4534 .gpio = 0x624000,
4535 }, {
4536 .name = name_svideo,
4537 .vmux = 1,
4538 .amux = LINE1,
4539 .gpio = 0x624000,
4540 } },
4541 .radio = {
4542 .name = name_radio,
4543 .amux = LINE2,
4544 .gpio = 0x624001,
4545 },
4546 .mute = {
4547 .name = name_mute,
4548 .amux = TV,
4549 },
4550 },
4551 [SAA7134_BOARD_ADS_INSTANT_HDTV_PCI] = {
4552 .name = "ADS Tech Instant HDTV",
4553 .audio_clock = 0x00187de7,
4554 .tuner_type = TUNER_PHILIPS_TUV1236D,
4555 .radio_type = UNSET,
4556 .tuner_addr = ADDR_UNSET,
4557 .radio_addr = ADDR_UNSET,
4558 .tda9887_conf = TDA9887_PRESENT,
4559 .mpeg = SAA7134_MPEG_DVB,
4560 .inputs = { {
4561 .name = name_tv,
4562 .vmux = 1,
4563 .amux = TV,
4564 .tv = 1,
4565 }, {
4566 .name = name_comp,
4567 .vmux = 4,
4568 .amux = LINE1,
4569 }, {
4570 .name = name_svideo,
4571 .vmux = 8,
4572 .amux = LINE1,
4573 } },
4574 },
4575 [SAA7134_BOARD_ASUSTeK_TIGER] = {
4576 .name = "Asus Tiger Rev:1.00",
4577 .audio_clock = 0x00187de7,
4578 .tuner_type = TUNER_PHILIPS_TDA8290,
4579 .radio_type = UNSET,
4580 .tuner_addr = ADDR_UNSET,
4581 .radio_addr = ADDR_UNSET,
4582 .tuner_config = 0,
4583 .mpeg = SAA7134_MPEG_DVB,
4584 .gpiomask = 0x0200000,
4585 .inputs = { {
4586 .name = name_tv,
4587 .vmux = 1,
4588 .amux = TV,
4589 .tv = 1,
4590 }, {
4591 .name = name_comp1,
4592 .vmux = 3,
4593 .amux = LINE2,
4594 }, {
4595 .name = name_comp2,
4596 .vmux = 0,
4597 .amux = LINE2,
4598 }, {
4599 .name = name_svideo,
4600 .vmux = 8,
4601 .amux = LINE2,
4602 } },
4603 .radio = {
4604 .name = name_radio,
4605 .amux = TV,
4606 .gpio = 0x0200000,
4607 },
4608 },
4412}; 4609};
4413 4610
4414const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 4611const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4777,6 +4974,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
4777 4974
4778 },{ 4975 },{
4779 .vendor = PCI_VENDOR_ID_PHILIPS, 4976 .vendor = PCI_VENDOR_ID_PHILIPS,
4977 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4978 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4979 .subdevice = 0xf11d,
4980 .driver_data = SAA7134_BOARD_AVERMEDIA_M135A,
4981 }, {
4982 .vendor = PCI_VENDOR_ID_PHILIPS,
4780 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 4983 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4781 .subvendor = PCI_VENDOR_ID_PHILIPS, 4984 .subvendor = PCI_VENDOR_ID_PHILIPS,
4782 .subdevice = 0x2004, 4985 .subdevice = 0x2004,
@@ -5157,6 +5360,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5157 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM, 5360 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM,
5158 },{ 5361 },{
5159 .vendor = PCI_VENDOR_ID_PHILIPS, 5362 .vendor = PCI_VENDOR_ID_PHILIPS,
5363 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
5364 .subvendor = 0x1a7f,
5365 .subdevice = 0x2008,
5366 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM53,
5367 }, {
5368 .vendor = PCI_VENDOR_ID_PHILIPS,
5160 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5369 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5161 .subvendor = 0x153b, 5370 .subvendor = 0x153b,
5162 .subdevice = 0x1175, 5371 .subdevice = 0x1175,
@@ -5183,8 +5392,8 @@ struct pci_device_id saa7134_pci_tbl[] = {
5183 .vendor = PCI_VENDOR_ID_PHILIPS, 5392 .vendor = PCI_VENDOR_ID_PHILIPS,
5184 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5393 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5185 .subvendor = 0x1043, 5394 .subvendor = 0x1043,
5186 .subdevice = 0x4857, 5395 .subdevice = 0x4857, /* REV:1.00 */
5187 .driver_data = SAA7134_BOARD_ASUSTeK_P7131_DUAL, 5396 .driver_data = SAA7134_BOARD_ASUSTeK_TIGER,
5188 },{ 5397 },{
5189 .vendor = PCI_VENDOR_ID_PHILIPS, 5398 .vendor = PCI_VENDOR_ID_PHILIPS,
5190 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 5399 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -5415,6 +5624,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5415 .driver_data = SAA7134_BOARD_VIDEOMATE_T750, 5624 .driver_data = SAA7134_BOARD_VIDEOMATE_T750,
5416 }, { 5625 }, {
5417 .vendor = PCI_VENDOR_ID_PHILIPS, 5626 .vendor = PCI_VENDOR_ID_PHILIPS,
5627 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
5628 .subvendor = 0x1421,
5629 .subdevice = 0x0380,
5630 .driver_data = SAA7134_BOARD_ADS_INSTANT_HDTV_PCI,
5631 }, {
5632 .vendor = PCI_VENDOR_ID_PHILIPS,
5418 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5633 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5419 .subvendor = 0x5169, 5634 .subvendor = 0x5169,
5420 .subdevice = 0x1502, 5635 .subdevice = 0x1502,
@@ -5432,6 +5647,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5432 .subdevice = 0xf636, 5647 .subdevice = 0xf636,
5433 .driver_data = SAA7134_BOARD_AVERMEDIA_M103, 5648 .driver_data = SAA7134_BOARD_AVERMEDIA_M103,
5434 }, { 5649 }, {
5650 .vendor = PCI_VENDOR_ID_PHILIPS,
5651 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5652 .subvendor = 0x1043,
5653 .subdevice = 0x4878, /* REV:1.02G */
5654 .driver_data = SAA7134_BOARD_ASUSTeK_TIGER_3IN1,
5655 }, {
5435 /* --- boards without eeprom + subsystem ID --- */ 5656 /* --- boards without eeprom + subsystem ID --- */
5436 .vendor = PCI_VENDOR_ID_PHILIPS, 5657 .vendor = PCI_VENDOR_ID_PHILIPS,
5437 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 5658 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -5540,7 +5761,7 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev,
5540 return 0; 5761 return 0;
5541} 5762}
5542 5763
5543int saa7134_tuner_callback(void *priv, int command, int arg) 5764int saa7134_tuner_callback(void *priv, int component, int command, int arg)
5544{ 5765{
5545 struct saa7134_dev *dev = priv; 5766 struct saa7134_dev *dev = priv;
5546 if (dev != NULL) { 5767 if (dev != NULL) {
@@ -5620,6 +5841,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5620 case SAA7134_BOARD_AVERMEDIA_STUDIO_507: 5841 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
5621 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 5842 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
5622 case SAA7134_BOARD_AVERMEDIA_777: 5843 case SAA7134_BOARD_AVERMEDIA_777:
5844 case SAA7134_BOARD_AVERMEDIA_M135A:
5623/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */ 5845/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */
5624 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 5846 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
5625 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: 5847 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
@@ -5644,6 +5866,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5644 case SAA7134_BOARD_AVERMEDIA_A16AR: 5866 case SAA7134_BOARD_AVERMEDIA_A16AR:
5645 case SAA7134_BOARD_ENCORE_ENLTV: 5867 case SAA7134_BOARD_ENCORE_ENLTV:
5646 case SAA7134_BOARD_ENCORE_ENLTV_FM: 5868 case SAA7134_BOARD_ENCORE_ENLTV_FM:
5869 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
5647 case SAA7134_BOARD_10MOONSTVMASTER3: 5870 case SAA7134_BOARD_10MOONSTVMASTER3:
5648 case SAA7134_BOARD_BEHOLD_401: 5871 case SAA7134_BOARD_BEHOLD_401:
5649 case SAA7134_BOARD_BEHOLD_403: 5872 case SAA7134_BOARD_BEHOLD_403:
@@ -5656,6 +5879,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5656 case SAA7134_BOARD_BEHOLD_505FM: 5879 case SAA7134_BOARD_BEHOLD_505FM:
5657 case SAA7134_BOARD_BEHOLD_507_9FM: 5880 case SAA7134_BOARD_BEHOLD_507_9FM:
5658 case SAA7134_BOARD_GENIUS_TVGO_A11MCE: 5881 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
5882 case SAA7134_BOARD_REAL_ANGEL_220:
5659 dev->has_remote = SAA7134_REMOTE_GPIO; 5883 dev->has_remote = SAA7134_REMOTE_GPIO;
5660 break; 5884 break;
5661 case SAA7134_BOARD_FLYDVBS_LR300: 5885 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -5745,6 +5969,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5745 case SAA7134_BOARD_PINNACLE_PCTV_110i: 5969 case SAA7134_BOARD_PINNACLE_PCTV_110i:
5746 case SAA7134_BOARD_PINNACLE_PCTV_310i: 5970 case SAA7134_BOARD_PINNACLE_PCTV_310i:
5747 case SAA7134_BOARD_UPMOST_PURPLE_TV: 5971 case SAA7134_BOARD_UPMOST_PURPLE_TV:
5972 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
5748 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 5973 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
5749 case SAA7134_BOARD_BEHOLD_607_9FM: 5974 case SAA7134_BOARD_BEHOLD_607_9FM:
5750 case SAA7134_BOARD_BEHOLD_M6: 5975 case SAA7134_BOARD_BEHOLD_M6:
@@ -5987,6 +6212,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5987 case SAA7134_BOARD_PINNACLE_PCTV_310i: 6212 case SAA7134_BOARD_PINNACLE_PCTV_310i:
5988 case SAA7134_BOARD_KWORLD_DVBT_210: 6213 case SAA7134_BOARD_KWORLD_DVBT_210:
5989 case SAA7134_BOARD_TEVION_DVBT_220RF: 6214 case SAA7134_BOARD_TEVION_DVBT_220RF:
6215 case SAA7134_BOARD_ASUSTeK_TIGER:
5990 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 6216 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
5991 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 6217 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
5992 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 6218 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
@@ -6002,6 +6228,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6002 i2c_transfer(&dev->i2c_adap, &msg, 1); 6228 i2c_transfer(&dev->i2c_adap, &msg, 1);
6003 break; 6229 break;
6004 } 6230 }
6231 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
6232 {
6233 u8 data[] = { 0x3c, 0x33, 0x60};
6234 struct i2c_msg msg = {.addr = 0x0b, .flags = 0, .buf = data,
6235 .len = sizeof(data)};
6236 i2c_transfer(&dev->i2c_adap, &msg, 1);
6237 break;
6238 }
6005 case SAA7134_BOARD_FLYDVB_TRIO: 6239 case SAA7134_BOARD_FLYDVB_TRIO:
6006 { 6240 {
6007 u8 data[] = { 0x3c, 0x33, 0x62}; 6241 u8 data[] = { 0x3c, 0x33, 0x62};
@@ -6027,6 +6261,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6027 i2c_transfer(&dev->i2c_adap, &msg, 1); 6261 i2c_transfer(&dev->i2c_adap, &msg, 1);
6028 break; 6262 break;
6029 } 6263 }
6264 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
6030 case SAA7134_BOARD_KWORLD_ATSC110: 6265 case SAA7134_BOARD_KWORLD_ATSC110:
6031 { 6266 {
6032 /* enable tuner */ 6267 /* enable tuner */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 75d618415f4f..b686bfabbde0 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -215,7 +215,7 @@ unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
215int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt) 215int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
216{ 216{
217 __le32 *cpu; 217 __le32 *cpu;
218 dma_addr_t dma_addr; 218 dma_addr_t dma_addr = 0;
219 219
220 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr); 220 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
221 if (NULL == cpu) 221 if (NULL == cpu)
@@ -359,32 +359,6 @@ void saa7134_buffer_timeout(unsigned long data)
359 spin_unlock_irqrestore(&dev->slock,flags); 359 spin_unlock_irqrestore(&dev->slock,flags);
360} 360}
361 361
362/* resends a current buffer in queue after resume */
363
364static int saa7134_buffer_requeue(struct saa7134_dev *dev,
365 struct saa7134_dmaqueue *q)
366{
367 struct saa7134_buf *buf, *next;
368
369 assert_spin_locked(&dev->slock);
370
371 buf = q->curr;
372 next = buf;
373 dprintk("buffer_requeue\n");
374
375 if (!buf)
376 return 0;
377
378 dprintk("buffer_requeue : resending active buffers \n");
379
380 if (!list_empty(&q->queue))
381 next = list_entry(q->queue.next, struct saa7134_buf,
382 vb.queue);
383 buf->activate(dev, buf, next);
384
385 return 0;
386}
387
388/* ------------------------------------------------------------------ */ 362/* ------------------------------------------------------------------ */
389 363
390int saa7134_set_dmabits(struct saa7134_dev *dev) 364int saa7134_set_dmabits(struct saa7134_dev *dev)
@@ -442,9 +416,7 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
442 /* TS capture -- dma 5 */ 416 /* TS capture -- dma 5 */
443 if (dev->ts_q.curr) { 417 if (dev->ts_q.curr) {
444 ctrl |= SAA7134_MAIN_CTRL_TE5; 418 ctrl |= SAA7134_MAIN_CTRL_TE5;
445 irq |= SAA7134_IRQ1_INTE_RA2_3 | 419 irq |= SAA7134_IRQ1_INTE_RA2_1 |
446 SAA7134_IRQ1_INTE_RA2_2 |
447 SAA7134_IRQ1_INTE_RA2_1 |
448 SAA7134_IRQ1_INTE_RA2_0; 420 SAA7134_IRQ1_INTE_RA2_0;
449 } 421 }
450 422
@@ -727,6 +699,10 @@ static int saa7134_hw_enable2(struct saa7134_dev *dev)
727 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A; 699 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A;
728 } 700 }
729 701
702 if (dev->has_remote == SAA7134_REMOTE_I2C) {
703 request_module("ir-kbd-i2c");
704 }
705
730 saa_writel(SAA7134_IRQ1, 0); 706 saa_writel(SAA7134_IRQ1, 0);
731 saa_writel(SAA7134_IRQ2, irq2_mask); 707 saa_writel(SAA7134_IRQ2, irq2_mask);
732 708
@@ -1139,6 +1115,32 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1139} 1115}
1140 1116
1141#ifdef CONFIG_PM 1117#ifdef CONFIG_PM
1118
1119/* resends a current buffer in queue after resume */
1120static int saa7134_buffer_requeue(struct saa7134_dev *dev,
1121 struct saa7134_dmaqueue *q)
1122{
1123 struct saa7134_buf *buf, *next;
1124
1125 assert_spin_locked(&dev->slock);
1126
1127 buf = q->curr;
1128 next = buf;
1129 dprintk("buffer_requeue\n");
1130
1131 if (!buf)
1132 return 0;
1133
1134 dprintk("buffer_requeue : resending active buffers \n");
1135
1136 if (!list_empty(&q->queue))
1137 next = list_entry(q->queue.next, struct saa7134_buf,
1138 vb.queue);
1139 buf->activate(dev, buf, next);
1140
1141 return 0;
1142}
1143
1142static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state) 1144static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1143{ 1145{
1144 1146
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index be48b9b66a67..87c10983266f 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -553,7 +553,6 @@ static int configure_tda827x_fe(struct saa7134_dev *dev,
553/* ------------------------------------------------------------------ */ 553/* ------------------------------------------------------------------ */
554 554
555static struct tda827x_config tda827x_cfg_0 = { 555static struct tda827x_config tda827x_cfg_0 = {
556 .tuner_callback = saa7134_tuner_callback,
557 .init = philips_tda827x_tuner_init, 556 .init = philips_tda827x_tuner_init,
558 .sleep = philips_tda827x_tuner_sleep, 557 .sleep = philips_tda827x_tuner_sleep,
559 .config = 0, 558 .config = 0,
@@ -561,7 +560,6 @@ static struct tda827x_config tda827x_cfg_0 = {
561}; 560};
562 561
563static struct tda827x_config tda827x_cfg_1 = { 562static struct tda827x_config tda827x_cfg_1 = {
564 .tuner_callback = saa7134_tuner_callback,
565 .init = philips_tda827x_tuner_init, 563 .init = philips_tda827x_tuner_init,
566 .sleep = philips_tda827x_tuner_sleep, 564 .sleep = philips_tda827x_tuner_sleep,
567 .config = 1, 565 .config = 1,
@@ -569,7 +567,6 @@ static struct tda827x_config tda827x_cfg_1 = {
569}; 567};
570 568
571static struct tda827x_config tda827x_cfg_2 = { 569static struct tda827x_config tda827x_cfg_2 = {
572 .tuner_callback = saa7134_tuner_callback,
573 .init = philips_tda827x_tuner_init, 570 .init = philips_tda827x_tuner_init,
574 .sleep = philips_tda827x_tuner_sleep, 571 .sleep = philips_tda827x_tuner_sleep,
575 .config = 2, 572 .config = 2,
@@ -577,7 +574,6 @@ static struct tda827x_config tda827x_cfg_2 = {
577}; 574};
578 575
579static struct tda827x_config tda827x_cfg_2_sw42 = { 576static struct tda827x_config tda827x_cfg_2_sw42 = {
580 .tuner_callback = saa7134_tuner_callback,
581 .init = philips_tda827x_tuner_init, 577 .init = philips_tda827x_tuner_init,
582 .sleep = philips_tda827x_tuner_sleep, 578 .sleep = philips_tda827x_tuner_sleep,
583 .config = 2, 579 .config = 2,
@@ -799,6 +795,20 @@ static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
799 .request_firmware = philips_tda1004x_request_firmware 795 .request_firmware = philips_tda1004x_request_firmware
800}; 796};
801 797
798static struct tda1004x_config asus_tiger_3in1_config = {
799 .demod_address = 0x0b,
800 .invert = 1,
801 .invert_oclk = 0,
802 .xtal_freq = TDA10046_XTAL_16M,
803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
805 .if_freq = TDA10046_FREQ_045,
806 .i2c_gate = 0x4b,
807 .tuner_address = 0x61,
808 .antenna_switch = 1,
809 .request_firmware = philips_tda1004x_request_firmware
810};
811
802/* ------------------------------------------------------------------ 812/* ------------------------------------------------------------------
803 * special case: this card uses saa713x GPIO22 for the mode switch 813 * special case: this card uses saa713x GPIO22 for the mode switch
804 */ 814 */
@@ -822,7 +832,6 @@ static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
822} 832}
823 833
824static struct tda827x_config ads_duo_cfg = { 834static struct tda827x_config ads_duo_cfg = {
825 .tuner_callback = saa7134_tuner_callback,
826 .init = ads_duo_tuner_init, 835 .init = ads_duo_tuner_init,
827 .sleep = ads_duo_tuner_sleep, 836 .sleep = ads_duo_tuner_sleep,
828 .config = 0 837 .config = 0
@@ -1147,6 +1156,7 @@ static int dvb_init(struct saa7134_dev *dev)
1147 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 1156 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1148 NULL, DVB_PLL_TDHU2); 1157 NULL, DVB_PLL_TDHU2);
1149 break; 1158 break;
1159 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1150 case SAA7134_BOARD_KWORLD_ATSC110: 1160 case SAA7134_BOARD_KWORLD_ATSC110:
1151 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110, 1161 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1152 &dev->i2c_adap); 1162 &dev->i2c_adap);
@@ -1300,6 +1310,36 @@ static int dvb_init(struct saa7134_dev *dev)
1300 &dev->i2c_adap); 1310 &dev->i2c_adap);
1301 attach_xc3028 = 1; 1311 attach_xc3028 = 1;
1302 break; 1312 break;
1313 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1314 if (!use_frontend) { /* terrestrial */
1315 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1316 &tda827x_cfg_2) < 0)
1317 goto dettach_frontend;
1318 } else { /* satellite */
1319 dev->dvb.frontend = dvb_attach(tda10086_attach,
1320 &flydvbs, &dev->i2c_adap);
1321 if (dev->dvb.frontend) {
1322 if (dvb_attach(tda826x_attach,
1323 dev->dvb.frontend, 0x60,
1324 &dev->i2c_adap, 0) == NULL) {
1325 wprintk("%s: Asus Tiger 3in1, no "
1326 "tda826x found!\n", __func__);
1327 goto dettach_frontend;
1328 }
1329 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1330 &dev->i2c_adap, 0, 0) == NULL) {
1331 wprintk("%s: Asus Tiger 3in1, no lnbp21"
1332 " found!\n", __func__);
1333 goto dettach_frontend;
1334 }
1335 }
1336 }
1337 break;
1338 case SAA7134_BOARD_ASUSTeK_TIGER:
1339 if (configure_tda827x_fe(dev, &philips_tiger_config,
1340 &tda827x_cfg_0) < 0)
1341 goto dettach_frontend;
1342 break;
1303 default: 1343 default:
1304 wprintk("Huh? unknown DVB card?\n"); 1344 wprintk("Huh? unknown DVB card?\n");
1305 break; 1345 break;
@@ -1327,6 +1367,8 @@ static int dvb_init(struct saa7134_dev *dev)
1327 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name); 1367 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1328 return -1; 1368 return -1;
1329 } 1369 }
1370 /* define general-purpose callback pointer */
1371 dev->dvb.frontend->callback = saa7134_tuner_callback;
1330 1372
1331 /* register everything else */ 1373 /* register everything else */
1332 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev, 1374 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev,
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index c0c5d7509c25..9a8766a78a0c 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -29,6 +29,7 @@
29 29
30#include <media/saa6752hs.h> 30#include <media/saa6752hs.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
32 33
33/* ------------------------------------------------------------------ */ 34/* ------------------------------------------------------------------ */
34 35
@@ -63,10 +64,19 @@ static void ts_reset_encoder(struct saa7134_dev* dev)
63 64
64static int ts_init_encoder(struct saa7134_dev* dev) 65static int ts_init_encoder(struct saa7134_dev* dev)
65{ 66{
66 struct v4l2_ext_controls ctrls = { V4L2_CTRL_CLASS_MPEG, 0 }; 67 u32 leading_null_bytes = 0;
67 68
69 /* If more cards start to need this, then this
70 should probably be added to the card definitions. */
71 switch (dev->board) {
72 case SAA7134_BOARD_BEHOLD_M6:
73 case SAA7134_BOARD_BEHOLD_M63:
74 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
75 leading_null_bytes = 1;
76 break;
77 }
68 ts_reset_encoder(dev); 78 ts_reset_encoder(dev);
69 saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, &ctrls); 79 saa7134_i2c_call_clients(dev, VIDIOC_INT_INIT, &leading_null_bytes);
70 dev->empress_started = 1; 80 dev->empress_started = 1;
71 return 0; 81 return 0;
72} 82}
@@ -79,9 +89,11 @@ static int ts_open(struct inode *inode, struct file *file)
79 struct saa7134_dev *dev; 89 struct saa7134_dev *dev;
80 int err; 90 int err;
81 91
92 lock_kernel();
82 list_for_each_entry(dev, &saa7134_devlist, devlist) 93 list_for_each_entry(dev, &saa7134_devlist, devlist)
83 if (dev->empress_dev && dev->empress_dev->minor == minor) 94 if (dev->empress_dev && dev->empress_dev->minor == minor)
84 goto found; 95 goto found;
96 unlock_kernel();
85 return -ENODEV; 97 return -ENODEV;
86 found: 98 found:
87 99
@@ -103,6 +115,7 @@ static int ts_open(struct inode *inode, struct file *file)
103done_up: 115done_up:
104 mutex_unlock(&dev->empress_tsq.vb_lock); 116 mutex_unlock(&dev->empress_tsq.vb_lock);
105done: 117done:
118 unlock_kernel();
106 return err; 119 return err;
107} 120}
108 121
@@ -290,15 +303,6 @@ static int empress_streamoff(struct file *file, void *priv,
290 return videobuf_streamoff(&dev->empress_tsq); 303 return videobuf_streamoff(&dev->empress_tsq);
291} 304}
292 305
293static int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
294 unsigned int cmd, void *arg)
295{
296 if (dev->mpeg_i2c_client == NULL)
297 return -EINVAL;
298 return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
299 cmd, arg);
300}
301
302static int empress_s_ext_ctrls(struct file *file, void *priv, 306static int empress_s_ext_ctrls(struct file *file, void *priv,
303 struct v4l2_ext_controls *ctrls) 307 struct v4l2_ext_controls *ctrls)
304{ 308{
@@ -400,6 +404,39 @@ static int empress_querymenu(struct file *file, void *priv,
400 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c); 404 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c);
401} 405}
402 406
407static int empress_g_chip_ident(struct file *file, void *fh,
408 struct v4l2_chip_ident *chip)
409{
410 struct saa7134_dev *dev = file->private_data;
411
412 chip->ident = V4L2_IDENT_NONE;
413 chip->revision = 0;
414 if (dev->mpeg_i2c_client == NULL)
415 return -EINVAL;
416 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER &&
417 chip->match_chip == I2C_DRIVERID_SAA6752HS)
418 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
419 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR &&
420 chip->match_chip == dev->mpeg_i2c_client->addr)
421 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
422 return -EINVAL;
423}
424
425static int empress_s_std(struct file *file, void *priv, v4l2_std_id *id)
426{
427 struct saa7134_dev *dev = file->private_data;
428
429 return saa7134_s_std_internal(dev, NULL, id);
430}
431
432static int empress_g_std(struct file *file, void *priv, v4l2_std_id *id)
433{
434 struct saa7134_dev *dev = file->private_data;
435
436 *id = dev->tvnorm->id;
437 return 0;
438}
439
403static const struct file_operations ts_fops = 440static const struct file_operations ts_fops =
404{ 441{
405 .owner = THIS_MODULE, 442 .owner = THIS_MODULE,
@@ -428,11 +465,13 @@ static const struct v4l2_ioctl_ops ts_ioctl_ops = {
428 .vidioc_enum_input = empress_enum_input, 465 .vidioc_enum_input = empress_enum_input,
429 .vidioc_g_input = empress_g_input, 466 .vidioc_g_input = empress_g_input,
430 .vidioc_s_input = empress_s_input, 467 .vidioc_s_input = empress_s_input,
431
432 .vidioc_queryctrl = empress_queryctrl, 468 .vidioc_queryctrl = empress_queryctrl,
433 .vidioc_querymenu = empress_querymenu, 469 .vidioc_querymenu = empress_querymenu,
434 .vidioc_g_ctrl = empress_g_ctrl, 470 .vidioc_g_ctrl = empress_g_ctrl,
435 .vidioc_s_ctrl = empress_s_ctrl, 471 .vidioc_s_ctrl = empress_s_ctrl,
472 .vidioc_g_chip_ident = empress_g_chip_ident,
473 .vidioc_s_std = empress_s_std,
474 .vidioc_g_std = empress_g_std,
436}; 475};
437 476
438/* ----------------------------------------------------------- */ 477/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 5f713e637683..20c1b33caf7b 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -337,6 +337,7 @@ static int attach_inform(struct i2c_client *client)
337 case 0x47: 337 case 0x47:
338 case 0x71: 338 case 0x71:
339 case 0x2d: 339 case 0x2d:
340 case 0x30:
340 { 341 {
341 struct IR_i2c *ir = i2c_get_clientdata(client); 342 struct IR_i2c *ir = i2c_get_clientdata(client);
342 d1printk("%s i2c IR detected (%s).\n", 343 d1printk("%s i2c IR detected (%s).\n",
@@ -427,6 +428,16 @@ void saa7134_i2c_call_clients(struct saa7134_dev *dev,
427 i2c_clients_command(&dev->i2c_adap, cmd, arg); 428 i2c_clients_command(&dev->i2c_adap, cmd, arg);
428} 429}
429 430
431int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
432 unsigned int cmd, void *arg)
433{
434 if (dev->mpeg_i2c_client == NULL)
435 return -EINVAL;
436 return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
437 cmd, arg);
438}
439EXPORT_SYMBOL_GPL(saa7134_i2c_call_saa6752);
440
430int saa7134_i2c_register(struct saa7134_dev *dev) 441int saa7134_i2c_register(struct saa7134_dev *dev)
431{ 442{
432 dev->i2c_adap = saa7134_adap_template; 443 dev->i2c_adap = saa7134_adap_template;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index ad08d13dffdd..c53fd5f9f6b5 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -62,8 +62,11 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
62#define i2cdprintk(fmt, arg...) if (ir_debug) \ 62#define i2cdprintk(fmt, arg...) if (ir_debug) \
63 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 63 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
64 64
65/** rc5 functions */ 65/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
66static int saa7134_rc5_irq(struct saa7134_dev *dev); 66static int saa7134_rc5_irq(struct saa7134_dev *dev);
67static int saa7134_nec_irq(struct saa7134_dev *dev);
68static void nec_task(unsigned long data);
69static void saa7134_nec_timer(unsigned long data);
67 70
68/* -------------------- GPIO generic keycode builder -------------------- */ 71/* -------------------- GPIO generic keycode builder -------------------- */
69 72
@@ -115,6 +118,53 @@ static int build_key(struct saa7134_dev *dev)
115 118
116/* --------------------- Chip specific I2C key builders ----------------- */ 119/* --------------------- Chip specific I2C key builders ----------------- */
117 120
121static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
122 u32 *ir_raw)
123{
124 unsigned char b;
125 int gpio;
126
127 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
128 struct saa7134_dev *dev = ir->c.adapter->algo_data;
129 if (dev == NULL) {
130 dprintk("get_key_msi_tvanywhere_plus: "
131 "gir->c.adapter->algo_data is NULL!\n");
132 return -EIO;
133 }
134
135 /* rising SAA7134_GPIO_GPRESCAN reads the status */
136
137 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
138 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
139
140 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
141
142 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
143 I2C receive if gpio&0x40 is not low. */
144
145 if (gpio & 0x40)
146 return 0; /* No button press */
147
148 /* GPIO says there is a button press. Get it. */
149
150 if (1 != i2c_master_recv(&ir->c, &b, 1)) {
151 i2cdprintk("read error\n");
152 return -EIO;
153 }
154
155 /* No button press */
156
157 if (b == 0xff)
158 return 0;
159
160 /* Button pressed */
161
162 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
163 *ir_key = b;
164 *ir_raw = b;
165 return 1;
166}
167
118static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 168static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
119{ 169{
120 unsigned char b; 170 unsigned char b;
@@ -280,7 +330,9 @@ void saa7134_input_irq(struct saa7134_dev *dev)
280{ 330{
281 struct card_ir *ir = dev->remote; 331 struct card_ir *ir = dev->remote;
282 332
283 if (!ir->polling && !ir->rc5_gpio) { 333 if (ir->nec_gpio) {
334 saa7134_nec_irq(dev);
335 } else if (!ir->polling && !ir->rc5_gpio) {
284 build_key(dev); 336 build_key(dev);
285 } else if (ir->rc5_gpio) { 337 } else if (ir->rc5_gpio) {
286 saa7134_rc5_irq(dev); 338 saa7134_rc5_irq(dev);
@@ -316,6 +368,10 @@ void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
316 ir->addr = 0x17; 368 ir->addr = 0x17;
317 ir->rc5_key_timeout = ir_rc5_key_timeout; 369 ir->rc5_key_timeout = ir_rc5_key_timeout;
318 ir->rc5_remote_gap = ir_rc5_remote_gap; 370 ir->rc5_remote_gap = ir_rc5_remote_gap;
371 } else if (ir->nec_gpio) {
372 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
373 (unsigned long)dev);
374 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
319 } 375 }
320} 376}
321 377
@@ -335,6 +391,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
335 u32 mask_keyup = 0; 391 u32 mask_keyup = 0;
336 int polling = 0; 392 int polling = 0;
337 int rc5_gpio = 0; 393 int rc5_gpio = 0;
394 int nec_gpio = 0;
338 int ir_type = IR_TYPE_OTHER; 395 int ir_type = IR_TYPE_OTHER;
339 int err; 396 int err;
340 397
@@ -391,6 +448,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
391 saa_setb(SAA7134_GPIO_GPMODE0, 0x4); 448 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
392 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); 449 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
393 break; 450 break;
451 case SAA7134_BOARD_AVERMEDIA_M135A:
452 ir_codes = ir_codes_avermedia_m135a;
453 mask_keydown = 0x0040000;
454 mask_keycode = 0x00013f;
455 nec_gpio = 1;
456 break;
394 case SAA7134_BOARD_AVERMEDIA_777: 457 case SAA7134_BOARD_AVERMEDIA_777:
395 case SAA7134_BOARD_AVERMEDIA_A16AR: 458 case SAA7134_BOARD_AVERMEDIA_A16AR:
396 ir_codes = ir_codes_avermedia; 459 ir_codes = ir_codes_avermedia;
@@ -499,6 +562,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
499 mask_keyup = 0x040000; 562 mask_keyup = 0x040000;
500 polling = 50; // ms 563 polling = 50; // ms
501 break; 564 break;
565 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
566 ir_codes = ir_codes_encore_enltv_fm53;
567 mask_keydown = 0x0040000;
568 mask_keycode = 0x00007f;
569 nec_gpio = 1;
570 break;
502 case SAA7134_BOARD_10MOONSTVMASTER3: 571 case SAA7134_BOARD_10MOONSTVMASTER3:
503 ir_codes = ir_codes_encore_enltv; 572 ir_codes = ir_codes_encore_enltv;
504 mask_keycode = 0x5f80000; 573 mask_keycode = 0x5f80000;
@@ -511,6 +580,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
511 mask_keydown = 0xf00000; 580 mask_keydown = 0xf00000;
512 polling = 50; /* ms */ 581 polling = 50; /* ms */
513 break; 582 break;
583 case SAA7134_BOARD_REAL_ANGEL_220:
584 ir_codes = ir_codes_real_audio_220_32_keys;
585 mask_keycode = 0x3f00;
586 mask_keyup = 0x4000;
587 polling = 50; /* ms */
588 break;
514 } 589 }
515 if (NULL == ir_codes) { 590 if (NULL == ir_codes) {
516 printk("%s: Oops: IR config error [card=%d]\n", 591 printk("%s: Oops: IR config error [card=%d]\n",
@@ -533,6 +608,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
533 ir->mask_keyup = mask_keyup; 608 ir->mask_keyup = mask_keyup;
534 ir->polling = polling; 609 ir->polling = polling;
535 ir->rc5_gpio = rc5_gpio; 610 ir->rc5_gpio = rc5_gpio;
611 ir->nec_gpio = nec_gpio;
536 612
537 /* init input device */ 613 /* init input device */
538 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", 614 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
@@ -612,6 +688,11 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
612 ir->get_key = get_key_purpletv; 688 ir->get_key = get_key_purpletv;
613 ir->ir_codes = ir_codes_purpletv; 689 ir->ir_codes = ir_codes_purpletv;
614 break; 690 break;
691 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
692 snprintf(ir->c.name, sizeof(ir->c.name), "MSI TV@nywhere Plus");
693 ir->get_key = get_key_msi_tvanywhere_plus;
694 ir->ir_codes = ir_codes_msi_tvanywhere_plus;
695 break;
615 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 696 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
616 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110"); 697 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
617 ir->get_key = get_key_hvr1110; 698 ir->get_key = get_key_hvr1110;
@@ -675,8 +756,125 @@ static int saa7134_rc5_irq(struct saa7134_dev *dev)
675 return 1; 756 return 1;
676} 757}
677 758
678/* ---------------------------------------------------------------------- 759
679 * Local variables: 760/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
680 * c-basic-offset: 8 761 The first pulse (start) has 9 + 4.5 ms
681 * End:
682 */ 762 */
763
764static void saa7134_nec_timer(unsigned long data)
765{
766 struct saa7134_dev *dev = (struct saa7134_dev *) data;
767 struct card_ir *ir = dev->remote;
768
769 dprintk("Cancel key repeat\n");
770
771 ir_input_nokey(ir->dev, &ir->ir);
772}
773
774static void nec_task(unsigned long data)
775{
776 struct saa7134_dev *dev = (struct saa7134_dev *) data;
777 struct card_ir *ir;
778 struct timeval tv;
779 int count, pulse, oldpulse, gap;
780 u32 ircode = 0, not_code = 0;
781 int ngap = 0;
782
783 if (!data) {
784 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
785 /* GPIO will be kept disabled */
786 return;
787 }
788
789 ir = dev->remote;
790
791 /* rising SAA7134_GPIO_GPRESCAN reads the status */
792 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
793 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
794
795 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
796 pulse = oldpulse;
797
798 do_gettimeofday(&tv);
799 ir->base_time = tv;
800
801 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
802 Unfortunately, using IRQ to decode pulse didn't work, since it uses
803 a pulse train of 38KHz. This means one pulse on each 52 us
804 */
805 do {
806 /* Wait until the end of pulse/space or 5 ms */
807 for (count = 0; count < 500; count++) {
808 udelay(10);
809 /* rising SAA7134_GPIO_GPRESCAN reads the status */
810 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
811 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
812 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
813 & ir->mask_keydown;
814 if (pulse != oldpulse)
815 break;
816 }
817
818 do_gettimeofday(&tv);
819 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
820 tv.tv_usec - ir->base_time.tv_usec;
821
822 if (!pulse) {
823 /* Bit 0 has 560 us, while bit 1 has 1120 us.
824 Do something only if bit == 1
825 */
826 if (ngap && (gap > 560 + 280)) {
827 unsigned int shift = ngap - 1;
828
829 /* Address first, then command */
830 if (shift < 8) {
831 shift += 8;
832 ircode |= 1 << shift;
833 } else if (shift < 16) {
834 not_code |= 1 << shift;
835 } else if (shift < 24) {
836 shift -= 16;
837 ircode |= 1 << shift;
838 } else {
839 shift -= 24;
840 not_code |= 1 << shift;
841 }
842 }
843 ngap++;
844 }
845
846
847 ir->base_time = tv;
848
849 /* TIMEOUT - Long pulse */
850 if (gap >= 5000)
851 break;
852 oldpulse = pulse;
853 } while (ngap < 32);
854
855 if (ngap == 32) {
856 /* FIXME: should check if not_code == ~ircode */
857 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
858
859 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
860 ir->code, ircode, not_code);
861
862 ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code);
863 } else
864 dprintk("Repeat last key\n");
865
866 /* Keep repeating the last key */
867 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
868
869 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
870}
871
872static int saa7134_nec_irq(struct saa7134_dev *dev)
873{
874 struct card_ir *ir = dev->remote;
875
876 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
877 tasklet_schedule(&ir->tlet);
878
879 return 1;
880}
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index eae72fd60cec..ef55a59f0cda 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -66,11 +66,29 @@ static int buffer_activate(struct saa7134_dev *dev,
66 saa7134_set_dmabits(dev); 66 saa7134_set_dmabits(dev);
67 67
68 mod_timer(&dev->ts_q.timeout, jiffies+BUFFER_TIMEOUT); 68 mod_timer(&dev->ts_q.timeout, jiffies+BUFFER_TIMEOUT);
69
70 if (dev->ts_state == SAA7134_TS_BUFF_DONE) {
71 /* Clear TS cache */
72 dev->buff_cnt = 0;
73 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
74 saa_writeb(SAA7134_TS_SERIAL1, 0x03);
75 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
76 saa_writeb(SAA7134_TS_SERIAL1, 0x01);
77
78 /* TS clock non-inverted */
79 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
80
81 /* Start TS stream */
82 saa_writeb(SAA7134_TS_SERIAL0, 0x40);
83 saa_writeb(SAA7134_TS_PARALLEL, 0xEC);
84 dev->ts_state = SAA7134_TS_STARTED;
85 }
86
69 return 0; 87 return 0;
70} 88}
71 89
72static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 90static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
73 enum v4l2_field field) 91 enum v4l2_field field)
74{ 92{
75 struct saa7134_dev *dev = q->priv_data; 93 struct saa7134_dev *dev = q->priv_data;
76 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 94 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
@@ -110,16 +128,22 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
110 goto oops; 128 goto oops;
111 } 129 }
112 130
113 /* dma: setup channel 5 (= TS) */ 131 dev->buff_cnt++;
114 control = SAA7134_RS_CONTROL_BURST_16 | 132
115 SAA7134_RS_CONTROL_ME | 133 if (dev->buff_cnt == dev->ts.nr_bufs) {
116 (buf->pt->dma >> 12); 134 dev->ts_state = SAA7134_TS_BUFF_DONE;
117 135 /* dma: setup channel 5 (= TS) */
118 saa_writeb(SAA7134_TS_DMA0, ((lines-1)&0xff)); 136 control = SAA7134_RS_CONTROL_BURST_16 |
119 saa_writeb(SAA7134_TS_DMA1, (((lines-1)>>8)&0xff)); 137 SAA7134_RS_CONTROL_ME |
120 saa_writeb(SAA7134_TS_DMA2, ((((lines-1)>>16)&0x3f) | 0x00)); /* TSNOPIT=0, TSCOLAP=0 */ 138 (buf->pt->dma >> 12);
121 saa_writel(SAA7134_RS_PITCH(5),TS_PACKET_SIZE); 139
122 saa_writel(SAA7134_RS_CONTROL(5),control); 140 saa_writeb(SAA7134_TS_DMA0, (lines - 1) & 0xff);
141 saa_writeb(SAA7134_TS_DMA1, ((lines - 1) >> 8) & 0xff);
142 /* TSNOPIT=0, TSCOLAP=0 */
143 saa_writeb(SAA7134_TS_DMA2, (((lines - 1) >> 16) & 0x3f) | 0x00);
144 saa_writel(SAA7134_RS_PITCH(5), TS_PACKET_SIZE);
145 saa_writel(SAA7134_RS_CONTROL(5), control);
146 }
123 147
124 buf->vb.state = VIDEOBUF_PREPARED; 148 buf->vb.state = VIDEOBUF_PREPARED;
125 buf->activate = buffer_activate; 149 buf->activate = buffer_activate;
@@ -140,6 +164,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
140 if (0 == *count) 164 if (0 == *count)
141 *count = dev->ts.nr_bufs; 165 *count = dev->ts.nr_bufs;
142 *count = saa7134_buffer_count(*size,*count); 166 *count = saa7134_buffer_count(*size,*count);
167 dev->buff_cnt = 0;
168 dev->ts_state = SAA7134_TS_STOPPED;
143 return 0; 169 return 0;
144} 170}
145 171
@@ -154,7 +180,13 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
154static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 180static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
155{ 181{
156 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 182 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
183 struct saa7134_dev *dev = q->priv_data;
157 184
185 if (dev->ts_state == SAA7134_TS_STARTED) {
186 /* Stop TS transport */
187 saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
188 dev->ts_state = SAA7134_TS_STOPPED;
189 }
158 saa7134_dma_free(q,buf); 190 saa7134_dma_free(q,buf);
159} 191}
160 192
@@ -182,7 +214,7 @@ int saa7134_ts_init_hw(struct saa7134_dev *dev)
182 /* deactivate TS softreset */ 214 /* deactivate TS softreset */
183 saa_writeb(SAA7134_TS_SERIAL1, 0x00); 215 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
184 /* TSSOP high active, TSVAL high active, TSLOCK ignored */ 216 /* TSSOP high active, TSVAL high active, TSLOCK ignored */
185 saa_writeb(SAA7134_TS_PARALLEL, 0xec); 217 saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
186 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1)); 218 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1));
187 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff)); 219 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff));
188 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff)); 220 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff));
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 68c268981861..02bb6747a39c 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -628,6 +628,9 @@ void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
628 628
629 if (card_in(dev, dev->ctl_input).tv) 629 if (card_in(dev, dev->ctl_input).tv)
630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id); 630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id);
631 /* Set the correct norm for the saa6752hs. This function
632 does nothing if there is no saa6752hs. */
633 saa7134_i2c_call_saa6752(dev, VIDIOC_S_STD, &dev->tvnorm->id);
631} 634}
632 635
633static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale) 636static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
@@ -1330,6 +1333,8 @@ static int video_open(struct inode *inode, struct file *file)
1330 struct saa7134_fh *fh; 1333 struct saa7134_fh *fh;
1331 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1334 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1332 int radio = 0; 1335 int radio = 0;
1336
1337 lock_kernel();
1333 list_for_each_entry(dev, &saa7134_devlist, devlist) { 1338 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1334 if (dev->video_dev && (dev->video_dev->minor == minor)) 1339 if (dev->video_dev && (dev->video_dev->minor == minor))
1335 goto found; 1340 goto found;
@@ -1342,6 +1347,7 @@ static int video_open(struct inode *inode, struct file *file)
1342 goto found; 1347 goto found;
1343 } 1348 }
1344 } 1349 }
1350 unlock_kernel();
1345 return -ENODEV; 1351 return -ENODEV;
1346 found: 1352 found:
1347 1353
@@ -1350,8 +1356,10 @@ static int video_open(struct inode *inode, struct file *file)
1350 1356
1351 /* allocate + initialize per filehandle data */ 1357 /* allocate + initialize per filehandle data */
1352 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1358 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1353 if (NULL == fh) 1359 if (NULL == fh) {
1360 unlock_kernel();
1354 return -ENOMEM; 1361 return -ENOMEM;
1362 }
1355 file->private_data = fh; 1363 file->private_data = fh;
1356 fh->dev = dev; 1364 fh->dev = dev;
1357 fh->radio = radio; 1365 fh->radio = radio;
@@ -1384,6 +1392,7 @@ static int video_open(struct inode *inode, struct file *file)
1384 /* switch to video/vbi mode */ 1392 /* switch to video/vbi mode */
1385 video_mux(dev,dev->ctl_input); 1393 video_mux(dev,dev->ctl_input);
1386 } 1394 }
1395 unlock_kernel();
1387 return 0; 1396 return 0;
1388} 1397}
1389 1398
@@ -1790,18 +1799,25 @@ static int saa7134_querycap(struct file *file, void *priv,
1790 return 0; 1799 return 0;
1791} 1800}
1792 1801
1793static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id) 1802int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id)
1794{ 1803{
1795 struct saa7134_fh *fh = priv;
1796 struct saa7134_dev *dev = fh->dev;
1797 unsigned long flags; 1804 unsigned long flags;
1798 unsigned int i; 1805 unsigned int i;
1799 v4l2_std_id fixup; 1806 v4l2_std_id fixup;
1800 int err; 1807 int err;
1801 1808
1802 err = v4l2_prio_check(&dev->prio, &fh->prio); 1809 /* When called from the empress code fh == NULL.
1803 if (0 != err) 1810 That needs to be fixed somehow, but for now this is
1804 return err; 1811 good enough. */
1812 if (fh) {
1813 err = v4l2_prio_check(&dev->prio, &fh->prio);
1814 if (0 != err)
1815 return err;
1816 } else if (res_locked(dev, RESOURCE_OVERLAY)) {
1817 /* Don't change the std from the mpeg device
1818 if overlay is active. */
1819 return -EBUSY;
1820 }
1805 1821
1806 for (i = 0; i < TVNORMS; i++) 1822 for (i = 0; i < TVNORMS; i++)
1807 if (*id == tvnorms[i].id) 1823 if (*id == tvnorms[i].id)
@@ -1834,7 +1850,7 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1834 *id = tvnorms[i].id; 1850 *id = tvnorms[i].id;
1835 1851
1836 mutex_lock(&dev->lock); 1852 mutex_lock(&dev->lock);
1837 if (res_check(fh, RESOURCE_OVERLAY)) { 1853 if (fh && res_check(fh, RESOURCE_OVERLAY)) {
1838 spin_lock_irqsave(&dev->slock, flags); 1854 spin_lock_irqsave(&dev->slock, flags);
1839 stop_preview(dev, fh); 1855 stop_preview(dev, fh);
1840 spin_unlock_irqrestore(&dev->slock, flags); 1856 spin_unlock_irqrestore(&dev->slock, flags);
@@ -1851,6 +1867,23 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1851 mutex_unlock(&dev->lock); 1867 mutex_unlock(&dev->lock);
1852 return 0; 1868 return 0;
1853} 1869}
1870EXPORT_SYMBOL_GPL(saa7134_s_std_internal);
1871
1872static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1873{
1874 struct saa7134_fh *fh = priv;
1875
1876 return saa7134_s_std_internal(fh->dev, fh, id);
1877}
1878
1879static int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id)
1880{
1881 struct saa7134_fh *fh = priv;
1882 struct saa7134_dev *dev = fh->dev;
1883
1884 *id = dev->tvnorm->id;
1885 return 0;
1886}
1854 1887
1855static int saa7134_cropcap(struct file *file, void *priv, 1888static int saa7134_cropcap(struct file *file, void *priv,
1856 struct v4l2_cropcap *cap) 1889 struct v4l2_cropcap *cap)
@@ -2077,18 +2110,6 @@ static int saa7134_enum_fmt_vid_overlay(struct file *file, void *priv,
2077 return 0; 2110 return 0;
2078} 2111}
2079 2112
2080static int saa7134_enum_fmt_vbi_cap(struct file *file, void *priv,
2081 struct v4l2_fmtdesc *f)
2082{
2083 if (0 != f->index)
2084 return -EINVAL;
2085
2086 f->pixelformat = V4L2_PIX_FMT_GREY;
2087 strcpy(f->description, "vbi data");
2088
2089 return 0;
2090}
2091
2092static int saa7134_g_fbuf(struct file *file, void *f, 2113static int saa7134_g_fbuf(struct file *file, void *f,
2093 struct v4l2_framebuffer *fb) 2114 struct v4l2_framebuffer *fb)
2094{ 2115{
@@ -2379,7 +2400,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2379 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay, 2400 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay,
2380 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay, 2401 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay,
2381 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay, 2402 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay,
2382 .vidioc_enum_fmt_vbi_cap = saa7134_enum_fmt_vbi_cap,
2383 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2403 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2384 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2404 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2385 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2405 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
@@ -2391,6 +2411,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2391 .vidioc_qbuf = saa7134_qbuf, 2411 .vidioc_qbuf = saa7134_qbuf,
2392 .vidioc_dqbuf = saa7134_dqbuf, 2412 .vidioc_dqbuf = saa7134_dqbuf,
2393 .vidioc_s_std = saa7134_s_std, 2413 .vidioc_s_std = saa7134_s_std,
2414 .vidioc_g_std = saa7134_g_std,
2394 .vidioc_enum_input = saa7134_enum_input, 2415 .vidioc_enum_input = saa7134_enum_input,
2395 .vidioc_g_input = saa7134_g_input, 2416 .vidioc_g_input = saa7134_g_input,
2396 .vidioc_s_input = saa7134_s_input, 2417 .vidioc_s_input = saa7134_s_input,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index a0884f639f65..491ab1f8fdd3 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -269,6 +269,12 @@ struct saa7134_format {
269#define SAA7134_BOARD_BEHOLD_M6_EXTRA 144 269#define SAA7134_BOARD_BEHOLD_M6_EXTRA 144
270#define SAA7134_BOARD_AVERMEDIA_M103 145 270#define SAA7134_BOARD_AVERMEDIA_M103 145
271#define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146 271#define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146
272#define SAA7134_BOARD_ASUSTeK_TIGER_3IN1 147
273#define SAA7134_BOARD_ENCORE_ENLTV_FM53 148
274#define SAA7134_BOARD_AVERMEDIA_M135A 149
275#define SAA7134_BOARD_REAL_ANGEL_220 150
276#define SAA7134_BOARD_ADS_INSTANT_HDTV_PCI 151
277#define SAA7134_BOARD_ASUSTeK_TIGER 152
272 278
273#define SAA7134_MAXBOARDS 8 279#define SAA7134_MAXBOARDS 8
274#define SAA7134_INPUT_MAX 8 280#define SAA7134_INPUT_MAX 8
@@ -462,6 +468,12 @@ struct saa7134_mpeg_ops {
462 void (*signal_change)(struct saa7134_dev *dev); 468 void (*signal_change)(struct saa7134_dev *dev);
463}; 469};
464 470
471enum saa7134_ts_status {
472 SAA7134_TS_STOPPED,
473 SAA7134_TS_BUFF_DONE,
474 SAA7134_TS_STARTED,
475};
476
465/* global device status */ 477/* global device status */
466struct saa7134_dev { 478struct saa7134_dev {
467 struct list_head devlist; 479 struct list_head devlist;
@@ -555,6 +567,8 @@ struct saa7134_dev {
555 /* SAA7134_MPEG_* */ 567 /* SAA7134_MPEG_* */
556 struct saa7134_ts ts; 568 struct saa7134_ts ts;
557 struct saa7134_dmaqueue ts_q; 569 struct saa7134_dmaqueue ts_q;
570 enum saa7134_ts_status ts_state;
571 unsigned int buff_cnt;
558 struct saa7134_mpeg_ops *mops; 572 struct saa7134_mpeg_ops *mops;
559 struct i2c_client *mpeg_i2c_client; 573 struct i2c_client *mpeg_i2c_client;
560 574
@@ -644,7 +658,7 @@ extern struct pci_device_id __devinitdata saa7134_pci_tbl[];
644 658
645extern int saa7134_board_init1(struct saa7134_dev *dev); 659extern int saa7134_board_init1(struct saa7134_dev *dev);
646extern int saa7134_board_init2(struct saa7134_dev *dev); 660extern int saa7134_board_init2(struct saa7134_dev *dev);
647int saa7134_tuner_callback(void *priv, int command, int arg); 661int saa7134_tuner_callback(void *priv, int component, int command, int arg);
648 662
649 663
650/* ----------------------------------------------------------- */ 664/* ----------------------------------------------------------- */
@@ -654,6 +668,8 @@ int saa7134_i2c_register(struct saa7134_dev *dev);
654int saa7134_i2c_unregister(struct saa7134_dev *dev); 668int saa7134_i2c_unregister(struct saa7134_dev *dev);
655void saa7134_i2c_call_clients(struct saa7134_dev *dev, 669void saa7134_i2c_call_clients(struct saa7134_dev *dev,
656 unsigned int cmd, void *arg); 670 unsigned int cmd, void *arg);
671int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
672 unsigned int cmd, void *arg);
657 673
658 674
659/* ----------------------------------------------------------- */ 675/* ----------------------------------------------------------- */
@@ -666,6 +682,7 @@ extern struct video_device saa7134_radio_template;
666int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 682int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
667int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 683int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
668int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c); 684int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
685int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id);
669 686
670int saa7134_videoport_init(struct saa7134_dev *dev); 687int saa7134_videoport_init(struct saa7134_dev *dev);
671void saa7134_set_tvnorm_hw(struct saa7134_dev *dev); 688void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);