3 bttv-gpio.c -- gpio sub drivers
5 sysfs-based sub driver interface for bttv
6 mainly intented for gpio access
9 Copyright (C) 1996,97,98 Ralph Metzler (rjkm@thp.uni-koeln.de)
10 & Marcus Metzler (mocm@thp.uni-koeln.de)
11 (c) 1999-2003 Gerd Knorr <kraxel@bytesex.org>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/delay.h>
32 #include <linux/device.h>
37 /* ----------------------------------------------------------------------- */
38 /* internal: the bttv "bus" */
40 static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv)
42 struct bttv_sub_driver *sub = to_bttv_sub_drv(drv);
43 int len = strlen(sub->wanted);
45 if (0 == strncmp(dev->bus_id, sub->wanted, len))
50 static int bttv_sub_probe(struct device *dev)
52 struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
53 struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
55 return sub->probe ? sub->probe(sdev) : -ENODEV;
58 static int bttv_sub_remove(struct device *dev)
60 struct bttv_sub_device *sdev = to_bttv_sub_dev(dev);
61 struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver);
68 struct bus_type bttv_sub_bus_type = {
70 .match = &bttv_sub_bus_match,
71 .probe = bttv_sub_probe,
72 .remove = bttv_sub_remove,
74 EXPORT_SYMBOL(bttv_sub_bus_type);
76 static void release_sub_device(struct device *dev)
78 struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
82 int bttv_sub_add_device(struct bttv_core *core, char *name)
84 struct bttv_sub_device *sub;
87 sub = kzalloc(sizeof(*sub),GFP_KERNEL);
92 sub->dev.parent = &core->pci->dev;
93 sub->dev.bus = &bttv_sub_bus_type;
94 sub->dev.release = release_sub_device;
95 snprintf(sub->dev.bus_id,sizeof(sub->dev.bus_id),"%s%d",
98 err = device_register(&sub->dev);
103 printk("bttv%d: add subdevice \"%s\"\n", core->nr, sub->dev.bus_id);
104 list_add_tail(&sub->list,&core->subs);
108 int bttv_sub_del_devices(struct bttv_core *core)
110 struct bttv_sub_device *sub;
111 struct list_head *item,*save;
113 list_for_each_safe(item,save,&core->subs) {
114 sub = list_entry(item,struct bttv_sub_device,list);
115 list_del(&sub->list);
116 device_unregister(&sub->dev);
121 /* ----------------------------------------------------------------------- */
122 /* external: sub-driver register/unregister */
124 int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted)
126 sub->drv.bus = &bttv_sub_bus_type;
127 snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted);
128 return driver_register(&sub->drv);
130 EXPORT_SYMBOL(bttv_sub_register);
132 int bttv_sub_unregister(struct bttv_sub_driver *sub)
134 driver_unregister(&sub->drv);
137 EXPORT_SYMBOL(bttv_sub_unregister);
139 /* ----------------------------------------------------------------------- */
140 /* external: gpio access functions */
142 void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits)
144 struct bttv *btv = container_of(core, struct bttv, c);
148 spin_lock_irqsave(&btv->gpio_lock,flags);
149 data = btread(BT848_GPIO_OUT_EN);
151 data = data | (mask & outbits);
152 btwrite(data,BT848_GPIO_OUT_EN);
153 spin_unlock_irqrestore(&btv->gpio_lock,flags);
155 EXPORT_SYMBOL(bttv_gpio_inout);
157 u32 bttv_gpio_read(struct bttv_core *core)
159 struct bttv *btv = container_of(core, struct bttv, c);
162 value = btread(BT848_GPIO_DATA);
165 EXPORT_SYMBOL(bttv_gpio_read);
167 void bttv_gpio_write(struct bttv_core *core, u32 value)
169 struct bttv *btv = container_of(core, struct bttv, c);
171 btwrite(value,BT848_GPIO_DATA);
173 EXPORT_SYMBOL(bttv_gpio_write);
175 void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
177 struct bttv *btv = container_of(core, struct bttv, c);
181 spin_lock_irqsave(&btv->gpio_lock,flags);
182 data = btread(BT848_GPIO_DATA);
184 data = data | (mask & bits);
185 btwrite(data,BT848_GPIO_DATA);
186 spin_unlock_irqrestore(&btv->gpio_lock,flags);
188 EXPORT_SYMBOL(bttv_gpio_bits);