ChangeSet 1.1276.22.24, 2003/08/22 15:42:39-07:00, greg@kroah.com [PATCH] USB: add sysfs files for stv680 driver, replacing the lost proc functionality. drivers/usb/media/stv680.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+) diff -Nru a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c --- a/drivers/usb/media/stv680.c Tue Sep 2 12:46:43 2003 +++ b/drivers/usb/media/stv680.c Tue Sep 2 12:46:43 2003 @@ -510,6 +510,57 @@ /***************** last of pencam routines *******************/ +/**************************************************************************** + * sysfs + ***************************************************************************/ +static inline struct usb_stv *cd_to_stv(struct class_device *cd) +{ + struct video_device *vdev = to_video_device(cd); + return video_get_drvdata(vdev); +} + +#define stv680_file(name, variable, field) \ +static ssize_t show_##name(struct class_device *class_dev, char *buf) \ +{ \ + struct video_device *vdev = to_video_device(class_dev); \ + struct usb_stv *stv = video_get_drvdata(vdev); \ + return sprintf(buf, field, stv->variable); \ +} \ +static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); + +stv680_file(model, camera_name, "%s\n"); +stv680_file(in_use, user, "%d\n"); +stv680_file(streaming, streaming, "%d\n"); +stv680_file(palette, palette, "%i\n"); +stv680_file(frames_total, readcount, "%d\n"); +stv680_file(frames_read, framecount, "%d\n"); +stv680_file(packets_dropped, dropped, "%d\n"); +stv680_file(decoding_errors, error, "%d\n"); + +static void stv680_create_sysfs_files(struct video_device *vdev) +{ + video_device_create_file(vdev, &class_device_attr_model); + video_device_create_file(vdev, &class_device_attr_in_use); + video_device_create_file(vdev, &class_device_attr_streaming); + video_device_create_file(vdev, &class_device_attr_palette); + video_device_create_file(vdev, &class_device_attr_frames_total); + video_device_create_file(vdev, &class_device_attr_frames_read); + video_device_create_file(vdev, &class_device_attr_packets_dropped); + video_device_create_file(vdev, &class_device_attr_decoding_errors); +} + +static void stv680_remove_sysfs_files(struct video_device *vdev) +{ + video_device_remove_file(vdev, &class_device_attr_model); + video_device_remove_file(vdev, &class_device_attr_in_use); + video_device_remove_file(vdev, &class_device_attr_streaming); + video_device_remove_file(vdev, &class_device_attr_palette); + video_device_remove_file(vdev, &class_device_attr_frames_total); + video_device_remove_file(vdev, &class_device_attr_frames_read); + video_device_remove_file(vdev, &class_device_attr_packets_dropped); + video_device_remove_file(vdev, &class_device_attr_decoding_errors); +} + /******************************************************************** * Camera control *******************************************************************/ @@ -1388,6 +1439,7 @@ PDEBUG (0, "STV(i): registered new video device: video%d", stv680->vdev->minor); usb_set_intfdata (intf, stv680); + stv680_create_sysfs_files(stv680->vdev); return 0; error: @@ -1432,6 +1484,7 @@ if (stv680) { /* We don't want people trying to open up the device */ if (stv680->vdev) { + stv680_remove_sysfs_files(stv680->vdev); video_unregister_device(stv680->vdev); stv680->vdev = NULL; }