2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
saa7146.o - driver for generic saa7146-based hardware
|
|
|
|
|
|
|
|
Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <media/saa7146.h>
|
|
|
|
|
|
|
|
LIST_HEAD(saa7146_devices);
|
2006-02-07 08:49:14 +00:00
|
|
|
DEFINE_MUTEX(saa7146_devices_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-17 04:54:20 +00:00
|
|
|
static int saa7146_num;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-17 04:54:20 +00:00
|
|
|
unsigned int saa7146_debug;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-07-12 23:37:50 +00:00
|
|
|
module_param(saa7146_debug, uint, 0644);
|
2005-04-16 22:20:36 +00:00
|
|
|
MODULE_PARM_DESC(saa7146_debug, "debug level (default: 0)");
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static void dump_registers(struct saa7146_dev* dev)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
INFO((" @ %li jiffies:\n",jiffies));
|
|
|
|
for(i = 0; i <= 0x148; i+=4) {
|
|
|
|
printk("0x%03x: 0x%08x\n",i,saa7146_read(dev,i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* gpio and debi helper functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void saa7146_setgpio(struct saa7146_dev *dev, int port, u32 data)
|
|
|
|
{
|
|
|
|
u32 value = 0;
|
|
|
|
|
|
|
|
BUG_ON(port > 3);
|
|
|
|
|
|
|
|
value = saa7146_read(dev, GPIO_CTRL);
|
|
|
|
value &= ~(0xff << (8*port));
|
|
|
|
value |= (data << (8*port));
|
|
|
|
saa7146_write(dev, GPIO_CTRL, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This DEBI code is based on the saa7146 Stradis driver by Nathan Laredo */
|
2007-10-31 03:39:48 +00:00
|
|
|
static inline int saa7146_wait_for_debi_done_sleep(struct saa7146_dev *dev,
|
|
|
|
unsigned long us1, unsigned long us2)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2007-10-31 03:39:48 +00:00
|
|
|
unsigned long timeout;
|
2005-07-08 00:58:28 +00:00
|
|
|
int err;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* wait for registers to be programmed */
|
2007-10-31 03:39:48 +00:00
|
|
|
timeout = jiffies + usecs_to_jiffies(us1);
|
2005-04-16 22:20:36 +00:00
|
|
|
while (1) {
|
2007-10-31 03:39:48 +00:00
|
|
|
err = time_after(jiffies, timeout);
|
2005-07-08 00:58:28 +00:00
|
|
|
if (saa7146_read(dev, MC2) & 2)
|
|
|
|
break;
|
|
|
|
if (err) {
|
2007-10-31 03:39:48 +00:00
|
|
|
printk(KERN_ERR "%s: %s timed out while waiting for "
|
|
|
|
"registers getting programmed\n",
|
2008-04-09 02:20:00 +00:00
|
|
|
dev->name, __func__);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
2007-10-31 03:39:48 +00:00
|
|
|
msleep(1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for transfer to complete */
|
2007-10-31 03:39:48 +00:00
|
|
|
timeout = jiffies + usecs_to_jiffies(us2);
|
2005-04-16 22:20:36 +00:00
|
|
|
while (1) {
|
2007-10-31 03:39:48 +00:00
|
|
|
err = time_after(jiffies, timeout);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S))
|
|
|
|
break;
|
|
|
|
saa7146_read(dev, MC2);
|
2005-07-08 00:58:28 +00:00
|
|
|
if (err) {
|
2007-10-31 03:39:48 +00:00
|
|
|
DEB_S(("%s: %s timed out while waiting for transfer "
|
2008-04-09 02:20:00 +00:00
|
|
|
"completion\n", dev->name, __func__));
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
2007-10-31 03:39:48 +00:00
|
|
|
msleep(1);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-31 03:39:48 +00:00
|
|
|
static inline int saa7146_wait_for_debi_done_busyloop(struct saa7146_dev *dev,
|
|
|
|
unsigned long us1, unsigned long us2)
|
|
|
|
{
|
|
|
|
unsigned long loops;
|
|
|
|
|
|
|
|
/* wait for registers to be programmed */
|
|
|
|
loops = us1;
|
|
|
|
while (1) {
|
|
|
|
if (saa7146_read(dev, MC2) & 2)
|
|
|
|
break;
|
|
|
|
if (!loops--) {
|
|
|
|
printk(KERN_ERR "%s: %s timed out while waiting for "
|
|
|
|
"registers getting programmed\n",
|
2008-04-09 02:20:00 +00:00
|
|
|
dev->name, __func__);
|
2007-10-31 03:39:48 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for transfer to complete */
|
|
|
|
loops = us2 / 5;
|
|
|
|
while (1) {
|
|
|
|
if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S))
|
|
|
|
break;
|
|
|
|
saa7146_read(dev, MC2);
|
|
|
|
if (!loops--) {
|
|
|
|
DEB_S(("%s: %s timed out while waiting for transfer "
|
2008-04-09 02:20:00 +00:00
|
|
|
"completion\n", dev->name, __func__));
|
2007-10-31 03:39:48 +00:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
udelay(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop)
|
|
|
|
{
|
|
|
|
if (nobusyloop)
|
|
|
|
return saa7146_wait_for_debi_done_sleep(dev, 50000, 250000);
|
|
|
|
else
|
|
|
|
return saa7146_wait_for_debi_done_busyloop(dev, 50000, 250000);
|
|
|
|
}
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/****************************************************************************
|
|
|
|
* general helper functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-08-23 19:37:49 +00:00
|
|
|
/* this is videobuf_vmalloc_to_sg() from videobuf-dma-sg.c
|
2005-04-16 22:20:36 +00:00
|
|
|
make sure virt has been allocated with vmalloc_32(), otherwise the BUG()
|
|
|
|
may be triggered on highmem machines */
|
|
|
|
static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
|
|
|
|
{
|
|
|
|
struct scatterlist *sglist;
|
|
|
|
struct page *pg;
|
|
|
|
int i;
|
|
|
|
|
2006-01-11 21:40:56 +00:00
|
|
|
sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (NULL == sglist)
|
|
|
|
return NULL;
|
2007-10-22 19:19:53 +00:00
|
|
|
sg_init_table(sglist, nr_pages);
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
|
|
|
|
pg = vmalloc_to_page(virt);
|
|
|
|
if (NULL == pg)
|
|
|
|
goto err;
|
2006-03-13 16:17:11 +00:00
|
|
|
BUG_ON(PageHighMem(pg));
|
2007-10-24 09:20:47 +00:00
|
|
|
sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return sglist;
|
|
|
|
|
|
|
|
err:
|
|
|
|
kfree(sglist);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/* common page table functions */
|
|
|
|
|
2007-07-12 23:37:50 +00:00
|
|
|
void *saa7146_vmalloc_build_pgtable(struct pci_dev *pci, long length, struct saa7146_pgtable *pt)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int pages = (length+PAGE_SIZE-1)/PAGE_SIZE;
|
2007-07-12 23:37:50 +00:00
|
|
|
void *mem = vmalloc_32(length);
|
2005-04-16 22:20:36 +00:00
|
|
|
int slen = 0;
|
|
|
|
|
2007-05-03 15:23:44 +00:00
|
|
|
if (NULL == mem)
|
|
|
|
goto err_null;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-03 15:23:44 +00:00
|
|
|
if (!(pt->slist = vmalloc_to_sg(mem, pages)))
|
|
|
|
goto err_free_mem;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-03 15:23:44 +00:00
|
|
|
if (saa7146_pgtable_alloc(pci, pt))
|
|
|
|
goto err_free_slist;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-05-03 15:23:44 +00:00
|
|
|
pt->nents = pages;
|
|
|
|
slen = pci_map_sg(pci,pt->slist,pt->nents,PCI_DMA_FROMDEVICE);
|
|
|
|
if (0 == slen)
|
|
|
|
goto err_free_pgtable;
|
|
|
|
|
|
|
|
if (0 != saa7146_pgtable_build_single(pci, pt, pt->slist, slen))
|
|
|
|
goto err_unmap_sg;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return mem;
|
2007-05-03 15:23:44 +00:00
|
|
|
|
|
|
|
err_unmap_sg:
|
|
|
|
pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
|
|
|
|
err_free_pgtable:
|
|
|
|
saa7146_pgtable_free(pci, pt);
|
|
|
|
err_free_slist:
|
|
|
|
kfree(pt->slist);
|
|
|
|
pt->slist = NULL;
|
|
|
|
err_free_mem:
|
|
|
|
vfree(mem);
|
|
|
|
err_null:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-12 23:37:50 +00:00
|
|
|
void saa7146_vfree_destroy_pgtable(struct pci_dev *pci, void *mem, struct saa7146_pgtable *pt)
|
2007-05-03 15:23:44 +00:00
|
|
|
{
|
|
|
|
pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
|
|
|
|
saa7146_pgtable_free(pci, pt);
|
|
|
|
kfree(pt->slist);
|
|
|
|
pt->slist = NULL;
|
|
|
|
vfree(mem);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
|
|
|
|
{
|
|
|
|
if (NULL == pt->cpu)
|
|
|
|
return;
|
|
|
|
pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
|
|
|
|
pt->cpu = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
|
|
|
|
{
|
2008-06-22 17:19:19 +00:00
|
|
|
__le32 *cpu;
|
2008-08-22 20:01:45 +00:00
|
|
|
dma_addr_t dma_addr = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr);
|
|
|
|
if (NULL == cpu) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
pt->size = PAGE_SIZE;
|
|
|
|
pt->cpu = cpu;
|
|
|
|
pt->dma = dma_addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt,
|
|
|
|
struct scatterlist *list, int sglen )
|
|
|
|
{
|
2008-06-22 17:19:19 +00:00
|
|
|
__le32 *ptr, fill;
|
2005-04-16 22:20:36 +00:00
|
|
|
int nr_pages = 0;
|
|
|
|
int i,p;
|
|
|
|
|
|
|
|
BUG_ON(0 == sglen);
|
|
|
|
BUG_ON(list->offset > PAGE_SIZE);
|
|
|
|
|
|
|
|
/* if we have a user buffer, the first page may not be
|
|
|
|
aligned to a page boundary. */
|
|
|
|
pt->offset = list->offset;
|
|
|
|
|
|
|
|
ptr = pt->cpu;
|
|
|
|
for (i = 0; i < sglen; i++, list++) {
|
|
|
|
/*
|
|
|
|
printk("i:%d, adr:0x%08x, len:%d, offset:%d\n", i,sg_dma_address(list), sg_dma_len(list), list->offset);
|
|
|
|
*/
|
|
|
|
for (p = 0; p * 4096 < list->length; p++, ptr++) {
|
|
|
|
*ptr = cpu_to_le32(sg_dma_address(list) + p * 4096);
|
|
|
|
nr_pages++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* safety; fill the page table up with the last valid page */
|
|
|
|
fill = *(ptr-1);
|
|
|
|
for(i=nr_pages;i<1024;i++) {
|
|
|
|
*ptr++ = fill;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ptr = pt->cpu;
|
|
|
|
printk("offset: %d\n",pt->offset);
|
|
|
|
for(i=0;i<5;i++) {
|
|
|
|
printk("ptr1 %d: 0x%08x\n",i,ptr[i]);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/* interrupt handler */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t interrupt_hw(int irq, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct saa7146_dev *dev = dev_id;
|
2007-08-09 05:41:16 +00:00
|
|
|
u32 isr;
|
|
|
|
u32 ack_isr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* read out the interrupt status register */
|
2007-08-09 05:41:16 +00:00
|
|
|
ack_isr = isr = saa7146_read(dev, ISR);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* is this our interrupt? */
|
|
|
|
if ( 0 == isr ) {
|
|
|
|
/* nope, some other device */
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2008-03-29 03:07:38 +00:00
|
|
|
if (dev->ext) {
|
|
|
|
if (dev->ext->irq_mask & isr) {
|
|
|
|
if (dev->ext->irq_func)
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->ext->irq_func(dev, &isr);
|
|
|
|
isr &= ~dev->ext->irq_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (0 != (isr & (MASK_27))) {
|
|
|
|
DEB_INT(("irq: RPS0 (0x%08x).\n",isr));
|
2008-03-29 03:07:38 +00:00
|
|
|
if (dev->vv_data && dev->vv_callback)
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->vv_callback(dev,isr);
|
|
|
|
isr &= ~MASK_27;
|
|
|
|
}
|
|
|
|
if (0 != (isr & (MASK_28))) {
|
2008-03-29 03:07:38 +00:00
|
|
|
if (dev->vv_data && dev->vv_callback)
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->vv_callback(dev,isr);
|
|
|
|
isr &= ~MASK_28;
|
|
|
|
}
|
|
|
|
if (0 != (isr & (MASK_16|MASK_17))) {
|
2007-08-09 05:41:16 +00:00
|
|
|
SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
|
|
|
|
/* only wake up if we expect something */
|
|
|
|
if (0 != dev->i2c_op) {
|
|
|
|
dev->i2c_op = 0;
|
|
|
|
wake_up(&dev->i2c_wq);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2007-08-09 05:41:16 +00:00
|
|
|
u32 psr = saa7146_read(dev, PSR);
|
|
|
|
u32 ssr = saa7146_read(dev, SSR);
|
|
|
|
printk(KERN_WARNING "%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
|
|
|
|
dev->name, isr, psr, ssr);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
isr &= ~(MASK_16|MASK_17);
|
|
|
|
}
|
|
|
|
if( 0 != isr ) {
|
|
|
|
ERR(("warning: interrupt enabled, but not handled properly.(0x%08x)\n",isr));
|
|
|
|
ERR(("disabling interrupt source(s)!\n"));
|
|
|
|
SAA7146_IER_DISABLE(dev,isr);
|
|
|
|
}
|
2007-08-09 05:41:16 +00:00
|
|
|
saa7146_write(dev, ISR, ack_isr);
|
2005-04-16 22:20:36 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************/
|
|
|
|
/* configuration-functions */
|
|
|
|
|
|
|
|
static int saa7146_init_one(struct pci_dev *pci, const struct pci_device_id *ent)
|
|
|
|
{
|
|
|
|
struct saa7146_pci_extension_data *pci_ext = (struct saa7146_pci_extension_data *)ent->driver_data;
|
|
|
|
struct saa7146_extension *ext = pci_ext->ext;
|
|
|
|
struct saa7146_dev *dev;
|
|
|
|
int err = -ENOMEM;
|
|
|
|
|
2006-01-11 21:40:56 +00:00
|
|
|
/* clear out mem for sure */
|
|
|
|
dev = kzalloc(sizeof(struct saa7146_dev), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!dev) {
|
|
|
|
ERR(("out of memory.\n"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEB_EE(("pci:%p\n",pci));
|
|
|
|
|
|
|
|
err = pci_enable_device(pci);
|
|
|
|
if (err < 0) {
|
|
|
|
ERR(("pci_enable_device() failed.\n"));
|
2009-02-07 23:42:33 +00:00
|
|
|
goto err_free;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* enable bus-mastering */
|
|
|
|
pci_set_master(pci);
|
|
|
|
|
|
|
|
dev->pci = pci;
|
|
|
|
|
|
|
|
/* get chip-revision; this is needed to enable bug-fixes */
|
2011-03-21 14:35:56 +00:00
|
|
|
dev->revision = pci->revision;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-03 15:18:59 +00:00
|
|
|
/* remap the memory from virtual to physical address */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = pci_request_region(pci, 0, "saa7146");
|
|
|
|
if (err < 0)
|
|
|
|
goto err_disable;
|
|
|
|
|
|
|
|
dev->mem = ioremap(pci_resource_start(pci, 0),
|
|
|
|
pci_resource_len(pci, 0));
|
|
|
|
if (!dev->mem) {
|
|
|
|
ERR(("ioremap() failed.\n"));
|
|
|
|
err = -ENODEV;
|
|
|
|
goto err_release;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we don't do a master reset here anymore, it screws up
|
|
|
|
some boards that don't have an i2c-eeprom for configuration
|
|
|
|
values */
|
|
|
|
/*
|
|
|
|
saa7146_write(dev, MC1, MASK_31);
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* disable all irqs */
|
|
|
|
saa7146_write(dev, IER, 0);
|
|
|
|
|
|
|
|
/* shut down all dma transfers and rps tasks */
|
|
|
|
saa7146_write(dev, MC1, 0x30ff0000);
|
|
|
|
|
|
|
|
/* clear out any rps-signals pending */
|
|
|
|
saa7146_write(dev, MC2, 0xf8000000);
|
|
|
|
|
|
|
|
/* request an interrupt for the saa7146 */
|
2006-07-02 02:29:37 +00:00
|
|
|
err = request_irq(pci->irq, interrupt_hw, IRQF_SHARED | IRQF_DISABLED,
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->name, dev);
|
|
|
|
if (err < 0) {
|
|
|
|
ERR(("request_irq() failed.\n"));
|
|
|
|
goto err_unmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
|
|
|
/* get memory for various stuff */
|
|
|
|
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(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(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, "saa7146 (%d)", saa7146_num);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-12-18 12:20:59 +00:00
|
|
|
mutex_init(&dev->v4l2_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
spin_lock_init(&dev->int_slock);
|
|
|
|
spin_lock_init(&dev->slock);
|
|
|
|
|
2006-02-07 08:49:14 +00:00
|
|
|
mutex_init(&dev->i2c_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dev->module = THIS_MODULE;
|
|
|
|
init_waitqueue_head(&dev->i2c_wq);
|
|
|
|
|
|
|
|
/* set some sane pci arbitrition values */
|
|
|
|
saa7146_write(dev, PCI_BT_V1, 0x1c00101f);
|
|
|
|
|
|
|
|
/* 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 (ext->attach(dev, pci_ext)) {
|
|
|
|
DEB_D(("ext->attach() failed for %p. skipping device.\n",dev));
|
2009-02-07 10:23:40 +00:00
|
|
|
goto err_free_i2c;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2009-02-07 23:42:33 +00:00
|
|
|
/* V4L extensions will set the pci drvdata to the v4l2_device in the
|
|
|
|
attach() above. So for those cards that do not use V4L we have to
|
|
|
|
set it explicitly. */
|
|
|
|
pci_set_drvdata(pci, &dev->v4l2_dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dev->item);
|
|
|
|
list_add_tail(&dev->item,&saa7146_devices);
|
|
|
|
saa7146_num++;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-02-07 10:23:40 +00:00
|
|
|
struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
|
2009-02-07 10:38:12 +00:00
|
|
|
struct saa7146_dev *dev = to_saa7146_dev(v4l2_dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
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);
|
2009-02-07 23:42:33 +00:00
|
|
|
/* Zero the PCI drvdata after use. */
|
|
|
|
pci_set_drvdata(pdev, NULL);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* shut down all video dma transfers */
|
|
|
|
saa7146_write(dev, MC1, 0x00ff0000);
|
|
|
|
|
|
|
|
/* disable all irqs, release irq-routine */
|
|
|
|
saa7146_write(dev, IER, 0);
|
|
|
|
|
|
|
|
free_irq(pdev->irq, dev);
|
|
|
|
|
|
|
|
for (p = dev_map; p->addr; p++)
|
|
|
|
pci_free_consistent(pdev, SAA7146_RPS_MEM, p->addr, p->dma);
|
|
|
|
|
|
|
|
iounmap(dev->mem);
|
|
|
|
pci_release_region(pdev, 0);
|
|
|
|
list_del(&dev->item);
|
|
|
|
pci_disable_device(pdev);
|
|
|
|
kfree(dev);
|
|
|
|
|
|
|
|
saa7146_num--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************************/
|
|
|
|
/* extension handling functions */
|
|
|
|
|
|
|
|
int saa7146_register_extension(struct saa7146_extension* ext)
|
|
|
|
{
|
|
|
|
DEB_EE(("ext:%p\n",ext));
|
|
|
|
|
|
|
|
ext->driver.name = ext->name;
|
|
|
|
ext->driver.id_table = ext->pci_tbl;
|
|
|
|
ext->driver.probe = saa7146_init_one;
|
|
|
|
ext->driver.remove = saa7146_remove_one;
|
|
|
|
|
|
|
|
printk("saa7146: register extension '%s'.\n",ext->name);
|
2005-07-08 00:57:47 +00:00
|
|
|
return pci_register_driver(&ext->driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int saa7146_unregister_extension(struct saa7146_extension* ext)
|
|
|
|
{
|
|
|
|
DEB_EE(("ext:%p\n",ext));
|
|
|
|
printk("saa7146: unregister extension '%s'.\n",ext->name);
|
|
|
|
pci_unregister_driver(&ext->driver);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_register_extension);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_unregister_extension);
|
|
|
|
|
|
|
|
/* misc functions used by extension modules */
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_pgtable_alloc);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_pgtable_free);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_pgtable_build_single);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_vmalloc_build_pgtable);
|
2007-05-03 15:23:44 +00:00
|
|
|
EXPORT_SYMBOL_GPL(saa7146_vfree_destroy_pgtable);
|
2005-04-16 22:20:36 +00:00
|
|
|
EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done);
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_setgpio);
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare);
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_debug);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_devices);
|
|
|
|
EXPORT_SYMBOL_GPL(saa7146_devices_lock);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
|
|
|
|
MODULE_DESCRIPTION("driver for generic saa7146-based hardware");
|
|
|
|
MODULE_LICENSE("GPL");
|