Release 1.2.1
[syntekdriver.git] / stk11xx-sysfs.c
blobe51f3532df67bf28f0c84c0ce80cbc6a14808e7d
1 /**
2 * @file stk11xx-sysfs.c
3 * @author Nicolas VIVIEN
4 * @date 2006-10-23
5 * @version v1.2.0
7 * @brief Driver for Syntek 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$
29 * $Revision$
30 * $Author$
31 * $HeadURL$
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 "stk11xx.h"
49 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
52 /**
53 * @brief show_release
55 * @param class Class device
57 * @retval buf Adress of buffer with the 'release' value
59 * @returns Size of buffer
61 static ssize_t show_release(struct class_device *class, char *buf)
63 struct video_device *vdev = to_video_device(class);
64 struct usb_stk11xx *dev = video_get_drvdata(vdev);
66 return sprintf(buf, "%d\n", dev->release);
70 /**
71 * @brief show_videostatus
73 * @param class Class device
75 * @retval buf Adress of buffer with the 'videostatus' value
77 * @returns Size of buffer
79 static ssize_t show_videostatus(struct class_device *class, char *buf)
81 struct video_device *vdev = to_video_device(class);
82 struct usb_stk11xx *dev = video_get_drvdata(vdev);
84 return sprintf(buf,
85 "Nbr ISOC errors : %d\n"
86 "Nbr dropped frames : %d\n"
87 "Nbr dumped frames : %d\n",
88 dev->visoc_errors,
89 dev->vframes_error,
90 dev->vframes_dumped);
94 /**
95 * @brief show_informations
97 * @param class Class device
99 * @retval buf Adress of buffer with the 'informations' value
101 * @returns Size of buffer
103 static ssize_t show_informations(struct class_device *class, char *buf)
105 int width, height;
106 char *pixelfmt = NULL;
108 struct video_device *vdev = to_video_device(class);
109 struct usb_stk11xx *dev = video_get_drvdata(vdev);
111 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
112 char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits";
113 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
114 char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits";
115 char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits";
116 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
119 switch (dev->vsettings.palette) {
120 case STK11XX_PALETTE_RGB24:
121 pixelfmt = palette_rgb24;
122 break;
124 case STK11XX_PALETTE_RGB32:
125 pixelfmt = palette_rgb32;
126 break;
128 case STK11XX_PALETTE_BGR24:
129 pixelfmt = palette_bgr24;
130 break;
132 case STK11XX_PALETTE_BGR32:
133 pixelfmt = palette_bgr32;
134 break;
136 case STK11XX_PALETTE_UYVY:
137 pixelfmt = palette_uyvy;
138 break;
140 case STK11XX_PALETTE_YUYV:
141 pixelfmt = palette_yuyv;
142 break;
145 switch (dev->resolution) {
146 case STK11XX_80x60:
147 case STK11XX_128x96:
148 case STK11XX_160x120:
149 case STK11XX_213x160:
150 case STK11XX_320x240:
151 case STK11XX_640x480:
152 width = stk11xx_image_sizes[STK11XX_640x480].x;
153 height = stk11xx_image_sizes[STK11XX_640x480].y;
154 break;
156 case STK11XX_800x600:
157 case STK11XX_1024x768:
158 case STK11XX_1280x1024:
159 width = stk11xx_image_sizes[STK11XX_1280x1024].x;
160 height = stk11xx_image_sizes[STK11XX_1280x1024].y;
161 break;
163 default:
164 width = 0;
165 height = 0;
168 return sprintf(buf,
169 "Asked resolution : %dx%d\n"
170 "Driver resolution : %dx%d\n"
171 "Webcam resolution : %dx%d\n"
172 "\n"
173 "%s\n"
174 "\n"
175 "Brightness : 0x%X\n"
176 "Contrast : 0x%X\n"
177 "Whiteness : 0x%X\n"
178 "Colour : 0x%X\n",
179 dev->view.x, dev->view.y,
180 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
181 width, height,
182 pixelfmt,
183 0xFFFF & dev->vsettings.brightness,
184 0xFFFF & dev->vsettings.contrast,
185 0xFFFF & dev->vsettings.whiteness,
186 0xFFFF & dev->vsettings.colour);
190 /**
191 * @brief show_fps
193 * @param class Class device
195 * @retval buf Adress of buffer with the 'fps' value
197 * @returns Size of buffer
199 static ssize_t show_fps(struct class_device *class, char *buf)
201 struct video_device *vdev = to_video_device(class);
202 struct usb_stk11xx *dev = video_get_drvdata(vdev);
204 return sprintf(buf, "%d\n", dev->vsettings.fps);
208 /**
209 * @brief show_brightness
211 * @param class Class device
213 * @retval buf Adress of buffer with the 'brightness' value
215 * @returns Size of buffer
217 static ssize_t show_brightness(struct class_device *class, char *buf)
219 struct video_device *vdev = to_video_device(class);
220 struct usb_stk11xx *dev = video_get_drvdata(vdev);
222 return sprintf(buf, "%X\n", dev->vsettings.brightness);
226 /**
227 * @brief store_brightness
229 * @param class Class device
230 * @param buf Buffer
231 * @param count Counter
233 * @returns Size of buffer
235 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
237 char *endp;
238 unsigned long value;
240 struct video_device *vdev = to_video_device(class);
241 struct usb_stk11xx *dev = video_get_drvdata(vdev);
243 value = simple_strtoul(buf, &endp, 16);
245 dev->vsettings.brightness = (int) value;
247 dev_stk11xx_set_camera_quality(dev);
249 return strlen(buf);
252 /**
253 * @brief show_contrast
255 * @param class Class device
257 * @retval buf Adress of buffer with the 'contrast' value
259 * @returns Size of buffer
261 static ssize_t show_contrast(struct class_device *class, char *buf)
263 struct video_device *vdev = to_video_device(class);
264 struct usb_stk11xx *dev = video_get_drvdata(vdev);
266 return sprintf(buf, "%X\n", dev->vsettings.contrast);
270 /**
271 * @brief store_contrast
273 * @param class Class device
274 * @param buf Buffer
275 * @param count Counter
277 * @returns Size of buffer
279 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
281 char *endp;
282 unsigned long value;
284 struct video_device *vdev = to_video_device(class);
285 struct usb_stk11xx *dev = video_get_drvdata(vdev);
287 value = simple_strtoul(buf, &endp, 16);
289 dev->vsettings.contrast = (int) value;
291 dev_stk11xx_set_camera_quality(dev);
293 return strlen(buf);
297 /**
298 * @brief show_whitebalance
300 * @param class Class device
302 * @retval buf Adress of buffer with the 'whitebalance' value
304 * @returns Size of buffer
306 static ssize_t show_whitebalance(struct class_device *class, char *buf)
308 struct video_device *vdev = to_video_device(class);
309 struct usb_stk11xx *dev = video_get_drvdata(vdev);
311 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
315 /**
316 * @brief store_whitebalance
318 * @param class Class device
319 * @param buf Buffer
320 * @param count Counter
322 * @returns Size of buffer
324 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
326 char *endp;
327 unsigned long value;
329 struct video_device *vdev = to_video_device(class);
330 struct usb_stk11xx *dev = video_get_drvdata(vdev);
332 value = simple_strtoul(buf, &endp, 16);
334 dev->vsettings.whiteness = (int) value;
336 dev_stk11xx_set_camera_quality(dev);
338 return strlen(buf);
342 /**
343 * @brief show_colour
345 * @param class Class device
347 * @retval buf Adress of buffer with the 'colour' value
349 * @returns Size of buffer
351 static ssize_t show_colour(struct class_device *class, char *buf)
353 struct video_device *vdev = to_video_device(class);
354 struct usb_stk11xx *dev = video_get_drvdata(vdev);
356 return sprintf(buf, "%X\n", dev->vsettings.colour);
360 /**
361 * @brief store_colour
363 * @param class Class device
364 * @param buf Buffer
365 * @param count Counter
367 * @returns Size of buffer
369 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
371 char *endp;
372 unsigned long value;
374 struct video_device *vdev = to_video_device(class);
375 struct usb_stk11xx *dev = video_get_drvdata(vdev);
377 value = simple_strtoul(buf, &endp, 16);
379 dev->vsettings.colour = (int) value;
381 dev_stk11xx_set_camera_quality(dev);
383 return strlen(buf);
387 /**
388 * @brief show_hflip
390 * @param class Class device
392 * @retval buf Adress of buffer with the 'hflip' value
394 * @returns Size of buffer
396 static ssize_t show_hflip(struct class_device *class, char *buf)
398 struct video_device *vdev = to_video_device(class);
399 struct usb_stk11xx *dev = video_get_drvdata(vdev);
401 return sprintf(buf, "%d\n", dev->vsettings.hflip);
405 /**
406 * @brief store_hflip
408 * @param class Class device
409 * @param buf Buffer
410 * @param count Counter
412 * @returns Size of buffer
414 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
416 struct video_device *vdev = to_video_device(class);
417 struct usb_stk11xx *dev = video_get_drvdata(vdev);
419 if (strncmp(buf, "1", 1) == 0)
420 dev->vsettings.hflip = 1;
421 else if (strncmp(buf, "0", 1) == 0)
422 dev->vsettings.hflip = 0;
423 else
424 return -EINVAL;
426 return strlen(buf);
430 /**
431 * @brief show_vflip
433 * @param class Class device
435 * @retval buf Adress of buffer with the 'vflip' value
437 * @returns Size of buffer
439 static ssize_t show_vflip(struct class_device *class, char *buf)
441 struct video_device *vdev = to_video_device(class);
442 struct usb_stk11xx *dev = video_get_drvdata(vdev);
444 return sprintf(buf, "%d\n", dev->vsettings.vflip);
448 /**
449 * @brief store_vflip
451 * @param class Class device
452 * @param buf Buffer
453 * @param count Counter
455 * @returns Size of buffer
457 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
459 struct video_device *vdev = to_video_device(class);
460 struct usb_stk11xx *dev = video_get_drvdata(vdev);
462 if (strncmp(buf, "1", 1) == 0)
463 dev->vsettings.vflip = 1;
464 else if (strncmp(buf, "0", 1) == 0)
465 dev->vsettings.vflip = 0;
466 else
467 return -EINVAL;
469 return strlen(buf);
475 static ssize_t runtest(struct class_device *class, const char *buf, size_t count)
477 char *endp;
478 unsigned long value;
480 struct video_device *vdev = to_video_device(class);
481 struct usb_stk11xx *dev = video_get_drvdata(vdev);
483 value = simple_strtoul(buf, &endp, 16);
485 switch (value) {
486 case 1:
487 dev_stk11xx_set_camera_quality(dev);
488 STK_INFO("1 run\n");
489 break;
491 case 2:
492 dev_stk11xx_set_camera_fps(dev);
493 STK_INFO("2 run\n");
494 break;
496 case 3:
497 dev_stk11xx_camera_settings(dev);
498 STK_INFO("3 run\n");
499 break;
502 return strlen(buf);
507 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
508 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
509 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
510 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
511 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); /**< Brightness value */
512 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); /**< Contrast value */
513 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); /**< Whitebalance value */
514 static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); /**< Hue value */
515 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); /**< Horizontal filp value */
516 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); /**< Vertical filp value */
517 static CLASS_DEVICE_ATTR(test, S_IRUGO | S_IWUGO, NULL, runtest);
520 /**
521 * @brief Create the 'sys' entries.
523 * This function permits to create all the entries in the 'sys' filesystem.
525 * @param vdev Video device structure
527 * @returns 0 if all is OK
529 int stk11xx_create_sysfs_files(struct video_device *vdev)
531 int ret;
533 ret = video_device_create_file(vdev, &class_device_attr_release);
534 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
535 ret = video_device_create_file(vdev, &class_device_attr_informations);
536 ret = video_device_create_file(vdev, &class_device_attr_fps);
537 ret = video_device_create_file(vdev, &class_device_attr_brightness);
538 ret = video_device_create_file(vdev, &class_device_attr_contrast);
539 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
540 ret = video_device_create_file(vdev, &class_device_attr_colour);
541 ret = video_device_create_file(vdev, &class_device_attr_hflip);
542 ret = video_device_create_file(vdev, &class_device_attr_vflip);
543 ret = video_device_create_file(vdev, &class_device_attr_test);
545 return ret;
549 /**
550 * @brief Remove the 'sys' entries.
552 * This function permits to remove all the entries in the 'sys' filesystem.
554 * @param vdev Video device structure
556 * @returns 0 if all is OK
558 void stk11xx_remove_sysfs_files(struct video_device *vdev)
560 video_device_remove_file(vdev, &class_device_attr_release);
561 video_device_remove_file(vdev, &class_device_attr_videostatus);
562 video_device_remove_file(vdev, &class_device_attr_informations);
563 video_device_remove_file(vdev, &class_device_attr_fps);
564 video_device_remove_file(vdev, &class_device_attr_brightness);
565 video_device_remove_file(vdev, &class_device_attr_contrast);
566 video_device_remove_file(vdev, &class_device_attr_whitebalance);
567 video_device_remove_file(vdev, &class_device_attr_colour);
568 video_device_remove_file(vdev, &class_device_attr_hflip);
569 video_device_remove_file(vdev, &class_device_attr_vflip);
570 video_device_remove_file(vdev, &class_device_attr_test);