2 * @file microdia-sysfs.c
3 * @author Nicolas VIVIEN
7 * @brief Driver for Microdia USB video camera
9 * @note Copyright (C) Nicolas VIVIEN
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
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>
44 extern const struct microdia_coord microdia_image_sizes
[MICRODIA_NBR_SIZES
];
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
)
59 static ssize_t
show_release(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
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
)
81 static ssize_t
show_videostatus(struct device
*class, struct device_attribute
*attr
, char *buf
)
84 struct video_device
*vdev
= to_video_device(class);
85 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
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
);
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
)
109 static ssize_t
show_informations(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
;
129 case V4L2_PIX_FMT_RGB24
:
130 pixelfmt
= palette_rgb24
;
133 case V4L2_PIX_FMT_YUYV
:
134 pixelfmt
= palette_yuyv
;
137 case V4L2_PIX_FMT_YUV420
:
138 pixelfmt
= palette_i420
;
142 switch (dev
->resolution
) {
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
;
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
;
166 "Asked resolution : %dx%d\n"
167 "Driver resolution : %dx%d\n"
168 "Webcam resolution : %dx%d\n"
172 "Brightness : 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
,
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
);
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
)
209 static ssize_t
show_fps(struct device
*class, struct device_attribute
*attr
, char *buf
)
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 * @brief show_rgb_gain
221 * @param class Class device
223 * @retval buf Address of buffer with the 'rgb_gain' value
225 * @returns Size of buffer
227 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
228 static ssize_t
show_rgb_gain(struct class_device
*class, char *buf
)
230 static ssize_t
show_rgb_gain(struct device
*class,
231 struct device_attribute
*attr
, char *buf
)
236 struct video_device
*vdev
= to_video_device(class);
237 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
238 rgb_gain
|= dev
->vsettings
.rgb_gain
[0] << 16;
239 rgb_gain
|= dev
->vsettings
.rgb_gain
[1] << 8;
240 rgb_gain
|= dev
->vsettings
.rgb_gain
[3];
241 return sprintf(buf
, "0x%06X\n", rgb_gain
);
245 * @brief store_exposure
247 * @param class Class device
249 * @param count Counter
251 * @returns Size of buffer
253 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
254 static ssize_t
store_rgb_gain(struct class_device
*class,
255 const char *buf
, size_t count
)
257 static ssize_t
store_rgb_gain(struct device
*class,
258 struct device_attribute
*attr
, const char *buf
, size_t count
)
262 unsigned long rgb_gain
;
264 struct video_device
*vdev
= to_video_device(class);
265 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
267 rgb_gain
= simple_strtoul(buf
, &endp
, 16);
269 dev
->vsettings
.rgb_gain
[0] = (rgb_gain
>> 16) & 0x7f;
270 dev
->vsettings
.rgb_gain
[1] = (rgb_gain
>> 8) & 0x7f;
271 dev
->vsettings
.rgb_gain
[2] = (rgb_gain
>> 8) & 0x7f;
272 dev
->vsettings
.rgb_gain
[3] = rgb_gain
& 0x7f;
274 dev_microdia_camera_set_rgb_gain(dev
);
280 * @brief show_exposure
282 * @param class Class device
284 * @retval buf Adress of buffer with the 'exposure' value
286 * @returns Size of buffer
288 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
289 static ssize_t
show_exposure(struct class_device
*class, char *buf
)
291 static ssize_t
show_exposure(struct device
*class, struct device_attribute
*attr
, char *buf
)
294 struct video_device
*vdev
= to_video_device(class);
295 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
297 return sprintf(buf
, "%X\n", dev
->vsettings
.exposure
);
301 * @brief store_exposure
303 * @param class Class device
305 * @param count Counter
307 * @returns Size of buffer
309 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
310 static ssize_t
store_exposure(struct class_device
*class, const char *buf
, size_t count
)
312 static ssize_t
store_exposure(struct device
*class, struct device_attribute
*attr
,
313 const char *buf
, size_t count
)
319 struct video_device
*vdev
= to_video_device(class);
320 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
322 value
= simple_strtoul(buf
, &endp
, 16);
324 dev
->vsettings
.exposure
= (int) value
;
326 dev_microdia_camera_set_exposure(dev
);
332 * @brief show_brightness
334 * @param class Class device
336 * @retval buf Adress of buffer with the 'brightness' value
338 * @returns Size of buffer
340 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
341 static ssize_t
show_brightness(struct class_device
*class, char *buf
)
343 static ssize_t
show_brightness(struct device
*class, struct device_attribute
*attr
, char *buf
)
346 struct video_device
*vdev
= to_video_device(class);
347 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
349 return sprintf(buf
, "%X\n", dev
->vsettings
.brightness
);
353 * @brief store_brightness
355 * @param class Class device
357 * @param count Counter
359 * @returns Size of buffer
361 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
362 static ssize_t
store_brightness(struct class_device
*class, const char *buf
, size_t count
)
364 static ssize_t
store_brightness(struct device
*class, struct device_attribute
*attr
,
365 const char *buf
, size_t count
)
371 struct video_device
*vdev
= to_video_device(class);
372 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
374 value
= simple_strtoul(buf
, &endp
, 16);
376 dev
->vsettings
.brightness
= (int) value
;
378 dev_microdia_camera_set_brightness(dev
);
384 * @brief show_contrast
386 * @param class Class device
388 * @retval buf Adress of buffer with the 'contrast' value
390 * @returns Size of buffer
392 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
393 static ssize_t
show_contrast(struct class_device
*class, char *buf
)
395 static ssize_t
show_contrast(struct device
*class, struct device_attribute
*attr
, char *buf
)
398 struct video_device
*vdev
= to_video_device(class);
399 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
401 return sprintf(buf
, "%X\n", dev
->vsettings
.contrast
);
406 * @brief store_contrast
408 * @param class Class device
410 * @param count Counter
412 * @returns Size of buffer
414 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
415 static ssize_t
store_contrast(struct class_device
*class, const char *buf
, size_t count
)
417 static ssize_t
store_contrast(struct device
*class, struct device_attribute
*attr
,
418 const char *buf
, size_t count
)
424 struct video_device
*vdev
= to_video_device(class);
425 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
427 value
= simple_strtoul(buf
, &endp
, 16);
429 dev
->vsettings
.contrast
= (int) value
;
431 dev_microdia_camera_set_contrast(dev
);
432 // dev_microdia_set_camera_quality(dev);
439 * @brief show_whitebalance
441 * @param class Class device
443 * @retval buf Adress of buffer with the 'whitebalance' value
445 * @returns Size of buffer
447 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
448 static ssize_t
show_whitebalance(struct class_device
*class, char *buf
)
450 static ssize_t
show_whitebalance(struct device
*class, struct device_attribute
*attr
, char *buf
)
453 struct video_device
*vdev
= to_video_device(class);
454 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
456 return sprintf(buf
, "%X\n", dev
->vsettings
.whiteness
);
461 * @brief store_whitebalance
463 * @param class Class device
465 * @param count Counter
467 * @returns Size of buffer
469 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
470 static ssize_t
store_whitebalance(struct class_device
*class, const char *buf
, size_t count
)
472 static ssize_t
store_whitebalance(struct device
*class, struct device_attribute
*attr
,
473 const char *buf
, size_t count
)
479 struct video_device
*vdev
= to_video_device(class);
480 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
482 value
= simple_strtoul(buf
, &endp
, 16);
484 dev
->vsettings
.whiteness
= (int) value
;
486 dev_microdia_camera_set_gamma(dev
);
487 // dev_microdia_set_camera_quality(dev);
496 * @param class Class device
498 * @retval buf Adress of buffer with the 'colour' value
500 * @returns Size of buffer
502 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
503 static ssize_t show_colour(struct class_device *class, char *buf)
505 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
508 struct video_device *vdev = to_video_device(class);
509 struct usb_microdia *dev = video_get_drvdata(vdev);
511 return sprintf(buf, "%X\n", dev->vsettings.colour);
516 * @brief store_colour
518 * @param class Class device
520 * @param count Counter
522 * @returns Size of buffer
524 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
525 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
527 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
528 const char *buf, size_t count)
534 struct video_device *vdev = to_video_device(class);
535 struct usb_microdia *dev = video_get_drvdata(vdev);
537 value = simple_strtoul(buf, &endp, 16);
539 dev->vsettings.colour = (int) value;
541 // dev_microdia_set_camera_quality(dev);
549 * @brief show_sharpness
551 * @param class Class device
553 * @retval buf Adress of buffer with the 'sharpness' value
555 * @returns Size of buffer
557 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
558 static ssize_t
show_sharpness(struct class_device
*class, char *buf
)
560 static ssize_t
show_sharpness(struct device
*class, struct device_attribute
*attr
, char *buf
)
563 struct video_device
*vdev
= to_video_device(class);
564 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
566 return sprintf(buf
, "%X\n", dev
->vsettings
.sharpness
);
570 * @brief store_sharpness
572 * @param class Class device
574 * @param count Counter
576 * @returns Size of buffer
578 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
579 static ssize_t
store_sharpness(struct class_device
*class, const char *buf
, size_t count
)
581 static ssize_t
store_sharpness(struct device
*class, struct device_attribute
*attr
,
582 const char *buf
, size_t count
)
588 struct video_device
*vdev
= to_video_device(class);
589 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
591 value
= simple_strtoul(buf
, &endp
, 16);
593 if (value
< 0 || value
> 0x3f)
596 dev
->vsettings
.sharpness
= (int) value
;
598 dev_microdia_camera_set_sharpness(dev
);
607 * @param class Class device
609 * @retval buf Adress of buffer with the 'hflip' value
611 * @returns Size of buffer
613 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
614 static ssize_t
show_hflip(struct class_device
*class, char *buf
)
616 static ssize_t
show_hflip(struct device
*class, struct device_attribute
*attr
, char *buf
)
619 struct video_device
*vdev
= to_video_device(class);
620 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
622 return sprintf(buf
, "%d\n", dev
->vsettings
.hflip
);
629 * @param class Class device
631 * @param count Counter
633 * @returns Size of buffer
635 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
636 static ssize_t
store_hflip(struct class_device
*class, const char *buf
, size_t count
)
638 static ssize_t
store_hflip(struct device
*class, struct device_attribute
*attr
,
639 const char *buf
, size_t count
)
642 struct video_device
*vdev
= to_video_device(class);
643 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
645 if (strncmp(buf
, "1", 1) == 0)
646 dev
->vsettings
.hflip
= 1;
647 else if (strncmp(buf
, "0", 1) == 0)
648 dev
->vsettings
.hflip
= 0;
652 dev_microdia_camera_set_hvflip(dev
);
661 * @param class Class device
663 * @retval buf Adress of buffer with the 'vflip' value
665 * @returns Size of buffer
667 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
668 static ssize_t
show_vflip(struct class_device
*class, char *buf
)
670 static ssize_t
show_vflip(struct device
*class, struct device_attribute
*attr
, char *buf
)
673 struct video_device
*vdev
= to_video_device(class);
674 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
676 return sprintf(buf
, "%d\n", dev
->vsettings
.vflip
);
683 * @param class Class device
685 * @param count Counter
687 * @returns Size of buffer
689 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
690 static ssize_t
store_vflip(struct class_device
*class, const char *buf
, size_t count
)
692 static ssize_t
store_vflip(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
695 struct video_device
*vdev
= to_video_device(class);
696 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
698 if (strncmp(buf
, "1", 1) == 0)
699 dev
->vsettings
.vflip
= 1;
700 else if (strncmp(buf
, "0", 1) == 0)
701 dev
->vsettings
.vflip
= 0;
705 dev_microdia_camera_set_hvflip(dev
);
712 * @brief show_autoexposure
714 * @param class Class device
716 * @retval buf Adress of buffer with the 'hflip' value
718 * @returns Size of buffer
720 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
721 static ssize_t
show_autoexposure(struct class_device
*class, char *buf
)
723 static ssize_t
show_autoexposure(struct device
*class, struct device_attribute
*attr
, char *buf
)
726 struct video_device
*vdev
= to_video_device(class);
727 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
729 return sprintf(buf
, "%d\n", dev
->vsettings
.auto_exposure
);
734 * @brief store_autoexposure
736 * @param class Class device
738 * @param count Counter
740 * @returns Size of buffer
742 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
743 static ssize_t
store_autoexposure(struct class_device
*class, const char *buf
, size_t count
)
745 static ssize_t
store_autoexposure(struct device
*class, struct device_attribute
*attr
,
746 const char *buf
, size_t count
)
749 struct video_device
*vdev
= to_video_device(class);
750 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
752 if (strncmp(buf
, "1", 1) == 0)
753 dev
->vsettings
.auto_exposure
= 1;
754 else if (strncmp(buf
, "0", 1) == 0)
755 dev
->vsettings
.auto_exposure
= 0;
759 dev_microdia_camera_set_auto_exposure(dev
);
766 * @brief show_autowhitebalance
768 * @param class Class device
770 * @retval buf Adress of buffer with the 'vflip' value
772 * @returns Size of buffer
774 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
775 static ssize_t
show_autowhitebalance(struct class_device
*class, char *buf
)
777 static ssize_t
show_autowhitebalance(struct device
*class, struct device_attribute
*attr
, char *buf
)
780 struct video_device
*vdev
= to_video_device(class);
781 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
783 return sprintf(buf
, "%d\n", dev
->vsettings
.auto_whitebalance
);
788 * @brief store_autowhitebalance
790 * @param class Class device
792 * @param count Counter
794 * @returns Size of buffer
796 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
797 static ssize_t
store_autowhitebalance(struct class_device
*class, const char *buf
, size_t count
)
799 static ssize_t
store_autowhitebalance(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
802 struct video_device
*vdev
= to_video_device(class);
803 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
805 if (strncmp(buf
, "1", 1) == 0)
806 dev
->vsettings
.auto_whitebalance
= 1;
807 else if (strncmp(buf
, "0", 1) == 0)
808 dev
->vsettings
.auto_whitebalance
= 0;
812 dev_microdia_camera_set_auto_whitebalance(dev
);
819 * @brief show_register adress
821 * @param class Class device
823 * @retval buf Adress of buffer with the 'register' value
825 * @returns Size of buffer
827 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
828 static ssize_t
show_register(struct class_device
*class, char *buf
)
830 static ssize_t
show_register(struct device
*class, struct device_attribute
*attr
, char *buf
)
835 struct video_device
*vdev
= to_video_device(class);
836 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
838 usb_microdia_control_read(dev
, dev
->vsettings
.reg
, &buf1
, 1);
840 dev
->vsettings
.val
= buf1
;
842 return sprintf(buf
, "0x%x = 0x%x\n",dev
->vsettings
.reg
, dev
->vsettings
.val
);
847 * @brief store_register
849 * @param class Class device
851 * @param count Counter
853 * @returns Size of buffer
855 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
856 static ssize_t
store_register(struct class_device
*class, const char *buf
, size_t count
)
858 static ssize_t
store_register(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
865 struct video_device
*vdev
= to_video_device(class);
866 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
868 value
= simple_strtoul(buf
, &endp
, 16);
870 dev
->vsettings
.val
= (int) value
;
871 buf1
= dev
->vsettings
.val
;
872 usb_microdia_control_write(dev
, dev
->vsettings
.reg
, &buf1
, 1);
880 * @param class Class device
884 * @returns Size of buffer
886 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
887 static ssize_t
show_adress(struct class_device
*class, char *buf
)
889 static ssize_t
show_adress(struct device
*class, struct device_attribute
*attr
, char *buf
)
892 struct video_device
*vdev
= to_video_device(class);
893 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
895 return sprintf(buf
, "0x%x\n", dev
->vsettings
.reg
);
900 * @brief store_adress
902 * @param class Class device
904 * @param count Counter
906 * @returns Size of buffer
908 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
909 static ssize_t
store_adress(struct class_device
*class, const char *buf
, size_t count
)
911 static ssize_t
store_adress(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
917 struct video_device
*vdev
= to_video_device(class);
918 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
920 value
= simple_strtoul(buf
, &endp
, 16);
922 dev
->vsettings
.reg
= (int) value
;
930 * @param class Class device
934 * @returns Size of buffer
936 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
937 static ssize_t
show_i2cadr(struct class_device
*class, char *buf
)
939 static ssize_t
show_i2cadr(struct device
*class, struct device_attribute
*attr
, char *buf
)
942 struct video_device
*vdev
= to_video_device(class);
943 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
945 return sprintf(buf
, "0x%x\n", dev
->vsettings
.i2creg
);
950 * @brief store_i2cadr
952 * @param class Class device
954 * @param count Counter
956 * @returns Size of buffer
958 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
959 static ssize_t
store_i2cadr(struct class_device
*class, const char *buf
, size_t count
)
961 static ssize_t
store_i2cadr(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
967 struct video_device
*vdev
= to_video_device(class);
968 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
970 value
= simple_strtoul(buf
, &endp
, 16);
972 dev
->vsettings
.i2creg
= (int) value
;
978 * @brief show_i2creg adress
980 * @param class Class device
984 * @returns Size of buffer
986 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
987 static ssize_t
show_i2creg(struct class_device
*class, char *buf
)
989 static ssize_t
show_i2creg(struct device
*class, struct device_attribute
*attr
, char *buf
)
993 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
994 __u8 i2c_flags
= SN9C20X_I2C_2WIRE
;
996 struct video_device
*vdev
= to_video_device(class);
997 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
999 sn9c20x_read_i2c_data(dev
, dev
->vsettings
.i2cslave
/*sensor_slave_id*/,
1000 dev
->vsettings
.reg
, dev
->vsettings
.i2creg
, i2c_flags
, buf1
);
1002 dev
->vsettings
.i2cval
= buf1
[0];
1003 return sprintf(buf
, "I2C-register 0x%x = 0x%x 0x%x (%d)\n",
1004 dev
->vsettings
.i2creg
,buf1
[0],buf1
[1],dev
->vsettings
.reg
);
1005 // return strlen(buf);
1010 * @brief store_i2creg
1012 * @param class Class device
1014 * @param count Counter
1016 * @returns Size of buffer
1018 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1019 static ssize_t
store_i2creg(struct class_device
*class, const char *buf
, size_t count
)
1021 static ssize_t
store_i2creg(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
1025 unsigned long value
;
1028 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
1029 __u8 i2c_flags
= SN9C20X_I2C_2WIRE
;
1031 struct video_device
*vdev
= to_video_device(class);
1032 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
1034 value
= simple_strtoul(buf
, &endp
, 16);
1036 dev
->vsettings
.i2cval
= (int) value
;
1037 buf1
[0] = ((dev
->vsettings
.i2cval
& 0xff00) >> 8);
1038 buf1
[1] = (dev
->vsettings
.i2cval
& 0xFF);
1043 sn9c20x_write_i2c_data(dev
,dev
->vsettings
.i2cslave
/*sensor_slave_id*/,
1044 dev
->vsettings
.reg
, dev
->vsettings
.i2creg
, i2c_flags
, buf1
);
1045 // sprintf(buf, "store_i2creg: set I2C-reg. 0x%x to 0x%x 0x%x (%d)\n",
1046 // dev->vsettings.i2creg,buf1[0],buf1[1],dev->vsettings.reg);
1052 * @brief store_i2c_slave_adr
1054 * @param class Class device
1056 * @param count Counter
1058 * @returns Size of buffer
1060 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1061 static ssize_t
store_i2c_slave_adr(struct class_device
*class, const char *buf
, size_t count
)
1063 static ssize_t
store_i2c_slave_adr(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
1067 unsigned long value
;
1069 struct video_device
*vdev
= to_video_device(class);
1070 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
1072 value
= simple_strtoul(buf
, &endp
, 16);
1074 dev
->vsettings
.i2cslave
= (int) value
;
1081 * @brief show_i2c_slave_adr
1083 * @param class Class device
1085 * @retval buf Buffer
1087 * @returns Size of buffer
1089 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1090 static ssize_t
show_i2c_slave_adr(struct class_device
*class, char *buf
)
1092 static ssize_t
show_i2c_slave_adr(struct device
*class, struct device_attribute
*attr
, char *buf
)
1095 struct video_device
*vdev
= to_video_device(class);
1096 struct usb_microdia
*dev
= video_get_drvdata(vdev
);
1098 return sprintf(buf
, "0x%x\n", dev
->vsettings
.i2cslave
);
1104 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1105 static CLASS_DEVICE_ATTR(release
, S_IRUGO
, show_release
, NULL
); /**< Release value */
1106 static CLASS_DEVICE_ATTR(videostatus
, S_IRUGO
, show_videostatus
, NULL
); /**< Video status */
1107 static CLASS_DEVICE_ATTR(informations
, S_IRUGO
, show_informations
, NULL
); /**< Informations */
1108 static CLASS_DEVICE_ATTR(fps
, S_IRUGO
, show_fps
, NULL
); /**< FPS value */
1109 static CLASS_DEVICE_ATTR(brightness
, S_IRUGO
| S_IWUGO
, show_brightness
, store_brightness
); /**< Brightness value */
1110 static CLASS_DEVICE_ATTR(rgb_gain
, S_IRUGO
| S_IWUGO
, show_rgb_gain
, store_rgb_gain
); /**< RGB Gain */
1111 static CLASS_DEVICE_ATTR(exposure
, S_IRUGO
| S_IWUGO
, show_exposure
, store_exposure
); /**< Brightness exposure */
1112 static CLASS_DEVICE_ATTR(contrast
, S_IRUGO
| S_IWUGO
, show_contrast
, store_contrast
); /**< Contrast value */
1113 static CLASS_DEVICE_ATTR(whitebalance
, S_IRUGO
| S_IWUGO
, show_whitebalance
, store_whitebalance
); /**< Whitebalance value */
1114 static CLASS_DEVICE_ATTR(sharpness
, S_IRUGO
| S_IWUGO
, show_sharpness
, store_sharpness
); /**< Sharpness value */
1115 //static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
1116 static CLASS_DEVICE_ATTR(hflip
, S_IRUGO
| S_IWUGO
, show_hflip
, store_hflip
); /**< Horizontal flip value */
1117 static CLASS_DEVICE_ATTR(vflip
, S_IRUGO
| S_IWUGO
, show_vflip
, store_vflip
); /**< Vertical flip value */
1118 static CLASS_DEVICE_ATTR(auto_exposure
, S_IRUGO
| S_IWUGO
, show_autoexposure
, store_autoexposure
); /**< Automatic exposure control value */
1119 static CLASS_DEVICE_ATTR(auto_whitebalance
, S_IRUGO
| S_IWUGO
, show_autowhitebalance
, store_autowhitebalance
); /**< Automatic whitebalance control value */
1120 static CLASS_DEVICE_ATTR(adr
, S_IRUGO
| S_IWUGO
, show_adress
, store_adress
); /**< Register adress */
1121 static CLASS_DEVICE_ATTR(reg
, S_IRUGO
| S_IWUGO
, show_register
, store_register
); /**< Register value */
1122 static CLASS_DEVICE_ATTR(i2cadr
, S_IRUGO
| S_IWUGO
, show_i2cadr
, store_i2cadr
); /**< I2C Register adress */
1123 static CLASS_DEVICE_ATTR(i2creg
, S_IRUGO
| S_IWUGO
, show_i2creg
, store_i2creg
); /**< I2C Register value */
1124 static CLASS_DEVICE_ATTR(i2cslave
, S_IRUGO
| S_IWUGO
, show_i2c_slave_adr
, store_i2c_slave_adr
); /**< I2C Slave adress */
1126 static DEVICE_ATTR(release
, S_IRUGO
, show_release
, NULL
); /**< Release value */
1127 static DEVICE_ATTR(videostatus
, S_IRUGO
, show_videostatus
, NULL
); /**< Video status */
1128 static DEVICE_ATTR(informations
, S_IRUGO
, show_informations
, NULL
); /**< Informations */
1129 static DEVICE_ATTR(fps
, S_IRUGO
, show_fps
, NULL
); /**< FPS value */
1130 static DEVICE_ATTR(brightness
, S_IRUGO
| S_IWUGO
, show_brightness
, store_brightness
); /**< Brightness value */
1131 static DEVICE_ATTR(rgb_gain
, S_IRUGO
| S_IWUGO
, show_rgb_gain
, store_rgb_gain
); /**< RGB Gain */
1132 static DEVICE_ATTR(exposure
, S_IRUGO
| S_IWUGO
, show_exposure
, store_exposure
); /**< Exposure value */
1133 static DEVICE_ATTR(contrast
, S_IRUGO
| S_IWUGO
, show_contrast
, store_contrast
); /**< Contrast value */
1134 static DEVICE_ATTR(whitebalance
, S_IRUGO
| S_IWUGO
, show_whitebalance
, store_whitebalance
); /**< Whitebalance value */
1135 static DEVICE_ATTR(sharpness
, S_IRUGO
| S_IWUGO
, show_sharpness
, store_sharpness
); /**< Sharpness value */
1136 //static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
1137 static DEVICE_ATTR(hflip
, S_IRUGO
| S_IWUGO
, show_hflip
, store_hflip
); /**< Horizontal flip value */
1138 static DEVICE_ATTR(vflip
, S_IRUGO
| S_IWUGO
, show_vflip
, store_vflip
); /**< Vertical flip value */
1139 static DEVICE_ATTR(auto_exposure
, S_IRUGO
| S_IWUGO
, show_autoexposure
, store_autoexposure
); /**< Automatic exposure control value */
1140 static DEVICE_ATTR(auto_whitebalance
, S_IRUGO
| S_IWUGO
, show_autowhitebalance
, store_autowhitebalance
); /**< Automatic whitebalance control value */
1141 static DEVICE_ATTR(adr
, S_IRUGO
| S_IWUGO
, show_adress
, store_adress
); /**< Register adress */
1142 static DEVICE_ATTR(reg
, S_IRUGO
| S_IWUGO
, show_register
, store_register
); /**< Register value */
1143 static DEVICE_ATTR(i2cadr
, S_IRUGO
| S_IWUGO
, show_i2cadr
, store_i2cadr
); /**< I2C Register adress */
1144 static DEVICE_ATTR(i2creg
, S_IRUGO
| S_IWUGO
, show_i2creg
, store_i2creg
); /**< I2C Register value */
1145 static DEVICE_ATTR(i2cslave
, S_IRUGO
| S_IWUGO
, show_i2c_slave_adr
, store_i2c_slave_adr
); /**< I2C Slave adress */
1150 * @brief Create the 'sys' entries.
1152 * This function permits to create all the entries in the 'sys' filesystem.
1154 * @param vdev Video device structure
1156 * @returns 0 if all is OK
1158 int microdia_create_sysfs_files(struct video_device
*vdev
)
1162 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1163 ret
= video_device_create_file(vdev
, &class_device_attr_release
);
1164 ret
= video_device_create_file(vdev
, &class_device_attr_videostatus
);
1165 ret
= video_device_create_file(vdev
, &class_device_attr_informations
);
1166 ret
= video_device_create_file(vdev
, &class_device_attr_fps
);
1167 ret
= video_device_create_file(vdev
, &class_device_attr_brightness
);
1168 ret
= video_device_create_file(vdev
, &class_device_attr_rgb_gain
);
1169 ret
= video_device_create_file(vdev
, &class_device_attr_exposure
);
1170 ret
= video_device_create_file(vdev
, &class_device_attr_contrast
);
1171 ret
= video_device_create_file(vdev
, &class_device_attr_whitebalance
);
1172 ret
= video_device_create_file(vdev
, &class_device_attr_sharpness
);
1173 /*ret = video_device_create_file(vdev, &class_device_attr_colour);*/
1174 ret
= video_device_create_file(vdev
, &class_device_attr_hflip
);
1175 ret
= video_device_create_file(vdev
, &class_device_attr_vflip
);
1176 ret
= video_device_create_file(vdev
, &class_device_attr_auto_exposure
);
1177 ret
= video_device_create_file(vdev
, &class_device_attr_auto_whitebalance
);
1178 ret
= video_device_create_file(vdev
, &class_device_attr_reg
);
1179 ret
= video_device_create_file(vdev
, &class_device_attr_adr
);
1180 ret
= video_device_create_file(vdev
, &class_device_attr_i2creg
);
1181 ret
= video_device_create_file(vdev
, &class_device_attr_i2cadr
);
1182 ret
= video_device_create_file(vdev
, &class_device_attr_i2cslave
);
1184 ret
= video_device_create_file(vdev
, &dev_attr_release
);
1185 ret
= video_device_create_file(vdev
, &dev_attr_videostatus
);
1186 ret
= video_device_create_file(vdev
, &dev_attr_informations
);
1187 ret
= video_device_create_file(vdev
, &dev_attr_fps
);
1188 ret
= video_device_create_file(vdev
, &dev_attr_brightness
);
1189 ret
= video_device_create_file(vdev
, &dev_attr_rgb_gain
);
1190 ret
= video_device_create_file(vdev
, &dev_attr_exposure
);
1191 ret
= video_device_create_file(vdev
, &dev_attr_contrast
);
1192 ret
= video_device_create_file(vdev
, &dev_attr_whitebalance
);
1193 ret
= video_device_create_file(vdev
, &dev_attr_sharpness
);
1194 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
1195 ret
= video_device_create_file(vdev
, &dev_attr_hflip
);
1196 ret
= video_device_create_file(vdev
, &dev_attr_vflip
);
1197 ret
= video_device_create_file(vdev
, &dev_attr_auto_exposure
);
1198 ret
= video_device_create_file(vdev
, &dev_attr_auto_whitebalance
);
1199 ret
= video_device_create_file(vdev
, &dev_attr_reg
);
1200 ret
= video_device_create_file(vdev
, &dev_attr_adr
);
1201 ret
= video_device_create_file(vdev
, &dev_attr_i2creg
);
1202 ret
= video_device_create_file(vdev
, &dev_attr_i2cadr
);
1203 ret
= video_device_create_file(vdev
, &dev_attr_i2cslave
);
1210 * @brief Remove the 'sys' entries.
1212 * This function permits to remove all the entries in the 'sys' filesystem.
1214 * @param vdev Video device structure
1216 * @returns 0 if all is OK
1218 void microdia_remove_sysfs_files(struct video_device
*vdev
)
1220 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
1221 video_device_remove_file(vdev
, &class_device_attr_release
);
1222 video_device_remove_file(vdev
, &class_device_attr_videostatus
);
1223 video_device_remove_file(vdev
, &class_device_attr_informations
);
1224 video_device_remove_file(vdev
, &class_device_attr_fps
);
1225 video_device_remove_file(vdev
, &class_device_attr_brightness
);
1226 video_device_remove_file(vdev
, &class_device_attr_exposure
);
1227 video_device_remove_file(vdev
, &class_device_attr_rgb_gain
);
1228 video_device_remove_file(vdev
, &class_device_attr_contrast
);
1229 video_device_remove_file(vdev
, &class_device_attr_whitebalance
);
1230 video_device_remove_file(vdev
, &class_device_attr_sharpness
);
1231 /*video_device_remove_file(vdev, &class_device_attr_colour);*/
1232 video_device_remove_file(vdev
, &class_device_attr_hflip
);
1233 video_device_remove_file(vdev
, &class_device_attr_vflip
);
1234 video_device_remove_file(vdev
, &class_device_attr_auto_exposure
);
1235 video_device_remove_file(vdev
, &class_device_attr_auto_whitebalance
);
1236 video_device_remove_file(vdev
, &class_device_attr_reg
);
1237 video_device_remove_file(vdev
, &class_device_attr_adr
);
1238 video_device_remove_file(vdev
, &class_device_attr_i2creg
);
1239 video_device_remove_file(vdev
, &class_device_attr_i2cadr
);
1240 video_device_remove_file(vdev
, &class_device_attr_i2cslave
);
1242 video_device_remove_file(vdev
, &dev_attr_release
);
1243 video_device_remove_file(vdev
, &dev_attr_videostatus
);
1244 video_device_remove_file(vdev
, &dev_attr_informations
);
1245 video_device_remove_file(vdev
, &dev_attr_fps
);
1246 video_device_remove_file(vdev
, &dev_attr_brightness
);
1247 video_device_remove_file(vdev
, &dev_attr_rgb_gain
);
1248 video_device_remove_file(vdev
, &dev_attr_exposure
);
1249 video_device_remove_file(vdev
, &dev_attr_contrast
);
1250 video_device_remove_file(vdev
, &dev_attr_whitebalance
);
1251 video_device_remove_file(vdev
, &dev_attr_sharpness
);
1252 /*video_device_remove_file(vdev, &dev_attr_colour);*/
1253 video_device_remove_file(vdev
, &dev_attr_hflip
);
1254 video_device_remove_file(vdev
, &dev_attr_vflip
);
1255 video_device_remove_file(vdev
, &dev_attr_auto_exposure
);
1256 video_device_remove_file(vdev
, &dev_attr_auto_whitebalance
);
1257 video_device_remove_file(vdev
, &dev_attr_reg
);
1258 video_device_remove_file(vdev
, &dev_attr_adr
);
1259 video_device_remove_file(vdev
, &dev_attr_i2creg
);
1260 video_device_remove_file(vdev
, &dev_attr_i2cadr
);
1261 video_device_remove_file(vdev
, &dev_attr_i2cslave
);