SyntekUSBVideoCamera
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 
52 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
53 
54 
64 static 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 
82 static 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 
106 static 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 
159  case STK11XX_800x600:
160  case STK11XX_1024x768:
161  case STK11XX_1280x1024:
162  width = stk11xx_image_sizes[STK11XX_1280x1024].x;
163  height = stk11xx_image_sizes[STK11XX_1280x1024].y;
164  break;
165 
166  default:
167  width = 0;
168  height = 0;
169  }
170 
171  return sprintf(buf,
172  "Asked resolution : %dx%d\n"
173  "Driver resolution : %dx%d\n"
174  "Webcam resolution : %dx%d\n"
175  "\n"
176  "%s\n"
177  "\n"
178  "Brightness : 0x%X\n"
179  "Contrast : 0x%X\n"
180  "Whiteness : 0x%X\n"
181  "Colour : 0x%X\n",
182  dev->view.x, dev->view.y,
183  stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
184  width, height,
185  pixelfmt,
186  0xFFFF & dev->vsettings.brightness,
187  0xFFFF & dev->vsettings.contrast,
188  0xFFFF & dev->vsettings.whiteness,
189  0xFFFF & dev->vsettings.colour);
190 }
191 
192 
202 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
203 {
204  struct video_device *vdev = to_video_device(class);
205  struct usb_stk11xx *dev = video_get_drvdata(vdev);
206 
207  return sprintf(buf, "%d\n", dev->vsettings.fps);
208 }
209 
210 
220 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
221 {
222  struct video_device *vdev = to_video_device(class);
223  struct usb_stk11xx *dev = video_get_drvdata(vdev);
224 
225  return sprintf(buf, "%X\n", dev->vsettings.brightness);
226 }
227 
228 
238 static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
239  const char *buf, size_t count)
240 {
241  char *endp;
242  unsigned long value;
243 
244  struct video_device *vdev = to_video_device(class);
245  struct usb_stk11xx *dev = video_get_drvdata(vdev);
246 
247  value = simple_strtoul(buf, &endp, 16);
248 
249  dev->vsettings.brightness = (int) value;
250 
252 
253  return strlen(buf);
254 }
255 
265 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
266 {
267  struct video_device *vdev = to_video_device(class);
268  struct usb_stk11xx *dev = video_get_drvdata(vdev);
269 
270  return sprintf(buf, "%X\n", dev->vsettings.contrast);
271 }
272 
273 
283 static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
284  const char *buf, size_t count)
285 {
286  char *endp;
287  unsigned long value;
288 
289  struct video_device *vdev = to_video_device(class);
290  struct usb_stk11xx *dev = video_get_drvdata(vdev);
291 
292  value = simple_strtoul(buf, &endp, 16);
293 
294  dev->vsettings.contrast = (int) value;
295 
297 
298  return strlen(buf);
299 }
300 
301 
311 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
312 {
313  struct video_device *vdev = to_video_device(class);
314  struct usb_stk11xx *dev = video_get_drvdata(vdev);
315 
316  return sprintf(buf, "%X\n", dev->vsettings.whiteness);
317 }
318 
319 
329 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
330  const char *buf, size_t count)
331 {
332  char *endp;
333  unsigned long value;
334 
335  struct video_device *vdev = to_video_device(class);
336  struct usb_stk11xx *dev = video_get_drvdata(vdev);
337 
338  value = simple_strtoul(buf, &endp, 16);
339 
340  dev->vsettings.whiteness = (int) value;
341 
343 
344  return strlen(buf);
345 }
346 
347 
357 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
358 {
359  struct video_device *vdev = to_video_device(class);
360  struct usb_stk11xx *dev = video_get_drvdata(vdev);
361 
362  return sprintf(buf, "%X\n", dev->vsettings.colour);
363 }
364 
365 
375 static ssize_t store_colour(struct device *class, struct device_attribute *attr,
376  const char *buf, size_t count)
377 {
378  char *endp;
379  unsigned long value;
380 
381  struct video_device *vdev = to_video_device(class);
382  struct usb_stk11xx *dev = video_get_drvdata(vdev);
383 
384  value = simple_strtoul(buf, &endp, 16);
385 
386  dev->vsettings.colour = (int) value;
387 
389 
390  return strlen(buf);
391 }
392 
393 
403 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
404 {
405  struct video_device *vdev = to_video_device(class);
406  struct usb_stk11xx *dev = video_get_drvdata(vdev);
407 
408  return sprintf(buf, "%d\n", dev->vsettings.hflip);
409 }
410 
411 
421 static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
422  const char *buf, size_t count)
423 {
424  struct video_device *vdev = to_video_device(class);
425  struct usb_stk11xx *dev = video_get_drvdata(vdev);
426 
427  if (strncmp(buf, "1", 1) == 0)
428  dev->vsettings.hflip = 1;
429  else if (strncmp(buf, "0", 1) == 0)
430  dev->vsettings.hflip = 0;
431  else
432  return -EINVAL;
433 
434  return strlen(buf);
435 }
436 
437 
447 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
448 {
449  struct video_device *vdev = to_video_device(class);
450  struct usb_stk11xx *dev = video_get_drvdata(vdev);
451 
452  return sprintf(buf, "%d\n", dev->vsettings.vflip);
453 }
454 
455 
465 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
466 {
467  struct video_device *vdev = to_video_device(class);
468  struct usb_stk11xx *dev = video_get_drvdata(vdev);
469 
470  if (strncmp(buf, "1", 1) == 0)
471  dev->vsettings.vflip = 1;
472  else if (strncmp(buf, "0", 1) == 0)
473  dev->vsettings.vflip = 0;
474  else
475  return -EINVAL;
476 
477  return strlen(buf);
478 }
479 
480 
481 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL);
482 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL);
483 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL);
484 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL);
486 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast);
487 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance);
488 static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour);
489 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);
490 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);
502 int stk11xx_create_sysfs_files(struct video_device *vdev)
503 {
504  int ret;
505 
506  ret = device_create_file(&vdev->dev, &dev_attr_release);
507  ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
508  ret = device_create_file(&vdev->dev, &dev_attr_informations);
509  ret = device_create_file(&vdev->dev, &dev_attr_fps);
510  ret = device_create_file(&vdev->dev, &dev_attr_brightness);
511  ret = device_create_file(&vdev->dev, &dev_attr_contrast);
512  ret = device_create_file(&vdev->dev, &dev_attr_whitebalance);
513  ret = device_create_file(&vdev->dev, &dev_attr_colour);
514  ret = device_create_file(&vdev->dev, &dev_attr_hflip);
515  ret = device_create_file(&vdev->dev, &dev_attr_vflip);
516 
517  return ret;
518 }
519 
520 
530 void stk11xx_remove_sysfs_files(struct video_device *vdev)
531 {
532  device_remove_file(&vdev->dev, &dev_attr_release);
533  device_remove_file(&vdev->dev, &dev_attr_videostatus);
534  device_remove_file(&vdev->dev, &dev_attr_informations);
535  device_remove_file(&vdev->dev, &dev_attr_fps);
536  device_remove_file(&vdev->dev, &dev_attr_brightness);
537  device_remove_file(&vdev->dev, &dev_attr_contrast);
538  device_remove_file(&vdev->dev, &dev_attr_whitebalance);
539  device_remove_file(&vdev->dev, &dev_attr_colour);
540  device_remove_file(&vdev->dev, &dev_attr_hflip);
541  device_remove_file(&vdev->dev, &dev_attr_vflip);
542 }
543 
usb_stk11xx::vframes_dumped
int vframes_dumped
Definition: stk11xx.h:326
show_brightness
static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
show_brightness
Definition: stk11xx-sysfs.c:220
stk11xx_video::hflip
int hflip
Definition: stk11xx.h:285
DEVICE_ATTR
static DEVICE_ATTR(release, S_IRUGO, show_release, NULL)
show_contrast
static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
show_contrast
Definition: stk11xx-sysfs.c:265
colour
static int colour
Definition: stk11xx-usb.c:1071
stk11xx_video::brightness
int brightness
Definition: stk11xx.h:278
stk11xx_coord
Definition: stk11xx.h:267
store_contrast
static ssize_t store_contrast(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_contrast
Definition: stk11xx-sysfs.c:283
show_colour
static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
show_colour
Definition: stk11xx-sysfs.c:357
stk11xx_coord::x
int x
Definition: stk11xx.h:268
stk11xx_image_sizes
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
Definition: stk11xx-v4l.c:59
stk11xx.h
Driver for Syntek USB video camera.
stk11xx_remove_sysfs_files
void stk11xx_remove_sysfs_files(struct video_device *vdev)
Remove the 'sys' entries.
Definition: stk11xx-sysfs.c:530
show_hflip
static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
show_hflip
Definition: stk11xx-sysfs.c:403
brightness
static int brightness
Definition: stk11xx-usb.c:1053
store_vflip
static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_vflip
Definition: stk11xx-sysfs.c:465
show_release
static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
show_release
Definition: stk11xx-sysfs.c:64
show_videostatus
static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
show_videostatus
Definition: stk11xx-sysfs.c:82
stk11xx_video::colour
int colour
Definition: stk11xx.h:281
store_brightness
static ssize_t store_brightness(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_brightness
Definition: stk11xx-sysfs.c:238
store_hflip
static ssize_t store_hflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_hflip
Definition: stk11xx-sysfs.c:421
usb_stk11xx::release
int release
Definition: stk11xx.h:306
stk11xx_video::vflip
int vflip
Definition: stk11xx.h:286
store_colour
static ssize_t store_colour(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_colour
Definition: stk11xx-sysfs.c:375
show_whitebalance
static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
show_whitebalance
Definition: stk11xx-sysfs.c:311
usb_stk11xx::vdev
struct video_device * vdev
Definition: stk11xx.h:302
stk11xx_video::palette
int palette
Definition: stk11xx.h:283
store_whitebalance
static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
store_whitebalance
Definition: stk11xx-sysfs.c:329
usb_stk11xx::vframes_error
int vframes_error
Definition: stk11xx.h:325
dev_stk11xx_set_camera_quality
int dev_stk11xx_set_camera_quality(struct usb_stk11xx *dev)
This function permits to modify the quality video of the camera.
Definition: stk11xx-dev.c:397
stk11xx_video::fps
int fps
Definition: stk11xx.h:277
stk11xx_video::contrast
int contrast
Definition: stk11xx.h:279
stk11xx_create_sysfs_files
int stk11xx_create_sysfs_files(struct video_device *vdev)
Create the 'sys' entries.
Definition: stk11xx-sysfs.c:502
usb_stk11xx
Definition: stk11xx.h:301
vflip
static int vflip
Definition: stk11xx-usb.c:1047
usb_stk11xx::vsettings
struct stk11xx_video vsettings
Definition: stk11xx.h:319
usb_stk11xx::visoc_errors
int visoc_errors
Definition: stk11xx.h:324
fps
static int fps
Definition: stk11xx-usb.c:1035
show_fps
static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
show_fps
Definition: stk11xx-sysfs.c:202
stk11xx_video::whiteness
int whiteness
Definition: stk11xx.h:280
stk11xx_coord::y
int y
Definition: stk11xx.h:269
contrast
static int contrast
Definition: stk11xx-usb.c:1065
hflip
static int hflip
Definition: stk11xx-usb.c:1041
show_vflip
static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
show_vflip
Definition: stk11xx-sysfs.c:447
show_informations
static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
show_informations
Definition: stk11xx-sysfs.c:106