V4L/DVB: c-qcam: 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>
This commit is contained in:
Hans Verkuil
2010-03-22 04:33:56 -03:00
committed by Mauro Carvalho Chehab
parent 380de498e2
commit 51224aa436

View File

@@ -105,8 +105,7 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam,
/* If the camera didn't respond within 1/25 second, poll slowly
for a while. */
for (i = 0; i < 50; i++)
{
for (i = 0; i < 50; i++) {
if (qcam_ready1(qcam) == value)
return 0;
msleep_interruptible(100);
@@ -131,8 +130,7 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
/* If the camera didn't respond within 1/25 second, poll slowly
for a while. */
for (i = 0; i < 50; i++)
{
for (i = 0; i < 50; i++) {
if (qcam_ready2(qcam) == value)
return 0;
msleep_interruptible(100);
@@ -149,22 +147,25 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
static int qcam_read_data(struct qcam_device *qcam)
{
unsigned int idata;
qcam_set_ack(qcam, 0);
if (qcam_await_ready1(qcam, 1)) return -1;
if (qcam_await_ready1(qcam, 1))
return -1;
idata = parport_read_status(qcam->pport) & 0xf0;
qcam_set_ack(qcam, 1);
if (qcam_await_ready1(qcam, 0)) return -1;
idata |= (parport_read_status(qcam->pport) >> 4);
if (qcam_await_ready1(qcam, 0))
return -1;
idata |= parport_read_status(qcam->pport) >> 4;
return idata;
}
static int qcam_write_data(struct qcam_device *qcam, unsigned int data)
{
unsigned int idata;
parport_write_data(qcam->pport, data);
idata = qcam_read_data(qcam);
if (data != idata)
{
if (data != idata) {
printk(KERN_WARNING "cqcam: sent %x but received %x\n", data,
idata);
return 1;
@@ -212,13 +213,12 @@ static int qc_detect(struct qcam_device *qcam)
/* look for a heartbeat */
ostat = stat = parport_read_status(qcam->pport);
for (i=0; i<250; i++)
{
for (i = 0; i < 250; i++) {
mdelay(1);
stat = parport_read_status(qcam->pport);
if (ostat != stat)
{
if (++count >= 3) return 1;
if (ostat != stat) {
if (++count >= 3)
return 1;
ostat = stat;
}
}
@@ -232,13 +232,12 @@ static int qc_detect(struct qcam_device *qcam)
count = 0;
ostat = stat = parport_read_status(qcam->pport);
for (i=0; i<250; i++)
{
for (i = 0; i < 250; i++) {
mdelay(1);
stat = parport_read_status(qcam->pport);
if (ostat != stat)
{
if (++count >= 3) return 1;
if (ostat != stat) {
if (++count >= 3)
return 1;
ostat = stat;
}
}
@@ -292,25 +291,25 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u
unsigned int bytes = 0;
qcam_set_ack(q, 0);
if (q->bidirectional)
{
if (q->bidirectional) {
/* It's a bidirectional port */
while (bytes < nbytes)
{
while (bytes < nbytes) {
unsigned int lo1, hi1, lo2, hi2;
unsigned char r, g, b;
if (qcam_await_ready2(q, 1)) return bytes;
if (qcam_await_ready2(q, 1))
return bytes;
lo1 = parport_read_data(q->pport) >> 1;
hi1 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
qcam_set_ack(q, 1);
if (qcam_await_ready2(q, 0)) return bytes;
if (qcam_await_ready2(q, 0))
return bytes;
lo2 = parport_read_data(q->pport) >> 1;
hi2 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
qcam_set_ack(q, 0);
r = (lo1 | ((hi1 & 1)<<7));
r = lo1 | ((hi1 & 1) << 7);
g = ((hi1 & 0x1e) << 3) | ((hi2 & 0x1e) >> 1);
b = (lo2 | ((hi2 & 1)<<7));
b = lo2 | ((hi2 & 1) << 7);
if (force_rgb) {
buf[bytes++] = r;
buf[bytes++] = g;
@@ -321,21 +320,20 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u
buf[bytes++] = r;
}
}
}
else
{
} else {
/* It's a unidirectional port */
int i = 0, n = bytes;
unsigned char rgb[3];
while (bytes < nbytes)
{
while (bytes < nbytes) {
unsigned int hi, lo;
if (qcam_await_ready1(q, 1)) return bytes;
if (qcam_await_ready1(q, 1))
return bytes;
hi = (parport_read_status(q->pport) & 0xf0);
qcam_set_ack(q, 1);
if (qcam_await_ready1(q, 0)) return bytes;
if (qcam_await_ready1(q, 0))
return bytes;
lo = (parport_read_status(q->pport) & 0xf0);
qcam_set_ack(q, 0);
/* flip some bits */
@@ -374,16 +372,15 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
return -EFAULT;
/* Wait for camera to become ready */
for (;;)
{
for (;;) {
int i = qcam_get(q, 41);
if (i == -1) {
qc_setup(q);
return -EIO;
}
if ((i & 0x80) == 0)
break;
else
schedule();
}
@@ -394,8 +391,7 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
pixelsperline = q->width;
bitsperxfer = (is_bi_dir) ? 24 : 8;
if (is_bi_dir)
{
if (is_bi_dir) {
/* Turn the port around */
parport_data_reverse(q->pport);
mdelay(3);
@@ -413,15 +409,16 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
wantlen = lines * pixelsperline * 24 / 8;
while (wantlen)
{
while (wantlen) {
size_t t, s;
s = (wantlen > BUFSZ) ? BUFSZ : wantlen;
t = qcam_read_bytes(q, tmpbuf, s);
if (outptr < len)
{
if (outptr < len) {
size_t sz = len - outptr;
if (sz > t) sz = t;
if (sz > t)
sz = t;
if (__copy_to_user(buf + outptr, tmpbuf, sz))
break;
outptr += sz;
@@ -434,33 +431,31 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
len = outptr;
if (wantlen)
{
printk("qcam: short read.\n");
if (wantlen) {
printk(KERN_ERR "qcam: short read.\n");
if (is_bi_dir)
parport_data_forward(q->pport);
qc_setup(q);
return len;
}
if (is_bi_dir)
{
if (is_bi_dir) {
int l;
do {
l = qcam_read_bytes(q, tmpbuf, 3);
cond_resched();
} while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e));
if (force_rgb) {
if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
printk("qcam: bad EOF\n");
printk(KERN_ERR "qcam: bad EOF\n");
} else {
if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
printk("qcam: bad EOF\n");
printk(KERN_ERR "qcam: bad EOF\n");
}
qcam_set_ack(q, 0);
if (qcam_await_ready1(q, 1))
{
printk("qcam: no ack after EOF\n");
if (qcam_await_ready1(q, 1)) {
printk(KERN_ERR "qcam: no ack after EOF\n");
parport_data_forward(q->pport);
qc_setup(q);
return len;
@@ -468,16 +463,14 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
parport_data_forward(q->pport);
mdelay(3);
qcam_set_ack(q, 1);
if (qcam_await_ready1(q, 0))
{
printk("qcam: no ack to port turnaround\n");
if (qcam_await_ready1(q, 0)) {
printk(KERN_ERR "qcam: no ack to port turnaround\n");
qc_setup(q);
return len;
}
}
else
{
} else {
int l;
do {
l = qcam_read_bytes(q, tmpbuf, 1);
cond_resched();
@@ -485,10 +478,10 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
l = qcam_read_bytes(q, tmpbuf + 1, 2);
if (force_rgb) {
if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
printk("qcam: bad EOF\n");
printk(KERN_ERR "qcam: bad EOF\n");
} else {
if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
printk("qcam: bad EOF\n");
printk(KERN_ERR "qcam: bad EOF\n");
}
}
@@ -505,11 +498,11 @@ 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;
switch(cmd)
{
switch (cmd) {
case VIDIOCGCAP:
{
struct video_capability *b = arg;
strcpy(b->name, "Quickcam");
b->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
b->channels = 1;
@@ -523,6 +516,7 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCGCHAN:
{
struct video_channel *v = arg;
if (v->channel != 0)
return -EINVAL;
v->flags = 0;
@@ -535,6 +529,7 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCSCHAN:
{
struct video_channel *v = arg;
if (v->channel != 0)
return -EINVAL;
return 0;
@@ -542,6 +537,7 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCGTUNER:
{
struct video_tuner *v = arg;
if (v->tuner)
return -EINVAL;
memset(v, 0, sizeof(*v));
@@ -552,6 +548,7 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCSTUNER:
{
struct video_tuner *v = arg;
if (v->tuner)
return -EINVAL;
if (v->mode != VIDEO_MODE_AUTO)
@@ -561,6 +558,7 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOCGPICT:
{
struct video_picture *p = arg;
p->colour = 0x8000;
p->hue = 0x8000;
p->brightness = qcam->brightness << 8;
@@ -611,22 +609,19 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
qcam->height = 60;
qcam->mode = QC_DECIMATION_4;
if(vw->width>=160 && vw->height>=120)
{
if (vw->width >= 160 && vw->height >= 120) {
qcam->width = 160;
qcam->height = 120;
qcam->mode = QC_DECIMATION_2;
}
if(vw->width>=320 && vw->height>=240)
{
if (vw->width >= 320 && vw->height >= 240) {
qcam->width = 320;
qcam->height = 240;
qcam->mode = QC_DECIMATION_1;
}
qcam->mode |= QC_MILLIONS;
#if 0
if(vw->width>=640 && vw->height>=480)
{
if (vw->width >= 640 && vw->height >= 480) {
qcam->width = 640;
qcam->height = 480;
qcam->mode = QC_BILLIONS | QC_DECIMATION_1;
@@ -713,8 +708,7 @@ static const struct v4l2_file_operations qcam_fops = {
.read = qcam_read,
};
static struct video_device qcam_template=
{
static struct video_device qcam_template = {
.name = "Colour QuickCam",
.fops = &qcam_fops,
.release = video_device_release_empty,
@@ -736,8 +730,7 @@ static struct qcam_device *qcam_init(struct parport *port)
q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE) ? 1 : 0;
if (q->pdev == NULL)
{
if (q->pdev == NULL) {
printk(KERN_ERR "c-qcam: couldn't register for %s.\n",
port->name);
kfree(q);
@@ -765,12 +758,11 @@ static int init_cqcam(struct parport *port)
{
struct qcam_device *qcam;
if (parport[0] != -1)
{
if (parport[0] != -1) {
/* The user gave specific instructions */
int i, found = 0;
for (i = 0; i < MAX_CAMS && parport[i] != -1; i++)
{
for (i = 0; i < MAX_CAMS && parport[i] != -1; i++) {
if (parport[0] == port->number)
found = 1;
}
@@ -789,8 +781,7 @@ static int init_cqcam(struct parport *port)
qc_reset(qcam);
if (probe && qc_detect(qcam)==0)
{
if (probe && qc_detect(qcam) == 0) {
parport_release(qcam->pdev);
parport_unregister_device(qcam->pdev);
kfree(qcam);
@@ -862,9 +853,9 @@ MODULE_DESCRIPTION(BANNER);
MODULE_LICENSE("GPL");
/* FIXME: parport=auto would never have worked, surely? --RR */
MODULE_PARM_DESC(parport ,"parport=<auto|n[,n]...> for port detection method\n\
probe=<0|1|2> for camera detection method\n\
force_rgb=<0|1> for RGB data format (default BGR)");
MODULE_PARM_DESC(parport, "parport=<auto|n[,n]...> for port detection method\n"
"probe=<0|1|2> for camera detection method\n"
"force_rgb=<0|1> for RGB data format (default BGR)");
module_param_array(parport, int, NULL, 0);
module_param(probe, int, 0);
module_param(force_rgb, bool, 0);