linux/drivers/media/pci/saa7164/saa7164.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 *  Driver for the NXP SAA7164 PCIe bridge
 *
 *  Copyright (c) 2010-2015 Steven Toth <[email protected]>
 */

/*
	Driver architecture
	*******************

	saa7164_core.c/buffer.c/cards.c/i2c.c/dvb.c
		|	: Standard Linux driver framework for creating
		|	: exposing and managing interfaces to the rest
		|	: of the kernel or userland. Also uses _fw.c to load
		|	: firmware direct into the PCIe bus, bypassing layers.
		V
	saa7164_api..()	: Translate kernel specific functions/features
		|	: into command buffers.
		V
	saa7164_cmd..()	: Manages the flow of command packets on/off,
		|	: the bus. Deal with bus errors, timeouts etc.
		V
	saa7164_bus..() : Manage a read/write memory ring buffer in the
		|	: PCIe Address space.
		|
		|		saa7164_fw...()	: Load any firmware
		|			|	: direct into the device
		V			V
	<- ----------------- PCIe address space -------------------- ->
*/

#include <linux/pci.h>
#include <linux/i2c.h>
#include <linux/kdev_t.h>
#include <linux/mutex.h>
#include <linux/crc32.h>
#include <linux/kthread.h>
#include <linux/freezer.h>

#include <media/tuner.h>
#include <media/tveeprom.h>
#include <media/dvb_demux.h>
#include <media/dvb_frontend.h>
#include <media/dvb_net.h>
#include <media/dvbdev.h>
#include <media/dmxdev.h>
#include <media/v4l2-common.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>

#include "saa7164-reg.h"
#include "saa7164-types.h"

#define SAA7164_MAXBOARDS

#define UNSET
#define SAA7164_BOARD_NOAUTO
#define SAA7164_BOARD_UNKNOWN
#define SAA7164_BOARD_UNKNOWN_REV2
#define SAA7164_BOARD_UNKNOWN_REV3
#define SAA7164_BOARD_HAUPPAUGE_HVR2250
#define SAA7164_BOARD_HAUPPAUGE_HVR2200
#define SAA7164_BOARD_HAUPPAUGE_HVR2200_2
#define SAA7164_BOARD_HAUPPAUGE_HVR2200_3
#define SAA7164_BOARD_HAUPPAUGE_HVR2250_2
#define SAA7164_BOARD_HAUPPAUGE_HVR2250_3
#define SAA7164_BOARD_HAUPPAUGE_HVR2200_4
#define SAA7164_BOARD_HAUPPAUGE_HVR2200_5
#define SAA7164_BOARD_HAUPPAUGE_HVR2255proto
#define SAA7164_BOARD_HAUPPAUGE_HVR2255
#define SAA7164_BOARD_HAUPPAUGE_HVR2205

#define SAA7164_MAX_UNITS
#define SAA7164_TS_NUMBER_OF_LINES
#define SAA7164_PS_NUMBER_OF_LINES
#define SAA7164_PT_ENTRIES
#define SAA7164_MAX_ENCODER_BUFFERS
#define SAA7164_MAX_VBI_BUFFERS

/* Port related defines */
#define SAA7164_PORT_TS1
#define SAA7164_PORT_TS2
#define SAA7164_PORT_ENC1
#define SAA7164_PORT_ENC2
#define SAA7164_PORT_VBI1
#define SAA7164_PORT_VBI2
#define SAA7164_MAX_PORTS

#define DBGLVL_FW
#define DBGLVL_DVB
#define DBGLVL_I2C
#define DBGLVL_API
#define DBGLVL_CMD
#define DBGLVL_BUS
#define DBGLVL_IRQ
#define DBGLVL_BUF
#define DBGLVL_ENC
#define DBGLVL_VBI
#define DBGLVL_THR
#define DBGLVL_CPU

#define SAA7164_NORMS

/* TV frequency range copied from tuner-core.c */
#define SAA7164_TV_MIN_FREQ
#define SAA7164_TV_MAX_FREQ

enum port_t {};

enum saa7164_i2c_bus_nr {};

enum saa7164_buffer_flags {};

enum saa7164_unit_type {};

/* The PCIe bridge doesn't grant direct access to i2c.
 * Instead, you address i2c devices using a uniqely
 * allocated 'unitid' value via a messaging API. This
 * is a problem. The kernel and existing demod/tuner
 * drivers expect to talk 'i2c', so we have to maintain
 * a translation layer, and a series of functions to
 * convert i2c bus + device address into a unit id.
 */
struct saa7164_unit {};

struct saa7164_board {};

struct saa7164_subid {};

struct saa7164_encoder_fh {};

struct saa7164_vbi_fh {};

struct saa7164_histogram_bucket {};

struct saa7164_histogram {};

struct saa7164_user_buffer {};

struct saa7164_fw_status {};

struct saa7164_dvb {};

struct saa7164_i2c {};

struct saa7164_tvnorm {};

struct saa7164_encoder_params {};

struct saa7164_vbi_params {};

struct saa7164_port;

struct saa7164_buffer {};

struct saa7164_port {};

struct saa7164_dev {};

extern struct list_head saa7164_devlist;
extern unsigned int waitsecs;
extern unsigned int encoder_buffers;
extern unsigned int vbi_buffers;

/* ----------------------------------------------------------- */
/* saa7164-core.c                                              */
void saa7164_dumpregs(struct saa7164_dev *dev, u32 addr);
void saa7164_getfirmwarestatus(struct saa7164_dev *dev);
u32 saa7164_getcurrentfirmwareversion(struct saa7164_dev *dev);
void saa7164_histogram_update(struct saa7164_histogram *hg, u32 val);

/* ----------------------------------------------------------- */
/* saa7164-fw.c                                                */
int saa7164_downloadfirmware(struct saa7164_dev *dev);

/* ----------------------------------------------------------- */
/* saa7164-i2c.c                                               */
extern int saa7164_i2c_register(struct saa7164_i2c *bus);
extern int saa7164_i2c_unregister(struct saa7164_i2c *bus);

/* ----------------------------------------------------------- */
/* saa7164-bus.c                                               */
int saa7164_bus_setup(struct saa7164_dev *dev);
void saa7164_bus_dump(struct saa7164_dev *dev);
int saa7164_bus_set(struct saa7164_dev *dev, struct tmComResInfo* msg,
	void *buf);
int saa7164_bus_get(struct saa7164_dev *dev, struct tmComResInfo* msg,
	void *buf, int peekonly);

/* ----------------------------------------------------------- */
/* saa7164-cmd.c                                               */
int saa7164_cmd_send(struct saa7164_dev *dev,
	u8 id, enum tmComResCmd command, u16 controlselector,
	u16 size, void *buf);
void saa7164_cmd_signal(struct saa7164_dev *dev, u8 seqno);
int saa7164_irq_dequeue(struct saa7164_dev *dev);

/* ----------------------------------------------------------- */
/* saa7164-api.c                                               */
int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version);
int saa7164_api_enum_subdevs(struct saa7164_dev *dev);
int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
	u32 datalen, u8 *data);
int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr,
	u32 datalen, u8 *data);
int saa7164_api_dif_write(struct saa7164_i2c *bus, u8 addr,
	u32 datalen, u8 *data);
int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen);
int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid, u8 pin);
int saa7164_api_transition_port(struct saa7164_port *port, u8 mode);
int saa7164_api_initialize_dif(struct saa7164_port *port);
int saa7164_api_configure_dif(struct saa7164_port *port, u32 std);
int saa7164_api_set_encoder(struct saa7164_port *port);
int saa7164_api_get_encoder(struct saa7164_port *port);
int saa7164_api_set_aspect_ratio(struct saa7164_port *port);
int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl);
int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl);
int saa7164_api_set_videomux(struct saa7164_port *port);
int saa7164_api_audio_mute(struct saa7164_port *port, int mute);
int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level);
int saa7164_api_set_audio_std(struct saa7164_port *port);
int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect);
int saa7164_api_get_videomux(struct saa7164_port *port);
int saa7164_api_set_vbi_format(struct saa7164_port *port);
int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level);
int saa7164_api_collect_debug(struct saa7164_dev *dev);
int saa7164_api_get_load_info(struct saa7164_dev *dev,
	struct tmFwInfoStruct *i);

/* ----------------------------------------------------------- */
/* saa7164-cards.c                                             */
extern struct saa7164_board saa7164_boards[];
extern const unsigned int saa7164_bcount;

extern struct saa7164_subid saa7164_subids[];
extern const unsigned int saa7164_idcount;

extern void saa7164_card_list(struct saa7164_dev *dev);
extern void saa7164_gpio_setup(struct saa7164_dev *dev);
extern void saa7164_card_setup(struct saa7164_dev *dev);

extern int saa7164_i2caddr_to_reglen(struct saa7164_i2c *bus, int addr);
extern int saa7164_i2caddr_to_unitid(struct saa7164_i2c *bus, int addr);
extern char *saa7164_unitid_name(struct saa7164_dev *dev, u8 unitid);

/* ----------------------------------------------------------- */
/* saa7164-dvb.c                                               */
extern int saa7164_dvb_register(struct saa7164_port *port);
extern int saa7164_dvb_unregister(struct saa7164_port *port);

/* ----------------------------------------------------------- */
/* saa7164-buffer.c                                            */
extern struct saa7164_buffer *saa7164_buffer_alloc(
	struct saa7164_port *port, u32 len);
extern int saa7164_buffer_dealloc(struct saa7164_buffer *buf);
extern void saa7164_buffer_display(struct saa7164_buffer *buf);
extern int saa7164_buffer_activate(struct saa7164_buffer *buf, int i);
extern int saa7164_buffer_cfg_port(struct saa7164_port *port);
extern struct saa7164_user_buffer *saa7164_buffer_alloc_user(
	struct saa7164_dev *dev, u32 len);
extern void saa7164_buffer_dealloc_user(struct saa7164_user_buffer *buf);
extern int saa7164_buffer_zero_offsets(struct saa7164_port *port, int i);

/* ----------------------------------------------------------- */
/* saa7164-encoder.c                                            */
int saa7164_s_std(struct saa7164_port *port, v4l2_std_id id);
int saa7164_g_std(struct saa7164_port *port, v4l2_std_id *id);
int saa7164_enum_input(struct file *file, void *priv, struct v4l2_input *i);
int saa7164_g_input(struct saa7164_port *port, unsigned int *i);
int saa7164_s_input(struct saa7164_port *port, unsigned int i);
int saa7164_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
int saa7164_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
int saa7164_g_frequency(struct saa7164_port *port, struct v4l2_frequency *f);
int saa7164_s_frequency(struct saa7164_port *port,
			const struct v4l2_frequency *f);
int saa7164_encoder_register(struct saa7164_port *port);
void saa7164_encoder_unregister(struct saa7164_port *port);

/* ----------------------------------------------------------- */
/* saa7164-vbi.c                                            */
int saa7164_vbi_register(struct saa7164_port *port);
void saa7164_vbi_unregister(struct saa7164_port *port);

/* ----------------------------------------------------------- */

extern unsigned int crc_checking;

extern unsigned int saa_debug;
#define dprintk(level, fmt, arg...)

#define log_warn(fmt, arg...)

#define saa7164_readl(reg)
#define saa7164_writel(reg, value)

#define saa7164_readb(reg)
#define saa7164_writeb(reg, value)