Commit 1d61aac0 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB: bw-qcam: coding style cleanup

Clean up the coding style before we convert this driver to V4L2.
Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 51224aa4
......@@ -80,8 +80,8 @@ OTHER DEALINGS IN THE SOFTWARE.
#include "bw-qcam.h"
static unsigned int maxpoll=250; /* Maximum busy-loop count for qcam I/O */
static unsigned int yieldlines=4; /* Yield after this many during capture */
static unsigned int maxpoll = 250; /* Maximum busy-loop count for qcam I/O */
static unsigned int yieldlines = 4; /* Yield after this many during capture */
static int video_nr = -1;
static unsigned int force_init; /* Whether to probe aggressively */
......@@ -156,7 +156,7 @@ static int qc_calibrate(struct qcam_device *q)
mdelay(1);
schedule();
count++;
} while (value == 0xff && count<2048);
} while (value == 0xff && count < 2048);
q->whitebal = value;
return value;
......@@ -170,14 +170,13 @@ static struct qcam_device *qcam_init(struct parport *port)
struct qcam_device *q;
q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
if(q==NULL)
if (q == NULL)
return NULL;
q->pport = port;
q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL,
NULL, 0, NULL);
if (q->pdev == NULL)
{
if (q->pdev == NULL) {
printk(KERN_ERR "bw-qcam: couldn't register for %s.\n",
port->name);
kfree(q);
......@@ -247,12 +246,10 @@ static int qc_readparam(struct qcam_device *q)
static int qc_waithand(struct qcam_device *q, int val)
{
int status;
int runs=0;
int runs = 0;
if (val)
{
while (!((status = read_lpstatus(q)) & 8))
{
if (val) {
while (!((status = read_lpstatus(q)) & 8)) {
/* 1000 is enough spins on the I/O for all normal
cases, at that point we start to poll slowly
until the camera wakes up. However, we are
......@@ -260,18 +257,13 @@ static int qc_waithand(struct qcam_device *q, int val)
setting it lower is much better for interactive
response. */
if(runs++>maxpoll)
{
if (runs++ > maxpoll)
msleep_interruptible(5);
}
if(runs>(maxpoll+1000)) /* 5 seconds */
if (runs > (maxpoll + 1000)) /* 5 seconds */
return -1;
}
}
else
{
while (((status = read_lpstatus(q)) & 8))
{
} else {
while (((status = read_lpstatus(q)) & 8)) {
/* 1000 is enough spins on the I/O for all normal
cases, at that point we start to poll slowly
until the camera wakes up. However, we are
......@@ -279,11 +271,9 @@ static int qc_waithand(struct qcam_device *q, int val)
setting it lower is much better for interactive
response. */
if(runs++>maxpoll)
{
if (runs++ > maxpoll)
msleep_interruptible(5);
}
if(runs++>(maxpoll+1000)) /* 5 seconds */
if (runs++ > (maxpoll + 1000)) /* 5 seconds */
return -1;
}
}
......@@ -299,10 +289,9 @@ static int qc_waithand(struct qcam_device *q, int val)
static unsigned int qc_waithand2(struct qcam_device *q, int val)
{
unsigned int status;
int runs=0;
int runs = 0;
do
{
do {
status = read_lpdata(q);
/* 1000 is enough spins on the I/O for all normal
cases, at that point we start to poll slowly
......@@ -311,14 +300,11 @@ static unsigned int qc_waithand2(struct qcam_device *q, int val)
setting it lower is much better for interactive
response. */
if(runs++>maxpoll)
{
if (runs++ > maxpoll)
msleep_interruptible(5);
}
if(runs++>(maxpoll+1000)) /* 5 seconds */
if (runs++ > (maxpoll + 1000)) /* 5 seconds */
return 0;
}
while ((status & 1) != val);
} while ((status & 1) != val);
return status;
}
......@@ -342,8 +328,7 @@ static int qc_detect(struct qcam_device *q)
lastreg = reg = read_lpstatus(q) & 0xf0;
for (i = 0; i < 500; i++)
{
for (i = 0; i < 500; i++) {
reg = read_lpstatus(q) & 0xf0;
if (reg != lastreg)
count++;
......@@ -357,7 +342,7 @@ static int qc_detect(struct qcam_device *q)
won't be flashing these bits. Possibly unloading the module
in the middle of a grab? Or some timeout condition?
I've seen this parameter as low as 19 on my 450Mhz box - mpc */
printk("Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count);
printk(KERN_DEBUG "Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count);
return 1;
#endif
......@@ -381,8 +366,7 @@ static int qc_detect(struct qcam_device *q)
static void qc_reset(struct qcam_device *q)
{
switch (q->port_mode & QC_FORCE_MASK)
{
switch (q->port_mode & QC_FORCE_MASK) {
case QC_FORCE_UNIDIR:
q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
break;
......@@ -395,11 +379,10 @@ static void qc_reset(struct qcam_device *q)
write_lpcontrol(q, 0x20);
write_lpdata(q, 0x75);
if (read_lpdata(q) != 0x75) {
if (read_lpdata(q) != 0x75)
q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
} else {
else
q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
}
break;
}
......@@ -423,8 +406,7 @@ static int qc_setscanmode(struct qcam_device *q)
{
int old_mode = q->mode;
switch (q->transfer_scale)
{
switch (q->transfer_scale) {
case 1:
q->mode = 0;
break;
......@@ -436,8 +418,7 @@ static int qc_setscanmode(struct qcam_device *q)
break;
}
switch (q->bpp)
{
switch (q->bpp) {
case 4:
break;
case 6:
......@@ -445,8 +426,7 @@ static int qc_setscanmode(struct qcam_device *q)
break;
}
switch (q->port_mode & QC_MODE_MASK)
{
switch (q->port_mode & QC_MODE_MASK) {
case QC_BIDIR:
q->mode += 1;
break;
......@@ -521,19 +501,17 @@ static void qc_set(struct qcam_device *q)
static inline int qc_readbytes(struct qcam_device *q, char buffer[])
{
int ret=1;
int ret = 1;
unsigned int hi, lo;
unsigned int hi2, lo2;
static int state;
if (buffer == NULL)
{
if (buffer == NULL) {
state = 0;
return 0;
}
switch (q->port_mode & QC_MODE_MASK)
{
switch (q->port_mode & QC_MODE_MASK) {
case QC_BIDIR: /* Bi-directional Port */
write_lpcontrol(q, 0x26);
lo = (qc_waithand2(q, 1) >> 1);
......@@ -541,8 +519,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
write_lpcontrol(q, 0x2e);
lo2 = (qc_waithand2(q, 0) >> 1);
hi2 = (read_lpstatus(q) >> 3) & 0x1f;
switch (q->bpp)
{
switch (q->bpp) {
case 4:
buffer[0] = lo & 0xf;
buffer[1] = ((lo & 0x70) >> 4) | ((hi & 1) << 3);
......@@ -568,16 +545,14 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
write_lpcontrol(q, 0xe);
hi = (qc_waithand(q, 0) & 0xf0) >> 4;
switch (q->bpp)
{
switch (q->bpp) {
case 4:
buffer[0] = lo;
buffer[1] = hi;
ret = 2;
break;
case 6:
switch (state)
{
switch (state) {
case 0:
buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
q->saved_bits = (hi & 3) << 4;
......@@ -615,7 +590,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
* n=2^(bit depth)-1. Ask me for more details if you don't understand
* this. */
static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long len)
static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long len)
{
int i, j, k, yield;
int bytes;
......@@ -623,9 +598,9 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
int divisor;
int pixels_per_line;
int pixels_read = 0;
int got=0;
int got = 0;
char buffer[6];
int shift=8-q->bpp;
int shift = 8 - q->bpp;
char invert;
if (q->mode == -1)
......@@ -634,13 +609,12 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
qc_command(q, 0x7);
qc_command(q, q->mode);
if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
{
if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
write_lpcontrol(q, 0x2e); /* turn port around */
write_lpcontrol(q, 0x26);
(void) qc_waithand(q, 1);
qc_waithand(q, 1);
write_lpcontrol(q, 0x2e);
(void) qc_waithand(q, 0);
qc_waithand(q, 0);
}
/* strange -- should be 15:63 below, but 4bpp is odd */
......@@ -653,30 +627,25 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
q->transfer_scale;
transperline = DIV_ROUND_UP(transperline, divisor);
for (i = 0, yield = yieldlines; i < linestotrans; i++)
{
for (pixels_read = j = 0; j < transperline; j++)
{
for (i = 0, yield = yieldlines; i < linestotrans; i++) {
for (pixels_read = j = 0; j < transperline; j++) {
bytes = qc_readbytes(q, buffer);
for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++)
{
for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++) {
int o;
if (buffer[k] == 0 && invert == 16)
{
if (buffer[k] == 0 && invert == 16) {
/* 4bpp is odd (again) -- inverter is 16, not 15, but output
must be 0-15 -- bls */
buffer[k] = 16;
}
o=i*pixels_per_line + pixels_read + k;
if(o<len)
{
o = i * pixels_per_line + pixels_read + k;
if (o < len) {
got++;
put_user((invert - buffer[k])<<shift, buf+o);
put_user((invert - buffer[k]) << shift, buf + o);
}
}
pixels_read += bytes;
}
(void) qc_readbytes(q, NULL); /* reset state machine */
qc_readbytes(q, NULL); /* reset state machine */
/* Grabbing an entire frame from the quickcam is a lengthy
process. We don't (usually) want to busy-block the
......@@ -690,14 +659,13 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
}
}
if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
{
if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
write_lpcontrol(q, 2);
write_lpcontrol(q, 6);
udelay(3);
write_lpcontrol(q, 0xe);
}
if(got<len)
if (got < len)
return got;
return len;
}
......@@ -709,10 +677,9 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
{
struct video_device *dev = video_devdata(file);
struct qcam_device *qcam=(struct qcam_device *)dev;
struct qcam_device *qcam = (struct qcam_device *)dev;
switch(cmd)
{
switch (cmd) {
case VIDIOCGCAP:
{
struct video_capability *b = arg;
......@@ -729,10 +696,10 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCGCHAN:
{
struct video_channel *v = arg;
if(v->channel!=0)
if (v->channel != 0)
return -EINVAL;
v->flags=0;
v->tuners=0;
v->flags = 0;
v->tuners = 0;
/* Good question.. its composite or SVHS so.. */
v->type = VIDEO_TYPE_CAMERA;
strcpy(v->name, "Camera");
......@@ -741,58 +708,58 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCSCHAN:
{
struct video_channel *v = arg;
if(v->channel!=0)
if (v->channel != 0)
return -EINVAL;
return 0;
}
case VIDIOCGTUNER:
{
struct video_tuner *v = arg;
if(v->tuner)
if (v->tuner)
return -EINVAL;
strcpy(v->name, "Format");
v->rangelow=0;
v->rangehigh=0;
v->flags= 0;
v->rangelow = 0;
v->rangehigh = 0;
v->flags = 0;
v->mode = VIDEO_MODE_AUTO;
return 0;
}
case VIDIOCSTUNER:
{
struct video_tuner *v = arg;
if(v->tuner)
if (v->tuner)
return -EINVAL;
if(v->mode!=VIDEO_MODE_AUTO)
if (v->mode != VIDEO_MODE_AUTO)
return -EINVAL;
return 0;
}
case VIDIOCGPICT:
{
struct video_picture *p = arg;
p->colour=0x8000;
p->hue=0x8000;
p->brightness=qcam->brightness<<8;
p->contrast=qcam->contrast<<8;
p->whiteness=qcam->whitebal<<8;
p->depth=qcam->bpp;
p->palette=VIDEO_PALETTE_GREY;
p->colour = 0x8000;
p->hue = 0x8000;
p->brightness = qcam->brightness << 8;
p->contrast = qcam->contrast << 8;
p->whiteness = qcam->whitebal << 8;
p->depth = qcam->bpp;
p->palette = VIDEO_PALETTE_GREY;
return 0;
}
case VIDIOCSPICT:
{
struct video_picture *p = arg;
if(p->palette!=VIDEO_PALETTE_GREY)
if (p->palette != VIDEO_PALETTE_GREY)
return -EINVAL;
if(p->depth!=4 && p->depth!=6)
if (p->depth != 4 && p->depth != 6)
return -EINVAL;
/*
* Now load the camera.
*/
qcam->brightness = p->brightness>>8;
qcam->contrast = p->contrast>>8;
qcam->whitebal = p->whiteness>>8;
qcam->brightness = p->brightness >> 8;
qcam->contrast = p->contrast >> 8;
qcam->whitebal = p->whiteness >> 8;
qcam->bpp = p->depth;
mutex_lock(&qcam->lock);
......@@ -805,25 +772,22 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCSWIN:
{
struct video_window *vw = arg;
if(vw->flags)
if (vw->flags)
return -EINVAL;
if(vw->clipcount)
if (vw->clipcount)
return -EINVAL;
if(vw->height<60||vw->height>240)
if (vw->height < 60 || vw->height > 240)
return -EINVAL;
if(vw->width<80||vw->width>320)
if (vw->width < 80 || vw->width > 320)
return -EINVAL;
qcam->width = 320;
qcam->height = 240;
qcam->transfer_scale = 4;
if(vw->width>=160 && vw->height>=120)
{
if (vw->width >= 160 && vw->height >= 120)
qcam->transfer_scale = 2;
}
if(vw->width>=320 && vw->height>=240)
{
if (vw->width >= 320 && vw->height >= 240) {
qcam->width = 320;
qcam->height = 240;
qcam->transfer_scale = 1;
......@@ -842,9 +806,10 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCGWIN:
{
struct video_window *vw = arg;
memset(vw, 0, sizeof(*vw));
vw->width=qcam->width/qcam->transfer_scale;
vw->height=qcam->height/qcam->transfer_scale;
vw->width = qcam->width / qcam->transfer_scale;
vw->height = qcam->height / qcam->transfer_scale;
return 0;
}
case VIDIOCKEY:
......@@ -873,7 +838,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct video_device *v = video_devdata(file);
struct qcam_device *qcam=(struct qcam_device *)v;
struct qcam_device *qcam = (struct qcam_device *)v;
int len;
parport_claim_or_block(qcam->pdev);
......@@ -885,7 +850,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
if (qcam->status & QC_PARAM_CHANGE)
qc_set(qcam);
len=qc_capture(qcam, buf,count);
len = qc_capture(qcam, buf, count);
mutex_unlock(&qcam->lock);
......@@ -917,8 +882,7 @@ static const struct v4l2_file_operations qcam_fops = {
.ioctl = qcam_ioctl,
.read = qcam_read,
};
static struct video_device qcam_template=
{
static struct video_device qcam_template = {
.name = "Connectix Quickcam",
.fops = &qcam_fops,
.release = video_device_release_empty,
......@@ -932,22 +896,20 @@ static int init_bwqcam(struct parport *port)
{
struct qcam_device *qcam;
if (num_cams == MAX_CAMS)
{
if (num_cams == MAX_CAMS) {
printk(KERN_ERR "Too many Quickcams (max %d)\n", MAX_CAMS);
return -ENOSPC;
}
qcam=qcam_init(port);
if(qcam==NULL)
qcam = qcam_init(port);
if (qcam == NULL)
return -ENODEV;
parport_claim_or_block(qcam->pdev);
qc_reset(qcam);
if(qc_detect(qcam)==0)
{
if (qc_detect(qcam) == 0) {
parport_release(qcam->pdev);
parport_unregister_device(qcam->pdev);
kfree(qcam);
......@@ -1045,12 +1007,12 @@ static int __init init_bw_qcams(void)
#ifdef MODULE
/* Do some sanity checks on the module parameters. */
if (maxpoll > 5000) {
printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n");
printk(KERN_INFO "Connectix Quickcam max-poll was above 5000. Using 5000.\n");
maxpoll = 5000;
}
if (yieldlines < 1) {
printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n");
printk(KERN_INFO "Connectix Quickcam yieldlines was less than 1. Using 1.\n");
yieldlines = 1;
}
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment