Commit 87b6d65e authored by Stelian Pop's avatar Stelian Pop Committed by Linus Torvalds

[PATCH] meye: cleanup init/exit paths

Signed-off-by: default avatarStelian Pop <stelian@popies.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fd050f09
...@@ -837,13 +837,14 @@ static int meye_open(struct inode *inode, struct file *file) { ...@@ -837,13 +837,14 @@ static int meye_open(struct inode *inode, struct file *file) {
err = video_exclusive_open(inode,file); err = video_exclusive_open(inode,file);
if (err < 0) if (err < 0)
return err; return err;
mchip_hic_stop();
if (mchip_dma_alloc()) { if (mchip_dma_alloc()) {
printk(KERN_ERR "meye: mchip framebuffer allocation failed\n"); printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
video_exclusive_release(inode,file); video_exclusive_release(inode,file);
return -ENOBUFS; return -ENOBUFS;
} }
mchip_hic_stop();
for (i = 0; i < MEYE_MAX_BUFNBRS; i++) for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
meye.grab_buffer[i].state = MEYE_BUF_UNUSED; meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
...@@ -1250,22 +1251,20 @@ static int meye_resume(struct pci_dev *pdev) ...@@ -1250,22 +1251,20 @@ static int meye_resume(struct pci_dev *pdev)
static int __devinit meye_probe(struct pci_dev *pcidev, static int __devinit meye_probe(struct pci_dev *pcidev,
const struct pci_device_id *ent) { const struct pci_device_id *ent) {
int ret; int ret = -EBUSY;
unsigned long mchip_adr; unsigned long mchip_adr;
u8 revision; u8 revision;
if (meye.mchip_dev != NULL) { if (meye.mchip_dev != NULL) {
printk(KERN_ERR "meye: only one device allowed!\n"); printk(KERN_ERR "meye: only one device allowed!\n");
ret = -EBUSY; goto outnotdev;
goto out1;
} }
meye.mchip_dev = pcidev; meye.mchip_dev = pcidev;
meye.video_dev = video_device_alloc(); meye.video_dev = video_device_alloc();
if (!meye.video_dev) { if (!meye.video_dev) {
printk(KERN_ERR "meye: video_device_alloc() failed!\n"); printk(KERN_ERR "meye: video_device_alloc() failed!\n");
ret = -EBUSY; goto outnotdev;
goto out1;
} }
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1295,46 +1294,42 @@ static int __devinit meye_probe(struct pci_dev *pcidev, ...@@ -1295,46 +1294,42 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 1); sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 1);
ret = -EIO;
if ((ret = pci_enable_device(meye.mchip_dev))) { if ((ret = pci_enable_device(meye.mchip_dev))) {
printk(KERN_ERR "meye: pci_enable_device failed\n"); printk(KERN_ERR "meye: pci_enable_device failed\n");
goto out2; goto outenabledev;
} }
meye.mchip_irq = pcidev->irq;
mchip_adr = pci_resource_start(meye.mchip_dev,0); mchip_adr = pci_resource_start(meye.mchip_dev,0);
if (!mchip_adr) { if (!mchip_adr) {
printk(KERN_ERR "meye: mchip has no device base address\n"); printk(KERN_ERR "meye: mchip has no device base address\n");
ret = -EIO; goto outregions;
goto out3;
} }
if (!request_mem_region(pci_resource_start(meye.mchip_dev, 0), if (!request_mem_region(pci_resource_start(meye.mchip_dev, 0),
pci_resource_len(meye.mchip_dev, 0), pci_resource_len(meye.mchip_dev, 0),
"meye")) { "meye")) {
ret = -EIO;
printk(KERN_ERR "meye: request_mem_region failed\n"); printk(KERN_ERR "meye: request_mem_region failed\n");
goto out3; goto outregions;
}
meye.mchip_mmregs = ioremap(mchip_adr, MCHIP_MM_REGS);
if (!meye.mchip_mmregs) {
printk(KERN_ERR "meye: ioremap failed\n");
goto outremap;
} }
pci_read_config_byte(meye.mchip_dev, PCI_REVISION_ID, &revision); meye.mchip_irq = pcidev->irq;
if (request_irq(meye.mchip_irq, meye_irq,
pci_set_master(meye.mchip_dev); SA_INTERRUPT | SA_SHIRQ, "meye", meye_irq)) {
printk(KERN_ERR "meye: request_irq failed\n");
goto outreqirq;
}
pci_read_config_byte(meye.mchip_dev, PCI_REVISION_ID, &revision);
pci_write_config_byte(meye.mchip_dev, PCI_CACHE_LINE_SIZE, 8); pci_write_config_byte(meye.mchip_dev, PCI_CACHE_LINE_SIZE, 8);
pci_write_config_byte(meye.mchip_dev, PCI_LATENCY_TIMER, 64); pci_write_config_byte(meye.mchip_dev, PCI_LATENCY_TIMER, 64);
if ((ret = request_irq(meye.mchip_irq, meye_irq, pci_set_master(meye.mchip_dev);
SA_INTERRUPT | SA_SHIRQ, "meye", meye_irq))) {
printk(KERN_ERR "meye: request_irq failed (ret=%d)\n", ret);
goto out4;
}
meye.mchip_mmregs = ioremap(mchip_adr, MCHIP_MM_REGS);
if (!meye.mchip_mmregs) {
printk(KERN_ERR "meye: ioremap failed\n");
ret = -EIO;
goto out5;
}
/* Ask the camera to perform a soft reset. */ /* Ask the camera to perform a soft reset. */
pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1); pci_write_config_word(meye.mchip_dev, MCHIP_PCI_SOFTRESET_SET, 1);
...@@ -1353,20 +1348,11 @@ static int __devinit meye_probe(struct pci_dev *pcidev, ...@@ -1353,20 +1348,11 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
if (video_register_device(meye.video_dev, VFL_TYPE_GRABBER, video_nr) < 0) { if (video_register_device(meye.video_dev, VFL_TYPE_GRABBER, video_nr) < 0) {
printk(KERN_ERR "meye: video_register_device failed\n"); printk(KERN_ERR "meye: video_register_device failed\n");
ret = -EIO; goto outvideoreg;
goto out6;
} }
printk(KERN_INFO "meye: Motion Eye Camera Driver v%d.%d.\n",
MEYE_DRIVER_MAJORVERSION,
MEYE_DRIVER_MINORVERSION);
printk(KERN_INFO "meye: mchip KL5A72002 rev. %d, base %lx, irq %d\n",
revision, mchip_adr, meye.mchip_irq);
/* init all fields */
init_MUTEX(&meye.lock); init_MUTEX(&meye.lock);
init_waitqueue_head(&meye.proc_list); init_waitqueue_head(&meye.proc_list);
meye.picture.depth = 16; meye.picture.depth = 16;
meye.picture.palette = VIDEO_PALETTE_YUV422; meye.picture.palette = VIDEO_PALETTE_YUV422;
meye.picture.brightness = 32 << 10; meye.picture.brightness = 32 << 10;
...@@ -1375,11 +1361,12 @@ static int __devinit meye_probe(struct pci_dev *pcidev, ...@@ -1375,11 +1361,12 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
meye.picture.contrast = 32 << 10; meye.picture.contrast = 32 << 10;
meye.picture.whiteness = 0; meye.picture.whiteness = 0;
meye.params.subsample = 0; meye.params.subsample = 0;
meye.params.quality = 7; meye.params.quality = 8;
meye.params.sharpness = 32; meye.params.sharpness = 32;
meye.params.agc = 48; meye.params.agc = 48;
meye.params.picture = 0; meye.params.picture = 0;
meye.params.framerate = 0; meye.params.framerate = 0;
sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 32); sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 32);
sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 32); sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 32);
sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 32); sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 32);
...@@ -1388,20 +1375,23 @@ static int __devinit meye_probe(struct pci_dev *pcidev, ...@@ -1388,20 +1375,23 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 0); sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 0);
sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 48); sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 48);
printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n",
MEYE_DRIVER_VERSION);
printk(KERN_INFO "meye: mchip KL5A72002 rev. %d, base %lx, irq %d\n",
revision, mchip_adr, meye.mchip_irq);
return 0; return 0;
out6:
iounmap(meye.mchip_mmregs); outvideoreg:
out5:
free_irq(meye.mchip_irq, meye_irq); free_irq(meye.mchip_irq, meye_irq);
out4: outreqirq:
iounmap(meye.mchip_mmregs);
outremap:
release_mem_region(pci_resource_start(meye.mchip_dev, 0), release_mem_region(pci_resource_start(meye.mchip_dev, 0),
pci_resource_len(meye.mchip_dev, 0)); pci_resource_len(meye.mchip_dev, 0));
out3: outregions:
pci_disable_device(meye.mchip_dev); pci_disable_device(meye.mchip_dev);
out2: outenabledev:
video_device_release(meye.video_dev);
meye.video_dev = NULL;
sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0);
kfifo_free(meye.doneq); kfifo_free(meye.doneq);
outkfifoalloc2: outkfifoalloc2:
...@@ -1410,7 +1400,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev, ...@@ -1410,7 +1400,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
vfree(meye.grab_temp); vfree(meye.grab_temp);
outvmalloc: outvmalloc:
video_device_release(meye.video_dev); video_device_release(meye.video_dev);
out1: outnotdev:
return ret; return ret;
} }
...@@ -1434,9 +1424,6 @@ static void __devexit meye_remove(struct pci_dev *pcidev) { ...@@ -1434,9 +1424,6 @@ static void __devexit meye_remove(struct pci_dev *pcidev) {
pci_disable_device(meye.mchip_dev); pci_disable_device(meye.mchip_dev);
if (meye.grab_fbuffer)
rvfree(meye.grab_fbuffer, gbuffers*gbufsize);
sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0);
kfifo_free(meye.doneq); kfifo_free(meye.doneq);
...@@ -1444,6 +1431,11 @@ static void __devexit meye_remove(struct pci_dev *pcidev) { ...@@ -1444,6 +1431,11 @@ static void __devexit meye_remove(struct pci_dev *pcidev) {
vfree(meye.grab_temp); vfree(meye.grab_temp);
if (meye.grab_fbuffer) {
rvfree(meye.grab_fbuffer, gbuffers*gbufsize);
meye.grab_fbuffer = NULL;
}
printk(KERN_INFO "meye: removed\n"); printk(KERN_INFO "meye: removed\n");
} }
...@@ -1467,12 +1459,10 @@ static struct pci_driver meye_driver = { ...@@ -1467,12 +1459,10 @@ static struct pci_driver meye_driver = {
}; };
static int __init meye_init(void) { static int __init meye_init(void) {
if (gbuffers < 2) gbuffers = max(2, min((int)gbuffers, MEYE_MAX_BUFNBRS));
gbuffers = 2;
if (gbuffers > MEYE_MAX_BUFNBRS)
gbuffers = MEYE_MAX_BUFNBRS;
if (gbufsize < 0 || gbufsize > MEYE_MAX_BUFSIZE) if (gbufsize < 0 || gbufsize > MEYE_MAX_BUFSIZE)
gbufsize = MEYE_MAX_BUFSIZE; gbufsize = MEYE_MAX_BUFSIZE;
gbufsize = PAGE_ALIGN(gbufsize);
printk(KERN_INFO "meye: using %d buffers with %dk (%dk total) for capture\n", printk(KERN_INFO "meye: using %d buffers with %dk (%dk total) for capture\n",
gbuffers, gbufsize/1024, gbuffers*gbufsize/1024); gbuffers, gbufsize/1024, gbuffers*gbufsize/1024);
return pci_module_init(&meye_driver); return pci_module_init(&meye_driver);
......
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