Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the NXP SAA7164 PCIe bridge |
| 3 | * |
Steven Toth | 9b8b019 | 2010-07-31 14:39:44 -0300 | [diff] [blame] | 4 | * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com> |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | /* TODO: Retest the driver with errors expressed as negatives */ |
| 23 | |
| 24 | /* Result codes */ |
| 25 | #define SAA_OK 0 |
| 26 | #define SAA_ERR_BAD_PARAMETER 0x09 |
| 27 | #define SAA_ERR_NO_RESOURCES 0x0c |
| 28 | #define SAA_ERR_NOT_SUPPORTED 0x13 |
| 29 | #define SAA_ERR_BUSY 0x15 |
| 30 | #define SAA_ERR_READ 0x17 |
| 31 | #define SAA_ERR_TIMEOUT 0x1f |
| 32 | #define SAA_ERR_OVERFLOW 0x20 |
| 33 | #define SAA_ERR_EMPTY 0x22 |
| 34 | #define SAA_ERR_NOT_STARTED 0x23 |
| 35 | #define SAA_ERR_ALREADY_STARTED 0x24 |
| 36 | #define SAA_ERR_NOT_STOPPED 0x25 |
| 37 | #define SAA_ERR_ALREADY_STOPPED 0x26 |
| 38 | #define SAA_ERR_INVALID_COMMAND 0x3e |
| 39 | #define SAA_ERR_NULL_PACKET 0x59 |
| 40 | |
| 41 | /* Errors and flags from the silicon */ |
| 42 | #define PVC_ERRORCODE_UNKNOWN 0x00 |
| 43 | #define PVC_ERRORCODE_INVALID_COMMAND 0x01 |
| 44 | #define PVC_ERRORCODE_INVALID_CONTROL 0x02 |
| 45 | #define PVC_ERRORCODE_INVALID_DATA 0x03 |
| 46 | #define PVC_ERRORCODE_TIMEOUT 0x04 |
| 47 | #define PVC_ERRORCODE_NAK 0x05 |
| 48 | #define PVC_RESPONSEFLAG_ERROR 0x01 |
| 49 | #define PVC_RESPONSEFLAG_OVERFLOW 0x02 |
| 50 | #define PVC_RESPONSEFLAG_RESET 0x04 |
| 51 | #define PVC_RESPONSEFLAG_INTERFACE 0x08 |
| 52 | #define PVC_RESPONSEFLAG_CONTINUED 0x10 |
| 53 | #define PVC_CMDFLAG_INTERRUPT 0x02 |
| 54 | #define PVC_CMDFLAG_INTERFACE 0x04 |
| 55 | #define PVC_CMDFLAG_SERIALIZE 0x08 |
| 56 | #define PVC_CMDFLAG_CONTINUE 0x10 |
| 57 | |
| 58 | /* Silicon Commands */ |
| 59 | #define GET_DESCRIPTORS_CONTROL 0x01 |
| 60 | #define GET_STRING_CONTROL 0x03 |
| 61 | #define GET_LANGUAGE_CONTROL 0x05 |
| 62 | #define SET_POWER_CONTROL 0x07 |
| 63 | #define GET_FW_VERSION_CONTROL 0x09 |
| 64 | #define SET_DEBUG_LEVEL_CONTROL 0x0B |
| 65 | #define GET_DEBUG_DATA_CONTROL 0x0C |
| 66 | #define GET_PRODUCTION_INFO_CONTROL 0x0D |
| 67 | |
| 68 | /* cmd defines */ |
| 69 | #define SAA_CMDFLAG_CONTINUE 0x10 |
| 70 | #define SAA_CMD_MAX_MSG_UNITS 256 |
| 71 | |
| 72 | /* Some defines */ |
| 73 | #define SAA_BUS_TIMEOUT 50 |
| 74 | #define SAA_DEVICE_TIMEOUT 5000 |
| 75 | #define SAA_DEVICE_MAXREQUESTSIZE 256 |
| 76 | |
| 77 | /* Register addresses */ |
| 78 | #define SAA_DEVICE_VERSION 0x30 |
| 79 | #define SAA_DOWNLOAD_FLAGS 0x34 |
| 80 | #define SAA_DOWNLOAD_FLAG 0x34 |
| 81 | #define SAA_DOWNLOAD_FLAG_ACK 0x38 |
| 82 | #define SAA_DATAREADY_FLAG 0x3C |
| 83 | #define SAA_DATAREADY_FLAG_ACK 0x40 |
| 84 | |
| 85 | /* Boot loader register and bit definitions */ |
| 86 | #define SAA_BOOTLOADERERROR_FLAGS 0x44 |
| 87 | #define SAA_DEVICE_IMAGE_SEARCHING 0x01 |
| 88 | #define SAA_DEVICE_IMAGE_LOADING 0x02 |
| 89 | #define SAA_DEVICE_IMAGE_BOOTING 0x03 |
| 90 | #define SAA_DEVICE_IMAGE_CORRUPT 0x04 |
| 91 | #define SAA_DEVICE_MEMORY_CORRUPT 0x08 |
| 92 | #define SAA_DEVICE_NO_IMAGE 0x10 |
| 93 | |
| 94 | /* Register addresses */ |
| 95 | #define SAA_DEVICE_2ND_VERSION 0x50 |
| 96 | #define SAA_DEVICE_2ND_DOWNLOADFLAG_OFFSET 0x54 |
| 97 | |
| 98 | /* Register addresses */ |
| 99 | #define SAA_SECONDSTAGEERROR_FLAGS 0x64 |
| 100 | |
| 101 | /* Bootloader regs and flags */ |
| 102 | #define SAA_DEVICE_DEADLOCK_DETECTED_OFFSET 0x6C |
| 103 | #define SAA_DEVICE_DEADLOCK_DETECTED 0xDEADDEAD |
| 104 | |
| 105 | /* Basic firmware status registers */ |
| 106 | #define SAA_DEVICE_SYSINIT_STATUS_OFFSET 0x70 |
| 107 | #define SAA_DEVICE_SYSINIT_STATUS 0x70 |
| 108 | #define SAA_DEVICE_SYSINIT_MODE 0x74 |
| 109 | #define SAA_DEVICE_SYSINIT_SPEC 0x78 |
| 110 | #define SAA_DEVICE_SYSINIT_INST 0x7C |
| 111 | #define SAA_DEVICE_SYSINIT_CPULOAD 0x80 |
| 112 | #define SAA_DEVICE_SYSINIT_REMAINHEAP 0x84 |
| 113 | |
| 114 | #define SAA_DEVICE_DOWNLOAD_OFFSET 0x1000 |
| 115 | #define SAA_DEVICE_BUFFERBLOCKSIZE 0x1000 |
| 116 | |
| 117 | #define SAA_DEVICE_2ND_BUFFERBLOCKSIZE 0x100000 |
| 118 | #define SAA_DEVICE_2ND_DOWNLOAD_OFFSET 0x200000 |
| 119 | |
| 120 | /* Descriptors */ |
| 121 | #define CS_INTERFACE 0x24 |
| 122 | |
| 123 | /* Descriptor subtypes */ |
| 124 | #define VC_INPUT_TERMINAL 0x02 |
| 125 | #define VC_OUTPUT_TERMINAL 0x03 |
| 126 | #define VC_SELECTOR_UNIT 0x04 |
| 127 | #define VC_PROCESSING_UNIT 0x05 |
| 128 | #define FEATURE_UNIT 0x06 |
| 129 | #define TUNER_UNIT 0x09 |
| 130 | #define ENCODER_UNIT 0x0A |
| 131 | #define EXTENSION_UNIT 0x0B |
| 132 | #define VC_TUNER_PATH 0xF0 |
| 133 | #define PVC_HARDWARE_DESCRIPTOR 0xF1 |
| 134 | #define PVC_INTERFACE_DESCRIPTOR 0xF2 |
| 135 | #define PVC_INFRARED_UNIT 0xF3 |
| 136 | #define DRM_UNIT 0xF4 |
| 137 | #define GENERAL_REQUEST 0xF5 |
| 138 | |
| 139 | /* Format Types */ |
| 140 | #define VS_FORMAT_TYPE 0x02 |
| 141 | #define VS_FORMAT_TYPE_I 0x01 |
| 142 | #define VS_FORMAT_UNCOMPRESSED 0x04 |
| 143 | #define VS_FRAME_UNCOMPRESSED 0x05 |
| 144 | #define VS_FORMAT_MPEG2PS 0x09 |
| 145 | #define VS_FORMAT_MPEG2TS 0x0A |
| 146 | #define VS_FORMAT_MPEG4SL 0x0B |
| 147 | #define VS_FORMAT_WM9 0x0C |
| 148 | #define VS_FORMAT_DIVX 0x0D |
| 149 | #define VS_FORMAT_VBI 0x0E |
| 150 | #define VS_FORMAT_RDS 0x0F |
| 151 | |
| 152 | /* Device extension commands */ |
| 153 | #define EXU_REGISTER_ACCESS_CONTROL 0x00 |
| 154 | #define EXU_GPIO_CONTROL 0x01 |
| 155 | #define EXU_GPIO_GROUP_CONTROL 0x02 |
| 156 | #define EXU_INTERRUPT_CONTROL 0x03 |
| 157 | |
| 158 | /* State Transition and args */ |
Steven Toth | e8ce2f2 | 2010-07-31 16:06:06 -0300 | [diff] [blame] | 159 | #define SAA_PROBE_CONTROL 0x01 |
| 160 | #define SAA_COMMIT_CONTROL 0x02 |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 161 | #define SAA_STATE_CONTROL 0x03 |
| 162 | #define SAA_DMASTATE_STOP 0x00 |
| 163 | #define SAA_DMASTATE_ACQUIRE 0x01 |
| 164 | #define SAA_DMASTATE_PAUSE 0x02 |
| 165 | #define SAA_DMASTATE_RUN 0x03 |
| 166 | |
Steven Toth | 335961c | 2010-07-31 14:41:09 -0300 | [diff] [blame] | 167 | /* A/V Mux Input Selector */ |
| 168 | #define SU_INPUT_SELECT_CONTROL 0x01 |
| 169 | |
| 170 | /* Encoder Profiles */ |
| 171 | #define EU_PROFILE_PS_DVD 0x06 |
| 172 | #define EU_PROFILE_TS_HQ 0x09 |
| 173 | #define EU_VIDEO_FORMAT_MPEG_2 0x02 |
| 174 | |
| 175 | /* Tuner */ |
| 176 | #define TU_AUDIO_MODE_CONTROL 0x17 |
| 177 | |
| 178 | /* Video Formats */ |
| 179 | #define TU_STANDARD_CONTROL 0x00 |
| 180 | #define TU_STANDARD_AUTO_CONTROL 0x01 |
| 181 | #define TU_STANDARD_NONE 0x00 |
| 182 | #define TU_STANDARD_NTSC_M 0x01 |
| 183 | #define TU_STANDARD_PAL_I 0x08 |
| 184 | #define TU_STANDARD_MANUAL 0x00 |
| 185 | #define TU_STANDARD_AUTO 0x01 |
| 186 | |
| 187 | /* Video Controls */ |
| 188 | #define PU_BRIGHTNESS_CONTROL 0x02 |
| 189 | #define PU_CONTRAST_CONTROL 0x03 |
| 190 | #define PU_HUE_CONTROL 0x06 |
| 191 | #define PU_SATURATION_CONTROL 0x07 |
| 192 | #define PU_SHARPNESS_CONTROL 0x08 |
| 193 | |
| 194 | /* Audio Controls */ |
| 195 | #define MUTE_CONTROL 0x01 |
| 196 | #define VOLUME_CONTROL 0x02 |
| 197 | #define AUDIO_DEFAULT_CONTROL 0x0D |
| 198 | |
| 199 | /* Default Volume Levels */ |
| 200 | #define TMHW_LEV_ADJ_DECLEV_DEFAULT 0x00 |
| 201 | #define TMHW_LEV_ADJ_MONOLEV_DEFAULT 0x00 |
| 202 | #define TMHW_LEV_ADJ_NICLEV_DEFAULT 0x00 |
| 203 | #define TMHW_LEV_ADJ_SAPLEV_DEFAULT 0x00 |
| 204 | #define TMHW_LEV_ADJ_ADCLEV_DEFAULT 0x00 |
| 205 | |
| 206 | /* Encoder Related Commands */ |
| 207 | #define EU_PROFILE_CONTROL 0x00 |
| 208 | #define EU_VIDEO_FORMAT_CONTROL 0x01 |
| 209 | #define EU_VIDEO_BIT_RATE_CONTROL 0x02 |
Steven Toth | f6eeece | 2010-07-31 15:28:18 -0300 | [diff] [blame] | 210 | #define EU_VIDEO_RESOLUTION_CONTROL 0x03 |
Steven Toth | eafea21 | 2010-07-31 14:48:45 -0300 | [diff] [blame] | 211 | #define EU_VIDEO_GOP_STRUCTURE_CONTROL 0x04 |
Steven Toth | 335961c | 2010-07-31 14:41:09 -0300 | [diff] [blame] | 212 | #define EU_VIDEO_INPUT_ASPECT_CONTROL 0x0A |
| 213 | #define EU_AUDIO_FORMAT_CONTROL 0x0C |
| 214 | #define EU_AUDIO_BIT_RATE_CONTROL 0x0D |
Steven Toth | 443c1228 | 2009-05-09 21:17:28 -0300 | [diff] [blame] | 215 | |
Steven Toth | e48836b | 2010-07-31 16:08:52 -0300 | [diff] [blame^] | 216 | /* Firmware Debugging */ |
| 217 | #define SET_DEBUG_LEVEL_CONTROL 0x0B |
| 218 | #define GET_DEBUG_DATA_CONTROL 0x0C |