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