Syntek USB Video Camera
stk11xx-sysfs.c
Go to the documentation of this file.
1
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>
42#include <linux/mm.h>
43
44
45#include <linux/usb.h>
46#include <media/v4l2-common.h>
47#include <media/v4l2-ioctl.h>
48
49#include "stk11xx.h"
50
51
52extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
53
54
64static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
65{
66 struct video_device *vdev = to_video_device(class);
67 struct usb_stk11xx *dev = video_get_drvdata(vdev);
68
69 return sprintf(buf, "%d\n", dev->release);
70}
71
72
82static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
83{
84 struct video_device *vdev = to_video_device(class);
85 struct usb_stk11xx *dev = video_get_drvdata(vdev);
86
87 return sprintf(buf,
88 "Nbr ISOC errors : %d\n"
89 "Nbr dropped frames : %d\n"
90 "Nbr dumped frames : %d\n",
91 dev->visoc_errors,
92 dev->vframes_error,
93 dev->vframes_dumped);
94}
95
96
106static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
107{
108 int width, height;
109 char *pixelfmt = NULL;
110
111 struct video_device *vdev = to_video_device(class);
112 struct usb_stk11xx *dev = video_get_drvdata(vdev);
113
114 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
115 char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits";
116 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
117 char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits";
118 char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits";
119 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
120
121
122 switch (dev->vsettings.palette) {
123 case STK11XX_PALETTE_RGB24:
124 pixelfmt = palette_rgb24;
125 break;
126
127 case STK11XX_PALETTE_RGB32:
128 pixelfmt = palette_rgb32;
129 break;
130
131 case STK11XX_PALETTE_BGR24:
132 pixelfmt = palette_bgr24;
133 break;
134
135 case STK11XX_PALETTE_BGR32:
136 pixelfmt = palette_bgr32;
137 break;
138
139 case STK11XX_PALETTE_UYVY:
140 pixelfmt = palette_uyvy;
141 break;
142
143 case STK11XX_PALETTE_YUYV:
144 pixelfmt = palette_yuyv;
145 break;
146 }
147
148 switch (dev->resolution) {
149 case STK11XX_80x60:
150 case STK11XX_128x96:
151 case STK11XX_160x120:
152 case STK11XX_213x160:
153 case STK11XX_320x240:
154 case STK11XX_640x480:
155 width = stk11xx_image_sizes[STK11XX_640x480].x;
156 height = stk11xx_image_sizes[STK11XX_640x480].y;
157 break;
158 case STK11XX_720x576:
159 width = stk11xx_image_sizes[STK11XX_720x576].x;
160 height = stk11xx_image_sizes[STK11XX_720x576].y;
161 break;
162 case STK11XX_800x600:
163 case STK11XX_1024x768:
164 case STK11XX_1280x1024:
165 width = stk11xx_image_sizes[STK11XX_1280x1024].x;
166 height = stk11xx_image_sizes[STK11XX_1280x1024].y;
167 break;
168
169 default:
170 width = 0;
171 height = 0;
172 }
173
174 return sprintf(buf,
175 "Asked resolution : %dx%d\n"
176 "Driver resolution : %dx%d\n"
177 "Webcam resolution : %dx%d\n"
178 "\n"
179 "%s\n"
180 "\n"
181 "Brightness : 0x%X\n"
182 "Contrast : 0x%X\n"
183 "Whiteness : 0x%X\n"
184 "Colour : 0x%X\n",
185 dev->view.x, dev->view.y,
186 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
187 width, height,
188 pixelfmt,
189 0xFFFF & dev->vsettings.brightness,
190 0xFFFF & dev->vsettings.contrast,
191 0xFFFF & dev->vsettings.whiteness,
192 0xFFFF & dev->vsettings.colour);
193}
194
195
205static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
206{
207 struct video_device *vdev = to_video_device(class);
208 struct usb_stk11xx *dev = video_get_drvdata(vdev);
209
210 return sprintf(buf, "%d\n", dev->vsettings.fps);
211}
212
213
223static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
224{
225 struct video_device *vdev = to_video_device(class);
226 struct usb_stk11xx *dev = video_get_drvdata(vdev);
227
228 return sprintf(buf, "%X\n", dev->vsettings.brightness);
229}
230
231
241static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
242 const char *buf, size_t count)
243{
244 char *endp;
245 unsigned long value;
246
247 struct video_device *vdev = to_video_device(class);
248 struct usb_stk11xx *dev = video_get_drvdata(vdev);
249
250 value = simple_strtoul(buf, &endp, 16);
251
252 dev->vsettings.brightness = (int) value;
253
255
256 return strlen(buf);
257}
258
268static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
269{
270 struct video_device *vdev = to_video_device(class);
271 struct usb_stk11xx *dev = video_get_drvdata(vdev);
272
273 return sprintf(buf, "%X\n", dev->vsettings.contrast);
274}
275
276
286static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
287 const char *buf, size_t count)
288{
289 char *endp;
290 unsigned long value;
291
292 struct video_device *vdev = to_video_device(class);
293 struct usb_stk11xx *dev = video_get_drvdata(vdev);
294
295 value = simple_strtoul(buf, &endp, 16);
296
297 dev->vsettings.contrast = (int) value;
298
300
301 return strlen(buf);
302}
303
304
314static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
315{
316 struct video_device *vdev = to_video_device(class);
317 struct usb_stk11xx *dev = video_get_drvdata(vdev);
318
319 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
320}
321
322
332static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
333 const char *buf, size_t count)
334{
335 char *endp;
336 unsigned long value;
337
338 struct video_device *vdev = to_video_device(class);
339 struct usb_stk11xx *dev = video_get_drvdata(vdev);
340
341 value = simple_strtoul(buf, &endp, 16);
342
343 dev->vsettings.whiteness = (int) value;
344
346
347 return strlen(buf);
348}
349
350
360static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
361{
362 struct video_device *vdev = to_video_device(class);
363 struct usb_stk11xx *dev = video_get_drvdata(vdev);
364
365 return sprintf(buf, "%X\n", dev->vsettings.colour);
366}
367
368
378static ssize_t store_colour(struct device *class, struct device_attribute *attr,
379 const char *buf, size_t count)
380{
381 char *endp;
382 unsigned long value;
383
384 struct video_device *vdev = to_video_device(class);
385 struct usb_stk11xx *dev = video_get_drvdata(vdev);
386
387 value = simple_strtoul(buf, &endp, 16);
388
389 dev->vsettings.colour = (int) value;
390
392
393 return strlen(buf);
394}
395
396
406static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
407{
408 struct video_device *vdev = to_video_device(class);
409 struct usb_stk11xx *dev = video_get_drvdata(vdev);
410
411 return sprintf(buf, "%d\n", dev->vsettings.hflip);
412}
413
414
424static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
425 const char *buf, size_t count)
426{
427 struct video_device *vdev = to_video_device(class);
428 struct usb_stk11xx *dev = video_get_drvdata(vdev);
429
430 if (strncmp(buf, "1", 1) == 0)
431 dev->vsettings.hflip = 1;
432 else if (strncmp(buf, "0", 1) == 0)
433 dev->vsettings.hflip = 0;
434 else
435 return -EINVAL;
436
437 return strlen(buf);
438}
439
440
450static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
451{
452 struct video_device *vdev = to_video_device(class);
453 struct usb_stk11xx *dev = video_get_drvdata(vdev);
454
455 return sprintf(buf, "%d\n", dev->vsettings.vflip);
456}
457
458
468static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
469{
470 struct video_device *vdev = to_video_device(class);
471 struct usb_stk11xx *dev = video_get_drvdata(vdev);
472
473 if (strncmp(buf, "1", 1) == 0)
474 dev->vsettings.vflip = 1;
475 else if (strncmp(buf, "0", 1) == 0)
476 dev->vsettings.vflip = 0;
477 else
478 return -EINVAL;
479
480 return strlen(buf);
481}
482
483
484static DEVICE_ATTR(release, S_IRUGO, show_release, NULL);
485static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL);
486static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL);
487static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL);
489static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast);
490static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance);
491static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour);
492static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);
493static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);
505int stk11xx_create_sysfs_files(struct video_device *vdev)
506{
507 int ret;
508
509 ret = device_create_file(&vdev->dev, &dev_attr_release);
510 ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
511 ret = device_create_file(&vdev->dev, &dev_attr_informations);
512 ret = device_create_file(&vdev->dev, &dev_attr_fps);
513 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
514 ret = device_create_file(&vdev->dev, &dev_attr_contrast);
515 ret = device_create_file(&vdev->dev, &dev_attr_whitebalance);
516 ret = device_create_file(&vdev->dev, &dev_attr_colour);
517 ret = device_create_file(&vdev->dev, &dev_attr_hflip);
518 ret = device_create_file(&vdev->dev, &dev_attr_vflip);
519
520 return ret;
521}
522
523
533void stk11xx_remove_sysfs_files(struct video_device *vdev)
534{
535 device_remove_file(&vdev->dev, &dev_attr_release);
536 device_remove_file(&vdev->dev, &dev_attr_videostatus);
537 device_remove_file(&vdev->dev, &dev_attr_informations);
538 device_remove_file(&vdev->dev, &dev_attr_fps);
539 device_remove_file(&vdev->dev, &dev_attr_brightness);
540 device_remove_file(&vdev->dev, &dev_attr_contrast);
541 device_remove_file(&vdev->dev, &dev_attr_whitebalance);
542 device_remove_file(&vdev->dev, &dev_attr_colour);
543 device_remove_file(&vdev->dev, &dev_attr_hflip);
544 device_remove_file(&vdev->dev, &dev_attr_vflip);
545}
546
int dev_stk11xx_set_camera_quality(struct usb_stk11xx *dev)
This function permits to modify the quality video of the camera.
static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
show_videostatus
static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_vflip
static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
show_brightness
static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
show_whitebalance
static ssize_t store_contrast(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_contrast
static ssize_t store_hflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_hflip
int stk11xx_create_sysfs_files(struct video_device *vdev)
Create the 'sys' entries.
void stk11xx_remove_sysfs_files(struct video_device *vdev)
Remove the 'sys' entries.
static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
show_contrast
static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
show_release
static ssize_t store_brightness(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_brightness
static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
show_hflip
static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
show_informations
static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
show_colour
static DEVICE_ATTR(release, S_IRUGO, show_release, NULL)
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
Definition stk11xx-v4l.c:59
static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
show_vflip
static ssize_t store_colour(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_colour
static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_whitebalance
static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
show_fps
static int hflip
static int vflip
static int fps
static int colour
static int brightness
static int contrast
Driver for Syntek USB video camera.
struct video_device * vdev
Definition stk11xx.h:319
struct stk11xx_video vsettings
Definition stk11xx.h:336
int vframes_error
Definition stk11xx.h:342
int visoc_errors
Definition stk11xx.h:341
int release
Definition stk11xx.h:323
int vframes_dumped
Definition stk11xx.h:343