diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2010-03-22 03:47:27 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-05-17 23:51:28 -0400 |
commit | 4bfdd58604ead4d49b29630ee8f72c99b7803b7d (patch) | |
tree | ab5fc9e986819484a9be3420932919db7ca5a788 /drivers | |
parent | 88f4423454a23375f07bb4ff3a80d209930560d0 (diff) |
V4L/DVB: w9966: coding style cleanup
Clean up the coding style before we convert this driver to V4L2.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/w9966.c | 461 |
1 files changed, 223 insertions, 238 deletions
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c index bf9bf650a317..25364b8f857b 100644 --- a/drivers/media/video/w9966.c +++ b/drivers/media/video/w9966.c | |||
@@ -76,12 +76,12 @@ | |||
76 | */ | 76 | */ |
77 | 77 | ||
78 | #define W9966_DRIVERNAME "W9966CF Webcam" | 78 | #define W9966_DRIVERNAME "W9966CF Webcam" |
79 | #define W9966_MAXCAMS 4 // Maximum number of cameras | 79 | #define W9966_MAXCAMS 4 /* Maximum number of cameras */ |
80 | #define W9966_RBUFFER 2048 // Read buffer (must be an even number) | 80 | #define W9966_RBUFFER 2048 /* Read buffer (must be an even number) */ |
81 | #define W9966_SRAMSIZE 131072 // 128kb | 81 | #define W9966_SRAMSIZE 131072 /* 128kb */ |
82 | #define W9966_SRAMID 0x02 // check w9966cf.pdf | 82 | #define W9966_SRAMID 0x02 /* check w9966cf.pdf */ |
83 | 83 | ||
84 | // Empirically determined window limits | 84 | /* Empirically determined window limits */ |
85 | #define W9966_WND_MIN_X 16 | 85 | #define W9966_WND_MIN_X 16 |
86 | #define W9966_WND_MIN_Y 14 | 86 | #define W9966_WND_MIN_Y 14 |
87 | #define W9966_WND_MAX_X 705 | 87 | #define W9966_WND_MAX_X 705 |
@@ -89,7 +89,7 @@ | |||
89 | #define W9966_WND_MAX_W (W9966_WND_MAX_X - W9966_WND_MIN_X) | 89 | #define W9966_WND_MAX_W (W9966_WND_MAX_X - W9966_WND_MIN_X) |
90 | #define W9966_WND_MAX_H (W9966_WND_MAX_Y - W9966_WND_MIN_Y) | 90 | #define W9966_WND_MAX_H (W9966_WND_MAX_Y - W9966_WND_MIN_Y) |
91 | 91 | ||
92 | // Keep track of our current state | 92 | /* Keep track of our current state */ |
93 | #define W9966_STATE_PDEV 0x01 | 93 | #define W9966_STATE_PDEV 0x01 |
94 | #define W9966_STATE_CLAIMED 0x02 | 94 | #define W9966_STATE_CLAIMED 0x02 |
95 | #define W9966_STATE_VDEV 0x04 | 95 | #define W9966_STATE_VDEV 0x04 |
@@ -105,8 +105,8 @@ struct w9966_dev { | |||
105 | unsigned char dev_state; | 105 | unsigned char dev_state; |
106 | unsigned char i2c_state; | 106 | unsigned char i2c_state; |
107 | unsigned short ppmode; | 107 | unsigned short ppmode; |
108 | struct parport* pport; | 108 | struct parport *pport; |
109 | struct pardevice* pdev; | 109 | struct pardevice *pdev; |
110 | struct video_device vdev; | 110 | struct video_device vdev; |
111 | unsigned short width; | 111 | unsigned short width; |
112 | unsigned short height; | 112 | unsigned short height; |
@@ -127,15 +127,15 @@ MODULE_LICENSE("GPL"); | |||
127 | 127 | ||
128 | 128 | ||
129 | #ifdef MODULE | 129 | #ifdef MODULE |
130 | static const char* pardev[] = {[0 ... W9966_MAXCAMS] = ""}; | 130 | static const char *pardev[] = {[0 ... W9966_MAXCAMS] = ""}; |
131 | #else | 131 | #else |
132 | static const char* pardev[] = {[0 ... W9966_MAXCAMS] = "aggressive"}; | 132 | static const char *pardev[] = {[0 ... W9966_MAXCAMS] = "aggressive"}; |
133 | #endif | 133 | #endif |
134 | module_param_array(pardev, charp, NULL, 0); | 134 | module_param_array(pardev, charp, NULL, 0); |
135 | MODULE_PARM_DESC(pardev, "pardev: where to search for\n\ | 135 | MODULE_PARM_DESC(pardev, "pardev: where to search for\n" |
136 | \teach camera. 'aggressive' means brute-force search.\n\ | 136 | "\teach camera. 'aggressive' means brute-force search.\n" |
137 | \tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n\ | 137 | "\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n" |
138 | \tcam 1 to parport3 and search every parport for cam 2 etc..."); | 138 | "\tcam 1 to parport3 and search every parport for cam 2 etc..."); |
139 | 139 | ||
140 | static int parmode; | 140 | static int parmode; |
141 | module_param(parmode, int, 0); | 141 | module_param(parmode, int, 0); |
@@ -154,31 +154,31 @@ static struct w9966_dev w9966_cams[W9966_MAXCAMS]; | |||
154 | * Private function declares | 154 | * Private function declares |
155 | */ | 155 | */ |
156 | 156 | ||
157 | static inline void w9966_setState(struct w9966_dev* cam, int mask, int val); | 157 | static inline void w9966_setState(struct w9966_dev *cam, int mask, int val); |
158 | static inline int w9966_getState(struct w9966_dev* cam, int mask, int val); | 158 | static inline int w9966_getState(struct w9966_dev *cam, int mask, int val); |
159 | static inline void w9966_pdev_claim(struct w9966_dev *vdev); | 159 | static inline void w9966_pdev_claim(struct w9966_dev *vdev); |
160 | static inline void w9966_pdev_release(struct w9966_dev *vdev); | 160 | static inline void w9966_pdev_release(struct w9966_dev *vdev); |
161 | 161 | ||
162 | static int w9966_rReg(struct w9966_dev* cam, int reg); | 162 | static int w9966_rReg(struct w9966_dev *cam, int reg); |
163 | static int w9966_wReg(struct w9966_dev* cam, int reg, int data); | 163 | static int w9966_wReg(struct w9966_dev *cam, int reg, int data); |
164 | #if 0 | 164 | #if 0 |
165 | static int w9966_rReg_i2c(struct w9966_dev* cam, int reg); | 165 | static int w9966_rReg_i2c(struct w9966_dev *cam, int reg); |
166 | #endif | 166 | #endif |
167 | static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data); | 167 | static int w9966_wReg_i2c(struct w9966_dev *cam, int reg, int data); |
168 | static int w9966_findlen(int near, int size, int maxlen); | 168 | static int w9966_findlen(int near, int size, int maxlen); |
169 | static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor); | 169 | static int w9966_calcscale(int size, int min, int max, int *beg, int *end, unsigned char *factor); |
170 | static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, int w, int h); | 170 | static int w9966_setup(struct w9966_dev *cam, int x1, int y1, int x2, int y2, int w, int h); |
171 | 171 | ||
172 | static int w9966_init(struct w9966_dev* cam, struct parport* port); | 172 | static int w9966_init(struct w9966_dev *cam, struct parport* port); |
173 | static void w9966_term(struct w9966_dev* cam); | 173 | static void w9966_term(struct w9966_dev *cam); |
174 | 174 | ||
175 | static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state); | 175 | static inline void w9966_i2c_setsda(struct w9966_dev *cam, int state); |
176 | static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state); | 176 | static inline int w9966_i2c_setscl(struct w9966_dev *cam, int state); |
177 | static inline int w9966_i2c_getsda(struct w9966_dev* cam); | 177 | static inline int w9966_i2c_getsda(struct w9966_dev *cam); |
178 | static inline int w9966_i2c_getscl(struct w9966_dev* cam); | 178 | static inline int w9966_i2c_getscl(struct w9966_dev *cam); |
179 | static int w9966_i2c_wbyte(struct w9966_dev* cam, int data); | 179 | static int w9966_i2c_wbyte(struct w9966_dev *cam, int data); |
180 | #if 0 | 180 | #if 0 |
181 | static int w9966_i2c_rbyte(struct w9966_dev* cam); | 181 | static int w9966_i2c_rbyte(struct w9966_dev *cam); |
182 | #endif | 182 | #endif |
183 | 183 | ||
184 | static long w9966_v4l_ioctl(struct file *file, | 184 | static long w9966_v4l_ioctl(struct file *file, |
@@ -219,20 +219,20 @@ static struct video_device w9966_template = { | |||
219 | */ | 219 | */ |
220 | 220 | ||
221 | 221 | ||
222 | // Set camera phase flags, so we know what to uninit when terminating | 222 | /* Set camera phase flags, so we know what to uninit when terminating */ |
223 | static inline void w9966_setState(struct w9966_dev* cam, int mask, int val) | 223 | static inline void w9966_setState(struct w9966_dev *cam, int mask, int val) |
224 | { | 224 | { |
225 | cam->dev_state = (cam->dev_state & ~mask) ^ val; | 225 | cam->dev_state = (cam->dev_state & ~mask) ^ val; |
226 | } | 226 | } |
227 | 227 | ||
228 | // Get camera phase flags | 228 | /* Get camera phase flags */ |
229 | static inline int w9966_getState(struct w9966_dev* cam, int mask, int val) | 229 | static inline int w9966_getState(struct w9966_dev *cam, int mask, int val) |
230 | { | 230 | { |
231 | return ((cam->dev_state & mask) == val); | 231 | return ((cam->dev_state & mask) == val); |
232 | } | 232 | } |
233 | 233 | ||
234 | // Claim parport for ourself | 234 | /* Claim parport for ourself */ |
235 | static inline void w9966_pdev_claim(struct w9966_dev* cam) | 235 | static inline void w9966_pdev_claim(struct w9966_dev *cam) |
236 | { | 236 | { |
237 | if (w9966_getState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED)) | 237 | if (w9966_getState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED)) |
238 | return; | 238 | return; |
@@ -240,8 +240,8 @@ static inline void w9966_pdev_claim(struct w9966_dev* cam) | |||
240 | w9966_setState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED); | 240 | w9966_setState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED); |
241 | } | 241 | } |
242 | 242 | ||
243 | // Release parport for others to use | 243 | /* Release parport for others to use */ |
244 | static inline void w9966_pdev_release(struct w9966_dev* cam) | 244 | static inline void w9966_pdev_release(struct w9966_dev *cam) |
245 | { | 245 | { |
246 | if (w9966_getState(cam, W9966_STATE_CLAIMED, 0)) | 246 | if (w9966_getState(cam, W9966_STATE_CLAIMED, 0)) |
247 | return; | 247 | return; |
@@ -249,12 +249,12 @@ static inline void w9966_pdev_release(struct w9966_dev* cam) | |||
249 | w9966_setState(cam, W9966_STATE_CLAIMED, 0); | 249 | w9966_setState(cam, W9966_STATE_CLAIMED, 0); |
250 | } | 250 | } |
251 | 251 | ||
252 | // Read register from W9966 interface-chip | 252 | /* Read register from W9966 interface-chip |
253 | // Expects a claimed pdev | 253 | Expects a claimed pdev |
254 | // -1 on error, else register data (byte) | 254 | -1 on error, else register data (byte) */ |
255 | static int w9966_rReg(struct w9966_dev* cam, int reg) | 255 | static int w9966_rReg(struct w9966_dev *cam, int reg) |
256 | { | 256 | { |
257 | // ECP, read, regtransfer, REG, REG, REG, REG, REG | 257 | /* ECP, read, regtransfer, REG, REG, REG, REG, REG */ |
258 | const unsigned char addr = 0x80 | (reg & 0x1f); | 258 | const unsigned char addr = 0x80 | (reg & 0x1f); |
259 | unsigned char val; | 259 | unsigned char val; |
260 | 260 | ||
@@ -270,12 +270,12 @@ static int w9966_rReg(struct w9966_dev* cam, int reg) | |||
270 | return val; | 270 | return val; |
271 | } | 271 | } |
272 | 272 | ||
273 | // Write register to W9966 interface-chip | 273 | /* Write register to W9966 interface-chip |
274 | // Expects a claimed pdev | 274 | Expects a claimed pdev |
275 | // -1 on error | 275 | -1 on error */ |
276 | static int w9966_wReg(struct w9966_dev* cam, int reg, int data) | 276 | static int w9966_wReg(struct w9966_dev *cam, int reg, int data) |
277 | { | 277 | { |
278 | // ECP, write, regtransfer, REG, REG, REG, REG, REG | 278 | /* ECP, write, regtransfer, REG, REG, REG, REG, REG */ |
279 | const unsigned char addr = 0xc0 | (reg & 0x1f); | 279 | const unsigned char addr = 0xc0 | (reg & 0x1f); |
280 | const unsigned char val = data; | 280 | const unsigned char val = data; |
281 | 281 | ||
@@ -291,11 +291,11 @@ static int w9966_wReg(struct w9966_dev* cam, int reg, int data) | |||
291 | return 0; | 291 | return 0; |
292 | } | 292 | } |
293 | 293 | ||
294 | // Initialize camera device. Setup all internal flags, set a | 294 | /* Initialize camera device. Setup all internal flags, set a |
295 | // default video mode, setup ccd-chip, register v4l device etc.. | 295 | default video mode, setup ccd-chip, register v4l device etc.. |
296 | // Also used for 'probing' of hardware. | 296 | Also used for 'probing' of hardware. |
297 | // -1 on error | 297 | -1 on error */ |
298 | static int w9966_init(struct w9966_dev* cam, struct parport* port) | 298 | static int w9966_init(struct w9966_dev *cam, struct parport* port) |
299 | { | 299 | { |
300 | if (cam->dev_state != 0) | 300 | if (cam->dev_state != 0) |
301 | return -1; | 301 | return -1; |
@@ -306,10 +306,9 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port) | |||
306 | cam->color = 64; | 306 | cam->color = 64; |
307 | cam->hue = 0; | 307 | cam->hue = 0; |
308 | 308 | ||
309 | // Select requested transfer mode | 309 | /* Select requested transfer mode */ |
310 | switch(parmode) | 310 | switch (parmode) { |
311 | { | 311 | default: /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */ |
312 | default: // Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) | ||
313 | case 0: | 312 | case 0: |
314 | if (port->modes & PARPORT_MODE_ECP) | 313 | if (port->modes & PARPORT_MODE_ECP) |
315 | cam->ppmode = IEEE1284_MODE_ECP; | 314 | cam->ppmode = IEEE1284_MODE_ECP; |
@@ -318,15 +317,15 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port) | |||
318 | else | 317 | else |
319 | cam->ppmode = IEEE1284_MODE_ECP; | 318 | cam->ppmode = IEEE1284_MODE_ECP; |
320 | break; | 319 | break; |
321 | case 1: // hw- or sw-ecp | 320 | case 1: /* hw- or sw-ecp */ |
322 | cam->ppmode = IEEE1284_MODE_ECP; | 321 | cam->ppmode = IEEE1284_MODE_ECP; |
323 | break; | 322 | break; |
324 | case 2: // hw- or sw-epp | 323 | case 2: /* hw- or sw-epp */ |
325 | cam->ppmode = IEEE1284_MODE_EPP; | 324 | cam->ppmode = IEEE1284_MODE_EPP; |
326 | break; | 325 | break; |
327 | } | 326 | } |
328 | 327 | ||
329 | // Tell the parport driver that we exists | 328 | /* Tell the parport driver that we exists */ |
330 | cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL); | 329 | cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL); |
331 | if (cam->pdev == NULL) { | 330 | if (cam->pdev == NULL) { |
332 | DPRINTF("parport_register_device() failed\n"); | 331 | DPRINTF("parport_register_device() failed\n"); |
@@ -336,7 +335,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port) | |||
336 | 335 | ||
337 | w9966_pdev_claim(cam); | 336 | w9966_pdev_claim(cam); |
338 | 337 | ||
339 | // Setup a default capture mode | 338 | /* Setup a default capture mode */ |
340 | if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) { | 339 | if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) { |
341 | DPRINTF("w9966_setup() failed.\n"); | 340 | DPRINTF("w9966_setup() failed.\n"); |
342 | return -1; | 341 | return -1; |
@@ -344,7 +343,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port) | |||
344 | 343 | ||
345 | w9966_pdev_release(cam); | 344 | w9966_pdev_release(cam); |
346 | 345 | ||
347 | // Fill in the video_device struct and register us to v4l | 346 | /* Fill in the video_device struct and register us to v4l */ |
348 | memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device)); | 347 | memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device)); |
349 | video_set_drvdata(&cam->vdev, cam); | 348 | video_set_drvdata(&cam->vdev, cam); |
350 | 349 | ||
@@ -353,32 +352,30 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port) | |||
353 | 352 | ||
354 | w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV); | 353 | w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV); |
355 | 354 | ||
356 | // All ok | 355 | /* All ok */ |
357 | printk( | 356 | printk(KERN_INFO "w9966cf: Found and initialized a webcam on %s.\n", |
358 | "w9966cf: Found and initialized a webcam on %s.\n", | 357 | cam->pport->name); |
359 | cam->pport->name | ||
360 | ); | ||
361 | return 0; | 358 | return 0; |
362 | } | 359 | } |
363 | 360 | ||
364 | 361 | ||
365 | // Terminate everything gracefully | 362 | /* Terminate everything gracefully */ |
366 | static void w9966_term(struct w9966_dev* cam) | 363 | static void w9966_term(struct w9966_dev *cam) |
367 | { | 364 | { |
368 | // Unregister from v4l | 365 | /* Unregister from v4l */ |
369 | if (w9966_getState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) { | 366 | if (w9966_getState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) { |
370 | video_unregister_device(&cam->vdev); | 367 | video_unregister_device(&cam->vdev); |
371 | w9966_setState(cam, W9966_STATE_VDEV, 0); | 368 | w9966_setState(cam, W9966_STATE_VDEV, 0); |
372 | } | 369 | } |
373 | 370 | ||
374 | // Terminate from IEEE1284 mode and release pdev block | 371 | /* Terminate from IEEE1284 mode and release pdev block */ |
375 | if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) { | 372 | if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) { |
376 | w9966_pdev_claim(cam); | 373 | w9966_pdev_claim(cam); |
377 | parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT); | 374 | parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT); |
378 | w9966_pdev_release(cam); | 375 | w9966_pdev_release(cam); |
379 | } | 376 | } |
380 | 377 | ||
381 | // Unregister from parport | 378 | /* Unregister from parport */ |
382 | if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) { | 379 | if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) { |
383 | parport_unregister_device(cam->pdev); | 380 | parport_unregister_device(cam->pdev); |
384 | w9966_setState(cam, W9966_STATE_PDEV, 0); | 381 | w9966_setState(cam, W9966_STATE_PDEV, 0); |
@@ -386,24 +383,23 @@ static void w9966_term(struct w9966_dev* cam) | |||
386 | } | 383 | } |
387 | 384 | ||
388 | 385 | ||
389 | // Find a good length for capture window (used both for W and H) | 386 | /* Find a good length for capture window (used both for W and H) |
390 | // A bit ugly but pretty functional. The capture length | 387 | A bit ugly but pretty functional. The capture length |
391 | // have to match the downscale | 388 | have to match the downscale */ |
392 | static int w9966_findlen(int near, int size, int maxlen) | 389 | static int w9966_findlen(int near, int size, int maxlen) |
393 | { | 390 | { |
394 | int bestlen = size; | 391 | int bestlen = size; |
395 | int besterr = abs(near - bestlen); | 392 | int besterr = abs(near - bestlen); |
396 | int len; | 393 | int len; |
397 | 394 | ||
398 | for(len = size+1;len < maxlen;len++) | 395 | for (len = size + 1; len < maxlen; len++) { |
399 | { | ||
400 | int err; | 396 | int err; |
401 | if ( ((64*size) %len) != 0) | 397 | if (((64 * size) % len) != 0) |
402 | continue; | 398 | continue; |
403 | 399 | ||
404 | err = abs(near - len); | 400 | err = abs(near - len); |
405 | 401 | ||
406 | // Only continue as long as we keep getting better values | 402 | /* Only continue as long as we keep getting better values */ |
407 | if (err > besterr) | 403 | if (err > besterr) |
408 | break; | 404 | break; |
409 | 405 | ||
@@ -414,32 +410,32 @@ static int w9966_findlen(int near, int size, int maxlen) | |||
414 | return bestlen; | 410 | return bestlen; |
415 | } | 411 | } |
416 | 412 | ||
417 | // Modify capture window (if necessary) | 413 | /* Modify capture window (if necessary) |
418 | // and calculate downscaling | 414 | and calculate downscaling |
419 | // Return -1 on error | 415 | Return -1 on error */ |
420 | static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor) | 416 | static int w9966_calcscale(int size, int min, int max, int *beg, int *end, unsigned char *factor) |
421 | { | 417 | { |
422 | int maxlen = max - min; | 418 | int maxlen = max - min; |
423 | int len = *end - *beg + 1; | 419 | int len = *end - *beg + 1; |
424 | int newlen = w9966_findlen(len, size, maxlen); | 420 | int newlen = w9966_findlen(len, size, maxlen); |
425 | int err = newlen - len; | 421 | int err = newlen - len; |
426 | 422 | ||
427 | // Check for bad format | 423 | /* Check for bad format */ |
428 | if (newlen > maxlen || newlen < size) | 424 | if (newlen > maxlen || newlen < size) |
429 | return -1; | 425 | return -1; |
430 | 426 | ||
431 | // Set factor (6 bit fixed) | 427 | /* Set factor (6 bit fixed) */ |
432 | *factor = (64*size) / newlen; | 428 | *factor = (64 * size) / newlen; |
433 | if (*factor == 64) | 429 | if (*factor == 64) |
434 | *factor = 0x00; // downscale is disabled | 430 | *factor = 0x00; /* downscale is disabled */ |
435 | else | 431 | else |
436 | *factor |= 0x80; // set downscale-enable bit | 432 | *factor |= 0x80; /* set downscale-enable bit */ |
437 | 433 | ||
438 | // Modify old beginning and end | 434 | /* Modify old beginning and end */ |
439 | *beg -= err / 2; | 435 | *beg -= err / 2; |
440 | *end += err - (err / 2); | 436 | *end += err - (err / 2); |
441 | 437 | ||
442 | // Move window if outside borders | 438 | /* Move window if outside borders */ |
443 | if (*beg < min) { | 439 | if (*beg < min) { |
444 | *end += min - *beg; | 440 | *end += min - *beg; |
445 | *beg += min - *beg; | 441 | *beg += min - *beg; |
@@ -452,10 +448,10 @@ static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsig | |||
452 | return 0; | 448 | return 0; |
453 | } | 449 | } |
454 | 450 | ||
455 | // Setup the cameras capture window etc. | 451 | /* Setup the cameras capture window etc. |
456 | // Expects a claimed pdev | 452 | Expects a claimed pdev |
457 | // return -1 on error | 453 | return -1 on error */ |
458 | static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, int w, int h) | 454 | static int w9966_setup(struct w9966_dev *cam, int x1, int y1, int x2, int y2, int w, int h) |
459 | { | 455 | { |
460 | unsigned int i; | 456 | unsigned int i; |
461 | unsigned int enh_s, enh_e; | 457 | unsigned int enh_s, enh_e; |
@@ -469,84 +465,84 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in | |||
469 | }; | 465 | }; |
470 | 466 | ||
471 | 467 | ||
472 | if (w*h*2 > W9966_SRAMSIZE) | 468 | if (w * h * 2 > W9966_SRAMSIZE) { |
473 | { | ||
474 | DPRINTF("capture window exceeds SRAM size!.\n"); | 469 | DPRINTF("capture window exceeds SRAM size!.\n"); |
475 | w = 200; h = 160; // Pick default values | 470 | w = 200; h = 160; /* Pick default values */ |
476 | } | 471 | } |
477 | 472 | ||
478 | w &= ~0x1; | 473 | w &= ~0x1; |
479 | if (w < 2) w = 2; | 474 | if (w < 2) |
480 | if (h < 1) h = 1; | 475 | w = 2; |
481 | if (w > W9966_WND_MAX_W) w = W9966_WND_MAX_W; | 476 | if (h < 1) |
482 | if (h > W9966_WND_MAX_H) h = W9966_WND_MAX_H; | 477 | h = 1; |
478 | if (w > W9966_WND_MAX_W) | ||
479 | w = W9966_WND_MAX_W; | ||
480 | if (h > W9966_WND_MAX_H) | ||
481 | h = W9966_WND_MAX_H; | ||
483 | 482 | ||
484 | cam->width = w; | 483 | cam->width = w; |
485 | cam->height = h; | 484 | cam->height = h; |
486 | 485 | ||
487 | enh_s = 0; | 486 | enh_s = 0; |
488 | enh_e = w*h*2; | 487 | enh_e = w * h * 2; |
489 | 488 | ||
490 | // Modify capture window if necessary and calculate downscaling | 489 | /* Modify capture window if necessary and calculate downscaling */ |
491 | if ( | 490 | if (w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 || |
492 | w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 || | 491 | w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, &scale_y) != 0) |
493 | w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, &scale_y) != 0 | 492 | return -1; |
494 | ) return -1; | 493 | |
495 | 494 | DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n", | |
496 | DPRINTF( | 495 | w, h, x1, x2, y1, y2, scale_x & ~0x80, scale_y & ~0x80); |
497 | "%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n", | 496 | |
498 | w, h, x1, x2, y1, y2, scale_x&~0x80, scale_y&~0x80 | 497 | /* Setup registers */ |
499 | ); | 498 | regs[0x00] = 0x00; /* Set normal operation */ |
500 | 499 | regs[0x01] = 0x18; /* Capture mode */ | |
501 | // Setup registers | 500 | regs[0x02] = scale_y; /* V-scaling */ |
502 | regs[0x00] = 0x00; // Set normal operation | 501 | regs[0x03] = scale_x; /* H-scaling */ |
503 | regs[0x01] = 0x18; // Capture mode | 502 | |
504 | regs[0x02] = scale_y; // V-scaling | 503 | /* Capture window */ |
505 | regs[0x03] = scale_x; // H-scaling | 504 | regs[0x04] = (x1 & 0x0ff); /* X-start (8 low bits) */ |
506 | 505 | regs[0x05] = (x1 & 0x300)>>8; /* X-start (2 high bits) */ | |
507 | // Capture window | 506 | regs[0x06] = (y1 & 0x0ff); /* Y-start (8 low bits) */ |
508 | regs[0x04] = (x1 & 0x0ff); // X-start (8 low bits) | 507 | regs[0x07] = (y1 & 0x300)>>8; /* Y-start (2 high bits) */ |
509 | regs[0x05] = (x1 & 0x300)>>8; // X-start (2 high bits) | 508 | regs[0x08] = (x2 & 0x0ff); /* X-end (8 low bits) */ |
510 | regs[0x06] = (y1 & 0x0ff); // Y-start (8 low bits) | 509 | regs[0x09] = (x2 & 0x300)>>8; /* X-end (2 high bits) */ |
511 | regs[0x07] = (y1 & 0x300)>>8; // Y-start (2 high bits) | 510 | regs[0x0a] = (y2 & 0x0ff); /* Y-end (8 low bits) */ |
512 | regs[0x08] = (x2 & 0x0ff); // X-end (8 low bits) | 511 | |
513 | regs[0x09] = (x2 & 0x300)>>8; // X-end (2 high bits) | 512 | regs[0x0c] = W9966_SRAMID; /* SRAM-banks (1x 128kb) */ |
514 | regs[0x0a] = (y2 & 0x0ff); // Y-end (8 low bits) | 513 | |
515 | 514 | /* Enhancement layer */ | |
516 | regs[0x0c] = W9966_SRAMID; // SRAM-banks (1x 128kb) | 515 | regs[0x0d] = (enh_s & 0x000ff); /* Enh. start (0-7) */ |
517 | 516 | regs[0x0e] = (enh_s & 0x0ff00) >> 8; /* Enh. start (8-15) */ | |
518 | // Enhancement layer | 517 | regs[0x0f] = (enh_s & 0x70000) >> 16; /* Enh. start (16-17/18??) */ |
519 | regs[0x0d] = (enh_s& 0x000ff); // Enh. start (0-7) | 518 | regs[0x10] = (enh_e & 0x000ff); /* Enh. end (0-7) */ |
520 | regs[0x0e] = (enh_s& 0x0ff00)>>8; // Enh. start (8-15) | 519 | regs[0x11] = (enh_e & 0x0ff00) >> 8; /* Enh. end (8-15) */ |
521 | regs[0x0f] = (enh_s& 0x70000)>>16; // Enh. start (16-17/18??) | 520 | regs[0x12] = (enh_e & 0x70000) >> 16; /* Enh. end (16-17/18??) */ |
522 | regs[0x10] = (enh_e& 0x000ff); // Enh. end (0-7) | 521 | |
523 | regs[0x11] = (enh_e& 0x0ff00)>>8; // Enh. end (8-15) | 522 | /* Misc */ |
524 | regs[0x12] = (enh_e& 0x70000)>>16; // Enh. end (16-17/18??) | 523 | regs[0x13] = 0x40; /* VEE control (raw 4:2:2) */ |
525 | 524 | regs[0x17] = 0x00; /* ??? */ | |
526 | // Misc | 525 | regs[0x18] = cam->i2c_state = 0x00; /* Serial bus */ |
527 | regs[0x13] = 0x40; // VEE control (raw 4:2:2) | 526 | regs[0x19] = 0xff; /* I/O port direction control */ |
528 | regs[0x17] = 0x00; // ??? | 527 | regs[0x1a] = 0xff; /* I/O port data register */ |
529 | regs[0x18] = cam->i2c_state = 0x00; // Serial bus | 528 | regs[0x1b] = 0x10; /* ??? */ |
530 | regs[0x19] = 0xff; // I/O port direction control | 529 | |
531 | regs[0x1a] = 0xff; // I/O port data register | 530 | /* SAA7111 chip settings */ |
532 | regs[0x1b] = 0x10; // ??? | ||
533 | |||
534 | // SAA7111 chip settings | ||
535 | saa7111_regs[0x0a] = cam->brightness; | 531 | saa7111_regs[0x0a] = cam->brightness; |
536 | saa7111_regs[0x0b] = cam->contrast; | 532 | saa7111_regs[0x0b] = cam->contrast; |
537 | saa7111_regs[0x0c] = cam->color; | 533 | saa7111_regs[0x0c] = cam->color; |
538 | saa7111_regs[0x0d] = cam->hue; | 534 | saa7111_regs[0x0d] = cam->hue; |
539 | 535 | ||
540 | // Reset (ECP-fifo & serial-bus) | 536 | /* Reset (ECP-fifo & serial-bus) */ |
541 | if (w9966_wReg(cam, 0x00, 0x03) == -1) | 537 | if (w9966_wReg(cam, 0x00, 0x03) == -1) |
542 | return -1; | 538 | return -1; |
543 | 539 | ||
544 | // Write regs to w9966cf chip | 540 | /* Write regs to w9966cf chip */ |
545 | for (i = 0; i < 0x1c; i++) | 541 | for (i = 0; i < 0x1c; i++) |
546 | if (w9966_wReg(cam, i, regs[i]) == -1) | 542 | if (w9966_wReg(cam, i, regs[i]) == -1) |
547 | return -1; | 543 | return -1; |
548 | 544 | ||
549 | // Write regs to saa7111 chip | 545 | /* Write regs to saa7111 chip */ |
550 | for (i = 0; i < 0x20; i++) | 546 | for (i = 0; i < 0x20; i++) |
551 | if (w9966_wReg_i2c(cam, i, saa7111_regs[i]) == -1) | 547 | if (w9966_wReg_i2c(cam, i, saa7111_regs[i]) == -1) |
552 | return -1; | 548 | return -1; |
@@ -558,9 +554,9 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in | |||
558 | * Ugly and primitive i2c protocol functions | 554 | * Ugly and primitive i2c protocol functions |
559 | */ | 555 | */ |
560 | 556 | ||
561 | // Sets the data line on the i2c bus. | 557 | /* Sets the data line on the i2c bus. |
562 | // Expects a claimed pdev. | 558 | Expects a claimed pdev. */ |
563 | static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state) | 559 | static inline void w9966_i2c_setsda(struct w9966_dev *cam, int state) |
564 | { | 560 | { |
565 | if (state) | 561 | if (state) |
566 | cam->i2c_state |= W9966_I2C_W_DATA; | 562 | cam->i2c_state |= W9966_I2C_W_DATA; |
@@ -571,17 +567,17 @@ static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state) | |||
571 | udelay(5); | 567 | udelay(5); |
572 | } | 568 | } |
573 | 569 | ||
574 | // Get peripheral clock line | 570 | /* Get peripheral clock line |
575 | // Expects a claimed pdev. | 571 | Expects a claimed pdev. */ |
576 | static inline int w9966_i2c_getscl(struct w9966_dev* cam) | 572 | static inline int w9966_i2c_getscl(struct w9966_dev *cam) |
577 | { | 573 | { |
578 | const unsigned char state = w9966_rReg(cam, 0x18); | 574 | const unsigned char state = w9966_rReg(cam, 0x18); |
579 | return ((state & W9966_I2C_R_CLOCK) > 0); | 575 | return ((state & W9966_I2C_R_CLOCK) > 0); |
580 | } | 576 | } |
581 | 577 | ||
582 | // Sets the clock line on the i2c bus. | 578 | /* Sets the clock line on the i2c bus. |
583 | // Expects a claimed pdev. -1 on error | 579 | Expects a claimed pdev. -1 on error */ |
584 | static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state) | 580 | static inline int w9966_i2c_setscl(struct w9966_dev *cam, int state) |
585 | { | 581 | { |
586 | unsigned long timeout; | 582 | unsigned long timeout; |
587 | 583 | ||
@@ -593,7 +589,7 @@ static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state) | |||
593 | w9966_wReg(cam, 0x18, cam->i2c_state); | 589 | w9966_wReg(cam, 0x18, cam->i2c_state); |
594 | udelay(5); | 590 | udelay(5); |
595 | 591 | ||
596 | // we go to high, we also expect the peripheral to ack. | 592 | /* we go to high, we also expect the peripheral to ack. */ |
597 | if (state) { | 593 | if (state) { |
598 | timeout = jiffies + 100; | 594 | timeout = jiffies + 100; |
599 | while (!w9966_i2c_getscl(cam)) { | 595 | while (!w9966_i2c_getscl(cam)) { |
@@ -604,21 +600,21 @@ static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state) | |||
604 | return 0; | 600 | return 0; |
605 | } | 601 | } |
606 | 602 | ||
607 | // Get peripheral data line | 603 | /* Get peripheral data line |
608 | // Expects a claimed pdev. | 604 | Expects a claimed pdev. */ |
609 | static inline int w9966_i2c_getsda(struct w9966_dev* cam) | 605 | static inline int w9966_i2c_getsda(struct w9966_dev *cam) |
610 | { | 606 | { |
611 | const unsigned char state = w9966_rReg(cam, 0x18); | 607 | const unsigned char state = w9966_rReg(cam, 0x18); |
612 | return ((state & W9966_I2C_R_DATA) > 0); | 608 | return ((state & W9966_I2C_R_DATA) > 0); |
613 | } | 609 | } |
614 | 610 | ||
615 | // Write a byte with ack to the i2c bus. | 611 | /* Write a byte with ack to the i2c bus. |
616 | // Expects a claimed pdev. -1 on error | 612 | Expects a claimed pdev. -1 on error */ |
617 | static int w9966_i2c_wbyte(struct w9966_dev* cam, int data) | 613 | static int w9966_i2c_wbyte(struct w9966_dev *cam, int data) |
618 | { | 614 | { |
619 | int i; | 615 | int i; |
620 | for (i = 7; i >= 0; i--) | 616 | |
621 | { | 617 | for (i = 7; i >= 0; i--) { |
622 | w9966_i2c_setsda(cam, (data >> i) & 0x01); | 618 | w9966_i2c_setsda(cam, (data >> i) & 0x01); |
623 | 619 | ||
624 | if (w9966_i2c_setscl(cam, 1) == -1) | 620 | if (w9966_i2c_setscl(cam, 1) == -1) |
@@ -635,18 +631,17 @@ static int w9966_i2c_wbyte(struct w9966_dev* cam, int data) | |||
635 | return 0; | 631 | return 0; |
636 | } | 632 | } |
637 | 633 | ||
638 | // Read a data byte with ack from the i2c-bus | 634 | /* Read a data byte with ack from the i2c-bus |
639 | // Expects a claimed pdev. -1 on error | 635 | Expects a claimed pdev. -1 on error */ |
640 | #if 0 | 636 | #if 0 |
641 | static int w9966_i2c_rbyte(struct w9966_dev* cam) | 637 | static int w9966_i2c_rbyte(struct w9966_dev *cam) |
642 | { | 638 | { |
643 | unsigned char data = 0x00; | 639 | unsigned char data = 0x00; |
644 | int i; | 640 | int i; |
645 | 641 | ||
646 | w9966_i2c_setsda(cam, 1); | 642 | w9966_i2c_setsda(cam, 1); |
647 | 643 | ||
648 | for (i = 0; i < 8; i++) | 644 | for (i = 0; i < 8; i++) { |
649 | { | ||
650 | if (w9966_i2c_setscl(cam, 1) == -1) | 645 | if (w9966_i2c_setscl(cam, 1) == -1) |
651 | return -1; | 646 | return -1; |
652 | data = data << 1; | 647 | data = data << 1; |
@@ -659,20 +654,18 @@ static int w9966_i2c_rbyte(struct w9966_dev* cam) | |||
659 | } | 654 | } |
660 | #endif | 655 | #endif |
661 | 656 | ||
662 | // Read a register from the i2c device. | 657 | /* Read a register from the i2c device. |
663 | // Expects claimed pdev. -1 on error | 658 | Expects claimed pdev. -1 on error */ |
664 | #if 0 | 659 | #if 0 |
665 | static int w9966_rReg_i2c(struct w9966_dev* cam, int reg) | 660 | static int w9966_rReg_i2c(struct w9966_dev *cam, int reg) |
666 | { | 661 | { |
667 | int data; | 662 | int data; |
668 | 663 | ||
669 | w9966_i2c_setsda(cam, 0); | 664 | w9966_i2c_setsda(cam, 0); |
670 | w9966_i2c_setscl(cam, 0); | 665 | w9966_i2c_setscl(cam, 0); |
671 | 666 | ||
672 | if ( | 667 | if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 || |
673 | w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 || | 668 | w9966_i2c_wbyte(cam, reg) == -1) |
674 | w9966_i2c_wbyte(cam, reg) == -1 | ||
675 | ) | ||
676 | return -1; | 669 | return -1; |
677 | 670 | ||
678 | w9966_i2c_setsda(cam, 1); | 671 | w9966_i2c_setsda(cam, 1); |
@@ -681,10 +674,10 @@ static int w9966_rReg_i2c(struct w9966_dev* cam, int reg) | |||
681 | w9966_i2c_setsda(cam, 0); | 674 | w9966_i2c_setsda(cam, 0); |
682 | w9966_i2c_setscl(cam, 0); | 675 | w9966_i2c_setscl(cam, 0); |
683 | 676 | ||
684 | if ( | 677 | if (w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1) |
685 | w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1 || | 678 | return -1; |
686 | (data = w9966_i2c_rbyte(cam)) == -1 | 679 | data = w9966_i2c_rbyte(cam); |
687 | ) | 680 | if (data == -1) |
688 | return -1; | 681 | return -1; |
689 | 682 | ||
690 | w9966_i2c_setsda(cam, 0); | 683 | w9966_i2c_setsda(cam, 0); |
@@ -697,18 +690,16 @@ static int w9966_rReg_i2c(struct w9966_dev* cam, int reg) | |||
697 | } | 690 | } |
698 | #endif | 691 | #endif |
699 | 692 | ||
700 | // Write a register to the i2c device. | 693 | /* Write a register to the i2c device. |
701 | // Expects claimed pdev. -1 on error | 694 | Expects claimed pdev. -1 on error */ |
702 | static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data) | 695 | static int w9966_wReg_i2c(struct w9966_dev *cam, int reg, int data) |
703 | { | 696 | { |
704 | w9966_i2c_setsda(cam, 0); | 697 | w9966_i2c_setsda(cam, 0); |
705 | w9966_i2c_setscl(cam, 0); | 698 | w9966_i2c_setscl(cam, 0); |
706 | 699 | ||
707 | if ( | 700 | if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 || |
708 | w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 || | 701 | w9966_i2c_wbyte(cam, reg) == -1 || |
709 | w9966_i2c_wbyte(cam, reg) == -1 || | 702 | w9966_i2c_wbyte(cam, data) == -1) |
710 | w9966_i2c_wbyte(cam, data) == -1 | ||
711 | ) | ||
712 | return -1; | 703 | return -1; |
713 | 704 | ||
714 | w9966_i2c_setsda(cam, 0); | 705 | w9966_i2c_setsda(cam, 0); |
@@ -728,8 +719,7 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
728 | { | 719 | { |
729 | struct w9966_dev *cam = video_drvdata(file); | 720 | struct w9966_dev *cam = video_drvdata(file); |
730 | 721 | ||
731 | switch(cmd) | 722 | switch (cmd) { |
732 | { | ||
733 | case VIDIOCGCAP: | 723 | case VIDIOCGCAP: |
734 | { | 724 | { |
735 | static struct video_capability vcap = { | 725 | static struct video_capability vcap = { |
@@ -748,9 +738,9 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
748 | case VIDIOCGCHAN: | 738 | case VIDIOCGCHAN: |
749 | { | 739 | { |
750 | struct video_channel *vch = arg; | 740 | struct video_channel *vch = arg; |
751 | if(vch->channel != 0) // We only support one channel (#0) | 741 | if (vch->channel != 0) /* We only support one channel (#0) */ |
752 | return -EINVAL; | 742 | return -EINVAL; |
753 | memset(vch,0,sizeof(*vch)); | 743 | memset(vch, 0, sizeof(*vch)); |
754 | strcpy(vch->name, "CCD-input"); | 744 | strcpy(vch->name, "CCD-input"); |
755 | vch->type = VIDEO_TYPE_CAMERA; | 745 | vch->type = VIDEO_TYPE_CAMERA; |
756 | return 0; | 746 | return 0; |
@@ -758,14 +748,14 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
758 | case VIDIOCSCHAN: | 748 | case VIDIOCSCHAN: |
759 | { | 749 | { |
760 | struct video_channel *vch = arg; | 750 | struct video_channel *vch = arg; |
761 | if(vch->channel != 0) | 751 | if (vch->channel != 0) |
762 | return -EINVAL; | 752 | return -EINVAL; |
763 | return 0; | 753 | return 0; |
764 | } | 754 | } |
765 | case VIDIOCGTUNER: | 755 | case VIDIOCGTUNER: |
766 | { | 756 | { |
767 | struct video_tuner *vtune = arg; | 757 | struct video_tuner *vtune = arg; |
768 | if(vtune->tuner != 0) | 758 | if (vtune->tuner != 0) |
769 | return -EINVAL; | 759 | return -EINVAL; |
770 | strcpy(vtune->name, "no tuner"); | 760 | strcpy(vtune->name, "no tuner"); |
771 | vtune->rangelow = 0; | 761 | vtune->rangelow = 0; |
@@ -787,12 +777,12 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
787 | case VIDIOCGPICT: | 777 | case VIDIOCGPICT: |
788 | { | 778 | { |
789 | struct video_picture vpic = { | 779 | struct video_picture vpic = { |
790 | cam->brightness << 8, // brightness | 780 | cam->brightness << 8, /* brightness */ |
791 | (cam->hue + 128) << 8, // hue | 781 | (cam->hue + 128) << 8, /* hue */ |
792 | cam->color << 9, // color | 782 | cam->color << 9, /* color */ |
793 | cam->contrast << 9, // contrast | 783 | cam->contrast << 9, /* contrast */ |
794 | 0x8000, // whiteness | 784 | 0x8000, /* whiteness */ |
795 | 16, VIDEO_PALETTE_YUV422// bpp, palette format | 785 | 16, VIDEO_PALETTE_YUV422/* bpp, palette format */ |
796 | }; | 786 | }; |
797 | struct video_picture *pic = arg; | 787 | struct video_picture *pic = arg; |
798 | *pic = vpic; | 788 | *pic = vpic; |
@@ -838,7 +828,7 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
838 | if (vwin->height < 1 || vwin->height > W9966_WND_MAX_H) | 828 | if (vwin->height < 1 || vwin->height > W9966_WND_MAX_H) |
839 | return -EINVAL; | 829 | return -EINVAL; |
840 | 830 | ||
841 | // Update camera regs | 831 | /* Update camera regs */ |
842 | w9966_pdev_claim(cam); | 832 | w9966_pdev_claim(cam); |
843 | ret = w9966_setup(cam, 0, 0, 1023, 1023, vwin->width, vwin->height); | 833 | ret = w9966_setup(cam, 0, 0, 1023, 1023, vwin->width, vwin->height); |
844 | w9966_pdev_release(cam); | 834 | w9966_pdev_release(cam); |
@@ -858,7 +848,7 @@ static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
858 | vwin->height = cam->height; | 848 | vwin->height = cam->height; |
859 | return 0; | 849 | return 0; |
860 | } | 850 | } |
861 | // Unimplemented | 851 | /* Unimplemented */ |
862 | case VIDIOCCAPTURE: | 852 | case VIDIOCCAPTURE: |
863 | case VIDIOCGFBUF: | 853 | case VIDIOCGFBUF: |
864 | case VIDIOCSFBUF: | 854 | case VIDIOCSFBUF: |
@@ -880,31 +870,29 @@ static long w9966_v4l_ioctl(struct file *file, | |||
880 | return video_usercopy(file, cmd, arg, w9966_v4l_do_ioctl); | 870 | return video_usercopy(file, cmd, arg, w9966_v4l_do_ioctl); |
881 | } | 871 | } |
882 | 872 | ||
883 | // Capture data | 873 | /* Capture data */ |
884 | static ssize_t w9966_v4l_read(struct file *file, char __user *buf, | 874 | static ssize_t w9966_v4l_read(struct file *file, char __user *buf, |
885 | size_t count, loff_t *ppos) | 875 | size_t count, loff_t *ppos) |
886 | { | 876 | { |
887 | struct w9966_dev *cam = video_drvdata(file); | 877 | struct w9966_dev *cam = video_drvdata(file); |
888 | unsigned char addr = 0xa0; // ECP, read, CCD-transfer, 00000 | 878 | unsigned char addr = 0xa0; /* ECP, read, CCD-transfer, 00000 */ |
889 | unsigned char __user *dest = (unsigned char __user *)buf; | 879 | unsigned char __user *dest = (unsigned char __user *)buf; |
890 | unsigned long dleft = count; | 880 | unsigned long dleft = count; |
891 | unsigned char *tbuf; | 881 | unsigned char *tbuf; |
892 | 882 | ||
893 | // Why would anyone want more than this?? | 883 | /* Why would anyone want more than this?? */ |
894 | if (count > cam->width * cam->height * 2) | 884 | if (count > cam->width * cam->height * 2) |
895 | return -EINVAL; | 885 | return -EINVAL; |
896 | 886 | ||
897 | w9966_pdev_claim(cam); | 887 | w9966_pdev_claim(cam); |
898 | w9966_wReg(cam, 0x00, 0x02); // Reset ECP-FIFO buffer | 888 | w9966_wReg(cam, 0x00, 0x02); /* Reset ECP-FIFO buffer */ |
899 | w9966_wReg(cam, 0x00, 0x00); // Return to normal operation | 889 | w9966_wReg(cam, 0x00, 0x00); /* Return to normal operation */ |
900 | w9966_wReg(cam, 0x01, 0x98); // Enable capture | 890 | w9966_wReg(cam, 0x01, 0x98); /* Enable capture */ |
901 | 891 | ||
902 | // write special capture-addr and negotiate into data transfer | 892 | /* write special capture-addr and negotiate into data transfer */ |
903 | if ( | 893 | if ((parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0) || |
904 | (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0 )|| | 894 | (parport_write(cam->pport, &addr, 1) != 1) || |
905 | (parport_write(cam->pport, &addr, 1) != 1 )|| | 895 | (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0)) { |
906 | (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0 ) | ||
907 | ) { | ||
908 | w9966_pdev_release(cam); | 896 | w9966_pdev_release(cam); |
909 | return -EFAULT; | 897 | return -EFAULT; |
910 | } | 898 | } |
@@ -915,8 +903,7 @@ static ssize_t w9966_v4l_read(struct file *file, char __user *buf, | |||
915 | goto out; | 903 | goto out; |
916 | } | 904 | } |
917 | 905 | ||
918 | while(dleft > 0) | 906 | while (dleft > 0) { |
919 | { | ||
920 | unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft; | 907 | unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft; |
921 | 908 | ||
922 | if (parport_read(cam->pport, tbuf, tsize) < tsize) { | 909 | if (parport_read(cam->pport, tbuf, tsize) < tsize) { |
@@ -931,7 +918,7 @@ static ssize_t w9966_v4l_read(struct file *file, char __user *buf, | |||
931 | dleft -= tsize; | 918 | dleft -= tsize; |
932 | } | 919 | } |
933 | 920 | ||
934 | w9966_wReg(cam, 0x01, 0x18); // Disable capture | 921 | w9966_wReg(cam, 0x01, 0x18); /* Disable capture */ |
935 | 922 | ||
936 | out: | 923 | out: |
937 | kfree(tbuf); | 924 | kfree(tbuf); |
@@ -941,33 +928,30 @@ out: | |||
941 | } | 928 | } |
942 | 929 | ||
943 | 930 | ||
944 | // Called once for every parport on init | 931 | /* Called once for every parport on init */ |
945 | static void w9966_attach(struct parport *port) | 932 | static void w9966_attach(struct parport *port) |
946 | { | 933 | { |
947 | int i; | 934 | int i; |
948 | 935 | ||
949 | for (i = 0; i < W9966_MAXCAMS; i++) | 936 | for (i = 0; i < W9966_MAXCAMS; i++) { |
950 | { | 937 | if (w9966_cams[i].dev_state != 0) /* Cam is already assigned */ |
951 | if (w9966_cams[i].dev_state != 0) // Cam is already assigned | ||
952 | continue; | 938 | continue; |
953 | if ( | 939 | if (strcmp(pardev[i], "aggressive") == 0 || strcmp(pardev[i], port->name) == 0) { |
954 | strcmp(pardev[i], "aggressive") == 0 || | ||
955 | strcmp(pardev[i], port->name) == 0 | ||
956 | ) { | ||
957 | if (w9966_init(&w9966_cams[i], port) != 0) | 940 | if (w9966_init(&w9966_cams[i], port) != 0) |
958 | w9966_term(&w9966_cams[i]); | 941 | w9966_term(&w9966_cams[i]); |
959 | break; // return | 942 | break; /* return */ |
960 | } | 943 | } |
961 | } | 944 | } |
962 | } | 945 | } |
963 | 946 | ||
964 | // Called once for every parport on termination | 947 | /* Called once for every parport on termination */ |
965 | static void w9966_detach(struct parport *port) | 948 | static void w9966_detach(struct parport *port) |
966 | { | 949 | { |
967 | int i; | 950 | int i; |
951 | |||
968 | for (i = 0; i < W9966_MAXCAMS; i++) | 952 | for (i = 0; i < W9966_MAXCAMS; i++) |
969 | if (w9966_cams[i].dev_state != 0 && w9966_cams[i].pport == port) | 953 | if (w9966_cams[i].dev_state != 0 && w9966_cams[i].pport == port) |
970 | w9966_term(&w9966_cams[i]); | 954 | w9966_term(&w9966_cams[i]); |
971 | } | 955 | } |
972 | 956 | ||
973 | 957 | ||
@@ -977,17 +961,18 @@ static struct parport_driver w9966_ppd = { | |||
977 | .detach = w9966_detach, | 961 | .detach = w9966_detach, |
978 | }; | 962 | }; |
979 | 963 | ||
980 | // Module entry point | 964 | /* Module entry point */ |
981 | static int __init w9966_mod_init(void) | 965 | static int __init w9966_mod_init(void) |
982 | { | 966 | { |
983 | int i; | 967 | int i; |
968 | |||
984 | for (i = 0; i < W9966_MAXCAMS; i++) | 969 | for (i = 0; i < W9966_MAXCAMS; i++) |
985 | w9966_cams[i].dev_state = 0; | 970 | w9966_cams[i].dev_state = 0; |
986 | 971 | ||
987 | return parport_register_driver(&w9966_ppd); | 972 | return parport_register_driver(&w9966_ppd); |
988 | } | 973 | } |
989 | 974 | ||
990 | // Module cleanup | 975 | /* Module cleanup */ |
991 | static void __exit w9966_mod_term(void) | 976 | static void __exit w9966_mod_term(void) |
992 | { | 977 | { |
993 | parport_unregister_driver(&w9966_ppd); | 978 | parport_unregister_driver(&w9966_ppd); |