Fix SXGA support to enforce bayer format
[microdia.git] / sn9c20x-sysfs.c
blob1f0d75f72c987c50ce5e91e66cefbef900d47c62
1 /**
2 * @file sn9c20x-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 "sn9c20x.h"
40 #include "sn9c20x-bridge.h"
42 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
43 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
45 char *tail;
46 unsigned long val;
47 size_t len;
49 *res = 0;
50 len = strlen(cp);
51 if (len == 0)
52 return -EINVAL;
54 val = simple_strtoul(cp, &tail, base);
55 if ((*tail == '\0') ||
56 ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
57 *res = val;
58 return 0;
61 return -EINVAL;
64 int strict_strtol(const char *cp, unsigned int base, long *res)
66 int ret;
67 if (*cp == '-') {
68 ret = strict_strtoul(cp + 1, base, (unsigned long *)res);
69 if (!ret)
70 *res = -(*res);
71 } else
72 ret = strict_strtoul(cp, base, (unsigned long *)res);
74 return ret;
76 #endif
78 /**
79 * @brief show_release
81 * @param class Class device
82 * @param attr
83 * @retval buf Adress of buffer with the 'release' value
85 * @returns Size of buffer
87 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
88 static ssize_t show_release(struct class_device *class, char *buf)
89 #else
90 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
91 #endif
93 struct video_device *vdev = to_video_device(class);
94 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
96 return sprintf(buf, "%d\n", dev->release);
101 * @brief show_videostatus
103 * @param class Class device
104 * @param attr
105 * @retval buf Adress of buffer with the 'videostatus' value
107 * @returns Size of buffer
109 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
110 static ssize_t show_videostatus(struct class_device *class, char *buf)
111 #else
112 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
113 #endif
115 struct video_device *vdev = to_video_device(class);
116 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
118 return sprintf(buf,
119 "Overflow frames : %d\n"
120 "Incomplete frames : %d\n"
121 "Dropped frames : %d\n",
122 dev->vframes_overflow,
123 dev->vframes_incomplete,
124 dev->vframes_dropped);
129 * @brief show_information
131 * @param class Class device
132 * @param attr
133 * @retval buf Address of buffer with the 'information' value
135 * @returns Size of buffer
137 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
138 static ssize_t show_information(struct class_device *class, char *buf)
139 #else
140 static ssize_t show_information(struct device *class, struct device_attribute *attr, char *buf)
141 #endif
143 char *pixelfmt = NULL;
145 struct video_device *vdev = to_video_device(class);
146 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
148 char *palette_bayer = "BAYER - BGGR - 8 bits";
149 char *palette_i420 = "SN9C20X_I420 - YUV 4:2:0 - 12 bits";
150 char *palette_jpeg = "JPEG - YUV 4:2:2 - 16 bits";
153 switch (dev->vsettings.format.pixelformat) {
154 case V4L2_PIX_FMT_SBGGR8:
155 pixelfmt = palette_bayer;
156 break;
158 case V4L2_PIX_FMT_JPEG:
159 pixelfmt = palette_jpeg;
160 break;
162 case V4L2_PIX_FMT_SN9C20X_I420:
163 pixelfmt = palette_i420;
164 break;
167 return sprintf(buf,
168 "Driver Resolution : %dx%d\n"
169 "\n"
170 "%s\n"
171 "\n"
172 "Brightness : %u\n"
173 "Contrast : %u\n"
174 "Hue : %d\n"
175 "Saturation : %u\n"
176 "Gamma : %u\n"
177 "Exposure : %u\n"
178 "Gain : %u\n"
179 "Sharpness : %u\n"
180 "Red Balance : %u\n"
181 "Blue Balance : %u\n"
182 "Horizontal flip : %d\n"
183 "Vertical flip : %d\n"
184 "Auto-exposure : %d\n"
185 "Auto-gain : %d\n"
186 "Auto-whitebalance : %d\n",
187 dev->vsettings.format.width,
188 dev->vsettings.format.height,
189 pixelfmt,
190 dev->vsettings.brightness,
191 dev->vsettings.contrast,
192 dev->vsettings.hue,
193 dev->vsettings.colour,
194 dev->vsettings.gamma,
195 dev->vsettings.exposure,
196 dev->vsettings.gain,
197 dev->vsettings.sharpness,
198 dev->vsettings.red_gain,
199 dev->vsettings.blue_gain,
200 dev->vsettings.hflip,
201 dev->vsettings.vflip,
202 dev->vsettings.auto_exposure,
203 dev->vsettings.auto_gain,
204 dev->vsettings.auto_whitebalance);
209 * @brief show_fps
211 * @param class Class device
212 * @param attr
213 * @retval buf Adress of buffer with the 'fps' value
215 * @returns Size of buffer
217 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
218 static ssize_t show_fps(struct class_device *class, char *buf)
219 #else
220 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
221 #endif
223 struct video_device *vdev = to_video_device(class);
224 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
226 return sprintf(buf, "%d\n", dev->vsettings.fps);
230 * @brief show_gain
232 * @param class Class device
233 * @param attr
234 * @retval buf Adress of buffer with the 'gain' value
236 * @returns Size of buffer
238 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
239 static ssize_t show_gain(struct class_device *class, char *buf)
240 #else
241 static ssize_t show_gain(struct device *class, struct device_attribute *attr, char *buf)
242 #endif
244 struct video_device *vdev = to_video_device(class);
245 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
247 return sprintf(buf, "%u\n", dev->vsettings.gain);
251 * @brief store_gain
253 * @param class Class device
254 * @param buf Buffer
255 * @param count Counter
256 * @param attr
258 * @returns Size of buffer
260 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
261 static ssize_t store_gain(struct class_device *class, const char *buf, size_t count)
262 #else
263 static ssize_t store_gain(struct device *class, struct device_attribute *attr,
264 const char *buf, size_t count)
265 #endif
267 unsigned long value;
269 struct video_device *vdev = to_video_device(class);
270 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
272 if (strict_strtoul(buf, 10, &value) < 0)
273 return -EINVAL;
275 if (value > 255)
276 return -EINVAL;
278 sn9c20x_set_camera_control(dev,
279 V4L2_CID_GAIN,
280 value);
282 return strlen(buf);
285 * @brief show_exposure
287 * @param class Class device
288 * @param attr
289 * @retval buf Adress of buffer with the 'exposure' value
291 * @returns Size of buffer
293 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
294 static ssize_t show_exposure(struct class_device *class, char *buf)
295 #else
296 static ssize_t show_exposure(struct device *class, struct device_attribute *attr, char *buf)
297 #endif
299 struct video_device *vdev = to_video_device(class);
300 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
302 return sprintf(buf, "%u\n", dev->vsettings.exposure);
306 * @brief store_exposure
308 * @param class Class device
309 * @param buf Buffer
310 * @param count Counter
311 * @param attr
313 * @returns Size of buffer
315 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
316 static ssize_t store_exposure(struct class_device *class, const char *buf, size_t count)
317 #else
318 static ssize_t store_exposure(struct device *class, struct device_attribute *attr,
319 const char *buf, size_t count)
320 #endif
322 unsigned long value;
324 struct video_device *vdev = to_video_device(class);
325 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
327 if (strict_strtoul(buf, 10, &value) < 0)
328 return -EINVAL;
330 if (value > 255)
331 return -EINVAL;
333 sn9c20x_set_camera_control(dev,
334 V4L2_CID_EXPOSURE,
335 value);
337 return strlen(buf);
341 * @brief show_brightness
343 * @param class Class device
344 * @param attr
345 * @retval buf Adress of buffer with the 'brightness' value
347 * @returns Size of buffer
349 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
350 static ssize_t show_brightness(struct class_device *class, char *buf)
351 #else
352 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
353 #endif
355 struct video_device *vdev = to_video_device(class);
356 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
358 return sprintf(buf, "%u\n", dev->vsettings.brightness);
362 * @brief store_brightness
364 * @param class Class device
365 * @param buf Buffer
366 * @param count Counter
367 * @param attr
369 * @returns Size of buffer
371 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
372 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
373 #else
374 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
375 const char *buf, size_t count)
376 #endif
378 unsigned long value;
380 struct video_device *vdev = to_video_device(class);
381 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
383 if (strict_strtoul(buf, 10, &value) < 0)
384 return -EINVAL;
386 if (value > 255)
387 return -EINVAL;
389 sn9c20x_set_camera_control(dev,
390 V4L2_CID_BRIGHTNESS,
391 value);
393 return strlen(buf);
397 * @brief show_contrast
399 * @param class Class device
400 * @param attr
401 * @retval buf Adress of buffer with the 'contrast' value
403 * @returns Size of buffer
405 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
406 static ssize_t show_contrast(struct class_device *class, char *buf)
407 #else
408 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
409 #endif
411 struct video_device *vdev = to_video_device(class);
412 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
414 return sprintf(buf, "%u\n", dev->vsettings.contrast);
419 * @brief store_contrast
421 * @param class Class device
422 * @param buf Buffer
423 * @param count Counter
424 * @param attr
426 * @returns Size of buffer
428 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
429 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
430 #else
431 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
432 const char *buf, size_t count)
433 #endif
435 unsigned long value;
437 struct video_device *vdev = to_video_device(class);
438 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
440 if (strict_strtoul(buf, 10, &value) < 0)
441 return -EINVAL;
443 if (value > 255)
444 return -EINVAL;
446 sn9c20x_set_camera_control(dev,
447 V4L2_CID_CONTRAST,
448 value);
450 return strlen(buf);
457 * @brief show_saturation
459 * @param class Class device
460 * @param attr
461 * @retval buf Adress of buffer with the 'contrast' value
463 * @returns Size of buffer
465 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
466 static ssize_t show_saturation(struct class_device *class, char *buf)
467 #else
468 static ssize_t show_saturation(struct device *class,
469 struct device_attribute *attr, char *buf)
470 #endif
472 struct video_device *vdev = to_video_device(class);
473 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
475 return sprintf(buf, "%u\n", dev->vsettings.colour);
480 * @brief store_saturation
482 * @param class Class device
483 * @param buf Buffer
484 * @param count Counter
485 * @param attr
487 * @returns Size of buffer
489 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
490 static ssize_t store_saturation(struct class_device *class,
491 const char *buf,
492 size_t count)
493 #else
494 static ssize_t store_saturation(struct device *class,
495 struct device_attribute *attr,
496 const char *buf,
497 size_t count)
498 #endif
500 unsigned long value;
502 struct video_device *vdev = to_video_device(class);
503 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
505 if (strict_strtoul(buf, 10, &value) < 0)
506 return -EINVAL;
508 if (value > 255)
509 return -EINVAL;
511 sn9c20x_set_camera_control(dev,
512 V4L2_CID_SATURATION,
513 value);
515 return strlen(buf);
521 * @brief show_hue
523 * @param class Class device
524 * @param attr
525 * @retval buf Adress of buffer with the 'contrast' value
527 * @returns Size of buffer
529 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
530 static ssize_t show_hue(struct class_device *class,
531 char *buf)
532 #else
533 static ssize_t show_hue(struct device *class,
534 struct device_attribute *attr,
535 char *buf)
536 #endif
538 struct video_device *vdev = to_video_device(class);
539 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
541 return sprintf(buf, "%d\n", dev->vsettings.hue);
546 * @brief store_hue
548 * @param class Class device
549 * @param buf Buffer
550 * @param count Counter
551 * @param attr
553 * @returns Size of buffer
555 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
556 static ssize_t store_hue(struct class_device *class,
557 const char *buf,
558 size_t count)
559 #else
560 static ssize_t store_hue(struct device *class,
561 struct device_attribute *attr,
562 const char *buf, size_t count)
563 #endif
565 long value;
567 struct video_device *vdev = to_video_device(class);
568 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
570 if (strict_strtol(buf, 10, &value) < 0)
571 return -EINVAL;
573 if (value > 180 || value < -180)
574 return -EINVAL;
576 sn9c20x_set_camera_control(dev,
577 V4L2_CID_HUE,
578 value);
580 return strlen(buf);
587 * @brief show_whitebalance
589 * @param class Class device
590 * @param attr
591 * @retval buf Adress of buffer with the 'whitebalance' value
593 * @returns Size of buffer
595 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
596 static ssize_t show_gamma(struct class_device *class,
597 char *buf)
598 #else
599 static ssize_t show_gamma(struct device *class,
600 struct device_attribute *attr,
601 char *buf)
602 #endif
604 struct video_device *vdev = to_video_device(class);
605 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
607 return sprintf(buf, "%u\n", dev->vsettings.gamma);
612 * @brief store_gamma
614 * @param class Class device
615 * @param buf Buffer
616 * @param count Counter
617 * @param attr
619 * @returns Size of buffer
621 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
622 static ssize_t store_gamma(struct class_device *class,
623 const char *buf,
624 size_t count)
625 #else
626 static ssize_t store_gamma(struct device *class,
627 struct device_attribute *attr,
628 const char *buf, size_t count)
629 #endif
631 unsigned long value;
633 struct video_device *vdev = to_video_device(class);
634 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
636 if (strict_strtoul(buf, 10, &value) < 0)
637 return -EINVAL;
639 if (value > 255)
640 return -EINVAL;
642 sn9c20x_set_camera_control(dev,
643 V4L2_CID_GAMMA,
644 value);
646 return strlen(buf);
653 * @brief show_sharpness
655 * @param class Class device
656 * @param attr
657 * @retval buf Adress of buffer with the 'sharpness' value
659 * @returns Size of buffer
661 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
662 static ssize_t show_sharpness(struct class_device *class, char *buf)
663 #else
664 static ssize_t show_sharpness(struct device *class, struct device_attribute *attr, char *buf)
665 #endif
667 struct video_device *vdev = to_video_device(class);
668 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
670 return sprintf(buf, "%u\n", dev->vsettings.sharpness);
674 * @brief store_sharpness
676 * @param class Class device
677 * @param buf Buffer
678 * @param count Counter
679 * @param attr
681 * @returns Size of buffer
683 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
684 static ssize_t store_sharpness(struct class_device *class, const char *buf, size_t count)
685 #else
686 static ssize_t store_sharpness(struct device *class, struct device_attribute *attr,
687 const char *buf, size_t count)
688 #endif
690 unsigned long value;
692 struct video_device *vdev = to_video_device(class);
693 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
695 if (strict_strtoul(buf, 10, &value) < 0)
696 return -EINVAL;
698 if (value > 63)
699 return -EINVAL;
701 sn9c20x_set_camera_control(dev,
702 V4L2_CID_SHARPNESS,
703 value);
705 return strlen(buf);
710 * @brief show_hflip
712 * @param class Class device
713 * @param attr
714 * @retval buf Adress of buffer with the 'hflip' value
716 * @returns Size of buffer
718 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
719 static ssize_t show_hflip(struct class_device *class, char *buf)
720 #else
721 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
722 #endif
724 struct video_device *vdev = to_video_device(class);
725 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
727 return sprintf(buf, "%d\n", dev->vsettings.hflip);
732 * @brief store_hflip
734 * @param class Class device
735 * @param buf Buffer
736 * @param count Counter
737 * @param attr
739 * @returns Size of buffer
741 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
742 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
743 #else
744 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
745 const char *buf, size_t count)
746 #endif
748 unsigned long value;
749 struct video_device *vdev = to_video_device(class);
750 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
752 if (strict_strtoul(buf, 10, &value) < 0)
753 return -EINVAL;
755 if (value != 0 && value != 1)
756 return -EINVAL;
758 sn9c20x_set_camera_control(dev,
759 V4L2_CID_HFLIP,
760 value);
762 return strlen(buf);
767 * @brief show_vflip
769 * @param class Class device
770 * @param attr
771 * @retval buf Adress of buffer with the 'vflip' value
773 * @returns Size of buffer
775 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
776 static ssize_t show_vflip(struct class_device *class, char *buf)
777 #else
778 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
779 #endif
781 struct video_device *vdev = to_video_device(class);
782 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
784 return sprintf(buf, "%d\n", dev->vsettings.vflip);
789 * @brief store_vflip
791 * @param class Class device
792 * @param buf Buffer
793 * @param count Counter
794 * @param attr
796 * @returns Size of buffer
798 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
799 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
800 #else
801 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
802 #endif
804 unsigned long value;
805 struct video_device *vdev = to_video_device(class);
806 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
808 if (strict_strtoul(buf, 10, &value) < 0)
809 return -EINVAL;
811 if (value != 0 && value != 1)
812 return -EINVAL;
814 sn9c20x_set_camera_control(dev,
815 V4L2_CID_VFLIP,
816 value);
818 return strlen(buf);
823 * @brief show_autoexposure
825 * @param class Class device
826 * @param attr
827 * @retval buf Adress of buffer with the 'hflip' value
829 * @returns Size of buffer
831 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
832 static ssize_t show_autoexposure(struct class_device *class, char *buf)
833 #else
834 static ssize_t show_autoexposure(struct device *class, struct device_attribute *attr, char *buf)
835 #endif
837 struct video_device *vdev = to_video_device(class);
838 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
840 return sprintf(buf, "%d\n", dev->vsettings.auto_exposure);
845 * @brief store_autoexposure
847 * @param class Class device
848 * @param buf Buffer
849 * @param count Counter
850 * @param attr
852 * @returns Size of buffer
854 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
855 static ssize_t store_autoexposure(struct class_device *class, const char *buf, size_t count)
856 #else
857 static ssize_t store_autoexposure(struct device *class, struct device_attribute *attr,
858 const char *buf, size_t count)
859 #endif
861 unsigned long value;
862 struct video_device *vdev = to_video_device(class);
863 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
865 if (strict_strtoul(buf, 10, &value) < 0)
866 return -EINVAL;
868 if (value != 0 && value != 1)
869 return -EINVAL;
871 sn9c20x_set_camera_control(dev,
872 V4L2_CID_EXPOSURE_AUTO,
873 value);
875 return strlen(buf);
880 * @brief show_autowhitebalance
882 * @param class Class device
883 * @param attr
884 * @retval buf Adress of buffer with the 'vflip' value
886 * @returns Size of buffer
888 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
889 static ssize_t show_autowhitebalance(struct class_device *class, char *buf)
890 #else
891 static ssize_t show_autowhitebalance(struct device *class, struct device_attribute *attr, char *buf)
892 #endif
894 struct video_device *vdev = to_video_device(class);
895 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
897 return sprintf(buf, "%d\n", dev->vsettings.auto_whitebalance);
902 * @brief store_autowhitebalance
904 * @param class Class device
905 * @param buf Buffer
906 * @param count Counter
907 * @param attr
909 * @returns Size of buffer
911 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
912 static ssize_t store_autowhitebalance(struct class_device *class, const char *buf, size_t count)
913 #else
914 static ssize_t store_autowhitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
915 #endif
917 unsigned long value;
918 struct video_device *vdev = to_video_device(class);
919 struct usb_sn9c20x *dev = video_get_drvdata(vdev);
921 if (strict_strtoul(buf, 10, &value) < 0)
922 return -EINVAL;
924 if (value != 0 && value != 1)
925 return -EINVAL;
927 sn9c20x_set_camera_control(dev,
928 V4L2_CID_AUTO_WHITE_BALANCE,
929 value);
931 return strlen(buf);
934 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
935 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
936 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
937 static CLASS_DEVICE_ATTR(information, S_IRUGO, show_information, NULL); /**< Information */
938 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
939 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
940 static CLASS_DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
941 static CLASS_DEVICE_ATTR(gain, S_IRUGO | S_IWUGO, show_gain, store_gain); /**< Gain value */
942 static CLASS_DEVICE_ATTR(saturation, S_IRUGO | S_IWUGO, show_saturation, store_saturation); /**< Saturation value */
943 static CLASS_DEVICE_ATTR(hue, S_IRUGO | S_IWUGO, show_hue, store_hue); /**< Hue value */
944 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
945 static CLASS_DEVICE_ATTR(gamma, S_IRUGO | S_IWUGO, show_gamma, store_gamma); /**< Gamma value */
946 static CLASS_DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
947 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
948 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
949 static CLASS_DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
950 static CLASS_DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
951 #else
952 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
953 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
954 static DEVICE_ATTR(information, S_IRUGO, show_information, NULL); /**< Information */
955 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
956 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
957 static DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
958 static DEVICE_ATTR(gain, S_IRUGO | S_IWUGO, show_gain, store_gain); /**< Gain value */
959 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
960 static DEVICE_ATTR(saturation, S_IRUGO | S_IWUGO, show_saturation, store_saturation); /**< Saturation value */
961 static DEVICE_ATTR(hue, S_IRUGO | S_IWUGO, show_hue, store_hue); /**< Hue value */
962 static DEVICE_ATTR(gamma, S_IRUGO | S_IWUGO, show_gamma, store_gamma); /**< Gamma value */
963 static DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
964 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
965 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
966 static DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
967 static DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
968 #endif
972 * @brief Create the 'sys' entries.
974 * This function permits to create all the entries in the 'sys' filesystem.
976 * @param vdev Video device structure
978 * @returns 0 if all is OK
980 int sn9c20x_create_sysfs_files(struct video_device *vdev)
982 int ret;
984 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
985 ret = video_device_create_file(vdev, &class_device_attr_release);
986 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
987 ret = video_device_create_file(vdev, &class_device_attr_information);
988 ret = video_device_create_file(vdev, &class_device_attr_fps);
989 ret = video_device_create_file(vdev, &class_device_attr_brightness);
990 ret = video_device_create_file(vdev, &class_device_attr_exposure);
991 ret = video_device_create_file(vdev, &class_device_attr_gain);
992 ret = video_device_create_file(vdev, &class_device_attr_contrast);
993 ret = video_device_create_file(vdev, &class_device_attr_saturation);
994 ret = video_device_create_file(vdev, &class_device_attr_hue);
995 ret = video_device_create_file(vdev, &class_device_attr_gamma);
996 ret = video_device_create_file(vdev, &class_device_attr_sharpness);
997 ret = video_device_create_file(vdev, &class_device_attr_hflip);
998 ret = video_device_create_file(vdev, &class_device_attr_vflip);
999 ret = video_device_create_file(vdev, &class_device_attr_auto_exposure);
1000 ret = video_device_create_file(vdev, &class_device_attr_auto_whitebalance);
1001 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
1002 ret = video_device_create_file(vdev, &dev_attr_release);
1003 ret = video_device_create_file(vdev, &dev_attr_videostatus);
1004 ret = video_device_create_file(vdev, &dev_attr_information);
1005 ret = video_device_create_file(vdev, &dev_attr_fps);
1006 ret = video_device_create_file(vdev, &dev_attr_brightness);
1007 ret = video_device_create_file(vdev, &dev_attr_exposure);
1008 ret = video_device_create_file(vdev, &dev_attr_gain);
1009 ret = video_device_create_file(vdev, &dev_attr_contrast);
1010 ret = video_device_create_file(vdev, &dev_attr_saturation);
1011 ret = video_device_create_file(vdev, &dev_attr_hue);
1012 ret = video_device_create_file(vdev, &dev_attr_gamma);
1013 ret = video_device_create_file(vdev, &dev_attr_sharpness);
1014 ret = video_device_create_file(vdev, &dev_attr_hflip);
1015 ret = video_device_create_file(vdev, &dev_attr_vflip);
1016 ret = video_device_create_file(vdev, &dev_attr_auto_exposure);
1017 ret = video_device_create_file(vdev, &dev_attr_auto_whitebalance);
1018 #else
1019 ret = device_create_file(&vdev->dev, &dev_attr_release);
1020 ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
1021 ret = device_create_file(&vdev->dev, &dev_attr_information);
1022 ret = device_create_file(&vdev->dev, &dev_attr_fps);
1023 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
1024 ret = device_create_file(&vdev->dev, &dev_attr_exposure);
1025 ret = device_create_file(&vdev->dev, &dev_attr_gain);
1026 ret = device_create_file(&vdev->dev, &dev_attr_contrast);
1027 ret = device_create_file(&vdev->dev, &dev_attr_saturation);
1028 ret = device_create_file(&vdev->dev, &dev_attr_hue);
1029 ret = device_create_file(&vdev->dev, &dev_attr_gamma);
1030 ret = device_create_file(&vdev->dev, &dev_attr_sharpness);
1031 ret = device_create_file(&vdev->dev, &dev_attr_hflip);
1032 ret = device_create_file(&vdev->dev, &dev_attr_vflip);
1033 ret = device_create_file(&vdev->dev, &dev_attr_auto_exposure);
1034 ret = device_create_file(&vdev->dev, &dev_attr_auto_whitebalance);
1035 #endif
1036 return ret;
1041 * @brief Remove the 'sys' entries.
1043 * This function permits to remove all the entries in the 'sys' filesystem.
1045 * @param vdev Video device structure
1047 * @returns 0 if all is OK
1049 void sn9c20x_remove_sysfs_files(struct video_device *vdev)
1051 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
1052 video_device_remove_file(vdev, &class_device_attr_release);
1053 video_device_remove_file(vdev, &class_device_attr_videostatus);
1054 video_device_remove_file(vdev, &class_device_attr_information);
1055 video_device_remove_file(vdev, &class_device_attr_fps);
1056 video_device_remove_file(vdev, &class_device_attr_brightness);
1057 video_device_remove_file(vdev, &class_device_attr_exposure);
1058 video_device_remove_file(vdev, &class_device_attr_gain);
1059 video_device_remove_file(vdev, &class_device_attr_contrast);
1060 video_device_remove_file(vdev, &class_device_attr_saturation);
1061 video_device_remove_file(vdev, &class_device_attr_hue);
1062 video_device_remove_file(vdev, &class_device_attr_gamma);
1063 video_device_remove_file(vdev, &class_device_attr_sharpness);
1064 video_device_remove_file(vdev, &class_device_attr_hflip);
1065 video_device_remove_file(vdev, &class_device_attr_vflip);
1066 video_device_remove_file(vdev, &class_device_attr_auto_exposure);
1067 video_device_remove_file(vdev, &class_device_attr_auto_whitebalance);
1068 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)
1069 video_device_remove_file(vdev, &dev_attr_release);
1070 video_device_remove_file(vdev, &dev_attr_videostatus);
1071 video_device_remove_file(vdev, &dev_attr_information);
1072 video_device_remove_file(vdev, &dev_attr_fps);
1073 video_device_remove_file(vdev, &dev_attr_brightness);
1074 video_device_remove_file(vdev, &dev_attr_exposure);
1075 video_device_remove_file(vdev, &dev_attr_gain);
1076 video_device_remove_file(vdev, &dev_attr_contrast);
1077 video_device_remove_file(vdev, &dev_attr_saturation);
1078 video_device_remove_file(vdev, &dev_attr_hue);
1079 video_device_remove_file(vdev, &dev_attr_gamma);
1080 video_device_remove_file(vdev, &dev_attr_sharpness);
1081 video_device_remove_file(vdev, &dev_attr_hflip);
1082 video_device_remove_file(vdev, &dev_attr_vflip);
1083 video_device_remove_file(vdev, &dev_attr_auto_exposure);
1084 video_device_remove_file(vdev, &dev_attr_auto_whitebalance);
1085 #else
1086 device_remove_file(&vdev->dev, &dev_attr_release);
1087 device_remove_file(&vdev->dev, &dev_attr_videostatus);
1088 device_remove_file(&vdev->dev, &dev_attr_information);
1089 device_remove_file(&vdev->dev, &dev_attr_fps);
1090 device_remove_file(&vdev->dev, &dev_attr_brightness);
1091 device_remove_file(&vdev->dev, &dev_attr_exposure);
1092 device_remove_file(&vdev->dev, &dev_attr_gain);
1093 device_remove_file(&vdev->dev, &dev_attr_contrast);
1094 device_remove_file(&vdev->dev, &dev_attr_saturation);
1095 device_remove_file(&vdev->dev, &dev_attr_hue);
1096 device_remove_file(&vdev->dev, &dev_attr_gamma);
1097 device_remove_file(&vdev->dev, &dev_attr_sharpness);
1098 device_remove_file(&vdev->dev, &dev_attr_hflip);
1099 device_remove_file(&vdev->dev, &dev_attr_vflip);
1100 device_remove_file(&vdev->dev, &dev_attr_auto_exposure);
1101 device_remove_file(&vdev->dev, &dev_attr_auto_whitebalance);
1102 #endif