Added support for O_NONBLOCK in DQBUF ioctl
[microdia.git] / microdia-sysfs.c
blob0c19620a154a548e6d9caa317cff773218b327d8
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
27 * @par SubVersion
28 * $Date: 2008-02-05 10:10:01 +0100 (mar, 05 fév 2008) $
29 * $Revision: 72 $
30 * $Author: nicklas79 $
31 * $HeadURL: https://syntekdriver.svn.sourceforge.net/svnroot/syntekdriver/trunk/driver/microdia-sysfs.c $
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/version.h>
38 #include <linux/errno.h>
39 #include <linux/slab.h>
40 #include <linux/kref.h>
41 #include <linux/device.h>
43 #include <linux/usb.h>
44 #include <media/v4l2-common.h>
46 #include "microdia.h"
47 #include "sn9c20x.h"
50 extern const struct microdia_coord microdia_image_sizes[MICRODIA_NBR_SIZES];
53 /**
54 * @brief show_release
56 * @param class Class device
58 * @retval buf Adress of buffer with the 'release' value
60 * @returns Size of buffer
62 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
63 static ssize_t show_release(struct class_device *class, char *buf)
64 #else
65 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
66 #endif
68 struct video_device *vdev = to_video_device(class);
69 struct usb_microdia *dev = video_get_drvdata(vdev);
71 return sprintf(buf, "%d\n", dev->release);
75 /**
76 * @brief show_videostatus
78 * @param class Class device
80 * @retval buf Adress of buffer with the 'videostatus' value
82 * @returns Size of buffer
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
85 static ssize_t show_videostatus(struct class_device *class, char *buf)
86 #else
87 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
88 #endif
90 struct video_device *vdev = to_video_device(class);
91 struct usb_microdia *dev = video_get_drvdata(vdev);
93 return sprintf(buf,
94 "Nbr ISOC errors : %d\n"
95 "Nbr dropped frames : %d\n"
96 "Nbr dumped frames : %d\n",
97 dev->visoc_errors,
98 dev->vframes_error,
99 dev->vframes_dumped);
103 /**
104 * @brief show_informations
106 * @param class Class device
108 * @retval buf Adress of buffer with the 'informations' value
110 * @returns Size of buffer
112 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
113 static ssize_t show_informations(struct class_device *class, char *buf)
114 #else
115 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
116 #endif
118 int width, height;
119 char *pixelfmt = NULL;
121 struct video_device *vdev = to_video_device(class);
122 struct usb_microdia *dev = video_get_drvdata(vdev);
124 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
125 char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits";
126 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
127 char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits";
128 char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits";
129 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
130 char *palette_i420 = "I420 - YUV 4:2:0 - 12 bits";
133 switch (dev->vsettings.palette) {
134 case MICRODIA_PALETTE_RGB24:
135 pixelfmt = palette_rgb24;
136 break;
138 case MICRODIA_PALETTE_RGB32:
139 pixelfmt = palette_rgb32;
140 break;
142 case MICRODIA_PALETTE_BGR24:
143 pixelfmt = palette_bgr24;
144 break;
146 case MICRODIA_PALETTE_BGR32:
147 pixelfmt = palette_bgr32;
148 break;
150 case MICRODIA_PALETTE_UYVY:
151 pixelfmt = palette_uyvy;
152 break;
154 case MICRODIA_PALETTE_YUYV:
155 pixelfmt = palette_yuyv;
156 break;
158 case MICRODIA_PALETTE_I420:
159 pixelfmt = palette_i420;
160 break;
163 switch (dev->resolution) {
164 case MICRODIA_80x60:
165 /*case MICRODIA_128x96:*/
166 case MICRODIA_160x120:
167 /*case MICRODIA_213x160: */
168 case MICRODIA_320x240:
169 case MICRODIA_640x480:
170 width = microdia_image_sizes[MICRODIA_640x480].x;
171 height = microdia_image_sizes[MICRODIA_640x480].y;
172 break;
174 case MICRODIA_800x600:
175 case MICRODIA_1024x768:
176 case MICRODIA_1280x1024:
177 width = microdia_image_sizes[MICRODIA_1280x1024].x;
178 height = microdia_image_sizes[MICRODIA_1280x1024].y;
179 break;
181 default:
182 width = 0;
183 height = 0;
186 return sprintf(buf,
187 "Asked resolution : %dx%d\n"
188 "Driver resolution : %dx%d\n"
189 "Webcam resolution : %dx%d\n"
190 "\n"
191 "%s\n"
192 "\n"
193 "Brightness : 0x%X\n"
194 "Contrast : 0x%X\n"
195 "Whiteness : 0x%X\n"
196 "Exposure : 0x%X\n",
197 dev->view.x, dev->view.y,
198 microdia_image_sizes[dev->resolution].x, microdia_image_sizes[dev->resolution].y,
199 width, height,
200 pixelfmt,
201 0xFFFF & dev->vsettings.brightness,
202 0xFFFF & dev->vsettings.contrast,
203 0xFFFF & dev->vsettings.whiteness,
204 0xFFFF & dev->vsettings.exposure);
208 /**
209 * @brief show_fps
211 * @param class Class device
213 * @retval buf Adress of buffer with the 'fps' value
215 * @returns Size of buffer
217 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
218 static ssize_t show_fps(struct class_device *class, char *buf)
219 #else
220 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
221 #endif
223 struct video_device *vdev = to_video_device(class);
224 struct usb_microdia *dev = video_get_drvdata(vdev);
226 return sprintf(buf, "%d\n", dev->vsettings.fps);
230 /**
231 * @brief show_exposure
233 * @param class Class device
235 * @retval buf Adress of buffer with the 'exposure' value
237 * @returns Size of buffer
239 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
240 static ssize_t show_exposure(struct class_device *class, char *buf)
241 #else
242 static ssize_t show_exposure(struct device *class, struct device_attribute *attr, char *buf)
243 #endif
245 struct video_device *vdev = to_video_device(class);
246 struct usb_microdia *dev = video_get_drvdata(vdev);
248 return sprintf(buf, "%X\n", dev->vsettings.exposure);
251 /**
252 * @brief store_exposure
254 * @param class Class device
255 * @param buf Buffer
256 * @param count Counter
258 * @returns Size of buffer
260 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
261 static ssize_t store_exposure(struct class_device *class, const char *buf, size_t count)
262 #else
263 static ssize_t store_exposure(struct device *class, struct device_attribute *attr,
264 const char *buf, size_t count)
265 #endif
267 char *endp;
268 unsigned long value;
270 struct video_device *vdev = to_video_device(class);
271 struct usb_microdia *dev = video_get_drvdata(vdev);
273 value = simple_strtoul(buf, &endp, 16);
275 dev->vsettings.exposure = (int) value;
277 dev_microdia_camera_set_exposure(dev);
279 return strlen(buf);
282 /**
283 * @brief show_brightness
285 * @param class Class device
287 * @retval buf Adress of buffer with the 'brightness' value
289 * @returns Size of buffer
291 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
292 static ssize_t show_brightness(struct class_device *class, char *buf)
293 #else
294 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
295 #endif
297 struct video_device *vdev = to_video_device(class);
298 struct usb_microdia *dev = video_get_drvdata(vdev);
300 return sprintf(buf, "%X\n", dev->vsettings.brightness);
303 /**
304 * @brief store_brightness
306 * @param class Class device
307 * @param buf Buffer
308 * @param count Counter
310 * @returns Size of buffer
312 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
313 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
314 #else
315 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
316 const char *buf, size_t count)
317 #endif
319 char *endp;
320 unsigned long value;
322 struct video_device *vdev = to_video_device(class);
323 struct usb_microdia *dev = video_get_drvdata(vdev);
325 value = simple_strtoul(buf, &endp, 16);
327 dev->vsettings.brightness = (int) value;
329 dev_microdia_camera_set_brightness(dev);
331 return strlen(buf);
334 /**
335 * @brief show_contrast
337 * @param class Class device
339 * @retval buf Adress of buffer with the 'contrast' value
341 * @returns Size of buffer
343 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
344 static ssize_t show_contrast(struct class_device *class, char *buf)
345 #else
346 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
347 #endif
349 struct video_device *vdev = to_video_device(class);
350 struct usb_microdia *dev = video_get_drvdata(vdev);
352 return sprintf(buf, "%X\n", dev->vsettings.contrast);
356 /**
357 * @brief store_contrast
359 * @param class Class device
360 * @param buf Buffer
361 * @param count Counter
363 * @returns Size of buffer
365 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
366 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
367 #else
368 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
369 const char *buf, size_t count)
370 #endif
372 char *endp;
373 unsigned long value;
375 struct video_device *vdev = to_video_device(class);
376 struct usb_microdia *dev = video_get_drvdata(vdev);
378 value = simple_strtoul(buf, &endp, 16);
380 dev->vsettings.contrast = (int) value;
382 dev_microdia_camera_set_contrast(dev);
383 // dev_microdia_set_camera_quality(dev);
385 return strlen(buf);
389 /**
390 * @brief show_whitebalance
392 * @param class Class device
394 * @retval buf Adress of buffer with the 'whitebalance' value
396 * @returns Size of buffer
398 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
399 static ssize_t show_whitebalance(struct class_device *class, char *buf)
400 #else
401 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
402 #endif
404 struct video_device *vdev = to_video_device(class);
405 struct usb_microdia *dev = video_get_drvdata(vdev);
407 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
411 /**
412 * @brief store_whitebalance
414 * @param class Class device
415 * @param buf Buffer
416 * @param count Counter
418 * @returns Size of buffer
420 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
421 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
422 #else
423 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
424 const char *buf, size_t count)
425 #endif
427 char *endp;
428 unsigned long value;
430 struct video_device *vdev = to_video_device(class);
431 struct usb_microdia *dev = video_get_drvdata(vdev);
433 value = simple_strtoul(buf, &endp, 16);
435 dev->vsettings.whiteness = (int) value;
437 dev_microdia_camera_set_gamma(dev);
438 // dev_microdia_set_camera_quality(dev);
440 return strlen(buf);
444 /**
445 * @brief show_colour
447 * @param class Class device
449 * @retval buf Adress of buffer with the 'colour' value
451 * @returns Size of buffer
453 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
454 static ssize_t show_colour(struct class_device *class, char *buf)
455 #else
456 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
457 #endif
459 struct video_device *vdev = to_video_device(class);
460 struct usb_microdia *dev = video_get_drvdata(vdev);
462 return sprintf(buf, "%X\n", dev->vsettings.colour);
466 /**
467 * @brief store_colour
469 * @param class Class device
470 * @param buf Buffer
471 * @param count Counter
473 * @returns Size of buffer
475 /*#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
476 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
477 #else
478 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
479 const char *buf, size_t count)
480 #endif
482 char *endp;
483 unsigned long value;
485 struct video_device *vdev = to_video_device(class);
486 struct usb_microdia *dev = video_get_drvdata(vdev);
488 value = simple_strtoul(buf, &endp, 16);
490 dev->vsettings.colour = (int) value;
492 // dev_microdia_set_camera_quality(dev);
494 return strlen(buf);
498 /**
499 * @brief show_hflip
501 * @param class Class device
503 * @retval buf Adress of buffer with the 'hflip' value
505 * @returns Size of buffer
507 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
508 static ssize_t show_hflip(struct class_device *class, char *buf)
509 #else
510 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
511 #endif
513 struct video_device *vdev = to_video_device(class);
514 struct usb_microdia *dev = video_get_drvdata(vdev);
516 return sprintf(buf, "%d\n", dev->vsettings.hflip);
520 /**
521 * @brief store_hflip
523 * @param class Class device
524 * @param buf Buffer
525 * @param count Counter
527 * @returns Size of buffer
529 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
530 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
531 #else
532 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
533 const char *buf, size_t count)
534 #endif
536 struct video_device *vdev = to_video_device(class);
537 struct usb_microdia *dev = video_get_drvdata(vdev);
539 if (strncmp(buf, "1", 1) == 0)
540 dev->vsettings.hflip = 1;
541 else if (strncmp(buf, "0", 1) == 0)
542 dev->vsettings.hflip = 0;
543 else
544 return -EINVAL;
546 return strlen(buf);
550 /**
551 * @brief show_vflip
553 * @param class Class device
555 * @retval buf Adress of buffer with the 'vflip' value
557 * @returns Size of buffer
559 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
560 static ssize_t show_vflip(struct class_device *class, char *buf)
561 #else
562 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
563 #endif
565 struct video_device *vdev = to_video_device(class);
566 struct usb_microdia *dev = video_get_drvdata(vdev);
568 return sprintf(buf, "%d\n", dev->vsettings.vflip);
572 /**
573 * @brief store_vflip
575 * @param class Class device
576 * @param buf Buffer
577 * @param count Counter
579 * @returns Size of buffer
581 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
582 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
583 #else
584 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
585 #endif
587 struct video_device *vdev = to_video_device(class);
588 struct usb_microdia *dev = video_get_drvdata(vdev);
590 if (strncmp(buf, "1", 1) == 0)
591 dev->vsettings.vflip = 1;
592 else if (strncmp(buf, "0", 1) == 0)
593 dev->vsettings.vflip = 0;
594 else
595 return -EINVAL;
597 return strlen(buf);
601 /**
602 * @brief show_register adress
604 * @param class Class device
606 * @retval buf Adress of buffer with the 'register' value
608 * @returns Size of buffer
610 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
611 static ssize_t show_register(struct class_device *class, char *buf)
612 #else
613 static ssize_t show_register(struct device *class, struct device_attribute *attr, char *buf)
614 #endif
616 __u8 buf1;
618 struct video_device *vdev = to_video_device(class);
619 struct usb_microdia *dev = video_get_drvdata(vdev);
621 usb_microdia_control_read(dev, dev->vsettings.reg, &buf1, 1);
623 dev->vsettings.val = buf1;
625 return sprintf(buf, "0x%x = 0x%x\n",dev->vsettings.reg, dev->vsettings.val);
629 /**
630 * @brief store_register
632 * @param class Class device
633 * @param buf Buffer
634 * @param count Counter
636 * @returns Size of buffer
638 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
639 static ssize_t store_register(struct class_device *class, const char *buf, size_t count)
640 #else
641 static ssize_t store_register(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
642 #endif
644 char *endp;
645 unsigned long value;
646 __u8 buf1;
648 struct video_device *vdev = to_video_device(class);
649 struct usb_microdia *dev = video_get_drvdata(vdev);
651 value = simple_strtoul(buf, &endp, 16);
653 dev->vsettings.val = (int) value;
654 buf1 = dev->vsettings.val;
655 usb_microdia_control_write(dev, dev->vsettings.reg, &buf1, 1);
657 return strlen(buf);
660 /**
661 * @brief show_adress
663 * @param class Class device
665 * @retval buf Buffer
667 * @returns Size of buffer
669 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
670 static ssize_t show_adress(struct class_device *class, char *buf)
671 #else
672 static ssize_t show_adress(struct device *class, struct device_attribute *attr, char *buf)
673 #endif
675 struct video_device *vdev = to_video_device(class);
676 struct usb_microdia *dev = video_get_drvdata(vdev);
678 return sprintf(buf, "0x%x\n", dev->vsettings.reg);
682 /**
683 * @brief store_adress
685 * @param class Class device
686 * @param buf Buffer
687 * @param count Counter
689 * @returns Size of buffer
691 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
692 static ssize_t store_adress(struct class_device *class, const char *buf, size_t count)
693 #else
694 static ssize_t store_adress(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
695 #endif
697 char *endp;
698 unsigned long value;
700 struct video_device *vdev = to_video_device(class);
701 struct usb_microdia *dev = video_get_drvdata(vdev);
703 value = simple_strtoul(buf, &endp, 16);
705 dev->vsettings.reg = (int) value;
707 return strlen(buf);
710 /**
711 * @brief show_i2cadr
713 * @param class Class device
715 * @retval buf Buffer
717 * @returns Size of buffer
719 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
720 static ssize_t show_i2cadr(struct class_device *class, char *buf)
721 #else
722 static ssize_t show_i2cadr(struct device *class, struct device_attribute *attr, char *buf)
723 #endif
725 struct video_device *vdev = to_video_device(class);
726 struct usb_microdia *dev = video_get_drvdata(vdev);
728 return sprintf(buf, "0x%x\n", dev->vsettings.i2creg);
732 /**
733 * @brief store_i2cadr
735 * @param class Class device
736 * @param buf Buffer
737 * @param count Counter
739 * @returns Size of buffer
741 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
742 static ssize_t store_i2cadr(struct class_device *class, const char *buf, size_t count)
743 #else
744 static ssize_t store_i2cadr(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
745 #endif
747 char *endp;
748 unsigned long value;
750 struct video_device *vdev = to_video_device(class);
751 struct usb_microdia *dev = video_get_drvdata(vdev);
753 value = simple_strtoul(buf, &endp, 16);
755 dev->vsettings.i2creg = (int) value;
757 return strlen(buf);
760 /**
761 * @brief show_i2creg adress
763 * @param class Class device
765 * @retval buf Buffer
767 * @returns Size of buffer
769 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
770 static ssize_t show_i2creg(struct class_device *class, char *buf)
771 #else
772 static ssize_t show_i2creg(struct device *class, struct device_attribute *attr, char *buf)
773 #endif
775 __u8 buf1[8];
776 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
777 __u8 i2c_flags = SN9C20X_I2C_2WIRE;
779 struct video_device *vdev = to_video_device(class);
780 struct usb_microdia *dev = video_get_drvdata(vdev);
782 sn9c20x_read_i2c_data(dev, dev->vsettings.i2cslave /*sensor_slave_id*/,
783 dev->vsettings.reg, dev->vsettings.i2creg, i2c_flags, buf1);
785 dev->vsettings.i2cval = buf1[0];
786 return sprintf(buf, "I2C-register 0x%x = 0x%x 0x%x (%d)\n",
787 dev->vsettings.i2creg,buf1[0],buf1[1],dev->vsettings.reg);
788 // return strlen(buf);
792 /**
793 * @brief store_i2creg
795 * @param class Class device
796 * @param buf Buffer
797 * @param count Counter
799 * @returns Size of buffer
801 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
802 static ssize_t store_i2creg(struct class_device *class, const char *buf, size_t count)
803 #else
804 static ssize_t store_i2creg(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
805 #endif
807 char *endp;
808 unsigned long value;
810 __u8 buf1[5];
811 // __u8 sensor_slave_id = 0x30; /* slave ID currently hard coded !! */
812 __u8 i2c_flags = SN9C20X_I2C_2WIRE;
814 struct video_device *vdev = to_video_device(class);
815 struct usb_microdia *dev = video_get_drvdata(vdev);
817 value = simple_strtoul(buf, &endp, 16);
819 dev->vsettings.i2cval = (int) value;
820 buf1[0] = ((dev->vsettings.i2cval & 0xff00) >> 8);
821 buf1[1] = (dev->vsettings.i2cval & 0xFF);
822 buf1[2] = 0;
823 buf1[3] = 0;
824 buf1[4] = 0;
826 sn9c20x_write_i2c_data(dev,dev->vsettings.i2cslave /*sensor_slave_id*/,
827 dev->vsettings.reg, dev->vsettings.i2creg, i2c_flags, buf1);
828 // sprintf(buf, "store_i2creg: set I2C-reg. 0x%x to 0x%x 0x%x (%d)\n",
829 // dev->vsettings.i2creg,buf1[0],buf1[1],dev->vsettings.reg);
830 return strlen(buf);
834 /**
835 * @brief store_i2c_slave_adr
837 * @param class Class device
838 * @param buf Buffer
839 * @param count Counter
841 * @returns Size of buffer
843 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
844 static ssize_t store_i2c_slave_adr(struct class_device *class, const char *buf, size_t count)
845 #else
846 static ssize_t store_i2c_slave_adr(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
847 #endif
849 char *endp;
850 unsigned long value;
852 struct video_device *vdev = to_video_device(class);
853 struct usb_microdia *dev = video_get_drvdata(vdev);
855 value = simple_strtoul(buf, &endp, 16);
857 dev->vsettings.i2cslave = (int) value;
859 return strlen(buf);
863 /**
864 * @brief show_i2c_slave_adr
866 * @param class Class device
868 * @retval buf Buffer
870 * @returns Size of buffer
872 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
873 static ssize_t show_i2c_slave_adr(struct class_device *class, char *buf)
874 #else
875 static ssize_t show_i2c_slave_adr(struct device *class, struct device_attribute *attr, char *buf)
876 #endif
878 struct video_device *vdev = to_video_device(class);
879 struct usb_microdia *dev = video_get_drvdata(vdev);
881 return sprintf(buf, "0x%x\n", dev->vsettings.i2cslave);
887 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
888 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
889 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
890 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
891 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
892 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
893 static CLASS_DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Brightness exposure */
894 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
895 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
896 //static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
897 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal filp value */
898 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical filp value */
899 static CLASS_DEVICE_ATTR(adr, S_IRUGO | S_IWUGO, show_adress, store_adress); /**< Register adress */
900 static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUGO, show_register, store_register); /**< Register value */
901 static CLASS_DEVICE_ATTR(i2cadr, S_IRUGO | S_IWUGO, show_i2cadr, store_i2cadr); /**< I2C Register adress */
902 static CLASS_DEVICE_ATTR(i2creg, S_IRUGO | S_IWUGO, show_i2creg, store_i2creg); /**< I2C Register value */
903 static CLASS_DEVICE_ATTR(i2cslave, S_IRUGO | S_IWUGO, show_i2c_slave_adr, store_i2c_slave_adr); /**< I2C Slave adress */
904 #else
905 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
906 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
907 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
908 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
909 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
910 static DEVICE_ATTR(exposure, S_IRUGO | S_IWUGO, show_exposure, store_exposure); /**< Exposure value */
911 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
912 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
913 //static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
914 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal filp value */
915 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical filp value */
916 static DEVICE_ATTR(adr, S_IRUGO | S_IWUGO, show_adress, store_adress); /**< Register adress */
917 static DEVICE_ATTR(reg, S_IRUGO | S_IWUGO, show_register, store_register); /**< Register value */
918 static DEVICE_ATTR(i2cadr, S_IRUGO | S_IWUGO, show_i2cadr, store_i2cadr); /**< I2C Register adress */
919 static DEVICE_ATTR(i2creg, S_IRUGO | S_IWUGO, show_i2creg, store_i2creg); /**< I2C Register value */
920 static DEVICE_ATTR(i2cslave, S_IRUGO | S_IWUGO, show_i2c_slave_adr, store_i2c_slave_adr); /**< I2C Slave adress */
921 #endif
924 /**
925 * @brief Create the 'sys' entries.
927 * This function permits to create all the entries in the 'sys' filesystem.
929 * @param vdev Video device structure
931 * @returns 0 if all is OK
933 int microdia_create_sysfs_files(struct video_device *vdev)
935 int ret;
937 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
938 ret = video_device_create_file(vdev, &class_device_attr_release);
939 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
940 ret = video_device_create_file(vdev, &class_device_attr_informations);
941 ret = video_device_create_file(vdev, &class_device_attr_fps);
942 ret = video_device_create_file(vdev, &class_device_attr_brightness);
943 ret = video_device_create_file(vdev, &class_device_attr_exposure);
944 ret = video_device_create_file(vdev, &class_device_attr_contrast);
945 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
946 /*ret = video_device_create_file(vdev, &class_device_attr_colour);*/
947 ret = video_device_create_file(vdev, &class_device_attr_hflip);
948 ret = video_device_create_file(vdev, &class_device_attr_vflip);
949 ret = video_device_create_file(vdev, &class_device_attr_reg);
950 ret = video_device_create_file(vdev, &class_device_attr_adr);
951 ret = video_device_create_file(vdev, &class_device_attr_i2creg);
952 ret = video_device_create_file(vdev, &class_device_attr_i2cadr);
953 ret = video_device_create_file(vdev, &class_device_attr_i2cslave);
954 #else
955 ret = video_device_create_file(vdev, &dev_attr_release);
956 ret = video_device_create_file(vdev, &dev_attr_videostatus);
957 ret = video_device_create_file(vdev, &dev_attr_informations);
958 ret = video_device_create_file(vdev, &dev_attr_fps);
959 ret = video_device_create_file(vdev, &dev_attr_brightness);
960 ret = video_device_create_file(vdev, &dev_attr_exposure);
961 ret = video_device_create_file(vdev, &dev_attr_contrast);
962 ret = video_device_create_file(vdev, &dev_attr_whitebalance);
963 /*ret = video_device_create_file(vdev, &dev_attr_colour);*/
964 ret = video_device_create_file(vdev, &dev_attr_hflip);
965 ret = video_device_create_file(vdev, &dev_attr_vflip);
966 ret = video_device_create_file(vdev, &dev_attr_reg);
967 ret = video_device_create_file(vdev, &dev_attr_adr);
968 ret = video_device_create_file(vdev, &dev_attr_i2creg);
969 ret = video_device_create_file(vdev, &dev_attr_i2cadr);
970 ret = video_device_create_file(vdev, &dev_attr_i2cslave);
971 #endif
972 return ret;
976 /**
977 * @brief Remove the 'sys' entries.
979 * This function permits to remove all the entries in the 'sys' filesystem.
981 * @param vdev Video device structure
983 * @returns 0 if all is OK
985 void microdia_remove_sysfs_files(struct video_device *vdev)
987 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
988 video_device_remove_file(vdev, &class_device_attr_release);
989 video_device_remove_file(vdev, &class_device_attr_videostatus);
990 video_device_remove_file(vdev, &class_device_attr_informations);
991 video_device_remove_file(vdev, &class_device_attr_fps);
992 video_device_remove_file(vdev, &class_device_attr_brightness);
993 video_device_remove_file(vdev, &class_device_attr_exposure);
994 video_device_remove_file(vdev, &class_device_attr_contrast);
995 video_device_remove_file(vdev, &class_device_attr_whitebalance);
996 /*video_device_remove_file(vdev, &class_device_attr_colour);*/
997 video_device_remove_file(vdev, &class_device_attr_hflip);
998 video_device_remove_file(vdev, &class_device_attr_vflip);
999 video_device_remove_file(vdev, &class_device_attr_reg);
1000 video_device_remove_file(vdev, &class_device_attr_adr);
1001 video_device_remove_file(vdev, &class_device_attr_i2creg);
1002 video_device_remove_file(vdev, &class_device_attr_i2cadr);
1003 video_device_remove_file(vdev, &class_device_attr_i2cslave);
1004 #else
1005 video_device_remove_file(vdev, &dev_attr_release);
1006 video_device_remove_file(vdev, &dev_attr_videostatus);
1007 video_device_remove_file(vdev, &dev_attr_informations);
1008 video_device_remove_file(vdev, &dev_attr_fps);
1009 video_device_remove_file(vdev, &dev_attr_brightness);
1010 video_device_remove_file(vdev, &dev_attr_exposure);
1011 video_device_remove_file(vdev, &dev_attr_contrast);
1012 video_device_remove_file(vdev, &dev_attr_whitebalance);
1013 /*video_device_remove_file(vdev, &dev_attr_colour);*/
1014 video_device_remove_file(vdev, &dev_attr_hflip);
1015 video_device_remove_file(vdev, &dev_attr_vflip);
1016 video_device_remove_file(vdev, &dev_attr_reg);
1017 video_device_remove_file(vdev, &dev_attr_adr);
1018 video_device_remove_file(vdev, &dev_attr_i2creg);
1019 video_device_remove_file(vdev, &dev_attr_i2cadr);
1020 video_device_remove_file(vdev, &dev_attr_i2cslave);
1021 #endif