drivers/media/pci/zoran/zr36016.c

Source file repositories/reference/linux-study-clean/drivers/media/pci/zoran/zr36016.c

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/zoran/zr36016.c
Extension
.c
Size
10792 bytes
Lines
407
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source 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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Zoran ZR36016 basic configuration functions
 *
 * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>

/* headerfile of this module */
#include "zr36016.h"

/* codec io API */
#include "videocodec.h"

/*
 * it doesn't make sense to have more than 20 or so,
 * just to prevent some unwanted loops
 */
#define MAX_CODECS 20

/* amount of chips attached via this driver */
static int zr36016_codecs;

/*
 * Local hardware I/O functions: read/write via codec layer
 * (registers are located in the master device)
 */

/* read and write functions */
static u8 zr36016_read(struct zr36016 *ptr, u16 reg)
{
	u8 value = 0;
	struct zoran *zr = videocodec_to_zoran(ptr->codec);

	/* just in case something is wrong... */
	if (ptr->codec->master_data->readreg)
		value = (ptr->codec->master_data->readreg(ptr->codec, reg)) & 0xFF;
	else
		zrdev_err(zr, "%s: invalid I/O setup, nothing read!\n", ptr->name);

	zrdev_dbg(zr, "%s: reading from 0x%04x: %02x\n", ptr->name, reg, value);

	return value;
}

static void zr36016_write(struct zr36016 *ptr, u16 reg, u8 value)
{
	struct zoran *zr = videocodec_to_zoran(ptr->codec);

	zrdev_dbg(zr, "%s: writing 0x%02x to 0x%04x\n", ptr->name, value, reg);

	// just in case something is wrong...
	if (ptr->codec->master_data->writereg)
		ptr->codec->master_data->writereg(ptr->codec, reg, value);
	else
		zrdev_err(zr, "%s: invalid I/O setup, nothing written!\n", ptr->name);
}

/*
 * indirect read and write functions
 *
 * the 016 supports auto-addr-increment, but
 * writing it all time cost not much and is safer...
 */
static u8 zr36016_readi(struct zr36016 *ptr, u16 reg)
{
	u8 value = 0;
	struct zoran *zr = videocodec_to_zoran(ptr->codec);

	/* just in case something is wrong... */
	if ((ptr->codec->master_data->writereg) && (ptr->codec->master_data->readreg)) {
		ptr->codec->master_data->writereg(ptr->codec, ZR016_IADDR, reg & 0x0F);
		value = (ptr->codec->master_data->readreg(ptr->codec, ZR016_IDATA)) & 0xFF;
	} else {
		zrdev_err(zr, "%s: invalid I/O setup, nothing read (i)!\n", ptr->name);
	}

	zrdev_dbg(zr, "%s: reading indirect from 0x%04x: %02x\n",
		  ptr->name, reg, value);
	return value;
}

static void zr36016_writei(struct zr36016 *ptr, u16 reg, u8 value)
{
	struct zoran *zr = videocodec_to_zoran(ptr->codec);

	zrdev_dbg(zr, "%s: writing indirect 0x%02x to 0x%04x\n", ptr->name,

Annotation

Implementation Notes