| Start/ | End/ | |||
| True | False | - | Line | Source |
| 1 | /* | |||
| 2 | ||||
| 3 | bttv-gpio.c -- gpio sub drivers | |||
| 4 | ||||
| 5 | sysfs-based sub driver interface for bttv | |||
| 6 | mainly intented for gpio access | |||
| 7 | ||||
| 8 | ||||
| 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> | |||
| 12 | ||||
| 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. | |||
| 17 | ||||
| 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. | |||
| 22 | ||||
| 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. | |||
| 26 | ||||
| 27 | */ | |||
| 28 | ||||
| 29 | #include <linux/module.h> | |||
| 30 | #include <linux/init.h> | |||
| 31 | #include <linux/delay.h> | |||
| 32 | #include <linux/device.h> | |||
| 33 | #include <asm/io.h> | |||
| 34 | ||||
| 35 | #include "bttvp.h" | |||
| 36 | ||||
| 37 | /* ----------------------------------------------------------------------- */ | |||
| 38 | /* internal: the bttv "bus" */ | |||
| 39 | ||||
| 0 | 0 | - | 40 | static int bttv_sub_bus_match(struct device *dev, struct device_driver *drv) |
| 41 | { | |||
| 42 | struct bttv_sub_driver *sub = to_bttv_sub_drv(drv); | |||
| 43 | int len = strlen(sub->wanted); | |||
| 44 | ||||
| 0 | 0 | - | 45 | if (0 == strncmp(dev->bus_id, sub->wanted, len)) |
| 0 | - | 46 | return 1; | |
| 0 | - | 47 | return 0; | |
| 48 | } | |||
| 49 | ||||
| 0 | 0 | - | 50 | static int bttv_sub_probe(struct device *dev) |
| 51 | { | |||
| 52 | struct bttv_sub_device *sdev = to_bttv_sub_dev(dev); | |||
| 53 | struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver); | |||
| 54 | ||||
| 55 | return sub->probe ? sub->probe(sdev) : -ENODEV; | |||
| 0 | 0 | - | 55 | ternary-?: sub -> probe |
| 0 | - | 55 | return sub -> probe ? sub -> probe ( sdev ) : .. | |
| 56 | } | |||
| 57 | ||||
| 0 | 0 | - | 58 | static int bttv_sub_remove(struct device *dev) |
| 59 | { | |||
| 60 | struct bttv_sub_device *sdev = to_bttv_sub_dev(dev); | |||
| 61 | struct bttv_sub_driver *sub = to_bttv_sub_drv(dev->driver); | |||
| 62 | ||||
| 0 | 0 | - | 63 | if (sub->remove) |
| 64 | sub->remove(sdev); | |||
| 0 | - | 65 | return 0; | |
| 66 | } | |||
| 67 | ||||
| 68 | struct bus_type bttv_sub_bus_type = { | |||
| 69 | .name = "bttv-sub", | |||
| 70 | .match = &bttv_sub_bus_match, | |||
| 71 | .probe = bttv_sub_probe, | |||
| 72 | .remove = bttv_sub_remove, | |||
| 73 | }; | |||
| 74 | EXPORT_SYMBOL(bttv_sub_bus_type); | |||
| 75 | ||||
| 0 | 0 | - | 76 | static void release_sub_device(struct device *dev) |
| 77 | { | |||
| 78 | struct bttv_sub_device *sub = to_bttv_sub_dev(dev); | |||
| 79 | kfree(sub); | |||
| 80 | } | |||
| 81 | ||||
| 0 | 0 | - | 82 | int bttv_sub_add_device(struct bttv_core *core, char *name) |
| 83 | { | |||
| 84 | struct bttv_sub_device *sub; | |||
| 85 | int err; | |||
| 86 | ||||
| 87 | sub = kzalloc(sizeof(*sub),GFP_KERNEL); | |||
| 0 | 0 | - | 88 | if (NULL == sub) |
| 0 | - | 89 | return -ENOMEM; | |
| 90 | ||||
| 91 | sub->core = core; | |||
| 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", | |||
| 96 | name, core->nr); | |||
| 97 | ||||
| 98 | err = device_register(&sub->dev); | |||
| 0 | 0 | - | 99 | if (0 != err) { |
| 100 | kfree(sub); | |||
| 0 | - | 101 | return err; | |
| 102 | } | |||
| 103 | printk("bttv%d: add subdevice \"%s\"\n", core->nr, sub->dev.bus_id); | |||
| 104 | list_add_tail(&sub->list,&core->subs); | |||
| 0 | - | 105 | return 0; | |
| 106 | } | |||
| 107 | ||||
| 0 | 0 | - | 108 | int bttv_sub_del_devices(struct bttv_core *core) |
| 109 | { | |||
| 110 | struct bttv_sub_device *sub; | |||
| 111 | struct list_head *item,*save; | |||
| 112 | ||||
| 0 | 0 | - | 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); | |||
| 117 | } | |||
| 0 | - | 118 | return 0; | |
| 119 | } | |||
| 120 | ||||
| 0 | 0 | - | 121 | void bttv_gpio_irq(struct bttv_core *core) |
| 122 | { | |||
| 123 | struct bttv_sub_driver *drv; | |||
| 124 | struct bttv_sub_device *dev; | |||
| 125 | struct list_head *item; | |||
| 126 | ||||
| 0 | 0 | - | 127 | list_for_each(item,&core->subs) { |
| 128 | dev = list_entry(item,struct bttv_sub_device,list); | |||
| 129 | drv = to_bttv_sub_drv(dev->dev.driver); | |||
| 0 | 0 | - | 130 | if (drv && drv->gpio_irq) |
| 0 | - | 130 | T && T | |
| 0 | - | 130 | T && F | |
| 0 | - | 130 | F && _ | |
| 131 | drv->gpio_irq(dev); | |||
| 132 | } | |||
| 133 | } | |||
| 134 | ||||
| 135 | /* ----------------------------------------------------------------------- */ | |||
| 136 | /* external: sub-driver register/unregister */ | |||
| 137 | ||||
| 0 | 0 | - | 138 | int bttv_sub_register(struct bttv_sub_driver *sub, char *wanted) |
| 139 | { | |||
| 140 | sub->drv.bus = &bttv_sub_bus_type; | |||
| 141 | snprintf(sub->wanted,sizeof(sub->wanted),"%s",wanted); | |||
| 0 | - | 142 | return driver_register(&sub->drv); | |
| 143 | } | |||
| 144 | EXPORT_SYMBOL(bttv_sub_register); | |||
| 145 | ||||
| 0 | 0 | - | 146 | int bttv_sub_unregister(struct bttv_sub_driver *sub) |
| 147 | { | |||
| 148 | driver_unregister(&sub->drv); | |||
| 0 | - | 149 | return 0; | |
| 150 | } | |||
| 151 | EXPORT_SYMBOL(bttv_sub_unregister); | |||
| 152 | ||||
| 153 | /* ----------------------------------------------------------------------- */ | |||
| 154 | /* external: gpio access functions */ | |||
| 155 | ||||
| 0 | 0 | - | 156 | void bttv_gpio_inout(struct bttv_core *core, u32 mask, u32 outbits) |
| 157 | { | |||
| 158 | struct bttv *btv = container_of(core, struct bttv, c); | |||
| 159 | unsigned long flags; | |||
| 160 | u32 data; | |||
| 161 | ||||
| 162 | spin_lock_irqsave(&btv->gpio_lock,flags); | |||
| 162 | do | |||
| 162 | do | |||
| 0 | 0 | - | 162 | do-while (0) |
| 0 | 0 | - | 162 | do-while (0) |
| 162 | do | |||
| 162 | do | |||
| 0 | 0 | - | 162 | do-while (0) |
| 0 | 0 | - | 162 | do-while (0) |
| 0 | 0 | - | 162 | do-while (0) |
| 163 | data = btread(BT848_GPIO_OUT_EN); | |||
| 164 | data = data & ~mask; | |||
| 165 | data = data | (mask & outbits); | |||
| 166 | btwrite(data,BT848_GPIO_OUT_EN); | |||
| 167 | spin_unlock_irqrestore(&btv->gpio_lock,flags); | |||
| 167 | do | |||
| 167 | do | |||
| 0 | 0 | - | 167 | do-while (0) |
| 0 | 0 | - | 167 | do-while (0) |
| 0 | 0 | - | 167 | do-while (0) |
| 168 | } | |||
| 169 | EXPORT_SYMBOL(bttv_gpio_inout); | |||
| 170 | ||||
| 0 | 0 | - | 171 | u32 bttv_gpio_read(struct bttv_core *core) |
| 172 | { | |||
| 173 | struct bttv *btv = container_of(core, struct bttv, c); | |||
| 174 | u32 value; | |||
| 175 | ||||
| 176 | value = btread(BT848_GPIO_DATA); | |||
| 0 | - | 177 | return value; | |
| 178 | } | |||
| 179 | EXPORT_SYMBOL(bttv_gpio_read); | |||
| 180 | ||||
| 0 | 0 | - | 181 | void bttv_gpio_write(struct bttv_core *core, u32 value) |
| 182 | { | |||
| 183 | struct bttv *btv = container_of(core, struct bttv, c); | |||
| 184 | ||||
| 185 | btwrite(value,BT848_GPIO_DATA); | |||
| 186 | } | |||
| 187 | EXPORT_SYMBOL(bttv_gpio_write); | |||
| 188 | ||||
| 0 | 0 | - | 189 | void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits) |
| 190 | { | |||
| 191 | struct bttv *btv = container_of(core, struct bttv, c); | |||
| 192 | unsigned long flags; | |||
| 193 | u32 data; | |||
| 194 | ||||
| 195 | spin_lock_irqsave(&btv->gpio_lock,flags); | |||
| 195 | do | |||
| 195 | do | |||
| 0 | 0 | - | 195 | do-while (0) |
| 0 | 0 | - | 195 | do-while (0) |
| 195 | do | |||
| 195 | do | |||
| 0 | 0 | - | 195 | do-while (0) |
| 0 | 0 | - | 195 | do-while (0) |
| 0 | 0 | - | 195 | do-while (0) |
| 196 | data = btread(BT848_GPIO_DATA); | |||
| 197 | data = data & ~mask; | |||
| 198 | data = data | (mask & bits); | |||
| 199 | btwrite(data,BT848_GPIO_DATA); | |||
| 200 | spin_unlock_irqrestore(&btv->gpio_lock,flags); | |||
| 200 | do | |||
| 200 | do | |||
| 0 | 0 | - | 200 | do-while (0) |
| 0 | 0 | - | 200 | do-while (0) |
| 0 | 0 | - | 200 | do-while (0) |
| 201 | } | |||
| 202 | EXPORT_SYMBOL(bttv_gpio_bits); | |||
| 203 | ||||
| 204 | /* | |||
| 205 | * Local variables: | |||
| 206 | * c-basic-offset: 8 | |||
| 207 | * End: | |||
| 208 | */ | |||
| ***TER 0% (0/75) of SOURCE FILE bttv-gpio.c | ||||