SyntekUSBVideoCamera
|
00001 00034 #include <linux/module.h> 00035 #include <linux/init.h> 00036 #include <linux/kernel.h> 00037 #include <linux/version.h> 00038 #include <linux/errno.h> 00039 #include <linux/slab.h> 00040 #include <linux/kref.h> 00041 #include <linux/device.h> 00042 #include <linux/mm.h> 00043 00044 00045 #include <linux/usb.h> 00046 #include <media/v4l2-common.h> 00047 #include <media/v4l2-ioctl.h> 00048 00049 #include "stk11xx.h" 00050 00051 00052 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]; 00053 00054 00064 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf) 00065 { 00066 struct video_device *vdev = to_video_device(class); 00067 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00068 00069 return sprintf(buf, "%d\n", dev->release); 00070 } 00071 00072 00082 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf) 00083 { 00084 struct video_device *vdev = to_video_device(class); 00085 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00086 00087 return sprintf(buf, 00088 "Nbr ISOC errors : %d\n" 00089 "Nbr dropped frames : %d\n" 00090 "Nbr dumped frames : %d\n", 00091 dev->visoc_errors, 00092 dev->vframes_error, 00093 dev->vframes_dumped); 00094 } 00095 00096 00106 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf) 00107 { 00108 int width, height; 00109 char *pixelfmt = NULL; 00110 00111 struct video_device *vdev = to_video_device(class); 00112 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00113 00114 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits"; 00115 char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits"; 00116 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits"; 00117 char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits"; 00118 char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits"; 00119 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits"; 00120 00121 00122 switch (dev->vsettings.palette) { 00123 case STK11XX_PALETTE_RGB24: 00124 pixelfmt = palette_rgb24; 00125 break; 00126 00127 case STK11XX_PALETTE_RGB32: 00128 pixelfmt = palette_rgb32; 00129 break; 00130 00131 case STK11XX_PALETTE_BGR24: 00132 pixelfmt = palette_bgr24; 00133 break; 00134 00135 case STK11XX_PALETTE_BGR32: 00136 pixelfmt = palette_bgr32; 00137 break; 00138 00139 case STK11XX_PALETTE_UYVY: 00140 pixelfmt = palette_uyvy; 00141 break; 00142 00143 case STK11XX_PALETTE_YUYV: 00144 pixelfmt = palette_yuyv; 00145 break; 00146 } 00147 00148 switch (dev->resolution) { 00149 case STK11XX_80x60: 00150 case STK11XX_128x96: 00151 case STK11XX_160x120: 00152 case STK11XX_213x160: 00153 case STK11XX_320x240: 00154 case STK11XX_640x480: 00155 width = stk11xx_image_sizes[STK11XX_640x480].x; 00156 height = stk11xx_image_sizes[STK11XX_640x480].y; 00157 break; 00158 00159 case STK11XX_800x600: 00160 case STK11XX_1024x768: 00161 case STK11XX_1280x1024: 00162 width = stk11xx_image_sizes[STK11XX_1280x1024].x; 00163 height = stk11xx_image_sizes[STK11XX_1280x1024].y; 00164 break; 00165 00166 default: 00167 width = 0; 00168 height = 0; 00169 } 00170 00171 return sprintf(buf, 00172 "Asked resolution : %dx%d\n" 00173 "Driver resolution : %dx%d\n" 00174 "Webcam resolution : %dx%d\n" 00175 "\n" 00176 "%s\n" 00177 "\n" 00178 "Brightness : 0x%X\n" 00179 "Contrast : 0x%X\n" 00180 "Whiteness : 0x%X\n" 00181 "Colour : 0x%X\n", 00182 dev->view.x, dev->view.y, 00183 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y, 00184 width, height, 00185 pixelfmt, 00186 0xFFFF & dev->vsettings.brightness, 00187 0xFFFF & dev->vsettings.contrast, 00188 0xFFFF & dev->vsettings.whiteness, 00189 0xFFFF & dev->vsettings.colour); 00190 } 00191 00192 00202 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf) 00203 { 00204 struct video_device *vdev = to_video_device(class); 00205 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00206 00207 return sprintf(buf, "%d\n", dev->vsettings.fps); 00208 } 00209 00210 00220 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf) 00221 { 00222 struct video_device *vdev = to_video_device(class); 00223 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00224 00225 return sprintf(buf, "%X\n", dev->vsettings.brightness); 00226 } 00227 00228 00238 static ssize_t store_brightness(struct device *class, struct device_attribute *attr, 00239 const char *buf, size_t count) 00240 { 00241 char *endp; 00242 unsigned long value; 00243 00244 struct video_device *vdev = to_video_device(class); 00245 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00246 00247 value = simple_strtoul(buf, &endp, 16); 00248 00249 dev->vsettings.brightness = (int) value; 00250 00251 dev_stk11xx_set_camera_quality(dev); 00252 00253 return strlen(buf); 00254 } 00255 00265 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf) 00266 { 00267 struct video_device *vdev = to_video_device(class); 00268 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00269 00270 return sprintf(buf, "%X\n", dev->vsettings.contrast); 00271 } 00272 00273 00283 static ssize_t store_contrast(struct device *class, struct device_attribute *attr, 00284 const char *buf, size_t count) 00285 { 00286 char *endp; 00287 unsigned long value; 00288 00289 struct video_device *vdev = to_video_device(class); 00290 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00291 00292 value = simple_strtoul(buf, &endp, 16); 00293 00294 dev->vsettings.contrast = (int) value; 00295 00296 dev_stk11xx_set_camera_quality(dev); 00297 00298 return strlen(buf); 00299 } 00300 00301 00311 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf) 00312 { 00313 struct video_device *vdev = to_video_device(class); 00314 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00315 00316 return sprintf(buf, "%X\n", dev->vsettings.whiteness); 00317 } 00318 00319 00329 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr, 00330 const char *buf, size_t count) 00331 { 00332 char *endp; 00333 unsigned long value; 00334 00335 struct video_device *vdev = to_video_device(class); 00336 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00337 00338 value = simple_strtoul(buf, &endp, 16); 00339 00340 dev->vsettings.whiteness = (int) value; 00341 00342 dev_stk11xx_set_camera_quality(dev); 00343 00344 return strlen(buf); 00345 } 00346 00347 00357 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf) 00358 { 00359 struct video_device *vdev = to_video_device(class); 00360 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00361 00362 return sprintf(buf, "%X\n", dev->vsettings.colour); 00363 } 00364 00365 00375 static ssize_t store_colour(struct device *class, struct device_attribute *attr, 00376 const char *buf, size_t count) 00377 { 00378 char *endp; 00379 unsigned long value; 00380 00381 struct video_device *vdev = to_video_device(class); 00382 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00383 00384 value = simple_strtoul(buf, &endp, 16); 00385 00386 dev->vsettings.colour = (int) value; 00387 00388 dev_stk11xx_set_camera_quality(dev); 00389 00390 return strlen(buf); 00391 } 00392 00393 00403 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf) 00404 { 00405 struct video_device *vdev = to_video_device(class); 00406 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00407 00408 return sprintf(buf, "%d\n", dev->vsettings.hflip); 00409 } 00410 00411 00421 static ssize_t store_hflip(struct device *class, struct device_attribute *attr, 00422 const char *buf, size_t count) 00423 { 00424 struct video_device *vdev = to_video_device(class); 00425 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00426 00427 if (strncmp(buf, "1", 1) == 0) 00428 dev->vsettings.hflip = 1; 00429 else if (strncmp(buf, "0", 1) == 0) 00430 dev->vsettings.hflip = 0; 00431 else 00432 return -EINVAL; 00433 00434 return strlen(buf); 00435 } 00436 00437 00447 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf) 00448 { 00449 struct video_device *vdev = to_video_device(class); 00450 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00451 00452 return sprintf(buf, "%d\n", dev->vsettings.vflip); 00453 } 00454 00455 00465 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count) 00466 { 00467 struct video_device *vdev = to_video_device(class); 00468 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00469 00470 if (strncmp(buf, "1", 1) == 0) 00471 dev->vsettings.vflip = 1; 00472 else if (strncmp(buf, "0", 1) == 0) 00473 dev->vsettings.vflip = 0; 00474 else 00475 return -EINVAL; 00476 00477 return strlen(buf); 00478 } 00479 00480 00481 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); 00482 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); 00483 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); 00484 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); 00485 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); 00486 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); 00487 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); 00488 static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); 00489 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); 00490 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); 00502 int stk11xx_create_sysfs_files(struct video_device *vdev) 00503 { 00504 int ret; 00505 00506 ret = device_create_file(&vdev->dev, &dev_attr_release); 00507 ret = device_create_file(&vdev->dev, &dev_attr_videostatus); 00508 ret = device_create_file(&vdev->dev, &dev_attr_informations); 00509 ret = device_create_file(&vdev->dev, &dev_attr_fps); 00510 ret = device_create_file(&vdev->dev, &dev_attr_brightness); 00511 ret = device_create_file(&vdev->dev, &dev_attr_contrast); 00512 ret = device_create_file(&vdev->dev, &dev_attr_whitebalance); 00513 ret = device_create_file(&vdev->dev, &dev_attr_colour); 00514 ret = device_create_file(&vdev->dev, &dev_attr_hflip); 00515 ret = device_create_file(&vdev->dev, &dev_attr_vflip); 00516 00517 return ret; 00518 } 00519 00520 00530 void stk11xx_remove_sysfs_files(struct video_device *vdev) 00531 { 00532 device_remove_file(&vdev->dev, &dev_attr_release); 00533 device_remove_file(&vdev->dev, &dev_attr_videostatus); 00534 device_remove_file(&vdev->dev, &dev_attr_informations); 00535 device_remove_file(&vdev->dev, &dev_attr_fps); 00536 device_remove_file(&vdev->dev, &dev_attr_brightness); 00537 device_remove_file(&vdev->dev, &dev_attr_contrast); 00538 device_remove_file(&vdev->dev, &dev_attr_whitebalance); 00539 device_remove_file(&vdev->dev, &dev_attr_colour); 00540 device_remove_file(&vdev->dev, &dev_attr_hflip); 00541 device_remove_file(&vdev->dev, &dev_attr_vflip); 00542 } 00543