18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Driver for the NXP SAA7164 PCIe bridge
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/* TODO: Retest the driver with errors expressed as negatives */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* Result codes */
118c2ecf20Sopenharmony_ci#define SAA_OK				0
128c2ecf20Sopenharmony_ci#define SAA_ERR_BAD_PARAMETER		0x09
138c2ecf20Sopenharmony_ci#define SAA_ERR_NO_RESOURCES		0x0c
148c2ecf20Sopenharmony_ci#define SAA_ERR_NOT_SUPPORTED		0x13
158c2ecf20Sopenharmony_ci#define SAA_ERR_BUSY			0x15
168c2ecf20Sopenharmony_ci#define SAA_ERR_READ			0x17
178c2ecf20Sopenharmony_ci#define SAA_ERR_TIMEOUT			0x1f
188c2ecf20Sopenharmony_ci#define SAA_ERR_OVERFLOW		0x20
198c2ecf20Sopenharmony_ci#define SAA_ERR_EMPTY			0x22
208c2ecf20Sopenharmony_ci#define SAA_ERR_NOT_STARTED		0x23
218c2ecf20Sopenharmony_ci#define SAA_ERR_ALREADY_STARTED		0x24
228c2ecf20Sopenharmony_ci#define SAA_ERR_NOT_STOPPED		0x25
238c2ecf20Sopenharmony_ci#define SAA_ERR_ALREADY_STOPPED		0x26
248c2ecf20Sopenharmony_ci#define SAA_ERR_INVALID_COMMAND		0x3e
258c2ecf20Sopenharmony_ci#define SAA_ERR_NULL_PACKET		0x59
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* Errors and flags from the silicon */
288c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_UNKNOWN		0x00
298c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_INVALID_COMMAND	0x01
308c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_INVALID_CONTROL	0x02
318c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_INVALID_DATA	0x03
328c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_TIMEOUT		0x04
338c2ecf20Sopenharmony_ci#define PVC_ERRORCODE_NAK		0x05
348c2ecf20Sopenharmony_ci#define PVC_RESPONSEFLAG_ERROR		0x01
358c2ecf20Sopenharmony_ci#define PVC_RESPONSEFLAG_OVERFLOW	0x02
368c2ecf20Sopenharmony_ci#define PVC_RESPONSEFLAG_RESET		0x04
378c2ecf20Sopenharmony_ci#define PVC_RESPONSEFLAG_INTERFACE	0x08
388c2ecf20Sopenharmony_ci#define PVC_RESPONSEFLAG_CONTINUED	0x10
398c2ecf20Sopenharmony_ci#define PVC_CMDFLAG_INTERRUPT		0x02
408c2ecf20Sopenharmony_ci#define PVC_CMDFLAG_INTERFACE		0x04
418c2ecf20Sopenharmony_ci#define PVC_CMDFLAG_SERIALIZE		0x08
428c2ecf20Sopenharmony_ci#define PVC_CMDFLAG_CONTINUE		0x10
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* Silicon Commands */
458c2ecf20Sopenharmony_ci#define GET_DESCRIPTORS_CONTROL		0x01
468c2ecf20Sopenharmony_ci#define GET_STRING_CONTROL		0x03
478c2ecf20Sopenharmony_ci#define GET_LANGUAGE_CONTROL		0x05
488c2ecf20Sopenharmony_ci#define SET_POWER_CONTROL		0x07
498c2ecf20Sopenharmony_ci#define GET_FW_STATUS_CONTROL		0x08
508c2ecf20Sopenharmony_ci#define GET_FW_VERSION_CONTROL		0x09
518c2ecf20Sopenharmony_ci#define SET_DEBUG_LEVEL_CONTROL		0x0B
528c2ecf20Sopenharmony_ci#define GET_DEBUG_DATA_CONTROL		0x0C
538c2ecf20Sopenharmony_ci#define GET_PRODUCTION_INFO_CONTROL	0x0D
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* cmd defines */
568c2ecf20Sopenharmony_ci#define SAA_CMDFLAG_CONTINUE		0x10
578c2ecf20Sopenharmony_ci#define SAA_CMD_MAX_MSG_UNITS		256
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* Some defines */
608c2ecf20Sopenharmony_ci#define SAA_BUS_TIMEOUT			50
618c2ecf20Sopenharmony_ci#define SAA_DEVICE_TIMEOUT		5000
628c2ecf20Sopenharmony_ci#define SAA_DEVICE_MAXREQUESTSIZE	256
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* Register addresses */
658c2ecf20Sopenharmony_ci#define SAA_DEVICE_VERSION		0x30
668c2ecf20Sopenharmony_ci#define SAA_DOWNLOAD_FLAGS		0x34
678c2ecf20Sopenharmony_ci#define SAA_DOWNLOAD_FLAG		0x34
688c2ecf20Sopenharmony_ci#define SAA_DOWNLOAD_FLAG_ACK		0x38
698c2ecf20Sopenharmony_ci#define SAA_DATAREADY_FLAG		0x3C
708c2ecf20Sopenharmony_ci#define SAA_DATAREADY_FLAG_ACK		0x40
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Boot loader register and bit definitions */
738c2ecf20Sopenharmony_ci#define SAA_BOOTLOADERERROR_FLAGS	0x44
748c2ecf20Sopenharmony_ci#define SAA_DEVICE_IMAGE_SEARCHING	0x01
758c2ecf20Sopenharmony_ci#define SAA_DEVICE_IMAGE_LOADING	0x02
768c2ecf20Sopenharmony_ci#define SAA_DEVICE_IMAGE_BOOTING	0x03
778c2ecf20Sopenharmony_ci#define SAA_DEVICE_IMAGE_CORRUPT	0x04
788c2ecf20Sopenharmony_ci#define SAA_DEVICE_MEMORY_CORRUPT	0x08
798c2ecf20Sopenharmony_ci#define SAA_DEVICE_NO_IMAGE		0x10
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci/* Register addresses */
828c2ecf20Sopenharmony_ci#define SAA_DEVICE_2ND_VERSION			0x50
838c2ecf20Sopenharmony_ci#define SAA_DEVICE_2ND_DOWNLOADFLAG_OFFSET	0x54
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Register addresses */
868c2ecf20Sopenharmony_ci#define SAA_SECONDSTAGEERROR_FLAGS		0x64
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* Bootloader regs and flags */
898c2ecf20Sopenharmony_ci#define SAA_DEVICE_DEADLOCK_DETECTED_OFFSET	0x6C
908c2ecf20Sopenharmony_ci#define SAA_DEVICE_DEADLOCK_DETECTED		0xDEADDEAD
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* Basic firmware status registers */
938c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_STATUS_OFFSET	0x70
948c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_STATUS		0x70
958c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_MODE			0x74
968c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_SPEC			0x78
978c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_INST			0x7C
988c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_CPULOAD		0x80
998c2ecf20Sopenharmony_ci#define SAA_DEVICE_SYSINIT_REMAINHEAP		0x84
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define SAA_DEVICE_DOWNLOAD_OFFSET		0x1000
1028c2ecf20Sopenharmony_ci#define SAA_DEVICE_BUFFERBLOCKSIZE		0x1000
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define SAA_DEVICE_2ND_BUFFERBLOCKSIZE		0x100000
1058c2ecf20Sopenharmony_ci#define SAA_DEVICE_2ND_DOWNLOAD_OFFSET		0x200000
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci/* Descriptors */
1088c2ecf20Sopenharmony_ci#define CS_INTERFACE	0x24
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/* Descriptor subtypes */
1118c2ecf20Sopenharmony_ci#define VC_INPUT_TERMINAL		0x02
1128c2ecf20Sopenharmony_ci#define VC_OUTPUT_TERMINAL		0x03
1138c2ecf20Sopenharmony_ci#define VC_SELECTOR_UNIT		0x04
1148c2ecf20Sopenharmony_ci#define VC_PROCESSING_UNIT		0x05
1158c2ecf20Sopenharmony_ci#define FEATURE_UNIT			0x06
1168c2ecf20Sopenharmony_ci#define TUNER_UNIT			0x09
1178c2ecf20Sopenharmony_ci#define ENCODER_UNIT			0x0A
1188c2ecf20Sopenharmony_ci#define EXTENSION_UNIT			0x0B
1198c2ecf20Sopenharmony_ci#define VC_TUNER_PATH			0xF0
1208c2ecf20Sopenharmony_ci#define PVC_HARDWARE_DESCRIPTOR		0xF1
1218c2ecf20Sopenharmony_ci#define PVC_INTERFACE_DESCRIPTOR	0xF2
1228c2ecf20Sopenharmony_ci#define PVC_INFRARED_UNIT		0xF3
1238c2ecf20Sopenharmony_ci#define DRM_UNIT			0xF4
1248c2ecf20Sopenharmony_ci#define GENERAL_REQUEST			0xF5
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci/* Format Types */
1278c2ecf20Sopenharmony_ci#define VS_FORMAT_TYPE         0x02
1288c2ecf20Sopenharmony_ci#define VS_FORMAT_TYPE_I       0x01
1298c2ecf20Sopenharmony_ci#define VS_FORMAT_UNCOMPRESSED 0x04
1308c2ecf20Sopenharmony_ci#define VS_FRAME_UNCOMPRESSED  0x05
1318c2ecf20Sopenharmony_ci#define VS_FORMAT_MPEG2PS      0x09
1328c2ecf20Sopenharmony_ci#define VS_FORMAT_MPEG2TS      0x0A
1338c2ecf20Sopenharmony_ci#define VS_FORMAT_MPEG4SL      0x0B
1348c2ecf20Sopenharmony_ci#define VS_FORMAT_WM9          0x0C
1358c2ecf20Sopenharmony_ci#define VS_FORMAT_DIVX         0x0D
1368c2ecf20Sopenharmony_ci#define VS_FORMAT_VBI          0x0E
1378c2ecf20Sopenharmony_ci#define VS_FORMAT_RDS          0x0F
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* Device extension commands */
1408c2ecf20Sopenharmony_ci#define EXU_REGISTER_ACCESS_CONTROL	0x00
1418c2ecf20Sopenharmony_ci#define EXU_GPIO_CONTROL		0x01
1428c2ecf20Sopenharmony_ci#define EXU_GPIO_GROUP_CONTROL		0x02
1438c2ecf20Sopenharmony_ci#define EXU_INTERRUPT_CONTROL		0x03
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* State Transition and args */
1468c2ecf20Sopenharmony_ci#define SAA_PROBE_CONTROL	0x01
1478c2ecf20Sopenharmony_ci#define SAA_COMMIT_CONTROL	0x02
1488c2ecf20Sopenharmony_ci#define SAA_STATE_CONTROL	0x03
1498c2ecf20Sopenharmony_ci#define SAA_DMASTATE_STOP	0x00
1508c2ecf20Sopenharmony_ci#define SAA_DMASTATE_ACQUIRE	0x01
1518c2ecf20Sopenharmony_ci#define SAA_DMASTATE_PAUSE	0x02
1528c2ecf20Sopenharmony_ci#define SAA_DMASTATE_RUN	0x03
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* A/V Mux Input Selector */
1558c2ecf20Sopenharmony_ci#define SU_INPUT_SELECT_CONTROL 0x01
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/* Encoder Profiles */
1588c2ecf20Sopenharmony_ci#define EU_PROFILE_PS_DVD	0x06
1598c2ecf20Sopenharmony_ci#define EU_PROFILE_TS_HQ	0x09
1608c2ecf20Sopenharmony_ci#define EU_VIDEO_FORMAT_MPEG_2	0x02
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci/* Tuner */
1638c2ecf20Sopenharmony_ci#define TU_AUDIO_MODE_CONTROL  0x17
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* Video Formats */
1668c2ecf20Sopenharmony_ci#define TU_STANDARD_CONTROL		0x00
1678c2ecf20Sopenharmony_ci#define TU_STANDARD_AUTO_CONTROL	0x01
1688c2ecf20Sopenharmony_ci#define TU_STANDARD_NONE		0x00
1698c2ecf20Sopenharmony_ci#define TU_STANDARD_NTSC_M		0x01
1708c2ecf20Sopenharmony_ci#define TU_STANDARD_PAL_I		0x08
1718c2ecf20Sopenharmony_ci#define TU_STANDARD_MANUAL		0x00
1728c2ecf20Sopenharmony_ci#define TU_STANDARD_AUTO		0x01
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci/* Video Controls */
1758c2ecf20Sopenharmony_ci#define PU_BRIGHTNESS_CONTROL	0x02
1768c2ecf20Sopenharmony_ci#define PU_CONTRAST_CONTROL	0x03
1778c2ecf20Sopenharmony_ci#define PU_HUE_CONTROL		0x06
1788c2ecf20Sopenharmony_ci#define PU_SATURATION_CONTROL	0x07
1798c2ecf20Sopenharmony_ci#define PU_SHARPNESS_CONTROL	0x08
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci/* Audio Controls */
1828c2ecf20Sopenharmony_ci#define MUTE_CONTROL		0x01
1838c2ecf20Sopenharmony_ci#define VOLUME_CONTROL		0x02
1848c2ecf20Sopenharmony_ci#define AUDIO_DEFAULT_CONTROL	0x0D
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/* Default Volume Levels */
1878c2ecf20Sopenharmony_ci#define TMHW_LEV_ADJ_DECLEV_DEFAULT     0x00
1888c2ecf20Sopenharmony_ci#define TMHW_LEV_ADJ_MONOLEV_DEFAULT    0x00
1898c2ecf20Sopenharmony_ci#define TMHW_LEV_ADJ_NICLEV_DEFAULT     0x00
1908c2ecf20Sopenharmony_ci#define TMHW_LEV_ADJ_SAPLEV_DEFAULT     0x00
1918c2ecf20Sopenharmony_ci#define TMHW_LEV_ADJ_ADCLEV_DEFAULT     0x00
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* Encoder Related Commands */
1948c2ecf20Sopenharmony_ci#define EU_PROFILE_CONTROL		0x00
1958c2ecf20Sopenharmony_ci#define EU_VIDEO_FORMAT_CONTROL		0x01
1968c2ecf20Sopenharmony_ci#define EU_VIDEO_BIT_RATE_CONTROL	0x02
1978c2ecf20Sopenharmony_ci#define EU_VIDEO_RESOLUTION_CONTROL	0x03
1988c2ecf20Sopenharmony_ci#define EU_VIDEO_GOP_STRUCTURE_CONTROL	0x04
1998c2ecf20Sopenharmony_ci#define EU_VIDEO_INPUT_ASPECT_CONTROL	0x0A
2008c2ecf20Sopenharmony_ci#define EU_AUDIO_FORMAT_CONTROL		0x0C
2018c2ecf20Sopenharmony_ci#define EU_AUDIO_BIT_RATE_CONTROL	0x0D
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* Firmware Debugging */
2048c2ecf20Sopenharmony_ci#define SET_DEBUG_LEVEL_CONTROL	0x0B
2058c2ecf20Sopenharmony_ci#define GET_DEBUG_DATA_CONTROL	0x0C
206