2 * @file stk11xx-sysfs.c
3 * @author Nicolas VIVIEN
7 * @brief Driver for Syntek 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
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>
49 extern const struct stk11xx_coord stk11xx_image_sizes
[STK11XX_NBR_SIZES
];
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
);
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
);
85 "Nbr ISOC errors : %d\n"
86 "Nbr dropped frames : %d\n"
87 "Nbr dumped frames : %d\n",
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
)
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
;
124 case STK11XX_PALETTE_RGB32
:
125 pixelfmt
= palette_rgb32
;
128 case STK11XX_PALETTE_BGR24
:
129 pixelfmt
= palette_bgr24
;
132 case STK11XX_PALETTE_BGR32
:
133 pixelfmt
= palette_bgr32
;
136 case STK11XX_PALETTE_UYVY
:
137 pixelfmt
= palette_uyvy
;
140 case STK11XX_PALETTE_YUYV
:
141 pixelfmt
= palette_yuyv
;
145 switch (dev
->resolution
) {
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
;
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
;
169 "Asked resolution : %dx%d\n"
170 "Driver resolution : %dx%d\n"
171 "Webcam resolution : %dx%d\n"
175 "Brightness : 0x%X\n"
179 dev
->view
.x
, dev
->view
.y
,
180 stk11xx_image_sizes
[dev
->resolution
].x
, stk11xx_image_sizes
[dev
->resolution
].y
,
183 0xFFFF & dev
->vsettings
.brightness
,
184 0xFFFF & dev
->vsettings
.contrast
,
185 0xFFFF & dev
->vsettings
.whiteness
,
186 0xFFFF & dev
->vsettings
.colour
);
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
);
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
);
227 * @brief store_brightness
229 * @param class Class device
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
)
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
);
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
);
271 * @brief store_contrast
273 * @param class Class device
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
)
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
);
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
);
316 * @brief store_whitebalance
318 * @param class Class device
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
)
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
);
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
);
361 * @brief store_colour
363 * @param class Class device
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
)
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
);
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
);
408 * @param class Class device
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;
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
);
451 * @param class Class device
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;
475 static ssize_t
runtest(struct class_device
*class, const char *buf
, size_t count
)
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);
487 dev_stk11xx_set_camera_quality(dev
);
492 dev_stk11xx_set_camera_fps(dev
);
497 dev_stk11xx_camera_settings(dev
);
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
);
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
)
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
);
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
);