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
);
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
)
231 static ssize_t
show_exposure(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
241 * @brief store_exposure
243 * @param class Class device
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
)
252 static ssize_t
store_exposure(struct device
*class, struct device_attribute
*attr
,
253 const char *buf
, size_t count
)
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
);
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
)
283 static ssize_t
show_brightness(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
293 * @brief store_brightness
295 * @param class Class device
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
)
304 static ssize_t
store_brightness(struct device
*class, struct device_attribute
*attr
,
305 const char *buf
, size_t count
)
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
);
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
)
335 static ssize_t
show_contrast(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
346 * @brief store_contrast
348 * @param class Class device
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
)
357 static ssize_t
store_contrast(struct device
*class, struct device_attribute
*attr
,
358 const char *buf
, size_t count
)
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);
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
)
390 static ssize_t
show_whitebalance(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
401 * @brief store_whitebalance
403 * @param class Class device
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
)
412 static ssize_t
store_whitebalance(struct device
*class, struct device_attribute
*attr
,
413 const char *buf
, size_t count
)
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);
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)
445 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
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);
456 * @brief store_colour
458 * @param class Class device
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)
467 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
468 const char *buf, size_t count)
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);
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
)
500 static ssize_t
show_sharpness(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
510 * @brief store_sharpness
512 * @param class Class device
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
)
521 static ssize_t
store_sharpness(struct device
*class, struct device_attribute
*attr
,
522 const char *buf
, size_t count
)
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)
536 dev
->vsettings
.sharpness
= (int) value
;
538 dev_microdia_camera_set_sharpness(dev
);
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
)
556 static ssize_t
show_hflip(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
569 * @param class Class device
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
)
578 static ssize_t
store_hflip(struct device
*class, struct device_attribute
*attr
,
579 const char *buf
, size_t count
)
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;
592 dev_microdia_camera_set_hvflip(dev
);
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
)
610 static ssize_t
show_vflip(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
623 * @param class Class device
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
)
632 static ssize_t
store_vflip(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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;
645 dev_microdia_camera_set_hvflip(dev
);
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
)
663 static ssize_t
show_autoexposure(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
674 * @brief store_autoexposure
676 * @param class Class device
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
)
685 static ssize_t
store_autoexposure(struct device
*class, struct device_attribute
*attr
,
686 const char *buf
, size_t count
)
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;
699 dev_microdia_camera_set_auto_exposure(dev
);
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
)
717 static ssize_t
show_autowhitebalance(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
728 * @brief store_autowhitebalance
730 * @param class Class device
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
)
739 static ssize_t
store_autowhitebalance(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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;
752 dev_microdia_camera_set_auto_whitebalance(dev
);
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
)
770 static ssize_t
show_register(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
787 * @brief store_register
789 * @param class Class device
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
)
798 static ssize_t
store_register(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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);
820 * @param class Class device
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
)
829 static ssize_t
show_adress(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
840 * @brief store_adress
842 * @param class Class device
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
)
851 static ssize_t
store_adress(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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
;
870 * @param class Class device
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
)
879 static ssize_t
show_i2cadr(struct device
*class, struct device_attribute
*attr
, char *buf
)
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
);
890 * @brief store_i2cadr
892 * @param class Class device
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
)
901 static ssize_t
store_i2cadr(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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
;
918 * @brief show_i2creg adress
920 * @param class Class device
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
)
929 static ssize_t
show_i2creg(struct device
*class, struct device_attribute
*attr
, char *buf
)
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);
950 * @brief store_i2creg
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_i2creg(struct class_device
*class, const char *buf
, size_t count
)
961 static ssize_t
store_i2creg(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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);
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);
992 * @brief store_i2c_slave_adr
994 * @param class Class device
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
)
1003 static ssize_t
store_i2c_slave_adr(struct device
*class, struct device_attribute
*attr
, const char *buf
, size_t count
)
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
;
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
)
1032 static ssize_t
show_i2c_slave_adr(struct device
*class, struct device_attribute
*attr
, char *buf
)
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 */
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 */
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
)
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
);
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
);
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
);
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
);