summaryrefslogtreecommitdiff
path: root/linux/drivers/media/common
diff options
context:
space:
mode:
authorAndrew de Quincy <devnull@localhost>2004-10-28 17:37:07 +0000
committerAndrew de Quincy <devnull@localhost>2004-10-28 17:37:07 +0000
commit25da23146538519f0f644671c49868bfb560740a (patch)
tree7987970be2d5e86492325711d234ff59319f2685 /linux/drivers/media/common
parentdcc0614123e60b1b01ed67850ebd22a517d8c086 (diff)
downloadmediapointer-dvb-s2-25da23146538519f0f644671c49868bfb560740a.tar.gz
mediapointer-dvb-s2-25da23146538519f0f644671c49868bfb560740a.tar.bz2
Imported FE_REFACTORING to HEAD
Diffstat (limited to 'linux/drivers/media/common')
-rw-r--r--linux/drivers/media/common/saa7146_core.c172
1 files changed, 91 insertions, 81 deletions
diff --git a/linux/drivers/media/common/saa7146_core.c b/linux/drivers/media/common/saa7146_core.c
index 7c076b2ef..2c8e70a66 100644
--- a/linux/drivers/media/common/saa7146_core.c
+++ b/linux/drivers/media/common/saa7146_core.c
@@ -48,7 +48,7 @@ static void dump_registers(struct saa7146_dev* dev)
* gpio and debi helper functions
****************************************************************************/
-/* write "data" to the gpio-pin "pin" */
+/* write "data" to the gpio-pin "pin" -- unused */
void saa7146_set_gpio(struct saa7146_dev *dev, u8 pin, u8 data)
{
u32 value = 0;
@@ -250,7 +250,7 @@ void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data)
/* interrupt handler */
static irqreturn_t interrupt_hw(int irq, void *dev_id, struct pt_regs *regs)
{
- struct saa7146_dev *dev = (struct saa7146_dev*)dev_id;
+ struct saa7146_dev *dev = dev_id;
u32 isr = 0;
/* read out the interrupt status register */
@@ -317,16 +317,15 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id, struct pt_regs *regs)
static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent)
{
- unsigned long adr = 0, len = 0;
- struct saa7146_dev* dev = kmalloc (sizeof(struct saa7146_dev),GFP_KERNEL);
-
struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data;
- struct saa7146_extension* ext = pci_ext->ext;
- int err = 0;
+ struct saa7146_extension *ext = pci_ext->ext;
+ struct saa7146_dev *dev;
+ int err = -ENOMEM;
- if (!(dev = kmalloc (sizeof(struct saa7146_dev),GFP_KERNEL))) {
+ dev = kmalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
+ if (!dev) {
ERR(("out of memory.\n"));
- return -ENOMEM;
+ goto out;
}
/* clear out mem for sure */
@@ -334,38 +333,37 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
DEB_EE(("pci:%p\n",pci));
- if (pci_enable_device(pci)) {
+ err = pci_enable_device(pci);
+ if (err < 0) {
ERR(("pci_enable_device() failed.\n"));
- err = -EIO;
- goto pci_error;
+ goto err_free;
}
/* enable bus-mastering */
pci_set_master(pci);
dev->pci = pci;
+
/* get chip-revision; this is needed to enable bug-fixes */
- if( 0 > pci_read_config_dword(dev->pci, PCI_CLASS_REVISION, &dev->revision)) {
+ err = pci_read_config_dword(pci, PCI_CLASS_REVISION, &dev->revision);
+ if (err < 0) {
ERR(("pci_read_config_dword() failed.\n"));
- err = -ENODEV;
- goto pci_error;
+ goto err_disable;
}
dev->revision &= 0xf;
/* remap the memory from virtual to physical adress */
- adr = pci_resource_start(pci,0);
- len = pci_resource_len(pci,0);
- if (!request_mem_region(pci_resource_start(pci,0), pci_resource_len(pci,0), "saa7146")) {
- ERR(("request_mem_region() failed.\n"));
- err = -ENODEV;
- goto pci_error;
- }
+ err = pci_request_region(pci, 0, "saa7146");
+ if (err < 0)
+ goto err_disable;
- if (!(dev->mem = ioremap(adr,len))) {
+ dev->mem = ioremap(pci_resource_start(pci, 0),
+ pci_resource_len(pci, 0));
+ if (!dev->mem) {
ERR(("ioremap() failed.\n"));
err = -ENODEV;
- goto ioremap_error;
+ goto err_release;
}
/* we don't do a master reset here anymore, it screws up
@@ -385,45 +383,43 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
saa7146_write(dev, MC2, 0xf8000000);
/* request an interrupt for the saa7146 */
- if (request_irq(dev->pci->irq, interrupt_hw, SA_SHIRQ | SA_INTERRUPT,
- dev->name, dev))
- {
+ err = request_irq(pci->irq, interrupt_hw, SA_SHIRQ | SA_INTERRUPT,
+ dev->name, dev);
+ if (err < 0) {
ERR(("request_irq() failed.\n"));
- err = -ENODEV;
- goto irq_error;
+ goto err_unmap;
}
+ err = -ENOMEM;
+
/* get memory for various stuff */
- dev->d_rps0.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_RPS_MEM, &dev->d_rps0.dma_handle);
- if( NULL == dev->d_rps0.cpu_addr ) {
- err = -ENOMEM;
- goto kmalloc_error_1;
- }
+ dev->d_rps0.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_rps0.dma_handle);
+ if (!dev->d_rps0.cpu_addr)
+ goto err_free_irq;
memset(dev->d_rps0.cpu_addr, 0x0, SAA7146_RPS_MEM);
- dev->d_rps1.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_RPS_MEM, &dev->d_rps1.dma_handle);
- if( NULL == dev->d_rps1.cpu_addr ) {
- err = -ENOMEM;
- goto kmalloc_error_2;
- }
+ dev->d_rps1.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_rps1.dma_handle);
+ if (!dev->d_rps1.cpu_addr)
+ goto err_free_rps0;
memset(dev->d_rps1.cpu_addr, 0x0, SAA7146_RPS_MEM);
- dev->d_i2c.cpu_addr = pci_alloc_consistent(dev->pci, SAA7146_RPS_MEM, &dev->d_i2c.dma_handle);
- if( NULL == dev->d_i2c.cpu_addr ) {
- err = -ENOMEM;
- goto kmalloc_error_3;
- }
+ dev->d_i2c.cpu_addr = pci_alloc_consistent(pci, SAA7146_RPS_MEM,
+ &dev->d_i2c.dma_handle);
+ if (!dev->d_i2c.cpu_addr)
+ goto err_free_rps1;
memset(dev->d_i2c.cpu_addr, 0x0, SAA7146_RPS_MEM);
/* the rest + print status message */
/* create a nice device name */
- sprintf(&dev->name[0], "saa7146 (%d)",saa7146_num);
+ sprintf(dev->name, "saa7146 (%d)", saa7146_num);
- INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision,dev->pci->irq,dev->pci->subsystem_vendor,dev->pci->subsystem_device));
+ INFO(("found saa7146 @ mem %p (revision %d, irq %d) (0x%04x,0x%04x).\n", dev->mem, dev->revision, pci->irq, pci->subsystem_vendor, pci->subsystem_device));
dev->ext = ext;
- pci_set_drvdata(pci,dev);
+ pci_set_drvdata(pci, dev);
init_MUTEX(&dev->lock);
dev->int_slock = SPIN_LOCK_UNLOCKED;
@@ -437,18 +433,18 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
/* set some sane pci arbitrition values */
saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
- if( 0 != ext->probe) {
- if( 0 != ext->probe(dev) ) {
- DEB_D(("ext->probe() failed for %p. skipping device.\n",dev));
- err = -ENODEV;
- goto probe_error;
- }
+ /* TODO: use the status code of the callback */
+
+ err = -ENODEV;
+
+ if (ext->probe && ext->probe(dev)) {
+ DEB_D(("ext->probe() failed for %p. skipping device.\n",dev));
+ goto err_free_i2c;
}
- if( 0 != ext->attach(dev,pci_ext) ) {
+ if (ext->attach(dev, pci_ext)) {
DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
- err = -ENODEV;
- goto attach_error;
+ goto err_unprobe;
}
INIT_LIST_HEAD(&dev->item);
@@ -456,30 +452,46 @@ static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent
saa7146_num++;
err = 0;
- goto out;
-attach_error:
-probe_error:
- pci_set_drvdata(pci,NULL);
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle);
-kmalloc_error_3:
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle);
-kmalloc_error_2:
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle);
-kmalloc_error_1:
- free_irq(dev->pci->irq, (void *)dev);
-irq_error:
- iounmap(dev->mem);
-ioremap_error:
- release_mem_region(adr,len);
-pci_error:
- kfree(dev);
out:
return err;
+
+err_unprobe:
+ pci_set_drvdata(pci, NULL);
+err_free_i2c:
+ pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr,
+ dev->d_i2c.dma_handle);
+err_free_rps1:
+ pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr,
+ dev->d_rps1.dma_handle);
+err_free_rps0:
+ pci_free_consistent(pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr,
+ dev->d_rps0.dma_handle);
+err_free_irq:
+ free_irq(pci->irq, (void *)dev);
+err_unmap:
+ iounmap(dev->mem);
+err_release:
+ pci_release_region(pci, 0);
+err_disable:
+ pci_disable_device(pci);
+err_free:
+ kfree(dev);
+ goto out;
}
static void saa7146_remove_one(struct pci_dev *pdev)
{
- struct saa7146_dev* dev = (struct saa7146_dev*) pci_get_drvdata(pdev);
+ struct saa7146_dev* dev = pci_get_drvdata(pdev);
+ struct {
+ void *addr;
+ dma_addr_t dma;
+ } dev_map[] = {
+ { dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle },
+ { dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle },
+ { dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle },
+ { NULL, 0 }
+ }, *p;
+
DEB_EE(("dev:%p\n",dev));
dev->ext->detach(dev);
@@ -490,17 +502,15 @@ static void saa7146_remove_one(struct pci_dev *pdev)
/* disable all irqs, release irq-routine */
saa7146_write(dev, IER, 0);
- free_irq(dev->pci->irq, (void *)dev);
+ free_irq(pdev->irq, dev);
- /* free kernel memory */
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_i2c.cpu_addr, dev->d_i2c.dma_handle);
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_rps1.cpu_addr, dev->d_rps1.dma_handle);
- pci_free_consistent(dev->pci, SAA7146_RPS_MEM, dev->d_rps0.cpu_addr, dev->d_rps0.dma_handle);
+ for (p = dev_map; p->addr; p++)
+ pci_free_consistent(pdev, SAA7146_RPS_MEM, p->addr, p->dma);
iounmap(dev->mem);
- release_mem_region(pci_resource_start(dev->pci,0), pci_resource_len(dev->pci,0));
-
+ pci_release_region(pdev, 0);
list_del(&dev->item);
+ pci_disable_device(pdev);
kfree(dev);
saa7146_num--;