xref: /openbmc/linux/drivers/media/pci/bt8xx/bttv-if.c (revision 7d545e77)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 
4     bttv-if.c  --  old gpio interface to other kernel modules
5 		   don't use in new code, will go away in 2.7
6 		   have a look at bttv-gpio.c instead.
7 
8     bttv - Bt848 frame grabber driver
9 
10     Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
11 			   & Marcus Metzler (mocm@thp.uni-koeln.de)
12     (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
13 
14 
15 */
16 
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/delay.h>
20 #include <asm/io.h>
21 
22 #include "bttvp.h"
23 
24 EXPORT_SYMBOL(bttv_get_pcidev);
25 EXPORT_SYMBOL(bttv_gpio_enable);
26 EXPORT_SYMBOL(bttv_read_gpio);
27 EXPORT_SYMBOL(bttv_write_gpio);
28 
29 /* ----------------------------------------------------------------------- */
30 /* Exported functions - for other modules which want to access the         */
31 /*                      gpio ports (IR for example)                        */
32 /*                      see bttv.h for comments                            */
33 
34 struct pci_dev* bttv_get_pcidev(unsigned int card)
35 {
36 	if (card >= bttv_num)
37 		return NULL;
38 	if (!bttvs[card])
39 		return NULL;
40 
41 	return bttvs[card]->c.pci;
42 }
43 
44 
45 int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data)
46 {
47 	struct bttv *btv;
48 
49 	if (card >= bttv_num) {
50 		return -EINVAL;
51 	}
52 
53 	btv = bttvs[card];
54 	if (!btv)
55 		return -ENODEV;
56 
57 	gpio_inout(mask,data);
58 	if (bttv_gpio)
59 		bttv_gpio_tracking(btv,"extern enable");
60 	return 0;
61 }
62 
63 int bttv_read_gpio(unsigned int card, unsigned long *data)
64 {
65 	struct bttv *btv;
66 
67 	if (card >= bttv_num) {
68 		return -EINVAL;
69 	}
70 
71 	btv = bttvs[card];
72 	if (!btv)
73 		return -ENODEV;
74 
75 	if(btv->shutdown) {
76 		return -ENODEV;
77 	}
78 
79 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
80    because we set direct input on init */
81 	*data = gpio_read();
82 	return 0;
83 }
84 
85 int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
86 {
87 	struct bttv *btv;
88 
89 	if (card >= bttv_num) {
90 		return -EINVAL;
91 	}
92 
93 	btv = bttvs[card];
94 	if (!btv)
95 		return -ENODEV;
96 
97 /* prior setting BT848_GPIO_REG_INP is (probably) not needed
98    because direct input is set on init */
99 	gpio_bits(mask,data);
100 	if (bttv_gpio)
101 		bttv_gpio_tracking(btv,"extern write");
102 	return 0;
103 }
104