162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Driver for the NXP SAA7164 PCIe bridge 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com> 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci/* TODO: Retest the driver with errors expressed as negatives */ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* Result codes */ 1162306a36Sopenharmony_ci#define SAA_OK 0 1262306a36Sopenharmony_ci#define SAA_ERR_BAD_PARAMETER 0x09 1362306a36Sopenharmony_ci#define SAA_ERR_NO_RESOURCES 0x0c 1462306a36Sopenharmony_ci#define SAA_ERR_NOT_SUPPORTED 0x13 1562306a36Sopenharmony_ci#define SAA_ERR_BUSY 0x15 1662306a36Sopenharmony_ci#define SAA_ERR_READ 0x17 1762306a36Sopenharmony_ci#define SAA_ERR_TIMEOUT 0x1f 1862306a36Sopenharmony_ci#define SAA_ERR_OVERFLOW 0x20 1962306a36Sopenharmony_ci#define SAA_ERR_EMPTY 0x22 2062306a36Sopenharmony_ci#define SAA_ERR_NOT_STARTED 0x23 2162306a36Sopenharmony_ci#define SAA_ERR_ALREADY_STARTED 0x24 2262306a36Sopenharmony_ci#define SAA_ERR_NOT_STOPPED 0x25 2362306a36Sopenharmony_ci#define SAA_ERR_ALREADY_STOPPED 0x26 2462306a36Sopenharmony_ci#define SAA_ERR_INVALID_COMMAND 0x3e 2562306a36Sopenharmony_ci#define SAA_ERR_NULL_PACKET 0x59 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* Errors and flags from the silicon */ 2862306a36Sopenharmony_ci#define PVC_ERRORCODE_UNKNOWN 0x00 2962306a36Sopenharmony_ci#define PVC_ERRORCODE_INVALID_COMMAND 0x01 3062306a36Sopenharmony_ci#define PVC_ERRORCODE_INVALID_CONTROL 0x02 3162306a36Sopenharmony_ci#define PVC_ERRORCODE_INVALID_DATA 0x03 3262306a36Sopenharmony_ci#define PVC_ERRORCODE_TIMEOUT 0x04 3362306a36Sopenharmony_ci#define PVC_ERRORCODE_NAK 0x05 3462306a36Sopenharmony_ci#define PVC_RESPONSEFLAG_ERROR 0x01 3562306a36Sopenharmony_ci#define PVC_RESPONSEFLAG_OVERFLOW 0x02 3662306a36Sopenharmony_ci#define PVC_RESPONSEFLAG_RESET 0x04 3762306a36Sopenharmony_ci#define PVC_RESPONSEFLAG_INTERFACE 0x08 3862306a36Sopenharmony_ci#define PVC_RESPONSEFLAG_CONTINUED 0x10 3962306a36Sopenharmony_ci#define PVC_CMDFLAG_INTERRUPT 0x02 4062306a36Sopenharmony_ci#define PVC_CMDFLAG_INTERFACE 0x04 4162306a36Sopenharmony_ci#define PVC_CMDFLAG_SERIALIZE 0x08 4262306a36Sopenharmony_ci#define PVC_CMDFLAG_CONTINUE 0x10 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* Silicon Commands */ 4562306a36Sopenharmony_ci#define GET_DESCRIPTORS_CONTROL 0x01 4662306a36Sopenharmony_ci#define GET_STRING_CONTROL 0x03 4762306a36Sopenharmony_ci#define GET_LANGUAGE_CONTROL 0x05 4862306a36Sopenharmony_ci#define SET_POWER_CONTROL 0x07 4962306a36Sopenharmony_ci#define GET_FW_STATUS_CONTROL 0x08 5062306a36Sopenharmony_ci#define GET_FW_VERSION_CONTROL 0x09 5162306a36Sopenharmony_ci#define SET_DEBUG_LEVEL_CONTROL 0x0B 5262306a36Sopenharmony_ci#define GET_DEBUG_DATA_CONTROL 0x0C 5362306a36Sopenharmony_ci#define GET_PRODUCTION_INFO_CONTROL 0x0D 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* cmd defines */ 5662306a36Sopenharmony_ci#define SAA_CMDFLAG_CONTINUE 0x10 5762306a36Sopenharmony_ci#define SAA_CMD_MAX_MSG_UNITS 256 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* Some defines */ 6062306a36Sopenharmony_ci#define SAA_BUS_TIMEOUT 50 6162306a36Sopenharmony_ci#define SAA_DEVICE_TIMEOUT 5000 6262306a36Sopenharmony_ci#define SAA_DEVICE_MAXREQUESTSIZE 256 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci/* Register addresses */ 6562306a36Sopenharmony_ci#define SAA_DEVICE_VERSION 0x30 6662306a36Sopenharmony_ci#define SAA_DOWNLOAD_FLAGS 0x34 6762306a36Sopenharmony_ci#define SAA_DOWNLOAD_FLAG 0x34 6862306a36Sopenharmony_ci#define SAA_DOWNLOAD_FLAG_ACK 0x38 6962306a36Sopenharmony_ci#define SAA_DATAREADY_FLAG 0x3C 7062306a36Sopenharmony_ci#define SAA_DATAREADY_FLAG_ACK 0x40 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci/* Boot loader register and bit definitions */ 7362306a36Sopenharmony_ci#define SAA_BOOTLOADERERROR_FLAGS 0x44 7462306a36Sopenharmony_ci#define SAA_DEVICE_IMAGE_SEARCHING 0x01 7562306a36Sopenharmony_ci#define SAA_DEVICE_IMAGE_LOADING 0x02 7662306a36Sopenharmony_ci#define SAA_DEVICE_IMAGE_BOOTING 0x03 7762306a36Sopenharmony_ci#define SAA_DEVICE_IMAGE_CORRUPT 0x04 7862306a36Sopenharmony_ci#define SAA_DEVICE_MEMORY_CORRUPT 0x08 7962306a36Sopenharmony_ci#define SAA_DEVICE_NO_IMAGE 0x10 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Register addresses */ 8262306a36Sopenharmony_ci#define SAA_DEVICE_2ND_VERSION 0x50 8362306a36Sopenharmony_ci#define SAA_DEVICE_2ND_DOWNLOADFLAG_OFFSET 0x54 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* Register addresses */ 8662306a36Sopenharmony_ci#define SAA_SECONDSTAGEERROR_FLAGS 0x64 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* Bootloader regs and flags */ 8962306a36Sopenharmony_ci#define SAA_DEVICE_DEADLOCK_DETECTED_OFFSET 0x6C 9062306a36Sopenharmony_ci#define SAA_DEVICE_DEADLOCK_DETECTED 0xDEADDEAD 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* Basic firmware status registers */ 9362306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_STATUS_OFFSET 0x70 9462306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_STATUS 0x70 9562306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_MODE 0x74 9662306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_SPEC 0x78 9762306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_INST 0x7C 9862306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_CPULOAD 0x80 9962306a36Sopenharmony_ci#define SAA_DEVICE_SYSINIT_REMAINHEAP 0x84 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define SAA_DEVICE_DOWNLOAD_OFFSET 0x1000 10262306a36Sopenharmony_ci#define SAA_DEVICE_BUFFERBLOCKSIZE 0x1000 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci#define SAA_DEVICE_2ND_BUFFERBLOCKSIZE 0x100000 10562306a36Sopenharmony_ci#define SAA_DEVICE_2ND_DOWNLOAD_OFFSET 0x200000 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* Descriptors */ 10862306a36Sopenharmony_ci#define CS_INTERFACE 0x24 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* Descriptor subtypes */ 11162306a36Sopenharmony_ci#define VC_INPUT_TERMINAL 0x02 11262306a36Sopenharmony_ci#define VC_OUTPUT_TERMINAL 0x03 11362306a36Sopenharmony_ci#define VC_SELECTOR_UNIT 0x04 11462306a36Sopenharmony_ci#define VC_PROCESSING_UNIT 0x05 11562306a36Sopenharmony_ci#define FEATURE_UNIT 0x06 11662306a36Sopenharmony_ci#define TUNER_UNIT 0x09 11762306a36Sopenharmony_ci#define ENCODER_UNIT 0x0A 11862306a36Sopenharmony_ci#define EXTENSION_UNIT 0x0B 11962306a36Sopenharmony_ci#define VC_TUNER_PATH 0xF0 12062306a36Sopenharmony_ci#define PVC_HARDWARE_DESCRIPTOR 0xF1 12162306a36Sopenharmony_ci#define PVC_INTERFACE_DESCRIPTOR 0xF2 12262306a36Sopenharmony_ci#define PVC_INFRARED_UNIT 0xF3 12362306a36Sopenharmony_ci#define DRM_UNIT 0xF4 12462306a36Sopenharmony_ci#define GENERAL_REQUEST 0xF5 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci/* Format Types */ 12762306a36Sopenharmony_ci#define VS_FORMAT_TYPE 0x02 12862306a36Sopenharmony_ci#define VS_FORMAT_TYPE_I 0x01 12962306a36Sopenharmony_ci#define VS_FORMAT_UNCOMPRESSED 0x04 13062306a36Sopenharmony_ci#define VS_FRAME_UNCOMPRESSED 0x05 13162306a36Sopenharmony_ci#define VS_FORMAT_MPEG2PS 0x09 13262306a36Sopenharmony_ci#define VS_FORMAT_MPEG2TS 0x0A 13362306a36Sopenharmony_ci#define VS_FORMAT_MPEG4SL 0x0B 13462306a36Sopenharmony_ci#define VS_FORMAT_WM9 0x0C 13562306a36Sopenharmony_ci#define VS_FORMAT_DIVX 0x0D 13662306a36Sopenharmony_ci#define VS_FORMAT_VBI 0x0E 13762306a36Sopenharmony_ci#define VS_FORMAT_RDS 0x0F 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci/* Device extension commands */ 14062306a36Sopenharmony_ci#define EXU_REGISTER_ACCESS_CONTROL 0x00 14162306a36Sopenharmony_ci#define EXU_GPIO_CONTROL 0x01 14262306a36Sopenharmony_ci#define EXU_GPIO_GROUP_CONTROL 0x02 14362306a36Sopenharmony_ci#define EXU_INTERRUPT_CONTROL 0x03 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/* State Transition and args */ 14662306a36Sopenharmony_ci#define SAA_PROBE_CONTROL 0x01 14762306a36Sopenharmony_ci#define SAA_COMMIT_CONTROL 0x02 14862306a36Sopenharmony_ci#define SAA_STATE_CONTROL 0x03 14962306a36Sopenharmony_ci#define SAA_DMASTATE_STOP 0x00 15062306a36Sopenharmony_ci#define SAA_DMASTATE_ACQUIRE 0x01 15162306a36Sopenharmony_ci#define SAA_DMASTATE_PAUSE 0x02 15262306a36Sopenharmony_ci#define SAA_DMASTATE_RUN 0x03 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/* A/V Mux Input Selector */ 15562306a36Sopenharmony_ci#define SU_INPUT_SELECT_CONTROL 0x01 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ci/* Encoder Profiles */ 15862306a36Sopenharmony_ci#define EU_PROFILE_PS_DVD 0x06 15962306a36Sopenharmony_ci#define EU_PROFILE_TS_HQ 0x09 16062306a36Sopenharmony_ci#define EU_VIDEO_FORMAT_MPEG_2 0x02 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/* Tuner */ 16362306a36Sopenharmony_ci#define TU_AUDIO_MODE_CONTROL 0x17 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci/* Video Formats */ 16662306a36Sopenharmony_ci#define TU_STANDARD_CONTROL 0x00 16762306a36Sopenharmony_ci#define TU_STANDARD_AUTO_CONTROL 0x01 16862306a36Sopenharmony_ci#define TU_STANDARD_NONE 0x00 16962306a36Sopenharmony_ci#define TU_STANDARD_NTSC_M 0x01 17062306a36Sopenharmony_ci#define TU_STANDARD_PAL_I 0x08 17162306a36Sopenharmony_ci#define TU_STANDARD_MANUAL 0x00 17262306a36Sopenharmony_ci#define TU_STANDARD_AUTO 0x01 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/* Video Controls */ 17562306a36Sopenharmony_ci#define PU_BRIGHTNESS_CONTROL 0x02 17662306a36Sopenharmony_ci#define PU_CONTRAST_CONTROL 0x03 17762306a36Sopenharmony_ci#define PU_HUE_CONTROL 0x06 17862306a36Sopenharmony_ci#define PU_SATURATION_CONTROL 0x07 17962306a36Sopenharmony_ci#define PU_SHARPNESS_CONTROL 0x08 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci/* Audio Controls */ 18262306a36Sopenharmony_ci#define MUTE_CONTROL 0x01 18362306a36Sopenharmony_ci#define VOLUME_CONTROL 0x02 18462306a36Sopenharmony_ci#define AUDIO_DEFAULT_CONTROL 0x0D 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci/* Default Volume Levels */ 18762306a36Sopenharmony_ci#define TMHW_LEV_ADJ_DECLEV_DEFAULT 0x00 18862306a36Sopenharmony_ci#define TMHW_LEV_ADJ_MONOLEV_DEFAULT 0x00 18962306a36Sopenharmony_ci#define TMHW_LEV_ADJ_NICLEV_DEFAULT 0x00 19062306a36Sopenharmony_ci#define TMHW_LEV_ADJ_SAPLEV_DEFAULT 0x00 19162306a36Sopenharmony_ci#define TMHW_LEV_ADJ_ADCLEV_DEFAULT 0x00 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci/* Encoder Related Commands */ 19462306a36Sopenharmony_ci#define EU_PROFILE_CONTROL 0x00 19562306a36Sopenharmony_ci#define EU_VIDEO_FORMAT_CONTROL 0x01 19662306a36Sopenharmony_ci#define EU_VIDEO_BIT_RATE_CONTROL 0x02 19762306a36Sopenharmony_ci#define EU_VIDEO_RESOLUTION_CONTROL 0x03 19862306a36Sopenharmony_ci#define EU_VIDEO_GOP_STRUCTURE_CONTROL 0x04 19962306a36Sopenharmony_ci#define EU_VIDEO_INPUT_ASPECT_CONTROL 0x0A 20062306a36Sopenharmony_ci#define EU_AUDIO_FORMAT_CONTROL 0x0C 20162306a36Sopenharmony_ci#define EU_AUDIO_BIT_RATE_CONTROL 0x0D 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/* Firmware Debugging */ 20462306a36Sopenharmony_ci#define SET_DEBUG_LEVEL_CONTROL 0x0B 20562306a36Sopenharmony_ci#define GET_DEBUG_DATA_CONTROL 0x0C 206