Stop sensor_init from being executed twice
[microdia.git] / microdia-sysfs.c
blob7ac07fca6ed17eea7c2410c3f33260625be753a6
1 /**
2 * @file microdia-sysfs.c
3 * @author Nicolas VIVIEN
4 * @date 2008-02-01
6 * @brief Sysfs interface for image settings
8 * @note Copyright (C) Nicolas VIVIEN
10 * @par Licences
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/kernel.h>
30 #include <linux/version.h>
31 #include <linux/errno.h>
32 #include <linux/slab.h>
33 #include <linux/kref.h>
34 #include <linux/device.h>
36 #include <linux/usb.h>
37 #include <media/v4l2-common.h>
39 #include "microdia.h"
40 #include "sn9c20x.h"
43 /**
44 * @brief show_release
46 * @param class Class device
47 * @param attr
48 * @retval buf Adress of buffer with the 'release' value
50 * @returns Size of buffer
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
53 static ssize_t show_release(struct class_device *class, char *buf)
54 #else
55 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
56 #endif
58 struct video_device *vdev = to_video_device(class);
59 struct usb_microdia *dev = video_get_drvdata(vdev);
61 return sprintf(buf, "%d\n", dev->release);
65 /**
66 * @brief show_videostatus
68 * @param class Class device
69 * @param attr
70 * @retval buf Adress of buffer with the 'videostatus' value
72 * @returns Size of buffer
74 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
75 static ssize_t show_videostatus(struct class_device *class, char *buf)
76 #else
77 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
78 #endif
80 struct video_device *vdev = to_video_device(class);
81 struct usb_microdia *dev = video_get_drvdata(vdev);
83 return sprintf(buf,
84 "Overflow frames : %d\n"
85 "Incomplete frames : %d\n"
86 "Dropped frames : %d\n",
87 dev->vframes_overflow,
88 dev->vframes_incomplete,
89 dev->vframes_dropped);
93 /**
94 * @brief show_informations
96 * @param class Class device
97 * @param attr
98 * @retval buf Adress of buffer with the 'informations' value
100 * @returns Size of buffer
102 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
103 static ssize_t show_informations(struct class_device *class, char *buf)
104 #else
105 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
106 #endif
108 char *pixelfmt = NULL;
110 struct video_device *vdev = to_video_device(class);
111 struct usb_microdia *dev = video_get_drvdata(vdev);
113 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
114 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
115 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
116 char *palette_i420 = "I420 - YUV 4:2:0 - 12 bits";
119 switch (dev->vsettings.format.pixelformat) {
120 case V4L2_PIX_FMT_BGR24:
121 pixelfmt = palette_bgr24;
122 break;
124 case V4L2_PIX_FMT_RGB24:
125 pixelfmt = palette_rgb24;
126 break;
128 case V4L2_PIX_FMT_YUYV:
129 pixelfmt = palette_yuyv;
130 break;
132 case V4L2_PIX_FMT_YUV420:
133 pixelfmt = palette_i420;
134 break;
137 return sprintf(buf,
138 "Driver Resolution : %dx%d\n"
139 "\n"
140 "%s\n"
141 "\n"
142 "Brightness : 0x%X\n"
143 "Contrast : 0x%X\n"
144 "Whiteness : 0x%X\n"
145 "Exposure : 0x%X\n"
146 "Sharpness : 0x%X\n"
147 "Horizontal flip : %d\n"
148 "Vertical flip : %d\n"
149 "Auto-exposure : %d\n"
150 "Auto-whitebalance : %d\n",
151 dev->vsettings.format.width,
152 dev->vsettings.format.height,
153 pixelfmt,
154 0xFFFF & dev->vsettings.brightness,
155 0xFFFF & dev->vsettings.contrast,
156 0xFFFF & dev->vsettings.whiteness,
157 0xFFFF & dev->vsettings.exposure,
158 0x3F & dev->vsettings.sharpness,
159 dev->vsettings.hflip,
160 dev->vsettings.vflip,
161 dev->vsettings.auto_exposure,
162 dev->vsettings.auto_whitebalance);
167 * @brief show_fps
169 * @param class Class device
170 * @param attr
171 * @retval buf Adress of buffer with the 'fps' value
173 * @returns Size of buffer
175 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
176 static ssize_t show_fps(struct class_device *class, char *buf)
177 #else
178 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
179 #endif
181 struct video_device *vdev = to_video_device(class);
182 struct usb_microdia *dev = video_get_drvdata(vdev);
184 return sprintf(buf, "%d\n", dev->vsettings.fps);
188 * @brief show_rgb_gain
190 * @param class Class device
191 * @param attr
192 * @retval buf Address of buffer with the 'rgb_gain' value
194 * @returns Size of buffer
196 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
197 static ssize_t show_rgb_gain(struct class_device *class, char *buf)
198 #else
199 static ssize_t show_rgb_gain(struct device *class,
200 struct device_attribute *attr, char *buf)
201 #endif
203 int rgb_gain = 0;
205 struct video_device *vdev = to_video_device(class);
206 struct usb_microdia *dev = video_get_drvdata(vdev);
207 rgb_gain |= dev->vsettings.rgb_gain[0] << 16;
208 rgb_gain |= dev->vsettings.rgb_gain[1] << 8;
209 rgb_gain |= dev->vsettings.rgb_gain[3];
210 return sprintf(buf, "0x%06X\n", rgb_gain);
214 * @brief store_exposure
216 * @param class Class device
217 * @param buf Buffer
218 * @param count Counter
219 * @param attr
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);
250 * @brief show_exposure
252 * @param class Class device
253 * @param attr
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
276 * @param attr
278 * @returns Size of buffer
280 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
281 static ssize_t store_exposure(struct class_device *class, const char *buf, size_t count)
282 #else
283 static ssize_t store_exposure(struct device *class, struct device_attribute *attr,
284 const char *buf, size_t count)
285 #endif
287 char *endp;
288 unsigned long value;
290 struct video_device *vdev = to_video_device(class);
291 struct usb_microdia *dev = video_get_drvdata(vdev);
293 value = simple_strtoul(buf, &endp, 16);
295 dev->vsettings.exposure = (int) value;
297 dev_microdia_camera_set_exposure(dev);
299 return strlen(buf);
303 * @brief show_brightness
305 * @param class Class device
306 * @param attr
307 * @retval buf Adress of buffer with the 'brightness' value
309 * @returns Size of buffer
311 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
312 static ssize_t show_brightness(struct class_device *class, char *buf)
313 #else
314 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
315 #endif
317 struct video_device *vdev = to_video_device(class);
318 struct usb_microdia *dev = video_get_drvdata(vdev);
320 return sprintf(buf, "%X\n", dev->vsettings.brightness);
324 * @brief store_brightness
326 * @param class Class device
327 * @param buf Buffer
328 * @param count Counter
329 * @param attr
331 * @returns Size of buffer
333 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
334 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
335 #else
336 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
337 const char *buf, size_t count)
338 #endif
340 char *endp;
341 unsigned long value;
343 struct video_device *vdev = to_video_device(class);
344 struct usb_microdia *dev = video_get_drvdata(vdev);
346 value = simple_strtoul(buf, &endp, 16);
348 dev->vsettings.brightness = (int) value;
350 dev_microdia_camera_set_brightness(dev);
352 return strlen(buf);
356 * @brief show_contrast
358 * @param class Class device
359 * @param attr
360 * @retval buf Adress of buffer with the 'contrast' value
362 * @returns Size of buffer
364 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
365 static ssize_t show_contrast(struct class_device *class, char *buf)
366 #else
367 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
368 #endif
370 struct video_device *vdev = to_video_device(class);
371 struct usb_microdia *dev = video_get_drvdata(vdev);
373 return sprintf(buf, "%X\n", dev->vsettings.contrast);
378 * @brief store_contrast
380 * @param class Class device
381 * @param buf Buffer
382 * @param count Counter
383 * @param attr
385 * @returns Size of buffer
387 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
388 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
389 #else
390 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
391 const char *buf, size_t count)
392 #endif
394 char *endp;
395 unsigned long value;
397 struct video_device *vdev = to_video_device(class);
398 struct usb_microdia *dev = video_get_drvdata(vdev);
400 value = simple_strtoul(buf, &endp, 16);
402 dev->vsettings.contrast = (int) value;
404 dev_microdia_camera_set_contrast(dev);
405 /* dev_microdia_set_camera_quality(dev); */
407 return strlen(buf);
412 * @brief show_whitebalance
414 * @param class Class device
415 * @param attr
416 * @retval buf Adress of buffer with the 'whitebalance' value
418 * @returns Size of buffer
420 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
421 static ssize_t show_whitebalance(struct class_device *class, char *buf)
422 #else
423 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
424 #endif
426 struct video_device *vdev = to_video_device(class);
427 struct usb_microdia *dev = video_get_drvdata(vdev);
429 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
434 * @brief store_whitebalance
436 * @param class Class device
437 * @param buf Buffer
438 * @param count Counter
439 * @param attr
441 * @returns Size of buffer
443 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
444 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
445 #else
446 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
447 const char *buf, size_t count)
448 #endif
450 char *endp;
451 unsigned long value;
453 struct video_device *vdev = to_video_device(class);
454 struct usb_microdia *dev = video_get_drvdata(vdev);
456 value = simple_strtoul(buf, &endp, 16);
458 dev->vsettings.whiteness = (int) value;
460 dev_microdia_camera_set_gamma(dev);
461 /* dev_microdia_set_camera_quality(dev); */
463 return strlen(buf);
468 * @brief show_colour
470 * @param class Class device
471 * @param attr
472 * @retval buf Adress of buffer with the 'colour' value
474 * @returns Size of buffer
476 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
477 static ssize_t show_colour(struct class_device *class, char *buf)
478 #else
479 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
480 #endif
482 struct video_device *vdev = to_video_device(class);
483 struct usb_microdia *dev = video_get_drvdata(vdev);
485 return sprintf(buf, "%X\n", dev->vsettings.colour);
490 * @brief store_colour
492 * @param class Class device
493 * @param buf Buffer
494 * @param count Counter
495 * @param attr
497 * @returns Size of buffer
499 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
500 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
501 #else
502 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
503 const char *buf, size_t count)
504 #endif
506 char *endp;
507 unsigned long value;
509 struct video_device *vdev = to_video_device(class);
510 struct usb_microdia *dev = video_get_drvdata(vdev);
512 value = simple_strtoul(buf, &endp, 16);
514 dev->vsettings.colour = (int) value;
516 / dev_microdia_set_camera_quality(dev); /
518 return strlen(buf);
524 * @brief show_sharpness
526 * @param class Class device
527 * @param attr
528 * @retval buf Adress of buffer with the 'sharpness' value
530 * @returns Size of buffer
532 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
533 static ssize_t show_sharpness(struct class_device *class, char *buf)
534 #else
535 static ssize_t show_sharpness(struct device *class, struct device_attribute *attr, char *buf)
536 #endif
538 struct video_device *vdev = to_video_device(class);
539 struct usb_microdia *dev = video_get_drvdata(vdev);
541 return sprintf(buf, "%X\n", dev->vsettings.sharpness);
545 * @brief store_sharpness
547 * @param class Class device
548 * @param buf Buffer
549 * @param count Counter
550 * @param attr
552 * @returns Size of buffer
554 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
555 static ssize_t store_sharpness(struct class_device *class, const char *buf, size_t count)
556 #else
557 static ssize_t store_sharpness(struct device *class, struct device_attribute *attr,
558 const char *buf, size_t count)
559 #endif
561 char *endp;
562 unsigned long value;
564 struct video_device *vdev = to_video_device(class);
565 struct usb_microdia *dev = video_get_drvdata(vdev);
567 value = simple_strtoul(buf, &endp, 16);
569 if (value < 0 || value > 0x3f)
570 return -EINVAL;
572 dev->vsettings.sharpness = (int) value;
574 dev_microdia_camera_set_sharpness(dev);
576 return strlen(buf);
581 * @brief show_hflip
583 * @param class Class device
584 * @param attr
585 * @retval buf Adress of buffer with the 'hflip' value
587 * @returns Size of buffer
589 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
590 static ssize_t show_hflip(struct class_device *class, char *buf)
591 #else
592 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
593 #endif
595 struct video_device *vdev = to_video_device(class);
596 struct usb_microdia *dev = video_get_drvdata(vdev);
598 return sprintf(buf, "%d\n", dev->vsettings.hflip);
603 * @brief store_hflip
605 * @param class Class device
606 * @param buf Buffer
607 * @param count Counter
608 * @param attr
610 * @returns Size of buffer
612 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
613 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
614 #else
615 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
616 const char *buf, size_t count)
617 #endif
619 struct video_device *vdev = to_video_device(class);
620 struct usb_microdia *dev = video_get_drvdata(vdev);
622 if (strncmp(buf, "1", 1) == 0)
623 dev->vsettings.hflip = 1;
624 else if (strncmp(buf, "0", 1) == 0)
625 dev->vsettings.hflip = 0;
626 else
627 return -EINVAL;
629 dev_microdia_camera_set_hvflip(dev);
631 return strlen(buf);
636 * @brief show_vflip
638 * @param class Class device
639 * @param attr
640 * @retval buf Adress of buffer with the 'vflip' value
642 * @returns Size of buffer
644 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
645 static ssize_t show_vflip(struct class_device *class, char *buf)
646 #else
647 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
648 #endif
650 struct video_device *vdev = to_video_device(class);
651 struct usb_microdia *dev = video_get_drvdata(vdev);
653 return sprintf(buf, "%d\n", dev->vsettings.vflip);
658 * @brief store_vflip
660 * @param class Class device
661 * @param buf Buffer
662 * @param count Counter
663 * @param attr
665 * @returns Size of buffer
667 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
668 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
669 #else
670 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
671 #endif
673 struct video_device *vdev = to_video_device(class);
674 struct usb_microdia *dev = video_get_drvdata(vdev);
676 if (strncmp(buf, "1", 1) == 0)
677 dev->vsettings.vflip = 1;
678 else if (strncmp(buf, "0", 1) == 0)
679 dev->vsettings.vflip = 0;
680 else
681 return -EINVAL;
683 dev_microdia_camera_set_hvflip(dev);
685 return strlen(buf);
690 * @brief show_autoexposure
692 * @param class Class device
693 * @param attr
694 * @retval buf Adress of buffer with the 'hflip' value
696 * @returns Size of buffer
698 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
699 static ssize_t show_autoexposure(struct class_device *class, char *buf)
700 #else
701 static ssize_t show_autoexposure(struct device *class, struct device_attribute *attr, char *buf)
702 #endif
704 struct video_device *vdev = to_video_device(class);
705 struct usb_microdia *dev = video_get_drvdata(vdev);
707 return sprintf(buf, "%d\n", dev->vsettings.auto_exposure);
712 * @brief store_autoexposure
714 * @param class Class device
715 * @param buf Buffer
716 * @param count Counter
717 * @param attr
719 * @returns Size of buffer
721 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
722 static ssize_t store_autoexposure(struct class_device *class, const char *buf, size_t count)
723 #else
724 static ssize_t store_autoexposure(struct device *class, struct device_attribute *attr,
725 const char *buf, size_t count)
726 #endif
728 struct video_device *vdev = to_video_device(class);
729 struct usb_microdia *dev = video_get_drvdata(vdev);
731 if (strncmp(buf, "1", 1) == 0)
732 dev->vsettings.auto_exposure = 1;
733 else if (strncmp(buf, "0", 1) == 0)
734 dev->vsettings.auto_exposure = 0;
735 else
736 return -EINVAL;
738 dev_microdia_camera_set_auto_exposure(dev);
740 return strlen(buf);
745 * @brief show_autowhitebalance
747 * @param class Class device
748 * @param attr
749 * @retval buf Adress of buffer with the 'vflip' value
751 * @returns Size of buffer
753 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
754 static ssize_t show_autowhitebalance(struct class_device *class, char *buf)
755 #else
756 static ssize_t show_autowhitebalance(struct device *class, struct device_attribute *attr, char *buf)
757 #endif
759 struct video_device *vdev = to_video_device(class);
760 struct usb_microdia *dev = video_get_drvdata(vdev);
762 return sprintf(buf, "%d\n", dev->vsettings.auto_whitebalance);
767 * @brief store_autowhitebalance
769 * @param class Class device
770 * @param buf Buffer
771 * @param count Counter
772 * @param attr
774 * @returns Size of buffer
776 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
777 static ssize_t store_autowhitebalance(struct class_device *class, const char *buf, size_t count)
778 #else
779 static ssize_t store_autowhitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
780 #endif
782 struct video_device *vdev = to_video_device(class);
783 struct usb_microdia *dev = video_get_drvdata(vdev);
785 if (strncmp(buf, "1", 1) == 0)
786 dev->vsettings.auto_whitebalance = 1;
787 else if (strncmp(buf, "0", 1) == 0)
788 dev->vsettings.auto_whitebalance = 0;
789 else
790 return -EINVAL;
792 dev_microdia_camera_set_auto_whitebalance(dev);
794 return strlen(buf);
797 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
798 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
799 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
800 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
801 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
802 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
803 static CLASS_DEVICE_ATTR(rgb_gain, S_IRUGO | S_IWUGO, show_rgb_gain, store_rgb_gain); /**< RGB Gain */
804 static CLASS_DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Brightness exposure */
805 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
806 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
807 static CLASS_DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
808 /*static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /< Hue value */
809 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
810 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
811 static CLASS_DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
812 static CLASS_DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
813 #else
814 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
815 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
816 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
817 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
818 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
819 static DEVICE_ATTR(rgb_gain, S_IRUGO | S_IWUGO, show_rgb_gain, store_rgb_gain); /**< RGB Gain */
820 static DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
821 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
822 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
823 static DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
824 /*static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /< Hue value */
825 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
826 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
827 static DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
828 static DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
829 #endif
833 * @brief Create the 'sys' entries.
835 * This function permits to create all the entries in the 'sys' filesystem.
837 * @param vdev Video device structure
839 * @returns 0 if all is OK
841 int microdia_create_sysfs_files(struct video_device *vdev)
843 int ret;
845 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
846 ret = video_device_create_file(vdev, &class_device_attr_release);
847 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
848 ret = video_device_create_file(vdev, &class_device_attr_informations);
849 ret = video_device_create_file(vdev, &class_device_attr_fps);
850 ret = video_device_create_file(vdev, &class_device_attr_brightness);
851 ret = video_device_create_file(vdev, &class_device_attr_rgb_gain);
852 ret = video_device_create_file(vdev, &class_device_attr_exposure);
853 ret = video_device_create_file(vdev, &class_device_attr_contrast);
854 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
855 ret = video_device_create_file(vdev, &class_device_attr_sharpness);
856 /*ret = video_device_create_file(vdev, &class_device_attr_colour);*/
857 ret = video_device_create_file(vdev, &class_device_attr_hflip);
858 ret = video_device_create_file(vdev, &class_device_attr_vflip);
859 ret = video_device_create_file(vdev, &class_device_attr_auto_exposure);
860 ret = video_device_create_file(vdev, &class_device_attr_auto_whitebalance);
861 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
862 ret = video_device_create_file(vdev, &dev_attr_release);
863 ret = video_device_create_file(vdev, &dev_attr_videostatus);
864 ret = video_device_create_file(vdev, &dev_attr_informations);
865 ret = video_device_create_file(vdev, &dev_attr_fps);
866 ret = video_device_create_file(vdev, &dev_attr_brightness);
867 ret = video_device_create_file(vdev, &dev_attr_rgb_gain);
868 ret = video_device_create_file(vdev, &dev_attr_exposure);
869 ret = video_device_create_file(vdev, &dev_attr_contrast);
870 ret = video_device_create_file(vdev, &dev_attr_whitebalance);
871 ret = video_device_create_file(vdev, &dev_attr_sharpness);
872 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
873 ret = video_device_create_file(vdev, &dev_attr_hflip);
874 ret = video_device_create_file(vdev, &dev_attr_vflip);
875 ret = video_device_create_file(vdev, &dev_attr_auto_exposure);
876 ret = video_device_create_file(vdev, &dev_attr_auto_whitebalance);
877 #else
878 ret = device_create_file(&vdev->dev, &dev_attr_release);
879 ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
880 ret = device_create_file(&vdev->dev, &dev_attr_informations);
881 ret = device_create_file(&vdev->dev, &dev_attr_fps);
882 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
883 ret = device_create_file(&vdev->dev, &dev_attr_rgb_gain);
884 ret = device_create_file(&vdev->dev, &dev_attr_exposure);
885 ret = device_create_file(&vdev->dev, &dev_attr_contrast);
886 ret = device_create_file(&vdev->dev, &dev_attr_whitebalance);
887 ret = device_create_file(&vdev->dev, &dev_attr_sharpness);
888 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
889 ret = device_create_file(&vdev->dev, &dev_attr_hflip);
890 ret = device_create_file(&vdev->dev, &dev_attr_vflip);
891 ret = device_create_file(&vdev->dev, &dev_attr_auto_exposure);
892 ret = device_create_file(&vdev->dev, &dev_attr_auto_whitebalance);
893 #endif
894 return ret;
899 * @brief Remove the 'sys' entries.
901 * This function permits to remove all the entries in the 'sys' filesystem.
903 * @param vdev Video device structure
905 * @returns 0 if all is OK
907 void microdia_remove_sysfs_files(struct video_device *vdev)
909 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
910 video_device_remove_file(vdev, &class_device_attr_release);
911 video_device_remove_file(vdev, &class_device_attr_videostatus);
912 video_device_remove_file(vdev, &class_device_attr_informations);
913 video_device_remove_file(vdev, &class_device_attr_fps);
914 video_device_remove_file(vdev, &class_device_attr_brightness);
915 video_device_remove_file(vdev, &class_device_attr_exposure);
916 video_device_remove_file(vdev, &class_device_attr_rgb_gain);
917 video_device_remove_file(vdev, &class_device_attr_contrast);
918 video_device_remove_file(vdev, &class_device_attr_whitebalance);
919 video_device_remove_file(vdev, &class_device_attr_sharpness);
920 /*video_device_remove_file(vdev, &class_device_attr_colour);*/
921 video_device_remove_file(vdev, &class_device_attr_hflip);
922 video_device_remove_file(vdev, &class_device_attr_vflip);
923 video_device_remove_file(vdev, &class_device_attr_auto_exposure);
924 video_device_remove_file(vdev, &class_device_attr_auto_whitebalance);
925 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
926 video_device_remove_file(vdev, &dev_attr_release);
927 video_device_remove_file(vdev, &dev_attr_videostatus);
928 video_device_remove_file(vdev, &dev_attr_informations);
929 video_device_remove_file(vdev, &dev_attr_fps);
930 video_device_remove_file(vdev, &dev_attr_brightness);
931 video_device_remove_file(vdev, &dev_attr_rgb_gain);
932 video_device_remove_file(vdev, &dev_attr_exposure);
933 video_device_remove_file(vdev, &dev_attr_contrast);
934 video_device_remove_file(vdev, &dev_attr_whitebalance);
935 video_device_remove_file(vdev, &dev_attr_sharpness);
936 /*video_device_remove_file(vdev, &dev_attr_colour);*/
937 video_device_remove_file(vdev, &dev_attr_hflip);
938 video_device_remove_file(vdev, &dev_attr_vflip);
939 video_device_remove_file(vdev, &dev_attr_auto_exposure);
940 video_device_remove_file(vdev, &dev_attr_auto_whitebalance);
941 #else
942 device_remove_file(&vdev->dev, &dev_attr_release);
943 device_remove_file(&vdev->dev, &dev_attr_videostatus);
944 device_remove_file(&vdev->dev, &dev_attr_informations);
945 device_remove_file(&vdev->dev, &dev_attr_fps);
946 device_remove_file(&vdev->dev, &dev_attr_brightness);
947 device_remove_file(&vdev->dev, &dev_attr_rgb_gain);
948 device_remove_file(&vdev->dev, &dev_attr_exposure);
949 device_remove_file(&vdev->dev, &dev_attr_contrast);
950 device_remove_file(&vdev->dev, &dev_attr_whitebalance);
951 device_remove_file(&vdev->dev, &dev_attr_sharpness);
952 /*video_device_remove_file(vdev, &dev_attr_colour);*/
953 device_remove_file(&vdev->dev, &dev_attr_hflip);
954 device_remove_file(&vdev->dev, &dev_attr_vflip);
955 device_remove_file(&vdev->dev, &dev_attr_auto_exposure);
956 device_remove_file(&vdev->dev, &dev_attr_auto_whitebalance);
957 #endif