forked from hbars/stk11xx-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stk11xx-sysfs.c
549 lines (458 loc) · 13.3 KB
/
stk11xx-sysfs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/**
* @file stk11xx-sysfs.c
* @author Nicolas VIVIEN
* @date 2006-10-23
* @version v2.2.x
*
* @brief Driver for Syntek USB video camera
*
* @note Copyright (C) Nicolas VIVIEN
*
* @par Licences
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @par SubVersion
* $Date$
* $Revision$
* $Author$
* $HeadURL$
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/kref.h>
#include <linux/device.h>
#include <linux/mm.h>
#if defined(VIDIOCGCAP)
#include <linux/videodev.h>
#endif
#include <linux/usb.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include "stk11xx.h"
extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
/**
* @brief show_release
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'release' value
*
* @returns Size of buffer
*/
static ssize_t show_release(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%d\n", dev->release);
}
/**
* @brief show_videostatus
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'videostatus' value
*
* @returns Size of buffer
*/
static ssize_t show_videostatus(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf,
"Nbr ISOC errors : %d\n"
"Nbr dropped frames : %d\n"
"Nbr dumped frames : %d\n",
dev->visoc_errors,
dev->vframes_error,
dev->vframes_dumped);
}
/**
* @brief show_informations
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'informations' value
*
* @returns Size of buffer
*/
static ssize_t show_informations(struct device *class, struct device_attribute *attr, char *buf)
{
int width, height;
char *pixelfmt = NULL;
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
char *palette_rgb24 = "RGB24 - RGB-8-8-8 - 24 bits";
char *palette_rgb32 = "RGB32 - RGB-8-8-8-8 - 32 bits";
char *palette_bgr24 = "BGR24 - BGR-8-8-8 - 24 bits";
char *palette_bgr32 = "BGR32 - BGR-8-8-8-8 - 32 bits";
char *palette_uyvy = "UYVY - YUV 4:2:2 - 16 bits";
char *palette_yuyv = "YUYV - YUV 4:2:2 - 16 bits";
switch (dev->vsettings.palette) {
case STK11XX_PALETTE_RGB24:
pixelfmt = palette_rgb24;
break;
case STK11XX_PALETTE_RGB32:
pixelfmt = palette_rgb32;
break;
case STK11XX_PALETTE_BGR24:
pixelfmt = palette_bgr24;
break;
case STK11XX_PALETTE_BGR32:
pixelfmt = palette_bgr32;
break;
case STK11XX_PALETTE_UYVY:
pixelfmt = palette_uyvy;
break;
case STK11XX_PALETTE_YUYV:
pixelfmt = palette_yuyv;
break;
}
switch (dev->resolution) {
case STK11XX_80x60:
case STK11XX_128x96:
case STK11XX_160x120:
case STK11XX_213x160:
case STK11XX_320x240:
case STK11XX_640x480:
width = stk11xx_image_sizes[STK11XX_640x480].x;
height = stk11xx_image_sizes[STK11XX_640x480].y;
break;
case STK11XX_720x576:
width = stk11xx_image_sizes[STK11XX_720x576].x;
height = stk11xx_image_sizes[STK11XX_720x576].y;
break;
case STK11XX_800x600:
case STK11XX_1024x768:
case STK11XX_1280x1024:
width = stk11xx_image_sizes[STK11XX_1280x1024].x;
height = stk11xx_image_sizes[STK11XX_1280x1024].y;
break;
default:
width = 0;
height = 0;
}
return sprintf(buf,
"Asked resolution : %dx%d\n"
"Driver resolution : %dx%d\n"
"Webcam resolution : %dx%d\n"
"\n"
"%s\n"
"\n"
"Brightness : 0x%X\n"
"Contrast : 0x%X\n"
"Whiteness : 0x%X\n"
"Colour : 0x%X\n",
dev->view.x, dev->view.y,
stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
width, height,
pixelfmt,
0xFFFF & dev->vsettings.brightness,
0xFFFF & dev->vsettings.contrast,
0xFFFF & dev->vsettings.whiteness,
0xFFFF & dev->vsettings.colour);
}
/**
* @brief show_fps
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'fps' value
*
* @returns Size of buffer
*/
static ssize_t show_fps(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%d\n", dev->vsettings.fps);
}
/**
* @brief show_brightness
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'brightness' value
*
* @returns Size of buffer
*/
static ssize_t show_brightness(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%X\n", dev->vsettings.brightness);
}
/**
* @brief store_brightness
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_brightness(struct device *class, struct device_attribute *attr,
const char *buf, size_t count)
{
char *endp;
unsigned long value;
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
value = simple_strtoul(buf, &endp, 16);
dev->vsettings.brightness = (int) value;
dev_stk11xx_set_camera_quality(dev);
return strlen(buf);
}
/**
* @brief show_contrast
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'contrast' value
*
* @returns Size of buffer
*/
static ssize_t show_contrast(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%X\n", dev->vsettings.contrast);
}
/**
* @brief store_contrast
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_contrast(struct device *class, struct device_attribute *attr,
const char *buf, size_t count)
{
char *endp;
unsigned long value;
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
value = simple_strtoul(buf, &endp, 16);
dev->vsettings.contrast = (int) value;
dev_stk11xx_set_camera_quality(dev);
return strlen(buf);
}
/**
* @brief show_whitebalance
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'whitebalance' value
*
* @returns Size of buffer
*/
static ssize_t show_whitebalance(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%X\n", dev->vsettings.whiteness);
}
/**
* @brief store_whitebalance
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_whitebalance(struct device *class, struct device_attribute *attr,
const char *buf, size_t count)
{
char *endp;
unsigned long value;
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
value = simple_strtoul(buf, &endp, 16);
dev->vsettings.whiteness = (int) value;
dev_stk11xx_set_camera_quality(dev);
return strlen(buf);
}
/**
* @brief show_colour
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'colour' value
*
* @returns Size of buffer
*/
static ssize_t show_colour(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%X\n", dev->vsettings.colour);
}
/**
* @brief store_colour
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_colour(struct device *class, struct device_attribute *attr,
const char *buf, size_t count)
{
char *endp;
unsigned long value;
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
value = simple_strtoul(buf, &endp, 16);
dev->vsettings.colour = (int) value;
dev_stk11xx_set_camera_quality(dev);
return strlen(buf);
}
/**
* @brief show_hflip
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'hflip' value
*
* @returns Size of buffer
*/
static ssize_t show_hflip(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%d\n", dev->vsettings.hflip);
}
/**
* @brief store_hflip
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_hflip(struct device *class, struct device_attribute *attr,
const char *buf, size_t count)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
if (strncmp(buf, "1", 1) == 0)
dev->vsettings.hflip = 1;
else if (strncmp(buf, "0", 1) == 0)
dev->vsettings.hflip = 0;
else
return -EINVAL;
return strlen(buf);
}
/**
* @brief show_vflip
*
* @param class Class device
*
* @retval buf Adress of buffer with the 'vflip' value
*
* @returns Size of buffer
*/
static ssize_t show_vflip(struct device *class, struct device_attribute *attr, char *buf)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
return sprintf(buf, "%d\n", dev->vsettings.vflip);
}
/**
* @brief store_vflip
*
* @param class Class device
* @param buf Buffer
* @param count Counter
*
* @returns Size of buffer
*/
static ssize_t store_vflip(struct device *class, struct device_attribute *attr, const char *buf, size_t count)
{
struct video_device *vdev = to_video_device(class);
struct usb_stk11xx *dev = video_get_drvdata(vdev);
if (strncmp(buf, "1", 1) == 0)
dev->vsettings.vflip = 1;
else if (strncmp(buf, "0", 1) == 0)
dev->vsettings.vflip = 0;
else
return -EINVAL;
return strlen(buf);
}
static DEVICE_ATTR(release, S_IRUGO, show_release, NULL); /**< Release value */
static DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL); /**< Video status */
static DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL); /**< Informations */
static DEVICE_ATTR(fps, S_IRUGO, show_fps, NULL); /**< FPS value */
static DEVICE_ATTR(brightness, 0660, show_brightness, store_brightness); /**< Brightness value */
static DEVICE_ATTR(contrast, 0660, show_contrast, store_contrast); /**< Contrast value */
static DEVICE_ATTR(whitebalance, 0660, show_whitebalance, store_whitebalance); /**< Whitebalance value */
static DEVICE_ATTR(colour, 0660, show_colour, store_colour); /**< Hue value */
static DEVICE_ATTR(hflip, 0660, show_hflip, store_hflip); /**< Horizontal filp value */
static DEVICE_ATTR(vflip, 0660, show_vflip, store_vflip); /**< Vertical filp value */
/**
* @brief Create the 'sys' entries.
*
* This function permits to create all the entries in the 'sys' filesystem.
*
* @param vdev Video device structure
*
* @returns 0 if all is OK
*/
int stk11xx_create_sysfs_files(struct video_device *vdev)
{
int ret;
ret = device_create_file(&vdev->dev, &dev_attr_release);
ret = device_create_file(&vdev->dev, &dev_attr_videostatus);
ret = device_create_file(&vdev->dev, &dev_attr_informations);
ret = device_create_file(&vdev->dev, &dev_attr_fps);
ret = device_create_file(&vdev->dev, &dev_attr_brightness);
ret = device_create_file(&vdev->dev, &dev_attr_contrast);
ret = device_create_file(&vdev->dev, &dev_attr_whitebalance);
ret = device_create_file(&vdev->dev, &dev_attr_colour);
ret = device_create_file(&vdev->dev, &dev_attr_hflip);
ret = device_create_file(&vdev->dev, &dev_attr_vflip);
return ret;
}
/**
* @brief Remove the 'sys' entries.
*
* This function permits to remove all the entries in the 'sys' filesystem.
*
* @param vdev Video device structure
*
* @returns 0 if all is OK
*/
void stk11xx_remove_sysfs_files(struct video_device *vdev)
{
device_remove_file(&vdev->dev, &dev_attr_release);
device_remove_file(&vdev->dev, &dev_attr_videostatus);
device_remove_file(&vdev->dev, &dev_attr_informations);
device_remove_file(&vdev->dev, &dev_attr_fps);
device_remove_file(&vdev->dev, &dev_attr_brightness);
device_remove_file(&vdev->dev, &dev_attr_contrast);
device_remove_file(&vdev->dev, &dev_attr_whitebalance);
device_remove_file(&vdev->dev, &dev_attr_colour);
device_remove_file(&vdev->dev, &dev_attr_hflip);
device_remove_file(&vdev->dev, &dev_attr_vflip);
}