18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  cx18 functions to query card hardware
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Derived from ivtv-cards.c
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
88c2ecf20Sopenharmony_ci *  Copyright (C) 2008  Andy Walls <awalls@md.metrocast.net>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* hardware flags */
128c2ecf20Sopenharmony_ci#define CX18_HW_TUNER			(1 << 0)
138c2ecf20Sopenharmony_ci#define CX18_HW_TVEEPROM		(1 << 1)
148c2ecf20Sopenharmony_ci#define CX18_HW_CS5345			(1 << 2)
158c2ecf20Sopenharmony_ci#define CX18_HW_DVB			(1 << 3)
168c2ecf20Sopenharmony_ci#define CX18_HW_418_AV			(1 << 4)
178c2ecf20Sopenharmony_ci#define CX18_HW_GPIO_MUX		(1 << 5)
188c2ecf20Sopenharmony_ci#define CX18_HW_GPIO_RESET_CTRL		(1 << 6)
198c2ecf20Sopenharmony_ci#define CX18_HW_Z8F0811_IR_HAUP		(1 << 7)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* video inputs */
228c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_VID_TUNER	1
238c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_SVIDEO1		2
248c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_SVIDEO2		3
258c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_COMPOSITE1	4
268c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_COMPOSITE2	5
278c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_COMPONENT1	6
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* audio inputs */
308c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_AUD_TUNER	1
318c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_LINE_IN1	2
328c2ecf20Sopenharmony_ci#define	CX18_CARD_INPUT_LINE_IN2	3
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define CX18_CARD_MAX_VIDEO_INPUTS 6
358c2ecf20Sopenharmony_ci#define CX18_CARD_MAX_AUDIO_INPUTS 3
368c2ecf20Sopenharmony_ci#define CX18_CARD_MAX_TUNERS	   2
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* V4L2 capability aliases */
398c2ecf20Sopenharmony_ci#define CX18_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
408c2ecf20Sopenharmony_ci			  V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | \
418c2ecf20Sopenharmony_ci			  V4L2_CAP_STREAMING | V4L2_CAP_VBI_CAPTURE | \
428c2ecf20Sopenharmony_ci			  V4L2_CAP_SLICED_VBI_CAPTURE)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct cx18_card_video_input {
458c2ecf20Sopenharmony_ci	u8  video_type;		/* video input type */
468c2ecf20Sopenharmony_ci	u8  audio_index;	/* index in cx18_card_audio_input array */
478c2ecf20Sopenharmony_ci	u32 video_input;	/* hardware video input */
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct cx18_card_audio_input {
518c2ecf20Sopenharmony_ci	u8  audio_type;		/* audio input type */
528c2ecf20Sopenharmony_ci	u32 audio_input;	/* hardware audio input */
538c2ecf20Sopenharmony_ci	u16 muxer_input;	/* hardware muxer input for boards with a
548c2ecf20Sopenharmony_ci				   multiplexer chip */
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct cx18_card_pci_info {
588c2ecf20Sopenharmony_ci	u16 device;
598c2ecf20Sopenharmony_ci	u16 subsystem_vendor;
608c2ecf20Sopenharmony_ci	u16 subsystem_device;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* GPIO definitions */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* The mask is the set of bits used by the operation */
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistruct cx18_gpio_init { /* set initial GPIO DIR and OUT values */
688c2ecf20Sopenharmony_ci	u32 direction;	/* DIR setting. Leave to 0 if no init is needed */
698c2ecf20Sopenharmony_ci	u32 initial_value;
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct cx18_gpio_i2c_slave_reset {
738c2ecf20Sopenharmony_ci	u32 active_lo_mask; /* GPIO outputs that reset i2c chips when low */
748c2ecf20Sopenharmony_ci	u32 active_hi_mask; /* GPIO outputs that reset i2c chips when high */
758c2ecf20Sopenharmony_ci	int msecs_asserted; /* time period reset must remain asserted */
768c2ecf20Sopenharmony_ci	int msecs_recovery; /* time after deassert for chips to be ready */
778c2ecf20Sopenharmony_ci	u32 ir_reset_mask;  /* GPIO to reset the Zilog Z8F0811 IR controller */
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct cx18_gpio_audio_input {	/* select tuner/line in input */
818c2ecf20Sopenharmony_ci	u32 mask;		/* leave to 0 if not supported */
828c2ecf20Sopenharmony_ci	u32 tuner;
838c2ecf20Sopenharmony_ci	u32 linein;
848c2ecf20Sopenharmony_ci	u32 radio;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistruct cx18_card_tuner {
888c2ecf20Sopenharmony_ci	v4l2_std_id std;	/* standard for which the tuner is suitable */
898c2ecf20Sopenharmony_ci	int	    tuner;	/* tuner ID (from tuner.h) */
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct cx18_card_tuner_i2c {
938c2ecf20Sopenharmony_ci	unsigned short radio[2];/* radio tuner i2c address to probe */
948c2ecf20Sopenharmony_ci	unsigned short demod[3];/* demodulator i2c address to probe */
958c2ecf20Sopenharmony_ci	unsigned short tv[4];	/* tv tuner i2c addresses to probe */
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistruct cx18_ddr {		/* DDR config data */
998c2ecf20Sopenharmony_ci	u32 chip_config;
1008c2ecf20Sopenharmony_ci	u32 refresh;
1018c2ecf20Sopenharmony_ci	u32 timing1;
1028c2ecf20Sopenharmony_ci	u32 timing2;
1038c2ecf20Sopenharmony_ci	u32 tune_lane;
1048c2ecf20Sopenharmony_ci	u32 initial_emrs;
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* for card information/parameters */
1088c2ecf20Sopenharmony_cistruct cx18_card {
1098c2ecf20Sopenharmony_ci	int type;
1108c2ecf20Sopenharmony_ci	char *name;
1118c2ecf20Sopenharmony_ci	char *comment;
1128c2ecf20Sopenharmony_ci	u32 v4l2_capabilities;
1138c2ecf20Sopenharmony_ci	u32 hw_audio_ctrl;	/* hardware used for the V4L2 controls (only
1148c2ecf20Sopenharmony_ci				   1 dev allowed currently) */
1158c2ecf20Sopenharmony_ci	u32 hw_muxer;		/* hardware used to multiplex audio input */
1168c2ecf20Sopenharmony_ci	u32 hw_all;		/* all hardware used by the board */
1178c2ecf20Sopenharmony_ci	struct cx18_card_video_input video_inputs[CX18_CARD_MAX_VIDEO_INPUTS];
1188c2ecf20Sopenharmony_ci	struct cx18_card_audio_input audio_inputs[CX18_CARD_MAX_AUDIO_INPUTS];
1198c2ecf20Sopenharmony_ci	struct cx18_card_audio_input radio_input;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	/* GPIO card-specific settings */
1228c2ecf20Sopenharmony_ci	u8 xceive_pin;		/* XCeive tuner GPIO reset pin */
1238c2ecf20Sopenharmony_ci	struct cx18_gpio_init		 gpio_init;
1248c2ecf20Sopenharmony_ci	struct cx18_gpio_i2c_slave_reset gpio_i2c_slave_reset;
1258c2ecf20Sopenharmony_ci	struct cx18_gpio_audio_input    gpio_audio_input;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	struct cx18_card_tuner tuners[CX18_CARD_MAX_TUNERS];
1288c2ecf20Sopenharmony_ci	struct cx18_card_tuner_i2c *i2c;
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci	struct cx18_ddr ddr;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	/* list of device and subsystem vendor/devices that
1338c2ecf20Sopenharmony_ci	   correspond to this card type. */
1348c2ecf20Sopenharmony_ci	const struct cx18_card_pci_info *pci_list;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciint cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input);
1388c2ecf20Sopenharmony_ciint cx18_get_audio_input(struct cx18 *cx, u16 index, struct v4l2_audio *input);
1398c2ecf20Sopenharmony_ciconst struct cx18_card *cx18_get_card(u16 index);
140