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 case STK11XX_720x576: 00159 width = stk11xx_image_sizes[STK11XX_720x576].x; 00160 height = stk11xx_image_sizes[STK11XX_720x576].y; 00161 break; 00162 case STK11XX_800x600: 00163 case STK11XX_1024x768: 00164 case STK11XX_1280x1024: 00165 width = stk11xx_image_sizes[STK11XX_1280x1024].x; 00166 height = stk11xx_image_sizes[STK11XX_1280x1024].y; 00167 break; 00168 00169 default: 00170 width = 0; 00171 height = 0; 00172 } 00173 00174 return sprintf(buf, 00175 "Asked resolution : %dx%d\n" 00176 "Driver resolution : %dx%d\n" 00177 "Webcam resolution : %dx%d\n" 00178 "\n" 00179 "%s\n" 00180 "\n" 00181 "Brightness : 0x%X\n" 00182 "Contrast : 0x%X\n" 00183 "Whiteness : 0x%X\n" 00184 "Colour : 0x%X\n", 00185 dev->view.x, dev->view.y, 00186 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y, 00187 width, height, 00188 pixelfmt, 00189 0xFFFF & dev->vsettings.brightness, 00190 0xFFFF & dev->vsettings.contrast, 00191 0xFFFF & dev->vsettings.whiteness, 00192 0xFFFF & dev->vsettings.colour); 00193 } 00194 00195 00205 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf) 00206 { 00207 struct video_device *vdev = to_video_device(class); 00208 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00209 00210 return sprintf(buf, "%d\n", dev->vsettings.fps); 00211 } 00212 00213 00223 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf) 00224 { 00225 struct video_device *vdev = to_video_device(class); 00226 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00227 00228 return sprintf(buf, "%X\n", dev->vsettings.brightness); 00229 } 00230 00231 00241 static ssize_t store_brightness(struct device *class, struct device_attribute *attr, 00242 const char *buf, size_t count) 00243 { 00244 char *endp; 00245 unsigned long value; 00246 00247 struct video_device *vdev = to_video_device(class); 00248 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00249 00250 value = simple_strtoul(buf, &endp, 16); 00251 00252 dev->vsettings.brightness = (int) value; 00253 00254 dev_stk11xx_set_camera_quality(dev); 00255 00256 return strlen(buf); 00257 } 00258 00268 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf) 00269 { 00270 struct video_device *vdev = to_video_device(class); 00271 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00272 00273 return sprintf(buf, "%X\n", dev->vsettings.contrast); 00274 } 00275 00276 00286 static ssize_t store_contrast(struct device *class, struct device_attribute *attr, 00287 const char *buf, size_t count) 00288 { 00289 char *endp; 00290 unsigned long value; 00291 00292 struct video_device *vdev = to_video_device(class); 00293 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00294 00295 value = simple_strtoul(buf, &endp, 16); 00296 00297 dev->vsettings.contrast = (int) value; 00298 00299 dev_stk11xx_set_camera_quality(dev); 00300 00301 return strlen(buf); 00302 } 00303 00304 00314 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf) 00315 { 00316 struct video_device *vdev = to_video_device(class); 00317 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00318 00319 return sprintf(buf, "%X\n", dev->vsettings.whiteness); 00320 } 00321 00322 00332 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr, 00333 const char *buf, size_t count) 00334 { 00335 char *endp; 00336 unsigned long value; 00337 00338 struct video_device *vdev = to_video_device(class); 00339 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00340 00341 value = simple_strtoul(buf, &endp, 16); 00342 00343 dev->vsettings.whiteness = (int) value; 00344 00345 dev_stk11xx_set_camera_quality(dev); 00346 00347 return strlen(buf); 00348 } 00349 00350 00360 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf) 00361 { 00362 struct video_device *vdev = to_video_device(class); 00363 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00364 00365 return sprintf(buf, "%X\n", dev->vsettings.colour); 00366 } 00367 00368 00378 static ssize_t store_colour(struct device *class, struct device_attribute *attr, 00379 const char *buf, size_t count) 00380 { 00381 char *endp; 00382 unsigned long value; 00383 00384 struct video_device *vdev = to_video_device(class); 00385 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00386 00387 value = simple_strtoul(buf, &endp, 16); 00388 00389 dev->vsettings.colour = (int) value; 00390 00391 dev_stk11xx_set_camera_quality(dev); 00392 00393 return strlen(buf); 00394 } 00395 00396 00406 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf) 00407 { 00408 struct video_device *vdev = to_video_device(class); 00409 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00410 00411 return sprintf(buf, "%d\n", dev->vsettings.hflip); 00412 } 00413 00414 00424 static ssize_t store_hflip(struct device *class, struct device_attribute *attr, 00425 const char *buf, size_t count) 00426 { 00427 struct video_device *vdev = to_video_device(class); 00428 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00429 00430 if (strncmp(buf, "1", 1) == 0) 00431 dev->vsettings.hflip = 1; 00432 else if (strncmp(buf, "0", 1) == 0) 00433 dev->vsettings.hflip = 0; 00434 else 00435 return -EINVAL; 00436 00437 return strlen(buf); 00438 } 00439 00440 00450 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf) 00451 { 00452 struct video_device *vdev = to_video_device(class); 00453 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00454 00455 return sprintf(buf, "%d\n", dev->vsettings.vflip); 00456 } 00457 00458 00468 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count) 00469 { 00470 struct video_device *vdev = to_video_device(class); 00471 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00472 00473 if (strncmp(buf, "1", 1) == 0) 00474 dev->vsettings.vflip = 1; 00475 else if (strncmp(buf, "0", 1) == 0) 00476 dev->vsettings.vflip = 0; 00477 else 00478 return -EINVAL; 00479 00480 return strlen(buf); 00481 } 00482 00483 00484 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); 00485 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); 00486 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); 00487 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); 00488 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); 00489 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); 00490 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); 00491 static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); 00492 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); 00493 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); 00505 int stk11xx_create_sysfs_files(struct video_device *vdev) 00506 { 00507 int ret; 00508 00509 ret = device_create_file(&vdev->dev, &dev_attr_release); 00510 ret = device_create_file(&vdev->dev, &dev_attr_videostatus); 00511 ret = device_create_file(&vdev->dev, &dev_attr_informations); 00512 ret = device_create_file(&vdev->dev, &dev_attr_fps); 00513 ret = device_create_file(&vdev->dev, &dev_attr_brightness); 00514 ret = device_create_file(&vdev->dev, &dev_attr_contrast); 00515 ret = device_create_file(&vdev->dev, &dev_attr_whitebalance); 00516 ret = device_create_file(&vdev->dev, &dev_attr_colour); 00517 ret = device_create_file(&vdev->dev, &dev_attr_hflip); 00518 ret = device_create_file(&vdev->dev, &dev_attr_vflip); 00519 00520 return ret; 00521 } 00522 00523 00533 void stk11xx_remove_sysfs_files(struct video_device *vdev) 00534 { 00535 device_remove_file(&vdev->dev, &dev_attr_release); 00536 device_remove_file(&vdev->dev, &dev_attr_videostatus); 00537 device_remove_file(&vdev->dev, &dev_attr_informations); 00538 device_remove_file(&vdev->dev, &dev_attr_fps); 00539 device_remove_file(&vdev->dev, &dev_attr_brightness); 00540 device_remove_file(&vdev->dev, &dev_attr_contrast); 00541 device_remove_file(&vdev->dev, &dev_attr_whitebalance); 00542 device_remove_file(&vdev->dev, &dev_attr_colour); 00543 device_remove_file(&vdev->dev, &dev_attr_hflip); 00544 device_remove_file(&vdev->dev, &dev_attr_vflip); 00545 } 00546