1 diff -Nur --exclude='*.orig' linux-2.6.0-test1.org/drivers/media/video/bttv-cards.c linux-2.6.0-test1/drivers/media/video/bttv-cards.c
2 --- linux-2.6.0-test1.org/drivers/media/video/bttv-cards.c Mon Jul 14 03:34:03 2003
3 +++ linux-2.6.0-test1/drivers/media/video/bttv-cards.c Tue Jul 22 09:01:24 2003
5 btv->type=card[btv->nr];
7 /* print which card config we are using */
8 - sprintf(btv->video_dev.name,"BT%d%s(%.23s)",
10 - (btv->id==848 && btv->revision==0x12) ? "A" : "",
11 - bttv_tvcards[btv->type].name);
12 printk(KERN_INFO "bttv%d: using: %s [card=%d,%s]\n",btv->nr,
13 - btv->video_dev.name,btv->type,
14 + bttv_tvcards[btv->type].name, btv->type,
15 (card[btv->nr] >= 0 && card[btv->nr] < bttv_num_tvcards) ?
16 "insmod option" : "autodetected");
18 diff -Nur --exclude='*.orig' linux-2.6.0-test1.org/drivers/media/video/bttv-driver.c linux-2.6.0-test1/drivers/media/video/bttv-driver.c
19 --- linux-2.6.0-test1.org/drivers/media/video/bttv-driver.c Mon Jul 14 03:36:43 2003
20 +++ linux-2.6.0-test1/drivers/media/video/bttv-driver.c Tue Jul 22 09:02:57 2003
22 #include <linux/sched.h>
23 #include <linux/interrupt.h>
24 #include <linux/kdev_t.h>
25 +#include <linux/device.h>
32 /* ----------------------------------------------------------------------- */
35 +static ssize_t show_card(struct class_device *cd, char *buf)
37 + struct video_device *vfd = to_video_device(cd);
38 + struct bttv *btv = dev_get_drvdata(vfd->dev);
39 + return sprintf(buf, "%d\n", btv ? btv->type : UNSET);
41 +static CLASS_DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
43 +/* ----------------------------------------------------------------------- */
46 /* special timing tables from conexant... */
48 struct video_capability *cap = arg;
50 memset(cap,0,sizeof(*cap));
51 - strcpy(cap->name,btv->video_dev.name);
52 + strcpy(cap->name,btv->video_dev->name);
53 if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) {
55 cap->type = VID_TYPE_TUNER|VID_TYPE_TELETEXT;
59 strcpy(cap->driver,"bttv");
60 - strlcpy(cap->card,btv->video_dev.name,sizeof(cap->card));
61 + strlcpy(cap->card,btv->video_dev->name,sizeof(cap->card));
62 sprintf(cap->bus_info,"PCI:%s",btv->dev->slot_name);
63 cap->version = BTTV_VERSION_CODE;
65 @@ -2683,12 +2695,12 @@
66 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
68 for (i = 0; i < bttv_num; i++) {
69 - if (bttvs[i].video_dev.minor == minor) {
70 + if (bttvs[i].video_dev->minor == minor) {
72 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
75 - if (bttvs[i].vbi_dev.minor == minor) {
76 + if (bttvs[i].vbi_dev->minor == minor) {
78 type = V4L2_BUF_TYPE_VBI_CAPTURE;
81 static struct video_device bttv_video_template =
84 - type: VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY|
85 - VID_TYPE_CLIPPING|VID_TYPE_SCALES,
86 + .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_OVERLAY|
87 + VID_TYPE_CLIPPING|VID_TYPE_SCALES,
88 .hardware = VID_HARDWARE_BT848,
92 dprintk("bttv: open minor=%d\n",minor);
94 for (i = 0; i < bttv_num; i++) {
95 - if (bttvs[i].radio_dev.minor == minor) {
96 + if (bttvs[i].radio_dev->minor == minor) {
100 @@ -2860,7 +2872,7 @@
101 struct video_capability *cap = arg;
103 memset(cap,0,sizeof(*cap));
104 - strcpy(cap->name,btv->radio_dev.name);
105 + strcpy(cap->name,btv->radio_dev->name);
106 cap->type = VID_TYPE_TUNER;
109 @@ -3239,30 +3251,83 @@
110 /* ----------------------------------------------------------------------- */
113 +static struct video_device *vdev_init(struct bttv *btv,
114 + struct video_device *template,
117 + struct video_device *vfd;
119 + vfd = video_device_alloc();
124 + vfd->release = video_device_release;
125 + vfd->dev = &btv->dev->dev;
126 + snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
127 + btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
128 + type, bttv_tvcards[btv->type].name);
132 /* register video4linux devices */
133 static int __devinit bttv_register_video(struct bttv *btv)
135 - if(video_register_device(&btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0)
138 + btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
139 + if (NULL == btv->video_dev)
141 + if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0)
143 printk(KERN_INFO "bttv%d: registered device video%d\n",
144 - btv->nr,btv->video_dev.minor & 0x1f);
145 + btv->nr,btv->video_dev->minor & 0x1f);
146 + video_device_create_file(btv->video_dev, &class_device_attr_card);
148 - if(video_register_device(&btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0) {
149 - video_unregister_device(&btv->video_dev);
153 + btv->vbi_dev = vdev_init(btv, &bttv_vbi_template, "vbi");
154 + if (NULL == btv->vbi_dev)
156 + if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0)
158 printk(KERN_INFO "bttv%d: registered device vbi%d\n",
159 - btv->nr,btv->vbi_dev.minor & 0x1f);
160 + btv->nr,btv->vbi_dev->minor & 0x1f);
164 - if (video_register_device(&btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0) {
165 - video_unregister_device(&btv->vbi_dev);
166 - video_unregister_device(&btv->video_dev);
170 + btv->radio_dev = vdev_init(btv, &radio_template, "radio");
171 + if (NULL == btv->radio_dev)
173 + if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0)
175 printk(KERN_INFO "bttv%d: registered device radio%d\n",
176 - btv->nr,btv->radio_dev.minor & 0x1f);
177 + btv->nr,btv->radio_dev->minor & 0x1f);
183 + if (btv->video_dev) {
184 + if (-1 != btv->video_dev->minor)
185 + video_unregister_device(btv->video_dev);
187 + video_device_release(btv->video_dev);
188 + btv->video_dev = NULL;
190 + if (btv->vbi_dev) {
191 + if (-1 != btv->vbi_dev->minor)
192 + video_unregister_device(btv->vbi_dev);
194 + video_device_release(btv->vbi_dev);
195 + btv->vbi_dev = NULL;
197 + if (btv->radio_dev) {
198 + if (-1 != btv->radio_dev->minor)
199 + video_unregister_device(btv->radio_dev);
201 + video_device_release(btv->radio_dev);
202 + btv->radio_dev = NULL;
207 @@ -3310,15 +3375,6 @@
209 btv->tuner_type = -1;
211 - memcpy(&btv->video_dev, &bttv_video_template, sizeof(bttv_video_template));
212 - memcpy(&btv->radio_dev, &radio_template, sizeof(radio_template));
213 - memcpy(&btv->vbi_dev, &bttv_vbi_template, sizeof(bttv_vbi_template));
214 - btv->video_dev.minor = -1;
215 - btv->video_dev.priv = btv;
216 - btv->radio_dev.minor = -1;
217 - btv->radio_dev.priv = btv;
218 - btv->vbi_dev.minor = -1;
219 - btv->vbi_dev.priv = btv;
220 btv->has_radio=radio[btv->nr];
222 /* pci stuff (init, get irq/mmip, ... */
223 @@ -3477,12 +3533,18 @@
224 i2c_bit_del_bus(&btv->i2c_adap);
226 /* unregister video4linux */
227 - if (btv->video_dev.minor!=-1)
228 - video_unregister_device(&btv->video_dev);
229 - if (btv->radio_dev.minor!=-1)
230 - video_unregister_device(&btv->radio_dev);
231 - if (btv->vbi_dev.minor!=-1)
232 - video_unregister_device(&btv->vbi_dev);
233 + if (btv->video_dev) {
234 + video_unregister_device(btv->video_dev);
235 + btv->video_dev = NULL;
237 + if (btv->radio_dev) {
238 + video_unregister_device(btv->radio_dev);
239 + btv->radio_dev = NULL;
241 + if (btv->vbi_dev) {
242 + video_unregister_device(btv->vbi_dev);
243 + btv->vbi_dev = NULL;
246 /* free allocated memory */
247 bttv_riscmem_free(btv->dev,&btv->main);
248 diff -Nur --exclude='*.orig' linux-2.6.0-test1.org/drivers/media/video/bttvp.h linux-2.6.0-test1/drivers/media/video/bttvp.h
249 --- linux-2.6.0-test1.org/drivers/media/video/bttvp.h Mon Jul 14 03:32:44 2003
250 +++ linux-2.6.0-test1/drivers/media/video/bttvp.h Tue Jul 22 08:57:59 2003
252 int i2c_state, i2c_rc;
254 /* video4linux (1) */
255 - struct video_device video_dev;
256 - struct video_device radio_dev;
257 - struct video_device vbi_dev;
258 + struct video_device *video_dev;
259 + struct video_device *radio_dev;
260 + struct video_device *vbi_dev;
264 diff -Nur --exclude='*.orig' linux-2.6.0-test1.org/drivers/media/video/videodev.c linux-2.6.0-test1/drivers/media/video/videodev.c
265 --- linux-2.6.0-test1.org/drivers/media/video/videodev.c Mon Jul 14 03:30:42 2003
266 +++ linux-2.6.0-test1/drivers/media/video/videodev.c Tue Jul 22 08:57:54 2003
268 * - Added procfs support
271 -#include <linux/config.h>
272 #include <linux/version.h>
273 #include <linux/module.h>
274 #include <linux/types.h>
276 #include <linux/init.h>
277 #include <linux/kmod.h>
278 #include <linux/slab.h>
279 +#include <linux/types.h>
280 #include <linux/devfs_fs_kernel.h>
281 #include <asm/uaccess.h>
282 #include <asm/system.h>
285 #include <linux/videodev.h>
287 -#define VIDEO_NUM_DEVICES 256
288 +#define VIDEO_NUM_DEVICES 256
289 +#define VIDEO_NAME "video4linux"
296 -static struct video_device *video_device[VIDEO_NUM_DEVICES];
297 -static DECLARE_MUTEX(videodev_lock);
299 +static ssize_t show_name(struct class_device *cd, char *buf)
301 + struct video_device *vfd = to_video_device(cd);
302 + return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
305 +static ssize_t show_dev(struct class_device *cd, char *buf)
307 + struct video_device *vfd = to_video_device(cd);
308 + dev_t dev = MKDEV(VIDEO_MAJOR, vfd->minor);
309 + return sprintf(buf,"%04x\n",(int)dev);
312 -#ifdef CONFIG_VIDEO_PROC_FS
313 +static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
314 +static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
316 -#include <linux/proc_fs.h>
317 +struct video_device *video_device_alloc(void)
319 + struct video_device *vfd;
321 -struct videodev_proc_data {
322 - struct list_head proc_list;
324 - struct video_device *vdev;
325 - struct proc_dir_entry *proc_entry;
327 + vfd = kmalloc(sizeof(*vfd),GFP_KERNEL);
330 + memset(vfd,0,sizeof(*vfd));
334 +void video_device_release(struct video_device *vfd)
339 +static void video_release(struct class_device *cd)
341 + struct video_device *vfd = container_of(cd, struct video_device, class_dev);
343 -static struct proc_dir_entry *video_dev_proc_entry = NULL;
344 -struct proc_dir_entry *video_proc_entry = NULL;
345 -EXPORT_SYMBOL(video_proc_entry);
346 -LIST_HEAD(videodev_proc_list);
347 +#if 1 /* needed until all drivers are fixed */
354 -#endif /* CONFIG_VIDEO_PROC_FS */
355 +static struct class video_class = {
356 + .name = VIDEO_NAME,
357 + .release = video_release,
364 +static struct video_device *video_device[VIDEO_NUM_DEVICES];
365 +static DECLARE_MUTEX(videodev_lock);
367 struct video_device* video_devdata(struct file *file)
369 @@ -192,156 +226,6 @@
377 -#ifdef CONFIG_VIDEO_PROC_FS
379 -/* Hmm... i'd like to see video_capability information here, but
380 - * how can I access it (without changing the other drivers? -claudio
382 -static int videodev_proc_read(char *page, char **start, off_t off,
383 - int count, int *eof, void *data)
386 - struct video_device *vfd = data;
387 - struct videodev_proc_data *d;
388 - struct list_head *tmp;
392 - list_for_each (tmp, &videodev_proc_list) {
393 - d = list_entry(tmp, struct videodev_proc_data, proc_list);
394 - if (vfd == d->vdev)
399 - if (tmp == &videodev_proc_list)
402 -#define PRINT_VID_TYPE(x) do { if (vfd->type & x) \
403 - out += sprintf (out, "%c%s", c, #x); c='|';} while (0)
405 - out += sprintf (out, "name : %s\n", vfd->name);
406 - out += sprintf (out, "type :");
407 - PRINT_VID_TYPE(VID_TYPE_CAPTURE);
408 - PRINT_VID_TYPE(VID_TYPE_TUNER);
409 - PRINT_VID_TYPE(VID_TYPE_TELETEXT);
410 - PRINT_VID_TYPE(VID_TYPE_OVERLAY);
411 - PRINT_VID_TYPE(VID_TYPE_CHROMAKEY);
412 - PRINT_VID_TYPE(VID_TYPE_CLIPPING);
413 - PRINT_VID_TYPE(VID_TYPE_FRAMERAM);
414 - PRINT_VID_TYPE(VID_TYPE_SCALES);
415 - PRINT_VID_TYPE(VID_TYPE_MONOCHROME);
416 - PRINT_VID_TYPE(VID_TYPE_SUBCAPTURE);
417 - PRINT_VID_TYPE(VID_TYPE_MPEG_DECODER);
418 - PRINT_VID_TYPE(VID_TYPE_MPEG_ENCODER);
419 - PRINT_VID_TYPE(VID_TYPE_MJPEG_DECODER);
420 - PRINT_VID_TYPE(VID_TYPE_MJPEG_ENCODER);
421 - out += sprintf (out, "\n");
422 - out += sprintf (out, "hardware : 0x%x\n", vfd->hardware);
424 - out += sprintf (out, "channels : %d\n", d->vcap.channels);
425 - out += sprintf (out, "audios : %d\n", d->vcap.audios);
426 - out += sprintf (out, "maxwidth : %d\n", d->vcap.maxwidth);
427 - out += sprintf (out, "maxheight : %d\n", d->vcap.maxheight);
428 - out += sprintf (out, "minwidth : %d\n", d->vcap.minwidth);
429 - out += sprintf (out, "minheight : %d\n", d->vcap.minheight);
442 - *start = page + off;
447 -static void videodev_proc_create(void)
449 - video_proc_entry = create_proc_entry("video", S_IFDIR, &proc_root);
451 - if (video_proc_entry == NULL) {
452 - printk("video_dev: unable to initialise /proc/video\n");
456 - video_proc_entry->owner = THIS_MODULE;
457 - video_dev_proc_entry = create_proc_entry("dev", S_IFDIR, video_proc_entry);
459 - if (video_dev_proc_entry == NULL) {
460 - printk("video_dev: unable to initialise /proc/video/dev\n");
464 - video_dev_proc_entry->owner = THIS_MODULE;
467 -static void __exit videodev_proc_destroy(void)
469 - if (video_dev_proc_entry != NULL)
470 - remove_proc_entry("dev", video_proc_entry);
472 - if (video_proc_entry != NULL)
473 - remove_proc_entry("video", &proc_root);
476 -static void videodev_proc_create_dev (struct video_device *vfd, char *name)
478 - struct videodev_proc_data *d;
479 - struct proc_dir_entry *p;
481 - if (video_dev_proc_entry == NULL)
484 - d = kmalloc (sizeof (struct videodev_proc_data), GFP_KERNEL);
488 - p = create_proc_entry(name, S_IFREG|S_IRUGO|S_IWUSR, video_dev_proc_entry);
494 - p->read_proc = videodev_proc_read;
498 - strcpy (d->name, name);
500 - /* How can I get capability information ? */
502 - list_add (&d->proc_list, &videodev_proc_list);
505 -static void videodev_proc_destroy_dev (struct video_device *vfd)
507 - struct list_head *tmp;
508 - struct videodev_proc_data *d;
510 - list_for_each (tmp, &videodev_proc_list) {
511 - d = list_entry(tmp, struct videodev_proc_data, proc_list);
512 - if (vfd == d->vdev) {
513 - remove_proc_entry(d->name, video_dev_proc_entry);
514 - list_del (&d->proc_list);
521 -#endif /* CONFIG_VIDEO_PROC_FS */
523 extern struct file_operations video_fops;
526 @@ -429,15 +313,23 @@
527 devfs_mk_cdev(MKDEV(VIDEO_MAJOR, vfd->minor),
528 S_IFCHR | S_IRUSR | S_IWUSR, vfd->devfs_name);
529 init_MUTEX(&vfd->lock);
531 -#ifdef CONFIG_VIDEO_PROC_FS
534 - sprintf(name, "%s%d", name_base, i - base);
535 - videodev_proc_create_dev(vfd, name);
540 + memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
542 + vfd->class_dev.dev = vfd->dev;
543 + vfd->class_dev.class = &video_class;
544 + strlcpy(vfd->class_dev.class_id, vfd->devfs_name + 4, BUS_ID_SIZE);
545 + class_device_register(&vfd->class_dev);
546 + video_device_create_file(vfd, &class_device_attr_name);
547 + video_device_create_file(vfd, &class_device_attr_dev);
549 +#if 1 /* needed until all drivers are fixed */
551 + printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
552 + "Please fix your driver for proper sysfs support, see "
553 + "http://lwn.net/Articles/36850/\n", vfd->name);
559 if(video_device[vfd->minor]!=vfd)
560 panic("videodev: bad unregister");
562 -#ifdef CONFIG_VIDEO_PROC_FS
563 - videodev_proc_destroy_dev (vfd);
566 + class_device_unregister(&vfd->class_dev);
567 devfs_remove(vfd->devfs_name);
568 video_device[vfd->minor]=NULL;
570 @@ -479,24 +368,18 @@
571 static int __init videodev_init(void)
573 printk(KERN_INFO "Linux video capture interface: v1.00\n");
574 - if (register_chrdev(VIDEO_MAJOR,"video_capture", &video_fops)) {
575 + if (register_chrdev(VIDEO_MAJOR,VIDEO_NAME, &video_fops)) {
576 printk("video_dev: unable to get major %d\n", VIDEO_MAJOR);
580 -#ifdef CONFIG_VIDEO_PROC_FS
581 - videodev_proc_create ();
584 + class_register(&video_class);
588 static void __exit videodev_exit(void)
590 -#ifdef CONFIG_VIDEO_PROC_FS
591 - videodev_proc_destroy ();
593 - unregister_chrdev(VIDEO_MAJOR, "video_capture");
594 + class_unregister(&video_class);
595 + unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
598 module_init(videodev_init)
600 EXPORT_SYMBOL(video_usercopy);
601 EXPORT_SYMBOL(video_exclusive_open);
602 EXPORT_SYMBOL(video_exclusive_release);
603 +EXPORT_SYMBOL(video_device_alloc);
604 +EXPORT_SYMBOL(video_device_release);
606 MODULE_AUTHOR("Alan Cox");
607 MODULE_DESCRIPTION("Device registrar for Video4Linux drivers");
608 diff -Nur --exclude='*.orig' linux-2.6.0-test1.org/include/linux/videodev.h linux-2.6.0-test1/include/linux/videodev.h
609 --- linux-2.6.0-test1.org/include/linux/videodev.h Mon Jul 14 03:39:37 2003
610 +++ linux-2.6.0-test1/include/linux/videodev.h Tue Jul 22 08:57:54 2003
613 #include <linux/types.h>
614 #include <linux/version.h>
615 +#include <linux/device.h>
619 - * v4l2 is still work-in-progress, integration planed for 2.5.x
620 - * documentation: http://bytesex.org/v4l/
621 - * patches available from: http://bytesex.org/patches/
623 -# define HAVE_V4L2 1
624 -# include <linux/videodev2.h>
629 +#include <linux/videodev2.h>
637 - struct module *owner;
639 + struct device *dev;
642 int type2; /* v4l2 */
646 - /* new interface -- we will use file_operations directly
647 - * like soundcore does. */
648 + /* device ops + callbacks */
649 struct file_operations *fops;
650 - void *priv; /* Used to be 'private' but that upsets C++ */
651 + void (*release)(struct video_device *vfd);
653 - /* for videodev.c intenal usage -- don't touch */
655 - struct semaphore lock;
656 - char devfs_name[64]; /* devfs */
657 +#if 1 /* to be removed in 2.7.x */
658 + /* obsolete -- fops->owner is used instead */
659 + struct module *owner;
660 + /* dev->driver_data will be used instead some day.
661 + * Use the video_{get|set}_drvdata() helper functions,
662 + * so the switch over will be transparent for you.
663 + * Or use {pci|usb|dev}_{get|set}_drvdata() directly. */
667 + /* for videodev.c intenal usage -- please don't touch */
668 + int users; /* video_exclusive_{open|close} ... */
669 + struct semaphore lock; /* ... helper function uses these */
670 + char devfs_name[64]; /* devfs */
671 + struct class_device class_dev; /* sysfs */
674 #define VIDEO_MAJOR 81
675 -extern int video_register_device(struct video_device *, int type, int nr);
677 #define VFL_TYPE_GRABBER 0
678 #define VFL_TYPE_VBI 1
679 #define VFL_TYPE_RADIO 2
680 #define VFL_TYPE_VTX 3
682 +extern int video_register_device(struct video_device *, int type, int nr);
683 extern void video_unregister_device(struct video_device *);
684 extern struct video_device* video_devdata(struct file*);
686 +#define to_video_device(cd) container_of(cd, struct video_device, class_dev)
688 +video_device_create_file(struct video_device *vfd,
689 + struct class_device_attribute *attr)
691 + class_device_create_file(&vfd->class_dev, attr);
694 +/* helper functions to alloc / release struct video_device, the
695 + later can be used for video_device->release() */
696 +struct video_device *video_device_alloc(void);
697 +void video_device_release(struct video_device *vfd);
699 +/* helper functions to access driver private data. */
700 +static inline void *video_get_drvdata(struct video_device *dev)
705 +static inline void video_set_drvdata(struct video_device *dev, void *data)
710 extern int video_exclusive_open(struct inode *inode, struct file *file);
711 extern int video_exclusive_release(struct inode *inode, struct file *file);
712 extern int video_usercopy(struct inode *inode, struct file *file,