Use lookup array to determine device specific functions
[microdia.git] / microdia-sysfs.c
blob002506a808b01f8f899dbc636dcb51073bec36b3
1 /**
2 * @file microdia-sysfs.c
3 * @author Nicolas VIVIEN
4 * @date 2008-02-01
5 * @version v0.0.0
7 * @brief Driver for Microdia USB video camera
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 extern const struct microdia_coord microdia_image_sizes[MICRODIA_NBR_SIZES];
47 /**
48 * @brief show_release
50 * @param class Class device
52 * @retval buf Adress of buffer with the 'release' value
54 * @returns Size of buffer
56 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
57 static ssize_t show_release(struct class_device *class, char *buf)
58 #else
59 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
60 #endif
62 struct video_device *vdev = to_video_device(class);
63 struct usb_microdia *dev = video_get_drvdata(vdev);
65 return sprintf(buf, "%d\n", dev->release);
69 /**
70 * @brief show_videostatus
72 * @param class Class device
74 * @retval buf Adress of buffer with the 'videostatus' value
76 * @returns Size of buffer
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
79 static ssize_t show_videostatus(struct class_device *class, char *buf)
80 #else
81 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
82 #endif
84 struct video_device *vdev = to_video_device(class);
85 struct usb_microdia *dev = video_get_drvdata(vdev);
87 return sprintf(buf,
88 "Overflow frames : %d\n"
89 "Incomplete frames : %d\n"
90 "Dropped frames : %d\n",
91 dev->vframes_overflow,
92 dev->vframes_incomplete,
93 dev->vframes_dropped);
97 /**
98 * @brief show_informations
100 * @param class Class device
102 * @retval buf Adress of buffer with the 'informations' value
104 * @returns Size of buffer
106 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
107 static ssize_t show_informations(struct class_device *class, char *buf)
108 #else
109 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
110 #endif
112 int width, height;
113 char *pixelfmt = NULL;
115 struct video_device *vdev = to_video_device(class);
116 struct usb_microdia *dev = video_get_drvdata(vdev);
118 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
119 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
120 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
121 char *palette_i420 = "I420 - YUV 4:2:0 - 12 bits";
124 switch (dev->vsettings.format.pixelformat) {
125 case V4L2_PIX_FMT_BGR24:
126 pixelfmt = palette_bgr24;
127 break;
129 case V4L2_PIX_FMT_RGB24:
130 pixelfmt = palette_rgb24;
131 break;
133 case V4L2_PIX_FMT_YUYV:
134 pixelfmt = palette_yuyv;
135 break;
137 case V4L2_PIX_FMT_YUV420:
138 pixelfmt = palette_i420;
139 break;
142 switch (dev->resolution) {
143 case MICRODIA_80x60:
144 /*case MICRODIA_128x96:*/
145 case MICRODIA_160x120:
146 /*case MICRODIA_213x160: */
147 case MICRODIA_320x240:
148 case MICRODIA_640x480:
149 width = microdia_image_sizes[MICRODIA_640x480].x;
150 height = microdia_image_sizes[MICRODIA_640x480].y;
151 break;
153 case MICRODIA_800x600:
154 case MICRODIA_1024x768:
155 case MICRODIA_1280x1024:
156 width = microdia_image_sizes[MICRODIA_1280x1024].x;
157 height = microdia_image_sizes[MICRODIA_1280x1024].y;
158 break;
160 default:
161 width = 0;
162 height = 0;
165 return sprintf(buf,
166 "Asked resolution : %dx%d\n"
167 "Driver resolution : %dx%d\n"
168 "Webcam resolution : %dx%d\n"
169 "\n"
170 "%s\n"
171 "\n"
172 "Brightness : 0x%X\n"
173 "Contrast : 0x%X\n"
174 "Whiteness : 0x%X\n"
175 "Exposure : 0x%X\n"
176 "Sharpness : 0x%X\n"
177 "Horizontal flip : %d\n"
178 "Vertical flip : %d\n"
179 "Auto-exposure : %d\n"
180 "Auto-whitebalance : %d\n",
181 dev->view.x, dev->view.y,
182 microdia_image_sizes[dev->resolution].x, microdia_image_sizes[dev->resolution].y,
183 width, height,
184 pixelfmt,
185 0xFFFF & dev->vsettings.brightness,
186 0xFFFF & dev->vsettings.contrast,
187 0xFFFF & dev->vsettings.whiteness,
188 0xFFFF & dev->vsettings.exposure,
189 0x3F & dev->vsettings.sharpness,
190 dev->vsettings.hflip,
191 dev->vsettings.vflip,
192 dev->vsettings.auto_exposure,
193 dev->vsettings.auto_whitebalance);
197 /**
198 * @brief show_fps
200 * @param class Class device
202 * @retval buf Adress of buffer with the 'fps' value
204 * @returns Size of buffer
206 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
207 static ssize_t show_fps(struct class_device *class, char *buf)
208 #else
209 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
210 #endif
212 struct video_device *vdev = to_video_device(class);
213 struct usb_microdia *dev = video_get_drvdata(vdev);
215 return sprintf(buf, "%d\n", dev->vsettings.fps);
219 /**
220 * @brief show_exposure
222 * @param class Class device
224 * @retval buf Adress of buffer with the 'exposure' value
226 * @returns Size of buffer
228 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
229 static ssize_t show_exposure(struct class_device *class, char *buf)
230 #else
231 static ssize_t show_exposure(struct device *class, struct device_attribute *attr, char *buf)
232 #endif
234 struct video_device *vdev = to_video_device(class);
235 struct usb_microdia *dev = video_get_drvdata(vdev);
237 return sprintf(buf, "%X\n", dev->vsettings.exposure);
240 /**
241 * @brief store_exposure
243 * @param class Class device
244 * @param buf Buffer
245 * @param count Counter
247 * @returns Size of buffer
249 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
250 static ssize_t store_exposure(struct class_device *class, const char *buf, size_t count)
251 #else
252 static ssize_t store_exposure(struct device *class, struct device_attribute *attr,
253 const char *buf, size_t count)
254 #endif
256 char *endp;
257 unsigned long value;
259 struct video_device *vdev = to_video_device(class);
260 struct usb_microdia *dev = video_get_drvdata(vdev);
262 value = simple_strtoul(buf, &endp, 16);
264 dev->vsettings.exposure = (int) value;
266 dev_microdia_camera_set_exposure(dev);
268 return strlen(buf);
271 /**
272 * @brief show_brightness
274 * @param class Class device
276 * @retval buf Adress of buffer with the 'brightness' value
278 * @returns Size of buffer
280 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
281 static ssize_t show_brightness(struct class_device *class, char *buf)
282 #else
283 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
284 #endif
286 struct video_device *vdev = to_video_device(class);
287 struct usb_microdia *dev = video_get_drvdata(vdev);
289 return sprintf(buf, "%X\n", dev->vsettings.brightness);
292 /**
293 * @brief store_brightness
295 * @param class Class device
296 * @param buf Buffer
297 * @param count Counter
299 * @returns Size of buffer
301 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
302 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
303 #else
304 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
305 const char *buf, size_t count)
306 #endif
308 char *endp;
309 unsigned long value;
311 struct video_device *vdev = to_video_device(class);
312 struct usb_microdia *dev = video_get_drvdata(vdev);
314 value = simple_strtoul(buf, &endp, 16);
316 dev->vsettings.brightness = (int) value;
318 dev_microdia_camera_set_brightness(dev);
320 return strlen(buf);
323 /**
324 * @brief show_contrast
326 * @param class Class device
328 * @retval buf Adress of buffer with the 'contrast' value
330 * @returns Size of buffer
332 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
333 static ssize_t show_contrast(struct class_device *class, char *buf)
334 #else
335 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
336 #endif
338 struct video_device *vdev = to_video_device(class);
339 struct usb_microdia *dev = video_get_drvdata(vdev);
341 return sprintf(buf, "%X\n", dev->vsettings.contrast);
345 /**
346 * @brief store_contrast
348 * @param class Class device
349 * @param buf Buffer
350 * @param count Counter
352 * @returns Size of buffer
354 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
355 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
356 #else
357 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
358 const char *buf, size_t count)
359 #endif
361 char *endp;
362 unsigned long value;
364 struct video_device *vdev = to_video_device(class);
365 struct usb_microdia *dev = video_get_drvdata(vdev);
367 value = simple_strtoul(buf, &endp, 16);
369 dev->vsettings.contrast = (int) value;
371 dev_microdia_camera_set_contrast(dev);
372 // dev_microdia_set_camera_quality(dev);
374 return strlen(buf);
378 /**
379 * @brief show_whitebalance
381 * @param class Class device
383 * @retval buf Adress of buffer with the 'whitebalance' value
385 * @returns Size of buffer
387 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
388 static ssize_t show_whitebalance(struct class_device *class, char *buf)
389 #else
390 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
391 #endif
393 struct video_device *vdev = to_video_device(class);
394 struct usb_microdia *dev = video_get_drvdata(vdev);
396 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
400 /**
401 * @brief store_whitebalance
403 * @param class Class device
404 * @param buf Buffer
405 * @param count Counter
407 * @returns Size of buffer
409 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
410 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
411 #else
412 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
413 const char *buf, size_t count)
414 #endif
416 char *endp;
417 unsigned long value;
419 struct video_device *vdev = to_video_device(class);
420 struct usb_microdia *dev = video_get_drvdata(vdev);
422 value = simple_strtoul(buf, &endp, 16);
424 dev->vsettings.whiteness = (int) value;
426 dev_microdia_camera_set_gamma(dev);
427 // dev_microdia_set_camera_quality(dev);
429 return strlen(buf);
433 /**
434 * @brief show_colour
436 * @param class Class device
438 * @retval buf Adress of buffer with the 'colour' value
440 * @returns Size of buffer
442 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
443 static ssize_t show_colour(struct class_device *class, char *buf)
444 #else
445 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
446 #endif
448 struct video_device *vdev = to_video_device(class);
449 struct usb_microdia *dev = video_get_drvdata(vdev);
451 return sprintf(buf, "%X\n", dev->vsettings.colour);
455 /**
456 * @brief store_colour
458 * @param class Class device
459 * @param buf Buffer
460 * @param count Counter
462 * @returns Size of buffer
464 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
465 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
466 #else
467 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
468 const char *buf, size_t count)
469 #endif
471 char *endp;
472 unsigned long value;
474 struct video_device *vdev = to_video_device(class);
475 struct usb_microdia *dev = video_get_drvdata(vdev);
477 value = simple_strtoul(buf, &endp, 16);
479 dev->vsettings.colour = (int) value;
481 // dev_microdia_set_camera_quality(dev);
483 return strlen(buf);
488 /**
489 * @brief show_sharpness
491 * @param class Class device
493 * @retval buf Adress of buffer with the 'sharpness' value
495 * @returns Size of buffer
497 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
498 static ssize_t show_sharpness(struct class_device *class, char *buf)
499 #else
500 static ssize_t show_sharpness(struct device *class, struct device_attribute *attr, char *buf)
501 #endif
503 struct video_device *vdev = to_video_device(class);
504 struct usb_microdia *dev = video_get_drvdata(vdev);
506 return sprintf(buf, "%X\n", dev->vsettings.sharpness);
509 /**
510 * @brief store_sharpness
512 * @param class Class device
513 * @param buf Buffer
514 * @param count Counter
516 * @returns Size of buffer
518 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
519 static ssize_t store_sharpness(struct class_device *class, const char *buf, size_t count)
520 #else
521 static ssize_t store_sharpness(struct device *class, struct device_attribute *attr,
522 const char *buf, size_t count)
523 #endif
525 char *endp;
526 unsigned long value;
528 struct video_device *vdev = to_video_device(class);
529 struct usb_microdia *dev = video_get_drvdata(vdev);
531 value = simple_strtoul(buf, &endp, 16);
533 if (value < 0 || value > 0x3f)
534 return -EINVAL;
536 dev->vsettings.sharpness = (int) value;
538 dev_microdia_camera_set_sharpness(dev);
540 return strlen(buf);
544 /**
545 * @brief show_hflip
547 * @param class Class device
549 * @retval buf Adress of buffer with the 'hflip' value
551 * @returns Size of buffer
553 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
554 static ssize_t show_hflip(struct class_device *class, char *buf)
555 #else
556 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
557 #endif
559 struct video_device *vdev = to_video_device(class);
560 struct usb_microdia *dev = video_get_drvdata(vdev);
562 return sprintf(buf, "%d\n", dev->vsettings.hflip);
566 /**
567 * @brief store_hflip
569 * @param class Class device
570 * @param buf Buffer
571 * @param count Counter
573 * @returns Size of buffer
575 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
576 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
577 #else
578 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
579 const char *buf, size_t count)
580 #endif
582 struct video_device *vdev = to_video_device(class);
583 struct usb_microdia *dev = video_get_drvdata(vdev);
585 if (strncmp(buf, "1", 1) == 0)
586 dev->vsettings.hflip = 1;
587 else if (strncmp(buf, "0", 1) == 0)
588 dev->vsettings.hflip = 0;
589 else
590 return -EINVAL;
592 dev_microdia_camera_set_hvflip(dev);
594 return strlen(buf);
598 /**
599 * @brief show_vflip
601 * @param class Class device
603 * @retval buf Adress of buffer with the 'vflip' value
605 * @returns Size of buffer
607 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
608 static ssize_t show_vflip(struct class_device *class, char *buf)
609 #else
610 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
611 #endif
613 struct video_device *vdev = to_video_device(class);
614 struct usb_microdia *dev = video_get_drvdata(vdev);
616 return sprintf(buf, "%d\n", dev->vsettings.vflip);
620 /**
621 * @brief store_vflip
623 * @param class Class device
624 * @param buf Buffer
625 * @param count Counter
627 * @returns Size of buffer
629 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
630 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
631 #else
632 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
633 #endif
635 struct video_device *vdev = to_video_device(class);
636 struct usb_microdia *dev = video_get_drvdata(vdev);
638 if (strncmp(buf, "1", 1) == 0)
639 dev->vsettings.vflip = 1;
640 else if (strncmp(buf, "0", 1) == 0)
641 dev->vsettings.vflip = 0;
642 else
643 return -EINVAL;
645 dev_microdia_camera_set_hvflip(dev);
647 return strlen(buf);
651 /**
652 * @brief show_autoexposure
654 * @param class Class device
656 * @retval buf Adress of buffer with the 'hflip' value
658 * @returns Size of buffer
660 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
661 static ssize_t show_autoexposure(struct class_device *class, char *buf)
662 #else
663 static ssize_t show_autoexposure(struct device *class, struct device_attribute *attr, char *buf)
664 #endif
666 struct video_device *vdev = to_video_device(class);
667 struct usb_microdia *dev = video_get_drvdata(vdev);
669 return sprintf(buf, "%d\n", dev->vsettings.auto_exposure);
673 /**
674 * @brief store_autoexposure
676 * @param class Class device
677 * @param buf Buffer
678 * @param count Counter
680 * @returns Size of buffer
682 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
683 static ssize_t store_autoexposure(struct class_device *class, const char *buf, size_t count)
684 #else
685 static ssize_t store_autoexposure(struct device *class, struct device_attribute *attr,
686 const char *buf, size_t count)
687 #endif
689 struct video_device *vdev = to_video_device(class);
690 struct usb_microdia *dev = video_get_drvdata(vdev);
692 if (strncmp(buf, "1", 1) == 0)
693 dev->vsettings.auto_exposure = 1;
694 else if (strncmp(buf, "0", 1) == 0)
695 dev->vsettings.auto_exposure = 0;
696 else
697 return -EINVAL;
699 dev_microdia_camera_set_auto_exposure(dev);
701 return strlen(buf);
705 /**
706 * @brief show_autowhitebalance
708 * @param class Class device
710 * @retval buf Adress of buffer with the 'vflip' value
712 * @returns Size of buffer
714 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
715 static ssize_t show_autowhitebalance(struct class_device *class, char *buf)
716 #else
717 static ssize_t show_autowhitebalance(struct device *class, struct device_attribute *attr, char *buf)
718 #endif
720 struct video_device *vdev = to_video_device(class);
721 struct usb_microdia *dev = video_get_drvdata(vdev);
723 return sprintf(buf, "%d\n", dev->vsettings.auto_whitebalance);
727 /**
728 * @brief store_autowhitebalance
730 * @param class Class device
731 * @param buf Buffer
732 * @param count Counter
734 * @returns Size of buffer
736 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
737 static ssize_t store_autowhitebalance(struct class_device *class, const char *buf, size_t count)
738 #else
739 static ssize_t store_autowhitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
740 #endif
742 struct video_device *vdev = to_video_device(class);
743 struct usb_microdia *dev = video_get_drvdata(vdev);
745 if (strncmp(buf, "1", 1) == 0)
746 dev->vsettings.auto_whitebalance = 1;
747 else if (strncmp(buf, "0", 1) == 0)
748 dev->vsettings.auto_whitebalance = 0;
749 else
750 return -EINVAL;
752 dev_microdia_camera_set_auto_whitebalance(dev);
754 return strlen(buf);
758 /**
759 * @brief show_register adress
761 * @param class Class device
763 * @retval buf Adress of buffer with the 'register' value
765 * @returns Size of buffer
767 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
768 static ssize_t show_register(struct class_device *class, char *buf)
769 #else
770 static ssize_t show_register(struct device *class, struct device_attribute *attr, char *buf)
771 #endif
773 __u8 buf1;
775 struct video_device *vdev = to_video_device(class);
776 struct usb_microdia *dev = video_get_drvdata(vdev);
778 usb_microdia_control_read(dev, dev->vsettings.reg, &buf1, 1);
780 dev->vsettings.val = buf1;
782 return sprintf(buf, "0x%x = 0x%x\n",dev->vsettings.reg, dev->vsettings.val);
786 /**
787 * @brief store_register
789 * @param class Class device
790 * @param buf Buffer
791 * @param count Counter
793 * @returns Size of buffer
795 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
796 static ssize_t store_register(struct class_device *class, const char *buf, size_t count)
797 #else
798 static ssize_t store_register(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
799 #endif
801 char *endp;
802 unsigned long value;
803 __u8 buf1;
805 struct video_device *vdev = to_video_device(class);
806 struct usb_microdia *dev = video_get_drvdata(vdev);
808 value = simple_strtoul(buf, &endp, 16);
810 dev->vsettings.val = (int) value;
811 buf1 = dev->vsettings.val;
812 usb_microdia_control_write(dev, dev->vsettings.reg, &buf1, 1);
814 return strlen(buf);
817 /**
818 * @brief show_adress
820 * @param class Class device
822 * @retval buf Buffer
824 * @returns Size of buffer
826 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
827 static ssize_t show_adress(struct class_device *class, char *buf)
828 #else
829 static ssize_t show_adress(struct device *class, struct device_attribute *attr, char *buf)
830 #endif
832 struct video_device *vdev = to_video_device(class);
833 struct usb_microdia *dev = video_get_drvdata(vdev);
835 return sprintf(buf, "0x%x\n", dev->vsettings.reg);
839 /**
840 * @brief store_adress
842 * @param class Class device
843 * @param buf Buffer
844 * @param count Counter
846 * @returns Size of buffer
848 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
849 static ssize_t store_adress(struct class_device *class, const char *buf, size_t count)
850 #else
851 static ssize_t store_adress(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
852 #endif
854 char *endp;
855 unsigned long value;
857 struct video_device *vdev = to_video_device(class);
858 struct usb_microdia *dev = video_get_drvdata(vdev);
860 value = simple_strtoul(buf, &endp, 16);
862 dev->vsettings.reg = (int) value;
864 return strlen(buf);
867 /**
868 * @brief show_i2cadr
870 * @param class Class device
872 * @retval buf Buffer
874 * @returns Size of buffer
876 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
877 static ssize_t show_i2cadr(struct class_device *class, char *buf)
878 #else
879 static ssize_t show_i2cadr(struct device *class, struct device_attribute *attr, char *buf)
880 #endif
882 struct video_device *vdev = to_video_device(class);
883 struct usb_microdia *dev = video_get_drvdata(vdev);
885 return sprintf(buf, "0x%x\n", dev->vsettings.i2creg);
889 /**
890 * @brief store_i2cadr
892 * @param class Class device
893 * @param buf Buffer
894 * @param count Counter
896 * @returns Size of buffer
898 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
899 static ssize_t store_i2cadr(struct class_device *class, const char *buf, size_t count)
900 #else
901 static ssize_t store_i2cadr(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
902 #endif
904 char *endp;
905 unsigned long value;
907 struct video_device *vdev = to_video_device(class);
908 struct usb_microdia *dev = video_get_drvdata(vdev);
910 value = simple_strtoul(buf, &endp, 16);
912 dev->vsettings.i2creg = (int) value;
914 return strlen(buf);
917 /**
918 * @brief show_i2creg adress
920 * @param class Class device
922 * @retval buf Buffer
924 * @returns Size of buffer
926 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
927 static ssize_t show_i2creg(struct class_device *class, char *buf)
928 #else
929 static ssize_t show_i2creg(struct device *class, struct device_attribute *attr, char *buf)
930 #endif
932 __u8 buf1[8];
933 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
934 __u8 i2c_flags = SN9C20X_I2C_2WIRE;
936 struct video_device *vdev = to_video_device(class);
937 struct usb_microdia *dev = video_get_drvdata(vdev);
939 sn9c20x_read_i2c_data(dev, dev->vsettings.i2cslave /*sensor_slave_id*/,
940 dev->vsettings.reg, dev->vsettings.i2creg, i2c_flags, buf1);
942 dev->vsettings.i2cval = buf1[0];
943 return sprintf(buf, "I2C-register 0x%x = 0x%x 0x%x (%d)\n",
944 dev->vsettings.i2creg,buf1[0],buf1[1],dev->vsettings.reg);
945 // return strlen(buf);
949 /**
950 * @brief store_i2creg
952 * @param class Class device
953 * @param buf Buffer
954 * @param count Counter
956 * @returns Size of buffer
958 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
959 static ssize_t store_i2creg(struct class_device *class, const char *buf, size_t count)
960 #else
961 static ssize_t store_i2creg(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
962 #endif
964 char *endp;
965 unsigned long value;
967 __u8 buf1[5];
968 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
969 __u8 i2c_flags = SN9C20X_I2C_2WIRE;
971 struct video_device *vdev = to_video_device(class);
972 struct usb_microdia *dev = video_get_drvdata(vdev);
974 value = simple_strtoul(buf, &endp, 16);
976 dev->vsettings.i2cval = (int) value;
977 buf1[0] = ((dev->vsettings.i2cval & 0xff00) >> 8);
978 buf1[1] = (dev->vsettings.i2cval & 0xFF);
979 buf1[2] = 0;
980 buf1[3] = 0;
981 buf1[4] = 0;
983 sn9c20x_write_i2c_data(dev,dev->vsettings.i2cslave /*sensor_slave_id*/,
984 dev->vsettings.reg, dev->vsettings.i2creg, i2c_flags, buf1);
985 // sprintf(buf, "store_i2creg: set I2C-reg. 0x%x to 0x%x 0x%x (%d)\n",
986 // dev->vsettings.i2creg,buf1[0],buf1[1],dev->vsettings.reg);
987 return strlen(buf);
991 /**
992 * @brief store_i2c_slave_adr
994 * @param class Class device
995 * @param buf Buffer
996 * @param count Counter
998 * @returns Size of buffer
1000 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1001 static ssize_t store_i2c_slave_adr(struct class_device *class, const char *buf, size_t count)
1002 #else
1003 static ssize_t store_i2c_slave_adr(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
1004 #endif
1006 char *endp;
1007 unsigned long value;
1009 struct video_device *vdev = to_video_device(class);
1010 struct usb_microdia *dev = video_get_drvdata(vdev);
1012 value = simple_strtoul(buf, &endp, 16);
1014 dev->vsettings.i2cslave = (int) value;
1016 return strlen(buf);
1020 /**
1021 * @brief show_i2c_slave_adr
1023 * @param class Class device
1025 * @retval buf Buffer
1027 * @returns Size of buffer
1029 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1030 static ssize_t show_i2c_slave_adr(struct class_device *class, char *buf)
1031 #else
1032 static ssize_t show_i2c_slave_adr(struct device *class, struct device_attribute *attr, char *buf)
1033 #endif
1035 struct video_device *vdev = to_video_device(class);
1036 struct usb_microdia *dev = video_get_drvdata(vdev);
1038 return sprintf(buf, "0x%x\n", dev->vsettings.i2cslave);
1044 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1045 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
1046 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
1047 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
1048 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
1049 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
1050 static CLASS_DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Brightness exposure */
1051 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
1052 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
1053 static CLASS_DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
1054 //static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
1055 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
1056 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
1057 static CLASS_DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
1058 static CLASS_DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
1059 static CLASS_DEVICE_ATTR(adr, S_IRUGO | S_IWUGO, show_adress, store_adress); /**< Register adress */
1060 static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUGO, show_register, store_register); /**< Register value */
1061 static CLASS_DEVICE_ATTR(i2cadr, S_IRUGO | S_IWUGO, show_i2cadr, store_i2cadr); /**< I2C Register adress */
1062 static CLASS_DEVICE_ATTR(i2creg, S_IRUGO | S_IWUGO, show_i2creg, store_i2creg); /**< I2C Register value */
1063 static CLASS_DEVICE_ATTR(i2cslave, S_IRUGO | S_IWUGO, show_i2c_slave_adr, store_i2c_slave_adr); /**< I2C Slave adress */
1064 #else
1065 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
1066 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
1067 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
1068 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
1069 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
1070 static DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
1071 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
1072 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
1073 static DEVICE_ATTR(sharpness, S_IRUGO | S_IWUGO, show_sharpness, store_sharpness); /**< Sharpness value */
1074 //static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
1075 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal flip value */
1076 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical flip value */
1077 static DEVICE_ATTR(auto_exposure, S_IRUGO | S_IWUGO, show_autoexposure, store_autoexposure); /**< Automatic exposure control value */
1078 static DEVICE_ATTR(auto_whitebalance, S_IRUGO | S_IWUGO, show_autowhitebalance, store_autowhitebalance); /**< Automatic whitebalance control value */
1079 static DEVICE_ATTR(adr, S_IRUGO | S_IWUGO, show_adress, store_adress); /**< Register adress */
1080 static DEVICE_ATTR(reg, S_IRUGO | S_IWUGO, show_register, store_register); /**< Register value */
1081 static DEVICE_ATTR(i2cadr, S_IRUGO | S_IWUGO, show_i2cadr, store_i2cadr); /**< I2C Register adress */
1082 static DEVICE_ATTR(i2creg, S_IRUGO | S_IWUGO, show_i2creg, store_i2creg); /**< I2C Register value */
1083 static DEVICE_ATTR(i2cslave, S_IRUGO | S_IWUGO, show_i2c_slave_adr, store_i2c_slave_adr); /**< I2C Slave adress */
1084 #endif
1087 /**
1088 * @brief Create the 'sys' entries.
1090 * This function permits to create all the entries in the 'sys' filesystem.
1092 * @param vdev Video device structure
1094 * @returns 0 if all is OK
1096 int microdia_create_sysfs_files(struct video_device *vdev)
1098 int ret;
1100 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1101 ret = video_device_create_file(vdev, &class_device_attr_release);
1102 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
1103 ret = video_device_create_file(vdev, &class_device_attr_informations);
1104 ret = video_device_create_file(vdev, &class_device_attr_fps);
1105 ret = video_device_create_file(vdev, &class_device_attr_brightness);
1106 ret = video_device_create_file(vdev, &class_device_attr_exposure);
1107 ret = video_device_create_file(vdev, &class_device_attr_contrast);
1108 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
1109 ret = video_device_create_file(vdev, &class_device_attr_sharpness);
1110 /*ret = video_device_create_file(vdev, &class_device_attr_colour);*/
1111 ret = video_device_create_file(vdev, &class_device_attr_hflip);
1112 ret = video_device_create_file(vdev, &class_device_attr_vflip);
1113 ret = video_device_create_file(vdev, &class_device_attr_auto_exposure);
1114 ret = video_device_create_file(vdev, &class_device_attr_auto_whitebalance);
1115 ret = video_device_create_file(vdev, &class_device_attr_reg);
1116 ret = video_device_create_file(vdev, &class_device_attr_adr);
1117 ret = video_device_create_file(vdev, &class_device_attr_i2creg);
1118 ret = video_device_create_file(vdev, &class_device_attr_i2cadr);
1119 ret = video_device_create_file(vdev, &class_device_attr_i2cslave);
1120 #else
1121 ret = video_device_create_file(vdev, &dev_attr_release);
1122 ret = video_device_create_file(vdev, &dev_attr_videostatus);
1123 ret = video_device_create_file(vdev, &dev_attr_informations);
1124 ret = video_device_create_file(vdev, &dev_attr_fps);
1125 ret = video_device_create_file(vdev, &dev_attr_brightness);
1126 ret = video_device_create_file(vdev, &dev_attr_exposure);
1127 ret = video_device_create_file(vdev, &dev_attr_contrast);
1128 ret = video_device_create_file(vdev, &dev_attr_whitebalance);
1129 ret = video_device_create_file(vdev, &dev_attr_sharpness);
1130 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
1131 ret = video_device_create_file(vdev, &dev_attr_hflip);
1132 ret = video_device_create_file(vdev, &dev_attr_vflip);
1133 ret = video_device_create_file(vdev, &dev_attr_auto_exposure);
1134 ret = video_device_create_file(vdev, &dev_attr_auto_whitebalance);
1135 ret = video_device_create_file(vdev, &dev_attr_reg);
1136 ret = video_device_create_file(vdev, &dev_attr_adr);
1137 ret = video_device_create_file(vdev, &dev_attr_i2creg);
1138 ret = video_device_create_file(vdev, &dev_attr_i2cadr);
1139 ret = video_device_create_file(vdev, &dev_attr_i2cslave);
1140 #endif
1141 return ret;
1145 /**
1146 * @brief Remove the 'sys' entries.
1148 * This function permits to remove all the entries in the 'sys' filesystem.
1150 * @param vdev Video device structure
1152 * @returns 0 if all is OK
1154 void microdia_remove_sysfs_files(struct video_device *vdev)
1156 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1157 video_device_remove_file(vdev, &class_device_attr_release);
1158 video_device_remove_file(vdev, &class_device_attr_videostatus);
1159 video_device_remove_file(vdev, &class_device_attr_informations);
1160 video_device_remove_file(vdev, &class_device_attr_fps);
1161 video_device_remove_file(vdev, &class_device_attr_brightness);
1162 video_device_remove_file(vdev, &class_device_attr_exposure);
1163 video_device_remove_file(vdev, &class_device_attr_contrast);
1164 video_device_remove_file(vdev, &class_device_attr_whitebalance);
1165 video_device_remove_file(vdev, &class_device_attr_sharpness);
1166 /*video_device_remove_file(vdev, &class_device_attr_colour);*/
1167 video_device_remove_file(vdev, &class_device_attr_hflip);
1168 video_device_remove_file(vdev, &class_device_attr_vflip);
1169 video_device_remove_file(vdev, &class_device_attr_auto_exposure);
1170 video_device_remove_file(vdev, &class_device_attr_auto_whitebalance);
1171 video_device_remove_file(vdev, &class_device_attr_reg);
1172 video_device_remove_file(vdev, &class_device_attr_adr);
1173 video_device_remove_file(vdev, &class_device_attr_i2creg);
1174 video_device_remove_file(vdev, &class_device_attr_i2cadr);
1175 video_device_remove_file(vdev, &class_device_attr_i2cslave);
1176 #else
1177 video_device_remove_file(vdev, &dev_attr_release);
1178 video_device_remove_file(vdev, &dev_attr_videostatus);
1179 video_device_remove_file(vdev, &dev_attr_informations);
1180 video_device_remove_file(vdev, &dev_attr_fps);
1181 video_device_remove_file(vdev, &dev_attr_brightness);
1182 video_device_remove_file(vdev, &dev_attr_exposure);
1183 video_device_remove_file(vdev, &dev_attr_contrast);
1184 video_device_remove_file(vdev, &dev_attr_whitebalance);
1185 video_device_remove_file(vdev, &dev_attr_sharpness);
1186 /*video_device_remove_file(vdev, &dev_attr_colour);*/
1187 video_device_remove_file(vdev, &dev_attr_hflip);
1188 video_device_remove_file(vdev, &dev_attr_vflip);
1189 video_device_remove_file(vdev, &dev_attr_auto_exposure);
1190 video_device_remove_file(vdev, &dev_attr_auto_whitebalance);
1191 video_device_remove_file(vdev, &dev_attr_reg);
1192 video_device_remove_file(vdev, &dev_attr_adr);
1193 video_device_remove_file(vdev, &dev_attr_i2creg);
1194 video_device_remove_file(vdev, &dev_attr_i2cadr);
1195 video_device_remove_file(vdev, &dev_attr_i2cslave);
1196 #endif