Starting the process of seperating bridge-sensor for 6240
[microdia.git] / microdia-sysfs.c
blobf052b3f2d7e5e6c4a0365ecaf0ac1a2a5172d7fe
1 /**
2 * @file microdia-sysfs.c
3 * @author Nicolas VIVIEN
4 * @date 2008-02-01
5 * @version v0.0.0
7 * @brief Sysfs interface for image settings
9 * @note Copyright (C) Nicolas VIVIEN
11 * @par Licences
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 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/version.h>
32 #include <linux/errno.h>
33 #include <linux/slab.h>
34 #include <linux/kref.h>
35 #include <linux/device.h>
37 #include <linux/usb.h>
38 #include <media/v4l2-common.h>
40 #include "microdia.h"
41 #include "sn9c20x.h"
44 /**
45 * @brief show_release
47 * @param class Class device
49 * @retval buf Adress of buffer with the 'release' value
51 * @returns Size of buffer
53 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
54 static ssize_t show_release(struct class_device *class, char *buf)
55 #else
56 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
57 #endif
59 struct video_device *vdev = to_video_device(class);
60 struct usb_microdia *dev = video_get_drvdata(vdev);
62 return sprintf(buf, "%d\n", dev->release);
66 /**
67 * @brief show_videostatus
69 * @param class Class device
71 * @retval buf Adress of buffer with the 'videostatus' value
73 * @returns Size of buffer
75 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
76 static ssize_t show_videostatus(struct class_device *class, char *buf)
77 #else
78 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
79 #endif
81 struct video_device *vdev = to_video_device(class);
82 struct usb_microdia *dev = video_get_drvdata(vdev);
84 return sprintf(buf,
85 "Overflow frames : %d\n"
86 "Incomplete frames : %d\n"
87 "Dropped frames : %d\n",
88 dev->vframes_overflow,
89 dev->vframes_incomplete,
90 dev->vframes_dropped);
94 /**
95 * @brief show_informations
97 * @param class Class device
99 * @retval buf Adress of buffer with the 'informations' value
101 * @returns Size of buffer
103 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
104 static ssize_t show_informations(struct class_device *class, char *buf)
105 #else
106 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
107 #endif
109 char *pixelfmt = NULL;
111 struct video_device *vdev = to_video_device(class);
112 struct usb_microdia *dev = video_get_drvdata(vdev);
114 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
115 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
116 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
117 char *palette_i420 = "I420 - YUV 4:2:0 - 12 bits";
120 switch (dev->vsettings.format.pixelformat) {
121 case V4L2_PIX_FMT_BGR24:
122 pixelfmt = palette_bgr24;
123 break;
125 case V4L2_PIX_FMT_RGB24:
126 pixelfmt = palette_rgb24;
127 break;
129 case V4L2_PIX_FMT_YUYV:
130 pixelfmt = palette_yuyv;
131 break;
133 case V4L2_PIX_FMT_YUV420:
134 pixelfmt = palette_i420;
135 break;
138 return sprintf(buf,
139 "Driver Resolution : %dx%d\n"
140 "\n"
141 "%s\n"
142 "\n"
143 "Brightness : 0x%X\n"
144 "Contrast : 0x%X\n"
145 "Whiteness : 0x%X\n"
146 "Exposure : 0x%X\n"
147 "Sharpness : 0x%X\n"
148 "Horizontal flip : %d\n"
149 "Vertical flip : %d\n"
150 "Auto-exposure : %d\n"
151 "Auto-whitebalance : %d\n",
152 dev->vsettings.format.width,
153 dev->vsettings.format.height,
154 pixelfmt,
155 0xFFFF & dev->vsettings.brightness,
156 0xFFFF & dev->vsettings.contrast,
157 0xFFFF & dev->vsettings.whiteness,
158 0xFFFF & dev->vsettings.exposure,
159 0x3F & dev->vsettings.sharpness,
160 dev->vsettings.hflip,
161 dev->vsettings.vflip,
162 dev->vsettings.auto_exposure,
163 dev->vsettings.auto_whitebalance);
167 /**
168 * @brief show_fps
170 * @param class Class device
172 * @retval buf Adress of buffer with the 'fps' value
174 * @returns Size of buffer
176 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
177 static ssize_t show_fps(struct class_device *class, char *buf)
178 #else
179 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
180 #endif
182 struct video_device *vdev = to_video_device(class);
183 struct usb_microdia *dev = video_get_drvdata(vdev);
185 return sprintf(buf, "%d\n", dev->vsettings.fps);
189 * @brief show_rgb_gain
191 * @param class Class device
193 * @retval buf Address of buffer with the 'rgb_gain' value
195 * @returns Size of buffer
197 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
198 static ssize_t show_rgb_gain(struct class_device *class, char *buf)
199 #else
200 static ssize_t show_rgb_gain(struct device *class,
201 struct device_attribute *attr, char *buf)
202 #endif
204 int rgb_gain = 0;
206 struct video_device *vdev = to_video_device(class);
207 struct usb_microdia *dev = video_get_drvdata(vdev);
208 rgb_gain |= dev->vsettings.rgb_gain[0] << 16;
209 rgb_gain |= dev->vsettings.rgb_gain[1] << 8;
210 rgb_gain |= dev->vsettings.rgb_gain[3];
211 return sprintf(buf, "0x%06X\n", rgb_gain);
215 * @brief store_exposure
217 * @param class Class device
218 * @param buf Buffer
219 * @param count Counter
221 * @returns Size of buffer
223 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
224 static ssize_t store_rgb_gain(struct class_device *class,
225 const char *buf, size_t count)
226 #else
227 static ssize_t store_rgb_gain(struct device *class,
228 struct device_attribute *attr, const char *buf, size_t count)
229 #endif
231 char *endp;
232 unsigned long rgb_gain;
234 struct video_device *vdev = to_video_device(class);
235 struct usb_microdia *dev = video_get_drvdata(vdev);
237 rgb_gain = simple_strtoul(buf, &endp, 16);
239 dev->vsettings.rgb_gain[0] = (rgb_gain >> 16) & 0x7f;
240 dev->vsettings.rgb_gain[1] = (rgb_gain >> 8) & 0x7f;
241 dev->vsettings.rgb_gain[2] = (rgb_gain >> 8) & 0x7f;
242 dev->vsettings.rgb_gain[3] = rgb_gain & 0x7f;
244 dev_microdia_camera_set_rgb_gain(dev);
246 return strlen(buf);
249 /**
250 * @brief show_exposure
252 * @param class Class device
254 * @retval buf Adress of buffer with the 'exposure' value
256 * @returns Size of buffer
258 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
259 static ssize_t show_exposure(struct class_device *class, char *buf)
260 #else
261 static ssize_t show_exposure(struct device *class, struct device_attribute *attr, char *buf)
262 #endif
264 struct video_device *vdev = to_video_device(class);
265 struct usb_microdia *dev = video_get_drvdata(vdev);
267 return sprintf(buf, "%X\n", dev->vsettings.exposure);
271 * @brief store_exposure
273 * @param class Class device
274 * @param buf Buffer
275 * @param count Counter
277 * @returns Size of buffer
279 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
280 static ssize_t store_exposure(struct class_device *class, const char *buf, size_t count)
281 #else
282 static ssize_t store_exposure(struct device *class, struct device_attribute *attr,
283 const char *buf, size_t count)
284 #endif
286 char *endp;
287 unsigned long value;
289 struct video_device *vdev = to_video_device(class);
290 struct usb_microdia *dev = video_get_drvdata(vdev);
292 value = simple_strtoul(buf, &endp, 16);
294 dev->vsettings.exposure = (int) value;
296 dev_microdia_camera_set_exposure(dev);
298 return strlen(buf);
301 /**
302 * @brief show_brightness
304 * @param class Class device
306 * @retval buf Adress of buffer with the 'brightness' value
308 * @returns Size of buffer
310 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
311 static ssize_t show_brightness(struct class_device *class, char *buf)
312 #else
313 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
314 #endif
316 struct video_device *vdev = to_video_device(class);
317 struct usb_microdia *dev = video_get_drvdata(vdev);
319 return sprintf(buf, "%X\n", dev->vsettings.brightness);
322 /**
323 * @brief store_brightness
325 * @param class Class device
326 * @param buf Buffer
327 * @param count Counter
329 * @returns Size of buffer
331 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
332 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
333 #else
334 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
335 const char *buf, size_t count)
336 #endif
338 char *endp;
339 unsigned long value;
341 struct video_device *vdev = to_video_device(class);
342 struct usb_microdia *dev = video_get_drvdata(vdev);
344 value = simple_strtoul(buf, &endp, 16);
346 dev->vsettings.brightness = (int) value;
348 dev_microdia_camera_set_brightness(dev);
350 return strlen(buf);
353 /**
354 * @brief show_contrast
356 * @param class Class device
358 * @retval buf Adress of buffer with the 'contrast' value
360 * @returns Size of buffer
362 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
363 static ssize_t show_contrast(struct class_device *class, char *buf)
364 #else
365 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
366 #endif
368 struct video_device *vdev = to_video_device(class);
369 struct usb_microdia *dev = video_get_drvdata(vdev);
371 return sprintf(buf, "%X\n", dev->vsettings.contrast);
375 /**
376 * @brief store_contrast
378 * @param class Class device
379 * @param buf Buffer
380 * @param count Counter
382 * @returns Size of buffer
384 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
385 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
386 #else
387 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
388 const char *buf, size_t count)
389 #endif
391 char *endp;
392 unsigned long value;
394 struct video_device *vdev = to_video_device(class);
395 struct usb_microdia *dev = video_get_drvdata(vdev);
397 value = simple_strtoul(buf, &endp, 16);
399 dev->vsettings.contrast = (int) value;
401 dev_microdia_camera_set_contrast(dev);
402 // dev_microdia_set_camera_quality(dev);
404 return strlen(buf);
408 /**
409 * @brief show_whitebalance
411 * @param class Class device
413 * @retval buf Adress of buffer with the 'whitebalance' value
415 * @returns Size of buffer
417 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
418 static ssize_t show_whitebalance(struct class_device *class, char *buf)
419 #else
420 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
421 #endif
423 struct video_device *vdev = to_video_device(class);
424 struct usb_microdia *dev = video_get_drvdata(vdev);
426 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
430 /**
431 * @brief store_whitebalance
433 * @param class Class device
434 * @param buf Buffer
435 * @param count Counter
437 * @returns Size of buffer
439 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
440 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
441 #else
442 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
443 const char *buf, size_t count)
444 #endif
446 char *endp;
447 unsigned long value;
449 struct video_device *vdev = to_video_device(class);
450 struct usb_microdia *dev = video_get_drvdata(vdev);
452 value = simple_strtoul(buf, &endp, 16);
454 dev->vsettings.whiteness = (int) value;
456 dev_microdia_camera_set_gamma(dev);
457 // dev_microdia_set_camera_quality(dev);
459 return strlen(buf);
463 /**
464 * @brief show_colour
466 * @param class Class device
468 * @retval buf Adress of buffer with the 'colour' value
470 * @returns Size of buffer
472 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
473 static ssize_t show_colour(struct class_device *class, char *buf)
474 #else
475 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
476 #endif
478 struct video_device *vdev = to_video_device(class);
479 struct usb_microdia *dev = video_get_drvdata(vdev);
481 return sprintf(buf, "%X\n", dev->vsettings.colour);
485 /**
486 * @brief store_colour
488 * @param class Class device
489 * @param buf Buffer
490 * @param count Counter
492 * @returns Size of buffer
494 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
495 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
496 #else
497 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
498 const char *buf, size_t count)
499 #endif
501 char *endp;
502 unsigned long value;
504 struct video_device *vdev = to_video_device(class);
505 struct usb_microdia *dev = video_get_drvdata(vdev);
507 value = simple_strtoul(buf, &endp, 16);
509 dev->vsettings.colour = (int) value;
511 // dev_microdia_set_camera_quality(dev);
513 return strlen(buf);
518 /**
519 * @brief show_sharpness
521 * @param class Class device
523 * @retval buf Adress of buffer with the 'sharpness' value
525 * @returns Size of buffer
527 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
528 static ssize_t show_sharpness(struct class_device *class, char *buf)
529 #else
530 static ssize_t show_sharpness(struct device *class, struct device_attribute *attr, char *buf)
531 #endif
533 struct video_device *vdev = to_video_device(class);
534 struct usb_microdia *dev = video_get_drvdata(vdev);
536 return sprintf(buf, "%X\n", dev->vsettings.sharpness);
539 /**
540 * @brief store_sharpness
542 * @param class Class device
543 * @param buf Buffer
544 * @param count Counter
546 * @returns Size of buffer
548 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
549 static ssize_t store_sharpness(struct class_device *class, const char *buf, size_t count)
550 #else
551 static ssize_t store_sharpness(struct device *class, struct device_attribute *attr,
552 const char *buf, size_t count)
553 #endif
555 char *endp;
556 unsigned long value;
558 struct video_device *vdev = to_video_device(class);
559 struct usb_microdia *dev = video_get_drvdata(vdev);
561 value = simple_strtoul(buf, &endp, 16);
563 if (value < 0 || value > 0x3f)
564 return -EINVAL;
566 dev->vsettings.sharpness = (int) value;
568 dev_microdia_camera_set_sharpness(dev);
570 return strlen(buf);
574 /**
575 * @brief show_hflip
577 * @param class Class device
579 * @retval buf Adress of buffer with the 'hflip' value
581 * @returns Size of buffer
583 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
584 static ssize_t show_hflip(struct class_device *class, char *buf)
585 #else
586 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
587 #endif
589 struct video_device *vdev = to_video_device(class);
590 struct usb_microdia *dev = video_get_drvdata(vdev);
592 return sprintf(buf, "%d\n", dev->vsettings.hflip);
596 /**
597 * @brief store_hflip
599 * @param class Class device
600 * @param buf Buffer
601 * @param count Counter
603 * @returns Size of buffer
605 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
606 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
607 #else
608 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
609 const char *buf, size_t count)
610 #endif
612 struct video_device *vdev = to_video_device(class);
613 struct usb_microdia *dev = video_get_drvdata(vdev);
615 if (strncmp(buf, "1", 1) == 0)
616 dev->vsettings.hflip = 1;
617 else if (strncmp(buf, "0", 1) == 0)
618 dev->vsettings.hflip = 0;
619 else
620 return -EINVAL;
622 dev_microdia_camera_set_hvflip(dev);
624 return strlen(buf);
628 /**
629 * @brief show_vflip
631 * @param class Class device
633 * @retval buf Adress of buffer with the 'vflip' value
635 * @returns Size of buffer
637 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
638 static ssize_t show_vflip(struct class_device *class, char *buf)
639 #else
640 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
641 #endif
643 struct video_device *vdev = to_video_device(class);
644 struct usb_microdia *dev = video_get_drvdata(vdev);
646 return sprintf(buf, "%d\n", dev->vsettings.vflip);
650 /**
651 * @brief store_vflip
653 * @param class Class device
654 * @param buf Buffer
655 * @param count Counter
657 * @returns Size of buffer
659 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
660 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
661 #else
662 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
663 #endif
665 struct video_device *vdev = to_video_device(class);
666 struct usb_microdia *dev = video_get_drvdata(vdev);
668 if (strncmp(buf, "1", 1) == 0)
669 dev->vsettings.vflip = 1;
670 else if (strncmp(buf, "0", 1) == 0)
671 dev->vsettings.vflip = 0;
672 else
673 return -EINVAL;
675 dev_microdia_camera_set_hvflip(dev);
677 return strlen(buf);
681 /**
682 * @brief show_autoexposure
684 * @param class Class device
686 * @retval buf Adress of buffer with the 'hflip' value
688 * @returns Size of buffer
690 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
691 static ssize_t show_autoexposure(struct class_device *class, char *buf)
692 #else
693 static ssize_t show_autoexposure(struct device *class, struct device_attribute *attr, char *buf)
694 #endif
696 struct video_device *vdev = to_video_device(class);
697 struct usb_microdia *dev = video_get_drvdata(vdev);
699 return sprintf(buf, "%d\n", dev->vsettings.auto_exposure);
703 /**
704 * @brief store_autoexposure
706 * @param class Class device
707 * @param buf Buffer
708 * @param count Counter
710 * @returns Size of buffer
712 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
713 static ssize_t store_autoexposure(struct class_device *class, const char *buf, size_t count)
714 #else
715 static ssize_t store_autoexposure(struct device *class, struct device_attribute *attr,
716 const char *buf, size_t count)
717 #endif
719 struct video_device *vdev = to_video_device(class);
720 struct usb_microdia *dev = video_get_drvdata(vdev);
722 if (strncmp(buf, "1", 1) == 0)
723 dev->vsettings.auto_exposure = 1;
724 else if (strncmp(buf, "0", 1) == 0)
725 dev->vsettings.auto_exposure = 0;
726 else
727 return -EINVAL;
729 dev_microdia_camera_set_auto_exposure(dev);
731 return strlen(buf);
735 /**
736 * @brief show_autowhitebalance
738 * @param class Class device
740 * @retval buf Adress of buffer with the 'vflip' value
742 * @returns Size of buffer
744 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
745 static ssize_t show_autowhitebalance(struct class_device *class, char *buf)
746 #else
747 static ssize_t show_autowhitebalance(struct device *class, struct device_attribute *attr, char *buf)
748 #endif
750 struct video_device *vdev = to_video_device(class);
751 struct usb_microdia *dev = video_get_drvdata(vdev);
753 return sprintf(buf, "%d\n", dev->vsettings.auto_whitebalance);
757 /**
758 * @brief store_autowhitebalance
760 * @param class Class device
761 * @param buf Buffer
762 * @param count Counter
764 * @returns Size of buffer
766 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
767 static ssize_t store_autowhitebalance(struct class_device *class, const char *buf, size_t count)
768 #else
769 static ssize_t store_autowhitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
770 #endif
772 struct video_device *vdev = to_video_device(class);
773 struct usb_microdia *dev = video_get_drvdata(vdev);
775 if (strncmp(buf, "1", 1) == 0)
776 dev->vsettings.auto_whitebalance = 1;
777 else if (strncmp(buf, "0", 1) == 0)
778 dev->vsettings.auto_whitebalance = 0;
779 else
780 return -EINVAL;
782 dev_microdia_camera_set_auto_whitebalance(dev);
784 return strlen(buf);
787 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
788 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
789 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
790 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
791 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
792 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
793 static CLASS_DEVICE_ATTR(rgb_gain, S_IRUGO | S_IWUGO, show_rgb_gain, store_rgb_gain); /**< RGB Gain */
794 static CLASS_DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Brightness exposure */
795 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
796 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
797 static CLASS_DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
798 //static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
799 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
800 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
801 static CLASS_DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
802 static CLASS_DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
803 #else
804 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
805 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
806 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
807 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
808 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
809 static DEVICE_ATTR(rgb_gain, S_IRUGO | S_IWUGO, show_rgb_gain, store_rgb_gain); /**< RGB Gain */
810 static DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
811 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
812 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
813 static DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
814 //static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
815 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
816 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
817 static DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
818 static DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
819 #endif
822 /**
823 * @brief Create the 'sys' entries.
825 * This function permits to create all the entries in the 'sys' filesystem.
827 * @param vdev Video device structure
829 * @returns 0 if all is OK
831 int microdia_create_sysfs_files(struct video_device *vdev)
833 int ret;
835 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
836 ret = video_device_create_file(vdev, &class_device_attr_release);
837 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
838 ret = video_device_create_file(vdev, &class_device_attr_informations);
839 ret = video_device_create_file(vdev, &class_device_attr_fps);
840 ret = video_device_create_file(vdev, &class_device_attr_brightness);
841 ret = video_device_create_file(vdev, &class_device_attr_rgb_gain);
842 ret = video_device_create_file(vdev, &class_device_attr_exposure);
843 ret = video_device_create_file(vdev, &class_device_attr_contrast);
844 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
845 ret = video_device_create_file(vdev, &class_device_attr_sharpness);
846 /*ret = video_device_create_file(vdev, &class_device_attr_colour);*/
847 ret = video_device_create_file(vdev, &class_device_attr_hflip);
848 ret = video_device_create_file(vdev, &class_device_attr_vflip);
849 ret = video_device_create_file(vdev, &class_device_attr_auto_exposure);
850 ret = video_device_create_file(vdev, &class_device_attr_auto_whitebalance);
851 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
852 ret = video_device_create_file(vdev, &dev_attr_release);
853 ret = video_device_create_file(vdev, &dev_attr_videostatus);
854 ret = video_device_create_file(vdev, &dev_attr_informations);
855 ret = video_device_create_file(vdev, &dev_attr_fps);
856 ret = video_device_create_file(vdev, &dev_attr_brightness);
857 ret = video_device_create_file(vdev, &dev_attr_rgb_gain);
858 ret = video_device_create_file(vdev, &dev_attr_exposure);
859 ret = video_device_create_file(vdev, &dev_attr_contrast);
860 ret = video_device_create_file(vdev, &dev_attr_whitebalance);
861 ret = video_device_create_file(vdev, &dev_attr_sharpness);
862 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
863 ret = video_device_create_file(vdev, &dev_attr_hflip);
864 ret = video_device_create_file(vdev, &dev_attr_vflip);
865 ret = video_device_create_file(vdev, &dev_attr_auto_exposure);
866 ret = video_device_create_file(vdev, &dev_attr_auto_whitebalance);
867 #else
868 ret = device_create_file(&vdev->dev, &dev_attr_release);
869 ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
870 ret = device_create_file(&vdev->dev, &dev_attr_informations);
871 ret = device_create_file(&vdev->dev, &dev_attr_fps);
872 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
873 ret = device_create_file(&vdev->dev, &dev_attr_rgb_gain);
874 ret = device_create_file(&vdev->dev, &dev_attr_exposure);
875 ret = device_create_file(&vdev->dev, &dev_attr_contrast);
876 ret = device_create_file(&vdev->dev, &dev_attr_whitebalance);
877 ret = device_create_file(&vdev->dev, &dev_attr_sharpness);
878 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
879 ret = device_create_file(&vdev->dev, &dev_attr_hflip);
880 ret = device_create_file(&vdev->dev, &dev_attr_vflip);
881 ret = device_create_file(&vdev->dev, &dev_attr_auto_exposure);
882 ret = device_create_file(&vdev->dev, &dev_attr_auto_whitebalance);
883 #endif
884 return ret;
888 /**
889 * @brief Remove the 'sys' entries.
891 * This function permits to remove all the entries in the 'sys' filesystem.
893 * @param vdev Video device structure
895 * @returns 0 if all is OK
897 void microdia_remove_sysfs_files(struct video_device *vdev)
899 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
900 video_device_remove_file(vdev, &class_device_attr_release);
901 video_device_remove_file(vdev, &class_device_attr_videostatus);
902 video_device_remove_file(vdev, &class_device_attr_informations);
903 video_device_remove_file(vdev, &class_device_attr_fps);
904 video_device_remove_file(vdev, &class_device_attr_brightness);
905 video_device_remove_file(vdev, &class_device_attr_exposure);
906 video_device_remove_file(vdev, &class_device_attr_rgb_gain);
907 video_device_remove_file(vdev, &class_device_attr_contrast);
908 video_device_remove_file(vdev, &class_device_attr_whitebalance);
909 video_device_remove_file(vdev, &class_device_attr_sharpness);
910 /*video_device_remove_file(vdev, &class_device_attr_colour);*/
911 video_device_remove_file(vdev, &class_device_attr_hflip);
912 video_device_remove_file(vdev, &class_device_attr_vflip);
913 video_device_remove_file(vdev, &class_device_attr_auto_exposure);
914 video_device_remove_file(vdev, &class_device_attr_auto_whitebalance);
915 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
916 video_device_remove_file(vdev, &dev_attr_release);
917 video_device_remove_file(vdev, &dev_attr_videostatus);
918 video_device_remove_file(vdev, &dev_attr_informations);
919 video_device_remove_file(vdev, &dev_attr_fps);
920 video_device_remove_file(vdev, &dev_attr_brightness);
921 video_device_remove_file(vdev, &dev_attr_rgb_gain);
922 video_device_remove_file(vdev, &dev_attr_exposure);
923 video_device_remove_file(vdev, &dev_attr_contrast);
924 video_device_remove_file(vdev, &dev_attr_whitebalance);
925 video_device_remove_file(vdev, &dev_attr_sharpness);
926 /*video_device_remove_file(vdev, &dev_attr_colour);*/
927 video_device_remove_file(vdev, &dev_attr_hflip);
928 video_device_remove_file(vdev, &dev_attr_vflip);
929 video_device_remove_file(vdev, &dev_attr_auto_exposure);
930 video_device_remove_file(vdev, &dev_attr_auto_whitebalance);
931 #else
932 device_remove_file(&vdev->dev, &dev_attr_release);
933 device_remove_file(&vdev->dev, &dev_attr_videostatus);
934 device_remove_file(&vdev->dev, &dev_attr_informations);
935 device_remove_file(&vdev->dev, &dev_attr_fps);
936 device_remove_file(&vdev->dev, &dev_attr_brightness);
937 device_remove_file(&vdev->dev, &dev_attr_rgb_gain);
938 device_remove_file(&vdev->dev, &dev_attr_exposure);
939 device_remove_file(&vdev->dev, &dev_attr_contrast);
940 device_remove_file(&vdev->dev, &dev_attr_whitebalance);
941 device_remove_file(&vdev->dev, &dev_attr_sharpness);
942 /*video_device_remove_file(vdev, &dev_attr_colour);*/
943 device_remove_file(&vdev->dev, &dev_attr_hflip);
944 device_remove_file(&vdev->dev, &dev_attr_vflip);
945 device_remove_file(&vdev->dev, &dev_attr_auto_exposure);
946 device_remove_file(&vdev->dev, &dev_attr_auto_whitebalance);
947 #endif