linux/drivers/media/usb/cx231xx/cx231xx.h

/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
   cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices

   Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
	Based on em28xx driver

 */

#ifndef _CX231XX_H
#define _CX231XX_H

#include <linux/videodev2.h>
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/usb.h>

#include <media/drv-intf/cx2341x.h>

#include <media/videobuf2-vmalloc.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/rc-core.h>
#include <media/i2c/ir-kbd-i2c.h>

#include "cx231xx-reg.h"
#include "cx231xx-pcb-cfg.h"
#include "cx231xx-conf-reg.h"

#define DRIVER_NAME
#define PWR_SLEEP_INTERVAL

/* I2C addresses for control block in Cx231xx */
#define AFE_DEVICE_ADDRESS
#define I2S_BLK_DEVICE_ADDRESS
#define VID_BLK_I2C_ADDRESS
#define VERVE_I2C_ADDRESS
#define DIF_USE_BASEBAND

/* Boards supported by driver */
#define CX231XX_BOARD_UNKNOWN
#define CX231XX_BOARD_CNXT_CARRAERA
#define CX231XX_BOARD_CNXT_SHELBY
#define CX231XX_BOARD_CNXT_RDE_253S
#define CX231XX_BOARD_CNXT_RDU_253S
#define CX231XX_BOARD_CNXT_VIDEO_GRABBER
#define CX231XX_BOARD_CNXT_RDE_250
#define CX231XX_BOARD_CNXT_RDU_250
#define CX231XX_BOARD_HAUPPAUGE_EXETER
#define CX231XX_BOARD_HAUPPAUGE_USBLIVE2
#define CX231XX_BOARD_PV_PLAYTV_USB_HYBRID
#define CX231XX_BOARD_PV_XCAPTURE_USB
#define CX231XX_BOARD_KWORLD_UB430_USB_HYBRID
#define CX231XX_BOARD_ICONBIT_U100
#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL
#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC
#define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2
#define CX231XX_BOARD_OTG102
#define CX231XX_BOARD_KWORLD_UB445_USB_HYBRID
#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1113xx
#define CX231XX_BOARD_HAUPPAUGE_930C_HD_1114xx
#define CX231XX_BOARD_HAUPPAUGE_955Q
#define CX231XX_BOARD_TERRATEC_GRABBY
#define CX231XX_BOARD_EVROMEDIA_FULL_HYBRID_FULLHD
#define CX231XX_BOARD_ASTROMETA_T2HYBRID
#define CX231XX_BOARD_THE_IMAGING_SOURCE_DFG_USB2_PRO
#define CX231XX_BOARD_HAUPPAUGE_935C
#define CX231XX_BOARD_HAUPPAUGE_975

/* Limits minimum and default number of buffers */
#define CX231XX_MIN_BUF
#define CX231XX_DEF_BUF
#define CX231XX_DEF_VBI_BUF

#define VBI_LINE_COUNT
#define VBI_LINE_LENGTH

/*Limits the max URB message size */
#define URB_MAX_CTRL_SIZE

/* Params for validated field */
#define CX231XX_BOARD_NOT_VALIDATED
#define CX231XX_BOARD_VALIDATED

/* maximum number of cx231xx boards */
#define CX231XX_MAXBOARDS

/* maximum number of frames that can be queued */
#define CX231XX_NUM_FRAMES

/* number of buffers for isoc transfers */
#define CX231XX_NUM_BUFS

/* number of packets for each buffer
   windows requests only 40 packets .. so we better do the same
   this is what I found out for all alternate numbers there!
 */
#define CX231XX_NUM_PACKETS

/* default alternate; 0 means choose the best */
#define CX231XX_PINOUT

#define CX231XX_INTERLACED_DEFAULT

/* time to wait when stopping the isoc transfer */
#define CX231XX_URB_TIMEOUT

#define CX231xx_NORMS

#define SLEEP_S5H1432
#define CX23417_OSC_EN
#define CX23417_RESET

#define EP5_BUF_SIZE
#define EP5_TIMEOUT_MS

struct cx23417_fmt {};
enum cx231xx_mode {};

enum cx231xx_std_mode {};

enum cx231xx_stream_state {};

struct cx231xx;

struct cx231xx_isoc_ctl {};

struct cx231xx_bulk_ctl {};

struct cx231xx_fmt {};

/* buffer for one video frame */
struct cx231xx_buffer {};

enum ps_package_head {};

struct cx231xx_dmaqueue {};

/* inputs */

#define MAX_CX231XX_INPUT

enum cx231xx_itype {};

enum cx231xx_v_input {};

/* cx231xx has two audio inputs: tuner and line in */
enum cx231xx_amux {};

struct cx231xx_reg_seq {};

struct cx231xx_input {};

#define INPUT(nr)

enum cx231xx_decoder {};

enum CX231XX_I2C_MASTER_PORT {};

struct cx231xx_board {};

/* device states */
enum cx231xx_dev_state {};

enum AFE_MODE {};

enum AUDIO_INPUT {};

#define CX231XX_AUDIO_BUFS
#define CX231XX_NUM_AUDIO_PACKETS
#define CX231XX_ISO_NUM_AUDIO_PACKETS

/* cx231xx extensions */
#define CX231XX_AUDIO
#define CX231XX_DVB

struct cx231xx_audio {};

/*****************************************************************/
/* set/get i2c */
/* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
#define I2C_SPEED_1M
#define I2C_SPEED_400K
#define I2C_SPEED_100K
#define I2C_SPEED_5M

/* 0-- STOP transaction */
#define I2C_STOP
/* 1-- do not transmit STOP at end of transaction */
#define I2C_NOSTOP
/* 1--allow slave to insert clock wait states */
#define I2C_SYNC

struct cx231xx_i2c {};

struct cx231xx_i2c_xfer_data {};

struct VENDOR_REQUEST_IN {};

struct cx231xx_tvnorm {};

enum TRANSFER_TYPE {} ;

struct cx231xx_video_mode {};

struct cx231xx_tsport {};

/* main device struct */
struct cx231xx {};

extern struct list_head cx231xx_devlist;

#define cx25840_call(cx231xx, o, f, args...)
#define tuner_call(cx231xx, o, f, args...)
#define call_all(dev, o, f, args...)

struct cx231xx_ops {};

/* call back functions in dvb module */
int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
int cx231xx_reset_analog_tuner(struct cx231xx *dev);

/* Provided by cx231xx-i2c.c */
void cx231xx_do_i2c_scan(struct cx231xx *dev, int i2c_port);
int cx231xx_i2c_register(struct cx231xx_i2c *bus);
void cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
int cx231xx_i2c_mux_create(struct cx231xx *dev);
int cx231xx_i2c_mux_register(struct cx231xx *dev, int mux_no);
void cx231xx_i2c_mux_unregister(struct cx231xx *dev);
struct i2c_adapter *cx231xx_get_i2c_adap(struct cx231xx *dev, int i2c_port);

/* Internal block control functions */
int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
		 u8 saddr_len, u32 *data, u8 data_len, int master);
int cx231xx_write_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
		 u8 saddr_len, u32 data, u8 data_len, int master);
int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
			  u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
			   u16 saddr, u8 saddr_len, u32 data, u8 data_len);
int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
			   u16 register_address, u8 bit_start, u8 bit_end,
			   u32 value);
int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
					u16 saddr, u32 mask, u32 value);
u32 cx231xx_set_field(u32 field_mask, u32 data);

/*verve r/w*/
void initGPIO(struct cx231xx *dev);
void uninitGPIO(struct cx231xx *dev);
/* afe related functions */
int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count);
int cx231xx_afe_init_channels(struct cx231xx *dev);
int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev);
int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux);
int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
int cx231xx_afe_update_power_control(struct cx231xx *dev,
					enum AV_MODE avmode);
int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input);

/* i2s block related functions */
int cx231xx_i2s_blk_initialize(struct cx231xx *dev);
int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
					enum AV_MODE avmode);
int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input);

/* DIF related functions */
int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
					  u32 function_mode, u32 standard);
void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
					 u8 spectral_invert, u32 mode);
u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd);
void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
					 u8 spectral_invert, u32 mode);
void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev);
void reset_s5h1432_demod(struct cx231xx *dev);
void cx231xx_dump_HH_reg(struct cx231xx *dev);
void update_HH_register_after_set_DIF(struct cx231xx *dev);



int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
int cx231xx_tuner_post_channel_change(struct cx231xx *dev);

/* video parser functions */
u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size,
			     u32 *p_bytes_used);
u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
				 u32 *p_bytes_used);
int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
		    u8 *p_buffer, u32 bytes_to_copy);
void cx231xx_reset_video_buffer(struct cx231xx *dev,
				struct cx231xx_dmaqueue *dma_q);
u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
			    u8 *p_line, u32 length, int field_number);
u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
			   u8 sav_eav, u8 *p_buffer, u32 buffer_size);
void cx231xx_swab(u16 *from, u16 *to, u16 len);

/* Provided by cx231xx-core.c */

u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
void cx231xx_queue_unusedframes(struct cx231xx *dev);
void cx231xx_release_buffers(struct cx231xx *dev);

/* read from control pipe */
int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
			  char *buf, int len);

/* write to control pipe */
int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
			   char *buf, int len);
int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);

int cx231xx_send_vendor_cmd(struct cx231xx *dev,
				struct VENDOR_REQUEST_IN *ven_req);
int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
				struct cx231xx_i2c_xfer_data *req_data);

/* Gpio related functions */
int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
			  u8 len, u8 request, u8 direction);
int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
			       int pin_value);

int cx231xx_gpio_i2c_start(struct cx231xx *dev);
int cx231xx_gpio_i2c_end(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);

int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);

/* audio related functions */
int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
				    enum AUDIO_INPUT audio_input);

int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
int cx231xx_set_video_alternate(struct cx231xx *dev);
int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
int is_fw_load(struct cx231xx *dev);
int cx231xx_check_fw(struct cx231xx *dev);
int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
		      int num_bufs, int max_pkt_size,
		      int (*isoc_copy) (struct cx231xx *dev,
					struct urb *urb));
int cx231xx_init_bulk(struct cx231xx *dev, int max_packets,
		      int num_bufs, int max_pkt_size,
		      int (*bulk_copy) (struct cx231xx *dev,
					struct urb *urb));
void cx231xx_stop_TS1(struct cx231xx *dev);
void cx231xx_start_TS1(struct cx231xx *dev);
void cx231xx_uninit_isoc(struct cx231xx *dev);
void cx231xx_uninit_bulk(struct cx231xx *dev);
int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
int cx231xx_unmute_audio(struct cx231xx *dev);
int cx231xx_ep5_bulkout(struct cx231xx *dev, u8 *firmware, u16 size);
void cx231xx_disable656(struct cx231xx *dev);
void cx231xx_enable656(struct cx231xx *dev);
int cx231xx_demod_reset(struct cx231xx *dev);
int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);

/* Device list functions */
void cx231xx_release_resources(struct cx231xx *dev);
void cx231xx_release_analog_resources(struct cx231xx *dev);
int cx231xx_register_analog_devices(struct cx231xx *dev);
void cx231xx_remove_from_devlist(struct cx231xx *dev);
void cx231xx_add_into_devlist(struct cx231xx *dev);
void cx231xx_init_extension(struct cx231xx *dev);
void cx231xx_close_extension(struct cx231xx *dev);

/* hardware init functions */
int cx231xx_dev_init(struct cx231xx *dev);
void cx231xx_dev_uninit(struct cx231xx *dev);
void cx231xx_config_i2c(struct cx231xx *dev);
int cx231xx_config(struct cx231xx *dev);

/* Stream control functions */
int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);

int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);

/* Power control functions */
int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode);
int cx231xx_power_suspend(struct cx231xx *dev);

/* chip specific control functions */
int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
					      u8 analog_or_digital);
int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3);

/* video audio decoder related functions */
void video_mux(struct cx231xx *dev, int index);
int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);

/* Provided by cx231xx-video.c */
int cx231xx_register_extension(struct cx231xx_ops *dev);
void cx231xx_unregister_extension(struct cx231xx_ops *dev);
void cx231xx_init_extension(struct cx231xx *dev);
void cx231xx_close_extension(struct cx231xx *dev);
void cx231xx_v4l2_create_entities(struct cx231xx *dev);
int cx231xx_querycap(struct file *file, void *priv,
			   struct v4l2_capability *cap);
int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
int cx231xx_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
int cx231xx_g_frequency(struct file *file, void *priv,
			      struct v4l2_frequency *f);
int cx231xx_s_frequency(struct file *file, void *priv,
			      const struct v4l2_frequency *f);
int cx231xx_enum_input(struct file *file, void *priv,
			     struct v4l2_input *i);
int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
int cx231xx_g_chip_info(struct file *file, void *fh, struct v4l2_dbg_chip_info *chip);
int cx231xx_g_register(struct file *file, void *priv,
			     struct v4l2_dbg_register *reg);
int cx231xx_s_register(struct file *file, void *priv,
			     const struct v4l2_dbg_register *reg);

/* Provided by cx231xx-cards.c */
extern void cx231xx_pre_card_setup(struct cx231xx *dev);
extern void cx231xx_card_setup(struct cx231xx *dev);
extern struct cx231xx_board cx231xx_boards[];
extern struct usb_device_id cx231xx_id_table[];
extern const unsigned int cx231xx_bcount;
int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);

/* cx23885-417.c                                               */
extern int cx231xx_417_register(struct cx231xx *dev);
extern void cx231xx_417_unregister(struct cx231xx *dev);

/* cx23885-input.c                                             */

#if defined(CONFIG_VIDEO_CX231XX_RC)
int cx231xx_ir_init(struct cx231xx *dev);
void cx231xx_ir_exit(struct cx231xx *dev);
#else
static inline int cx231xx_ir_init(struct cx231xx *dev)
{
	return 0;
}
static inline void cx231xx_ir_exit(struct cx231xx *dev) {}
#endif

static inline unsigned int norm_maxw(struct cx231xx *dev)
{}

static inline unsigned int norm_maxh(struct cx231xx *dev)
{}
#endif