00001
00034 #include <linux/module.h>
00035 #include <linux/init.h>
00036 #include <linux/kernel.h>
00037 #include <linux/errno.h>
00038 #include <linux/slab.h>
00039 #include <linux/kref.h>
00040 #include <linux/device.h>
00041
00042 #include <linux/usb.h>
00043 #include <media/v4l2-common.h>
00044
00045 #include "stk11xx.h"
00046
00047
00048 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
00049
00050
00060 static ssize_t show_release(struct class_device *class, char *buf)
00061 {
00062 struct video_device *vdev = to_video_device(class);
00063 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00064
00065 return sprintf(buf, "%d\n", dev->release);
00066 }
00067
00068
00078 static ssize_t show_videostatus(struct class_device *class, char *buf)
00079 {
00080 struct video_device *vdev = to_video_device(class);
00081 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00082
00083 return sprintf(buf,
00084 "Nbr ISOC errors : %d\n"
00085 "Nbr dropped frames : %d\n"
00086 "Nbr dumped frames : %d\n",
00087 dev->visoc_errors,
00088 dev->vframes_error,
00089 dev->vframes_dumped);
00090 }
00091
00092
00102 static ssize_t show_informations(struct class_device *class, char *buf)
00103 {
00104 int width, height;
00105
00106 struct video_device *vdev = to_video_device(class);
00107 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00108
00109
00110 switch (dev->resolution) {
00111 case STK11XX_80x60:
00112 case STK11XX_128x96:
00113 case STK11XX_160x120:
00114 case STK11XX_213x160:
00115 case STK11XX_320x240:
00116 case STK11XX_640x480:
00117 width = stk11xx_image_sizes[STK11XX_640x480].x;
00118 height = stk11xx_image_sizes[STK11XX_640x480].y;
00119 break;
00120
00121 case STK11XX_800x600:
00122 case STK11XX_1024x768:
00123 case STK11XX_1280x1024:
00124 width = stk11xx_image_sizes[STK11XX_1280x1024].x;
00125 height = stk11xx_image_sizes[STK11XX_1280x1024].y;
00126 break;
00127
00128 default:
00129 width = 0;
00130 height = 0;
00131 }
00132
00133 return sprintf(buf,
00134 "Asked resolution : %dx%d\n"
00135 "Driver resolution : %dx%d\n"
00136 "Webcam resolution : %dx%d\n"
00137 "\n"
00138 "Brightness : 0x%X\n"
00139 "Contrast : 0x%X\n"
00140 "Whiteness : 0x%X\n"
00141 "Colour : 0x%X\n",
00142 dev->view.x, dev->view.y,
00143 stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
00144 width, height,
00145 0xFFFF & dev->vsettings.brightness,
00146 0xFFFF & dev->vsettings.contrast,
00147 0xFFFF & dev->vsettings.whiteness,
00148 0xFFFF & dev->vsettings.colour);
00149 }
00150
00151
00161 static ssize_t show_brightness(struct class_device *class, char *buf)
00162 {
00163 struct video_device *vdev = to_video_device(class);
00164 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00165
00166 return sprintf(buf, "%X\n", dev->vsettings.brightness);
00167 }
00168
00169
00179 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
00180 {
00181 char *endp;
00182 unsigned long value;
00183
00184 struct video_device *vdev = to_video_device(class);
00185 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00186
00187 value = simple_strtoul(buf, &endp, 16);
00188
00189 dev->vsettings.brightness = (int) value;
00190
00191 dev_stk11xx_set_camera_quality(dev);
00192
00193 return strlen(buf);
00194 }
00195
00205 static ssize_t show_contrast(struct class_device *class, 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, "%X\n", dev->vsettings.contrast);
00211 }
00212
00213
00223 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
00224 {
00225 char *endp;
00226 unsigned long value;
00227
00228 struct video_device *vdev = to_video_device(class);
00229 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00230
00231 value = simple_strtoul(buf, &endp, 16);
00232
00233 dev->vsettings.contrast = (int) value;
00234
00235 dev_stk11xx_set_camera_quality(dev);
00236
00237 return strlen(buf);
00238 }
00239
00240
00250 static ssize_t show_whitebalance(struct class_device *class, char *buf)
00251 {
00252 struct video_device *vdev = to_video_device(class);
00253 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00254
00255 return sprintf(buf, "%X\n", dev->vsettings.whiteness);
00256 }
00257
00258
00268 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
00269 {
00270 char *endp;
00271 unsigned long value;
00272
00273 struct video_device *vdev = to_video_device(class);
00274 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00275
00276 value = simple_strtoul(buf, &endp, 16);
00277
00278 dev->vsettings.whiteness = (int) value;
00279
00280 dev_stk11xx_set_camera_quality(dev);
00281
00282 return strlen(buf);
00283 }
00284
00285
00295 static ssize_t show_colour(struct class_device *class, char *buf)
00296 {
00297 struct video_device *vdev = to_video_device(class);
00298 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00299
00300 return sprintf(buf, "%X\n", dev->vsettings.colour);
00301 }
00302
00303
00313 static ssize_t store_colour(struct class_device *class, const char *buf, size_t count)
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.colour = (int) value;
00324
00325 dev_stk11xx_set_camera_quality(dev);
00326
00327 return strlen(buf);
00328 }
00329
00330
00340 static ssize_t show_hflip(struct class_device *class, char *buf)
00341 {
00342 struct video_device *vdev = to_video_device(class);
00343 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00344
00345 return sprintf(buf, "%d\n", dev->vsettings.hflip);
00346 }
00347
00348
00358 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
00359 {
00360 struct video_device *vdev = to_video_device(class);
00361 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00362
00363 if (strncmp(buf, "1", 1) == 0)
00364 dev->vsettings.hflip = 1;
00365 else if (strncmp(buf, "0", 1) == 0)
00366 dev->vsettings.hflip = 0;
00367 else
00368 return -EINVAL;
00369
00370 return strlen(buf);
00371 }
00372
00373
00383 static ssize_t show_vflip(struct class_device *class, char *buf)
00384 {
00385 struct video_device *vdev = to_video_device(class);
00386 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00387
00388 return sprintf(buf, "%d\n", dev->vsettings.vflip);
00389 }
00390
00391
00401 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
00402 {
00403 struct video_device *vdev = to_video_device(class);
00404 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00405
00406 if (strncmp(buf, "1", 1) == 0)
00407 dev->vsettings.vflip = 1;
00408 else if (strncmp(buf, "0", 1) == 0)
00409 dev->vsettings.vflip = 0;
00410 else
00411 return -EINVAL;
00412
00413 return strlen(buf);
00414 }
00415
00416
00417
00418
00419 static ssize_t runtest(struct class_device *class, const char *buf, size_t count)
00420 {
00421 char *endp;
00422 unsigned long value;
00423
00424 struct video_device *vdev = to_video_device(class);
00425 struct usb_stk11xx *dev = video_get_drvdata(vdev);
00426
00427 value = simple_strtoul(buf, &endp, 16);
00428
00429 switch (value) {
00430 case 1:
00431 dev_stk11xx_set_camera_quality(dev);
00432 STK_INFO("1 run\n");
00433 break;
00434
00435 case 2:
00436 dev_stk11xx_set_camera_fps(dev);
00437 STK_INFO("2 run\n");
00438 break;
00439
00440 case 3:
00441 dev_stk11xx_camera_settings(dev);
00442 STK_INFO("3 run\n");
00443 break;
00444 }
00445
00446 return strlen(buf);
00447 }
00448
00449
00450
00451 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL);
00452 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL);
00453 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL);
00454 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness);
00455 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast);
00456 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance);
00457 static CLASS_DEVICE_ATTR(colour, S_IRUGO | S_IWUGO, show_colour, store_colour);
00458 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);
00459 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);
00460 static CLASS_DEVICE_ATTR(test, S_IRUGO | S_IWUGO, NULL, runtest);
00461
00462
00472 int stk11xx_create_sysfs_files(struct video_device *vdev)
00473 {
00474 int ret;
00475
00476 ret = video_device_create_file(vdev, &class_device_attr_release);
00477 ret = video_device_create_file(vdev, &class_device_attr_videostatus);
00478 ret = video_device_create_file(vdev, &class_device_attr_informations);
00479 ret = video_device_create_file(vdev, &class_device_attr_brightness);
00480 ret = video_device_create_file(vdev, &class_device_attr_contrast);
00481 ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
00482 ret = video_device_create_file(vdev, &class_device_attr_colour);
00483 ret = video_device_create_file(vdev, &class_device_attr_hflip);
00484 ret = video_device_create_file(vdev, &class_device_attr_vflip);
00485 ret = video_device_create_file(vdev, &class_device_attr_test);
00486
00487 return ret;
00488 }
00489
00490
00500 void stk11xx_remove_sysfs_files(struct video_device *vdev)
00501 {
00502 video_device_remove_file(vdev, &class_device_attr_release);
00503 video_device_remove_file(vdev, &class_device_attr_videostatus);
00504 video_device_remove_file(vdev, &class_device_attr_informations);
00505 video_device_remove_file(vdev, &class_device_attr_brightness);
00506 video_device_remove_file(vdev, &class_device_attr_contrast);
00507 video_device_remove_file(vdev, &class_device_attr_whitebalance);
00508 video_device_remove_file(vdev, &class_device_attr_colour);
00509 video_device_remove_file(vdev, &class_device_attr_hflip);
00510 video_device_remove_file(vdev, &class_device_attr_vflip);
00511 video_device_remove_file(vdev, &class_device_attr_test);
00512 }
00513