ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / media / video / bttv-if.c
1 /*
2     bttv-if.c  --  old gpio interface to other kernel modules
3                    don't use in new code, will go away in 2.7
4                    have a look at bttv-gpio.c instead.
5
6     bttv - Bt848 frame grabber driver
7
8     Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
9                            & Marcus Metzler (mocm@thp.uni-koeln.de)
10     (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
11
12     This program is free software; you can redistribute it and/or modify
13     it under the terms of the GNU General Public License as published by
14     the Free Software Foundation; either version 2 of the License, or
15     (at your option) any later version.
16
17     This program is distributed in the hope that it will be useful,
18     but WITHOUT ANY WARRANTY; without even the implied warranty of
19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20     GNU General Public License for more details.
21
22     You should have received a copy of the GNU General Public License
23     along with this program; if not, write to the Free Software
24     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25     
26 */
27
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <asm/io.h>
32
33 #include "bttvp.h"
34
35 EXPORT_SYMBOL(bttv_get_cardinfo);
36 EXPORT_SYMBOL(bttv_get_pcidev);
37 EXPORT_SYMBOL(bttv_get_id);
38 EXPORT_SYMBOL(bttv_gpio_enable);
39 EXPORT_SYMBOL(bttv_read_gpio);
40 EXPORT_SYMBOL(bttv_write_gpio);
41 EXPORT_SYMBOL(bttv_get_gpio_queue);
42 EXPORT_SYMBOL(bttv_i2c_call);
43
44 /* ----------------------------------------------------------------------- */
45 /* Exported functions - for other modules which want to access the         */
46 /*                      gpio ports (IR for example)                        */
47 /*                      see bttv.h for comments                            */
48
49 int bttv_get_cardinfo(unsigned int card, int *type, unsigned *cardid)
50 {
51         if (card >= bttv_num) {
52                 return -1;
53         }
54         *type   = bttvs[card].c.type;
55         *cardid = bttvs[card].cardid;
56         return 0;
57 }
58
59 struct pci_dev* bttv_get_pcidev(unsigned int card)
60 {
61         if (card >= bttv_num)
62                 return NULL;
63         return bttvs[card].c.pci;
64 }
65
66 int bttv_get_id(unsigned int card)
67 {
68         printk("bttv_get_id is obsolete, use bttv_get_cardinfo instead\n");
69         if (card >= bttv_num) {
70                 return -1;
71         }
72         return bttvs[card].c.type;
73 }
74
75
76 int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
77 {
78         struct bttv *btv;
79
80         if (card >= bttv_num) {
81                 return -EINVAL;
82         }
83         
84         btv = &bttvs[card];
85         gpio_inout(mask,data);
86         if (bttv_gpio)
87                 bttv_gpio_tracking(btv,"extern enable");
88         return 0;
89 }
90
91 int bttv_read_gpio(unsigned int card, unsigned long *data)
92 {
93         struct bttv *btv;
94         
95         if (card >= bttv_num) {
96                 return -EINVAL;
97         }
98
99         btv = &bttvs[card];
100
101         if(btv->shutdown) {
102                 return -ENODEV;
103         }
104
105 /* prior setting BT848_GPIO_REG_INP is (probably) not needed 
106    because we set direct input on init */
107         *data = gpio_read();
108         return 0;
109 }
110
111 int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
112 {
113         struct bttv *btv;
114         
115         if (card >= bttv_num) {
116                 return -EINVAL;
117         }
118
119         btv = &bttvs[card];
120
121 /* prior setting BT848_GPIO_REG_INP is (probably) not needed 
122    because direct input is set on init */
123         gpio_bits(mask,data);
124         if (bttv_gpio)
125                 bttv_gpio_tracking(btv,"extern write");
126         return 0;
127 }
128
129 wait_queue_head_t* bttv_get_gpio_queue(unsigned int card)
130 {
131         struct bttv *btv;
132
133         if (card >= bttv_num) {
134                 return NULL;
135         }
136
137         btv = &bttvs[card];
138         if (bttvs[card].shutdown) {
139                 return NULL;
140         }
141         return &btv->gpioq;
142 }
143
144 /*
145  * Local variables:
146  * c-basic-offset: 8
147  * End:
148  */