[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / media / video / bttv-gpio.c
blob77320cdf205fc5e7d6fa03303b0c5b7644597540
1 /*
2 $Id: bttv-gpio.c,v 1.7 2005/02/16 12:14:10 kraxel Exp $
4 bttv-gpio.c -- gpio sub drivers
6 sysfs-based sub driver interface for bttv
7 mainly intented for gpio access
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>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/device.h>
34 #include <asm/io.h>
36 #include "bttvp.h"
38 /* ----------------------------------------------------------------------- */
39 /* internal: the bttv "bus" */
41 static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv)
43 struct bttv_sub_driver *sub = to_bttv_sub_drv(drv);
44 int len = strlen(sub->wanted);
46 if (0 == strncmp(dev->bus_id, sub->wanted, len))
47 return 1;
48 return 0;
51 struct bus_type bttv_sub_bus_type = {
52 .name = "bttv-sub",
53 .match = &bttv_sub_bus_match,
55 EXPORT_SYMBOL(bttv_sub_bus_type);
57 static void release_sub_device(struct device *dev)
59 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
60 kfree(sub);
63 int bttv_sub_add_device(struct bttv_core *core, char *name)
65 struct bttv_sub_device *sub;
66 int err;
68 sub = kmalloc(sizeof(*sub),GFP_KERNEL);
69 if (NULL == sub)
70 return -ENOMEM;
71 memset(sub,0,sizeof(*sub));
73 sub->core = core;
74 sub->dev.parent = &core->pci->dev;
75 sub->dev.bus = &bttv_sub_bus_type;
76 sub->dev.release = release_sub_device;
77 snprintf(sub->dev.bus_id,sizeof(sub->dev.bus_id),"%s%d",
78 name, core->nr);
80 err = device_register(&sub->dev);
81 if (0 != err) {
82 kfree(sub);
83 return err;
85 printk("bttv%d: add subdevice \"%s\"\n", core->nr, sub->dev.bus_id);
86 list_add_tail(&sub->list,&core->subs);
87 return 0;
90 int bttv_sub_del_devices(struct bttv_core *core)
92 struct bttv_sub_device *sub;
93 struct list_head *item,*save;
95 list_for_each_safe(item,save,&core->subs) {
96 sub = list_entry(item,struct bttv_sub_device,list);
97 list_del(&sub->list);
98 device_unregister(&sub->dev);
100 return 0;
103 void bttv_gpio_irq(struct bttv_core *core)
105 struct bttv_sub_driver *drv;
106 struct bttv_sub_device *dev;
107 struct list_head *item;
109 list_for_each(item,&core->subs) {
110 dev = list_entry(item,struct bttv_sub_device,list);
111 drv = to_bttv_sub_drv(dev->dev.driver);
112 if (drv && drv->gpio_irq)
113 drv->gpio_irq(dev);
117 /* ----------------------------------------------------------------------- */
118 /* external: sub-driver register/unregister */
120 int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted)
122 sub->drv.bus = &bttv_sub_bus_type;
123 snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted);
124 return driver_register(&sub->drv);
126 EXPORT_SYMBOL(bttv_sub_register);
128 int bttv_sub_unregister(struct bttv_sub_driver *sub)
130 driver_unregister(&sub->drv);
131 return 0;
133 EXPORT_SYMBOL(bttv_sub_unregister);
135 /* ----------------------------------------------------------------------- */
136 /* external: gpio access functions */
138 void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits)
140 struct bttv *btv = container_of(core, struct bttv, c);
141 unsigned long flags;
142 u32 data;
144 spin_lock_irqsave(&btv->gpio_lock,flags);
145 data = btread(BT848_GPIO_OUT_EN);
146 data = data & ~mask;
147 data = data | (mask & outbits);
148 btwrite(data,BT848_GPIO_OUT_EN);
149 spin_unlock_irqrestore(&btv->gpio_lock,flags);
151 EXPORT_SYMBOL(bttv_gpio_inout);
153 u32 bttv_gpio_read(struct bttv_core *core)
155 struct bttv *btv = container_of(core, struct bttv, c);
156 u32 value;
158 value = btread(BT848_GPIO_DATA);
159 return value;
161 EXPORT_SYMBOL(bttv_gpio_read);
163 void bttv_gpio_write(struct bttv_core *core, u32 value)
165 struct bttv *btv = container_of(core, struct bttv, c);
167 btwrite(value,BT848_GPIO_DATA);
169 EXPORT_SYMBOL(bttv_gpio_write);
171 void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
173 struct bttv *btv = container_of(core, struct bttv, c);
174 unsigned long flags;
175 u32 data;
177 spin_lock_irqsave(&btv->gpio_lock,flags);
178 data = btread(BT848_GPIO_DATA);
179 data = data & ~mask;
180 data = data | (mask & bits);
181 btwrite(data,BT848_GPIO_DATA);
182 spin_unlock_irqrestore(&btv->gpio_lock,flags);
184 EXPORT_SYMBOL(bttv_gpio_bits);
187 * Local variables:
188 * c-basic-offset: 8
189 * End: