Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2     $Id: bttv-gpio.c,v 1.6 2004/11/03 09:04:50 kraxel Exp $
  3 
  4     bttv-gpio.c  --  gpio sub drivers
  5 
  6     sysfs-based sub driver interface for bttv
  7     mainly intented for gpio access
  8 
  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     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.
 18 
 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.
 23 
 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.
 27 
 28 */
 29 
 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>
 35 
 36 #include "bttvp.h"
 37 
 38 /* ----------------------------------------------------------------------- */
 39 /* internal: the bttv "bus"                                                */
 40 
 41 static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv)
 42 {
 43         struct bttv_sub_driver *sub = to_bttv_sub_drv(drv);
 44         int len = strlen(sub->wanted);
 45 
 46         if (0 == strncmp(dev->bus_id, sub->wanted, len))
 47                 return 1;
 48         return 0;
 49 }
 50 
 51 struct bus_type bttv_sub_bus_type = {
 52         .name  = "bttv-sub",
 53         .match = &bttv_sub_bus_match,
 54 };
 55 EXPORT_SYMBOL(bttv_sub_bus_type);
 56 
 57 static void release_sub_device(struct device *dev)
 58 {
 59         struct bttv_sub_device *sub = to_bttv_sub_dev(dev);
 60         kfree(sub);
 61 }
 62 
 63 int bttv_sub_add_device(struct bttv_core *core, char *name)
 64 {
 65         struct bttv_sub_device *sub;
 66         int err;
 67 
 68         sub = kmalloc(sizeof(*sub),GFP_KERNEL);
 69         if (NULL == sub)
 70                 return -ENOMEM;
 71         memset(sub,0,sizeof(*sub));
 72 
 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);
 79 
 80         err = device_register(&sub->dev);
 81         if (0 != err) {
 82                 kfree(sub);
 83                 return err;
 84         }
 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;
 88 }
 89 
 90 int bttv_sub_del_devices(struct bttv_core *core)
 91 {
 92         struct bttv_sub_device *sub;
 93         struct list_head *item,*save;
 94 
 95         list_for_each_safe(item,save,&core->subs) {
 96                 sub = list_entry(item,struct bttv_sub_device,list);
 97                 device_unregister(&sub->dev);
 98         }
 99         return 0;
100 }
101 
102 void bttv_gpio_irq(struct bttv_core *core)
103 {
104         struct bttv_sub_driver *drv;
105         struct bttv_sub_device *dev;
106         struct list_head *item;
107 
108         list_for_each(item,&core->subs) {
109                 dev = list_entry(item,struct bttv_sub_device,list);
110                 drv = to_bttv_sub_drv(dev->dev.driver);
111                 if (drv && drv->gpio_irq)
112                         drv->gpio_irq(dev);
113         }
114 }
115 
116 void bttv_i2c_info(struct bttv_core *core, struct i2c_client *client, int attach)
117 {
118         struct bttv_sub_driver *drv;
119         struct bttv_sub_device *dev;
120         struct list_head *item;
121 
122         list_for_each(item,&core->subs) {
123                 dev = list_entry(item,struct bttv_sub_device,list);
124                 drv = to_bttv_sub_drv(dev->dev.driver);
125                 if (drv && drv->i2c_info)
126                         drv->i2c_info(dev,client,attach);
127         }
128 }
129 
130 /* ----------------------------------------------------------------------- */
131 /* external: sub-driver register/unregister                                */
132 
133 int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted)
134 {
135         sub->drv.bus = &bttv_sub_bus_type;
136         snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted);
137         return driver_register(&sub->drv);
138 }
139 EXPORT_SYMBOL(bttv_sub_register);
140 
141 int bttv_sub_unregister(struct bttv_sub_driver *sub)
142 {
143         driver_unregister(&sub->drv);
144         return 0;
145 }
146 EXPORT_SYMBOL(bttv_sub_unregister);
147 
148 /* ----------------------------------------------------------------------- */
149 /* external: gpio access functions                                         */
150 
151 void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits)
152 {
153         struct bttv *btv = container_of(core, struct bttv, c);
154         unsigned long flags;
155         u32 data;
156 
157         spin_lock_irqsave(&btv->gpio_lock,flags);
158         data = btread(BT848_GPIO_OUT_EN);
159         data = data & ~mask;
160         data = data | (mask & outbits);
161         btwrite(data,BT848_GPIO_OUT_EN);
162         spin_unlock_irqrestore(&btv->gpio_lock,flags);
163 }
164 EXPORT_SYMBOL(bttv_gpio_inout);
165 
166 u32 bttv_gpio_read(struct bttv_core *core)
167 {
168         struct bttv *btv = container_of(core, struct bttv, c);
169         u32 value;
170 
171         value = btread(BT848_GPIO_DATA);
172         return value;
173 }
174 EXPORT_SYMBOL(bttv_gpio_read);
175 
176 void bttv_gpio_write(struct bttv_core *core, u32 value)
177 {
178         struct bttv *btv = container_of(core, struct bttv, c);
179 
180         btwrite(value,BT848_GPIO_DATA);
181 }
182 EXPORT_SYMBOL(bttv_gpio_write);
183 
184 void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
185 {
186         struct bttv *btv = container_of(core, struct bttv, c);
187         unsigned long flags;
188         u32 data;
189 
190         spin_lock_irqsave(&btv->gpio_lock,flags);
191         data = btread(BT848_GPIO_DATA);
192         data = data & ~mask;
193         data = data | (mask & bits);
194         btwrite(data,BT848_GPIO_DATA);
195         spin_unlock_irqrestore(&btv->gpio_lock,flags);
196 }
197 EXPORT_SYMBOL(bttv_gpio_bits);
198 
199 /*
200  * Local variables:
201  * c-basic-offset: 8
202  * End:
203  */
204 
  This page was automatically generated by the LXR engine.