6ebf58724a0134d27737b015a0acced695252ce0
[linux-2.6.git] / drivers / media / video / cx23885 / cx23885-cards.c
1 /*
2  *  Driver for the Conexant CX23885 PCIe bridge
3  *
4  *  Copyright (c) 2006 Steven Toth <stoth@hauppauge.com>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/delay.h>
26 #include <media/cx25840.h>
27
28 #include "cx23885.h"
29
30 /* ------------------------------------------------------------------ */
31 /* board config info                                                  */
32
33 struct cx23885_board cx23885_boards[] = {
34         [CX23885_BOARD_UNKNOWN] = {
35                 .name           = "UNKNOWN/GENERIC",
36                 /* Ensure safe default for unknown boards */
37                 .clk_freq       = 0,
38                 .input          = {{
39                         .type   = CX23885_VMUX_COMPOSITE1,
40                         .vmux   = 0,
41                 },{
42                         .type   = CX23885_VMUX_COMPOSITE2,
43                         .vmux   = 1,
44                 },{
45                         .type   = CX23885_VMUX_COMPOSITE3,
46                         .vmux   = 2,
47                 },{
48                         .type   = CX23885_VMUX_COMPOSITE4,
49                         .vmux   = 3,
50                 }},
51         },
52         [CX23885_BOARD_HAUPPAUGE_HVR1800lp] = {
53                 .name           = "Hauppauge WinTV-HVR1800lp",
54                 .portc          = CX23885_MPEG_DVB,
55                 .input          = {{
56                         .type   = CX23885_VMUX_TELEVISION,
57                         .vmux   = 0,
58                         .gpio0  = 0xff00,
59                 },{
60                         .type   = CX23885_VMUX_DEBUG,
61                         .vmux   = 0,
62                         .gpio0  = 0xff01,
63                 },{
64                         .type   = CX23885_VMUX_COMPOSITE1,
65                         .vmux   = 1,
66                         .gpio0  = 0xff02,
67                 },{
68                         .type   = CX23885_VMUX_SVIDEO,
69                         .vmux   = 2,
70                         .gpio0  = 0xff02,
71                 }},
72         },
73         [CX23885_BOARD_HAUPPAUGE_HVR1800] = {
74                 .name           = "Hauppauge WinTV-HVR1800",
75                 .porta          = CX23885_ANALOG_VIDEO,
76                 .portb          = CX23885_MPEG_ENCODER,
77                 .portc          = CX23885_MPEG_DVB,
78                 .tuner_type     = TUNER_PHILIPS_TDA8290,
79                 .tuner_addr     = 0x42, /* 0x84 >> 1 */
80                 .input          = {{
81                         .type   = CX23885_VMUX_TELEVISION,
82                         .vmux   =       CX25840_VIN7_CH3 |
83                                         CX25840_VIN5_CH2 |
84                                         CX25840_VIN2_CH1,
85                         .gpio0  = 0,
86                 },{
87                         .type   = CX23885_VMUX_COMPOSITE1,
88                         .vmux   =       CX25840_VIN7_CH3 |
89                                         CX25840_VIN4_CH2 |
90                                         CX25840_VIN6_CH1,
91                         .gpio0  = 0,
92                 },{
93                         .type   = CX23885_VMUX_SVIDEO,
94                         .vmux   =       CX25840_VIN7_CH3 |
95                                         CX25840_VIN4_CH2 |
96                                         CX25840_VIN8_CH1 |
97                                         CX25840_SVIDEO_ON,
98                         .gpio0  = 0,
99                 }},
100         },
101         [CX23885_BOARD_HAUPPAUGE_HVR1250] = {
102                 .name           = "Hauppauge WinTV-HVR1250",
103                 .portc          = CX23885_MPEG_DVB,
104                 .input          = {{
105                         .type   = CX23885_VMUX_TELEVISION,
106                         .vmux   = 0,
107                         .gpio0  = 0xff00,
108                 },{
109                         .type   = CX23885_VMUX_DEBUG,
110                         .vmux   = 0,
111                         .gpio0  = 0xff01,
112                 },{
113                         .type   = CX23885_VMUX_COMPOSITE1,
114                         .vmux   = 1,
115                         .gpio0  = 0xff02,
116                 },{
117                         .type   = CX23885_VMUX_SVIDEO,
118                         .vmux   = 2,
119                         .gpio0  = 0xff02,
120                 }},
121         },
122         [CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP] = {
123                 .name           = "DViCO FusionHDTV5 Express",
124                 .portb          = CX23885_MPEG_DVB,
125         },
126         [CX23885_BOARD_HAUPPAUGE_HVR1500Q] = {
127                 .name           = "Hauppauge WinTV-HVR1500Q",
128                 .portc          = CX23885_MPEG_DVB,
129         },
130         [CX23885_BOARD_HAUPPAUGE_HVR1500] = {
131                 .name           = "Hauppauge WinTV-HVR1500",
132                 .portc          = CX23885_MPEG_DVB,
133         },
134         [CX23885_BOARD_HAUPPAUGE_HVR1200] = {
135                 .name           = "Hauppauge WinTV-HVR1200",
136                 .portc          = CX23885_MPEG_DVB,
137         },
138         [CX23885_BOARD_HAUPPAUGE_HVR1700] = {
139                 .name           = "Hauppauge WinTV-HVR1700",
140                 .portc          = CX23885_MPEG_DVB,
141         },
142         [CX23885_BOARD_HAUPPAUGE_HVR1400] = {
143                 .name           = "Hauppauge WinTV-HVR1400",
144                 .portc          = CX23885_MPEG_DVB,
145         },
146 };
147 const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
148
149 /* ------------------------------------------------------------------ */
150 /* PCI subsystem IDs                                                  */
151
152 struct cx23885_subid cx23885_subids[] = {
153         {
154                 .subvendor = 0x0070,
155                 .subdevice = 0x3400,
156                 .card      = CX23885_BOARD_UNKNOWN,
157         },{
158                 .subvendor = 0x0070,
159                 .subdevice = 0x7600,
160                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1800lp,
161         },{
162                 .subvendor = 0x0070,
163                 .subdevice = 0x7800,
164                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1800,
165         },{
166                 .subvendor = 0x0070,
167                 .subdevice = 0x7801,
168                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1800,
169         },{
170                 .subvendor = 0x0070,
171                 .subdevice = 0x7809,
172                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1800,
173         },{
174                 .subvendor = 0x0070,
175                 .subdevice = 0x7911,
176                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1250,
177         },{
178                 .subvendor = 0x18ac,
179                 .subdevice = 0xd500,
180                 .card      = CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP,
181         },{
182                 .subvendor = 0x0070,
183                 .subdevice = 0x7790,
184                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1500Q,
185         },{
186                 .subvendor = 0x0070,
187                 .subdevice = 0x7797,
188                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1500Q,
189         },{
190                 .subvendor = 0x0070,
191                 .subdevice = 0x7710,
192                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1500,
193         },{
194                 .subvendor = 0x0070,
195                 .subdevice = 0x7717,
196                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1500,
197         }, {
198                 .subvendor = 0x0070,
199                 .subdevice = 0x71d1,
200                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1200,
201         }, {
202                 .subvendor = 0x0070,
203                 .subdevice = 0x8101,
204                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1700,
205         }, {
206                 .subvendor = 0x0070,
207                 .subdevice = 0x8010,
208                 .card      = CX23885_BOARD_HAUPPAUGE_HVR1400,
209         },
210 };
211 const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
212
213 void cx23885_card_list(struct cx23885_dev *dev)
214 {
215         int i;
216
217         if (0 == dev->pci->subsystem_vendor &&
218             0 == dev->pci->subsystem_device) {
219                 printk("%s: Your board has no valid PCIe Subsystem ID and thus can't\n"
220                        "%s: be autodetected.  Please pass card=<n> insmod option to\n"
221                        "%s: workaround that.  Redirect complaints to the vendor of\n"
222                        "%s: the TV card.  Best regards,\n"
223                        "%s:         -- tux\n",
224                        dev->name, dev->name, dev->name, dev->name, dev->name);
225         } else {
226                 printk("%s: Your board isn't known (yet) to the driver.  You can\n"
227                        "%s: try to pick one of the existing card configs via\n"
228                        "%s: card=<n> insmod option.  Updating to the latest\n"
229                        "%s: version might help as well.\n",
230                        dev->name, dev->name, dev->name, dev->name);
231         }
232         printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
233                dev->name);
234         for (i = 0; i < cx23885_bcount; i++)
235                 printk("%s:    card=%d -> %s\n",
236                        dev->name, i, cx23885_boards[i].name);
237 }
238
239 static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
240 {
241         struct tveeprom tv;
242
243         tveeprom_hauppauge_analog(&dev->i2c_bus[0].i2c_client, &tv, eeprom_data);
244
245         /* Make sure we support the board model */
246         switch (tv.model)
247         {
248         case 76601: /* WinTV-HVR1800lp (PCIe, Retail, No IR, Dual channel ATSC and MPEG2 HW Encoder */
249         case 77001: /* WinTV-HVR1500 (Express Card, OEM, No IR, ATSC and Basic analog */
250         case 77011: /* WinTV-HVR1500 (Express Card, Retail, No IR, ATSC and Basic analog */
251         case 77041: /* WinTV-HVR1500Q (Express Card, OEM, No IR, ATSC/QAM and Basic analog */
252         case 77051: /* WinTV-HVR1500Q (Express Card, Retail, No IR, ATSC/QAM and Basic analog */
253         case 78011: /* WinTV-HVR1800 (PCIe, Retail, 3.5mm in, IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
254         case 78501: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, FM, Dual channel ATSC and MPEG2 HW Encoder */
255         case 78521: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, FM, Dual channel ATSC and MPEG2 HW Encoder */
256         case 78531: /* WinTV-HVR1800 (PCIe, OEM, RCA in, No IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
257         case 78631: /* WinTV-HVR1800 (PCIe, OEM, No IR, No FM, Dual channel ATSC and MPEG2 HW Encoder */
258         case 79001: /* WinTV-HVR1250 (PCIe, Retail, IR, full height, ATSC and Basic analog */
259         case 79101: /* WinTV-HVR1250 (PCIe, Retail, IR, half height, ATSC and Basic analog */
260         case 79561: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */
261         case 79571: /* WinTV-HVR1250 (PCIe, OEM, No IR, full height, ATSC and Basic analog */
262         case 79671: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */
263         case 80019:
264                 /* WinTV-HVR1400 (Express Card, Retail, IR,
265                  * DVB-T and Basic analog */
266         case 81519:
267                 /* WinTV-HVR1700 (PCIe, Retail, No IR, half height,
268                  * DVB-T and MPEG2 HW Encoder */
269                 break;
270         default:
271                 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model);
272                 break;
273         }
274
275         printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
276                         dev->name, tv.model);
277 }
278
279 /* Tuner callback function for cx23885 boards. Currently only needed
280  * for HVR1500Q, which has an xc5000 tuner.
281  */
282 int cx23885_tuner_callback(void *priv, int command, int arg)
283 {
284         struct cx23885_i2c *bus = priv;
285         struct cx23885_dev *dev = bus->dev;
286
287         switch(dev->board) {
288         case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
289                 if(command == 0) {      /* Tuner Reset Command from xc5000 */
290                         /* Drive the tuner into reset and out */
291                         cx_clear(GP0_IO, 0x00000004);
292                         mdelay(200);
293                         cx_set(GP0_IO, 0x00000004);
294                         return 0;
295                 }
296                 else {
297                         printk(KERN_ERR
298                                 "%s(): Unknow command.\n", __func__);
299                         return -EINVAL;
300                 }
301                 break;
302         }
303
304         return 0; /* Should never be here */
305 }
306
307 void cx23885_gpio_setup(struct cx23885_dev *dev)
308 {
309         switch(dev->board) {
310         case CX23885_BOARD_HAUPPAUGE_HVR1250:
311                 /* GPIO-0 cx24227 demodulator reset */
312                 cx_set(GP0_IO, 0x00010001); /* Bring the part out of reset */
313                 break;
314         case CX23885_BOARD_HAUPPAUGE_HVR1500:
315                 /* GPIO-0 cx24227 demodulator */
316                 /* GPIO-2 xc3028 tuner */
317
318                 /* Put the parts into reset */
319                 cx_set(GP0_IO, 0x00050000);
320                 cx_clear(GP0_IO, 0x00000005);
321                 msleep(5);
322
323                 /* Bring the parts out of reset */
324                 cx_set(GP0_IO, 0x00050005);
325                 break;
326         case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
327                 /* GPIO-0 cx24227 demodulator reset */
328                 /* GPIO-2 xc5000 tuner reset */
329                 cx_set(GP0_IO, 0x00050005); /* Bring the part out of reset */
330                 break;
331         case CX23885_BOARD_HAUPPAUGE_HVR1800:
332                 /* GPIO-0 656_CLK */
333                 /* GPIO-1 656_D0 */
334                 /* GPIO-2 8295A Reset */
335                 /* GPIO-3-10 cx23417 data0-7 */
336                 /* GPIO-11-14 cx23417 addr0-3 */
337                 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
338                 /* GPIO-19 IR_RX */
339
340                 /* CX23417 GPIO's */
341                 /* EIO15 Zilog Reset */
342                 /* EIO14 S5H1409/CX24227 Reset */
343
344                 /* Force the TDA8295A into reset and back */
345                 cx_set(GP0_IO, 0x00040004);
346                 mdelay(20);
347                 cx_clear(GP0_IO, 0x00000004);
348                 mdelay(20);
349                 cx_set(GP0_IO, 0x00040004);
350                 mdelay(20);
351                 break;
352         case CX23885_BOARD_HAUPPAUGE_HVR1200:
353                 /* GPIO-0 tda10048 demodulator reset */
354                 /* GPIO-2 tda18271 tuner reset */
355
356                 /* Put the parts into reset and back */
357                 cx_set(GP0_IO, 0x00050000);
358                 mdelay(20);
359                 cx_clear(GP0_IO, 0x00000005);
360                 mdelay(20);
361                 cx_set(GP0_IO, 0x00050005);
362                 break;
363         case CX23885_BOARD_HAUPPAUGE_HVR1700:
364                 /* GPIO-0 TDA10048 demodulator reset */
365                 /* GPIO-2 TDA8295A Reset */
366                 /* GPIO-3-10 cx23417 data0-7 */
367                 /* GPIO-11-14 cx23417 addr0-3 */
368                 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
369
370                 /* The following GPIO's are on the interna AVCore (cx25840) */
371                 /* GPIO-19 IR_RX */
372                 /* GPIO-20 IR_TX 416/DVBT Select */
373                 /* GPIO-21 IIS DAT */
374                 /* GPIO-22 IIS WCLK */
375                 /* GPIO-23 IIS BCLK */
376
377                 /* Put the parts into reset and back */
378                 cx_set(GP0_IO, 0x00050000);
379                 mdelay(20);
380                 cx_clear(GP0_IO, 0x00000005);
381                 mdelay(20);
382                 cx_set(GP0_IO, 0x00050005);
383                 break;
384         case CX23885_BOARD_HAUPPAUGE_HVR1400:
385                 /* GPIO-0  Dibcom7000p demodulator reset */
386                 /* GPIO-2  xc3028L tuner reset */
387                 /* GPIO-13 LED */
388
389                 /* Put the parts into reset and back */
390                 cx_set(GP0_IO, 0x00050000);
391                 mdelay(20);
392                 cx_clear(GP0_IO, 0x00000005);
393                 mdelay(20);
394                 cx_set(GP0_IO, 0x00050005);
395                 break;
396         }
397 }
398
399 int cx23885_ir_init(struct cx23885_dev *dev)
400 {
401         switch (dev->board) {
402         case CX23885_BOARD_HAUPPAUGE_HVR1250:
403         case CX23885_BOARD_HAUPPAUGE_HVR1500:
404         case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
405         case CX23885_BOARD_HAUPPAUGE_HVR1800:
406         case CX23885_BOARD_HAUPPAUGE_HVR1200:
407         case CX23885_BOARD_HAUPPAUGE_HVR1400:
408                 /* FIXME: Implement me */
409                 break;
410         }
411
412         return 0;
413 }
414
415 void cx23885_card_setup(struct cx23885_dev *dev)
416 {
417         struct cx23885_tsport *ts1 = &dev->ts1;
418         struct cx23885_tsport *ts2 = &dev->ts2;
419
420         static u8 eeprom[256];
421
422         if (dev->i2c_bus[0].i2c_rc == 0) {
423                 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
424                 tveeprom_read(&dev->i2c_bus[0].i2c_client,
425                               eeprom, sizeof(eeprom));
426         }
427
428         switch (dev->board) {
429         case CX23885_BOARD_HAUPPAUGE_HVR1250:
430         case CX23885_BOARD_HAUPPAUGE_HVR1500:
431         case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
432         case CX23885_BOARD_HAUPPAUGE_HVR1400:
433                 if (dev->i2c_bus[0].i2c_rc == 0)
434                         hauppauge_eeprom(dev, eeprom+0x80);
435                 break;
436         case CX23885_BOARD_HAUPPAUGE_HVR1800:
437         case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
438         case CX23885_BOARD_HAUPPAUGE_HVR1200:
439         case CX23885_BOARD_HAUPPAUGE_HVR1700:
440                 if (dev->i2c_bus[0].i2c_rc == 0)
441                         hauppauge_eeprom(dev, eeprom+0xc0);
442                 break;
443         }
444
445         switch (dev->board) {
446         case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
447                 ts1->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
448                 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
449                 ts1->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
450                 break;
451         case CX23885_BOARD_HAUPPAUGE_HVR1800:
452                 /* Defaults for VID B - Analog encoder */
453                 /* DREQ_POL, SMODE, PUNC_CLK, MCLK_POL Serial bus + punc clk */
454                 ts1->gen_ctrl_val    = 0x10e;
455                 ts1->ts_clk_en_val   = 0x1; /* Enable TS_CLK */
456                 ts1->src_sel_val     = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
457
458                 /* APB_TSVALERR_POL (active low)*/
459                 ts1->vld_misc_val    = 0x2000;
460                 ts1->hw_sop_ctrl_val = (0x47 << 16 | 188 << 4 | 0xc);
461
462                 /* Defaults for VID C */
463                 ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
464                 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
465                 ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
466                 break;
467         case CX23885_BOARD_HAUPPAUGE_HVR1250:
468         case CX23885_BOARD_HAUPPAUGE_HVR1500:
469         case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
470         case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
471         case CX23885_BOARD_HAUPPAUGE_HVR1200:
472         case CX23885_BOARD_HAUPPAUGE_HVR1700:
473         case CX23885_BOARD_HAUPPAUGE_HVR1400:
474         default:
475                 ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
476                 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
477                 ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
478         }
479
480         /* Certain boards support analog, or require the avcore to be
481          * loaded, ensure this happens.
482          */
483         switch (dev->board) {
484         case CX23885_BOARD_HAUPPAUGE_HVR1800:
485         case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
486         case CX23885_BOARD_HAUPPAUGE_HVR1700:
487                 request_module("cx25840");
488                 break;
489         }
490 }
491
492 /* ------------------------------------------------------------------ */
493
494 /*
495  * Local variables:
496  * c-basic-offset: 8
497  * End:
498  * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
499  */