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 00043 #include <linux/usb.h> 00044 #include <media/v4l2-common.h> 00045 00046 #include "stk11xx.h" 00047 00048 00049 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]; 00050 00051 00061 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00062 static ssize_t show_release(struct class_device *class, char *buf) 00063 #else 00064 static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf) 00065 #endif 00066 { 00067 struct video_device *vdev = to_video_device(class); 00068 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00069 00070 return sprintf(buf, "%d\n", dev->release); 00071 } 00072 00073 00083 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00084 static ssize_t show_videostatus(struct class_device *class, char *buf) 00085 #else 00086 static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf) 00087 #endif 00088 { 00089 struct video_device *vdev = to_video_device(class); 00090 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00091 00092 return sprintf(buf, 00093 "Nbr ISOC errors : %d\n" 00094 "Nbr dropped frames : %d\n" 00095 "Nbr dumped frames : %d\n", 00096 dev->visoc_errors, 00097 dev->vframes_error, 00098 dev->vframes_dumped); 00099 } 00100 00101 00111 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00112 static ssize_t show_informations(struct class_device *class, char *buf) 00113 #else 00114 static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf) 00115 #endif 00116 { 00117 int width, height; 00118 char *pixelfmt = NULL; 00119 00120 struct video_device *vdev = to_video_device(class); 00121 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00122 00123 char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits"; 00124 char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits"; 00125 char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits"; 00126 char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits"; 00127 char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits"; 00128 char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits"; 00129 00130 00131 switch (dev->vsettings.palette) { 00132 case STK11XX_PALETTE_RGB24: 00133 pixelfmt = palette_rgb24; 00134 break; 00135 00136 case STK11XX_PALETTE_RGB32: 00137 pixelfmt = palette_rgb32; 00138 break; 00139 00140 case STK11XX_PALETTE_BGR24: 00141 pixelfmt = palette_bgr24; 00142 break; 00143 00144 case STK11XX_PALETTE_BGR32: 00145 pixelfmt = palette_bgr32; 00146 break; 00147 00148 case STK11XX_PALETTE_UYVY: 00149 pixelfmt = palette_uyvy; 00150 break; 00151 00152 case STK11XX_PALETTE_YUYV: 00153 pixelfmt = palette_yuyv; 00154 break; 00155 } 00156 00157 switch (dev->resolution) { 00158 case STK11XX_80x60: 00159 case STK11XX_128x96: 00160 case STK11XX_160x120: 00161 case STK11XX_213x160: 00162 case STK11XX_320x240: 00163 case STK11XX_640x480: 00164 width = stk11xx_image_sizes[STK11XX_640x480].x; 00165 height = stk11xx_image_sizes[STK11XX_640x480].y; 00166 break; 00167 00168 case STK11XX_800x600: 00169 case STK11XX_1024x768: 00170 case STK11XX_1280x1024: 00171 width = stk11xx_image_sizes[STK11XX_1280x1024].x; 00172 height = stk11xx_image_sizes[STK11XX_1280x1024].y; 00173 break; 00174 00175 default: 00176 width = 0; 00177 height = 0; 00178 } 00179 00180 return sprintf(buf, 00181 "Asked resolution : %dx%d\n" 00182 "Driver resolution : %dx%d\n" 00183 "Webcam resolution : %dx%d\n" 00184 "\n" 00185 "%s\n" 00186 "\n" 00187 "Brightness : 0x%X\n" 00188 "Contrast : 0x%X\n" 00189 "Whiteness : 0x%X\n" 00190 "Colour : 0x%X\n", 00191 dev->view.x, dev->view.y, 00192 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y, 00193 width, height, 00194 pixelfmt, 00195 0xFFFF & dev->vsettings.brightness, 00196 0xFFFF & dev->vsettings.contrast, 00197 0xFFFF & dev->vsettings.whiteness, 00198 0xFFFF & dev->vsettings.colour); 00199 } 00200 00201 00211 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00212 static ssize_t show_fps(struct class_device *class, char *buf) 00213 #else 00214 static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf) 00215 #endif 00216 { 00217 struct video_device *vdev = to_video_device(class); 00218 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00219 00220 return sprintf(buf, "%d\n", dev->vsettings.fps); 00221 } 00222 00223 00233 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00234 static ssize_t show_brightness(struct class_device *class, char *buf) 00235 #else 00236 static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf) 00237 #endif 00238 { 00239 struct video_device *vdev = to_video_device(class); 00240 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00241 00242 return sprintf(buf, "%X\n", dev->vsettings.brightness); 00243 } 00244 00245 00255 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00256 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count) 00257 #else 00258 static ssize_t store_brightness(struct device *class, struct device_attribute *attr, 00259 const char *buf, size_t count) 00260 #endif 00261 { 00262 char *endp; 00263 unsigned long value; 00264 00265 struct video_device *vdev = to_video_device(class); 00266 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00267 00268 value = simple_strtoul(buf, &endp, 16); 00269 00270 dev->vsettings.brightness = (int) value; 00271 00272 dev_stk11xx_set_camera_quality(dev); 00273 00274 return strlen(buf); 00275 } 00276 00286 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00287 static ssize_t show_contrast(struct class_device *class, char *buf) 00288 #else 00289 static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf) 00290 #endif 00291 { 00292 struct video_device *vdev = to_video_device(class); 00293 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00294 00295 return sprintf(buf, "%X\n", dev->vsettings.contrast); 00296 } 00297 00298 00308 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00309 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count) 00310 #else 00311 static ssize_t store_contrast(struct device *class, struct device_attribute *attr, 00312 const char *buf, size_t count) 00313 #endif 00314 { 00315 char *endp; 00316 unsigned long value; 00317 00318 struct video_device *vdev = to_video_device(class); 00319 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00320 00321 value = simple_strtoul(buf, &endp, 16); 00322 00323 dev->vsettings.contrast = (int) value; 00324 00325 dev_stk11xx_set_camera_quality(dev); 00326 00327 return strlen(buf); 00328 } 00329 00330 00340 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00341 static ssize_t show_whitebalance(struct class_device *class, char *buf) 00342 #else 00343 static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf) 00344 #endif 00345 { 00346 struct video_device *vdev = to_video_device(class); 00347 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00348 00349 return sprintf(buf, "%X\n", dev->vsettings.whiteness); 00350 } 00351 00352 00362 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00363 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count) 00364 #else 00365 static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr, 00366 const char *buf, size_t count) 00367 #endif 00368 { 00369 char *endp; 00370 unsigned long value; 00371 00372 struct video_device *vdev = to_video_device(class); 00373 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00374 00375 value = simple_strtoul(buf, &endp, 16); 00376 00377 dev->vsettings.whiteness = (int) value; 00378 00379 dev_stk11xx_set_camera_quality(dev); 00380 00381 return strlen(buf); 00382 } 00383 00384 00394 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00395 static ssize_t show_colour(struct class_device *class, char *buf) 00396 #else 00397 static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf) 00398 #endif 00399 { 00400 struct video_device *vdev = to_video_device(class); 00401 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00402 00403 return sprintf(buf, "%X\n", dev->vsettings.colour); 00404 } 00405 00406 00416 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00417 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count) 00418 #else 00419 static ssize_t store_colour(struct device *class, struct device_attribute *attr, 00420 const char *buf, size_t count) 00421 #endif 00422 { 00423 char *endp; 00424 unsigned long value; 00425 00426 struct video_device *vdev = to_video_device(class); 00427 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00428 00429 value = simple_strtoul(buf, &endp, 16); 00430 00431 dev->vsettings.colour = (int) value; 00432 00433 dev_stk11xx_set_camera_quality(dev); 00434 00435 return strlen(buf); 00436 } 00437 00438 00448 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00449 static ssize_t show_hflip(struct class_device *class, char *buf) 00450 #else 00451 static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf) 00452 #endif 00453 { 00454 struct video_device *vdev = to_video_device(class); 00455 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00456 00457 return sprintf(buf, "%d\n", dev->vsettings.hflip); 00458 } 00459 00460 00470 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00471 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count) 00472 #else 00473 static ssize_t store_hflip(struct device *class, struct device_attribute *attr, 00474 const char *buf, size_t count) 00475 #endif 00476 { 00477 struct video_device *vdev = to_video_device(class); 00478 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00479 00480 if (strncmp(buf, "1", 1) == 0) 00481 dev->vsettings.hflip = 1; 00482 else if (strncmp(buf, "0", 1) == 0) 00483 dev->vsettings.hflip = 0; 00484 else 00485 return -EINVAL; 00486 00487 return strlen(buf); 00488 } 00489 00490 00500 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00501 static ssize_t show_vflip(struct class_device *class, char *buf) 00502 #else 00503 static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf) 00504 #endif 00505 { 00506 struct video_device *vdev = to_video_device(class); 00507 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00508 00509 return sprintf(buf, "%d\n", dev->vsettings.vflip); 00510 } 00511 00512 00522 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00523 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count) 00524 #else 00525 static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count) 00526 #endif 00527 { 00528 struct video_device *vdev = to_video_device(class); 00529 struct usb_stk11xx *dev = video_get_drvdata(vdev); 00530 00531 if (strncmp(buf, "1", 1) == 0) 00532 dev->vsettings.vflip = 1; 00533 else if (strncmp(buf, "0", 1) == 0) 00534 dev->vsettings.vflip = 0; 00535 else 00536 return -EINVAL; 00537 00538 return strlen(buf); 00539 } 00540 00541 00542 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00543 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL); 00544 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); 00545 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); 00546 static CLASS_DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); 00547 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); 00548 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); 00549 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); 00550 static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); 00551 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); 00552 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); 00553 #else 00554 static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); 00555 static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); 00556 static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); 00557 static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); 00558 static DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness); 00559 static DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast); 00560 static DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance); 00561 static DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour); 00562 static DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip); 00563 static DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip); 00564 #endif 00565 00566 00576 int stk11xx_create_sysfs_files(struct video_device *vdev) 00577 { 00578 int ret; 00579 00580 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00581 ret = video_device_create_file(vdev, &class_device_attr_release); 00582 ret = video_device_create_file(vdev, &class_device_attr_videostatus); 00583 ret = video_device_create_file(vdev, &class_device_attr_informations); 00584 ret = video_device_create_file(vdev, &class_device_attr_fps); 00585 ret = video_device_create_file(vdev, &class_device_attr_brightness); 00586 ret = video_device_create_file(vdev, &class_device_attr_contrast); 00587 ret = video_device_create_file(vdev, &class_device_attr_whitebalance); 00588 ret = video_device_create_file(vdev, &class_device_attr_colour); 00589 ret = video_device_create_file(vdev, &class_device_attr_hflip); 00590 ret = video_device_create_file(vdev, &class_device_attr_vflip); 00591 #else 00592 ret = video_device_create_file(vdev, &dev_attr_release); 00593 ret = video_device_create_file(vdev, &dev_attr_videostatus); 00594 ret = video_device_create_file(vdev, &dev_attr_informations); 00595 ret = video_device_create_file(vdev, &dev_attr_fps); 00596 ret = video_device_create_file(vdev, &dev_attr_brightness); 00597 ret = video_device_create_file(vdev, &dev_attr_contrast); 00598 ret = video_device_create_file(vdev, &dev_attr_whitebalance); 00599 ret = video_device_create_file(vdev, &dev_attr_colour); 00600 ret = video_device_create_file(vdev, &dev_attr_hflip); 00601 ret = video_device_create_file(vdev, &dev_attr_vflip); 00602 #endif 00603 00604 return ret; 00605 } 00606 00607 00617 void stk11xx_remove_sysfs_files(struct video_device *vdev) 00618 { 00619 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) 00620 video_device_remove_file(vdev, &class_device_attr_release); 00621 video_device_remove_file(vdev, &class_device_attr_videostatus); 00622 video_device_remove_file(vdev, &class_device_attr_informations); 00623 video_device_remove_file(vdev, &class_device_attr_fps); 00624 video_device_remove_file(vdev, &class_device_attr_brightness); 00625 video_device_remove_file(vdev, &class_device_attr_contrast); 00626 video_device_remove_file(vdev, &class_device_attr_whitebalance); 00627 video_device_remove_file(vdev, &class_device_attr_colour); 00628 video_device_remove_file(vdev, &class_device_attr_hflip); 00629 video_device_remove_file(vdev, &class_device_attr_vflip); 00630 #else 00631 video_device_remove_file(vdev, &dev_attr_release); 00632 video_device_remove_file(vdev, &dev_attr_videostatus); 00633 video_device_remove_file(vdev, &dev_attr_informations); 00634 video_device_remove_file(vdev, &dev_attr_fps); 00635 video_device_remove_file(vdev, &dev_attr_brightness); 00636 video_device_remove_file(vdev, &dev_attr_contrast); 00637 video_device_remove_file(vdev, &dev_attr_whitebalance); 00638 video_device_remove_file(vdev, &dev_attr_colour); 00639 video_device_remove_file(vdev, &dev_attr_hflip); 00640 video_device_remove_file(vdev, &dev_attr_vflip); 00641 #endif 00642 } 00643