OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [media/] [video/] [tda9887.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
#include <linux/module.h>
2
#include <linux/kernel.h>
3
#include <linux/i2c.h>
4
#include <linux/types.h>
5
#include <linux/videodev.h>
6
#include <linux/init.h>
7
#include <linux/errno.h>
8
#include <linux/slab.h>
9
 
10
#include "audiochip.h"
11
#include "id.h"
12
#include "i2c-compat.h"
13
 
14
/* Chips:
15
   TDA9885 (PAL, NTSC)
16
   TDA9886 (PAL, SECAM, NTSC)
17
   TDA9887 (PAL, SECAM, NTSC, FM Radio)
18
 
19
   found on:
20
   - Pinnacle PCTV (Jul.2002 Version with MT2032, bttv)
21
      TDA9887 (world), TDA9885 (USA)
22
      Note: OP2 of tda988x must be set to 1, else MT2032 is disabled!
23
   - KNC One TV-Station RDS (saa7134)
24
*/
25
 
26
 
27
/* Addresses to scan */
28
static unsigned short normal_i2c[] = {I2C_CLIENT_END};
29
static unsigned short normal_i2c_range[] = {0x86>>1,0x86>>1,I2C_CLIENT_END};
30
I2C_CLIENT_INSMOD;
31
 
32
/* insmod options */
33
static int debug =  0;
34
static char *pal =  "b";
35
static char *secam =  "l";
36
MODULE_PARM(debug,"i");
37
MODULE_PARM(pal,"s");
38
MODULE_PARM(secam,"s");
39
MODULE_LICENSE("GPL");
40
 
41
/* ---------------------------------------------------------------------- */
42
 
43
#define dprintk     if (debug) printk
44
 
45
struct tda9887 {
46
        struct i2c_client client;
47
        int radio,tvnorm;
48
        int pinnacle_id;
49
};
50
 
51
static struct i2c_driver driver;
52
static struct i2c_client client_template;
53
 
54
/* ---------------------------------------------------------------------- */
55
 
56
//
57
// TDA defines
58
//
59
 
60
//// first reg
61
#define cVideoTrapBypassOFF     0x00    // bit b0
62
#define cVideoTrapBypassON      0x01    // bit b0
63
 
64
#define cAutoMuteFmInactive     0x00    // bit b1
65
#define cAutoMuteFmActive       0x02    // bit b1
66
 
67
#define cIntercarrier           0x00    // bit b2
68
#define cQSS                    0x04    // bit b2
69
 
70
#define cPositiveAmTV           0x00    // bit b3:4
71
#define cFmRadio                0x08    // bit b3:4
72
#define cNegativeFmTV           0x10    // bit b3:4
73
 
74
 
75
#define cForcedMuteAudioON      0x20    // bit b5
76
#define cForcedMuteAudioOFF     0x00    // bit b5
77
 
78
#define cOutputPort1Active      0x00    // bit b6
79
#define cOutputPort1Inactive    0x40    // bit b6
80
 
81
#define cOutputPort2Active      0x00    // bit b7
82
#define cOutputPort2Inactive    0x80    // bit b7
83
 
84
 
85
//// second reg
86
#define cDeemphasisOFF          0x00    // bit c5
87
#define cDeemphasisON           0x20    // bit c5
88
 
89
#define cDeemphasis75           0x00    // bit c6
90
#define cDeemphasis50           0x40    // bit c6
91
 
92
#define cAudioGain0             0x00    // bit c7
93
#define cAudioGain6             0x80    // bit c7
94
 
95
 
96
//// third reg
97
#define cAudioIF_4_5             0x00    // bit e0:1
98
#define cAudioIF_5_5             0x01    // bit e0:1
99
#define cAudioIF_6_0             0x02    // bit e0:1
100
#define cAudioIF_6_5             0x03    // bit e0:1
101
 
102
 
103
#define cVideoIF_58_75           0x00    // bit e2:4
104
#define cVideoIF_45_75           0x04    // bit e2:4
105
#define cVideoIF_38_90           0x08    // bit e2:4
106
#define cVideoIF_38_00           0x0C    // bit e2:4
107
#define cVideoIF_33_90           0x10    // bit e2:4
108
#define cVideoIF_33_40           0x14    // bit e2:4
109
#define cRadioIF_45_75           0x18    // bit e2:4
110
#define cRadioIF_38_90           0x1C    // bit e2:4
111
 
112
 
113
#define cTunerGainNormal         0x00    // bit e5
114
#define cTunerGainLow            0x20    // bit e5
115
 
116
#define cGating_18               0x00    // bit e6
117
#define cGating_36               0x40    // bit e6
118
 
119
#define cAgcOutON                0x80    // bit e7
120
#define cAgcOutOFF               0x00    // bit e7
121
 
122
static int tda9887_miro(struct tda9887 *t)
123
{
124
        int rc;
125
        u8   bData[4]     = { 0 };
126
        u8   bVideoIF     = 0;
127
        u8   bAudioIF     = 0;
128
        u8   bDeEmphasis  = 0;
129
        u8   bDeEmphVal   = 0;
130
        u8   bModulation  = 0;
131
        u8   bCarrierMode = 0;
132
        u8   bOutPort1    = cOutputPort1Inactive;
133
#if 0
134
        u8   bOutPort2    = cOutputPort2Inactive & mbTADState; // store i2c tuner state
135
#else
136
        u8   bOutPort2    = cOutputPort2Inactive;
137
#endif
138
        u8   bVideoTrap   = cVideoTrapBypassOFF;
139
#if 1
140
        u8   bTopAdjust   = 0x0e /* -2dB */;
141
#else
142
        u8   bTopAdjust   = 0;
143
#endif
144
 
145
#if 0
146
        if (mParams.fVideoTrap)
147
                bVideoTrap   = cVideoTrapBypassON;
148
#endif
149
 
150
        if (t->radio) {
151
                bVideoTrap   = cVideoTrapBypassOFF;
152
                bCarrierMode = cQSS;
153
                bModulation  = cFmRadio;
154
                bOutPort1    = cOutputPort1Inactive;
155
                bDeEmphasis  = cDeemphasisON;
156
                if (3 == t->pinnacle_id) {
157
                        /* ntsc */
158
                        bDeEmphVal   = cDeemphasis75;
159
                        bAudioIF     = cAudioIF_4_5;
160
                        bVideoIF     = cRadioIF_45_75;
161
                } else {
162
                        /* pal */
163
                        bAudioIF     = cAudioIF_5_5;
164
                        bVideoIF     = cRadioIF_38_90;
165
                        bDeEmphVal   = cDeemphasis50;
166
                }
167
 
168
        } else if (t->tvnorm == VIDEO_MODE_PAL) {
169
                bDeEmphasis  = cDeemphasisON;
170
                bDeEmphVal   = cDeemphasis50;
171
                bModulation  = cNegativeFmTV;
172
                bOutPort1    = cOutputPort1Inactive;
173
                if (1 == t->pinnacle_id) {
174
                        bCarrierMode = cIntercarrier;
175
                } else {
176
                        // stereo boards
177
                        bCarrierMode = cQSS;
178
                }
179
                switch (pal[0]) {
180
                case 'b':
181
                case 'g':
182
                case 'h':
183
                        bVideoIF     = cVideoIF_38_90;
184
                        bAudioIF     = cAudioIF_5_5;
185
                        break;
186
                case 'd':
187
                        bVideoIF     = cVideoIF_38_00;
188
                        bAudioIF     = cAudioIF_6_5;
189
                        break;
190
                case 'i':
191
                        bVideoIF     = cVideoIF_38_90;
192
                        bAudioIF     = cAudioIF_6_0;
193
                        break;
194
                case 'm':
195
                case 'n':
196
                        bVideoIF     = cVideoIF_45_75;
197
                        bAudioIF     = cAudioIF_4_5;
198
                        bDeEmphVal   = cDeemphasis75;
199
                        if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) {
200
                                bCarrierMode = cIntercarrier;
201
                        } else {
202
                                bCarrierMode = cQSS;
203
                        }
204
                        break;
205
                }
206
 
207
        } else if (t->tvnorm == VIDEO_MODE_SECAM) {
208
                bAudioIF     = cAudioIF_6_5;
209
                bDeEmphasis  = cDeemphasisON;
210
                bDeEmphVal   = cDeemphasis50;
211
                bModulation  = cNegativeFmTV;
212
                bCarrierMode = cQSS;
213
                bOutPort1    = cOutputPort1Inactive;
214
                switch (secam[0]) {
215
                case 'd':
216
                        bVideoIF     = cVideoIF_38_00;
217
                        break;
218
                case 'k':
219
                        bVideoIF     = cVideoIF_38_90;
220
                        break;
221
                case 'l':
222
                        bVideoIF     = cVideoIF_38_90;
223
                        bDeEmphasis  = cDeemphasisOFF;
224
                        bDeEmphVal   = cDeemphasis75;
225
                        bModulation  = cPositiveAmTV;
226
                        break;
227
                case 'L' /* L1 */:
228
                        bVideoIF     = cVideoIF_33_90;
229
                        bDeEmphasis  = cDeemphasisOFF;
230
                        bDeEmphVal   = cDeemphasis75;
231
                        bModulation  = cPositiveAmTV;
232
                        break;
233
                }
234
 
235
        } else if (t->tvnorm == VIDEO_MODE_NTSC) {
236
                bVideoIF     = cVideoIF_45_75;
237
                bAudioIF     = cAudioIF_4_5;
238
                bDeEmphasis  = cDeemphasisON;
239
                bDeEmphVal   = cDeemphasis75;
240
                bModulation  = cNegativeFmTV;
241
                bOutPort1    = cOutputPort1Inactive;
242
                if ((5 == t->pinnacle_id) || (6 == t->pinnacle_id)) {
243
                        bCarrierMode = cIntercarrier;
244
                } else {
245
                        bCarrierMode = cQSS;
246
                }
247
        }
248
 
249
        bData[1] = bVideoTrap        |  // B0: video trap bypass
250
                cAutoMuteFmInactive  |  // B1: auto mute
251
                bCarrierMode         |  // B2: InterCarrier for PAL else QSS 
252
                bModulation          |  // B3 - B4: positive AM TV for SECAM only
253
                cForcedMuteAudioOFF  |  // B5: forced Audio Mute (off)
254
                bOutPort1            |  // B6: Out Port 1 
255
                bOutPort2;              // B7: Out Port 2 
256
        bData[2] = bTopAdjust |   // C0 - C4: Top Adjust 0 == -16dB  31 == 15dB
257
                bDeEmphasis   |   // C5: De-emphasis on/off
258
                bDeEmphVal    |   // C6: De-emphasis 50/75 microsec
259
                cAudioGain0;      // C7: normal audio gain
260
        bData[3] = bAudioIF      |  // E0 - E1: Sound IF
261
                bVideoIF         |  // E2 - E4: Video IF
262
                cTunerGainNormal |  // E5: Tuner gain (normal)
263
                cGating_18       |  // E6: Gating (18%)
264
                cAgcOutOFF;         // E7: VAGC  (off)
265
 
266
        dprintk("tda9885/6/7: 0x%02x 0x%02x 0x%02x [pinnacle_id=%d]\n",
267
                bData[1],bData[2],bData[3],t->pinnacle_id);
268
        if (4 != (rc = i2c_master_send(&t->client,bData,4)))
269
                printk("tda9885/6/7: i2c i/o error: rc == %d (should be 4)\n",rc);
270
        return 0;
271
}
272
 
273
/* ---------------------------------------------------------------------- */
274
 
275
#if 0
276
/* just for reference: old knc-one saa7134 stuff */
277
static unsigned char buf_pal_bg[]    = { 0x00, 0x16, 0x70, 0x49 };
278
static unsigned char buf_pal_i[]     = { 0x00, 0x16, 0x70, 0x4a };
279
static unsigned char buf_pal_dk[]    = { 0x00, 0x16, 0x70, 0x4b };
280
static unsigned char buf_pal_l[]     = { 0x00, 0x06, 0x50, 0x4b };
281
static unsigned char buf_fm_stereo[] = { 0x00, 0x0e, 0x0d, 0x77 };
282
#endif
283
 
284
static unsigned char buf_pal_bg[]    = { 0x00, 0x96, 0x70, 0x49 };
285
static unsigned char buf_pal_i[]     = { 0x00, 0x96, 0x70, 0x4a };
286
static unsigned char buf_pal_dk[]    = { 0x00, 0x96, 0x70, 0x4b };
287
static unsigned char buf_pal_l[]     = { 0x00, 0x86, 0x50, 0x4b };
288
static unsigned char buf_fm_stereo[] = { 0x00, 0x8e, 0x0d, 0x77 };
289
static unsigned char buf_ntsc[]      = { 0x00, 0x96, 0x70, 0x44 };
290
static unsigned char buf_ntsc_jp[]   = { 0x00, 0x96, 0x70, 0x40 };
291
 
292
static int tda9887_configure(struct tda9887 *t)
293
{
294
        unsigned char *buf = NULL;
295
        int rc;
296
 
297
        if (t->radio) {
298
                dprintk("tda9885/6/7: FM Radio mode\n");
299
                buf = buf_fm_stereo;
300
 
301
        } else if (t->tvnorm == VIDEO_MODE_PAL) {
302
                dprintk("tda9885/6/7: PAL-%c mode\n",pal[0]);
303
                switch (pal[0]) {
304
                case 'b':
305
                case 'g':
306
                        buf = buf_pal_bg;
307
                        break;
308
                case 'i':
309
                        buf = buf_pal_i;
310
                        break;
311
                case 'd':
312
                case 'k':
313
                        buf = buf_pal_dk;
314
                        break;
315
                case 'l':
316
                        buf = buf_pal_l;
317
                        break;
318
                }
319
 
320
        } else if (t->tvnorm == VIDEO_MODE_NTSC) {
321
                dprintk("tda9885/6/7: NTSC mode\n");
322
                buf = buf_ntsc;
323
 
324
        } else if (t->tvnorm == VIDEO_MODE_SECAM) {
325
                dprintk("tda9885/6/7: SECAM mode\n");
326
                buf = buf_pal_l;
327
 
328
        } else if (t->tvnorm == 6 /* BTTV hack */) {
329
                dprintk("tda9885/6/7: NTSC-Japan mode\n");
330
                buf = buf_ntsc_jp;
331
        }
332
 
333
        if (NULL == buf) {
334
                printk("tda9885/6/7 unknown norm=%d\n",t->tvnorm);
335
                return 0;
336
        }
337
 
338
        dprintk("tda9885/6/7: 0x%02x 0x%02x 0x%02x\n",
339
                buf[1],buf[2],buf[3]);
340
        if (4 != (rc = i2c_master_send(&t->client,buf,4)))
341
                printk("tda9885/6/7: i2c i/o error: rc == %d (should be 4)\n",rc);
342
        return 0;
343
}
344
 
345
/* ---------------------------------------------------------------------- */
346
 
347
static int tda9887_attach(struct i2c_adapter *adap, int addr,
348
                          unsigned short flags, int kind)
349
{
350
        struct tda9887 *t;
351
 
352
        client_template.adapter = adap;
353
        client_template.addr    = addr;
354
 
355
        printk("tda9887: chip found @ 0x%x\n", addr<<1);
356
 
357
        if (NULL == (t = kmalloc(sizeof(*t), GFP_KERNEL)))
358
                return -ENOMEM;
359
        memset(t,0,sizeof(*t));
360
        t->client = client_template;
361
        t->pinnacle_id = -1;
362
        t->tvnorm=VIDEO_MODE_PAL;
363
        i2c_set_clientdata(&t->client, t);
364
        i2c_attach_client(&t->client);
365
 
366
        MOD_INC_USE_COUNT;
367
        return 0;
368
}
369
 
370
static int tda9887_probe(struct i2c_adapter *adap)
371
{
372
#ifdef I2C_ADAP_CLASS_TV_ANALOG
373
        if (adap->class & I2C_ADAP_CLASS_TV_ANALOG)
374
                return i2c_probe(adap, &addr_data, tda9887_attach);
375
#else
376
        switch (adap->id) {
377
        case I2C_ALGO_BIT | I2C_HW_B_BT848:
378
        case I2C_ALGO_BIT | I2C_HW_B_RIVA:
379
        case I2C_ALGO_SAA7134:
380
                return i2c_probe(adap, &addr_data, tda9887_attach);
381
                break;
382
        }
383
#endif
384
        return 0;
385
}
386
 
387
static int tda9887_detach(struct i2c_client *client)
388
{
389
        struct tda9887 *t = i2c_get_clientdata(client);
390
 
391
        i2c_detach_client(client);
392
        kfree(t);
393
        MOD_DEC_USE_COUNT;
394
        return 0;
395
}
396
 
397
static int
398
tda9887_command(struct i2c_client *client, unsigned int cmd, void *arg)
399
{
400
        struct tda9887 *t = i2c_get_clientdata(client);
401
 
402
        switch (cmd) {
403
 
404
        /* --- configuration --- */
405
        case AUDC_SET_RADIO:
406
                t->radio = 1;
407
                if (-1 != t->pinnacle_id)
408
                        tda9887_miro(t);
409
                else
410
                        tda9887_configure(t);
411
                break;
412
 
413
        case AUDC_CONFIG_PINNACLE:
414
        {
415
                int *i = arg;
416
 
417
                t->pinnacle_id = *i;
418
                tda9887_miro(t);
419
                break;
420
        }
421
        /* --- v4l ioctls --- */
422
        /* take care: bttv does userspace copying, we'll get a
423
           kernel pointer here... */
424
        case VIDIOCSCHAN:
425
        {
426
                struct video_channel *vc = arg;
427
 
428
                t->radio  = 0;
429
                t->tvnorm = vc->norm;
430
                if (-1 != t->pinnacle_id)
431
                        tda9887_miro(t);
432
                else
433
                        tda9887_configure(t);
434
                break;
435
        }
436
        default:
437
                /* nothing */
438
                break;
439
        }
440
        return 0;
441
}
442
 
443
/* ----------------------------------------------------------------------- */
444
 
445
static struct i2c_driver driver = {
446
        .name           = "i2c tda9887 driver",
447
        .id             = -1, /* FIXME */
448
        .flags          = I2C_DF_NOTIFY,
449
        .attach_adapter = tda9887_probe,
450
        .detach_client  = tda9887_detach,
451
        .command        = tda9887_command,
452
};
453
static struct i2c_client client_template =
454
{
455
        I2C_DEVNAME("tda9887"),
456
        .flags     = I2C_CLIENT_ALLOW_USE,
457
        .driver    = &driver,
458
};
459
 
460
static int tda9887_init_module(void)
461
{
462
        i2c_add_driver(&driver);
463
        return 0;
464
}
465
 
466
static void tda9887_cleanup_module(void)
467
{
468
        i2c_del_driver(&driver);
469
}
470
 
471
module_init(tda9887_init_module);
472
module_exit(tda9887_cleanup_module);
473
 
474
/*
475
 * Overrides for Emacs so that we follow Linus's tabbing style.
476
 * ---------------------------------------------------------------------------
477
 * Local variables:
478
 * c-basic-offset: 8
479
 * End:
480
 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.