drivers/media/common/saa7146/saa7146_core.c
Source file repositories/reference/linux-study-clean/drivers/media/common/saa7146/saa7146_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/common/saa7146/saa7146_core.c- Extension
.c- Size
- 14109 bytes
- Lines
- 567
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
media/drv-intf/saa7146.hlinux/module.h
Detected Declarations
function dump_registersfunction saa7146_setgpiofunction saa7146_wait_for_debi_done_sleepfunction saa7146_wait_for_debi_done_busyloopfunction saa7146_wait_for_debi_donefunction vmalloc_32function saa7146_vfree_destroy_pgtablefunction saa7146_pgtable_freefunction saa7146_pgtable_allocfunction saa7146_pgtable_build_singlefunction interrupt_hwfunction saa7146_init_onefunction saa7146_remove_onefunction saa7146_register_extensionfunction saa7146_unregister_extensionexport saa7146_register_extensionexport saa7146_unregister_extensionexport saa7146_pgtable_allocexport saa7146_pgtable_freeexport saa7146_pgtable_build_singleexport saa7146_vmalloc_build_pgtableexport saa7146_vfree_destroy_pgtableexport saa7146_wait_for_debi_doneexport saa7146_setgpioexport saa7146_i2c_adapter_prepareexport saa7146_debug
Annotated Snippet
if (err) {
pr_debug("%s: %s timed out while waiting for registers getting programmed\n",
dev->name, __func__);
return -ETIMEDOUT;
}
msleep(1);
}
/* wait for transfer to complete */
timeout = jiffies + usecs_to_jiffies(us2);
while (1) {
err = time_after(jiffies, timeout);
if (!(saa7146_read(dev, PSR) & SPCI_DEBI_S))
break;
saa7146_read(dev, MC2);
if (err) {
DEB_S("%s: %s timed out while waiting for transfer completion\n",
dev->name, __func__);
return -ETIMEDOUT;
}
msleep(1);
}
return 0;
}
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--) {
pr_err("%s: %s timed out while waiting for registers getting programmed\n",
dev->name, __func__);
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 completion\n",
dev->name, __func__);
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);
}
/****************************************************************************
* general helper functions
****************************************************************************/
/* this is videobuf_vmalloc_to_sg() from videobuf-dma-sg.c
make sure virt has been allocated with vmalloc_32(), otherwise return NULL
on highmem machines */
static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
{
struct scatterlist *sglist;
struct page *pg;
int i;
sglist = kmalloc_objs(struct scatterlist, nr_pages);
if (NULL == sglist)
return NULL;
sg_init_table(sglist, nr_pages);
for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
pg = vmalloc_to_page(virt);
if (NULL == pg)
goto err;
Annotation
- Immediate include surface: `media/drv-intf/saa7146.h`, `linux/module.h`.
- Detected declarations: `function dump_registers`, `function saa7146_setgpio`, `function saa7146_wait_for_debi_done_sleep`, `function saa7146_wait_for_debi_done_busyloop`, `function saa7146_wait_for_debi_done`, `function vmalloc_32`, `function saa7146_vfree_destroy_pgtable`, `function saa7146_pgtable_free`, `function saa7146_pgtable_alloc`, `function saa7146_pgtable_build_single`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.